Skip to content

Commit

Permalink
Add maps for mixed-domain assembly (#3056)
Browse files Browse the repository at this point in the history
* Add ent maps to form

* Add maps to create_form_factory

* Pass entity maps

* Add maps

* Add additional domain function

* Update demo

* Update test

* Add new sparsity build function

* Handle case when same mesh is used

* Call mixed-domain sparsity

* Add mixed-domain assembler

* Call mixed domain assembler and add test

* Add some docs

* Docs

* Use transform

* Add braces

* Add braces

* Clarify docs

* Change numering style

* Pass cells as array

* Remove default arg

* Simplify

* Use hack to avoid passing shared pointer

* Remove second Form constructor

* Doc updates

* Doc updates

* Remove duplicate function.

* Remove PETSc dependency in test

* Small simplification

* Remove duplicated function

* Cluster dof data

* Tidy up

* Small simplifications

* Remove include

* Small doc fixes

* Doc fixes

* Improve docs

* More docs

* Simplification

* Small update

* Simplification

* Simplification

---------

Co-authored-by: Garth N. Wells <gnw20@cam.ac.uk>
  • Loading branch information
jpdean and garth-wells authored Feb 27, 2024
1 parent 03ba4a0 commit c7c6205
Show file tree
Hide file tree
Showing 19 changed files with 445 additions and 213 deletions.
15 changes: 8 additions & 7 deletions cpp/demo/custom_kernel/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ double assemble_matrix0(std::shared_ptr<fem::FunctionSpace<T>> V, auto kernel,
// Associate kernel with cells (as opposed to facets, etc)
std::map integrals{std::pair{fem::IntegralType::cell, kernel_data}};

fem::Form<T> a({V, V}, integrals, {}, {}, false, V->mesh());
fem::Form<T> a({V, V}, integrals, {}, {}, false, {}, V->mesh());
auto dofmap = V->dofmap();
auto sp = la::SparsityPattern(
V->mesh()->comm(), {dofmap->index_map, dofmap->index_map},
{dofmap->index_map_bs(), dofmap->index_map_bs()});
fem::sparsitybuild::cells(sp, cells, {*dofmap, *dofmap});
fem::sparsitybuild::cells(sp, {cells, cells}, {*dofmap, *dofmap});
sp.finalize();
la::MatrixCSR<T> A(sp);
common::Timer timer("Assembler0 std::function (matrix)");
Expand All @@ -103,7 +103,7 @@ double assemble_vector0(std::shared_ptr<fem::FunctionSpace<T>> V, auto kernel,
auto mesh = V->mesh();
std::vector kernal_data{fem::integral_data<T>(-1, kernel, cells)};
std::map integrals{std::pair{fem::IntegralType::cell, kernal_data}};
fem::Form<T> L({V}, integrals, {}, {}, false, mesh);
fem::Form<T> L({V}, integrals, {}, {}, false, {}, mesh);
auto dofmap = V->dofmap();
la::Vector<T> b(dofmap->index_map, 1);
common::Timer timer("Assembler0 std::function (vector)");
Expand All @@ -130,14 +130,15 @@ double assemble_matrix1(const mesh::Geometry<T>& g, const fem::DofMap& dofmap,
auto sp = la::SparsityPattern(dofmap.index_map->comm(),
{dofmap.index_map, dofmap.index_map},
{dofmap.index_map_bs(), dofmap.index_map_bs()});
fem::sparsitybuild::cells(sp, cells, {dofmap, dofmap});
fem::sparsitybuild::cells(sp, {cells, cells}, {dofmap, dofmap});
sp.finalize();
la::MatrixCSR<T> A(sp);
auto ident = [](auto, auto, auto, auto) {}; // DOF permutation not required
common::Timer timer("Assembler1 lambda (matrix)");
fem::impl::assemble_cells(A.mat_add_values(), g.dofmap(), g.x(), cells, ident,
dofmap.map(), 1, ident, dofmap.map(), 1, {}, {},
kernel, std::span<const T>(), 0, {}, {});
fem::impl::assemble_cells(A.mat_add_values(), g.dofmap(), g.x(), cells,
{dofmap.map(), 1, cells}, ident,
{dofmap.map(), 1, cells}, ident, {}, {}, kernel,
std::span<const T>(), 0, {}, {}, {});
A.scatter_rev();
return A.squared_norm();
}
Expand Down
8 changes: 4 additions & 4 deletions cpp/dolfinx/fem/ElementDofLayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ enum class CellType;
namespace dolfinx::fem
{

/// The class represents the degree-of-freedom (dofs) for an element.
/// Dofs are associated with a mesh entity. This class also handles
/// sub-space dofs, which are views into the parent dofs.

// TODO: For this class/concept to be robust, the topology of the
// reference cell needs to be defined.

//
// TODO: Handle block dofmaps properly

/// The class represents the degree-of-freedom (dofs) for an element.
/// Dofs are associated with a mesh entity. This class also handles
/// sub-space dofs, which are views into the parent dofs.
class ElementDofLayout
{
public:
Expand Down
7 changes: 1 addition & 6 deletions cpp/dolfinx/fem/FiniteElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#pragma once

#include "traits.h"
#include <array>
#include <basix/finite-element.h>
#include <concepts>
Expand All @@ -21,12 +22,6 @@ struct ufcx_finite_element;

namespace dolfinx::fem
{
/// @brief DOF transform kernel concept.
template <class U, class T>
concept DofTransformKernel
= std::is_invocable_v<U, std::span<T>, std::span<const std::uint32_t>,
std::int32_t, int>;

/// Finite Element, containing the dof layout on a reference element,
/// and various methods for evaluating and transforming the basis.
template <std::floating_point T>
Expand Down
Loading

0 comments on commit c7c6205

Please sign in to comment.