https://mooseframework.inl.gov
Loading...
Searching...
No Matches
OverlayMeshGenerator.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"
13#include "InputParameters.h"
14
15// libMesh includes
16#include "libmesh/mesh_modification.h"
17#include "libmesh/mesh_tools.h"
18
20
23{
25
27 params.addRequiredParam<MeshGeneratorName>("input", "The base mesh we want to overlay");
28
29 params.addClassDescription("Creates a Cartesian mesh overlaying "
30 "the input mesh region.");
31
32 return params;
33}
34
36 : MeshGenerator(parameters),
37 _dim(getParam<MooseEnum>("dim")),
38 _mesh_name(getParam<MeshGeneratorName>("input"))
39{
40 // Declare that all of the meshes in the "inputs" parameter are to be used by
41 // a sub mesh generator
42 declareMeshForSub("input");
43
45
46 auto input_params = _app.getFactory().getValidParams("DistributedRectilinearMeshGenerator");
47
49 {"dim",
50 "nx",
51 "ny",
52 "nz",
53 "xmin",
54 "ymin",
55 "zmin",
56 "xmax",
57 "ymax",
58 "zmax",
59 "bias_x",
60 "bias_y",
61 "bias_z",
62 "num_side_layers",
63 "num_cores_for_partition",
64 "partition",
65 "elem_type"});
66
67 addMeshSubgenerator("DistributedRectilinearMeshGenerator",
68 _mesh_name + "_distributedrectilinearmeshgenerator",
69 input_params);
70 _build_mesh = &getMeshByName(_mesh_name + "_distributedrectilinearmeshgenerator");
71}
72std::unique_ptr<MeshBase>
74{
75 std::unique_ptr<MeshBase> input_mesh = std::move(*_input_mesh);
76 std::unique_ptr<MeshBase> build_mesh = std::move(*_build_mesh);
77
78 // find the boundary of the input mesh box
79 auto bbox_input = MeshTools::create_bounding_box(*input_mesh);
80
81 // Transform the generated DistributedRectilinearMesh to overlay with the input mesh
82 RealVectorValue scale_factor;
83 scale_factor = bbox_input.max() - bbox_input.min();
84
85 // scale
86 if (scale_factor(0) != 1 || scale_factor(1) != 1 || scale_factor(2) != 1)
87 MeshTools::Modification::scale(*build_mesh, scale_factor(0), scale_factor(1), scale_factor(2));
88
89 RealVectorValue translation_vector;
90 translation_vector = bbox_input.min();
91
92 // translate
93 if (translation_vector(0) != 0 || translation_vector(1) != 0 || translation_vector(2) != 0)
94 MeshTools::Modification::translate(
95 *build_mesh, translation_vector(0), translation_vector(1), translation_vector(2));
96
97 return dynamic_pointer_cast<MeshBase>(build_mesh);
98}
registerMooseObject("MooseApp", OverlayMeshGenerator)
InputParameters getValidParams(const std::string &name) const
Get valid parameters for the object.
Definition Factory.C:68
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
void applySpecificParameters(const InputParameters &common, const std::vector< std::string > &include, bool allow_private=false)
Method for applying common parameters.
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.
MeshGenerators are objects that can modify or add to an existing mesh.
void declareMeshForSub(const std::string &param_name)
Declares that a MeshGenerator referenced in the InputParameters is to be used as a dependency of a su...
void addMeshSubgenerator(const std::string &type, const std::string &name, Ts... extra_input_parameters)
Construct a "subgenerator", a different MeshGenerator subclass that will be added to the same MooseAp...
std::unique_ptr< MeshBase > & getMeshByName(const MeshGeneratorName &mesh_generator_name)
Like getMesh(), but takes the name of another MeshGenerator directly.
static InputParameters validParams()
Factory & getFactory()
Retrieve a writable reference to the Factory associated with this App.
Definition MooseApp.h:407
const InputParameters & parameters() const
Get the parameters of the object.
Definition MooseBase.h:131
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition MooseEnum.h:55
MooseApp & _app
The MOOSE application this is associated with.
Definition MooseBase.h:375
OverlayMeshGenerator(const InputParameters &parameters)
std::unique_ptr< MeshBase > * _input_mesh
Hold the input mesh.
std::unique_ptr< MeshBase > generate() override
Generate / modify the mesh.
std::unique_ptr< MeshBase > * _build_mesh
Hold the generated mesh.
static InputParameters validParams()
const MeshGeneratorName _mesh_name
Name of the input mesh.
libMesh::BoundingBox create_bounding_box(const MeshBase &mesh)