9#include "assemble_matrix_impl.h"
10#include "assemble_scalar_impl.h"
11#include "assemble_vector_impl.h"
15#include <dolfinx/common/types.h>
22template <dolfinx::scalar T, std::
floating_po
int U>
24template <dolfinx::scalar T, std::
floating_po
int U>
26template <std::
floating_po
int T>
32template <dolfinx::scalar T>
33std::map<std::pair<IntegralType, int>, std::pair<std::span<const T>,
int>>
35 std::pair<std::vector<T>,
int>>& coeffs)
37 using Key =
typename std::remove_reference_t<
decltype(coeffs)>::key_type;
38 std::map<Key, std::pair<std::span<const T>,
int>> c;
39 std::transform(coeffs.cbegin(), coeffs.cend(), std::inserter(c, c.end()),
40 [](
auto& e) ->
typename decltype(c)::value_type {
41 return {e.first, {e.second.first, e.second.second}};
59template <dolfinx::scalar T, std::
floating_po
int U>
61 const Form<T, U>& M, std::span<const T> constants,
62 const std::map<std::pair<IntegralType, int>,
63 std::pair<std::span<const T>,
int>>& coefficients)
65 std::shared_ptr<const mesh::Mesh<U>> mesh = M.
mesh();
67 if constexpr (std::is_same_v<U, scalar_value_type_t<T>>)
69 return impl::assemble_scalar(M, mesh->geometry().dofmap(),
70 mesh->geometry().x(), constants, coefficients);
74 auto x = mesh->geometry().x();
75 std::vector<scalar_value_type_t<T>> _x(x.begin(), x.end());
76 return impl::assemble_scalar(M, mesh->geometry().dofmap(), _x, constants,
86template <dolfinx::scalar T, std::
floating_po
int U>
92 return assemble_scalar(M, std::span(constants),
108template <dolfinx::scalar T, std::
floating_po
int U>
110 std::span<T> b,
const Form<T, U>& L, std::span<const T> constants,
111 const std::map<std::pair<IntegralType, int>,
112 std::pair<std::span<const T>,
int>>& coefficients)
114 impl::assemble_vector(b, L, constants, coefficients);
121template <dolfinx::scalar T, std::
floating_po
int U>
127 assemble_vector(b, L, std::span(constants),
149template <dolfinx::scalar T, std::
floating_po
int U>
151 std::span<T> b,
const std::vector<std::shared_ptr<
const Form<T, U>>>& a,
152 const std::vector<std::span<const T>>& constants,
153 const std::vector<std::map<std::pair<IntegralType, int>,
154 std::pair<std::span<const T>,
int>>>& coeffs,
157 const std::vector<std::span<const T>>& x0, T scale)
159 std::shared_ptr<const mesh::Mesh<U>> mesh;
164 if (a_i and mesh and a_i->mesh() != mesh)
165 throw std::runtime_error(
"Mismatch between meshes.");
169 throw std::runtime_error(
"Unable to extract a mesh.");
171 if constexpr (std::is_same_v<U, scalar_value_type_t<T>>)
173 impl::apply_lifting<T>(b, a, mesh->geometry().dofmap(),
174 mesh->geometry().x(), constants, coeffs, bcs1, x0,
179 auto x = mesh->geometry().x();
180 std::vector<scalar_value_type_t<T>> _x(x.begin(), x.end());
181 impl::apply_lifting<T>(b, a, mesh->geometry().dofmap(), _x, constants,
182 coeffs, bcs1, x0, scale);
198template <dolfinx::scalar T, std::
floating_po
int U>
200 std::span<T> b,
const std::vector<std::shared_ptr<
const Form<T, U>>>& a,
203 const std::vector<std::span<const T>>& x0, T scale)
206 std::map<std::pair<IntegralType, int>, std::pair<std::vector<T>,
int>>>
208 std::vector<std::vector<T>> constants;
215 coeffs.push_back(coefficients);
220 coeffs.emplace_back();
221 constants.emplace_back();
225 std::vector<std::span<const T>> _constants(constants.begin(),
227 std::vector<std::map<std::pair<IntegralType, int>,
228 std::pair<std::span<const T>,
int>>>
230 std::transform(coeffs.cbegin(), coeffs.cend(), std::back_inserter(_coeffs),
231 [](
auto& c) { return make_coefficients_span(c); });
233 apply_lifting(b, a, _constants, _coeffs, bcs1, x0, scale);
250template <dolfinx::scalar T, std::
floating_po
int U>
253 std::span<const T> constants,
254 const std::map<std::pair<IntegralType, int>,
255 std::pair<std::span<const T>,
int>>& coefficients,
256 std::span<const std::int8_t> dof_marker0,
257 std::span<const std::int8_t> dof_marker1)
260 std::shared_ptr<const mesh::Mesh<U>> mesh = a.
mesh();
262 if constexpr (std::is_same_v<U, scalar_value_type_t<T>>)
264 impl::assemble_matrix(mat_add, a, mesh->geometry().dofmap(),
265 mesh->geometry().x(), constants, coefficients,
266 dof_marker0, dof_marker1);
270 auto x = mesh->geometry().x();
271 std::vector<scalar_value_type_t<T>> _x(x.begin(), x.end());
272 impl::assemble_matrix(mat_add, a, mesh->geometry().dofmap(), _x, constants,
273 coefficients, dof_marker0, dof_marker1);
284template <dolfinx::scalar T, std::
floating_po
int U>
286 auto mat_add,
const Form<T, U>& a, std::span<const T> constants,
287 const std::map<std::pair<IntegralType, int>,
288 std::pair<std::span<const T>,
int>>& coefficients,
298 std::vector<std::int8_t> dof_marker0, dof_marker1;
300 std::int32_t dim0 = bs0 * (map0->size_local() + map0->num_ghosts());
302 std::int32_t dim1 = bs1 * (map1->size_local() + map1->num_ghosts());
303 for (std::size_t k = 0; k < bcs.size(); ++k)
306 assert(bcs[k]->function_space());
309 dof_marker0.resize(dim0,
false);
310 bcs[k]->mark_dofs(dof_marker0);
315 dof_marker1.resize(dim1,
false);
316 bcs[k]->mark_dofs(dof_marker1);
321 assemble_matrix(mat_add, a, constants, coefficients, dof_marker0,
330template <dolfinx::scalar T, std::
floating_po
int U>
341 assemble_matrix(mat_add, a, std::span(constants),
355template <dolfinx::scalar T, std::
floating_po
int U>
357 std::span<const std::int8_t> dof_marker0,
358 std::span<const std::int8_t> dof_marker1)
367 assemble_matrix(mat_add, a, std::span(constants),
383template <dolfinx::scalar T>
387 for (std::size_t i = 0; i < rows.size(); ++i)
389 std::span diag_span(&diagonal, 1);
390 set_fn(rows.subspan(i, 1), rows.subspan(i, 1), diag_span);
410template <dolfinx::scalar T, std::
floating_po
int U>
419 if (V.
contains(*bc->function_space()))
421 const auto [dofs, range] = bc->dof_indices();
437template <dolfinx::scalar T, std::
floating_po
int U>
440 std::span<const T> x0, T scale = 1)
442 if (b.size() > x0.size())
443 throw std::runtime_error(
"Size mismatch between b and x0 vectors.");
447 bc->set(b, x0, scale);
454template <dolfinx::scalar T, std::
floating_po
int U>
Object for setting (strong) Dirichlet boundary conditions.
Definition DirichletBC.h:251
This class represents a finite element function space defined by a mesh, a finite element,...
Definition FunctionSpace.h:35
bool contains(const FunctionSpace &V) const
Check whether V is subspace of this, or this itself.
Definition FunctionSpace.h:107
Matrix accumulate/set concept for functions that can be used in assemblers to accumulate or set value...
Definition utils.h:28
Finite element method functionality.
Definition assemble_matrix_impl.h:25
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:920
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:384
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:34
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:1196
void set_bc(std::span< T > b, const std::vector< std::shared_ptr< const DirichletBC< T, U > > > &bcs, std::span< const T > x0, T scale=1)
Set bc values in owned (local) part of the vector, multiplied by 'scale'. The vectors b and x0 must h...
Definition assembler.h:438
FunctionSpace(U mesh, V element, W dofmap) -> FunctionSpace< typename std::remove_cvref< typename U::element_type >::type::geometry_type::value_type >
Type deduction.
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:974