Skip to content

Commit

Permalink
Merge pull request #23513 from MengnanLi91/overlay_mesh_generator
Browse files Browse the repository at this point in the history
Build a mesh generator which creates an overlaying mesh over the given mesh
  • Loading branch information
MengnanLi91 committed Jan 31, 2024
2 parents 1fbb5aa + 53edc62 commit 6c4b5ec
Show file tree
Hide file tree
Showing 8 changed files with 202 additions and 0 deletions.
@@ -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
3 changes: 3 additions & 0 deletions framework/include/mesh/MooseMesh.h
Expand Up @@ -151,6 +151,9 @@ class MooseMesh : public MooseObject, public Restartable, public PerfGraphInterf
/// returns MooseMesh partitioning options so other classes can use it
static MooseEnum partitioning();

/// returns MooseMesh element type options
static MooseEnum elemTypes();

/**
* Initialize the Mesh object. Most of the time this will turn around
* and call build_mesh so the child class can build the Mesh object.
Expand Down
35 changes: 35 additions & 0 deletions framework/include/meshgenerators/OverlayMeshGenerator.h
@@ -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;
};
9 changes: 9 additions & 0 deletions framework/src/mesh/MooseMesh.C
Expand Up @@ -3641,6 +3641,15 @@ MooseMesh::partitioning()
return partitioning;
}

MooseEnum
MooseMesh::elemTypes()
{
MooseEnum elemTypes(
"EDGE EDGE2 EDGE3 EDGE4 QUAD QUAD4 QUAD8 QUAD9 TRI3 TRI6 HEX HEX8 HEX20 HEX27 TET4 TET10 "
"PRISM6 PRISM15 PRISM18 PYRAMID5 PYRAMID13 PYRAMID14");
return elemTypes;
}

void
MooseMesh::allowRemoteElementRemoval(const bool allow_remote_element_removal)
{
Expand Down
98 changes: 98 additions & 0 deletions framework/src/meshgenerators/OverlayMeshGenerator.C
@@ -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 not shown.
@@ -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
[]


13 changes: 13 additions & 0 deletions test/tests/meshgenerators/overlay_mesh_generator/tests
@@ -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
[]
[]

0 comments on commit 6c4b5ec

Please sign in to comment.