https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
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
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
65void
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}
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_INITIAL
Definition Moose.C:30
const ExecFlagType EXEC_LINEAR
Definition Moose.C:31
registerMooseObject("MooseApp", TransformedPositions)
A MultiMooseEnum object to hold "execute_on" flags.
const Positions & getPositionsObject(const std::string &name) const
Get the Positions object by its name.
bool hasUserObject(const std::string &name) const
Check if there if a user object of given name.
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 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.
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 & name() const
Get the name of the class.
Definition MooseBase.h:103
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition MooseEnum.h:55
Positions objects are under the hood Reporters.
Definition Positions.h:21
bool initialized(bool initial) const
Whether the positions object has been initialized.
Definition Positions.C:262
const Point & getPosition(unsigned int index, bool initial) const
Getter for a single position at a known index.
Definition Positions.C:59
unsigned int getNumPositions(bool initial=false) const
}
Definition Positions.h:37
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
Positions transformed using a simple operation (translation, rotation, scaling)
const MooseEnum & _transform
Transformation to perform.
const Point _vector_value
Vector to use for the operation.
TransformedPositions(const InputParameters &parameters)
virtual void initialize() override
In charge of computing / loading the positions.
const Positions * _base_positions
Position object providing the transformed positions.
static InputParameters validParams()
FEProblemBase & _fe_problem
Reference to the FEProblemBase for this user object.
libMesh::Point rotatePointAboutAxis(const libMesh::Point &p, const libMesh::Real angle, const libMesh::Point &axis)
Rotate point about an axis.