https://mooseframework.inl.gov
PointVariableSamplerBase.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 
11 
12 // MOOSE includes
13 #include "MooseMesh.h"
14 #include "Assembly.h"
15 
16 #include "libmesh/mesh_tools.h"
17 
20 {
22 
23  params += SamplerBase::validParams();
24 
25  params.addRequiredCoupledVar(
26  "variable", "The names of the variables that this VectorPostprocessor operates on");
27  params.addParam<PostprocessorName>(
28  "scaling", 1.0, "The postprocessor that the variables are multiplied with");
29  params.addParam<bool>(
30  "warn_discontinuous_face_values",
31  true,
32  "Whether to return a warning if a discontinuous variable is sampled on a face");
33 
34  return params;
35 }
36 
38  : PointSamplerBase(parameters),
41  false,
42  "variable",
45  _var_slns(_coupled_moose_vars.size(), nullptr)
46 {
48 
49  std::vector<std::string> var_names(_coupled_moose_vars.size());
50 
51  for (const auto i : index_range(_coupled_moose_vars))
52  {
53  const auto * const var = _coupled_moose_vars[i];
54  var_names[i] = var->name();
56  _var_slns[i] = &libMesh::cast_ptr<const MooseVariableField<Real> *>(var)->sln();
57  }
58 
59  // Initialize the data structures in SamplerBase
60  SamplerBase::setupVariables(var_names);
61 }
62 
63 void
65 {
67 
68  // Check for elemental variables, which are ill-defined on faces for this object
69  for (const auto * const var : _coupled_moose_vars)
70  {
71  const auto continuity = _assembly.getFE(var->feType(), _mesh.dimension())->get_continuity();
72  if (continuity != libMesh::C_ZERO && continuity != libMesh::C_ONE)
74  }
75 }
76 
77 void
79 {
80  BoundingBox bbox = _mesh.getInflatedProcessorBoundingBox();
81 
83  std::vector<Point> point_vec(1);
84 
85  for (MooseIndex(_points) i = 0; i < _points.size(); ++i)
86  {
87  Point & p = _points[i];
88 
89  // Do a bounding box check so we're not doing unnecessary PointLocator lookups
90  // In the discontinuous case all ranks must proceed to get a global consensus
91  // on who owns face points in getLocalElemContainingPoint()
92  if (bbox.contains_point(p) || _discontinuous_at_faces)
93  {
94  auto & values = _point_values[i];
95 
96  if (values.empty())
97  values.resize(_coupled_moose_vars.size());
98 
99  // First find the element the hit lands in
100  const Elem * elem = getLocalElemContainingPoint(p);
101 
102  if (elem)
103  {
104  // We have to pass a vector of points into reinitElemPhys
105  point_vec[0] = p;
106 
108  _subproblem.reinitElemPhys(elem, point_vec, 0); // Zero is for tid
109 
110  for (const auto j : index_range(_coupled_moose_vars))
111  values[j] = (*_var_slns[j])[0] * _pp_value; // The zero is for the "qp"
112 
113  _found_points[i] = true;
114  }
115  }
116  }
117 }
118 
119 void
120 PointVariableSamplerBase::setPointsVector(const std::vector<Point> & points)
121 {
122  _points = points;
123 }
124 
125 void
127 {
128  _points = std::move(points);
129 }
VarFieldType
Definition: MooseTypes.h:770
virtual void initialize()
Initialize the datastructures.
virtual void execute()
Execute method.
virtual void initialize()
Initialize the datastructures.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
std::vector< Point > _points
The points to evaluate at.
PointVariableSamplerBase(const InputParameters &parameters)
virtual void setCurrentSubdomainID(const Elem *elem, const THREAD_ID tid)=0
static InputParameters validParams()
std::vector< const MooseArray< Real > * > _var_slns
Variable solutions with inner indexing corresponding to quadrature points.
std::vector< std::vector< Real > > _point_values
Vector of values per point.
void setupVariables(const std::vector< std::string > &variable_names)
You MUST call this in the constructor of the child class and pass down the name of the variables...
Definition: SamplerBase.C:69
const Elem * getLocalElemContainingPoint(const Point &p)
Find the local element that contains the point.
std::vector< short > _found_points
Whether or not the Point was found on this processor (short because bool and char don&#39;t work with MPI...
static InputParameters validParams()
virtual unsigned int dimension() const
Returns MeshBase::mesh_dimension(), (not MeshBase::spatial_dimension()!) of the underlying libMesh me...
Definition: MooseMesh.C:2985
VarKindType
Framework-wide stuff.
Definition: MooseTypes.h:763
void transferPointsVector(std::vector< Point > &&points)
SubProblem & _subproblem
Reference to the Subproblem for this user object.
const Real & _pp_value
Postprocessor multiplying the variables.
Assembly & _assembly
Reference to the assembly object for this user object.
bool _discontinuous_at_faces
Whether values are requested for objects that are discontinuous on faces.
Base class for sampling objects (variables, functors etc) at points.
void addRequiredCoupledVar(const std::string &name, const std::string &doc_string)
This method adds a coupled variable name pair.
static InputParameters validParams()
Definition: SamplerBase.C:24
std::vector< MooseVariableFieldBase * > _coupled_moose_vars
Vector of all coupled variables.
Definition: Coupleable.h:1426
virtual void reinitElemPhys(const Elem *elem, const std::vector< Point > &phys_points_in_elem, const THREAD_ID tid)=0
void addMooseVariableDependency(MooseVariableFieldBase *var)
Call this function to add the passed in MooseVariableFieldBase as a variable that this object depends...
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Intermediate base class that ties together all the interfaces for getting MooseVariableFEBases with t...
Interface for objects that need to get values of MooseVariables.
libMesh::BoundingBox getInflatedProcessorBoundingBox(Real inflation_multiplier=0.01) const
Get a (slightly inflated) processor bounding box.
Definition: MooseMesh.C:3519
MooseVariableField< Real > & mooseVariableField()
Return the MooseVariableField object that this interface acts on.
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...
MooseMesh & _mesh
The Mesh we&#39;re using.
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
const FEBase *const & getFE(FEType type, unsigned int dim) const
Get a reference to a pointer that will contain the current volume FE.
Definition: Assembly.h:132
void checkForStandardFieldVariableType(const MooseVariableFieldBase *const var_ptr, const std::string &var_param_name="variable") const
Checks whether the passed variable pointer corresponds to a regular single-valued field variable...
Definition: SamplerBase.C:153
auto index_range(const T &sizable)
void setPointsVector(const std::vector< Point > &points)