https://mooseframework.inl.gov
MFEMVariableValueSamplerBase.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 
13 
14 #include "MFEMProblem.h"
15 #include "MFEMVectorUtils.h"
16 #include "MooseError.h"
17 
18 #include "mfem/fem/fespace.hpp"
19 
22 {
24 }
25 
27  const std::vector<Point> & points)
28  : MFEMVariableSamplerBase(parameters, points),
29  _var(*getMFEMProblem().getGridFunction(_var_name)),
30  _interp_vals(points.size())
31 {
32  // declare value vectors for outputting
33  const auto val_dim = _var.VectorDim();
34  for (const auto i : make_range(val_dim))
35  {
36  auto & declared = this->declareVector(_var_name + "_" + std::to_string(i));
37  declared.resize(points.size());
38  _declared_vals.push_back(declared);
39  }
40 }
41 
42 int
44 {
45  return _var.FESpace()->FEColl()->GetContType();
46 }
47 
48 void
50 {
51  _finder.Interpolate(_var, _interp_vals);
52 }
53 
54 void
56 {
57  _interp_vals.HostReadWrite();
58 
59  const auto val_dims = _var.VectorDim();
60  const auto num_points = _declared_points[0].get().size();
61  const auto val_fespace_ordering = _var.FESpace()->GetOrdering();
62  for (const auto i_dim : make_range(val_dims))
63  for (const auto i_point : make_range(num_points))
64  {
65  const auto mfem_idx =
66  Moose::MFEM::MFEMIndex(i_dim, i_point, val_dims, num_points, val_fespace_ordering);
67  _declared_vals[i_dim].get()[i_point] = _interp_vals[mfem_idx];
68  }
69 }
70 
71 #endif // MOOSE_MFEM_ENABLED
void execute() override
Interpolate the real variable at all query points.
const mfem::GridFunction & _var
Grid function being sampled.
int getFESpaceContinuityType() const override
Return the continuity type of the sampled variable&#39;s finite element collection.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
MFEMVariableValueSamplerBase(const InputParameters &parameters, const std::vector< Point > &points)
Base class for sampling real or complex MFEM variables at points.
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...
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.
IntRange< T > make_range(T beg, T end)
static InputParameters validParams()
std::vector< std::reference_wrapper< VectorPostprocessorValue > > _declared_vals
VectorPostprocessor output columns for the variable components.
void finalizeValues() override
Copies interpolated values into the subclass VPP vectors.
mfem::Vector _interp_vals
Values interpolated from the grid function.
const VariableName _var_name
Name of the variable being sampled.