Skip to content

Commit

Permalink
Add TRANSLATE_CENTER_ORIGIN and TRANSLATE_MIN_ORIGIN to TransformGene…
Browse files Browse the repository at this point in the history
…rator

refs idaholab#16927
  • Loading branch information
loganharbour committed Feb 8, 2021
1 parent 72dd96f commit 29f32e0
Show file tree
Hide file tree
Showing 11 changed files with 126 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@
## Overview

The Transform MeshGenerator applies one of three linear transformations
(TRANSLATE, ROTATE, or SCALE) to the entire mesh. Several independent modifiers
may be executed in a specific order to perform more complex transformations.
(TRANSLATE, ROTATE, or SCALE) to the entire mesh.
In addition, the following specific translations are available:

- `TRANSLATE_CENTER_ORIGIN`: Translates the center of the mesh to be at the origin
- `TRANSLATE_MIN_ORIGIN`: Translates the minimum of the mesh to be at the origin

Several independent modifiers may be executed in a specific order to perform more complex transformations.
This class simply calls through to the methods in libMesh's
[MeshTools::Modification](https://libmesh.github.io/doxygen/namespacelibMesh_1_1MeshTools_1_1Modification.html)
[MeshTools::Modification](https://mooseframework.inl.gov/docs/doxygen/libmesh/namespacelibMesh_1_1MeshTools_1_1Modification.html)
namespace.

!syntax parameters /Mesh/TransformGenerator
Expand Down
4 changes: 1 addition & 3 deletions framework/include/meshgenerators/TransformGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,5 @@ class TransformGenerator : public MeshGenerator
protected:
std::unique_ptr<MeshBase> & _input;

MooseEnum _transform;
RealVectorValue _vector_value;
const MooseEnum _transform;
};

48 changes: 37 additions & 11 deletions framework/src/meshgenerators/TransformGenerator.C
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,28 @@
#include "libmesh/mesh_modification.h"
#include "CastUniquePointer.h"

#include "libmesh/mesh_tools.h"

registerMooseObject("MooseApp", TransformGenerator);

defineLegacyParams(TransformGenerator);

InputParameters
TransformGenerator::validParams()
{
MooseEnum transforms("TRANSLATE=1 ROTATE=2 SCALE=3");
MooseEnum transforms(
"TRANSLATE=1 TRANSLATE_CENTER_ORIGIN=2 TRANSLATE_MIN_ORIGIN=3 ROTATE=4 SCALE=5");

InputParameters params = MeshGenerator::validParams();

params.addRequiredParam<MeshGeneratorName>("input", "The mesh we want to modify");
params.addClassDescription("Applies a linear transform to the entire mesh.");
params.addRequiredParam<MooseEnum>(
"transform", transforms, "The type of transformation to perform (TRANSLATE, ROTATE, SCALE)");
params.addRequiredParam<RealVectorValue>(
"transform",
transforms,
"The type of transformation to perform (TRANSLATE, TRANSLATE_CENTER_ORIGIN, "
"TRANSLATE_MIN_ORIGIN, ROTATE, SCALE)");
params.addParam<RealVectorValue>(
"vector_value",
"The value to use for the transformation. When using TRANSLATE or SCALE, the "
"xyz coordinates are applied in each direction respectively. When using "
Expand All @@ -39,27 +45,47 @@ TransformGenerator::validParams()
TransformGenerator::TransformGenerator(const InputParameters & parameters)
: MeshGenerator(parameters),
_input(getMesh("input")),
_transform(getParam<MooseEnum>("transform")),
_vector_value(getParam<RealVectorValue>("vector_value"))
_transform(getParam<MooseEnum>("transform"))
{
if ((_transform != "TRANSLATE_CENTER_ORIGIN" && _transform != "TRANSLATE_MIN_ORIGIN") &&
!isParamValid("vector_value"))
paramError("transform",
"The parameter 'vector_value' must be supplied with 'transform' = ",
_transform);
}

std::unique_ptr<MeshBase>
TransformGenerator::generate()
{
std::unique_ptr<MeshBase> mesh = std::move(_input);

RealVectorValue vector_value;
if (_transform == 2 || _transform == 3)
{
const auto bbox = MeshTools::create_bounding_box(*mesh);
if (_transform == 2)
{
const auto center = 0.5 * (bbox.max() + bbox.min());
vector_value = -center;
}
else
vector_value = -bbox.min();
}
else
vector_value = getParam<RealVectorValue>("vector_value");

switch (_transform)
{
case 1:
MeshTools::Modification::translate(
*mesh, _vector_value(0), _vector_value(1), _vector_value(2));
break;
case 2:
MeshTools::Modification::rotate(*mesh, _vector_value(0), _vector_value(1), _vector_value(2));
break;
case 3:
MeshTools::Modification::scale(*mesh, _vector_value(0), _vector_value(1), _vector_value(2));
MeshTools::Modification::translate(*mesh, vector_value(0), vector_value(1), vector_value(2));
break;
case 4:
MeshTools::Modification::rotate(*mesh, vector_value(0), vector_value(1), vector_value(2));
break;
case 5:
MeshTools::Modification::scale(*mesh, vector_value(0), vector_value(1), vector_value(2));
break;
}

Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
40 changes: 33 additions & 7 deletions test/tests/meshgenerators/transform_generator/tests
Original file line number Diff line number Diff line change
@@ -1,12 +1,38 @@
[Tests]
[./transform_generator_test]
design = 'meshgenerators/TransformGenerator.md'
issues = '#11640 #16927'

[rotate_and_scale]
type = 'Exodiff'
input = 'rotate_and_scale.i'
exodiff = 'rotate_and_scale_out.e'
exodiff = 'rotate_and_scale_in.e'
requirement = "The system shall include the ability to rotate and scale a finite element mesh."
design = 'meshgenerators/TransformGenerator.md'
issues = '#11640'
mesh_mode = 'REPLICATED'
recover = false
[../]
cli_args = '--mesh-only'
[]

[translate]
requirement = "The system shall include the ability to translate a finite element mesh in a manner that"

[user_set]
type = 'Exodiff'
input = 'translate.i'
exodiff = 'translate_in.e'
cli_args = '--mesh-only'
detail = 'is defined by the user,'
[]
[center_origin]
type = 'Exodiff'
input = 'translate_center_origin.i'
exodiff = 'translate_center_origin_in.e'
cli_args = '--mesh-only'
detail = 'places the center of the mesh at the origin, or'
[]
[min_origin]
type = 'Exodiff'
input = 'translate_min_origin.i'
exodiff = 'translate_min_origin_in.e'
cli_args = '--mesh-only'
detail = 'places the minimum of the mesh at the origin.'
[]
[]
[]
15 changes: 15 additions & 0 deletions test/tests/meshgenerators/transform_generator/translate.i
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[Mesh]
[gmg]
type = GeneratedMeshGenerator
dim = 2
nx = 2
ny = 2
[]

[translate]
type = TransformGenerator
input = gmg
transform = translate
# vector_value = '1 2 0'
[]
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[Mesh]
[gmg]
type = GeneratedMeshGenerator
dim = 2
nx = 2
ny = 2
[]

[translate]
type = TransformGenerator
input = gmg
transform = translate_center_origin
[]
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[Mesh]
[gmg]
type = GeneratedMeshGenerator
dim = 2
nx = 2
ny = 2
xmin = 1
xmax = 2
ymin = 3
ymax = 4
[]

[translate]
type = TransformGenerator
input = gmg
transform = translate_min_origin
[]
[]

0 comments on commit 29f32e0

Please sign in to comment.