https://mooseframework.inl.gov
FunctorPositions.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 
10 #include "FunctorPositions.h"
11 
13 
16 {
19 
20  params.addRequiredParam<std::vector<MooseFunctorName>>(
21  "positions_functors", "Functors providing the XYZ coordinates of the positions");
22  // Use user-provided ordering
23  params.set<bool>("auto_sort") = false;
24  // All functors defined on all processes for now
25  params.set<bool>("auto_broadcast") = false;
26  // Keep as up-to-date as possible given the generality of functors
27  params.set<ExecFlagEnum>("execute_on") = {EXEC_LINEAR, EXEC_TIMESTEP_BEGIN};
28 
29  params.addClassDescription(
30  "Computes positions from groups of three functors specified by the user");
31  return params;
32 }
33 
35  : Positions(parameters), NonADFunctorInterface(this)
36 
37 {
38  const auto & functor_names = getParam<std::vector<MooseFunctorName>>("positions_functors");
39 
40  // Check input sizes
41  if (functor_names.size() % 3 != 0)
42  paramError("position_functors",
43  "The list of functors must be divisible by three, the number of coordinates");
44 
45  for (const auto & name : functor_names)
46  _pos_functors.push_back(&getFunctor<Real>(name));
47 
48  // Obtain the positions by evaluating the functors
49  initialize();
50  // Sort if needed (user-specified)
51  finalize();
52 }
53 
54 void
56 {
58  const auto n_positions = _pos_functors.size() / 3;
59  _positions.resize(n_positions);
60 
61  // Use the mesh center as a global argument for now
63  // Locate the origin on the mesh
64  const Point p(0, 0, 0);
65  auto pl = _fe_problem.mesh().getMesh().sub_point_locator();
66  auto * const elem = (*pl)(p);
67  if (!elem)
68  mooseError("Origin point not in local mesh, cannot evaluate the functor there");
69  const Moose::ElemPointArg elem_origin = {elem, p, false};
70  const auto t = determineState();
71 
72  for (auto i : make_range(n_positions))
73  _positions[i] = {(*_pos_functors[3 * i])(elem_origin, t),
74  (*_pos_functors[3 * i + 1])(elem_origin, t),
75  (*_pos_functors[3 * i + 2])(elem_origin, t)};
76  _initialized = true;
77 }
An interface for accessing Moose::Functors for systems that do not care about automatic differentiati...
A MultiMooseEnum object to hold "execute_on" flags.
Definition: ExecFlagEnum.h:21
static InputParameters validParams()
Definition: Positions.C:15
void paramError(const std::string &param, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
Definition: MooseBase.h:435
void clearPositions()
Clear all positions vectors.
Definition: Positions.C:154
static InputParameters validParams()
Moose::StateArg determineState() const
Create a functor state argument that corresponds to the implicit state of this object.
Positions objects are under the hood Reporters.
Definition: Positions.h:20
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
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...
bool _initialized
Whether the positions object has been initialized. This must be set by derived objects.
Definition: Positions.h:116
void errorIfDistributedMesh(std::string name) const
Generate a unified error message if the underlying libMesh mesh is a DistributedMesh.
Definition: MooseMesh.C:3617
FunctorPositions(const InputParameters &parameters)
const std::string & name() const
Get the name of the class.
Definition: MooseBase.h:99
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
Definition: MooseMesh.C:3448
std::vector< const Moose::Functor< Real > * > _pos_functors
Vector of pointers to the functors for each coordinate (inner-ordering is coordinates) ...
const ExecFlagType EXEC_TIMESTEP_BEGIN
Definition: Moose.C:37
void initialize() override
In charge of computing / loading the positions.
std::vector< Point > & _positions
For now, only the 1D vector will be shared across all ranks.
Definition: Positions.h:92
const std::string & type() const
Get the type of this class.
Definition: MooseBase.h:89
const ExecFlagType EXEC_LINEAR
Definition: Moose.C:31
registerMooseObject("MooseApp", FunctorPositions)
FEProblemBase & _fe_problem
Reference to the FEProblemBase for this user object.
Definition: UserObject.h:211
IntRange< T > make_range(T beg, T end)
virtual MooseMesh & mesh() override
virtual void finalize() override
In charge of reduction across all ranks & sorting for consistent output.
Definition: Positions.C:220
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type and optionally a file path to the top-level block p...
Definition: MooseBase.h:267
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...
static InputParameters validParams()
Positions from groups of three functors.