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);