https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
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
54void
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 = _subproblem.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}
registerMooseObject("MooseApp", FunctorPositions)
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_TIMESTEP_BEGIN
Definition Moose.C:37
const ExecFlagType EXEC_LINEAR
Definition Moose.C:31
A MultiMooseEnum object to hold "execute_on" flags.
virtual MooseMesh & mesh() override
Positions from groups of three functors.
FunctorPositions(const InputParameters &parameters)
static InputParameters validParams()
void initialize() override
In charge of computing / loading the positions.
std::vector< const Moose::Functor< Real > * > _pos_functors
Vector of pointers to the functors for each coordinate (inner-ordering is coordinates)
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.
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
const std::string & type() const
Get the type of this class.
Definition MooseBase.h:93
const std::string & name() const
Get the name of the class.
Definition MooseBase.h:103
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:457
MeshBase & getMesh()
Accessor for the underlying libMesh Mesh object.
Definition MooseMesh.C:3549
void errorIfDistributedMesh(std::string name) const
Generate a unified error message if the underlying libMesh mesh is a DistributedMesh.
Definition MooseMesh.C:3718
An interface for accessing Moose::Functors for systems that do not care about automatic differentiati...
static InputParameters validParams()
Positions objects are under the hood Reporters.
Definition Positions.h:21
void clearPositions()
Clear all positions vectors.
Definition Positions.C:154
std::vector< Point > & _positions
For now, only the 1D vector will be shared across all ranks.
Definition Positions.h:92
static InputParameters validParams()
Definition Positions.C:15
virtual void finalize() override
In charge of reduction across all ranks & sorting for consistent output.
Definition Positions.C:220
bool _initialized
Whether the positions object has been initialized. This must be set by derived objects.
Definition Positions.h:116
virtual MooseMesh & mesh()=0
Moose::StateArg determineState() const
Create a functor state argument that corresponds to the implicit state of this object.
SubProblem & _subproblem
Reference to the Subproblem for this user 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...