https://mooseframework.inl.gov
TransformedPositions.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 "TransformedPositions.h"
11 #include "GeometryUtils.h"
12 
14 
17 {
19 
20  params.addRequiredParam<PositionsName>("base_positions",
21  "Positions object providing the positions to transform");
22 
23  MooseEnum transforms("TRANSLATE ROTATE_XYZ SCALE");
25  "transform",
26  transforms,
27  "The type of transformation to perform (TRANSLATE, ROTATE_XYZ, SCALE)");
28  params.addParam<RealVectorValue>(
29  "vector_value",
30  "The value to use for the transformation. When using TRANSLATE or SCALE, the "
31  "xyz coordinates are applied in each direction respectively. When using "
32  "ROTATE_XYZ, the values are interpreted as rotations in degrees around the X, Y and Z axis, "
33  "in that order.");
34 
35  // Use base position ordering
36  params.set<bool>("auto_sort") = false;
37  // If the base position is broadcast already we do not need to
38  params.set<bool>("auto_broadcast") = false;
39  // Keep as up-to-date as possible given that the base position could be changing
40  params.set<ExecFlagEnum>("execute_on") = {EXEC_LINEAR, EXEC_TIMESTEP_BEGIN};
41 
42  params.addClassDescription(
43  "Transform, with a linear transformation, positions from another Positions object");
44  return params;
45 }
46 
48  : Positions(parameters),
49  _transform(getParam<MooseEnum>("transform")),
50  _vector_value(getParam<RealVectorValue>("vector_value"))
51 {
52  const auto & base_name = getParam<PositionsName>("base_positions");
53  if (_fe_problem.hasUserObject(base_name))
55  else
56  mooseError("Base positions has not been created yet. If it exists, re-order Positions objects "
57  "in the input file or implement automated construction ordering for Positions");
58 
59  // Obtain the positions from the base, then transform them
60  initialize();
61  // Sort if needed (user-specified)
62  finalize();
63 }
64 
65 void
67 {
69  const bool initial = _fe_problem.getCurrentExecuteOnFlag() == EXEC_INITIAL;
70  if (!_base_positions->initialized(initial))
71  mooseError("Positions '", _base_positions->name(), "' is not initialized.");
72 
73  const auto n_positions = _base_positions->getNumPositions(initial);
74  _positions.resize(n_positions);
75 
76  for (const auto i : make_range(n_positions))
77  {
78  const auto & base_point = _base_positions->getPosition(i, initial);
79  if (_transform == "ROTATE_XYZ")
83  base_point, _vector_value(0) / 90 * M_PI_2, Point(1, 0, 0)),
84  _vector_value(1) / 90 * M_PI_2,
85  Point(0, 1, 0)),
86  _vector_value(2) / 90 * M_PI_2,
87  Point(0, 0, 1));
88  else if (_transform == "SCALE")
89  _positions[i] = Point(base_point(0) * _vector_value(0),
90  base_point(1) * _vector_value(1),
91  base_point(2) * _vector_value(2));
92  else
93  _positions[i] = Point(base_point(0) + _vector_value(0),
94  base_point(1) + _vector_value(1),
95  base_point(2) + _vector_value(2));
96 
97  _initialized = true;
98  }
99 }
const Point _vector_value
Vector to use for the operation.
A MultiMooseEnum object to hold "execute_on" flags.
Definition: ExecFlagEnum.h:21
TransformedPositions(const InputParameters &parameters)
static InputParameters validParams()
Definition: Positions.C:15
const ExecFlagType & getCurrentExecuteOnFlag() const
Return/set the current execution flag.
void clearPositions()
Clear all positions vectors.
Definition: Positions.C:154
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.
registerMooseObject("MooseApp", TransformedPositions)
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
const Point & getPosition(unsigned int index, bool initial) const
Getter for a single position at a known index.
Definition: Positions.C:59
libMesh::Point rotatePointAboutAxis(const libMesh::Point &p, const libMesh::Real angle, const libMesh::Point &axis)
Rotate point about an axis.
bool hasUserObject(const std::string &name) const
Check if there if a user object of given name.
const Positions & getPositionsObject(const std::string &name) const
Get the Positions object by its name.
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...
Positions transformed using a simple operation (translation, rotation, scaling)
static InputParameters validParams()
bool _initialized
Whether the positions object has been initialized. This must be set by derived objects.
Definition: Positions.h:116
virtual void initialize() override
In charge of computing / loading the positions.
const std::string & name() const
Get the name of the class.
Definition: MooseBase.h:99
const ExecFlagType EXEC_TIMESTEP_BEGIN
Definition: Moose.C:37
const MooseEnum & _transform
Transformation to perform.
std::vector< Point > & _positions
For now, only the 1D vector will be shared across all ranks.
Definition: Positions.h:92
bool initialized(bool initial) const
Whether the positions object has been initialized.
Definition: Positions.C:262
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition: MooseEnum.h:33
unsigned int getNumPositions(bool initial=false) const
}
Definition: Positions.h:37
const ExecFlagType EXEC_LINEAR
Definition: Moose.C:31
const Positions * _base_positions
Position object providing the transformed positions.
FEProblemBase & _fe_problem
Reference to the FEProblemBase for this user object.
Definition: UserObject.h:211
IntRange< T > make_range(T beg, T end)
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...
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...
const ExecFlagType EXEC_INITIAL
Definition: Moose.C:30