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>
154 std::vector<std::optional<std::reference_wrapper<
const Form<T, U>>>> a,
155 const std::vector<std::span<const T>>& constants,
156 const std::vector<std::map<std::pair<IntegralType, int>,
157 std::pair<std::span<const T>,
int>>>& coeffs,
160 const std::vector<std::span<const T>>& x0, T alpha)
163 if (std::ranges::all_of(a, [](
auto ai) {
return !ai; }))
166 impl::apply_lifting<T>(b, a, constants, coeffs, bcs1, x0, alpha);
181template <dolfinx::scalar T, std::
floating_po
int U>
184 std::vector<std::optional<std::reference_wrapper<
const Form<T, U>>>> a,
187 const std::vector<std::span<const T>>& x0, T alpha)
190 std::map<std::pair<IntegralType, int>, std::pair<std::vector<T>,
int>>>
192 std::vector<std::vector<T>> constants;
199 coeffs.push_back(coefficients);
204 coeffs.emplace_back();
205 constants.emplace_back();
209 std::vector<std::span<const T>> _constants(constants.begin(),
211 std::vector<std::map<std::pair<IntegralType, int>,
212 std::pair<std::span<const T>,
int>>>
214 std::ranges::transform(coeffs, std::back_inserter(_coeffs),
217 apply_lifting(b, a, _constants, _coeffs, bcs1, x0, alpha);
234template <dolfinx::scalar T, std::
floating_po
int U>
237 std::span<const T> constants,
238 const std::map<std::pair<IntegralType, int>,
239 std::pair<std::span<const T>,
int>>& coefficients,
240 std::span<const std::int8_t> dof_marker0,
241 std::span<const std::int8_t> dof_marker1)
244 std::shared_ptr<const mesh::Mesh<U>> mesh = a.mesh();
246 if constexpr (std::is_same_v<U, scalar_value_type_t<T>>)
248 impl::assemble_matrix(mat_add, a, mesh->geometry().dofmap(),
249 mesh->geometry().x(), constants, coefficients,
250 dof_marker0, dof_marker1);
254 auto x = mesh->geometry().x();
255 std::vector<scalar_value_type_t<T>> _x(x.begin(), x.end());
256 impl::assemble_matrix(mat_add, a, mesh->geometry().dofmap(), _x, constants,
257 coefficients, dof_marker0, dof_marker1);
268template <dolfinx::scalar T, std::
floating_po
int U>
270 auto mat_add,
const Form<T, U>& a, std::span<const T> constants,
271 const std::map<std::pair<IntegralType, int>,
272 std::pair<std::span<const T>,
int>>& coefficients,
276 auto map0 = a.function_spaces().at(0)->dofmap()->index_map;
277 auto map1 = a.function_spaces().at(1)->dofmap()->index_map;
278 auto bs0 = a.function_spaces().at(0)->dofmap()->index_map_bs();
279 auto bs1 = a.function_spaces().at(1)->dofmap()->index_map_bs();
282 std::vector<std::int8_t> dof_marker0, dof_marker1;
284 std::int32_t dim0 = bs0 * (map0->size_local() + map0->num_ghosts());
286 std::int32_t dim1 = bs1 * (map1->size_local() + map1->num_ghosts());
287 for (std::size_t k = 0; k < bcs.size(); ++k)
289 assert(bcs[k].get().function_space());
290 if (a.function_spaces().at(0)->contains(*bcs[k].get().function_space()))
292 dof_marker0.resize(dim0,
false);
293 bcs[k].get().mark_dofs(dof_marker0);
296 if (a.function_spaces().at(1)->contains(*bcs[k].get().function_space()))
298 dof_marker1.resize(dim1,
false);
299 bcs[k].get().mark_dofs(dof_marker1);
304 assemble_matrix(mat_add, a, constants, coefficients, dof_marker0,
313template <dolfinx::scalar T, std::
floating_po
int U>
324 assemble_matrix(mat_add, a, std::span(constants),
338template <dolfinx::scalar T, std::
floating_po
int U>
340 std::span<const std::int8_t> dof_marker0,
341 std::span<const std::int8_t> dof_marker1)
350 assemble_matrix(mat_add, a, std::span(constants),
366template <dolfinx::scalar T>
370 for (std::size_t i = 0; i < rows.size(); ++i)
372 std::span diag_span(&diagonal, 1);
373 set_fn(rows.subspan(i, 1), rows.subspan(i, 1), diag_span);
393template <dolfinx::scalar T, std::
floating_po
int U>
401 if (V.contains(*bc.get().function_space()))
403 const auto [dofs, range] = bc.get().dof_indices();
Definition DirichletBC.h:260
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:973
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:367
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:1314
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:1027