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 params.addParam<double>("mesh_boundary_tolerance",
22 1e-8,
23 "Distance from point to mesh boundary below which the point is "
24 "considered to be on the boundary rather than outside the mesh.");
25 return params;
26}
27
29 const std::vector<Point> & points,
30 mfem::ParMesh & mesh)
31 : MFEMVectorPostprocessor(parameters),
32 _query_points(points),
33 _mesh(mesh),
34 _finder(this->comm().get()),
35 _points(Moose::MFEM::libMeshPointsToMFEMVector(
36 points, _mesh.SpaceDimension(), mfem::Ordering::byVDIM))
37{
38 if (getMFEMProblem().mesh().shouldDisplace())
39 mooseError("MFEMSamplerBase does not yet support problems with displacement.");
40
41 _finder.SetDistanceToleranceForPointsFoundOnBoundary(getParam<double>("mesh_boundary_tolerance"));
42
43 _mesh.EnsureNodes();
44 _finder.Setup(_mesh);
45 _finder.FindPoints(_points, mfem::Ordering::byVDIM);
46
47 for (const auto i : make_range(_mesh.SpaceDimension()))
48 {
49 auto & declared = this->declareVector("x_" + std::to_string(i));
50 declared.resize(points.size());
51 _declared_points.push_back(declared);
52 }
53}
54
55void
57{
58 const auto & point_codes = _finder.GetCode();
59 for (const auto i : index_range(_query_points))
61 mooseError(typeAndName(), " could not find point at ", _query_points[i], ".");
62
63 for (const auto i_dim : index_range(_declared_points))
64 for (const auto i_point : make_range(_query_points.size()))
65 _declared_points[i_dim].get()[i_point] = _query_points[i_point](i_dim);
66}
67
68#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.
const std::vector< Point > _query_points
Original query points used for point-location diagnostics.
void initialSetup() override
Checks that all query points were found and prepares coordinate output.
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.
Vector postprocessor for MFEM results.
static InputParameters validParams()
std::string typeAndName() const
Get the class'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.
MeshBase & mesh
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...