diff --git a/framework/doc/content/source/meshgenerators/OverlappingMeshGenerator.md b/framework/doc/content/source/meshgenerators/OverlappingMeshGenerator.md new file mode 100644 index 000000000000..2f96e6241f98 --- /dev/null +++ b/framework/doc/content/source/meshgenerators/OverlappingMeshGenerator.md @@ -0,0 +1,18 @@ +# OverlayMeshGenerator + +!syntax description /Mesh/OverlayMeshGenerator + +## Overview + +The `OverlayMeshGenerator` object is the built-in mesh generation capable of creating an overlaying mesh with the given mesh block. The overlay mesh uses DistributedRectilinearMeshGenerator(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 diff --git a/framework/include/meshgenerators/BlockCartesianGenerator.h b/framework/include/meshgenerators/BlockCartesianGenerator.h deleted file mode 100644 index 88a17d710496..000000000000 --- a/framework/include/meshgenerators/BlockCartesianGenerator.h +++ /dev/null @@ -1,65 +0,0 @@ -//* 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" -#include "MooseEnum.h" - -/* - * Mesh generator to create a Cartesian mesh - */ -class BlockCartesianGenerator : public MeshGenerator -{ -public: - static InputParameters validParams(); - - BlockCartesianGenerator(const InputParameters & parameters); - - std::unique_ptr generate() override; - -protected: - /// The dimension of the mesh - MooseEnum _dim; - - /// Number of elements in x, y, z direction - dof_id_type &_nx, &_ny, &_nz; - - /// Number of cores for partitioning the graph - processor_id_type _num_cores_for_partition; - - /// The type of element to build - ElemType _elem_type; - - /// The amount by which to bias the cells in the x,y,z directions. - /// Must be in the range 0.5 <= _bias_x <= 2.0. - /// _bias_x < 1 implies cells are shrinking in the x-direction. - /// _bias_x==1 implies no bias (original mesh unchanged). - /// _bias_x > 1 implies cells are growing in the x-direction. - Real _bias_x, _bias_y, _bias_z; - - /// External partitioner - std::string _part_package; - - /// Number of cores per compute node if hierarch partitioning is used - processor_id_type _num_parts_per_compute_node; - - /// Which method is used to partition the mesh that is not built yet - std::string _partition_method; - - /// Number of element side neighbor layers - /// While most of applications in moose require one layer of side neighbors, - /// phase field simulation with grain tracker needs two layers. This parameter - /// allow us to reserve an arbitrary number of side neighbors - unsigned _num_side_layers; - /// Name of the generated Cartesian mesh - std::unique_ptr * _build_mesh; - /// Name of the base mesh - std::unique_ptr & _mesh_input; -}; diff --git a/framework/include/meshgenerators/OverlayMeshGenerator.h b/framework/include/meshgenerators/OverlayMeshGenerator.h new file mode 100644 index 000000000000..346340dbcc79 --- /dev/null +++ b/framework/include/meshgenerators/OverlayMeshGenerator.h @@ -0,0 +1,24 @@ +//* https://www.gnu.org/licenses/lgpl-2.1.html +#pragma once +#include "MeshGenerator.h" +#include "MooseEnum.h" +/* + * Mesh generator to create a Overlay mesh + */ +class OverlayMeshGenerator : public MeshGenerator +{ +public: + static InputParameters validParams(); + OverlayMeshGenerator(const InputParameters & parameters); + std::unique_ptr generate() override; + +protected: + /// The dimension of the mesh + MooseEnum _dim; + + /// Name of the generated mesh + std::unique_ptr * _build_mesh; + + /// Name of the base mesh + std::unique_ptr & _mesh_input; +}; diff --git a/framework/src/meshgenerators/BlockCartesianGenerator.C b/framework/src/meshgenerators/OverlayMeshGenerator.C similarity index 51% rename from framework/src/meshgenerators/BlockCartesianGenerator.C rename to framework/src/meshgenerators/OverlayMeshGenerator.C index 45a4907654a7..2cabc51263bb 100644 --- a/framework/src/meshgenerators/BlockCartesianGenerator.C +++ b/framework/src/meshgenerators/OverlayMeshGenerator.C @@ -6,43 +6,34 @@ //* //* Licensed under LGPL 2.1, please see LICENSE for details //* https://www.gnu.org/licenses/lgpl-2.1.html - -#include "BlockCartesianGenerator.h" +#include "OverlayMeshGenerator.h" #include "CastUniquePointer.h" - // libMesh includes #include "libmesh/mesh_generation.h" #include "libmesh/unstructured_mesh.h" #include "libmesh/replicated_mesh.h" -#include "libmesh/mesh_communication.h" -#include "libmesh/remote_elem.h" -#include "libmesh/partitioner.h" -#include "libmesh/string_to_enum.h" -#include "libmesh/periodic_boundaries.h" -#include "libmesh/periodic_boundary_base.h" - -registerMooseObject("MooseApp", BlockCartesianGenerator); - +#include "libmesh/point.h" +#include "libmesh/elem.h" +#include "libmesh/node.h" +registerMooseObject("MooseApp", OverlayMeshGenerator); InputParameters -BlockCartesianGenerator::validParams() +OverlayMeshGenerator::validParams() { InputParameters params = MeshGenerator::validParams(); - params.addClassDescription("This BlockCartesianGenerator creates a Cartesian mesh using " + params.addClassDescription("This OverlayMeshGenerator creates a Cartesian mesh using " "DistributedRectilinearMeshGenerator in " "the mesh block region."); - params.addRequiredParam("input", "The mesh we want to modify"); + params.addRequiredParam("input", "The base mesh we want to overlay"); MooseEnum dims("1=1 2 3"); - params.addRequiredParam("dim", dims, "The dimension of the mesh to be generated"); - + params.addRequiredParam( + "dim", dims, "The dimension of the mesh to be generated"); // Make this parameter required params.addParam("nx", 1, "Number of elements in the X direction"); params.addParam("ny", 1, "Number of elements in the Y direction"); params.addParam("nz", 1, "Number of elements in the Z direction"); - params.addParam( "num_cores_for_partition", 0, "Number of cores for partitioning the graph (dafaults to the number of MPI ranks)"); - params.addRangeCheckedParam( "num_side_layers", 2, @@ -75,70 +66,58 @@ BlockCartesianGenerator::validParams() 1., "bias_z>=0.5 & bias_z<=2", "The amount by which to grow (or shrink) the cells in the z-direction."); - - params.addParamNamesToGroup("dim", "Main"); - return params; } -BlockCartesianGenerator::BlockCartesianGenerator(const InputParameters & parameters) - : MeshGenerator(parameters), - _dim(getParam("dim")), - _nx(declareMeshProperty("num_elements_x", getParam("nx"))), - _ny(declareMeshProperty("num_elements_y", getParam("ny"))), - _nz(declareMeshProperty("num_elements_z", getParam("nz"))), - // _num_cores_for_partition(getParam("num_cores_for_partition")), - _bias_x(getParam("bias_x")), - _bias_y(getParam("bias_y")), - _bias_z(getParam("bias_z")), - // _num_parts_per_compute_node(getParam("num_cores_per_compute_node")), - _partition_method(getParam("partition")), - _num_side_layers(getParam("num_side_layers")), - _mesh_input(getMesh("input")) +OverlayMeshGenerator::OverlayMeshGenerator(const InputParameters & parameters) + : MeshGenerator(parameters), _dim(getParam("dim")), _mesh_input(getMesh("input")) { - auto bbox_input = MeshTools::create_bounding_box(*_mesh_input); - Real xmin = bbox_input.min()(0); - Real ymin = bbox_input.min()(1); - Real zmin = bbox_input.min()(2); - Real xmax = bbox_input.max()(0); - Real ymax = bbox_input.max()(1); - Real zmax = bbox_input.max()(2); - auto params = _app.getFactory().getValidParams("DistributedRectilinearMeshGenerator"); - params.set("dim") = _dim; - params.set("xmin") = xmin; - params.set("ymin") = ymin; - params.set("zmin") = zmin; - params.set("xmax") = xmax; - params.set("ymax") = ymax; - params.set("zmax") = zmax; - params.set("num_elements_x") = _nx; - params.set("num_elements_y") = _ny; - params.set("num_elements_z") = _nz; + params.set("nx") = getParam("nx"); + params.set("ny") = getParam("ny"); + params.set("nz") = getParam("nz"); + + params.set("xmin") = 0; + params.set("ymin") = 0; + params.set("zmin") = 0; + params.set("xmax") = 1; + params.set("ymax") = 1; + params.set("zmax") = 1; + + params.set("bias_x") = getParam("bias_x"); + params.set("bias_y") = getParam("bias_y"); + params.set("bias_z") = getParam("bias_z"); + + params.set("num_side_layers") = getParam("num_side_layers"); + params.set("num_cores_for_partition") = + getParam("num_cores_for_partition"); - // params.set("num_cores_for_partition") = _num_cores_for_partition; + params.set("partition") = getParam("partition"); + params.set("elem_type") = getParam("elem_type"); - // generate lower dimensional mesh from the given sideset _build_mesh = &addMeshSubgenerator("DistributedRectilinearMeshGenerator", - name() + "_DistributedRectilinearmeshgenerator", + name() + "_distributedrectilinearmeshgenerator", params); } - std::unique_ptr -BlockCartesianGenerator::generate() +OverlayMeshGenerator::generate() { - // auto bbox_input = MeshTools::create_bounding_box(*_mesh_input); - // auto bbox = MeshTools::create_bounding_box(_build_mesh); + auto bbox_input = MeshTools::create_bounding_box(*_mesh_input); + + RealVectorValue scale_factor; + scale_factor = bbox_input.max() - bbox_input.min(); + + 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)); - // Real diff = 0; - // for (auto i = 0; i < _dim; i++) - // { - // diff = std::abs(bbox_input.max()(i) - bbox_input.min()(i) - bbox.max()(i) + bbox.min()(i)); - // if (diff > TOLERANCE) - // mooseError("The Intervals in ", i, "th dimension doesn't match!"); - // } + RealVectorValue translate_factor; + translate_factor = bbox_input.min(); + if (translate_factor(0) != 0 || translate_factor(1) != 0 || translate_factor(2) != 0) + MeshTools::Modification::translate( + *(*_build_mesh), translate_factor(0), translate_factor(1), translate_factor(2)); return std::move(*_build_mesh); } diff --git a/test/tests/meshgenerators/overlay_mesh_generator/gold/overlay_mesh_generator_in.e b/test/tests/meshgenerators/overlay_mesh_generator/gold/overlay_mesh_generator_in.e new file mode 100644 index 000000000000..bd2e9128114b Binary files /dev/null and b/test/tests/meshgenerators/overlay_mesh_generator/gold/overlay_mesh_generator_in.e differ diff --git a/test/tests/meshgenerators/block_cartesian_generator/block_cartesian_generator.i b/test/tests/meshgenerators/overlay_mesh_generator/overlay_mesh_generator.i similarity index 67% rename from test/tests/meshgenerators/block_cartesian_generator/block_cartesian_generator.i rename to test/tests/meshgenerators/overlay_mesh_generator/overlay_mesh_generator.i index 88c936287861..96022c45ff80 100644 --- a/test/tests/meshgenerators/block_cartesian_generator/block_cartesian_generator.i +++ b/test/tests/meshgenerators/overlay_mesh_generator/overlay_mesh_generator.i @@ -4,13 +4,15 @@ dim = 2 nx = 3 ny = 3 - xmin = 0 + xmin = -1 xmax = 4 - ymin = 0 + ymin = -1 ymax = 2.2 + nemesis = true + output = true [] [bcg] - type = BlockCartesianGenerator + type = OverlayMeshGenerator input = 'gmg' dim = 2 nx = 6 diff --git a/test/tests/meshgenerators/overlay_mesh_generator/tests b/test/tests/meshgenerators/overlay_mesh_generator/tests new file mode 100644 index 000000000000..9a557f1aba72 --- /dev/null +++ b/test/tests/meshgenerators/overlay_mesh_generator/tests @@ -0,0 +1,15 @@ +[Tests] + [test] + type = 'Exodiff' + input = 'overlay_mesh_generator.i' + cli_args = '--mesh-only' + exodiff = 'overlay_mesh_generator_in.e' + requirement = 'The system shall be able to create a distributedrectilinear mesh overlaying with the given mesh.' + design = 'meshgenerators/OverlayMeshGenerator.md' + issues = '#0' + mesh_mode = 'REPLICATED' + recover = false + + detail = 'The refinement of the generated mesh is different from the given mesh.' + [] +[]