https://mooseframework.inl.gov
SymmetryTransformGenerator.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 "CastUniquePointer.h"
12 #include "MooseUtils.h"
13 #include "libmesh/mesh_modification.h"
14 
16 
19 {
21 
22  params.addClassDescription("Applies a symmetry transformation to the entire mesh.");
23  params.addRequiredParam<MeshGeneratorName>("input", "The mesh we want to modify");
25  "mirror_point",
26  "Any point on the plane/line over which the reflection operation will be done");
28  "mirror_normal_vector",
29  "A vector normal to (perpendicular/orthogonal to) the plane/line over which the "
30  "reflection operation will be done");
31 
32  return params;
33 }
34 
36  : MeshGenerator(parameters),
37  _input(getMesh("input")),
38  _mirror_point_vector(getParam<RealEigenVector>("mirror_point")),
39  _mirror_normal_vector(getParam<RealEigenVector>("mirror_normal_vector"))
40 {
41  // enforce 3D coordinates
42  if (_mirror_point_vector.size() != 3)
43  paramError("mirror_point",
44  "mirror_point should be a 3d vector, but only ",
45  _mirror_point_vector.size(),
46  "components were specified.");
47 
48  if (_mirror_normal_vector.size() != 3)
49  paramError("mirror_point",
50  " mirror_normal_vector should be a 3d vector, but only ",
51  _mirror_normal_vector.size(),
52  "components were specified.");
53 
54  // convert normal vector into a unit normal vector
55  const auto norm = _mirror_normal_vector.norm();
57  mooseInfo("Input normal plane vector was not normalized, normalization was performed");
59 }
60 
61 std::unique_ptr<MeshBase>
63 {
64  std::unique_ptr<MeshBase> mesh = std::move(_input);
65 
66  // https://en.wikipedia.org/wiki/Transformation_matrix#Reflection_2
67  // variables renamed for readability and verification
68  const auto a = _mirror_normal_vector[0], b = _mirror_normal_vector[1],
69  c = _mirror_normal_vector[2],
71  0);
72 
73  RealEigenMatrix mirror_transformation(4, 4);
74  mirror_transformation << (1 - 2 * a * a), (-2 * a * b), (-2 * a * c), (-2 * a * d), (-2 * a * b),
75  (1 - 2 * b * b), (-2 * b * c), (-2 * b * d), (-2 * a * c), (-2 * b * c), (1 - 2 * c * c),
76  (-2 * c * d), (0), (0), (0), (1);
77 
78  for (auto & node : mesh->node_ptr_range())
79  {
80  RealEigenVector location_vec(4);
81  location_vec << (*node)(0), (*node)(1), (*node)(2), 1;
82  location_vec = mirror_transformation * location_vec;
83 
84  (*node)(0) = location_vec(0);
85  (*node)(1) = location_vec(1);
86  (*node)(2) = location_vec(2);
87  }
88 
89  // Fix flipped orientation from the symmetry
90  MeshTools::Modification::orient_elements(*mesh);
91 
92  return mesh;
93 }
void mooseInfo(Args &&... args) const
Definition: MooseBase.h:317
std::unique_ptr< MeshBase > & _input
the input mesh
bool absoluteFuzzyEqual(const T &var1, const T2 &var2, const T3 &tol=libMesh::TOLERANCE *libMesh::TOLERANCE)
Function to check whether two variables are equal within an absolute tolerance.
Definition: MooseUtils.h:380
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:435
const RealEigenVector _mirror_point_vector
A point in the mirror plane from which to transform the mesh.
MeshBase & mesh
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...
registerMooseObject("MooseApp", SymmetryTransformGenerator)
SymmetryTransformGenerator(const InputParameters &parameters)
Eigen::Matrix< Real, Eigen::Dynamic, Eigen::Dynamic > RealEigenMatrix
Definition: MooseTypes.h:149
auto norm(const T &a) -> decltype(std::abs(a))
static InputParameters validParams()
Definition: MeshGenerator.C:23
std::unique_ptr< MeshBase > generate() override
Generate / modify the mesh.
static InputParameters validParams()
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...
Eigen::Matrix< Real, Eigen::Dynamic, 1 > RealEigenVector
Definition: MooseTypes.h:146
MeshGenerators are objects that can modify or add to an existing mesh.
Definition: MeshGenerator.h:32
RealEigenVector _mirror_normal_vector
The normal of the mirror plane from which to transform the mesh.