9 #include "assemble_matrix_impl.h"
10 #include "assemble_scalar_impl.h"
11 #include "assemble_vector_impl.h"
14 #include <xtl/xspan.hpp>
35 return fem::impl::assemble_scalar(M);
47 fem::impl::assemble_vector(b, L);
70 xtl::span<T> b,
const std::vector<std::shared_ptr<
const Form<T>>>& a,
71 const std::vector<std::vector<std::shared_ptr<
const DirichletBC<T>>>>& bcs1,
72 const std::vector<xtl::span<const T>>& x0,
double scale)
74 fem::impl::apply_lifting(b, a, bcs1, x0, scale);
87 const std::function<
int(std::int32_t,
const std::int32_t*, std::int32_t,
88 const std::int32_t*,
const T*)>& mat_add,
99 std::vector<bool> dof_marker0, dof_marker1;
101 std::int32_t dim0 = bs0 * (map0->size_local() + map0->num_ghosts());
103 std::int32_t dim1 = bs1 * (map1->size_local() + map1->num_ghosts());
104 for (std::size_t k = 0; k < bcs.size(); ++k)
107 assert(bcs[k]->function_space());
110 dof_marker0.resize(dim0,
false);
111 bcs[k]->mark_dofs(dof_marker0);
116 dof_marker1.resize(dim1,
false);
117 bcs[k]->mark_dofs(dof_marker1);
122 impl::assemble_matrix(mat_add, a, dof_marker0, dof_marker1);
135 template <
typename T>
137 const std::function<
int(std::int32_t,
const std::int32_t*, std::int32_t,
138 const std::int32_t*,
const T*)>& mat_add,
139 const Form<T>& a,
const std::vector<bool>& dof_marker0,
140 const std::vector<bool>& dof_marker1)
143 impl::assemble_matrix(mat_add, a, dof_marker0, dof_marker1);
156 template <
typename T>
158 const std::function<
int(std::int32_t,
const std::int32_t*, std::int32_t,
159 const std::int32_t*,
const T*)>& set_fn,
160 const xtl::span<const std::int32_t>& rows, T diagonal = 1.0)
162 for (std::size_t i = 0; i < rows.size(); ++i)
164 const std::int32_t row = rows[i];
165 set_fn(1, &row, 1, &row, &diagonal);
184 template <
typename T>
186 const std::function<
int(std::int32_t,
const std::int32_t*, std::int32_t,
187 const std::int32_t*,
const T*)>& set_fn,
192 for (
const auto& bc : bcs)
195 if (V.
contains(*bc->function_space()))
197 const auto [dofs, range] = bc->dof_indices();
198 set_diagonal<T>(set_fn, dofs.first(range), diagonal);
213 template <
typename T>
216 const xtl::span<const T>& x0,
double scale = 1.0)
218 if (b.size() > x0.size())
219 throw std::runtime_error(
"Size mismatch between b and x0 vectors.");
220 for (
const auto& bc : bcs)
223 bc->set(b, x0, scale);
230 template <
typename T>
235 for (
const auto& bc : bcs)
252 template <
typename T>
253 std::vector<std::vector<std::shared_ptr<const fem::DirichletBC<T>>>>
258 std::vector<std::vector<std::shared_ptr<const fem::DirichletBC<T>>>> bcs0(
260 for (std::size_t i = 0; i < L.size(); ++i)
262 if (L[i]->function_spaces()[0]->contains(*bc->function_space()))
263 bcs0[i].push_back(bc);
277 template <
typename T>
279 std::vector<std::vector<std::shared_ptr<const fem::DirichletBC<T>>>>>
285 std::vector<std::vector<std::shared_ptr<const fem::DirichletBC<T>>>>>
287 for (std::size_t i = 0; i < a.size(); ++i)
289 for (std::size_t j = 0; j < a[i].size(); ++j)
291 bcs1[i].resize(a[j].size());
297 if (a[i][j]->function_spaces()[1]->contains(*bc->function_space()))
298 bcs1[i][j].push_back(bc);
Interface for setting (strong) Dirichlet boundary conditions.
Definition: DirichletBC.h:131
This class represents a finite element function space defined by a mesh, a finite element,...
Definition: FunctionSpace.h:34
bool contains(const FunctionSpace &V) const
Check whether V is subspace of this, or this itself.
Definition: FunctionSpace.cpp:223
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:157
void apply_lifting(xtl::span< T > b, const std::vector< std::shared_ptr< const Form< T >>> &a, 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:69
void assemble_vector(xtl::span< T > b, const Form< T > &L)
Assemble linear form into a vector.
Definition: assembler.h:45
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 std::vector< std::shared_ptr< const DirichletBC< T >>> &bcs)
Assemble bilinear form into a matrix.
Definition: assembler.h:86
T assemble_scalar(const Form< T > &M)
Assemble functional into scalar. Caller is responsible for accumulation across processes.
Definition: assembler.h:33
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:254
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:280
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:214