9#include "assemble_matrix_impl.h"
10#include "assemble_scalar_impl.h"
11#include "assemble_vector_impl.h"
16#include <dolfinx/common/types.h>
24template <dolfinx::scalar T, std::
floating_po
int U>
26template <dolfinx::scalar T, std::
floating_po
int U>
28template <std::
floating_po
int T>
34template <dolfinx::scalar T>
35std::map<std::pair<IntegralType, int>, std::pair<std::span<const T>,
int>>
37 std::pair<std::vector<T>,
int>>& coeffs)
39 using Key =
typename std::remove_reference_t<
decltype(coeffs)>::key_type;
40 std::map<Key, std::pair<std::span<const T>,
int>> c;
41 std::ranges::transform(
42 coeffs, std::inserter(c, c.end()),
43 [](
auto& e) ->
typename decltype(c)::value_type
44 { return {e.first, {e.second.first, e.second.second}}; });
61template <dolfinx::scalar T, std::
floating_po
int U>
63 const Form<T, U>& M, std::span<const T> constants,
64 const std::map<std::pair<IntegralType, int>,
65 std::pair<std::span<const T>,
int>>& coefficients)
67 std::shared_ptr<const mesh::Mesh<U>> mesh = M.mesh();
69 if constexpr (std::is_same_v<U, scalar_value_type_t<T>>)
71 return impl::assemble_scalar(M, mesh->geometry().dofmap(),
72 mesh->geometry().x(), constants, coefficients);
76 auto x = mesh->geometry().x();
77 std::vector<scalar_value_type_t<T>> _x(x.begin(), x.end());
78 return impl::assemble_scalar(M, mesh->geometry().dofmap(), _x, constants,
88template <dolfinx::scalar T, std::
floating_po
int U>
94 return assemble_scalar(M, std::span(constants),
110template <dolfinx::scalar T, std::
floating_po
int U>
112 std::span<T> b,
const Form<T, U>& L, std::span<const T> constants,
113 const std::map<std::pair<IntegralType, int>,
114 std::pair<std::span<const T>,
int>>& coefficients)
116 impl::assemble_vector(b, L, constants, coefficients);
123template <dolfinx::scalar T, std::
floating_po
int U>
129 assemble_vector(b, L, std::span(constants),
151template <dolfinx::scalar T, std::
floating_po
int U>
153 std::span<T> b,
const std::vector<std::shared_ptr<
const Form<T, U>>>& a,
154 const std::vector<std::span<const T>>& constants,
155 const std::vector<std::map<std::pair<IntegralType, int>,
156 std::pair<std::span<const T>,
int>>>& coeffs,
159 const std::vector<std::span<const T>>& x0, T alpha)
162 if (std::ranges::all_of(a, [](
auto ptr) {
return ptr ==
nullptr; }))
165 impl::apply_lifting<T>(b, a, constants, coeffs, bcs1, x0, alpha);
180template <dolfinx::scalar T, std::
floating_po
int U>
182 std::span<T> b,
const std::vector<std::shared_ptr<
const Form<T, U>>>& a,
185 const std::vector<std::span<const T>>& x0, T alpha)
188 std::map<std::pair<IntegralType, int>, std::pair<std::vector<T>,
int>>>
190 std::vector<std::vector<T>> constants;
197 coeffs.push_back(coefficients);
202 coeffs.emplace_back();
203 constants.emplace_back();
207 std::vector<std::span<const T>> _constants(constants.begin(),
209 std::vector<std::map<std::pair<IntegralType, int>,
210 std::pair<std::span<const T>,
int>>>
212 std::ranges::transform(coeffs, std::back_inserter(_coeffs),
215 apply_lifting(b, a, _constants, _coeffs, bcs1, x0, alpha);
232template <dolfinx::scalar T, std::
floating_po
int U>
235 std::span<const T> constants,
236 const std::map<std::pair<IntegralType, int>,
237 std::pair<std::span<const T>,
int>>& coefficients,
238 std::span<const std::int8_t> dof_marker0,
239 std::span<const std::int8_t> dof_marker1)
242 std::shared_ptr<const mesh::Mesh<U>> mesh = a.mesh();
244 if constexpr (std::is_same_v<U, scalar_value_type_t<T>>)
246 impl::assemble_matrix(mat_add, a, mesh->geometry().dofmap(),
247 mesh->geometry().x(), constants, coefficients,
248 dof_marker0, dof_marker1);
252 auto x = mesh->geometry().x();
253 std::vector<scalar_value_type_t<T>> _x(x.begin(), x.end());
254 impl::assemble_matrix(mat_add, a, mesh->geometry().dofmap(), _x, constants,
255 coefficients, dof_marker0, dof_marker1);
266template <dolfinx::scalar T, std::
floating_po
int U>
268 auto mat_add,
const Form<T, U>& a, std::span<const T> constants,
269 const std::map<std::pair<IntegralType, int>,
270 std::pair<std::span<const T>,
int>>& coefficients,
274 auto map0 = a.function_spaces().at(0)->dofmap()->index_map;
275 auto map1 = a.function_spaces().at(1)->dofmap()->index_map;
276 auto bs0 = a.function_spaces().at(0)->dofmap()->index_map_bs();
277 auto bs1 = a.function_spaces().at(1)->dofmap()->index_map_bs();
280 std::vector<std::int8_t> dof_marker0, dof_marker1;
282 std::int32_t dim0 = bs0 * (map0->size_local() + map0->num_ghosts());
284 std::int32_t dim1 = bs1 * (map1->size_local() + map1->num_ghosts());
285 for (std::size_t k = 0; k < bcs.size(); ++k)
288 assert(bcs[k]->function_space());
289 if (a.function_spaces().at(0)->contains(*bcs[k]->function_space()))
291 dof_marker0.resize(dim0,
false);
292 bcs[k]->mark_dofs(dof_marker0);
295 if (a.function_spaces().at(1)->contains(*bcs[k]->function_space()))
297 dof_marker1.resize(dim1,
false);
298 bcs[k]->mark_dofs(dof_marker1);
303 assemble_matrix(mat_add, a, constants, coefficients, dof_marker0,
312template <dolfinx::scalar T, std::
floating_po
int U>
323 assemble_matrix(mat_add, a, std::span(constants),
337template <dolfinx::scalar T, std::
floating_po
int U>
339 std::span<const std::int8_t> dof_marker0,
340 std::span<const std::int8_t> dof_marker1)
349 assemble_matrix(mat_add, a, std::span(constants),
365template <dolfinx::scalar T>
369 for (std::size_t i = 0; i < rows.size(); ++i)
371 std::span diag_span(&diagonal, 1);
372 set_fn(rows.subspan(i, 1), rows.subspan(i, 1), diag_span);
392template <dolfinx::scalar T, std::
floating_po
int U>
401 if (V.contains(*bc->function_space()))
403 const auto [dofs, range] = bc->dof_indices();
This class represents a finite element function space defined by a mesh, a finite element,...
Definition vtk_utils.h:32
Matrix accumulate/set concept for functions that can be used in assemblers to accumulate or set value...
Definition utils.h:28
Functions supporting finite element method operations.
Finite element method functionality.
Definition assemble_matrix_impl.h:26
std::pair< std::vector< T >, int > allocate_coefficient_storage(const Form< T, U > &form, IntegralType integral_type, int id)
Allocate storage for coefficients of a pair (integral_type, / id) from a Form.
Definition utils.h:1008
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:366
std::map< std::pair< 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:36
std::vector< typename U::scalar_type > pack_constants(const U &u)
Pack constants of u into a single array ready for assembly.
Definition utils.h:1348
void pack_coefficients(const Form< T, U > &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:1062