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
32using mdspan2_t = MDSPAN_IMPL_STANDARD_NAMESPACE::mdspan<
34 MDSPAN_IMPL_STANDARD_NAMESPACE::dextents<std::size_t, 2>>;
76 std::span<T> b, mdspan2_t x_dofmap,
77 std::span<
const scalar_value_type_t<T>> x, FEkernel<T>
auto kernel,
78 std::span<const std::int32_t> cells,
79 std::tuple<mdspan2_t,
int, std::span<const std::int32_t>> dofmap0,
80 fem::DofTransformKernel<T>
auto P0,
81 std::tuple<mdspan2_t,
int, std::span<const std::int32_t>> dofmap1,
82 fem::DofTransformKernel<T>
auto P1T, std::span<const T> constants,
83 std::span<const T> coeffs,
int cstride,
84 std::span<const std::uint32_t> cell_info0,
85 std::span<const std::uint32_t> cell_info1, std::span<const T> bc_values1,
86 std::span<const std::int8_t> bc_markers1, std::span<const T> x0, T alpha)
91 const auto [dmap0, bs0, cells0] = dofmap0;
92 const auto [dmap1, bs1, cells1] = dofmap1;
93 assert(_bs0 < 0 or _bs0 == bs0);
94 assert(_bs1 < 0 or _bs1 == bs1);
97 std::vector<scalar_value_type_t<T>> coordinate_dofs(3 * x_dofmap.extent(1));
98 std::vector<T> Ae, be;
99 assert(cells0.size() ==
cells.size());
100 assert(cells1.size() ==
cells.size());
101 for (std::size_t index = 0; index <
cells.size(); ++index)
105 std::int32_t c =
cells[index];
106 std::int32_t c0 = cells0[index];
107 std::int32_t c1 = cells1[index];
110 auto dofs1 = MDSPAN_IMPL_STANDARD_NAMESPACE::submdspan(
111 dmap1, c1, MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent);
115 for (std::size_t j = 0; j < dofs1.size(); ++j)
117 if constexpr (_bs1 > 0)
119 for (
int k = 0; k < _bs1; ++k)
121 assert(_bs1 * dofs1[j] + k < (
int)bc_markers1.size());
122 if (bc_markers1[_bs1 * dofs1[j] + k])
131 for (
int k = 0; k < bs1; ++k)
133 assert(bs1 * dofs1[j] + k < (
int)bc_markers1.size());
134 if (bc_markers1[bs1 * dofs1[j] + k])
147 auto x_dofs = MDSPAN_IMPL_STANDARD_NAMESPACE::submdspan(
148 x_dofmap, c, MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent);
149 for (std::size_t i = 0; i < x_dofs.size(); ++i)
151 std::copy_n(std::next(x.begin(), 3 * x_dofs[i]), 3,
152 std::next(coordinate_dofs.begin(), 3 * i));
156 auto dofs0 = MDSPAN_IMPL_STANDARD_NAMESPACE::submdspan(
157 dmap0, c0, MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent);
159 const int num_rows = bs0 * dofs0.size();
160 const int num_cols = bs1 * dofs1.size();
162 const T* coeff_array = coeffs.data() + index * cstride;
163 Ae.resize(num_rows * num_cols);
164 std::ranges::fill(Ae, 0);
165 kernel(Ae.data(), coeff_array, constants.data(), coordinate_dofs.data(),
167 P0(Ae, cell_info0, c0, num_cols);
168 P1T(Ae, cell_info1, c1, num_rows);
172 std::ranges::fill(be, 0);
173 for (std::size_t j = 0; j < dofs1.size(); ++j)
175 if constexpr (_bs1 > 0)
177 for (
int k = 0; k < _bs1; ++k)
179 const std::int32_t jj = _bs1 * dofs1[j] + k;
180 assert(jj < (
int)bc_markers1.size());
183 const T bc = bc_values1[jj];
184 const T _x0 = x0.empty() ? 0 : x0[jj];
187 for (
int m = 0; m < num_rows; ++m)
188 be[m] -= Ae[m * num_cols + _bs1 * j + k] * alpha * (bc - _x0);
194 for (
int k = 0; k < bs1; ++k)
196 const std::int32_t jj = bs1 * dofs1[j] + k;
197 assert(jj < (
int)bc_markers1.size());
200 const T bc = bc_values1[jj];
201 const T _x0 = x0.empty() ? 0 : x0[jj];
203 for (
int m = 0; m < num_rows; ++m)
204 be[m] -= Ae[m * num_cols + bs1 * j + k] * alpha * (bc - _x0);
210 for (std::size_t i = 0; i < dofs0.size(); ++i)
212 if constexpr (_bs0 > 0)
214 for (
int k = 0; k < _bs0; ++k)
215 b[_bs0 * dofs0[i] + k] += be[_bs0 * i + k];
219 for (
int k = 0; k < bs0; ++k)
220 b[bs0 * dofs0[i] + k] += be[bs0 * i + k];
262void _lift_bc_exterior_facets(
263 std::span<T> b, mdspan2_t x_dofmap,
264 std::span<
const scalar_value_type_t<T>> x,
int num_facets_per_cell,
265 FEkernel<T>
auto kernel, std::span<const std::int32_t> facets,
266 std::tuple<mdspan2_t,
int, std::span<const std::int32_t>> dofmap0,
267 fem::DofTransformKernel<T>
auto P0,
268 std::tuple<mdspan2_t,
int, std::span<const std::int32_t>> dofmap1,
269 fem::DofTransformKernel<T>
auto P1T, std::span<const T> constants,
270 std::span<const T> coeffs,
int cstride,
271 std::span<const std::uint32_t> cell_info0,
272 std::span<const std::uint32_t> cell_info1, std::span<const T> bc_values1,
273 std::span<const std::int8_t> bc_markers1, std::span<const T> x0, T alpha,
274 std::span<const std::uint8_t> perms)
279 const auto [dmap0, bs0, facets0] = dofmap0;
280 const auto [dmap1, bs1, facets1] = dofmap1;
283 std::vector<scalar_value_type_t<T>> coordinate_dofs(3 * x_dofmap.extent(1));
284 std::vector<T> Ae, be;
285 assert(facets.size() % 2 == 0);
286 assert(facets0.size() == facets.size());
287 assert(facets1.size() == facets.size());
288 for (std::size_t index = 0; index < facets.size(); index += 2)
291 std::int32_t
cell = facets[index];
293 std::int32_t cell0 = facets0[index];
295 std::int32_t cell1 = facets1[index];
298 std::int32_t local_facet = facets[index + 1];
301 auto dofs1 = MDSPAN_IMPL_STANDARD_NAMESPACE::submdspan(
302 dmap1, cell1, MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent);
306 for (std::size_t j = 0; j < dofs1.size(); ++j)
308 for (
int k = 0; k < bs1; ++k)
310 if (bc_markers1[bs1 * dofs1[j] + k])
322 auto x_dofs = MDSPAN_IMPL_STANDARD_NAMESPACE::submdspan(
323 x_dofmap,
cell, MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent);
324 for (std::size_t i = 0; i < x_dofs.size(); ++i)
326 std::copy_n(std::next(x.begin(), 3 * x_dofs[i]), 3,
327 std::next(coordinate_dofs.begin(), 3 * i));
331 auto dofs0 = MDSPAN_IMPL_STANDARD_NAMESPACE::submdspan(
332 dmap0, cell0, MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent);
334 const int num_rows = bs0 * dofs0.size();
335 const int num_cols = bs1 * dofs1.size();
339 = perms.empty() ? 0 : perms[
cell * num_facets_per_cell + local_facet];
341 const T* coeff_array = coeffs.data() + index / 2 * cstride;
342 Ae.resize(num_rows * num_cols);
343 std::ranges::fill(Ae, 0);
344 kernel(Ae.data(), coeff_array, constants.data(), coordinate_dofs.data(),
345 &local_facet, &perm);
346 P0(Ae, cell_info0, cell0, num_cols);
347 P1T(Ae, cell_info1, cell1, num_rows);
351 std::ranges::fill(be, 0);
352 for (std::size_t j = 0; j < dofs1.size(); ++j)
354 for (
int k = 0; k < bs1; ++k)
356 const std::int32_t jj = bs1 * dofs1[j] + k;
359 const T bc = bc_values1[jj];
360 const T _x0 = x0.empty() ? 0 : x0[jj];
362 for (
int m = 0; m < num_rows; ++m)
363 be[m] -= Ae[m * num_cols + bs1 * j + k] * alpha * (bc - _x0);
368 for (std::size_t i = 0; i < dofs0.size(); ++i)
369 for (
int k = 0; k < bs0; ++k)
370 b[bs0 * dofs0[i] + k] += be[bs0 * i + k];
411void _lift_bc_interior_facets(
412 std::span<T> b, mdspan2_t x_dofmap,
413 std::span<
const scalar_value_type_t<T>> x,
int num_facets_per_cell,
414 FEkernel<T>
auto kernel, std::span<const std::int32_t> facets,
415 std::tuple<mdspan2_t,
int, std::span<const std::int32_t>> dofmap0,
416 fem::DofTransformKernel<T>
auto P0,
417 std::tuple<mdspan2_t,
int, std::span<const std::int32_t>> dofmap1,
418 fem::DofTransformKernel<T>
auto P1T, std::span<const T> constants,
419 std::span<const T> coeffs,
int cstride,
420 std::span<const std::uint32_t> cell_info0,
421 std::span<const std::uint32_t> cell_info1,
422 std::span<const std::uint8_t> perms, std::span<const T> bc_values1,
423 std::span<const std::int8_t> bc_markers1, std::span<const T> x0, T alpha)
428 const auto [dmap0, bs0, facets0] = dofmap0;
429 const auto [dmap1, bs1, facets1] = dofmap1;
432 using X = scalar_value_type_t<T>;
433 std::vector<X> coordinate_dofs(2 * x_dofmap.extent(1) * 3);
434 std::span<X> cdofs0(coordinate_dofs.data(), x_dofmap.extent(1) * 3);
435 std::span<X> cdofs1(coordinate_dofs.data() + x_dofmap.extent(1) * 3,
436 x_dofmap.extent(1) * 3);
437 std::vector<T> Ae, be;
440 std::vector<std::int32_t> dmapjoint0, dmapjoint1;
441 assert(facets.size() % 4 == 0);
443 const int num_dofs0 = dmap0.extent(1);
444 const int num_dofs1 = dmap1.extent(1);
445 assert(facets0.size() == facets.size());
446 assert(facets1.size() == facets.size());
447 for (std::size_t index = 0; index < facets.size(); index += 4)
451 std::array
cells{facets[index], facets[index + 2]};
452 std::array cells0{facets0[index], facets0[index + 2]};
453 std::array cells1{facets1[index], facets1[index + 2]};
456 std::array<std::int32_t, 2> local_facet
457 = {facets[index + 1], facets[index + 3]};
460 auto x_dofs0 = MDSPAN_IMPL_STANDARD_NAMESPACE::submdspan(
461 x_dofmap, cells[0], MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent);
462 for (std::size_t i = 0; i < x_dofs0.size(); ++i)
464 std::copy_n(std::next(x.begin(), 3 * x_dofs0[i]), 3,
465 std::next(cdofs0.begin(), 3 * i));
467 auto x_dofs1 = MDSPAN_IMPL_STANDARD_NAMESPACE::submdspan(
468 x_dofmap, cells[1], MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent);
469 for (std::size_t i = 0; i < x_dofs1.size(); ++i)
471 std::copy_n(std::next(x.begin(), 3 * x_dofs1[i]), 3,
472 std::next(cdofs1.begin(), 3 * i));
477 = std::span(dmap0.data_handle() + cells0[0] * num_dofs0, num_dofs0);
479 = std::span(dmap0.data_handle() + cells0[1] * num_dofs0, num_dofs0);
481 dmapjoint0.resize(dmap0_cell0.size() + dmap0_cell1.size());
482 std::ranges::copy(dmap0_cell0, dmapjoint0.begin());
483 std::ranges::copy(dmap0_cell1,
484 std::next(dmapjoint0.begin(), dmap0_cell0.size()));
487 = std::span(dmap1.data_handle() + cells1[0] * num_dofs1, num_dofs1);
489 = std::span(dmap1.data_handle() + cells1[1] * num_dofs1, num_dofs1);
491 dmapjoint1.resize(dmap1_cell0.size() + dmap1_cell1.size());
492 std::ranges::copy(dmap1_cell0, dmapjoint1.begin());
493 std::ranges::copy(dmap1_cell1,
494 std::next(dmapjoint1.begin(), dmap1_cell0.size()));
498 for (std::size_t j = 0; j < dmap1_cell0.size(); ++j)
500 for (
int k = 0; k < bs1; ++k)
502 if (bc_markers1[bs1 * dmap1_cell0[j] + k])
511 for (std::size_t j = 0; j < dmap1_cell1.size(); ++j)
513 for (
int k = 0; k < bs1; ++k)
515 if (bc_markers1[bs1 * dmap1_cell1[j] + k])
526 const int num_rows = bs0 * dmapjoint0.size();
527 const int num_cols = bs1 * dmapjoint1.size();
530 Ae.resize(num_rows * num_cols);
531 std::ranges::fill(Ae, 0);
534 ? std::array<std::uint8_t, 2>{0, 0}
536 perms[
cells[0] * num_facets_per_cell + local_facet[0]],
537 perms[
cells[1] * num_facets_per_cell + local_facet[1]]};
538 kernel(Ae.data(), coeffs.data() + index / 2 * cstride, constants.data(),
539 coordinate_dofs.data(), local_facet.data(), perm.data());
541 std::span<T> _Ae(Ae);
542 std::span<T> sub_Ae0 = _Ae.subspan(bs0 * dmap0_cell0.size() * num_cols,
543 bs0 * dmap0_cell1.size() * num_cols);
545 P0(_Ae, cell_info0, cells0[0], num_cols);
546 P0(sub_Ae0, cell_info0, cells0[1], num_cols);
547 P1T(_Ae, cell_info1, cells1[0], num_rows);
549 for (
int row = 0; row < num_rows; ++row)
553 std::span<T> sub_Ae1 = _Ae.subspan(
554 row * num_cols + bs1 * dmap1_cell0.size(), bs1 * dmap1_cell1.size());
555 P1T(sub_Ae1, cell_info1, cells1[1], 1);
559 std::ranges::fill(be, 0);
562 for (std::size_t j = 0; j < dmap1_cell0.size(); ++j)
564 for (
int k = 0; k < bs1; ++k)
566 const std::int32_t jj = bs1 * dmap1_cell0[j] + k;
569 const T bc = bc_values1[jj];
570 const T _x0 = x0.empty() ? 0 : x0[jj];
572 for (
int m = 0; m < num_rows; ++m)
573 be[m] -= Ae[m * num_cols + bs1 * j + k] * alpha * (bc - _x0);
579 const int offset = bs1 * dmap1_cell0.size();
580 for (std::size_t j = 0; j < dmap1_cell1.size(); ++j)
582 for (
int k = 0; k < bs1; ++k)
584 const std::int32_t jj = bs1 * dmap1_cell1[j] + k;
587 const T bc = bc_values1[jj];
588 const T _x0 = x0.empty() ? 0 : x0[jj];
590 for (
int m = 0; m < num_rows; ++m)
593 -= Ae[m * num_cols + offset + bs1 * j + k] * alpha * (bc - _x0);
599 for (std::size_t i = 0; i < dmap0_cell0.size(); ++i)
600 for (
int k = 0; k < bs0; ++k)
601 b[bs0 * dmap0_cell0[i] + k] += be[bs0 * i + k];
603 const int offset_be = bs0 * dmap0_cell0.size();
604 for (std::size_t i = 0; i < dmap0_cell1.size(); ++i)
605 for (
int k = 0; k < bs0; ++k)
606 b[bs0 * dmap0_cell1[i] + k] += be[offset_be + bs0 * i + k];
634 fem::DofTransformKernel<T>
auto P0, std::span<T> b, mdspan2_t x_dofmap,
635 std::span<
const scalar_value_type_t<T>> x,
636 std::span<const std::int32_t> cells,
637 std::tuple<mdspan2_t,
int, std::span<const std::int32_t>> dofmap,
638 FEkernel<T>
auto kernel, std::span<const T> constants,
639 std::span<const T> coeffs,
int cstride,
640 std::span<const std::uint32_t> cell_info0)
645 const auto [dmap, bs, cells0] = dofmap;
646 assert(_bs < 0 or _bs == bs);
649 std::vector<scalar_value_type_t<T>> coordinate_dofs(3 * x_dofmap.extent(1));
650 std::vector<T> be(bs * dmap.extent(1));
651 std::span<T> _be(be);
654 for (std::size_t index = 0; index <
cells.size(); ++index)
657 std::int32_t c =
cells[index];
658 std::int32_t c0 = cells0[index];
661 auto x_dofs = MDSPAN_IMPL_STANDARD_NAMESPACE::submdspan(
662 x_dofmap, c, MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent);
663 for (std::size_t i = 0; i < x_dofs.size(); ++i)
665 std::copy_n(std::next(x.begin(), 3 * x_dofs[i]), 3,
666 std::next(coordinate_dofs.begin(), 3 * i));
670 std::ranges::fill(be, 0);
671 kernel(be.data(), coeffs.data() + index * cstride, constants.data(),
672 coordinate_dofs.data(),
nullptr,
nullptr);
673 P0(_be, cell_info0, c0, 1);
676 auto dofs = MDSPAN_IMPL_STANDARD_NAMESPACE::submdspan(
677 dmap, c0, MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent);
678 if constexpr (_bs > 0)
680 for (std::size_t i = 0; i < dofs.size(); ++i)
681 for (
int k = 0; k < _bs; ++k)
682 b[_bs * dofs[i] + k] += be[_bs * i + k];
686 for (std::size_t i = 0; i < dofs.size(); ++i)
687 for (
int k = 0; k < bs; ++k)
688 b[bs * dofs[i] + k] += be[bs * i + k];
719void assemble_exterior_facets(
720 fem::DofTransformKernel<T>
auto P0, std::span<T> b, mdspan2_t x_dofmap,
721 std::span<
const scalar_value_type_t<T>> x,
int num_facets_per_cell,
722 std::span<const std::int32_t> facets,
723 std::tuple<mdspan2_t,
int, std::span<const std::int32_t>> dofmap,
724 FEkernel<T>
auto fn, std::span<const T> constants,
725 std::span<const T> coeffs,
int cstride,
726 std::span<const std::uint32_t> cell_info0,
727 std::span<const std::uint8_t> perms)
732 const auto [dmap, bs, facets0] = dofmap;
733 assert(_bs < 0 or _bs == bs);
737 const int num_dofs = dmap.extent(1);
738 std::vector<scalar_value_type_t<T>> coordinate_dofs(3 * x_dofmap.extent(1));
739 std::vector<T> be(bs * num_dofs);
740 std::span<T> _be(be);
741 assert(facets.size() % 2 == 0);
742 assert(facets0.size() == facets.size());
743 for (std::size_t index = 0; index < facets.size(); index += 2)
747 std::int32_t
cell = facets[index];
748 std::int32_t local_facet = facets[index + 1];
749 std::int32_t cell0 = facets0[index];
752 auto x_dofs = MDSPAN_IMPL_STANDARD_NAMESPACE::submdspan(
753 x_dofmap,
cell, MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent);
754 for (std::size_t i = 0; i < x_dofs.size(); ++i)
756 std::copy_n(std::next(x.begin(), 3 * x_dofs[i]), 3,
757 std::next(coordinate_dofs.begin(), 3 * i));
762 = perms.empty() ? 0 : perms[
cell * num_facets_per_cell + local_facet];
765 std::ranges::fill(be, 0);
766 fn(be.data(), coeffs.data() + index / 2 * cstride, constants.data(),
767 coordinate_dofs.data(), &local_facet, &perm);
769 P0(_be, cell_info0, cell0, 1);
772 auto dofs = MDSPAN_IMPL_STANDARD_NAMESPACE::submdspan(
773 dmap, cell0, MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent);
774 if constexpr (_bs > 0)
776 for (std::size_t i = 0; i < dofs.size(); ++i)
777 for (
int k = 0; k < _bs; ++k)
778 b[_bs * dofs[i] + k] += be[_bs * i + k];
782 for (std::size_t i = 0; i < dofs.size(); ++i)
783 for (
int k = 0; k < bs; ++k)
784 b[bs * dofs[i] + k] += be[bs * i + k];
815void assemble_interior_facets(
816 fem::DofTransformKernel<T>
auto P0, std::span<T> b, mdspan2_t x_dofmap,
817 std::span<
const scalar_value_type_t<T>> x,
int num_facets_per_cell,
818 std::span<const std::int32_t> facets,
819 std::tuple<
const DofMap&,
int, std::span<const std::int32_t>> dofmap,
820 FEkernel<T>
auto fn, std::span<const T> constants,
821 std::span<const T> coeffs,
int cstride,
822 std::span<const std::uint32_t> cell_info0,
823 std::span<const std::uint8_t> perms)
828 const auto [dmap, bs, facets0] = dofmap;
829 assert(_bs < 0 or _bs == bs);
832 using X = scalar_value_type_t<T>;
833 std::vector<X> coordinate_dofs(2 * x_dofmap.extent(1) * 3);
834 std::span<X> cdofs0(coordinate_dofs.data(), x_dofmap.extent(1) * 3);
835 std::span<X> cdofs1(coordinate_dofs.data() + x_dofmap.extent(1) * 3,
836 x_dofmap.extent(1) * 3);
839 assert(facets.size() % 4 == 0);
840 assert(facets0.size() == facets.size());
841 for (std::size_t index = 0; index < facets.size(); index += 4)
844 std::array<std::int32_t, 2>
cells{facets[index], facets[index + 2]};
845 std::array<std::int32_t, 2> cells0{facets0[index], facets0[index + 2]};
848 std::array<std::int32_t, 2> local_facet{facets[index + 1],
852 auto x_dofs0 = MDSPAN_IMPL_STANDARD_NAMESPACE::submdspan(
853 x_dofmap, cells[0], MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent);
854 for (std::size_t i = 0; i < x_dofs0.size(); ++i)
856 std::copy_n(std::next(x.begin(), 3 * x_dofs0[i]), 3,
857 std::next(cdofs0.begin(), 3 * i));
859 auto x_dofs1 = MDSPAN_IMPL_STANDARD_NAMESPACE::submdspan(
860 x_dofmap, cells[1], MDSPAN_IMPL_STANDARD_NAMESPACE::full_extent);
861 for (std::size_t i = 0; i < x_dofs1.size(); ++i)
863 std::copy_n(std::next(x.begin(), 3 * x_dofs1[i]), 3,
864 std::next(cdofs1.begin(), 3 * i));
868 std::span<const std::int32_t> dmap0 = dmap.cell_dofs(cells0[0]);
869 std::span<const std::int32_t> dmap1 = dmap.cell_dofs(cells0[1]);
872 be.resize(bs * (dmap0.size() + dmap1.size()));
873 std::ranges::fill(be, 0);
876 ? std::array<std::uint8_t, 2>{0, 0}
878 perms[
cells[0] * num_facets_per_cell + local_facet[0]],
879 perms[
cells[1] * num_facets_per_cell + local_facet[1]]};
880 fn(be.data(), coeffs.data() + index / 2 * cstride, constants.data(),
881 coordinate_dofs.data(), local_facet.data(), perm.data());
883 std::span<T> _be(be);
884 std::span<T> sub_be = _be.subspan(bs * dmap0.size(), bs * dmap1.size());
886 P0(be, cell_info0, cells0[0], 1);
887 P0(sub_be, cell_info0, cells0[1], 1);
890 if constexpr (_bs > 0)
892 for (std::size_t i = 0; i < dmap0.size(); ++i)
893 for (
int k = 0; k < _bs; ++k)
894 b[_bs * dmap0[i] + k] += be[_bs * i + k];
895 for (std::size_t i = 0; i < dmap1.size(); ++i)
896 for (
int k = 0; k < _bs; ++k)
897 b[_bs * dmap1[i] + k] += be[_bs * (i + dmap0.size()) + k];
901 for (std::size_t i = 0; i < dmap0.size(); ++i)
902 for (
int k = 0; k < bs; ++k)
903 b[bs * dmap0[i] + k] += be[bs * i + k];
904 for (std::size_t i = 0; i < dmap1.size(); ++i)
905 for (
int k = 0; k < bs; ++k)
906 b[bs * dmap1[i] + k] += be[bs * (i + dmap0.size()) + k];
927template <dolfinx::scalar T, std::
floating_po
int U>
928void lift_bc(std::span<T> b,
const Form<T, U>& a, mdspan2_t x_dofmap,
929 std::span<
const scalar_value_type_t<T>> x,
930 std::span<const T> constants,
931 const std::map<std::pair<IntegralType, int>,
932 std::pair<std::span<const T>,
int>>& coefficients,
933 std::span<const T> bc_values1,
934 std::span<const std::int8_t> bc_markers1, std::span<const T> x0,
938 std::shared_ptr<const mesh::Mesh<U>> mesh = a.mesh();
942 auto mesh0 = a.function_spaces().at(0)->mesh();
946 auto mesh1 = a.function_spaces().at(1)->mesh();
950 assert(a.function_spaces().at(0));
951 assert(a.function_spaces().at(1));
952 auto dofmap0 = a.function_spaces()[0]->dofmap()->map();
953 const int bs0 = a.function_spaces()[0]->dofmap()->bs();
954 auto element0 = a.function_spaces()[0]->element();
955 auto dofmap1 = a.function_spaces()[1]->dofmap()->map();
956 const int bs1 = a.function_spaces()[1]->dofmap()->bs();
957 auto element1 = a.function_spaces()[1]->element();
960 std::span<const std::uint32_t> cell_info0;
961 std::span<const std::uint32_t> cell_info1;
963 if (element0->needs_dof_transformations()
964 or element1->needs_dof_transformations() or a.needs_facet_permutations())
966 mesh0->topology_mutable()->create_entity_permutations();
967 mesh1->topology_mutable()->create_entity_permutations();
968 cell_info0 = std::span(mesh0->topology()->get_cell_permutation_info());
969 cell_info1 = std::span(mesh1->topology()->get_cell_permutation_info());
972 fem::DofTransformKernel<T>
auto P0
974 fem::DofTransformKernel<T>
auto P1T
975 = element1->template dof_transformation_right_fn<T>(
984 if (bs0 == 1 and bs1 == 1)
986 _lift_bc_cells<T, 1, 1>(
987 b, x_dofmap, x, kernel, cells,
990 constants, coeffs, cstride, cell_info0, cell_info1, bc_values1,
991 bc_markers1, x0, alpha);
993 else if (bs0 == 3 and bs1 == 3)
995 _lift_bc_cells<T, 3, 3>(
996 b, x_dofmap, x, kernel, cells,
999 constants, coeffs, cstride, cell_info0, cell_info1, bc_values1,
1000 bc_markers1, x0, alpha);
1004 _lift_bc_cells(b, x_dofmap, x, kernel, cells,
1008 P1T, constants, coeffs, cstride, cell_info0, cell_info1,
1009 bc_values1, bc_markers1, x0, alpha);
1013 std::span<const std::uint8_t> perms;
1014 if (a.needs_facet_permutations())
1016 mesh->topology_mutable()->create_entity_permutations();
1017 perms = std::span(mesh->topology()->get_facet_permutations());
1021 int num_facets_per_cell
1027 auto& [coeffs, cstride]
1029 _lift_bc_exterior_facets(
1030 b, x_dofmap, x, num_facets_per_cell, kernel,
1032 {dofmap0, bs0, a.domain(IntegralType::exterior_facet, i, *mesh0)}, P0,
1033 {dofmap1, bs1, a.domain(IntegralType::exterior_facet, i, *mesh1)}, P1T,
1034 constants, coeffs, cstride, cell_info0, cell_info1, bc_values1,
1035 bc_markers1, x0, alpha, perms);
1042 auto& [coeffs, cstride]
1044 _lift_bc_interior_facets(
1045 b, x_dofmap, x, num_facets_per_cell, kernel,
1047 {dofmap0, bs0, a.domain(IntegralType::interior_facet, i, *mesh0)}, P0,
1048 {dofmap1, bs1, a.domain(IntegralType::interior_facet, i, *mesh1)}, P1T,
1049 constants, coeffs, cstride, cell_info0, cell_info1, perms, bc_values1,
1050 bc_markers1, x0, alpha);
1074template <dolfinx::scalar T, std::
floating_po
int U>
1077 std::vector<std::optional<std::reference_wrapper<
const Form<T, U>>>> a,
1078 const std::vector<std::span<const T>>& constants,
1079 const std::vector<std::map<std::pair<IntegralType, int>,
1080 std::pair<std::span<const T>,
int>>>& coeffs,
1082 std::vector<std::reference_wrapper<
const DirichletBC<T, U>>>>& bcs1,
1083 const std::vector<std::span<const T>>& x0, T alpha)
1085 if (!x0.empty() and x0.size() != a.size())
1087 throw std::runtime_error(
1088 "Mismatch in size between x0 and bilinear form in assembler.");
1091 if (a.size() != bcs1.size())
1093 throw std::runtime_error(
1094 "Mismatch in size between a and bcs in assembler.");
1097 for (std::size_t j = 0; j < a.size(); ++j)
1099 std::vector<std::int8_t> bc_markers1;
1100 std::vector<T> bc_values1;
1101 if (a[j] and !bcs1[j].empty())
1104 std::shared_ptr<const mesh::Mesh<U>> mesh = a[j]->get().mesh();
1106 throw std::runtime_error(
"Unable to extract a mesh.");
1107 mdspan2_t x_dofmap = mesh->geometry().dofmap();
1108 auto x = mesh->geometry().x();
1110 assert(a[j]->get().function_spaces().at(0));
1111 auto V1 = a[j]->get().function_spaces()[1];
1113 auto map1 = V1->dofmap()->index_map;
1114 const int bs1 = V1->dofmap()->index_map_bs();
1116 const int crange = bs1 * (map1->size_local() + map1->num_ghosts());
1117 bc_markers1.assign(crange,
false);
1118 bc_values1.assign(crange, 0);
1119 for (
auto& bc : bcs1[j])
1121 bc.get().mark_dofs(bc_markers1);
1122 bc.get().set(bc_values1, std::nullopt, 1);
1127 lift_bc<T>(b, a[j]->get(), x_dofmap, x, constants[j], coeffs[j],
1128 bc_values1, bc_markers1, x0[j], alpha);
1132 lift_bc<T>(b, a[j]->get(), x_dofmap, x, constants[j], coeffs[j],
1133 bc_values1, bc_markers1, std::span<const T>(), alpha);
1147template <dolfinx::scalar T, std::
floating_po
int U>
1148void assemble_vector(
1149 std::span<T> b,
const Form<T, U>& L, mdspan2_t x_dofmap,
1150 std::span<
const scalar_value_type_t<T>> x, std::span<const T> constants,
1151 const std::map<std::pair<IntegralType, int>,
1152 std::pair<std::span<const T>,
int>>& coefficients)
1155 std::shared_ptr<const mesh::Mesh<U>> mesh = L.mesh();
1159 auto mesh0 = L.function_spaces().at(0)->mesh();
1163 assert(L.function_spaces().at(0));
1164 auto element = L.function_spaces().at(0)->element();
1166 std::shared_ptr<const fem::DofMap> dofmap
1167 = L.function_spaces().at(0)->dofmap();
1169 auto dofs = dofmap->map();
1170 const int bs = dofmap->bs();
1172 fem::DofTransformKernel<T>
auto P0
1175 std::span<const std::uint32_t> cell_info0;
1176 if (element->needs_dof_transformations() or L.needs_facet_permutations())
1178 mesh0->topology_mutable()->create_entity_permutations();
1179 cell_info0 = std::span(mesh0->topology()->get_cell_permutation_info());
1190 impl::assemble_cells<T, 1>(
1191 P0, b, x_dofmap, x, cells,
1193 coeffs, cstride, cell_info0);
1197 impl::assemble_cells<T, 3>(
1198 P0, b, x_dofmap, x, cells,
1200 coeffs, cstride, cell_info0);
1204 impl::assemble_cells(P0, b, x_dofmap, x, cells,
1206 fn, constants, coeffs, cstride, cell_info0);
1210 std::span<const std::uint8_t> perms;
1211 if (L.needs_facet_permutations())
1213 mesh->topology_mutable()->create_entity_permutations();
1214 perms = std::span(mesh->topology()->get_facet_permutations());
1218 int num_facets_per_cell
1224 auto& [coeffs, cstride]
1226 std::span<const std::int32_t> facets
1230 impl::assemble_exterior_facets<T, 1>(
1231 P0, b, x_dofmap, x, num_facets_per_cell, facets,
1233 constants, coeffs, cstride, cell_info0, perms);
1237 impl::assemble_exterior_facets<T, 3>(
1238 P0, b, x_dofmap, x, num_facets_per_cell, facets,
1240 constants, coeffs, cstride, cell_info0, perms);
1244 impl::assemble_exterior_facets(
1245 P0, b, x_dofmap, x, num_facets_per_cell, facets,
1247 constants, coeffs, cstride, cell_info0, perms);
1255 auto& [coeffs, cstride]
1257 std::span<const std::int32_t> facets
1261 impl::assemble_interior_facets<T, 1>(
1262 P0, b, x_dofmap, x, num_facets_per_cell, facets,
1264 constants, coeffs, cstride, cell_info0, perms);
1268 impl::assemble_interior_facets<T, 3>(
1269 P0, b, x_dofmap, x, num_facets_per_cell, facets,
1271 constants, coeffs, cstride, cell_info0, perms);
1275 impl::assemble_interior_facets(
1276 P0, b, x_dofmap, x, num_facets_per_cell, facets,
1278 constants, coeffs, cstride, cell_info0, perms);
1289template <dolfinx::scalar T, std::
floating_po
int U>
1290void assemble_vector(
1291 std::span<T> b,
const Form<T, U>& L, std::span<const T> constants,
1292 const std::map<std::pair<IntegralType, int>,
1293 std::pair<std::span<const T>,
int>>& coefficients)
1295 std::shared_ptr<const mesh::Mesh<U>> mesh = L.mesh();
1297 if constexpr (std::is_same_v<U, scalar_value_type_t<T>>)
1298 assemble_vector(b, L, mesh->geometry().dofmap(), mesh->geometry().x(),
1299 constants, coefficients);
1302 auto x = mesh->geometry().x();
1303 std::vector<scalar_value_type_t<T>> _x(x.begin(), x.end());
1304 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