11#include "CoordinateElement.h"
13#include "ElementDofLayout.h"
14#include "Expression.h"
17#include "FunctionSpace.h"
19#include "sparsitybuild.h"
24#include <dolfinx/common/defines.h>
25#include <dolfinx/common/types.h>
26#include <dolfinx/la/SparsityPattern.h>
27#include <dolfinx/mesh/EntityMap.h>
28#include <dolfinx/mesh/Topology.h>
29#include <dolfinx/mesh/cell_types.h>
51template <std::
floating_po
int T>
62template <dolfinx::scalar T, std::
floating_po
int U>
73template <
int num_cells>
74std::array<std::int32_t, 2 * num_cells>
79 assert(cells.size() == num_cells);
80 std::array<std::int32_t, 2 * num_cells> cell_local_facet_pairs;
81 for (
int c = 0; c < num_cells; ++c)
84 std::int32_t
cell = cells[c];
86 auto facet_it = std::find(cell_facets.begin(), cell_facets.end(), f);
87 assert(facet_it != cell_facets.end());
88 int local_f = std::distance(cell_facets.begin(), facet_it);
89 cell_local_facet_pairs[2 * c] =
cell;
90 cell_local_facet_pairs[2 * c + 1] = local_f;
93 return cell_local_facet_pairs;
103template <
int num_cells>
104std::array<std::int32_t, 2 * num_cells>
108 static_assert(num_cells == 1);
110 assert(cells.size() > 0);
113 std::int32_t
cell = cells[0];
117 auto it = std::ranges::find(cell_entities, e);
118 assert(it != cell_entities.end());
119 std::int32_t local_index = std::distance(cell_entities.begin(), it);
121 return {
cell, local_index};
159std::vector<std::int32_t>
162 std::span<const std::int32_t> entities);
171template <dolfinx::scalar T, std::
floating_po
int U>
172std::vector<std::vector<std::array<std::shared_ptr<const FunctionSpace<U>>, 2>>>
176 std::vector<std::array<std::shared_ptr<const FunctionSpace<U>>, 2>>>
181 for (std::size_t i = 0; i < a.size(); ++i)
183 for (std::size_t j = 0; j < a[i].size(); ++j)
186 spaces[i][j] = {form->function_spaces()[0], form->function_spaces()[1]};
197template <dolfinx::scalar T, std::
floating_po
int U>
206 std::array<std::reference_wrapper<const DofMap>, 2> dofmaps{
210 const std::array index_maps{dofmaps[0].get().index_map,
211 dofmaps[1].get().index_map};
213 = {dofmaps[0].get().index_map_bs(), dofmaps[1].get().index_map_bs()};
225template <dolfinx::scalar T, std::
floating_po
int U>
230 throw std::runtime_error(
231 "Cannot create sparsity pattern. Form is not a bilinear.");
246 int tdim =
mesh->topology()->dim();
247 mesh->topology_mutable()->create_entities(tdim - 1);
248 mesh->topology_mutable()->create_connectivity(tdim - 1, tdim);
253 auto extract_cells = [](std::span<const std::int32_t> facets)
255 assert(facets.size() % 2 == 0);
256 std::vector<std::int32_t> cells;
257 cells.reserve(facets.size() / 2);
258 for (std::size_t i = 0; i < facets.size(); i += 2)
259 cells.push_back(facets[i]);
263 const int num_cell_types =
mesh->topology()->cell_types().size();
264 for (
int cell_type_idx = 0; cell_type_idx < num_cell_types; ++cell_type_idx)
266 std::array<std::reference_wrapper<const DofMap>, 2> dofmaps{
271 for (
auto type : types)
276 for (
int i = 0; i < a.
num_integrals(type, cell_type_idx); ++i)
280 std::pair{a.
domain_arg(type, 0, i, cell_type_idx),
282 {{dofmaps[0], dofmaps[1]}});
286 for (
int i = 0; i < a.
num_integrals(type, cell_type_idx); ++i)
292 {{dofmaps[0], dofmaps[1]}});
298 for (
int i = 0; i < a.
num_integrals(type, cell_type_idx); ++i)
302 std::pair{extract_cells(a.
domain_arg(type, 0, i, 0)),
304 {{dofmaps[0], dofmaps[1]}});
308 throw std::runtime_error(
"Unsupported integral type");
317template <std::
floating_po
int T>
319 const std::vector<int>& parent_map
323 std::vector<int> offsets(1, 0);
324 std::vector<dolfinx::fem::ElementDofLayout> sub_doflayout;
331 std::shared_ptr<const fem::FiniteElement<T>> sub_e
338 std::vector<int> parent_map_sub(sub_e->space_dimension(), offsets.back());
339 for (std::size_t j = 0; j < parent_map_sub.size(); ++j)
340 parent_map_sub[j] += bs * j;
341 offsets.push_back(offsets.back() + (bs > 1 ? 1 : sub_e->space_dimension()));
342 sub_doflayout.push_back(
361 mesh::Topology& topology,
362 const std::function<
void(std::span<std::int32_t>, std::uint32_t)>&
364 const std::function<std::vector<int>(
365 const graph::AdjacencyList<std::int32_t>&)>& reorder_fn);
378 MPI_Comm comm,
const std::vector<ElementDofLayout>& layouts,
379 mesh::Topology& topology,
380 const std::function<
void(std::span<std::int32_t>, std::uint32_t)>&
382 const std::function<std::vector<int>(
383 const graph::AdjacencyList<std::int32_t>&)>& reorder_fn);
413template <dolfinx::scalar T, std::
floating_po
int U = scalar_value_t<T>>
415 const std::vector<std::reference_wrapper<const ufcx_form>>& ufcx_forms,
417 const std::vector<std::shared_ptr<
const Function<T, U>>>& coefficients,
418 const std::vector<std::shared_ptr<
const Constant<T>>>& constants,
421 std::vector<std::pair<std::int32_t, std::span<const std::int32_t>>>>&
423 const std::vector<std::reference_wrapper<const mesh::EntityMap>>&
427 for (
const ufcx_form& ufcx_form : ufcx_forms)
429 if (ufcx_form.rank != (
int)spaces.size())
430 throw std::runtime_error(
"Wrong number of argument spaces for Form.");
431 if (ufcx_form.num_coefficients != (
int)coefficients.size())
433 throw std::runtime_error(
"Mismatch between number of expected and "
434 "provided Form coefficients.");
438 if (ufcx_form.num_constants != (
int)constants.size())
440 throw std::runtime_error(std::format(
441 "Mismatch between number of expected and "
442 "provided Form Constants. Expected {} constants, but got {}.",
443 ufcx_form.num_constants, constants.size()));
445 for (std::size_t c = 0; c < constants.size(); ++c)
447 if (ufcx_form.constant_ranks[c] != (
int)constants[c]->shape.size())
449 throw std::runtime_error(std::format(
450 "Mismatch between expected and actual rank of "
451 "Form Constant. Rank of Constant {} should be {}, but got rank {}.",
452 c, ufcx_form.constant_ranks[c], constants[c]->shape.size()));
454 if (!std::equal(constants[c]->shape.begin(), constants[c]->shape.end(),
455 ufcx_form.constant_shapes[c]))
457 throw std::runtime_error(
458 std::format(
"Mismatch between expected and actual shape of Form "
459 "Constant for Constant {}.",
466 for (std::size_t form_idx = 0; form_idx < ufcx_forms.size(); ++form_idx)
468 for (std::size_t i = 0; i < spaces.size(); ++i)
470 assert(spaces[i]->elements(form_idx));
471 if (
auto element_hash
472 = ufcx_forms[form_idx].get().finite_element_hashes[i];
475 != spaces[i]->elements(form_idx)->basix_element().hash())
477 throw std::runtime_error(
478 "Cannot create form. Elements are different to "
479 "those used to compile the form.");
485 if (!
mesh and !spaces.empty())
486 mesh = spaces.front()->mesh();
488 throw std::runtime_error(
"No mesh could be associated with the Form.");
490 auto topology =
mesh->topology();
492 const int tdim = topology->dim();
497 const int* integral_offsets = ufcx_forms[0].get().form_integral_offsets;
498 std::array<int, 5> num_integrals_type;
499 for (std::size_t i = 0; i < num_integrals_type.size(); ++i)
500 num_integrals_type[i] = integral_offsets[i + 1] - integral_offsets[i];
503 if (num_integrals_type[
vertex] > 0)
505 mesh->topology_mutable()->create_connectivity(0, tdim);
506 mesh->topology_mutable()->create_connectivity(tdim, 0);
514 mesh->topology_mutable()->create_entities(tdim - 1);
515 mesh->topology_mutable()->create_connectivity(tdim - 1, tdim);
516 mesh->topology_mutable()->create_connectivity(tdim, tdim - 1);
520 if (num_integrals_type[
ridge] > 0)
522 mesh->topology_mutable()->create_entities(tdim - 2);
523 mesh->topology_mutable()->create_connectivity(tdim - 2, tdim);
524 mesh->topology_mutable()->create_connectivity(tdim, tdim - 2);
531 auto check_geometry_hash
532 = [&geo =
mesh->geometry()](
const ufcx_integral& integral,
533 std::size_t cell_idx)
535 if (integral.coordinate_element_hash != geo.cmap(cell_idx).hash())
537 throw std::runtime_error(
538 "Generated integral geometry element does not match mesh geometry: "
539 + std::to_string(integral.coordinate_element_hash) +
", "
540 + std::to_string(geo.cmap(cell_idx).hash()));
545 bool needs_facet_permutations =
false;
547 std::vector<std::int32_t> default_cells;
548 std::span<const int> ids(ufcx_forms[0].get().form_integral_ids
549 + integral_offsets[
cell],
550 num_integrals_type[
cell]);
552 for (std::size_t form_idx = 0; form_idx < ufcx_forms.size(); ++form_idx)
554 const ufcx_form& ufcx_form = ufcx_forms[form_idx];
555 for (
int i = 0; i < num_integrals_type[
cell]; ++i)
557 const int id = ids[i];
558 ufcx_integral* integral
559 = ufcx_form.form_integrals[integral_offsets[
cell] + i];
561 check_geometry_hash(*integral, form_idx);
564 std::vector<int> active_coeffs;
565 for (
int j = 0; j < ufcx_form.num_coefficients; ++j)
567 if (integral->enabled_coefficients[j])
568 active_coeffs.push_back(j);
571 impl::kernel_t<T, U> k = impl::extract_kernel<T>(integral);
574 throw std::runtime_error(
575 "UFCx kernel function is NULL. Check requested types.");
582 assert(topology->index_maps(tdim).at(form_idx));
583 default_cells.resize(
584 topology->index_maps(tdim).at(form_idx)->size_local(), 0);
585 std::iota(default_cells.begin(), default_cells.end(), 0);
587 {k, default_cells, active_coeffs}});
589 else if (sd != subdomains.end())
592 auto it = std::ranges::lower_bound(sd->second,
id, std::less<>{},
593 [](
auto& a) { return a.first; });
594 if (it != sd->second.end() and it->first ==
id)
598 std::vector<std::int32_t>(it->second.begin(),
604 if (integral->needs_facet_permutations)
605 needs_facet_permutations =
true;
612 std::vector<std::int32_t> default_facets_int;
613 std::span<const int> ids(ufcx_forms[0].get().form_integral_ids
617 for (std::size_t form_idx = 0; form_idx < ufcx_forms.size(); ++form_idx)
619 const ufcx_form& ufcx_form = ufcx_forms[form_idx];
622 std::vector<std::int8_t> interprocess_marker;
625 assert(topology->index_map(tdim - 1));
626 const std::vector<std::int32_t>& interprocess_facets
627 = topology->interprocess_facets();
628 std::int32_t num_facets = topology->index_map(tdim - 1)->size_local()
629 + topology->index_map(tdim - 1)->num_ghosts();
630 interprocess_marker.resize(num_facets, 0);
631 std::ranges::for_each(interprocess_facets,
632 [&interprocess_marker](
auto f)
633 { interprocess_marker[f] = 1; });
638 const int id = ids[i];
639 ufcx_integral* integral
642 check_geometry_hash(*integral, form_idx);
644 std::vector<int> active_coeffs;
645 for (
int j = 0; j < ufcx_form.num_coefficients; ++j)
647 if (integral->enabled_coefficients[j])
648 active_coeffs.push_back(j);
651 impl::kernel_t<T, U> k = impl::extract_kernel<T>(integral);
655 auto f_to_c = topology->connectivity(tdim - 1, tdim);
657 auto c_to_f = topology->connectivity(tdim, tdim - 1);
662 assert(topology->index_map(tdim - 1));
663 std::int32_t num_facets = topology->index_map(tdim - 1)->size_local();
664 default_facets_int.reserve(4 * num_facets);
665 for (std::int32_t f = 0; f < num_facets; ++f)
667 if (f_to_c->num_links(f) == 2)
669 std::array<std::int32_t, 4> pairs
670 = impl::get_cell_facet_pairs<2>(f, f_to_c->links(f), *c_to_f);
671 default_facets_int.insert(default_facets_int.end(), pairs.begin(),
674 else if (interprocess_marker[f])
676 throw std::runtime_error(
677 "Cannot compute interior facet integral over interprocess "
678 "facet. Please use ghost mode shared facet when creating the "
683 {k, default_facets_int, active_coeffs}});
685 else if (sd != subdomains.end())
687 auto it = std::ranges::lower_bound(sd->second,
id, std::less{},
688 [](
auto& a) { return a.first; });
689 if (it != sd->second.end() and it->first ==
id)
693 std::vector<std::int32_t>(it->second.begin(),
699 if (integral->needs_facet_permutations)
700 needs_facet_permutations =
true;
729 throw std::runtime_error(
"Unsupported integral type");
732 const std::function<std::vector<std::int32_t>(
const mesh::Topology&,
734 get_default_integration_entities
745 std::int32_t num_entities = topology.
index_map(dim)->size_local();
746 std::vector<std::int32_t> entities(num_entities);
747 std::iota(entities.begin(), entities.end(), 0);
752 std::vector<std::int32_t> default_entities_ext;
754 std::span<const int> ids(ufcx_forms[0].get().form_integral_ids
755 + integral_offsets[(std::int8_t)itg_type],
756 num_integrals_type[(std::int8_t)itg_type]);
757 auto sd = subdomains.find(itg_type);
758 for (std::size_t form_idx = 0; form_idx < ufcx_forms.size(); ++form_idx)
760 const ufcx_form& ufcx_form = ufcx_forms[form_idx];
761 for (
int i = 0; i < num_integrals_type[(std::int8_t)itg_type]; ++i)
763 const int id = ids[i];
764 ufcx_integral* integral
765 = ufcx_form.form_integrals[integral_offsets[(std::int8_t)itg_type]
768 check_geometry_hash(*integral, form_idx);
770 std::vector<int> active_coeffs;
771 for (
int j = 0; j < ufcx_form.num_coefficients; ++j)
773 if (integral->enabled_coefficients[j])
774 active_coeffs.push_back(j);
777 impl::kernel_t<T, U> k = impl::extract_kernel<T>(integral);
786 std::vector default_entities
787 = get_default_integration_entities(*topology, itg_type);
789 default_entities_ext.reserve(2 * default_entities.size());
790 for (std::int32_t e : default_entities)
793 std::array<std::int32_t, 2> pair = impl::get_cell_entity_pairs<1>(
794 e, e_to_c->links(e), *c_to_e);
795 default_entities_ext.insert(default_entities_ext.end(),
796 pair.begin(), pair.end());
798 integrals.insert({{itg_type, i, form_idx},
799 {k, default_entities_ext, active_coeffs}});
801 else if (sd != subdomains.end())
804 auto it = std::ranges::lower_bound(sd->second,
id, std::less<>{},
805 [](
auto& a) { return a.first; });
806 if (it != sd->second.end() and it->first ==
id)
808 integrals.insert({{itg_type, i, form_idx},
810 std::vector<std::int32_t>(it->second.begin(),
816 if (integral->needs_facet_permutations)
817 needs_facet_permutations =
true;
823 return Form<T, U>(spaces, std::move(integrals),
mesh, coefficients, constants,
824 needs_facet_permutations, entity_maps);
841template <dolfinx::scalar T, std::
floating_po
int U = scalar_value_t<T>>
843 const ufcx_form& ufcx_form,
845 const std::map<std::string, std::shared_ptr<
const Function<T, U>>>&
847 const std::map<std::string, std::shared_ptr<
const Constant<T>>>& constants,
850 std::vector<std::pair<std::int32_t, std::span<const std::int32_t>>>>&
852 const std::vector<std::reference_wrapper<const mesh::EntityMap>>&
857 std::vector<std::shared_ptr<const Function<T, U>>> coeff_map;
860 if (
auto it = coefficients.find(name); it != coefficients.end())
861 coeff_map.push_back(it->second);
864 throw std::runtime_error(
"Form coefficient \"" + name
865 +
"\" not provided.");
870 std::vector<std::shared_ptr<const Constant<T>>> const_map;
873 if (
auto it = constants.find(name); it != constants.end())
874 const_map.push_back(it->second);
876 throw std::runtime_error(
"Form constant \"" + name +
"\" not provided.");
880 subdomains, entity_maps,
mesh);
901template <dolfinx::scalar T, std::
floating_po
int U = scalar_value_t<T>>
903 ufcx_form* (*fptr)(),
905 const std::map<std::string, std::shared_ptr<
const Function<T, U>>>&
907 const std::map<std::string, std::shared_ptr<
const Constant<T>>>& constants,
910 std::vector<std::pair<std::int32_t, std::span<const std::int32_t>>>>&
912 const std::vector<std::reference_wrapper<const mesh::EntityMap>>&
916 ufcx_form* form = fptr();
918 subdomains, entity_maps,
mesh);
924template <std::
floating_po
int T>
929 reorder_fn =
nullptr)
934 assert(
mesh->topology());
935 if (e->cell_type() !=
mesh->topology()->cell_type())
936 throw std::runtime_error(
"Cell type of element and mesh must match.");
942 std::function<void(std::span<std::int32_t>, std::uint32_t)> permute_inv
943 = e->needs_dof_permutations() ? e->dof_permutation_fn(
true,
true)
946 mesh->comm(), layout, *
mesh->topology(), permute_inv, reorder_fn));
952template <dolfinx::scalar T, std::
floating_po
int U = scalar_value_t<T>>
954 const ufcx_expression& e,
955 const std::vector<std::shared_ptr<
const Function<T, U>>>& coefficients,
956 const std::vector<std::shared_ptr<
const Constant<T>>>& constants,
959 if (!coefficients.empty())
961 assert(coefficients.front());
962 assert(coefficients.front()->function_space());
963 std::shared_ptr<const mesh::Mesh<U>>
mesh
964 = coefficients.front()->function_space()->mesh();
965 if (
mesh->geometry().cmap().hash() != e.coordinate_element_hash)
967 throw std::runtime_error(
968 "Expression and mesh geometric maps do not match.");
972 if (e.rank > 0 and !argument_space)
974 throw std::runtime_error(
"Expression has Argument but no Argument "
975 "function space was provided.");
978 std::vector<U> X(e.points, e.points + e.num_points * e.entity_dimension);
979 std::array<std::size_t, 2> Xshape
980 = {
static_cast<std::size_t
>(e.num_points),
981 static_cast<std::size_t
>(e.entity_dimension)};
982 std::vector<std::size_t> value_shape(e.value_shape,
983 e.value_shape + e.num_components);
984 std::function<void(T*,
const T*,
const T*,
const scalar_value_t<T>*,
985 const int*,
const std::uint8_t*,
void*)>
986 tabulate_tensor =
nullptr;
987 if constexpr (std::is_same_v<T, float>)
988 tabulate_tensor = e.tabulate_tensor_float32;
989#ifndef DOLFINX_NO_STDC_COMPLEX_KERNELS
990 else if constexpr (std::is_same_v<T, std::complex<float>>)
992 tabulate_tensor =
reinterpret_cast<void (*)(
993 T*,
const T*,
const T*,
const scalar_value_t<T>*,
const int*,
994 const unsigned char*,
void*)
>(e.tabulate_tensor_complex64);
997 else if constexpr (std::is_same_v<T, double>)
998 tabulate_tensor = e.tabulate_tensor_float64;
999#ifndef DOLFINX_NO_STDC_COMPLEX_KERNELS
1000 else if constexpr (std::is_same_v<T, std::complex<double>>)
1002 tabulate_tensor =
reinterpret_cast<void (*)(
1003 T*,
const T*,
const T*,
const scalar_value_t<T>*,
const int*,
1004 const unsigned char*,
void*)
>(e.tabulate_tensor_complex128);
1008 throw std::runtime_error(
"Type not supported.");
1010 assert(tabulate_tensor);
1011 return Expression(coefficients, constants, std::span<const U>(X), Xshape,
1012 tabulate_tensor, value_shape, argument_space);
1017template <dolfinx::scalar T, std::
floating_po
int U = scalar_value_t<T>>
1019 const ufcx_expression& e,
1020 const std::map<std::string, std::shared_ptr<
const Function<T, U>>>&
1022 const std::map<std::string, std::shared_ptr<
const Constant<T>>>& constants,
1026 std::vector<std::shared_ptr<const Function<T, U>>> coeff_map;
1027 std::vector<std::string> coefficient_names;
1028 coefficient_names.reserve(e.num_coefficients);
1029 for (
int i = 0; i < e.num_coefficients; ++i)
1030 coefficient_names.push_back(e.coefficient_names[i]);
1032 for (
const std::string& name : coefficient_names)
1034 if (
auto it = coefficients.find(name); it != coefficients.end())
1035 coeff_map.push_back(it->second);
1038 throw std::runtime_error(
"Expression coefficient \"" + name
1039 +
"\" not provided.");
1044 std::vector<std::shared_ptr<const Constant<T>>> const_map;
1045 std::vector<std::string> constant_names;
1046 constant_names.reserve(e.num_constants);
1047 for (
int i = 0; i < e.num_constants; ++i)
1048 constant_names.push_back(e.constant_names[i]);
1050 for (
const std::string& name : constant_names)
1052 if (
auto it = constants.find(name); it != constants.end())
1053 const_map.push_back(it->second);
1056 throw std::runtime_error(
"Expression constant \"" + name
1057 +
"\" not provided.");
1078template <std::
floating_po
int T>
1081 const std::function<std::vector<int>(
1088 throw std::runtime_error(
1089 "Cell shape of new coordinate element must match input mesh.");
1092 const int gdim =
mesh->geometry().dim();
1096 basix::element::family::P,
1098 new_cmap.
variant(), basix::element::dpc_variant::unset,
false);
1099 auto element = std::make_shared<const FiniteElement<T>>(
1100 b_element, std::vector<std::size_t>{
static_cast<std::size_t
>(gdim)});
1105 std::vector<T> x_new = V.tabulate_dof_coordinates(
false);
1108 std::shared_ptr<const DofMap> dm = V.dofmap();
1110 std::shared_ptr<const common::IndexMap> new_imap = dm->index_map;
1113 auto map_view = dm->map();
1114 std::vector<std::int32_t> dofmap_flat(
1115 map_view.data_handle(), map_view.data_handle() + map_view.size());
1119 const std::int32_t num_nodes
1120 = new_imap->size_local() + new_imap->num_ghosts();
1121 std::vector<std::int32_t> local(num_nodes);
1122 std::iota(local.begin(), local.end(), 0);
1123 std::vector<std::int64_t> igi(num_nodes);
1124 new_imap->local_to_global(local, igi);
1127 new_imap, std::vector<std::vector<std::int32_t>>{std::move(dofmap_flat)},
1128 std::vector<CoordinateElement<T>>{new_cmap}, std::move(x_new), gdim,
Degree-of-freedom map representations and tools.
Definition CoordinateElement.h:26
Timer for measuring and logging elapsed time durations.
Definition Timer.h:40
std::chrono::duration< double, Period > stop()
Stop timer and return elapsed time.
Definition Timer.h:92
Constant (in space) value which can be attached to a Form.
Definition Constant.h:22
Definition CoordinateElement.h:38
basix::element::lagrange_variant variant() const
Variant of the element.
Definition CoordinateElement.cpp:212
mesh::CellType cell_shape() const
Cell shape.
Definition CoordinateElement.cpp:41
int degree() const
The polynomial degree of the element.
Definition CoordinateElement.cpp:198
Degree-of-freedom map.
Definition DofMap.h:73
Definition ElementDofLayout.h:31
An Expression represents a mathematical expression evaluated at a pre-defined points on a reference c...
Definition Expression.h:41
Model of a finite element.
Definition FiniteElement.h:57
const std::vector< std::shared_ptr< const FiniteElement< geometry_type > > > & sub_elements() const noexcept
Get subelements (if any).
Definition FiniteElement.cpp:396
const std::vector< std::vector< std::vector< int > > > & entity_dofs() const noexcept
Local DOFs associated with each sub-entity of the cell.
Definition FiniteElement.cpp:340
int num_sub_elements() const noexcept
Number of sub elements (for a mixed or blocked element).
Definition FiniteElement.cpp:383
const std::vector< std::vector< std::vector< int > > > & entity_closure_dofs() const noexcept
Local DOFs associated with the closure of each sub-entity of the cell.
Definition FiniteElement.cpp:347
int block_size() const noexcept
Block size of the finite element function space.
Definition FiniteElement.cpp:359
This class represents a finite element function space defined by a mesh, a finite element,...
Definition FunctionSpace.h:34
This class provides a static adjacency list data structure.
Definition AdjacencyList.h:38
std::span< LinkData > links(std::size_t node)
Get the links (edges) for given node.
Definition AdjacencyList.h:155
Definition SparsityPattern.h:26
Geometry stores the geometry imposed on a mesh.
Definition Geometry.h:34
A Mesh consists of a set of connected and numbered mesh topological entities, and geometry data.
Definition Mesh.h:23
Topology stores the topology of a mesh, consisting of mesh entities and connectivity (incidence relat...
Definition Topology.h:49
std::shared_ptr< const common::IndexMap > index_map(int dim) const
Get the IndexMap that described the parallel distribution of the mesh entities.
Definition Topology.cpp:843
std::shared_ptr< const graph::AdjacencyList< std::int32_t > > connectivity(std::array< int, 2 > d0, std::array< int, 2 > d1) const
Get the connectivity from entities of topological dimension d0 to dimension d1.
Definition Topology.cpp:865
std::array< std::int32_t, 2 *num_cells > get_cell_facet_pairs(std::int32_t f, std::span< const std::int32_t > cells, const graph::AdjacencyList< std::int32_t > &c_to_f)
Definition utils.h:75
std::array< std::int32_t, 2 *num_cells > get_cell_entity_pairs(std::int32_t e, std::span< const std::int32_t > cells, const graph::AdjacencyList< std::int32_t > &c_to_e)
Definition utils.h:105
Functions supporting mesh operations.
Miscellaneous classes, functions and types.
Definition dolfinx_common.h:8
void interior_facets(la::SparsityPattern &pattern, std::array< std::span< const std::int32_t >, 2 > cells, std::array< std::reference_wrapper< const DofMap >, 2 > dofmaps)
Iterate over interior facets and insert entries into sparsity pattern.
Definition sparsitybuild.cpp:16
void cells(la::SparsityPattern &pattern, const std::pair< R0, R1 > &cells, std::array< std::reference_wrapper< const DofMap >, 2 > dofmaps)
Iterate over cells and insert entries into sparsity pattern.
Definition sparsitybuild.h:37
Finite element method functionality.
Definition assemble_expression_impl.h:23
std::vector< std::string > get_constant_names(const ufcx_form &ufcx_form)
Get the name of each constant in a UFC form.
Definition utils.cpp:146
FunctionSpace< T > create_functionspace(std::shared_ptr< mesh::Mesh< T > > mesh, std::shared_ptr< const fem::FiniteElement< T > > e, std::function< std::vector< int >(const graph::AdjacencyList< std::int32_t > &)> reorder_fn=nullptr)
NEW Create a function space from a fem::FiniteElement.
Definition utils.h:925
mesh::Mesh< T > interpolate_geometry(std::shared_ptr< mesh::Mesh< T > > mesh, const CoordinateElement< T > &new_cmap, const std::function< std::vector< int >(const graph::AdjacencyList< std::int32_t > &)> &reorder_fn=nullptr)
Take an existing mesh and create a new mesh with its geometry interpolated into a new coordinate elem...
Definition utils.h:1079
Form< T, U > create_form_factory(const std::vector< std::reference_wrapper< const ufcx_form > > &ufcx_forms, const std::vector< std::shared_ptr< const FunctionSpace< U > > > &spaces, const std::vector< std::shared_ptr< const Function< T, U > > > &coefficients, const std::vector< std::shared_ptr< const Constant< T > > > &constants, const std::map< IntegralType, std::vector< std::pair< std::int32_t, std::span< const std::int32_t > > > > &subdomains, const std::vector< std::reference_wrapper< const mesh::EntityMap > > &entity_maps, std::shared_ptr< const mesh::Mesh< U > > mesh=nullptr)
Create a Form from UFCx input with coefficients and constants passed in the required order.
Definition utils.h:414
std::vector< std::string > get_coefficient_names(const ufcx_form &ufcx_form)
Definition utils.cpp:139
std::vector< std::vector< std::array< std::shared_ptr< const FunctionSpace< U > >, 2 > > > extract_function_spaces(const std::vector< std::vector< const Form< T, U > * > > &a)
Extract test (0) and trial (1) function spaces pairs for each bilinear form for a rectangular array o...
Definition utils.h:173
Expression< T, U > create_expression(const ufcx_expression &e, const std::vector< std::shared_ptr< const Function< T, U > > > &coefficients, const std::vector< std::shared_ptr< const Constant< T > > > &constants, std::shared_ptr< const FunctionSpace< U > > argument_space=nullptr)
Create Expression from UFC.
Definition utils.h:953
std::vector< std::int32_t > compute_integration_domains(IntegralType integral_type, const mesh::Topology &topology, std::span< const std::int32_t > entities)
Given an integral type and a set of entities, computes and return data for the entities that should b...
Definition utils.cpp:154
Form< T, U > create_form(const ufcx_form &ufcx_form, const std::vector< std::shared_ptr< const FunctionSpace< U > > > &spaces, const std::map< std::string, std::shared_ptr< const Function< T, U > > > &coefficients, const std::map< std::string, std::shared_ptr< const Constant< T > > > &constants, const std::map< IntegralType, std::vector< std::pair< std::int32_t, std::span< const std::int32_t > > > > &subdomains, const std::vector< std::reference_wrapper< const mesh::EntityMap > > &entity_maps, std::shared_ptr< const mesh::Mesh< U > > mesh=nullptr)
Create a Form from UFC input with coefficients and constants resolved by name.
Definition utils.h:842
ElementDofLayout create_element_dof_layout(const fem::FiniteElement< T > &element, const std::vector< int > &parent_map={})
Create an ElementDofLayout from a FiniteElement.
Definition utils.h:318
IntegralType
Type of integral.
Definition Form.h:39
@ vertex
Vertex.
Definition Form.h:43
@ interior_facet
Interior facet.
Definition Form.h:42
@ ridge
Ridge.
Definition Form.h:44
@ cell
Cell.
Definition Form.h:40
@ exterior_facet
Facet.
Definition Form.h:41
la::SparsityPattern create_sparsity_pattern(const Form< T, U > &a)
Create a sparsity pattern for a given form.
Definition utils.h:198
DofMap create_dofmap(MPI_Comm comm, const ElementDofLayout &layout, mesh::Topology &topology, const std::function< void(std::span< std::int32_t >, std::uint32_t)> &permute_inv, const std::function< std::vector< int >(const graph::AdjacencyList< std::int32_t > &)> &reorder_fn)
Create a dof map on mesh.
Definition utils.cpp:32
std::vector< DofMap > create_dofmaps(MPI_Comm comm, const std::vector< ElementDofLayout > &layouts, mesh::Topology &topology, const std::function< void(std::span< std::int32_t >, std::uint32_t)> &permute_inv, const std::function< std::vector< int >(const graph::AdjacencyList< std::int32_t > &)> &reorder_fn)
Create a set of dofmaps on a given topology.
Definition utils.cpp:78
FunctionSpace(U mesh, V element, W dofmap) -> FunctionSpace< typename std::remove_cvref< typename U::element_type >::type::geometry_type::value_type >
Type deduction.
void build_sparsity_pattern(la::SparsityPattern &pattern, const Form< T, U > &a)
Build a sparsity pattern for a given form.
Definition utils.h:226
Geometry data structures and algorithms.
Definition BoundingBoxTree.h:22
Mesh data structures and algorithms on meshes.
Definition DofMap.h:32
std::vector< std::int32_t > exterior_facet_indices(const Topology &topology, int facet_type_idx)
Compute the indices of all exterior facets that are owned by the caller.
Definition utils.cpp:59
basix::cell::type cell_type_to_basix_type(CellType celltype)
Convert a cell type to a Basix cell type.
Definition cell_types.cpp:163
Represents integral data, containing the kernel, and a list of entities to integrate over and the ind...
Definition Form.h:52