https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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");
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").getEnum<mfem::Ordering::Type>()),
43 _points(
44 Moose::MFEM::libMeshPointsToMFEMVector(points, _mesh.SpaceDimension(), _points_ordering))
45{
46 if (getMFEMProblem().mesh().shouldDisplace())
47 mooseError("MFEMSamplerBase does not yet support problems with displacement.");
48
49 _finder.SetDistanceToleranceForPointsFoundOnBoundary(getParam<double>("mesh_boundary_tolerance"));
50
51 _mesh.EnsureNodes();
52 _finder.Setup(_mesh);
53 _finder.FindPoints(_points, _points_ordering);
54
55 const auto mesh_dim = _mesh.SpaceDimension();
56 for (const auto i : make_range(mesh_dim))
57 {
58 auto & declared = this->declareVector("x_" + std::to_string(i));
59 declared.resize(points.size());
60 _declared_points.push_back(declared);
61 }
62}
63
64void
66{
67 const auto & point_codes = _finder.GetCode();
68 for (const auto i : index_range(_query_points))
70 mooseError(typeAndName(), " could not find point at ", _query_points[i], ".");
71}
72
73void
75{
76 _points.HostReadWrite();
77
78 const auto mesh_dim = _mesh.SpaceDimension();
79 const auto num_points = _declared_points[0].get().size();
80 for (const auto i_dim : index_range(_declared_points))
81 for (const auto i_point : make_range(num_points))
82 _declared_points[i_dim].get()[i_point] =
83 _points(Moose::MFEM::MFEMIndex(i_dim, i_point, mesh_dim, num_points, _points_ordering));
84
86}
87
88#endif // MOOSE_MFEM_ENABLED
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
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.
MFEMProblem & getMFEMProblem()
Return the owning MFEM problem.
Definition MFEMObject.h:45
mfem::FindPointsGSLIB _finder
GSLIB point finder used to locate and interpolate the query points.
static InputParameters validParams()
mfem::ParMesh & _mesh
MFEM mesh on which the sampled quantity is defined.
PointLocationCode
Classification returned by GSLIB for a query point's location.
void finalize() override
Outputs coordinates then delegates value output to finalizeValues().
const std::vector< Point > _query_points
Original query points used for point-location diagnostics.
virtual void finalizeValues()=0
Copies interpolated values into the subclass VPP vectors.
void initialSetup() override
Checks that all query points were found.
mfem::Ordering::Type _points_ordering
Ordering used to store the point coordinates in the MFEM vector.
MFEMSamplerBase(const InputParameters &parameters, const std::vector< Point > &points, mfem::ParMesh &mesh)
std::vector< std::reference_wrapper< VectorPostprocessorValue > > _declared_points
Declared VPP output vectors for spatial coordinates ("x_0", "x_1", ...).
mfem::Vector _points
MFEM vector containing the query-point coordinates.
static InputParameters validParams()
std::string typeAndName() const
Get the class's combined type and name; useful in error handling.
Definition MooseBase.C:57
void addDocumentation(const std::string &name, const std::string &doc)
Add an item documentation string.
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition MooseEnum.h:55
VectorPostprocessorValue & declareVector(const std::string &vector_name)
Register a new vector to fill up.
MeshBase & mesh
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.
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...