9#include "assemble_matrix_impl.h"
10#include "assemble_scalar_impl.h"
11#include "assemble_vector_impl.h"
29std::map<std::pair<fem::IntegralType, int>, std::pair<std::span<const T>,
int>>
31 std::pair<std::vector<T>,
int>>& coeffs)
33 using Key =
typename std::remove_reference_t<
decltype(coeffs)>::key_type;
34 std::map<Key, std::pair<std::span<const T>,
int>> c;
35 std::transform(coeffs.cbegin(), coeffs.cend(), std::inserter(c, c.end()),
36 [](
auto& e) ->
typename decltype(c)::value_type {
37 return {e.first, {e.second.first, e.second.second}};
57 const Form<T>& M, std::span<const T> constants,
58 const std::map<std::pair<IntegralType, int>,
59 std::pair<std::span<const T>,
int>>& coefficients)
61 return impl::assemble_scalar(M, constants, coefficients);
75 return assemble_scalar(M, std::span(constants),
93 std::span<T> b,
const Form<T>& L, std::span<const T> constants,
94 const std::map<std::pair<IntegralType, int>,
95 std::pair<std::span<const T>,
int>>& coefficients)
97 impl::assemble_vector(b, L, constants, coefficients);
105void assemble_vector(std::span<T> b,
const Form<T>& L)
110 assemble_vector(b, L, std::span(constants),
134 std::span<T> b,
const std::vector<std::shared_ptr<
const Form<T>>>& a,
135 const std::vector<std::span<const T>>& constants,
136 const std::vector<std::map<std::pair<IntegralType, int>,
137 std::pair<std::span<const T>,
int>>>& coeffs,
138 const std::vector<std::vector<std::shared_ptr<
const DirichletBC<T>>>>& bcs1,
139 const std::vector<std::span<const T>>& x0,
double scale)
141 impl::apply_lifting(b, a, constants, coeffs, bcs1, x0, scale);
158 std::span<T> b,
const std::vector<std::shared_ptr<
const Form<T>>>& a,
159 const std::vector<std::vector<std::shared_ptr<
const DirichletBC<T>>>>& bcs1,
160 const std::vector<std::span<const T>>& x0,
double scale)
163 std::map<std::pair<IntegralType, int>, std::pair<std::vector<T>,
int>>>
165 std::vector<std::vector<T>> constants;
172 coeffs.push_back(coefficients);
177 coeffs.emplace_back();
178 constants.emplace_back();
182 std::vector<std::span<const T>> _constants(constants.begin(),
184 std::vector<std::map<std::pair<IntegralType, int>,
185 std::pair<std::span<const T>,
int>>>
187 std::transform(coeffs.cbegin(), coeffs.cend(), std::back_inserter(_coeffs),
188 [](
auto& c) { return make_coefficients_span(c); });
189 apply_lifting(b, a, _constants, _coeffs, bcs1, x0, scale);
203 auto mat_add,
const Form<T>& a, std::span<const T> constants,
204 const std::map<std::pair<IntegralType, int>,
205 std::pair<std::span<const T>,
int>>& coefficients,
215 std::vector<std::int8_t> dof_marker0, dof_marker1;
217 std::int32_t dim0 = bs0 * (map0->size_local() + map0->num_ghosts());
219 std::int32_t dim1 = bs1 * (map1->size_local() + map1->num_ghosts());
220 for (std::size_t k = 0; k < bcs.size(); ++k)
223 assert(bcs[k]->function_space());
226 dof_marker0.resize(dim0,
false);
227 bcs[k]->mark_dofs(dof_marker0);
232 dof_marker1.resize(dim1,
false);
233 bcs[k]->mark_dofs(dof_marker1);
238 impl::assemble_matrix(mat_add, a, constants, coefficients, dof_marker0,
249 auto mat_add,
const Form<T>& a,
258 assemble_matrix(mat_add, a, std::span(constants),
276 auto mat_add,
const Form<T>& a, std::span<const T> constants,
277 const std::map<std::pair<IntegralType, int>,
278 std::pair<std::span<const T>,
int>>& coefficients,
279 std::span<const std::int8_t> dof_marker0,
280 std::span<const std::int8_t> dof_marker1)
283 impl::assemble_matrix(mat_add, a, constants, coefficients, dof_marker0,
298void assemble_matrix(
auto mat_add,
const Form<T>& a,
299 std::span<const std::int8_t> dof_marker0,
300 std::span<const std::int8_t> dof_marker1)
309 assemble_matrix(mat_add, a, std::span(constants),
329 for (std::size_t i = 0; i < rows.size(); ++i)
331 std::span diag_span(&diagonal, 1);
332 set_fn(rows.subspan(i, 1), rows.subspan(i, 1), diag_span);
357 for (
const auto& bc : bcs)
360 if (V.
contains(*bc->function_space()))
362 const auto [dofs, range] = bc->dof_indices();
381 std::span<const T> x0,
double scale = 1.0)
383 if (b.size() > x0.size())
384 throw std::runtime_error(
"Size mismatch between b and x0 vectors.");
385 for (
const auto& bc : bcs)
388 bc->set(b, x0, scale);
400 for (
const auto& bc : bcs)
Object for setting (strong) Dirichlet boundary conditions.
Definition: DirichletBC.h:133
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
void set_diagonal(auto set_fn, std::span< const std::int32_t > rows, T diagonal=1.0)
Sets a value to the diagonal of a matrix for specified rows.
Definition: assembler.h:326
std::map< std::pair< 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 of std::spans from a map of std::vectors.
Definition: assembler.h:30
void set_bc(std::span< T > b, const std::vector< std::shared_ptr< const DirichletBC< T > > > &bcs, 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:379
void pack_coefficients(const Form< T > &form, IntegralType integral_type, int id, std::span< T > c, int cstride)
Pack coefficients of a Form for a given integral type and domain id.
Definition: utils.h:755
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:985
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:692