9 #include "assemble_matrix_impl.h"
10 #include "assemble_scalar_impl.h"
11 #include "assemble_vector_impl.h"
29 std::map<std::pair<dolfinx::fem::IntegralType, int>,
30 std::pair<std::span<const T>,
int>>
32 std::pair<std::vector<T>,
int>>& coeffs)
34 using Key =
typename std::remove_reference_t<decltype(coeffs)>::key_type;
35 std::map<Key, std::pair<std::span<const T>,
int>> c;
36 std::transform(coeffs.cbegin(), coeffs.cend(), std::inserter(c, c.end()),
37 [](
auto& e) ->
typename decltype(c)::value_type {
38 return {e.first, {e.second.first, e.second.second}};
56 const Form<T>& M,
const std::span<const T>& constants,
57 const std::map<std::pair<IntegralType, int>,
58 std::pair<std::span<const T>,
int>>& coefficients)
60 return impl::assemble_scalar(M, constants, coefficients);
90 std::span<T> b,
const Form<T>& L,
const std::span<const T>& constants,
91 const std::map<std::pair<IntegralType, int>,
92 std::pair<std::span<const T>,
int>>& coefficients)
94 impl::assemble_vector(b, L, constants, coefficients);
101 template <
typename T>
129 template <
typename T>
131 std::span<T> b,
const std::vector<std::shared_ptr<
const Form<T>>>& a,
132 const std::vector<std::span<const T>>& constants,
133 const std::vector<std::map<std::pair<IntegralType, int>,
134 std::pair<std::span<const T>,
int>>>& coeffs,
135 const std::vector<std::vector<std::shared_ptr<
const DirichletBC<T>>>>& bcs1,
136 const std::vector<std::span<const T>>& x0,
double scale)
138 impl::apply_lifting(b, a, constants, coeffs, bcs1, x0, scale);
153 template <
typename T>
155 std::span<T> b,
const std::vector<std::shared_ptr<
const Form<T>>>& a,
156 const std::vector<std::vector<std::shared_ptr<
const DirichletBC<T>>>>& bcs1,
157 const std::vector<std::span<const T>>& x0,
double scale)
160 std::map<std::pair<IntegralType, int>, std::pair<std::vector<T>,
int>>>
162 std::vector<std::vector<T>> constants;
169 coeffs.push_back(coefficients);
174 coeffs.push_back(std::map<std::pair<IntegralType, int>,
175 std::pair<std::vector<T>,
int>>());
176 constants.push_back({});
180 std::vector<std::span<const T>> _constants(constants.begin(),
182 std::vector<std::map<std::pair<IntegralType, int>,
183 std::pair<std::span<const T>,
int>>>
185 std::transform(coeffs.cbegin(), coeffs.cend(), std::back_inserter(_coeffs),
186 [](
auto& c) { return make_coefficients_span(c); });
199 template <
typename T,
typename U>
201 U mat_add,
const Form<T>& a,
const std::span<const T>& constants,
202 const std::map<std::pair<IntegralType, int>,
203 std::pair<std::span<const T>,
int>>& coefficients,
213 std::vector<std::int8_t> dof_marker0, dof_marker1;
215 std::int32_t dim0 = bs0 * (map0->size_local() + map0->num_ghosts());
217 std::int32_t dim1 = bs1 * (map1->size_local() + map1->num_ghosts());
218 for (std::size_t k = 0; k < bcs.size(); ++k)
221 assert(bcs[k]->function_space());
224 dof_marker0.resize(dim0,
false);
225 bcs[k]->mark_dofs(dof_marker0);
230 dof_marker1.resize(dim1,
false);
231 bcs[k]->mark_dofs(dof_marker1);
236 impl::assemble_matrix(mat_add, a, constants, coefficients, dof_marker0,
245 template <
typename T,
typename U>
272 template <
typename T,
typename U>
274 U mat_add,
const Form<T>& a,
const std::span<const T>& constants,
275 const std::map<std::pair<IntegralType, int>,
276 std::pair<std::span<const T>,
int>>& coefficients,
277 const std::span<const std::int8_t>& dof_marker0,
278 const std::span<const std::int8_t>& dof_marker1)
281 impl::assemble_matrix(mat_add, a, constants, coefficients, dof_marker0,
295 template <
typename T,
typename U>
297 const std::span<const std::int8_t>& dof_marker0,
298 const std::span<const std::int8_t>& dof_marker1)
322 template <
typename T,
typename U>
326 for (std::size_t i = 0; i < rows.size(); ++i)
328 std::span diag_span(&diagonal, 1);
329 set_fn(rows.subspan(i, 1), rows.subspan(i, 1), diag_span);
348 template <
typename T,
typename U>
353 for (
const auto& bc : bcs)
356 if (V.
contains(*bc->function_space()))
358 const auto [dofs, range] = bc->dof_indices();
374 template <
typename T>
377 const std::span<const T>& x0,
double scale = 1.0)
379 if (b.size() > x0.size())
380 throw std::runtime_error(
"Size mismatch between b and x0 vectors.");
381 for (
const auto& bc : bcs)
384 bc->set(b, x0, scale);
391 template <
typename T>
396 for (
const auto& bc : bcs)
Object for setting (strong) Dirichlet boundary conditions.
Definition: DirichletBC.h:125
This class represents a finite element function space defined by a mesh, a finite element,...
Definition: FunctionSpace.h:31
bool contains(const FunctionSpace &V) const
Check whether V is subspace of this, or this itself.
Definition: FunctionSpace.cpp:69
Finite element method functionality.
Definition: assemble_matrix_impl.h:25
std::vector< typename U::scalar_type > pack_constants(const U &u)
Pack constants of u of generic type U ready for assembly.
Definition: utils.h:970
void assemble_vector(std::span< T > b, const Form< T > &L, const std::span< const T > &constants, const std::map< std::pair< IntegralType, int >, std::pair< std::span< const T >, int >> &coefficients)
Assemble linear form into a vector, The caller supplies the form constants and coefficients for this ...
Definition: assembler.h:89
std::pair< std::vector< T >, int > allocate_coefficient_storage(const Form< T > &form, IntegralType integral_type, int id)
Allocate storage for coefficients of a pair (integral_type, id) from a fem::Form form.
Definition: utils.h:675
std::map< std::pair< dolfinx::fem::IntegralType, int >, std::pair< std::span< const T >, int > > make_coefficients_span(const std::map< std::pair< IntegralType, int >, std::pair< std::vector< T >, int >> &coeffs)
Create a map std::span from a map of std::vector.
Definition: assembler.h:31
T assemble_scalar(const Form< T > &M, const std::span< const T > &constants, const std::map< std::pair< IntegralType, int >, std::pair< std::span< const T >, int >> &coefficients)
Assemble functional into scalar. The caller supplies the form constants and coefficients for this ver...
Definition: assembler.h:55
void pack_coefficients(const Form< T > &form, IntegralType integral_type, int id, const std::span< T > &c, int cstride)
Pack coefficients of a Form for a given integral type and domain id.
Definition: utils.h:738
void apply_lifting(std::span< T > b, const std::vector< std::shared_ptr< const Form< T >>> &a, const std::vector< std::span< const T >> &constants, const std::vector< std::map< std::pair< IntegralType, int >, std::pair< std::span< const T >, int >>> &coeffs, const std::vector< std::vector< std::shared_ptr< const DirichletBC< T >>>> &bcs1, const std::vector< std::span< const T >> &x0, double scale)
Modify b such that:
Definition: assembler.h:130
void set_bc(std::span< T > b, const std::vector< std::shared_ptr< const DirichletBC< T >>> &bcs, const std::span< const T > &x0, double scale=1.0)
Set bc values in owned (local) part of the vector, multiplied by 'scale'. The vectors b and x0 must h...
Definition: assembler.h:375
void set_diagonal(U set_fn, const std::span< const std::int32_t > &rows, T diagonal=1.0)
Sets a value to the diagonal of a matrix for specified rows. It is typically called after assembly....
Definition: assembler.h:323
void assemble_matrix(U mat_add, const Form< T > &a, const std::span< const T > &constants, const std::map< std::pair< IntegralType, int >, std::pair< std::span< const T >, int >> &coefficients, const std::vector< std::shared_ptr< const DirichletBC< T >>> &bcs)
Assemble bilinear form into a matrix.
Definition: assembler.h:200