https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
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),
40 MooseVariableInterface<Real>(this,
41 false,
42 "variable",
43 Moose::VarKindType::VAR_ANY,
44 Moose::VarFieldType::VAR_FIELD_STANDARD),
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
61}
62
63void
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
77void
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
119void
120PointVariableSamplerBase::setPointsVector(const std::vector<Point> & points)
121{
122 _points = points;
123}
124
125void
127{
128 _points = std::move(points);
129}
std::array< Real, 2 > values
Definition MortarUtils.C:52
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
Intermediate base class that ties together all the interfaces for getting MooseVariableFEBases with t...
std::vector< MooseVariableFieldBase * > _coupled_moose_vars
Vector of all coupled variables.
static InputParameters validParams()
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
void addRequiredCoupledVar(const std::string &name, const std::string &doc_string)
This method adds a coupled variable name pair.
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.
libMesh::BoundingBox getInflatedProcessorBoundingBox(Real inflation_multiplier=0.01) const
Get a (slightly inflated) processor bounding box.
Definition MooseMesh.C:3520
virtual unsigned int dimension() const
Returns MeshBase::mesh_dimension(), (not MeshBase::spatial_dimension()!) of the underlying libMesh me...
Definition MooseMesh.C:2986
void addMooseVariableDependency(MooseVariableFieldBase *var)
Call this function to add the passed in MooseVariableFieldBase as a variable that this object depends...
Interface for objects that need to get values of MooseVariables.
MooseVariableField< Real > & mooseVariableField()
Return the MooseVariableField object that this interface acts on.
Base class for sampling objects (variables, functors etc) at points.
std::vector< Point > _points
The points to evaluate at.
const Elem * getLocalElemContainingPoint(const Point &p)
Find the local element that contains the point.
std::vector< std::vector< Real > > _point_values
Vector of values per point.
const Real & _pp_value
Postprocessor multiplying the variables.
std::vector< short > _found_points
Whether or not the Point was found on this processor (short because bool and char don't work with MPI...
MooseMesh & _mesh
The Mesh we're using.
bool _discontinuous_at_faces
Whether values are requested for objects that are discontinuous on faces.
virtual void initialize()
Called before execute() is ever called so that data can be cleared.
static InputParameters validParams()
void setPointsVector(const std::vector< Point > &points)
virtual void initialize()
Called before execute() is ever called so that data can be cleared.
void transferPointsVector(std::vector< Point > &&points)
std::vector< const MooseArray< Real > * > _var_slns
Variable solutions with inner indexing corresponding to quadrature points.
virtual void execute()
Execute method.
PointVariableSamplerBase(const InputParameters &parameters)
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
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.
static InputParameters validParams()
Definition SamplerBase.C:24
virtual void reinitElemPhys(const Elem *elem, const std::vector< Point > &phys_points_in_elem, const THREAD_ID tid)=0
virtual void setCurrentSubdomainID(const Elem *elem, const THREAD_ID tid)=0
SubProblem & _subproblem
Reference to the Subproblem for this user object.
Assembly & _assembly
Reference to the assembly object for this user object.
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...