https://mooseframework.inl.gov
ComponentMeshTransformHelper.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 "RotationMatrix.h"
12 #include "Factory.h"
13 #include "MooseApp.h"
14 
17 {
18  auto params = ActionComponent::validParams();
19 
20  // If your component is 0D, you should make these two parameters private!
21  params.addParam<RealVectorValue>(
22  "rotation",
23  "Rotation angles (XZX convention, in degrees NOT radians) to rotate the "
24  "mesh of this component with. Note that this rotation "
25  "is applied before the translation.");
26  params.addParam<RealVectorValue>(
27  "direction",
28  "Direction to orient the component mesh with, assuming it is initially oriented along the "
29  "X-axis (1, 0, 0). Note that this rotation is applied before the translation.");
30  // Position is widely applicable to components
31  params.addParam<Point>(
32  "position", Point(0., 0., 0.), "Vector to translate the mesh of this component by.");
33 
34  params.addParamNamesToGroup("rotation direction position",
35  "Position and orientation of the component");
36  return params;
37 }
38 
40  : ActionComponent(params),
41  _rotation(queryParam<RealVectorValue>("rotation")),
42  _direction(queryParam<RealVectorValue>("direction")),
43  _translation(getParam<Point>("position"))
44 {
45  addRequiredTask("add_mesh_generator");
46  checkSecondParamNotSetIfFirstOneSet("rotation", "direction");
47 }
48 
49 void
51 {
52  // Rotate the mesh as desired
53  if (_rotation || _direction)
54  {
55  InputParameters params = _factory.getValidParams("TransformGenerator");
56  params.set<MeshGeneratorName>("input") = _mg_names.back();
57  params.set<MooseEnum>("transform") = "ROTATE";
58  if (_rotation)
59  params.set<RealVectorValue>("vector_value") = *_rotation;
60  else
61  {
62  const auto rotation_matrix =
63  RotationMatrix::rotVec1ToVec2<false>(RealVectorValue(1, 0, 0), *_direction);
64  RealVectorValue angles;
65  angles(0) = std::atan2(rotation_matrix(1, 0), rotation_matrix(0, 0));
66  angles(1) = std::asin(-rotation_matrix(2, 0));
67  angles(2) = std::atan2(rotation_matrix(2, 1), rotation_matrix(2, 2));
68  params.set<RealVectorValue>("vector_value") = angles / M_PI_2 * 90;
69  }
71  "TransformGenerator", name() + "_rotated", params);
72  _mg_names.push_back(name() + "_rotated");
73  }
74 
75  // Add a translation
76  {
77  InputParameters params = _factory.getValidParams("TransformGenerator");
78  params.set<MeshGeneratorName>("input") = _mg_names.back();
79  params.set<MooseEnum>("transform") = "TRANSLATE";
80  params.set<RealVectorValue>("vector_value") = getParam<Point>("position");
82  "TransformGenerator", name() + "_translated", params);
83  _mg_names.push_back(name() + "_translated");
84  }
85 }
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
InputParameters getValidParams(const std::string &name) const
Get valid parameters for the object.
Definition: Factory.C:68
const RealVectorValue *const _direction
Direction vector (easier to conceptualize than rotation)
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
std::vector< MeshGeneratorName > _mg_names
Name(s) of the final mesh generator(s) creating the mesh for the component.
Base class for components that are defined using an action.
virtual const std::string & name() const
Get the name of the class.
Definition: MooseBase.h:57
const RealVectorValue *const _rotation
Rotation angles.
static InputParameters validParams()
void addMeshGenerator(const std::string &type, const std::string &name, const InputParameters &params)
Add a mesh generator that will act on the meshes in the system.
Factory & _factory
The Factory associated with the MooseApp.
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition: MooseEnum.h:33
MooseApp & _app
The MOOSE application this is associated with.
Definition: MooseBase.h:84
void addRequiredTask(const std::string &task)
Add a new required task for all physics deriving from this class NOTE: This does not register the tas...
MeshGeneratorSystem & getMeshGeneratorSystem()
Gets the system that manages the MeshGenerators.
Definition: MooseApp.h:857
void checkSecondParamNotSetIfFirstOneSet(const std::string &param1, const std::string &param2) const
Check that a parameter is not set if the first one is set.
ComponentMeshTransformHelper(const InputParameters &params)