Loading [MathJax]/extensions/tex2jax.js
https://mooseframework.inl.gov
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends
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 {
20  params.addClassDescription(
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.addParam<bool>("discontinuous", false, "Indicate that the functors are discontinuous");
28 
29  return params;
30 }
31 
33  : PointSamplerBase(parameters),
35  _positions(_fe_problem.getPositionsObject(getParam<PositionsName>("positions")))
36 {
37  const auto & functor_names = getParam<std::vector<MooseFunctorName>>("functors");
38  for (const auto & functor_name : functor_names)
39  _functors.push_back(&getFunctor<Real>(functor_name));
40 
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 
50 void
52 {
53  // Pull new points
55 
57 }
58 
59 void
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 }
An interface for accessing Moose::Functors for systems that do not care about automatic differentiati...
registerMooseObject("MooseApp", PositionsFunctorValueSampler)
const ExecFlagType & getCurrentExecuteOnFlag() const
Return/set the current execution flag.
Moose::StateArg determineState() const
Create a functor state argument that corresponds to the implicit state of this object.
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.
Samples one or more functor(s) at points given by a Positions object.
A structure that is used to evaluate Moose functors at an arbitrary physical point contained within a...
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...
const Positions & _positions
Positions to sample the functors at.
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:53
static InputParameters validParams()
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...
std::vector< const Moose::Functor< Real > * > _functors
Functors to sample.
const Real & _pp_value
Postprocessor multiplying the variables.
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
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.
virtual void initialize() override
Initialize the datastructures.
FEProblemBase & _fe_problem
Reference to the FEProblemBase for this user object.
Definition: UserObject.h:209
libMesh::BoundingBox getInflatedProcessorBoundingBox(Real inflation_multiplier=0.01) const
Get a (slightly inflated) processor bounding box.
Definition: MooseMesh.C:3408
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
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...
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.
virtual void execute() override
Execute method.
PositionsFunctorValueSampler(const InputParameters &parameters)
auto index_range(const T &sizable)
const ExecFlagType EXEC_INITIAL
Definition: Moose.C:28