https://mooseframework.inl.gov
Loading...
Searching...
No Matches
PositionsFunctorValueSampler.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#include "Positions.h"
12#include "FEProblemBase.h"
13
15
18{
21 "Sample one or more functors at points specified by a Positions object.");
22 params.addRequiredParam<PositionsName>(
23 "positions",
24 "Positions object specifying the points where you want to evaluate the functors");
25 params.addRequiredParam<std::vector<MooseFunctorName>>(
26 "functors", "The functors we want to evaluate at the positions");
27 params.addRequiredParam<bool>("discontinuous", "Indicate whether the functors are discontinuous");
28
29 return params;
30}
31
33 : PointSamplerBase(parameters),
34 _positions(_fe_problem.getPositionsObject(getParam<PositionsName>("positions")))
35{
36 const auto & functor_names = getParam<std::vector<MooseFunctorName>>("functors");
37 for (const auto & functor_name : functor_names)
38 _functors.push_back(&getFunctor<Real>(functor_name));
39
40 // Checks all elements around the face when discontinuous
41 _discontinuous_at_faces = getParam<bool>("discontinuous");
42
43 // Initialize the data structures in SamplerBase
44 std::vector<std::string> functor_string_names;
45 for (const auto & functor_name : functor_names)
46 functor_string_names.push_back(functor_name);
47 SamplerBase::setupVariables(functor_string_names);
48}
49
50void
58
59void
61{
62 BoundingBox bbox = _mesh.getInflatedProcessorBoundingBox();
63 const auto state = determineState();
64
65 // Pull new points
66 const auto old_size = _points.size();
68 if (_points.size() != old_size)
69 mooseError("The points array has grown since initialize() was called");
70
71 for (const auto i : index_range(_points))
72 {
73 const Point & p = _points[i];
74
75 // Do a bounding box check so we're not doing unnecessary PointLocator lookups
76 // In the discontinuous case all ranks must proceed to get a global consensus
77 // on who owns face points in getLocalElemContainingPoint()
78 if (bbox.contains_point(p) || _discontinuous_at_faces)
79 {
80 auto & values = _point_values[i];
81
82 if (values.empty())
83 values.resize(_functors.size());
84
85 // First find the element the hit lands in
86 const Elem * elem = getLocalElemContainingPoint(p);
87
88 if (elem)
89 {
90 Moose::ElemPointArg elem_point_arg = {elem, p, false};
91 for (const auto j : index_range(_functors))
92 values[j] = (*_functors[j])(elem_point_arg, state) * _pp_value;
93
94 _found_points[i] = true;
95 }
96 }
97 }
98}
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
const ExecFlagType EXEC_INITIAL
Definition Moose.C:30
std::array< Real, 2 > values
Definition MortarUtils.C:52
registerMooseObject("MooseApp", PositionsFunctorValueSampler)
const ExecFlagType & getCurrentExecuteOnFlag() const
Return/set the current execution flag.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
void addRequiredParam(const std::string &name, const std::string &doc_string)
This method adds a parameter and documentation string to the InputParameters object that will be extr...
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump.
libMesh::BoundingBox getInflatedProcessorBoundingBox(Real inflation_multiplier=0.01) const
Get a (slightly inflated) processor bounding box.
Definition MooseMesh.C:3520
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.
static InputParameters validParams()
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.
Samples one or more functor(s) at points given by a Positions object.
PositionsFunctorValueSampler(const InputParameters &parameters)
virtual void execute() override
Execute method.
virtual void initialize() override
Called before execute() is ever called so that data can be cleared.
std::vector< const Moose::Functor< Real > * > _functors
Functors to sample.
const Positions & _positions
Positions to sample the functors at.
const std::vector< Point > & getPositions(bool initial) const
{ Getters for the positions vector for the desired dimension 1D will be the only one guaranteed to su...
Definition Positions.C:116
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
Moose::StateArg determineState() const
Create a functor state argument that corresponds to the implicit state of this object.
FEProblemBase & _fe_problem
Reference to the FEProblemBase for this user object.
A structure that is used to evaluate Moose functors at an arbitrary physical point contained within a...