-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23513 from MengnanLi91/overlay_mesh_generator
Build a mesh generator which creates an overlaying mesh over the given mesh
- Loading branch information
Showing
8 changed files
with
202 additions
and
0 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
framework/doc/content/source/meshgenerators/OverlayMeshGenerator.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# OverlayMeshGenerator | ||
|
||
!syntax description /Mesh/OverlayMeshGenerator | ||
|
||
## Overview | ||
|
||
The `OverlayMeshGenerator` object is the built-in mesh generation capable of creating a Cartesian mesh overlaying the given input mesh. The overlay mesh uses [DistributedRectilinearMeshGenerator.md] as sub-generator. The input parameters for DistributedRectilinearMeshGenerator are all available for OverlayMeshGenerator. The required input parameters are [!param](/Mesh/OverlayMeshGenerator/dim) (the dimension of the domain) and [!param](/Mesh/OverlayMeshGenerator/input) (the base mesh we want to overlay). | ||
|
||
## Example Syntax | ||
|
||
!listing test/tests/meshgenerators/overlay_mesh_generator/overlay_mesh_generator.i | ||
block=Mesh | ||
|
||
!syntax parameters /Mesh/OverlayMeshGenerator | ||
|
||
!syntax inputs /Mesh/OverlayMeshGenerator | ||
|
||
!syntax children /Mesh/OverlayMeshGenerator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
//* This file is part of the MOOSE framework | ||
//* https://www.mooseframework.org | ||
//* | ||
//* All rights reserved, see COPYRIGHT for full restrictions | ||
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT | ||
//* | ||
//* Licensed under LGPL 2.1, please see LICENSE for details | ||
//* https://www.gnu.org/licenses/lgpl-2.1.html | ||
|
||
#pragma once | ||
#include "MeshGenerator.h" | ||
|
||
/* | ||
* Mesh generator to create a Overlay mesh | ||
*/ | ||
class OverlayMeshGenerator : public MeshGenerator | ||
{ | ||
public: | ||
static InputParameters validParams(); | ||
OverlayMeshGenerator(const InputParameters & parameters); | ||
std::unique_ptr<MeshBase> generate() override; | ||
|
||
protected: | ||
/// The dimension of the mesh | ||
MooseEnum _dim; | ||
|
||
/// Hold the generated mesh | ||
std::unique_ptr<MeshBase> * _build_mesh; | ||
|
||
/// Name of the input mesh | ||
const MeshGeneratorName _mesh_name; | ||
|
||
/// Hold the input mesh | ||
std::unique_ptr<MeshBase> * _input_mesh; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
//* This file is part of the MOOSE framework | ||
//* https://www.mooseframework.org | ||
//* | ||
//* All rights reserved, see COPYRIGHT for full restrictions | ||
//* https://github.com/idaholab/moose/blob/master/COPYRIGHT | ||
//* | ||
//* Licensed under LGPL 2.1, please see LICENSE for details | ||
//* https://www.gnu.org/licenses/lgpl-2.1.html | ||
|
||
#include "OverlayMeshGenerator.h" | ||
#include "CastUniquePointer.h" | ||
#include "DistributedRectilinearMeshGenerator.h" | ||
#include "InputParameters.h" | ||
|
||
// libMesh includes | ||
#include "libmesh/mesh_modification.h" | ||
#include "libmesh/mesh_tools.h" | ||
|
||
registerMooseObject("MooseApp", OverlayMeshGenerator); | ||
|
||
InputParameters | ||
OverlayMeshGenerator::validParams() | ||
{ | ||
InputParameters params = MeshGenerator::validParams(); | ||
|
||
params += DistributedRectilinearMeshGenerator::validParams(); | ||
params.addRequiredParam<MeshGeneratorName>("input", "The base mesh we want to overlay"); | ||
|
||
params.addClassDescription("Creates a Cartesian mesh overlaying " | ||
"the input mesh region."); | ||
|
||
return params; | ||
} | ||
|
||
OverlayMeshGenerator::OverlayMeshGenerator(const InputParameters & parameters) | ||
: MeshGenerator(parameters), | ||
_dim(getParam<MooseEnum>("dim")), | ||
_mesh_name(getParam<MeshGeneratorName>("input")) | ||
{ | ||
// Declare that all of the meshes in the "inputs" parameter are to be used by | ||
// a sub mesh generator | ||
declareMeshForSub("input"); | ||
|
||
_input_mesh = &getMeshByName(_mesh_name); | ||
|
||
auto input_params = _app.getFactory().getValidParams("DistributedRectilinearMeshGenerator"); | ||
|
||
input_params.applySpecificParameters(parameters, | ||
{"dim", | ||
"nx", | ||
"ny", | ||
"nz", | ||
"xmin", | ||
"ymin", | ||
"zmin", | ||
"xmax", | ||
"ymax", | ||
"zmax", | ||
"bias_x", | ||
"bias_y", | ||
"bias_z", | ||
"num_side_layers", | ||
"num_cores_for_partition", | ||
"partition", | ||
"elem_type"}); | ||
|
||
addMeshSubgenerator("DistributedRectilinearMeshGenerator", | ||
_mesh_name + "_distributedrectilinearmeshgenerator", | ||
input_params); | ||
_build_mesh = &getMeshByName(_mesh_name + "_distributedrectilinearmeshgenerator"); | ||
} | ||
std::unique_ptr<MeshBase> | ||
OverlayMeshGenerator::generate() | ||
{ | ||
std::unique_ptr<MeshBase> input_mesh = std::move(*_input_mesh); | ||
std::unique_ptr<MeshBase> build_mesh = std::move(*_build_mesh); | ||
|
||
// find the boundary of the input mesh box | ||
auto bbox_input = MeshTools::create_bounding_box(*input_mesh); | ||
|
||
// Transform the generated DistributedRectilinearMesh to overlay with the input mesh | ||
RealVectorValue scale_factor; | ||
scale_factor = bbox_input.max() - bbox_input.min(); | ||
|
||
// scale | ||
if (scale_factor(0) != 1 || scale_factor(1) != 1 || scale_factor(2) != 1) | ||
MeshTools::Modification::scale(*build_mesh, scale_factor(0), scale_factor(1), scale_factor(2)); | ||
|
||
RealVectorValue translation_vector; | ||
translation_vector = bbox_input.min(); | ||
|
||
// translate | ||
if (translation_vector(0) != 0 || translation_vector(1) != 0 || translation_vector(2) != 0) | ||
MeshTools::Modification::translate( | ||
*build_mesh, translation_vector(0), translation_vector(1), translation_vector(2)); | ||
|
||
return dynamic_pointer_cast<MeshBase>(build_mesh); | ||
} |
Binary file added
BIN
+6.84 KB
test/tests/meshgenerators/overlay_mesh_generator/gold/overlay_mesh_generator_in.e
Binary file not shown.
26 changes: 26 additions & 0 deletions
26
test/tests/meshgenerators/overlay_mesh_generator/overlay_mesh_generator.i
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
[Mesh] | ||
[gmg] | ||
type = GeneratedMeshGenerator | ||
dim = 2 | ||
nx = 3 | ||
ny = 3 | ||
xmin = -1 | ||
xmax = 4 | ||
ymin = -1 | ||
ymax = 2.2 | ||
output = true | ||
[] | ||
[bcg] | ||
type = OverlayMeshGenerator | ||
input = 'gmg' | ||
dim = 2 | ||
nx = 6 | ||
ny = 6 | ||
[] | ||
[] | ||
|
||
[Outputs] | ||
exodus = true | ||
[] | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[Tests] | ||
issues = '#23513' | ||
design = 'meshgenerators/OverlayMeshGenerator.md' | ||
[Test] | ||
requirement = 'The system shall be able to create in a distributed manner a rectilinear mesh overlaying a given mesh.' | ||
type = 'Exodiff' | ||
input = 'overlay_mesh_generator.i' | ||
cli_args = '--mesh-only' | ||
exodiff = 'overlay_mesh_generator_in.e' | ||
mesh_mode = 'REPLICATED' | ||
recover = false | ||
[] | ||
[] |