https://mooseframework.inl.gov
MFEMSamplerBase.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #ifdef MOOSE_MFEM_ENABLED
11 
12 #include "MFEMSamplerBase.h"
13 #include "MFEMProblem.h"
14 #include "MFEMVectorUtils.h"
15 #include "MooseError.h"
16 
19 {
21  // The MFEM ordering option names the index that varies fastest in the flattened point vector.
22  MooseEnum ordering("NODES VDIM", "VDIM", false);
23  ordering.addDocumentation("NODES", "Point/node index varies fastest: x0 x1 ... y0 y1 ...");
24  ordering.addDocumentation("VDIM",
25  "Spatial-component index varies fastest: x0 y0 z0 x1 y1 z1 ...");
26  params.addParam<MooseEnum>(
27  "point_ordering", ordering, "Ordering style to use for point vector DoFs.");
28  params.addParam<double>("mesh_boundary_tolerance",
29  1e-8,
30  "Distance from point to mesh boundary below which the point is "
31  "considered to be on the boundary rather than outside the mesh.");
32  return params;
33 }
34 
36  const std::vector<Point> & points,
37  mfem::ParMesh & mesh)
38  : MFEMVectorPostprocessor(parameters),
39  _query_points(points),
40  _mesh(mesh),
41  _finder(this->comm().get()),
42  _points_ordering(getParam<MooseEnum>("point_ordering") == "NODES" ? mfem::Ordering::byNODES
43  : mfem::Ordering::byVDIM),
44  _points(
45  Moose::MFEM::libMeshPointsToMFEMVector(points, _mesh.SpaceDimension(), _points_ordering))
46 {
47  if (getMFEMProblem().mesh().shouldDisplace())
48  mooseError("MFEMSamplerBase does not yet support problems with displacement.");
49 
50  _finder.SetDistanceToleranceForPointsFoundOnBoundary(getParam<double>("mesh_boundary_tolerance"));
51 
52  _mesh.EnsureNodes();
53  _finder.Setup(_mesh);
54  _finder.FindPoints(_points, _points_ordering);
55 
56  const auto mesh_dim = _mesh.SpaceDimension();
57  for (const auto i : make_range(mesh_dim))
58  {
59  auto & declared = this->declareVector("x_" + std::to_string(i));
60  declared.resize(points.size());
61  _declared_points.push_back(declared);
62  }
63 }
64 
65 void
67 {
68  const auto & point_codes = _finder.GetCode();
69  for (const auto i : index_range(_query_points))
70  if (PointLocationCode(point_codes[i]) == PointLocationCode::NOT_FOUND)
71  mooseError(typeAndName(), " could not find point at ", _query_points[i], ".");
72 }
73 
74 void
76 {
77  _points.HostReadWrite();
78 
79  const auto mesh_dim = _mesh.SpaceDimension();
80  const auto num_points = _declared_points[0].get().size();
81  for (const auto i_dim : index_range(_declared_points))
82  for (const auto i_point : make_range(num_points))
83  _declared_points[i_dim].get()[i_point] =
84  _points(Moose::MFEM::MFEMIndex(i_dim, i_point, mesh_dim, num_points, _points_ordering));
85 
87 }
88 
89 #endif // MOOSE_MFEM_ENABLED
mfem::Ordering::Type _points_ordering
Ordering used to store the point coordinates in the MFEM vector.
MFEMProblem & getMFEMProblem()
Return the owning MFEM problem.
Definition: MFEMObject.h:45
virtual void finalizeValues()=0
Copies interpolated values into the subclass VPP vectors.
static InputParameters validParams()
MFEMSamplerBase(const InputParameters &parameters, const std::vector< Point > &points, mfem::ParMesh &mesh)
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.
MeshBase & mesh
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
void finalize() override
Outputs coordinates then delegates value output to finalizeValues().
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition: MooseEnum.h:54
void initialSetup() override
Checks that all query points were found.
std::string typeAndName() const
Get the class&#39;s combined type and name; useful in error handling.
Definition: MooseBase.C:57
VectorPostprocessorValue & declareVector(const std::string &vector_name)
Register a new vector to fill up.
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...
mfem::ParMesh & _mesh
MFEM mesh on which the sampled quantity is defined.
std::vector< std::reference_wrapper< VectorPostprocessorValue > > _declared_points
Declared VPP output vectors for spatial coordinates ("x_0", "x_1", ...).
mfem::FindPointsGSLIB _finder
GSLIB point finder used to locate and interpolate the query points.
PointLocationCode
Classification returned by GSLIB for a query point&#39;s location.
void addDocumentation(const std::string &name, const std::string &doc)
Add an item documentation string.
IntRange< T > make_range(T beg, T end)
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type and optionally a file path to the top-level block p...
Definition: MooseBase.h:271
static InputParameters validParams()
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object...
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
mfem::Vector _points
MFEM vector containing the query-point coordinates.
const std::vector< Point > _query_points
Original query points used for point-location diagnostics.
auto index_range(const T &sizable)
const Elem & get(const ElemType type_in)