https://mooseframework.inl.gov
Public Member Functions | List of all members
MFEMNodalProjector Class Reference

Auxiliary class to extract locations of nodes in MFEM GridFunctions and project values defined at them to set DoFs. More...

#include <MFEMNodalProjector.h>

Public Member Functions

 MFEMNodalProjector ()=default
 
void extractNodePositions (const mfem::ParFiniteElementSpace &fespace, mfem::Vector &node_positions, mfem::Ordering::Type &node_ordering)
 Extract node positions from MFEM FESpace at which projection will take place. More...
 
void projectNodalValues (const mfem::Vector &nodal_vals, const mfem::Ordering::Type &nodal_val_ordering, mfem::ParGridFunction &gridfunction)
 Project a vector of values provided at projection points (nodes) to set GridFunction DoFs. More...
 

Detailed Description

Auxiliary class to extract locations of nodes in MFEM GridFunctions and project values defined at them to set DoFs.

Definition at line 22 of file MFEMNodalProjector.h.

Constructor & Destructor Documentation

◆ MFEMNodalProjector()

MFEMNodalProjector::MFEMNodalProjector ( )
default

Member Function Documentation

◆ extractNodePositions()

void MFEMNodalProjector::extractNodePositions ( const mfem::ParFiniteElementSpace &  fespace,
mfem::Vector &  node_positions,
mfem::Ordering::Type &  node_ordering 
)

Extract node positions from MFEM FESpace at which projection will take place.

Definition at line 17 of file MFEMNodalProjector.C.

Referenced by MultiApplibMeshToMFEMShapeEvaluationTransfer::transferVariables(), and MultiAppMFEMShapeEvaluationTransfer::transferVariables().

20 {
21  const int nelem = fespace.GetParMesh()->GetNE();
22  const int dim = fespace.GetParMesh()->Dimension();
23 
24  // Find total number of local nodes/interpolation points
25  int nnodes = 0;
26  for (const auto i : make_range(nelem))
27  nnodes += fespace.GetFE(i)->GetNodes().GetNPoints();
28 
29  node_positions.SetSize(nnodes * dim);
30 
31  int nodal_offset = 0;
32  for (const auto i : make_range(nelem))
33  {
34  const mfem::IntegrationRule ir = fespace.GetFE(i)->GetNodes();
35  const int nqpt = ir.GetNPoints();
36 
37  mfem::DenseMatrix pos;
38  fespace.GetElementTransformation(i)->Transform(ir, pos);
39  mfem::Vector row;
40 
41  for (const auto d : make_range(dim))
42  {
43  row.SetDataAndSize(node_positions.GetData() + nodal_offset + d * nnodes, nqpt);
44  pos.GetRow(d, row);
45  }
46 
47  nodal_offset += nqpt;
48  }
49  node_ordering = mfem::Ordering::Type::byNODES;
50 }
static constexpr std::size_t dim
This is the dimension of all vector and tensor datastructures used in MOOSE.
Definition: Moose.h:163
IntRange< T > make_range(T beg, T end)

◆ projectNodalValues()

void MFEMNodalProjector::projectNodalValues ( const mfem::Vector &  nodal_vals,
const mfem::Ordering::Type &  nodal_val_ordering,
mfem::ParGridFunction &  gridfunction 
)

Project a vector of values provided at projection points (nodes) to set GridFunction DoFs.

Definition at line 53 of file MFEMNodalProjector.C.

Referenced by MultiApplibMeshToMFEMShapeEvaluationTransfer::transferVariables(), and MultiAppMFEMShapeEvaluationTransfer::transferVariables().

56 {
57  mfem::ParFiniteElementSpace & fespace = *gridfunction.ParFESpace();
58  const int nelem = fespace.GetParMesh()->GetNE();
59  const int gf_ncomp = gridfunction.VectorDim();
60 
61  fespace.GetParMesh()->EnsureNodes();
62 
63  // Check FESpaces can be transferred
64  const auto map = fespace.FEColl()->GetMapType(fespace.GetParMesh()->Dimension());
65  const bool H1L2 = map == mfem::FiniteElement::VALUE || map == mfem::FiniteElement::INTEGRAL;
66  const bool RTND = map == mfem::FiniteElement::H_DIV || map == mfem::FiniteElement::H_CURL;
67  if (!H1L2 && !RTND)
68  mooseError("FESpace type not supported yet in transfers.");
69 
70  // Project the interpolated values to the target FiniteElementSpace.
71  mfem::Ordering::Type dof_ordering = H1L2 ? mfem::Ordering::byNODES : mfem::Ordering::byVDIM;
72  mfem::Array<int> vdofs;
73  mfem::Vector vals;
74  int nodal_offset = 0;
75  for (const auto el : make_range(nelem))
76  {
77  const int nqpt = fespace.GetFE(el)->GetNodes().GetNPoints();
78  mfem::Vector dof_vals(nqpt * gf_ncomp);
79  fespace.GetElementVDofs(el, vdofs); // Returned vdofs always indexed with ordering byNODES
80  for (const auto qp : make_range(nqpt))
81  for (const auto d : make_range(gf_ncomp))
82  dof_vals(Moose::MFEM::MFEMIndex(d, qp, gf_ncomp, nqpt, dof_ordering)) = nodal_vals(
83  Moose::MFEM::MFEMIndex(d, qp, gf_ncomp, nqpt, nodal_val_ordering) + nodal_offset);
84 
85  if (H1L2)
86  gridfunction.SetSubVector(vdofs, dof_vals);
87  else if (RTND)
88  {
89  vals.SetSize(vdofs.Size());
90  fespace.GetFE(el)->ProjectFromNodes(dof_vals, *fespace.GetElementTransformation(el), vals);
91  gridfunction.SetSubVector(vdofs, vals);
92  }
93 
94  nodal_offset += nqpt * gf_ncomp;
95  }
96  gridfunction.SetTrueVector();
97 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:311
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...
IntRange< T > make_range(T beg, T end)

The documentation for this class was generated from the following files: