10#include "DirichletBC.h"
13#include "FunctionSpace.h"
17#include <basix/mdspan.hpp>
19#include <dolfinx/common/IndexMap.h>
20#include <dolfinx/mesh/Geometry.h>
21#include <dolfinx/mesh/Mesh.h>
22#include <dolfinx/mesh/Topology.h>
29namespace dolfinx::fem::impl
33using mdspan2_t = MDSPAN_IMPL_STANDARD_NAMESPACE::mdspan<
35 MDSPAN_IMPL_STANDARD_NAMESPACE::dextents<std::size_t, 2>>;
77 std::span<T> b, mdspan2_t x_dofmap,
78 std::span<
const scalar_value_type_t<T>> x, FEkernel<T>
auto kernel,
79 std::span<const std::int32_t> cells,
80 std::tuple<mdspan2_t,
int, std::span<const std::int32_t>> dofmap0,
81 fem::DofTransformKernel<T>
auto P0,
82 std::tuple<mdspan2_t,
int, std::span<const std::int32_t>> dofmap1,
83 fem::DofTransformKernel<T>
auto P1T, std::span<const T> constants,
84 std::span<const T> coeffs,
int cstride,
85 std::span<const std::uint32_t> cell_info0,
86 std::span<const std::uint32_t> cell_info1, std::span<const T> bc_values1,
87 std::span<const std::int8_t> bc_markers1, std::span<const T> x0, T alpha)
92 const auto [dmap0, bs0, cells0] = dofmap0;
93 const auto [dmap1, bs1, cells1] = dofmap1;
94 assert(_bs0 < 0 or _bs0 == bs0);
95 assert(_bs1 < 0 or _bs1 == bs1);
98 std::vector<scalar_value_type_t<T>> coordinate_dofs(3 * x_dofmap.extent(1));
99 std::vector<T> Ae, be;
100 assert(cells0.size() ==
cells.size());
101 assert(cells1.size() ==
cells.size());
102 for (std::size_t index = 0; index <
cells.size(); ++index)
106 std::int32_t c =
cells[index];
107 std::int32_t c0 = cells0[index];
108 std::int32_t c1 = cells1[index];
111 auto dofs1 = MDSPAN_IMPL_STANDARD_NAMESPACE::submdspan(
112 dmap1, c1, MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent);
116 for (std::size_t j = 0; j < dofs1.size(); ++j)
118 if constexpr (_bs1 > 0)
120 for (
int k = 0; k < _bs1; ++k)
122 assert(_bs1 * dofs1[j] + k < (
int)bc_markers1.size());
123 if (bc_markers1[_bs1 * dofs1[j] + k])
132 for (
int k = 0; k < bs1; ++k)
134 assert(bs1 * dofs1[j] + k < (
int)bc_markers1.size());
135 if (bc_markers1[bs1 * dofs1[j] + k])
148 auto x_dofs = MDSPAN_IMPL_STANDARD_NAMESPACE::submdspan(
149 x_dofmap, c, MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent);
150 for (std::size_t i = 0; i < x_dofs.size(); ++i)
152 std::copy_n(std::next(x.begin(), 3 * x_dofs[i]), 3,
153 std::next(coordinate_dofs.begin(), 3 * i));
157 auto dofs0 = MDSPAN_IMPL_STANDARD_NAMESPACE::submdspan(
158 dmap0, c0, MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent);
160 const int num_rows = bs0 * dofs0.size();
161 const int num_cols = bs1 * dofs1.size();
163 const T* coeff_array = coeffs.data() + index * cstride;
164 Ae.resize(num_rows * num_cols);
165 std::ranges::fill(Ae, 0);
166 kernel(Ae.data(), coeff_array, constants.data(), coordinate_dofs.data(),
168 P0(Ae, cell_info0, c0, num_cols);
169 P1T(Ae, cell_info1, c1, num_rows);
173 std::ranges::fill(be, 0);
174 for (std::size_t j = 0; j < dofs1.size(); ++j)
176 if constexpr (_bs1 > 0)
178 for (
int k = 0; k < _bs1; ++k)
180 const std::int32_t jj = _bs1 * dofs1[j] + k;
181 assert(jj < (
int)bc_markers1.size());
184 const T bc = bc_values1[jj];
185 const T _x0 = x0.empty() ? 0 : x0[jj];
188 for (
int m = 0; m < num_rows; ++m)
189 be[m] -= Ae[m * num_cols + _bs1 * j + k] * alpha * (bc - _x0);
195 for (
int k = 0; k < bs1; ++k)
197 const std::int32_t jj = bs1 * dofs1[j] + k;
198 assert(jj < (
int)bc_markers1.size());
201 const T bc = bc_values1[jj];
202 const T _x0 = x0.empty() ? 0 : x0[jj];
204 for (
int m = 0; m < num_rows; ++m)
205 be[m] -= Ae[m * num_cols + bs1 * j + k] * alpha * (bc - _x0);
211 for (std::size_t i = 0; i < dofs0.size(); ++i)
213 if constexpr (_bs0 > 0)
215 for (
int k = 0; k < _bs0; ++k)
216 b[_bs0 * dofs0[i] + k] += be[_bs0 * i + k];
220 for (
int k = 0; k < bs0; ++k)
221 b[bs0 * dofs0[i] + k] += be[bs0 * i + k];
263void _lift_bc_exterior_facets(
264 std::span<T> b, mdspan2_t x_dofmap,
265 std::span<
const scalar_value_type_t<T>> x,
int num_facets_per_cell,
266 FEkernel<T>
auto kernel, std::span<const std::int32_t> facets,
267 std::tuple<mdspan2_t,
int, std::span<const std::int32_t>> dofmap0,
268 fem::DofTransformKernel<T>
auto P0,
269 std::tuple<mdspan2_t,
int, std::span<const std::int32_t>> dofmap1,
270 fem::DofTransformKernel<T>
auto P1T, std::span<const T> constants,
271 std::span<const T> coeffs,
int cstride,
272 std::span<const std::uint32_t> cell_info0,
273 std::span<const std::uint32_t> cell_info1, std::span<const T> bc_values1,
274 std::span<const std::int8_t> bc_markers1, std::span<const T> x0, T alpha,
275 std::span<const std::uint8_t> perms)
280 const auto [dmap0, bs0, facets0] = dofmap0;
281 const auto [dmap1, bs1, facets1] = dofmap1;
284 std::vector<scalar_value_type_t<T>> coordinate_dofs(3 * x_dofmap.extent(1));
285 std::vector<T> Ae, be;
286 assert(facets.size() % 2 == 0);
287 assert(facets0.size() == facets.size());
288 assert(facets1.size() == facets.size());
289 for (std::size_t index = 0; index < facets.size(); index += 2)
292 std::int32_t
cell = facets[index];
294 std::int32_t cell0 = facets0[index];
296 std::int32_t cell1 = facets1[index];
299 std::int32_t local_facet = facets[index + 1];
302 auto dofs1 = MDSPAN_IMPL_STANDARD_NAMESPACE::submdspan(
303 dmap1, cell1, MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent);
307 for (std::size_t j = 0; j < dofs1.size(); ++j)
309 for (
int k = 0; k < bs1; ++k)
311 if (bc_markers1[bs1 * dofs1[j] + k])
323 auto x_dofs = MDSPAN_IMPL_STANDARD_NAMESPACE::submdspan(
324 x_dofmap,
cell, MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent);
325 for (std::size_t i = 0; i < x_dofs.size(); ++i)
327 std::copy_n(std::next(x.begin(), 3 * x_dofs[i]), 3,
328 std::next(coordinate_dofs.begin(), 3 * i));
332 auto dofs0 = MDSPAN_IMPL_STANDARD_NAMESPACE::submdspan(
333 dmap0, cell0, MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent);
335 const int num_rows = bs0 * dofs0.size();
336 const int num_cols = bs1 * dofs1.size();
340 = perms.empty() ? 0 : perms[
cell * num_facets_per_cell + local_facet];
342 const T* coeff_array = coeffs.data() + index / 2 * cstride;
343 Ae.resize(num_rows * num_cols);
344 std::ranges::fill(Ae, 0);
345 kernel(Ae.data(), coeff_array, constants.data(), coordinate_dofs.data(),
346 &local_facet, &perm);
347 P0(Ae, cell_info0, cell0, num_cols);
348 P1T(Ae, cell_info1, cell1, num_rows);
352 std::ranges::fill(be, 0);
353 for (std::size_t j = 0; j < dofs1.size(); ++j)
355 for (
int k = 0; k < bs1; ++k)
357 const std::int32_t jj = bs1 * dofs1[j] + k;
360 const T bc = bc_values1[jj];
361 const T _x0 = x0.empty() ? 0 : x0[jj];
363 for (
int m = 0; m < num_rows; ++m)
364 be[m] -= Ae[m * num_cols + bs1 * j + k] * alpha * (bc - _x0);
369 for (std::size_t i = 0; i < dofs0.size(); ++i)
370 for (
int k = 0; k < bs0; ++k)
371 b[bs0 * dofs0[i] + k] += be[bs0 * i + k];
412void _lift_bc_interior_facets(
413 std::span<T> b, mdspan2_t x_dofmap,
414 std::span<
const scalar_value_type_t<T>> x,
int num_facets_per_cell,
415 FEkernel<T>
auto kernel, std::span<const std::int32_t> facets,
416 std::tuple<mdspan2_t,
int, std::span<const std::int32_t>> dofmap0,
417 fem::DofTransformKernel<T>
auto P0,
418 std::tuple<mdspan2_t,
int, std::span<const std::int32_t>> dofmap1,
419 fem::DofTransformKernel<T>
auto P1T, std::span<const T> constants,
420 std::span<const T> coeffs,
int cstride,
421 std::span<const std::uint32_t> cell_info0,
422 std::span<const std::uint32_t> cell_info1,
423 std::span<const std::uint8_t> perms, std::span<const T> bc_values1,
424 std::span<const std::int8_t> bc_markers1, std::span<const T> x0, T alpha)
429 const auto [dmap0, bs0, facets0] = dofmap0;
430 const auto [dmap1, bs1, facets1] = dofmap1;
433 using X = scalar_value_type_t<T>;
434 std::vector<X> coordinate_dofs(2 * x_dofmap.extent(1) * 3);
435 std::span<X> cdofs0(coordinate_dofs.data(), x_dofmap.extent(1) * 3);
436 std::span<X> cdofs1(coordinate_dofs.data() + x_dofmap.extent(1) * 3,
437 x_dofmap.extent(1) * 3);
438 std::vector<T> Ae, be;
441 std::vector<std::int32_t> dmapjoint0, dmapjoint1;
442 assert(facets.size() % 4 == 0);
444 const int num_dofs0 = dmap0.extent(1);
445 const int num_dofs1 = dmap1.extent(1);
446 assert(facets0.size() == facets.size());
447 assert(facets1.size() == facets.size());
448 for (std::size_t index = 0; index < facets.size(); index += 4)
452 std::array
cells{facets[index], facets[index + 2]};
453 std::array cells0{facets0[index], facets0[index + 2]};
454 std::array cells1{facets1[index], facets1[index + 2]};
457 std::array<std::int32_t, 2> local_facet
458 = {facets[index + 1], facets[index + 3]};
461 auto x_dofs0 = MDSPAN_IMPL_STANDARD_NAMESPACE::submdspan(
462 x_dofmap, cells[0], MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent);
463 for (std::size_t i = 0; i < x_dofs0.size(); ++i)
465 std::copy_n(std::next(x.begin(), 3 * x_dofs0[i]), 3,
466 std::next(cdofs0.begin(), 3 * i));
468 auto x_dofs1 = MDSPAN_IMPL_STANDARD_NAMESPACE::submdspan(
469 x_dofmap, cells[1], MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent);
470 for (std::size_t i = 0; i < x_dofs1.size(); ++i)
472 std::copy_n(std::next(x.begin(), 3 * x_dofs1[i]), 3,
473 std::next(cdofs1.begin(), 3 * i));
478 = std::span(dmap0.data_handle() + cells0[0] * num_dofs0, num_dofs0);
480 = std::span(dmap0.data_handle() + cells0[1] * num_dofs0, num_dofs0);
482 dmapjoint0.resize(dmap0_cell0.size() + dmap0_cell1.size());
483 std::ranges::copy(dmap0_cell0, dmapjoint0.begin());
484 std::ranges::copy(dmap0_cell1,
485 std::next(dmapjoint0.begin(), dmap0_cell0.size()));
488 = std::span(dmap1.data_handle() + cells1[0] * num_dofs1, num_dofs1);
490 = std::span(dmap1.data_handle() + cells1[1] * num_dofs1, num_dofs1);
492 dmapjoint1.resize(dmap1_cell0.size() + dmap1_cell1.size());
493 std::ranges::copy(dmap1_cell0, dmapjoint1.begin());
494 std::ranges::copy(dmap1_cell1,
495 std::next(dmapjoint1.begin(), dmap1_cell0.size()));
499 for (std::size_t j = 0; j < dmap1_cell0.size(); ++j)
501 for (
int k = 0; k < bs1; ++k)
503 if (bc_markers1[bs1 * dmap1_cell0[j] + k])
512 for (std::size_t j = 0; j < dmap1_cell1.size(); ++j)
514 for (
int k = 0; k < bs1; ++k)
516 if (bc_markers1[bs1 * dmap1_cell1[j] + k])
527 const int num_rows = bs0 * dmapjoint0.size();
528 const int num_cols = bs1 * dmapjoint1.size();
531 Ae.resize(num_rows * num_cols);
532 std::ranges::fill(Ae, 0);
535 ? std::array<std::uint8_t, 2>{0, 0}
537 perms[
cells[0] * num_facets_per_cell + local_facet[0]],
538 perms[
cells[1] * num_facets_per_cell + local_facet[1]]};
539 kernel(Ae.data(), coeffs.data() + index / 2 * cstride, constants.data(),
540 coordinate_dofs.data(), local_facet.data(), perm.data());
542 std::span<T> _Ae(Ae);
543 std::span<T> sub_Ae0 = _Ae.subspan(bs0 * dmap0_cell0.size() * num_cols,
544 bs0 * dmap0_cell1.size() * num_cols);
546 P0(_Ae, cell_info0, cells0[0], num_cols);
547 P0(sub_Ae0, cell_info0, cells0[1], num_cols);
548 P1T(_Ae, cell_info1, cells1[0], num_rows);
550 for (
int row = 0; row < num_rows; ++row)
554 std::span<T> sub_Ae1 = _Ae.subspan(
555 row * num_cols + bs1 * dmap1_cell0.size(), bs1 * dmap1_cell1.size());
556 P1T(sub_Ae1, cell_info1, cells1[1], 1);
560 std::ranges::fill(be, 0);
563 for (std::size_t j = 0; j < dmap1_cell0.size(); ++j)
565 for (
int k = 0; k < bs1; ++k)
567 const std::int32_t jj = bs1 * dmap1_cell0[j] + k;
570 const T bc = bc_values1[jj];
571 const T _x0 = x0.empty() ? 0 : x0[jj];
573 for (
int m = 0; m < num_rows; ++m)
574 be[m] -= Ae[m * num_cols + bs1 * j + k] * alpha * (bc - _x0);
580 const int offset = bs1 * dmap1_cell0.size();
581 for (std::size_t j = 0; j < dmap1_cell1.size(); ++j)
583 for (
int k = 0; k < bs1; ++k)
585 const std::int32_t jj = bs1 * dmap1_cell1[j] + k;
588 const T bc = bc_values1[jj];
589 const T _x0 = x0.empty() ? 0 : x0[jj];
591 for (
int m = 0; m < num_rows; ++m)
594 -= Ae[m * num_cols + offset + bs1 * j + k] * alpha * (bc - _x0);
600 for (std::size_t i = 0; i < dmap0_cell0.size(); ++i)
601 for (
int k = 0; k < bs0; ++k)
602 b[bs0 * dmap0_cell0[i] + k] += be[bs0 * i + k];
604 const int offset_be = bs0 * dmap0_cell0.size();
605 for (std::size_t i = 0; i < dmap0_cell1.size(); ++i)
606 for (
int k = 0; k < bs0; ++k)
607 b[bs0 * dmap0_cell1[i] + k] += be[offset_be + bs0 * i + k];
635 fem::DofTransformKernel<T>
auto P0, std::span<T> b, mdspan2_t x_dofmap,
636 std::span<
const scalar_value_type_t<T>> x,
637 std::span<const std::int32_t> cells,
638 std::tuple<mdspan2_t,
int, std::span<const std::int32_t>> dofmap,
639 FEkernel<T>
auto kernel, std::span<const T> constants,
640 std::span<const T> coeffs,
int cstride,
641 std::span<const std::uint32_t> cell_info0)
646 const auto [dmap, bs, cells0] = dofmap;
647 assert(_bs < 0 or _bs == bs);
650 std::vector<scalar_value_type_t<T>> coordinate_dofs(3 * x_dofmap.extent(1));
651 std::vector<T> be(bs * dmap.extent(1));
652 std::span<T> _be(be);
655 for (std::size_t index = 0; index <
cells.size(); ++index)
658 std::int32_t c =
cells[index];
659 std::int32_t c0 = cells0[index];
662 auto x_dofs = MDSPAN_IMPL_STANDARD_NAMESPACE::submdspan(
663 x_dofmap, c, MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent);
664 for (std::size_t i = 0; i < x_dofs.size(); ++i)
666 std::copy_n(std::next(x.begin(), 3 * x_dofs[i]), 3,
667 std::next(coordinate_dofs.begin(), 3 * i));
671 std::ranges::fill(be, 0);
672 kernel(be.data(), coeffs.data() + index * cstride, constants.data(),
673 coordinate_dofs.data(),
nullptr,
nullptr);
674 P0(_be, cell_info0, c0, 1);
677 auto dofs = MDSPAN_IMPL_STANDARD_NAMESPACE::submdspan(
678 dmap, c0, MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent);
679 if constexpr (_bs > 0)
681 for (std::size_t i = 0; i < dofs.size(); ++i)
682 for (
int k = 0; k < _bs; ++k)
683 b[_bs * dofs[i] + k] += be[_bs * i + k];
687 for (std::size_t i = 0; i < dofs.size(); ++i)
688 for (
int k = 0; k < bs; ++k)
689 b[bs * dofs[i] + k] += be[bs * i + k];
720void assemble_exterior_facets(
721 fem::DofTransformKernel<T>
auto P0, std::span<T> b, mdspan2_t x_dofmap,
722 std::span<
const scalar_value_type_t<T>> x,
int num_facets_per_cell,
723 std::span<const std::int32_t> facets,
724 std::tuple<mdspan2_t,
int, std::span<const std::int32_t>> dofmap,
725 FEkernel<T>
auto fn, std::span<const T> constants,
726 std::span<const T> coeffs,
int cstride,
727 std::span<const std::uint32_t> cell_info0,
728 std::span<const std::uint8_t> perms)
733 const auto [dmap, bs, facets0] = dofmap;
734 assert(_bs < 0 or _bs == bs);
738 const int num_dofs = dmap.extent(1);
739 std::vector<scalar_value_type_t<T>> coordinate_dofs(3 * x_dofmap.extent(1));
740 std::vector<T> be(bs * num_dofs);
741 std::span<T> _be(be);
742 assert(facets.size() % 2 == 0);
743 assert(facets0.size() == facets.size());
744 for (std::size_t index = 0; index < facets.size(); index += 2)
748 std::int32_t
cell = facets[index];
749 std::int32_t local_facet = facets[index + 1];
750 std::int32_t cell0 = facets0[index];
753 auto x_dofs = MDSPAN_IMPL_STANDARD_NAMESPACE::submdspan(
754 x_dofmap,
cell, MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent);
755 for (std::size_t i = 0; i < x_dofs.size(); ++i)
757 std::copy_n(std::next(x.begin(), 3 * x_dofs[i]), 3,
758 std::next(coordinate_dofs.begin(), 3 * i));
763 = perms.empty() ? 0 : perms[
cell * num_facets_per_cell + local_facet];
766 std::ranges::fill(be, 0);
767 fn(be.data(), coeffs.data() + index / 2 * cstride, constants.data(),
768 coordinate_dofs.data(), &local_facet, &perm);
770 P0(_be, cell_info0, cell0, 1);
773 auto dofs = MDSPAN_IMPL_STANDARD_NAMESPACE::submdspan(
774 dmap, cell0, MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent);
775 if constexpr (_bs > 0)
777 for (std::size_t i = 0; i < dofs.size(); ++i)
778 for (
int k = 0; k < _bs; ++k)
779 b[_bs * dofs[i] + k] += be[_bs * i + k];
783 for (std::size_t i = 0; i < dofs.size(); ++i)
784 for (
int k = 0; k < bs; ++k)
785 b[bs * dofs[i] + k] += be[bs * i + k];
816void assemble_interior_facets(
817 fem::DofTransformKernel<T>
auto P0, std::span<T> b, mdspan2_t x_dofmap,
818 std::span<
const scalar_value_type_t<T>> x,
int num_facets_per_cell,
819 std::span<const std::int32_t> facets,
820 std::tuple<
const DofMap&,
int, std::span<const std::int32_t>> dofmap,
821 FEkernel<T>
auto fn, std::span<const T> constants,
822 std::span<const T> coeffs,
int cstride,
823 std::span<const std::uint32_t> cell_info0,
824 std::span<const std::uint8_t> perms)
829 const auto [dmap, bs, facets0] = dofmap;
830 assert(_bs < 0 or _bs == bs);
833 using X = scalar_value_type_t<T>;
834 std::vector<X> coordinate_dofs(2 * x_dofmap.extent(1) * 3);
835 std::span<X> cdofs0(coordinate_dofs.data(), x_dofmap.extent(1) * 3);
836 std::span<X> cdofs1(coordinate_dofs.data() + x_dofmap.extent(1) * 3,
837 x_dofmap.extent(1) * 3);
840 assert(facets.size() % 4 == 0);
841 assert(facets0.size() == facets.size());
842 for (std::size_t index = 0; index < facets.size(); index += 4)
845 std::array<std::int32_t, 2>
cells{facets[index], facets[index + 2]};
846 std::array<std::int32_t, 2> cells0{facets0[index], facets0[index + 2]};
849 std::array<std::int32_t, 2> local_facet{facets[index + 1],
853 auto x_dofs0 = MDSPAN_IMPL_STANDARD_NAMESPACE::submdspan(
854 x_dofmap, cells[0], MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent);
855 for (std::size_t i = 0; i < x_dofs0.size(); ++i)
857 std::copy_n(std::next(x.begin(), 3 * x_dofs0[i]), 3,
858 std::next(cdofs0.begin(), 3 * i));
860 auto x_dofs1 = MDSPAN_IMPL_STANDARD_NAMESPACE::submdspan(
861 x_dofmap, cells[1], MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent);
862 for (std::size_t i = 0; i < x_dofs1.size(); ++i)
864 std::copy_n(std::next(x.begin(), 3 * x_dofs1[i]), 3,
865 std::next(cdofs1.begin(), 3 * i));
869 std::span<const std::int32_t> dmap0 = dmap.cell_dofs(cells0[0]);
870 std::span<const std::int32_t> dmap1 = dmap.cell_dofs(cells0[1]);
873 be.resize(bs * (dmap0.size() + dmap1.size()));
874 std::ranges::fill(be, 0);
877 ? std::array<std::uint8_t, 2>{0, 0}
879 perms[
cells[0] * num_facets_per_cell + local_facet[0]],
880 perms[
cells[1] * num_facets_per_cell + local_facet[1]]};
881 fn(be.data(), coeffs.data() + index / 2 * cstride, constants.data(),
882 coordinate_dofs.data(), local_facet.data(), perm.data());
884 std::span<T> _be(be);
885 std::span<T> sub_be = _be.subspan(bs * dmap0.size(), bs * dmap1.size());
887 P0(be, cell_info0, cells0[0], 1);
888 P0(sub_be, cell_info0, cells0[1], 1);
891 if constexpr (_bs > 0)
893 for (std::size_t i = 0; i < dmap0.size(); ++i)
894 for (
int k = 0; k < _bs; ++k)
895 b[_bs * dmap0[i] + k] += be[_bs * i + k];
896 for (std::size_t i = 0; i < dmap1.size(); ++i)
897 for (
int k = 0; k < _bs; ++k)
898 b[_bs * dmap1[i] + k] += be[_bs * (i + dmap0.size()) + k];
902 for (std::size_t i = 0; i < dmap0.size(); ++i)
903 for (
int k = 0; k < bs; ++k)
904 b[bs * dmap0[i] + k] += be[bs * i + k];
905 for (std::size_t i = 0; i < dmap1.size(); ++i)
906 for (
int k = 0; k < bs; ++k)
907 b[bs * dmap1[i] + k] += be[bs * (i + dmap0.size()) + k];
928template <dolfinx::scalar T, std::
floating_po
int U>
929void lift_bc(std::span<T> b,
const Form<T, U>& a, mdspan2_t x_dofmap,
930 std::span<
const scalar_value_type_t<T>> x,
931 std::span<const T> constants,
932 const std::map<std::pair<IntegralType, int>,
933 std::pair<std::span<const T>,
int>>& coefficients,
934 std::span<const T> bc_values1,
935 std::span<const std::int8_t> bc_markers1, std::span<const T> x0,
939 std::shared_ptr<const mesh::Mesh<U>> mesh = a.mesh();
942 auto mesh0 = a.function_spaces().at(0)->mesh();
945 auto mesh1 = a.function_spaces().at(1)->mesh();
949 assert(a.function_spaces().at(0));
950 assert(a.function_spaces().at(1));
951 auto dofmap0 = a.function_spaces()[0]->dofmap()->map();
952 const int bs0 = a.function_spaces()[0]->dofmap()->bs();
953 auto element0 = a.function_spaces()[0]->element();
954 auto dofmap1 = a.function_spaces()[1]->dofmap()->map();
955 const int bs1 = a.function_spaces()[1]->dofmap()->bs();
956 auto element1 = a.function_spaces()[1]->element();
959 std::span<const std::uint32_t> cell_info0;
960 std::span<const std::uint32_t> cell_info1;
962 if (element0->needs_dof_transformations()
963 or element1->needs_dof_transformations() or a.needs_facet_permutations())
965 mesh0->topology_mutable()->create_entity_permutations();
966 mesh1->topology_mutable()->create_entity_permutations();
967 cell_info0 = std::span(mesh0->topology()->get_cell_permutation_info());
968 cell_info1 = std::span(mesh1->topology()->get_cell_permutation_info());
971 fem::DofTransformKernel<T>
auto P0
973 fem::DofTransformKernel<T>
auto P1T
974 = element1->template dof_transformation_right_fn<T>(
983 if (bs0 == 1 and bs1 == 1)
985 _lift_bc_cells<T, 1, 1>(
986 b, x_dofmap, x, kernel, cells,
989 constants, coeffs, cstride, cell_info0, cell_info1, bc_values1,
990 bc_markers1, x0, alpha);
992 else if (bs0 == 3 and bs1 == 3)
994 _lift_bc_cells<T, 3, 3>(
995 b, x_dofmap, x, kernel, cells,
998 constants, coeffs, cstride, cell_info0, cell_info1, bc_values1,
999 bc_markers1, x0, alpha);
1003 _lift_bc_cells(b, x_dofmap, x, kernel, cells,
1007 P1T, constants, coeffs, cstride, cell_info0, cell_info1,
1008 bc_values1, bc_markers1, x0, alpha);
1012 std::span<const std::uint8_t> perms;
1013 if (a.needs_facet_permutations())
1015 mesh->topology_mutable()->create_entity_permutations();
1016 perms = std::span(mesh->topology()->get_facet_permutations());
1020 int num_facets_per_cell
1026 auto& [coeffs, cstride]
1028 _lift_bc_exterior_facets(
1029 b, x_dofmap, x, num_facets_per_cell, kernel,
1031 {dofmap0, bs0, a.domain(IntegralType::exterior_facet, i, *mesh0)}, P0,
1032 {dofmap1, bs1, a.domain(IntegralType::exterior_facet, i, *mesh1)}, P1T,
1033 constants, coeffs, cstride, cell_info0, cell_info1, bc_values1,
1034 bc_markers1, x0, alpha, perms);
1041 auto& [coeffs, cstride]
1043 _lift_bc_interior_facets(
1044 b, x_dofmap, x, num_facets_per_cell, kernel,
1046 {dofmap0, bs0, a.domain(IntegralType::interior_facet, i, *mesh0)}, P0,
1047 {dofmap1, bs1, a.domain(IntegralType::interior_facet, i, *mesh1)}, P1T,
1048 constants, coeffs, cstride, cell_info0, cell_info1, perms, bc_values1,
1049 bc_markers1, x0, alpha);
1073template <dolfinx::scalar T, std::
floating_po
int U>
1075 std::span<T> b,
const std::vector<std::shared_ptr<
const Form<T, U>>> a,
1076 const std::vector<std::span<const T>>& constants,
1077 const std::vector<std::map<std::pair<IntegralType, int>,
1078 std::pair<std::span<const T>,
int>>>& coeffs,
1079 const std::vector<std::vector<std::shared_ptr<
const DirichletBC<T, U>>>>&
1081 const std::vector<std::span<const T>>& x0, T alpha)
1083 if (!x0.empty() and x0.size() != a.size())
1085 throw std::runtime_error(
1086 "Mismatch in size between x0 and bilinear form in assembler.");
1089 if (a.size() != bcs1.size())
1091 throw std::runtime_error(
1092 "Mismatch in size between a and bcs in assembler.");
1095 for (std::size_t j = 0; j < a.size(); ++j)
1097 std::vector<std::int8_t> bc_markers1;
1098 std::vector<T> bc_values1;
1099 if (a[j] and !bcs1[j].empty())
1102 std::shared_ptr<const mesh::Mesh<U>> mesh = a[j]->mesh();
1104 throw std::runtime_error(
"Unable to extract a mesh.");
1105 mdspan2_t x_dofmap = mesh->geometry().dofmap();
1106 auto x = mesh->geometry().x();
1108 assert(a[j]->function_spaces().at(0));
1110 auto V1 = a[j]->function_spaces()[1];
1112 auto map1 = V1->dofmap()->index_map;
1113 const int bs1 = V1->dofmap()->index_map_bs();
1115 const int crange = bs1 * (map1->size_local() + map1->num_ghosts());
1116 bc_markers1.assign(crange,
false);
1117 bc_values1.assign(crange, 0);
1118 for (
const std::shared_ptr<
const DirichletBC<T, U>>& bc : bcs1[j])
1120 bc->mark_dofs(bc_markers1);
1121 bc->set(bc_values1, std::nullopt, 1);
1126 lift_bc<T>(b, *a[j], x_dofmap, x, constants[j], coeffs[j], bc_values1,
1127 bc_markers1, x0[j], alpha);
1131 lift_bc<T>(b, *a[j], x_dofmap, x, constants[j], coeffs[j], bc_values1,
1132 bc_markers1, std::span<const T>(), alpha);
1146template <dolfinx::scalar T, std::
floating_po
int U>
1147void assemble_vector(
1148 std::span<T> b,
const Form<T, U>& L, mdspan2_t x_dofmap,
1149 std::span<
const scalar_value_type_t<T>> x, std::span<const T> constants,
1150 const std::map<std::pair<IntegralType, int>,
1151 std::pair<std::span<const T>,
int>>& coefficients)
1154 std::shared_ptr<const mesh::Mesh<U>> mesh = L.mesh();
1158 auto mesh0 = L.function_spaces().at(0)->mesh();
1162 assert(L.function_spaces().at(0));
1163 auto element = L.function_spaces().at(0)->element();
1165 std::shared_ptr<const fem::DofMap> dofmap
1166 = L.function_spaces().at(0)->dofmap();
1168 auto dofs = dofmap->map();
1169 const int bs = dofmap->bs();
1171 fem::DofTransformKernel<T>
auto P0
1174 std::span<const std::uint32_t> cell_info0;
1175 if (element->needs_dof_transformations() or L.needs_facet_permutations())
1177 mesh0->topology_mutable()->create_entity_permutations();
1178 cell_info0 = std::span(mesh0->topology()->get_cell_permutation_info());
1189 impl::assemble_cells<T, 1>(
1190 P0, b, x_dofmap, x, cells,
1192 coeffs, cstride, cell_info0);
1196 impl::assemble_cells<T, 3>(
1197 P0, b, x_dofmap, x, cells,
1199 coeffs, cstride, cell_info0);
1203 impl::assemble_cells(P0, b, x_dofmap, x, cells,
1205 fn, constants, coeffs, cstride, cell_info0);
1209 std::span<const std::uint8_t> perms;
1210 if (L.needs_facet_permutations())
1212 mesh->topology_mutable()->create_entity_permutations();
1213 perms = std::span(mesh->topology()->get_facet_permutations());
1217 int num_facets_per_cell
1223 auto& [coeffs, cstride]
1225 std::span<const std::int32_t> facets
1229 impl::assemble_exterior_facets<T, 1>(
1230 P0, b, x_dofmap, x, num_facets_per_cell, facets,
1232 constants, coeffs, cstride, cell_info0, perms);
1236 impl::assemble_exterior_facets<T, 3>(
1237 P0, b, x_dofmap, x, num_facets_per_cell, facets,
1239 constants, coeffs, cstride, cell_info0, perms);
1243 impl::assemble_exterior_facets(
1244 P0, b, x_dofmap, x, num_facets_per_cell, facets,
1246 constants, coeffs, cstride, cell_info0, perms);
1254 auto& [coeffs, cstride]
1256 std::span<const std::int32_t> facets
1260 impl::assemble_interior_facets<T, 1>(
1261 P0, b, x_dofmap, x, num_facets_per_cell, facets,
1263 constants, coeffs, cstride, cell_info0, perms);
1267 impl::assemble_interior_facets<T, 3>(
1268 P0, b, x_dofmap, x, num_facets_per_cell, facets,
1270 constants, coeffs, cstride, cell_info0, perms);
1274 impl::assemble_interior_facets(
1275 P0, b, x_dofmap, x, num_facets_per_cell, facets,
1277 constants, coeffs, cstride, cell_info0, perms);
1288template <dolfinx::scalar T, std::
floating_po
int U>
1289void assemble_vector(
1290 std::span<T> b,
const Form<T, U>& L, std::span<const T> constants,
1291 const std::map<std::pair<IntegralType, int>,
1292 std::pair<std::span<const T>,
int>>& coefficients)
1294 std::shared_ptr<const mesh::Mesh<U>> mesh = L.mesh();
1296 if constexpr (std::is_same_v<U, scalar_value_type_t<T>>)
1297 assemble_vector(b, L, mesh->geometry().dofmap(), mesh->geometry().x(),
1298 constants, coefficients);
1301 auto x = mesh->geometry().x();
1302 std::vector<scalar_value_type_t<T>> _x(x.begin(), x.end());
1303 assemble_vector(b, L, mesh->geometry().dofmap(), _x, constants,
Degree-of-freedom map representations and tools.
Functions supporting finite element method operations.
void cells(la::SparsityPattern &pattern, std::array< std::span< const std::int32_t >, 2 > cells, std::array< std::reference_wrapper< const DofMap >, 2 > dofmaps)
Iterate over cells and insert entries into sparsity pattern.
Definition sparsitybuild.cpp:16
@ interior_facet
Interior facet.
@ exterior_facet
Exterior facet.
int cell_num_entities(CellType type, int dim)
Definition cell_types.cpp:139
CellType
Cell type identifier.
Definition cell_types.h:22