https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Classes | Typedefs | Functions | Variables
Moose::MFEM Namespace Reference

Utilities for converting between vector(s) of libMesh Points and MFEM Vector(s). More...

Classes

class  BlockDistribution
 Block distribution of a dense global index range [0, n) over the ranks of a communicator: rank r owns [begin(r), end(r)). More...
 
class  CoefficientManager
 Front-end class for creating and storing MFEM coefficients. More...
 
class  CoefficientMap
 Class to manage MFEM coefficient objects representing material properties. More...
 
class  ComplexEquationSystem
 Class to store weak form components (bilinear and linear forms, and optionally mixed and nonlinear forms) and build methods. More...
 
class  ComplexEquationSystemProblemOperator
 Steady-state problem operator with an equation system. More...
 
class  DampedNewtonSolver
 mfem::NewtonSolver applying a constant damping factor to the Newton update, optionally shortening it further with a backtracking line search on the residual norm. More...
 
struct  DistributedEdge
 An undirected edge of the distributed vertex graph. More...
 
class  EigenproblemEquationSystem
 Equation system specialization for eigenproblems. More...
 
class  EigenproblemESProblemOperator
 Steady-state eigenproblem operator with an equation system. More...
 
class  EigensolverBase
 Base class for eigensolvers. More...
 
class  EquationSystem
 Owns the weak-form mathematics of a MOOSE MFEM problem. More...
 
class  EquationSystemInterface
 Interface required for: More...
 
class  EquationSystemProblemOperator
 Steady-state ProblemOperator that prepares and solves a single EquationSystem. More...
 
class  LinearSolverBase
 Base class for linear MFEM solvers and preconditioners. More...
 
class  LORLinearSolverBase
 Base class for LOR compatible linear MFEM solvers and preconditioners. More...
 
class  MeridionalCurlVectorCoefficient
 Class to compute the meridional curl associated with an azimuthal scalar field A_theta. More...
 
class  NamedFieldsMap
 Lightweight adaptor over an std::map from strings to pointer to T. More...
 
class  NLBoundaryConvectiveHeatFluxIntegrator
 
class  NLCurlCurlIntegrator
 
class  NLCurlCurlJacMatrixCoefficient
 Matrix coefficient for the Jacobian of NLCurlCurlIntegrator. More...
 
class  NLDiffusionIntegrator
 
class  NLScaleIntegrator
 NonlinearFormIntegrator which scales its results by a constant value. More...
 
class  NonlinearSolverBase
 MooseObject base for nonlinear MFEM solve strategies configured in the input file. More...
 
class  ProblemOperator
 Steady-state problem operator with no equation system. More...
 
class  ProblemOperatorBase
 Connects MFEMProblem's MOOSE solver objects to EquationSystem's mathematics. More...
 
class  ScaleIntegrator
 Integrator which scales its results by a constant value. More...
 
struct  SolutionState
 
class  SolverBase
 Base class for wrapping mfem::Solver-derived classes. More...
 
class  SuperLUSolver
 Wrapper for mfem::SuperLUSolver that creates a SuperLURowLocMatrix from the operator when set. More...
 
class  TimeDependentEquationSystem
 Class to store weak form components for time dependent PDEs. More...
 
class  TimeDependentEquationSystemProblemOperator
 Problem operator for time-dependent problems with an equation system. More...
 
class  TimeDependentProblemOperator
 Problem operator for time-dependent problems with no equation system. More...
 
class  TimeDerivativeMap
 Lightweight adaptor over a std::map relating names of GridFunctions with the name of their time derivatives. More...
 
class  TreeCotreeGauge
 Shared implementation of the tree-cotree gauge for an H(curl) (Nedelec) variable, used by both the real (MFEMTreeCotreeGaugeEssentialConstraint) and complex (MFEMComplexTreeCotreeGaugeEssentialConstraint) constraints. More...
 

Typedefs

using FECollections = NamedFieldsMap< mfem::FiniteElementCollection >
 
using FESpaces = NamedFieldsMap< mfem::ParFiniteElementSpace >
 
using SubMeshes = NamedFieldsMap< mfem::ParSubMesh >
 
using GridFunctions = NamedFieldsMap< mfem::ParGridFunction >
 
using ComplexGridFunctions = NamedFieldsMap< mfem::ParComplexGridFunction >
 
using FESpaceHierarchies = NamedFieldsMap< mfem::ParFiniteElementSpaceHierarchy >
 
using Kernels = NamedFieldsMap< MFEMKernel >
 
using BoundaryConditions = NamedFieldsMap< MFEMBoundaryCondition >
 
using Constraints = NamedFieldsMap< MFEMConstraint >
 
using EquationSystems = NamedFieldsMap< EquationSystem >
 
using EigenRHSCoefficient = std::variant< mfem::Coefficient *, mfem::MatrixCoefficient * >
 Scalar or matrix coefficient scaling the eigenproblem right-hand side.
 
using ScalarMap = CoefficientMap< mfem::Coefficient, mfem::PWCoefficient >
 
using VectorMap = CoefficientMap< mfem::VectorCoefficient, mfem::PWVectorCoefficient >
 
using MatrixMap = CoefficientMap< mfem::MatrixCoefficient, mfem::PWMatrixCoefficient >
 

Functions

void subdomainTDofs (mfem::ParFiniteElementSpace &pfes, const mfem::Array< int > &subdomain_markers, bool include_boundary, mfem::Array< int > &ldof_marker, mfem::Array< int > &tdofs)
 Degrees of freedom of pfes belonging to elements whose mesh attribute is set in the attribute marker array subdomain_markers, as returned by MFEMBlockRestrictable::getSubdomainMarkers.
 
void projectCoefficientOnSubdomains (mfem::ParGridFunction &gf, mfem::Coefficient &coef, const mfem::Array< int > &subdomain_markers, const mfem::Array< int > &ldof_marker)
 Overwrite the degrees of freedom of grid function gf marked in the local dof marker ldof_marker with the projection of coefficient coef over the elements whose mesh attribute is set in the attribute marker array subdomain_markers.
 
void projectCoefficientOnSubdomains (mfem::ParGridFunction &gf, mfem::VectorCoefficient &coef, const mfem::Array< int > &subdomain_markers, const mfem::Array< int > &ldof_marker)
 
void zeroTrueDofs (mfem::ParGridFunction &gf, const mfem::Array< int > &tdofs)
 Strongly set the true dofs listed in tdofs of grid function gf to zero, leaving its local vector consistent with the true vector.
 
template<typename T , typename DestinationFn >
std::vector< T > groupByDestination (const std::vector< T > &items, int nprocs, DestinationFn destination, std::vector< int > &counts)
 Group items by the destination rank returned by destination, so they can be handed to allToAll.
 
template<typename T >
std::vector< T > allToAll (const std::vector< T > &send, const std::vector< int > &send_counts, MPI_Comm comm)
 MPI_Alltoallv over a trivially copyable payload.
 
void distributedSpanningForest (std::vector< DistributedEdge > &edges, std::int64_t num_labels, MPI_Comm comm, std::vector< int > *selected, std::vector< std::int64_t > *owned_labels=nullptr)
 Distributed Boruvka over the edges held collectively by the ranks of comm.
 
std::vector< std::int64_t > fetchLabels (const std::vector< std::int64_t > &queries, const std::vector< std::int64_t > &owned_labels, const BlockDistribution &dist, MPI_Comm comm)
 Final component representative of each id in queries, looked up from the distributed label array.
 
std::size_t MFEMIndex (const std::size_t i_dim, const std::size_t i_point, const std::size_t num_dims, const std::size_t num_points, const mfem::Ordering::Type ordering)
 Convert an index of a vector of libMesh::Points to an MFEM vector index, given an MFEM ordering.
 
libMesh::Point libMeshPointFromMFEMVector (const mfem::Vector &vec)
 Convert an MFEM position vector to a libMesh::Point.
 
mfem::Vector libMeshPointsToMFEMVector (const std::vector< libMesh::Point > &points, const unsigned int num_dims, const mfem::Ordering::Type ordering)
 Convert a vector of libMesh::Point objects to an mfem::Vector containing all points, given an ordering.
 
std::vector< Point > generateLinePoints (const Point &start_point, const Point &end_point, unsigned int num_points)
 

Variables

template<typename T , typename... Ts>
constexpr bool is_any_of_v = (std::is_same_v<T, Ts> || ...)
 

Detailed Description

Utilities for converting between vector(s) of libMesh Points and MFEM Vector(s).

Typedef Documentation

◆ BoundaryConditions

Definition at line 251 of file MFEMContainers.h.

◆ ComplexGridFunctions

using Moose::MFEM::ComplexGridFunctions = typedef NamedFieldsMap<mfem::ParComplexGridFunction>

Definition at line 248 of file MFEMContainers.h.

◆ Constraints

Definition at line 252 of file MFEMContainers.h.

◆ EigenRHSCoefficient

using Moose::MFEM::EigenRHSCoefficient = typedef std::variant<mfem::Coefficient *, mfem::MatrixCoefficient *>

Scalar or matrix coefficient scaling the eigenproblem right-hand side.

mfem::Coefficient and mfem::MatrixCoefficient are unrelated types, so no single reference can express both.

Definition at line 24 of file EigenproblemEquationSystem.h.

◆ EquationSystems

Definition at line 253 of file MFEMContainers.h.

◆ FECollections

using Moose::MFEM::FECollections = typedef NamedFieldsMap<mfem::FiniteElementCollection>

Definition at line 244 of file MFEMContainers.h.

◆ FESpaceHierarchies

using Moose::MFEM::FESpaceHierarchies = typedef NamedFieldsMap<mfem::ParFiniteElementSpaceHierarchy>

Definition at line 249 of file MFEMContainers.h.

◆ FESpaces

using Moose::MFEM::FESpaces = typedef NamedFieldsMap<mfem::ParFiniteElementSpace>

Definition at line 245 of file MFEMContainers.h.

◆ GridFunctions

using Moose::MFEM::GridFunctions = typedef NamedFieldsMap<mfem::ParGridFunction>

Definition at line 247 of file MFEMContainers.h.

◆ Kernels

Definition at line 250 of file MFEMContainers.h.

◆ MatrixMap

using Moose::MFEM::MatrixMap = typedef CoefficientMap<mfem::MatrixCoefficient, mfem::PWMatrixCoefficient>

Definition at line 173 of file CoefficientMap.h.

◆ ScalarMap

using Moose::MFEM::ScalarMap = typedef CoefficientMap<mfem::Coefficient, mfem::PWCoefficient>

Definition at line 171 of file CoefficientMap.h.

◆ SubMeshes

using Moose::MFEM::SubMeshes = typedef NamedFieldsMap<mfem::ParSubMesh>

Definition at line 246 of file MFEMContainers.h.

◆ VectorMap

using Moose::MFEM::VectorMap = typedef CoefficientMap<mfem::VectorCoefficient, mfem::PWVectorCoefficient>

Definition at line 172 of file CoefficientMap.h.

Function Documentation

◆ allToAll()

template<typename T >
std::vector< T > Moose::MFEM::allToAll ( const std::vector< T > &  send,
const std::vector< int > &  send_counts,
MPI_Comm  comm 
)

MPI_Alltoallv over a trivially copyable payload.

send holds the outgoing items grouped by destination rank (see groupByDestination), send_counts their per-rank counts. The received items are returned grouped by source rank.

Definition at line 82 of file MFEMDistributedGraph.h.

83{
84 int nprocs;
85 MPI_Comm_size(comm, &nprocs);
86
87 std::vector<int> recv_counts(nprocs);
88 MPI_Alltoall(send_counts.data(), 1, MPI_INT, recv_counts.data(), 1, MPI_INT, comm);
89
90 std::vector<int> send_displs(nprocs, 0), recv_displs(nprocs, 0);
91 std::partial_sum(send_counts.begin(), send_counts.end() - 1, send_displs.begin() + 1);
92 std::partial_sum(recv_counts.begin(), recv_counts.end() - 1, recv_displs.begin() + 1);
93
94 std::vector<T> recv(static_cast<std::size_t>(recv_displs.back()) + recv_counts.back());
95
96 // A contiguous datatype of sizeof(T) bytes keeps the MPI counts in elements
97 // rather than bytes, so a large exchange cannot overflow the int counts.
98 MPI_Datatype item_type;
99 MPI_Type_contiguous(sizeof(T), MPI_BYTE, &item_type);
100 MPI_Type_commit(&item_type);
101 MPI_Alltoallv(send.data(),
102 send_counts.data(),
103 send_displs.data(),
104 item_type,
105 recv.data(),
106 recv_counts.data(),
107 recv_displs.data(),
108 item_type,
109 comm);
110 MPI_Type_free(&item_type);
111
112 return recv;
113}

Referenced by distributedSpanningForest(), and fetchLabels().

◆ distributedSpanningForest()

void Moose::MFEM::distributedSpanningForest ( std::vector< DistributedEdge > &  edges,
std::int64_t  num_labels,
MPI_Comm  comm,
std::vector< int > *  selected,
std::vector< std::int64_t > *  owned_labels = nullptr 
)

Distributed Boruvka over the edges held collectively by the ranks of comm.

Each rank passes only its own edges; nothing is replicated, so the memory used is proportional to this rank's share of the graph.

Because the edge weights are distinct, the minimum spanning forest is unique, so the result is identical to a serial Kruskal pass over the globally sorted edge list and does not depend on how the graph is distributed.

Parameters
edgesthis rank's edges. Endpoint labels are updated in place to the final component representative of each endpoint
num_labelssize of the dense label space the endpoints live in
selectedif non-null, receives origin_index for every edge of this rank that was selected into the spanning forest. Pass nullptr when only the components are wanted
owned_labelsif non-null, receives the final component representative of every label this rank owns under BlockDistribution(num_labels, comm size), ready to be passed to fetchLabels

Definition at line 102 of file MFEMDistributedGraph.C.

107{
108 int nprocs, rank;
109 MPI_Comm_size(comm, &nprocs);
110 MPI_Comm_rank(comm, &rank);
111
112 if (num_labels == 0)
113 {
114 if (owned_labels)
115 owned_labels->clear();
116 return;
117 }
118
119 const BlockDistribution dist(num_labels, nprocs);
120 const std::int64_t owned_begin = dist.begin(rank);
121 const auto num_owned = static_cast<std::size_t>(dist.end(rank) - owned_begin);
122
123 // Global id of an owned slot.
124 auto id_of = [&](std::size_t slot) { return owned_begin + static_cast<std::int64_t>(slot); };
125
126 // Representative of every id this rank owns. Edge endpoints always name a
127 // current representative, but ids absorbed in an earlier round do not, so this
128 // has to be carried forward separately from the per-round hooks below. It costs
129 // an extra exchange per round, so it is only maintained when asked for.
130 std::vector<std::int64_t> label;
131 if (owned_labels)
132 {
133 label.resize(num_owned);
134 std::iota(label.begin(), label.end(), owned_begin);
135 }
136
137 while (true)
138 {
139 // Drop edges whose endpoints have already merged; they are interior to a
140 // component and can never join the forest.
141 edges.erase(std::remove_if(edges.begin(),
142 edges.end(),
143 [](const DistributedEdge & e) { return e.u == e.v; }),
144 edges.end());
145
146 std::int64_t local_active = static_cast<std::int64_t>(edges.size()), global_active = 0;
147 MPI_Allreduce(&local_active, &global_active, 1, MPI_INT64_T, MPI_SUM, comm);
148 if (global_active == 0)
149 break;
150
151 // Offer every remaining edge to the components at both of its ends.
152 std::vector<Proposal> proposals;
153 proposals.reserve(2 * edges.size());
154 for (const auto & e : edges)
155 {
156 proposals.push_back({e.u, e.wu, e.wv, e.v, e.origin_rank, e.origin_index});
157 proposals.push_back({e.v, e.wu, e.wv, e.u, e.origin_rank, e.origin_index});
158 }
159
160 std::vector<int> counts;
161 auto grouped = groupByDestination(
162 proposals, nprocs, [&](const Proposal & p) { return dist.owner(p.component); }, counts);
163 // The ungrouped copy is dead once grouped; release it before the exchange
164 // allocates its own buffers, since this is the largest allocation per round.
165 proposals.clear();
166 proposals.shrink_to_fit();
167 const auto received = allToAll(grouped, counts, comm);
168 grouped.clear();
169 grouped.shrink_to_fit();
170
171 // Each component keeps its lightest incident edge. Distinct weights make the
172 // choice unique, so the forest matches a serial Kruskal pass exactly.
173 std::vector<const Proposal *> best(num_owned, nullptr);
174 for (const auto & p : received)
175 {
176 const auto slot = static_cast<std::size_t>(p.component - owned_begin);
177 if (!best[slot] || p.wu < best[slot]->wu || (p.wu == best[slot]->wu && p.wv < best[slot]->wv))
178 best[slot] = &p;
179 }
180
181 // Tell the owning rank about every edge that was picked. An edge chosen by
182 // both of its endpoints arrives twice; marking it is idempotent.
183 if (selected)
184 {
185 std::vector<Proposal> picks;
186 picks.reserve(num_owned);
187 for (const auto slot : index_range(best))
188 if (best[slot])
189 picks.push_back(*best[slot]);
190
191 std::vector<int> pick_counts;
192 const auto pick_grouped = groupByDestination(
193 picks, nprocs, [](const Proposal & p) { return p.origin_rank; }, pick_counts);
194 for (const auto & p : allToAll(pick_grouped, pick_counts, comm))
195 selected->push_back(p.origin_index);
196 }
197
198 // Hook each component onto the component at the far end of its chosen edge.
199 // A component that received no offer is already a root and hooks to itself.
200 std::vector<std::int64_t> hook(num_owned);
201 for (const auto slot : index_range(best))
202 hook[slot] = best[slot] ? best[slot]->partner : id_of(slot);
203
204 // Two components that chose the same edge point at each other. Root that pair
205 // at the smaller id; every other chain terminates at such a pair, because the
206 // chosen weights strictly decrease along a chain.
207 const auto partner_hook = fetchLabels(hook, hook, dist, comm);
208 for (const auto slot : index_range(hook))
209 if (partner_hook[slot] == id_of(slot))
210 hook[slot] = std::min(id_of(slot), hook[slot]);
211
212 // Pointer-jump until every component points directly at its root.
213 while (true)
214 {
215 const auto grandparent = fetchLabels(hook, hook, dist, comm);
216 std::int64_t local_changed = 0;
217 for (const auto slot : index_range(hook))
218 if (hook[slot] != grandparent[slot])
219 {
220 hook[slot] = grandparent[slot];
221 local_changed = 1;
222 }
223
224 std::int64_t global_changed = 0;
225 MPI_Allreduce(&local_changed, &global_changed, 1, MPI_INT64_T, MPI_MAX, comm);
226 if (global_changed == 0)
227 break;
228 }
229
230 // Carry every id's representative through this round's merge.
231 if (owned_labels)
232 label = fetchLabels(label, hook, dist, comm);
233
234 // Relabel this rank's edges onto the merged components.
235 std::vector<std::int64_t> endpoints;
236 endpoints.reserve(2 * edges.size());
237 for (const auto & e : edges)
238 {
239 endpoints.push_back(e.u);
240 endpoints.push_back(e.v);
241 }
242 const auto relabelled = fetchLabels(endpoints, hook, dist, comm);
243 for (const auto i : index_range(edges))
244 {
245 edges[i].u = relabelled[2 * i];
246 edges[i].v = relabelled[2 * i + 1];
247 }
248 }
249
250 if (owned_labels)
251 *owned_labels = std::move(label);
252}
if(!dmm->_nl) SETERRQ(PETSC_COMM_WORLD
auto min(const L &left, const R &right)
std::vector< std::int64_t > fetchLabels(const std::vector< std::int64_t > &queries, const std::vector< std::int64_t > &owned_labels, const BlockDistribution &dist, MPI_Comm comm)
Final component representative of each id in queries, looked up from the distributed label array.
std::vector< T > groupByDestination(const std::vector< T > &items, int nprocs, DestinationFn destination, std::vector< int > &counts)
Group items by the destination rank returned by destination, so they can be handed to allToAll.
std::vector< T > allToAll(const std::vector< T > &send, const std::vector< int > &send_counts, MPI_Comm comm)
MPI_Alltoallv over a trivially copyable payload.
auto index_range(const T &sizable)

◆ fetchLabels()

std::vector< std::int64_t > Moose::MFEM::fetchLabels ( const std::vector< std::int64_t > &  queries,
const std::vector< std::int64_t > &  owned_labels,
const BlockDistribution &  dist,
MPI_Comm  comm 
)

Final component representative of each id in queries, looked up from the distributed label array.

owned_labels holds the labels of the ids this rank owns under dist.

Definition at line 66 of file MFEMDistributedGraph.C.

70{
71 int nprocs, rank;
72 MPI_Comm_size(comm, &nprocs);
73 MPI_Comm_rank(comm, &rank);
74
75 std::vector<LabelQuery> outgoing(queries.size());
76 for (const auto i : index_range(queries))
77 outgoing[i] = {queries[i], 0, rank, static_cast<int>(i)};
78
79 std::vector<int> counts;
80 const auto grouped = groupByDestination(
81 outgoing, nprocs, [&](const LabelQuery & q) { return dist.owner(q.id); }, counts);
82
83 auto received = allToAll(grouped, counts, comm);
84
85 // Answer from the owned slice, then send each answer straight back to the rank
86 // that asked for it.
87 const std::int64_t owned_begin = dist.begin(rank);
88 for (auto & q : received)
89 q.label = owned_labels[q.id - owned_begin];
90
91 std::vector<int> answer_counts;
92 const auto answers = groupByDestination(
93 received, nprocs, [](const LabelQuery & q) { return q.origin_rank; }, answer_counts);
94
95 std::vector<std::int64_t> labels(queries.size());
96 for (const auto & q : allToAll(answers, answer_counts, comm))
97 labels[q.origin_index] = q.label;
98 return labels;
99}
std::int64_t begin(int rank) const
int owner(std::int64_t g) const
Owning rank of global id g, which must lie in [0, n).

Referenced by distributedSpanningForest().

◆ generateLinePoints()

std::vector< Point > Moose::MFEM::generateLinePoints ( const Point &  start_point,
const Point &  end_point,
unsigned int  num_points 
)

Definition at line 21 of file MFEMVariableSamplerBase.C.

22{
23 // initialize and populate vector with linearly-spaced points along line
24 std::vector<Point> points;
25 points.reserve(num_points);
26 for (const auto i_point : make_range(num_points))
27 {
28 // fractional distance along line [0, 1]
29 Real t = static_cast<Real>(i_point) / static_cast<Real>(num_points - 1);
30 points.push_back(t * end_point + (1 - t) * start_point);
31 }
32
33 return points;
34}

◆ groupByDestination()

template<typename T , typename DestinationFn >
std::vector< T > Moose::MFEM::groupByDestination ( const std::vector< T > &  items,
int  nprocs,
DestinationFn  destination,
std::vector< int > &  counts 
)

Group items by the destination rank returned by destination, so they can be handed to allToAll.

The per-rank counts are written to counts.

Definition at line 54 of file MFEMDistributedGraph.h.

58{
59 // Evaluate the destination once per item and remember it: it can be a binary
60 // search over the splitters, which the placement pass would otherwise repeat.
61 std::vector<int> destinations(items.size());
62 counts.assign(nprocs, 0);
63 for (const auto i : index_range(items))
64 counts[destinations[i] = destination(items[i])]++;
65
66 std::vector<int> offset(nprocs, 0);
67 std::partial_sum(counts.begin(), counts.end() - 1, offset.begin() + 1);
68
69 std::vector<T> grouped(items.size());
70 for (const auto i : index_range(items))
71 grouped[offset[destinations[i]]++] = items[i];
72 return grouped;
73}

Referenced by distributedSpanningForest(), and fetchLabels().

◆ libMeshPointFromMFEMVector()

libMesh::Point Moose::MFEM::libMeshPointFromMFEMVector ( const mfem::Vector &  vec)

Convert an MFEM position vector to a libMesh::Point.

Definition at line 18 of file MFEMVectorUtils.C.

19{
20 return libMesh::Point(vec(0), vec.Size() > 1 ? vec(1) : 0., vec.Size() > 2 ? vec(2) : 0.);
21}

Referenced by MFEMProblem::addFunction().

◆ libMeshPointsToMFEMVector()

mfem::Vector Moose::MFEM::libMeshPointsToMFEMVector ( const std::vector< libMesh::Point > &  points,
const unsigned int  num_dims,
const mfem::Ordering::Type  ordering 
)

Convert a vector of libMesh::Point objects to an mfem::Vector containing all points, given an ordering.

Definition at line 24 of file MFEMVectorUtils.C.

27{
28 const unsigned int num_points = points.size();
29 mfem::Vector mfem_points(num_points * num_dims);
30 for (const auto i_point : make_range(num_points))
31 for (const auto i_dim : make_range(num_dims))
32 mfem_points(MFEMIndex(i_dim, i_point, num_dims, num_points, ordering)) =
33 points[i_point](i_dim);
34
35 return mfem_points;
36}
for(PetscInt i=0;i< nvars;++i)
std::size_t MFEMIndex(const std::size_t i_dim, const std::size_t i_point, const std::size_t num_dims, const std::size_t num_points, const mfem::Ordering::Type ordering)
Convert an index of a vector of libMesh::Points to an MFEM vector index, given an MFEM ordering.

Referenced by MultiAppMFEMTolibMeshShapeEvaluationTransfer::transferVariables().

◆ MFEMIndex()

std::size_t Moose::MFEM::MFEMIndex ( const std::size_t  i_dim,
const std::size_t  i_point,
const std::size_t  num_dims,
const std::size_t  num_points,
const mfem::Ordering::Type  ordering 
)
inline

Convert an index of a vector of libMesh::Points to an MFEM vector index, given an MFEM ordering.

Definition at line 29 of file MFEMVectorUtils.h.

34{
35 if (ordering == mfem::Ordering::byNODES)
36 return mfem::Ordering::Map<mfem::Ordering::byNODES>(num_points, num_dims, i_point, i_dim);
37 else
38 return mfem::Ordering::Map<mfem::Ordering::byVDIM>(num_points, num_dims, i_point, i_dim);
39}

Referenced by MFEMComplexVariableValueSamplerBase::finalize(), MFEMVariableValueSamplerBase::finalize(), libMeshPointsToMFEMVector(), and MFEMNodalProjector::projectNodalValues().

◆ projectCoefficientOnSubdomains() [1/2]

void Moose::MFEM::projectCoefficientOnSubdomains ( mfem::ParGridFunction &  gf,
mfem::Coefficient &  coef,
const mfem::Array< int > &  subdomain_markers,
const mfem::Array< int > &  ldof_marker 
)

Overwrite the degrees of freedom of grid function gf marked in the local dof marker ldof_marker with the projection of coefficient coef over the elements whose mesh attribute is set in the attribute marker array subdomain_markers.

Every marked dof must belong to such an element. The projected values are averaged across all elements and ranks contributing to a shared dof, so they agree on every rank including the one that owns the dof. coef must have the same number of components as the space of gf.

The vector overload works for vector H1 as well as H(curl)/H(div) spaces.

Definition at line 183 of file MFEMConstraintUtils.C.

187{
188 projectOnSubdomains(gf, coef, subdomain_markers, ldof_marker);
189}

Referenced by MFEMComplexScalarEssentialConstraint::ApplyConstraint(), MFEMComplexVectorEssentialConstraint::ApplyConstraint(), MFEMScalarEssentialConstraint::ApplyConstraint(), and MFEMVectorEssentialConstraint::ApplyConstraint().

◆ projectCoefficientOnSubdomains() [2/2]

void Moose::MFEM::projectCoefficientOnSubdomains ( mfem::ParGridFunction &  gf,
mfem::VectorCoefficient &  coef,
const mfem::Array< int > &  subdomain_markers,
const mfem::Array< int > &  ldof_marker 
)

Definition at line 192 of file MFEMConstraintUtils.C.

196{
197 projectOnSubdomains(gf, coef, subdomain_markers, ldof_marker);
198}

◆ subdomainTDofs()

void Moose::MFEM::subdomainTDofs ( mfem::ParFiniteElementSpace &  pfes,
const mfem::Array< int > &  subdomain_markers,
bool  include_boundary,
mfem::Array< int > &  ldof_marker,
mfem::Array< int > &  tdofs 
)

Degrees of freedom of pfes belonging to elements whose mesh attribute is set in the attribute marker array subdomain_markers, as returned by MFEMBlockRestrictable::getSubdomainMarkers.

If include_boundary is false, the dofs on the boundary of the subdomains - those shared with any other element and those on the exterior boundary of the mesh - are left out.

ldof_marker is set to a local dof marker of the selected dofs and tdofs to the matching true-dof indices; both are overwritten. Both are parallel-consistent: a dof shared across a processor boundary that coincides with the subdomain boundary is selected on every rank that touches it, even a rank whose own elements do not carry the attribute.

Definition at line 119 of file MFEMConstraintUtils.C.

124{
125 mfem::ParMesh & pmesh = *pfes.GetParMesh();
126
127 // Local dof markers: ldof_marker is 1 if the dof touches a local element carrying
128 // one of the requested attributes, outside_marker if it touches one that does not.
129 // outside_marker is needed only to exclude the subdomain boundary. All requested
130 // attributes are marked in a single pass so multi-subdomain restrictions are not
131 // clobbered.
132 ldof_marker.SetSize(pfes.GetVSize());
133 ldof_marker = 0;
134 mfem::Array<int> outside_marker;
135 if (!include_boundary)
136 outside_marker.SetSize(pfes.GetVSize(), 0);
137 mfem::Array<int> ldofs;
138 for (const auto e : make_range(pmesh.GetNE()))
139 {
140 const bool inside = subdomain_markers[pmesh.GetAttribute(e) - 1];
141 if (!inside && include_boundary)
142 continue;
143 pfes.GetElementVDofs(e, ldofs);
144 auto & marker = inside ? ldof_marker : outside_marker;
145 for (const auto d : ldofs)
146 marker[mfem::FiniteElementSpace::DecodeDof(d)] = 1; // undo ND/RT sign encoding
147 }
148
149 // Make the marker consistent across processors sharing a dof (boolean-OR).
150 pfes.Synchronize(ldof_marker);
151
152 if (!include_boundary)
153 {
154 // The subdomain boundary consists of the dofs the subdomains share with other
155 // elements, marked above, and those on the exterior boundary of the mesh.
156 // Periodic faces and nonconforming master faces are not exterior, and neither
157 // are faces shared between ranks. GetFaceInformation only tells those apart once
158 // ParMesh::ExchangeFaceNbrData has run, so they are skipped explicitly.
159 std::vector<bool> shared_face(pmesh.GetNumFaces(), false);
160 for (const auto i : make_range(pmesh.GetNSharedFaces()))
161 shared_face[pmesh.GetSharedFace(i)] = true;
162 for (const auto f : make_range(pmesh.GetNumFaces()))
163 if (!shared_face[f] && pmesh.GetFaceInformation(f).IsBoundary())
164 {
165 pfes.GetFaceVDofs(f, ldofs);
166 for (const auto d : ldofs)
167 outside_marker[mfem::FiniteElementSpace::DecodeDof(d)] = 1;
168 }
169 // Synchronizing makes an interface coinciding with a processor boundary visible
170 // on the rank holding only the subdomain side of it.
171 pfes.Synchronize(outside_marker);
172 for (const auto i : make_range(ldof_marker.Size()))
173 ldof_marker[i] = ldof_marker[i] && !outside_marker[i];
174 }
175
176 // Convert the local dof marker to a true dof list exactly as GetEssentialTrueDofs does.
177 mfem::Array<int> tdof_marker;
178 pfes.GetRestrictionMatrix()->BooleanMult(ldof_marker, tdof_marker);
179 mfem::FiniteElementSpace::MarkerToList(tdof_marker, tdofs);
180}

Referenced by Moose::MFEM::TreeCotreeGauge::trueDofs(), and MFEMConstraint::updateSubdomainTDofs().

◆ zeroTrueDofs()

void Moose::MFEM::zeroTrueDofs ( mfem::ParGridFunction &  gf,
const mfem::Array< int > &  tdofs 
)

Strongly set the true dofs listed in tdofs of grid function gf to zero, leaving its local vector consistent with the true vector.

Definition at line 201 of file MFEMConstraintUtils.C.

202{
203 // Go through the true vector so the local vector is left consistent across the
204 // ranks sharing a dof.
205 gf.SetTrueVector();
206 gf.GetTrueVector().SetSubVector(tdofs, 0.);
207 gf.SetFromTrueVector();
208}

Referenced by MFEMComplexTreeCotreeGaugeEssentialConstraint::ApplyConstraint(), and MFEMTreeCotreeGaugeEssentialConstraint::ApplyConstraint().

Variable Documentation

◆ is_any_of_v

template<typename T , typename... Ts>
constexpr bool Moose::MFEM::is_any_of_v = (std::is_same_v<T, Ts> || ...)
constexpr

Definition at line 74 of file MFEMLORLinearSolverBase.h.