9 #include "assemble_matrix_impl.h"
10 #include "assemble_scalar_impl.h"
11 #include "assemble_vector_impl.h"
14 #include <xtl/xspan.hpp>
39 return impl::assemble_scalar(M, constants, coeffs);
67 const xtl::span<const T>& constants,
70 impl::assemble_vector(b, L, constants, coeffs);
103 template <
typename T>
105 xtl::span<T> b,
const std::vector<std::shared_ptr<
const Form<T>>>& a,
106 const std::vector<xtl::span<const T>>& constants,
108 const std::vector<std::vector<std::shared_ptr<
const DirichletBC<T>>>>& bcs1,
109 const std::vector<xtl::span<const T>>& x0,
double scale)
111 impl::apply_lifting(b, a, constants, coeffs, bcs1, x0, scale);
126 template <
typename T>
128 xtl::span<T> b,
const std::vector<std::shared_ptr<
const Form<T>>>& a,
129 const std::vector<std::vector<std::shared_ptr<
const DirichletBC<T>>>>& bcs1,
130 const std::vector<xtl::span<const T>>& x0,
double scale)
132 std::vector<std::unique_ptr<array2d<T>>> coeffs;
133 std::vector<std::vector<T>> constants;
143 coeffs.push_back(
nullptr);
144 constants.push_back({});
148 std::vector<const array2d<T>*> _coeffs;
149 std::for_each(coeffs.begin(), coeffs.end(),
150 [&_coeffs](
const auto& c) { _coeffs.push_back(c.get()); });
151 std::vector<xtl::span<const T>> _constants(constants.begin(),
165 template <
typename T>
167 const std::function<
int(std::int32_t,
const std::int32_t*, std::int32_t,
168 const std::int32_t*,
const T*)>& mat_add,
169 const Form<T>& a,
const xtl::span<const T>& constants,
180 std::vector<bool> dof_marker0, dof_marker1;
182 std::int32_t dim0 = bs0 * (map0->size_local() + map0->num_ghosts());
184 std::int32_t dim1 = bs1 * (map1->size_local() + map1->num_ghosts());
185 for (std::size_t k = 0; k < bcs.size(); ++k)
188 assert(bcs[k]->function_space());
191 dof_marker0.resize(dim0,
false);
192 bcs[k]->mark_dofs(dof_marker0);
197 dof_marker1.resize(dim1,
false);
198 bcs[k]->mark_dofs(dof_marker1);
203 impl::assemble_matrix(mat_add, a, constants, coeffs, dof_marker0,
212 template <
typename T>
214 const std::function<
int(std::int32_t,
const std::int32_t*, std::int32_t,
215 const std::int32_t*,
const T*)>& mat_add,
239 template <
typename T>
241 const std::function<
int(std::int32_t,
const std::int32_t*, std::int32_t,
242 const std::int32_t*,
const T*)>& mat_add,
243 const Form<T>& a,
const xtl::span<const T>& constants,
244 const array2d<T>& coeffs,
const std::vector<bool>& dof_marker0,
245 const std::vector<bool>& dof_marker1)
248 impl::assemble_matrix(mat_add, a, constants, coeffs, dof_marker0,
262 template <
typename T>
264 const std::function<
int(std::int32_t,
const std::int32_t*, std::int32_t,
265 const std::int32_t*,
const T*)>& mat_add,
266 const Form<T>& a,
const std::vector<bool>& dof_marker0,
267 const std::vector<bool>& dof_marker1)
275 assemble_matrix(mat_add, a, tcb::make_span(constants), coeffs, dof_marker0,
289 template <
typename T>
291 const std::function<
int(std::int32_t,
const std::int32_t*, std::int32_t,
292 const std::int32_t*,
const T*)>& set_fn,
293 const xtl::span<const std::int32_t>& rows, T diagonal = 1.0)
295 for (std::size_t i = 0; i < rows.size(); ++i)
297 const std::int32_t row = rows[i];
298 set_fn(1, &row, 1, &row, &diagonal);
317 template <
typename T>
319 const std::function<
int(std::int32_t,
const std::int32_t*, std::int32_t,
320 const std::int32_t*,
const T*)>& set_fn,
325 for (
const auto& bc : bcs)
328 if (V.
contains(*bc->function_space()))
330 const auto [dofs, range] = bc->dof_indices();
331 set_diagonal<T>(set_fn, dofs.first(range), diagonal);
346 template <
typename T>
349 const xtl::span<const T>& x0,
double scale = 1.0)
351 if (b.size() > x0.size())
352 throw std::runtime_error(
"Size mismatch between b and x0 vectors.");
353 for (
const auto& bc : bcs)
356 bc->set(b, x0, scale);
363 template <
typename T>
368 for (
const auto& bc : bcs)
385 template <
typename T>
386 std::vector<std::vector<std::shared_ptr<const fem::DirichletBC<T>>>>
391 std::vector<std::vector<std::shared_ptr<const fem::DirichletBC<T>>>> bcs0(
393 for (std::size_t i = 0; i < L.size(); ++i)
395 if (L[i]->function_spaces()[0]->contains(*bc->function_space()))
396 bcs0[i].push_back(bc);
410 template <
typename T>
412 std::vector<std::vector<std::shared_ptr<const fem::DirichletBC<T>>>>>
418 std::vector<std::vector<std::shared_ptr<const fem::DirichletBC<T>>>>>
420 for (std::size_t i = 0; i < a.size(); ++i)
422 for (std::size_t j = 0; j < a[i].size(); ++j)
424 bcs1[i].resize(a[j].size());
430 if (a[i][j]->function_spaces()[1]->contains(*bc->function_space()))
431 bcs1[i][j].push_back(bc);
This class provides a dynamic 2-dimensional row-wise array data structure.
Definition: array2d.h:21
Interface for setting (strong) Dirichlet boundary conditions.
Definition: DirichletBC.h:128
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:230
Finite element method functionality.
Definition: assemble_matrix_impl.h:23
void set_diagonal(const std::function< int(std::int32_t, const std::int32_t *, std::int32_t, const std::int32_t *, const T *)> &set_fn, const xtl::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:290
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:508
std::vector< std::vector< std::shared_ptr< const fem::DirichletBC< T > > > > bcs_rows(const std::vector< const Form< T > * > &L, const std::vector< std::shared_ptr< const fem::DirichletBC< T >>> &bcs)
Arrange boundary conditions by block.
Definition: assembler.h:387
std::vector< std::vector< std::vector< std::shared_ptr< const fem::DirichletBC< T > > > > > bcs_cols(const std::vector< std::vector< std::shared_ptr< const Form< T >>>> &a, const std::vector< std::shared_ptr< const DirichletBC< T >>> &bcs)
Arrange boundary conditions by block.
Definition: assembler.h:413
array2d< typename U::scalar_type > pack_coefficients(const U &u)
Pack coefficients of u of generic type U ready for assembly.
Definition: utils.h:423
void assemble_vector(xtl::span< T > b, const Form< T > &L, const xtl::span< const T > &constants, const array2d< T > &coeffs)
Assemble linear form into a vector, The caller supplies the form constants and coefficients for this ...
Definition: assembler.h:66
T assemble_scalar(const Form< T > &M, const xtl::span< const T > &constants, const array2d< T > &coeffs)
Assemble functional into scalar. The caller supplies the form constants and coefficients for this ver...
Definition: assembler.h:36
void set_bc(xtl::span< T > b, const std::vector< std::shared_ptr< const DirichletBC< T >>> &bcs, const xtl::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:347
void apply_lifting(xtl::span< T > b, const std::vector< std::shared_ptr< const Form< T >>> &a, const std::vector< xtl::span< const T >> &constants, const std::vector< const array2d< T > * > &coeffs, const std::vector< std::vector< std::shared_ptr< const DirichletBC< T >>>> &bcs1, const std::vector< xtl::span< const T >> &x0, double scale)
Modify b such that:
Definition: assembler.h:104
void assemble_matrix(const std::function< int(std::int32_t, const std::int32_t *, std::int32_t, const std::int32_t *, const T *)> &mat_add, const Form< T > &a, const xtl::span< const T > &constants, const array2d< T > &coeffs, const std::vector< std::shared_ptr< const DirichletBC< T >>> &bcs)
Assemble bilinear form into a matrix.
Definition: assembler.h:166