https://mooseframework.inl.gov
TransformGenerator.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 "TransformGenerator.h"
11 #include "libmesh/mesh_modification.h"
12 #include "CastUniquePointer.h"
13 
14 #include "libmesh/mesh_tools.h"
15 
17 
20 {
21  MooseEnum transforms(
22  "TRANSLATE=1 TRANSLATE_CENTER_ORIGIN=2 TRANSLATE_MIN_ORIGIN=3 ROTATE=4 SCALE=5");
23 
25 
26  params.addRequiredParam<MeshGeneratorName>("input", "The mesh we want to modify");
27  params.addClassDescription("Applies a linear transform to the entire mesh.");
29  "transform",
30  transforms,
31  "The type of transformation to perform (TRANSLATE, TRANSLATE_CENTER_ORIGIN, "
32  "TRANSLATE_MIN_ORIGIN, ROTATE, SCALE)");
33  params.addParam<RealVectorValue>(
34  "vector_value",
35  "The value to use for the transformation. When using TRANSLATE or SCALE, the "
36  "xyz coordinates are applied in each direction respectively. When using "
37  "ROTATE, the values are interpreted as the Euler angles phi, theta and psi "
38  "given in degrees.");
39 
40  return params;
41 }
42 
44  : MeshGenerator(parameters),
45  _input(getMesh("input")),
46  _transform(getParam<MooseEnum>("transform"))
47 {
48  if ((_transform != "TRANSLATE_CENTER_ORIGIN" && _transform != "TRANSLATE_MIN_ORIGIN") &&
49  !isParamValid("vector_value"))
50  paramError("transform",
51  "The parameter 'vector_value' must be supplied with 'transform' = ",
52  _transform);
53 }
54 
55 std::unique_ptr<MeshBase>
57 {
58  std::unique_ptr<MeshBase> mesh = std::move(_input);
59 
60  RealVectorValue vector_value;
61  if (_transform == 2 || _transform == 3)
62  {
63  const auto bbox = MeshTools::create_bounding_box(*mesh);
64  if (_transform == 2)
65  vector_value = -0.5 * (bbox.max() + bbox.min());
66  else
67  vector_value = -bbox.min();
68  }
69  else
70  vector_value = getParam<RealVectorValue>("vector_value");
71 
72  switch (_transform)
73  {
74  case 1:
75  case 2:
76  case 3:
77  MeshTools::Modification::translate(*mesh, vector_value(0), vector_value(1), vector_value(2));
78  break;
79  case 4:
80  MeshTools::Modification::rotate(*mesh, vector_value(0), vector_value(1), vector_value(2));
81  break;
82  case 5:
83  MeshTools::Modification::scale(*mesh, vector_value(0), vector_value(1), vector_value(2));
84  break;
85  }
86 
87  mesh->set_isnt_prepared();
88  return dynamic_pointer_cast<MeshBase>(mesh);
89 }
const MooseEnum _transform
the transform to apply to the mesh
static InputParameters validParams()
registerMooseObject("MooseApp", TransformGenerator)
MeshBase & mesh
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
std::unique_ptr< T_DEST, T_DELETER > dynamic_pointer_cast(std::unique_ptr< T_SRC, T_DELETER > &src)
These are reworked from https://stackoverflow.com/a/11003103.
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...
TransformGenerator(const InputParameters &parameters)
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
std::unique_ptr< MeshBase > & _input
the input mesh
std::unique_ptr< MeshBase > generate() override
Generate / modify the mesh.
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition: MooseEnum.h:33
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 ...
static InputParameters validParams()
Definition: MeshGenerator.C:23
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...
MeshGenerators are objects that can modify or add to an existing mesh.
Definition: MeshGenerator.h:32