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 {
47 
48  std::vector<std::string> var_names(_coupled_moose_vars.size());
49 
50  for (unsigned int i = 0; i < _coupled_moose_vars.size(); i++)
51  {
52  var_names[i] = _coupled_moose_vars[i]->name();
54  }
55 
56  // Initialize the data structures in SamplerBase
57  SamplerBase::setupVariables(var_names);
58 }
59 
60 void
62 {
64 
65  // Check for elemental variables, which are ill-defined on faces for this object
66  for (unsigned int i = 0; i < _coupled_moose_vars.size(); i++)
67  if (!_assembly.getFE(_coupled_moose_vars[i]->feType(), _mesh.dimension())->get_continuity())
69 }
70 
71 void
73 {
74  BoundingBox bbox = _mesh.getInflatedProcessorBoundingBox();
75 
77  std::vector<Point> point_vec(1);
78 
79  for (MooseIndex(_points) i = 0; i < _points.size(); ++i)
80  {
81  Point & p = _points[i];
82 
83  // Do a bounding box check so we're not doing unnecessary PointLocator lookups
84  // In the discontinuous case all ranks must proceed to get a global consensus
85  // on who owns face points in getLocalElemContainingPoint()
86  if (bbox.contains_point(p) || _discontinuous_at_faces)
87  {
88  auto & values = _point_values[i];
89 
90  if (values.empty())
91  values.resize(_coupled_moose_vars.size());
92 
93  // First find the element the hit lands in
94  const Elem * elem = getLocalElemContainingPoint(p);
95 
96  if (elem)
97  {
98  // We have to pass a vector of points into reinitElemPhys
99  point_vec[0] = p;
100 
102  _subproblem.reinitElemPhys(elem, point_vec, 0); // Zero is for tid
103 
104  for (MooseIndex(_coupled_moose_vars) j = 0; j < _coupled_moose_vars.size(); ++j)
105  values[j] = (dynamic_cast<MooseVariableField<Real> *>(_coupled_moose_vars[j]))->sln()[0] *
106  _pp_value; // The zero is for the "qp"
107 
108  _found_points[i] = true;
109  }
110  }
111  }
112 }
113 
114 void
115 PointVariableSamplerBase::setPointsVector(const std::vector<Point> & points)
116 {
117  _points = points;
118 }
119 
120 void
122 {
123  _points = std::move(points);
124 }
VarFieldType
Definition: MooseTypes.h:721
virtual void initialize()
Initialize the datastructures.
Assembly & _assembly
Definition: UserObject.h:219
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()
SubProblem & _subproblem
Reference to the Subproblem for this user object.
Definition: UserObject.h:208
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:60
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:2923
VarKindType
Framework-wide stuff.
Definition: MooseTypes.h:714
void transferPointsVector(std::vector< Point > &&points)
const Real & _pp_value
Postprocessor multiplying the variables.
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:27
std::vector< MooseVariableFieldBase * > _coupled_moose_vars
Vector of all coupled variables.
Definition: Coupleable.h:1412
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:3414
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:124
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:132
void setPointsVector(const std::vector< Point > &points)