From cfe5939c2afb1c597bb77270f337e9cf266018f2 Mon Sep 17 00:00:00 2001 From: MengnanLi91 <118846840+MengnanLi91@users.noreply.github.com> Date: Mon, 20 Feb 2023 17:36:44 -0700 Subject: [PATCH] Working progress on MeshGenerator --- .../meshgenerators/BlockCartesianGenerator.h | 47 ++++--- .../meshgenerators/BlockCartesianGenerator.C | 125 ++++++++++++------ .../block_cartesian_generator.i | 11 +- 3 files changed, 120 insertions(+), 63 deletions(-) diff --git a/framework/include/meshgenerators/BlockCartesianGenerator.h b/framework/include/meshgenerators/BlockCartesianGenerator.h index 7b72c9c5fc7f..88a17d710496 100644 --- a/framework/include/meshgenerators/BlockCartesianGenerator.h +++ b/framework/include/meshgenerators/BlockCartesianGenerator.h @@ -27,24 +27,39 @@ class BlockCartesianGenerator : public MeshGenerator protected: /// The dimension of the mesh MooseEnum _dim; - /// Intervals in x direction - std::vector _dx; - /// Number of grids in all intervals in x direction - std::vector _ix; - /// Intervals in y direction - std::vector _dy; - /// Number of grids in all intervals in y direction - std::vector _iy; - /// Intervals in z direction - std::vector _dz; - /// Number of grids in all intervals in z direction - std::vector _iz; - /// Block IDs - std::vector _subdomain_id; + + /// 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; - - int _nx, _ny, _nz; }; diff --git a/framework/src/meshgenerators/BlockCartesianGenerator.C b/framework/src/meshgenerators/BlockCartesianGenerator.C index 2280071a92f6..45a4907654a7 100644 --- a/framework/src/meshgenerators/BlockCartesianGenerator.C +++ b/framework/src/meshgenerators/BlockCartesianGenerator.C @@ -14,9 +14,12 @@ #include "libmesh/mesh_generation.h" #include "libmesh/unstructured_mesh.h" #include "libmesh/replicated_mesh.h" -#include "libmesh/point.h" -#include "libmesh/elem.h" -#include "libmesh/node.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); @@ -24,65 +27,109 @@ InputParameters BlockCartesianGenerator::validParams() { InputParameters params = MeshGenerator::validParams(); + params.addClassDescription("This BlockCartesianGenerator creates a Cartesian mesh using " + "DistributedRectilinearMeshGenerator in " + "the mesh block region."); params.addRequiredParam("input", "The mesh we want to modify"); MooseEnum dims("1=1 2 3"); params.addRequiredParam("dim", dims, "The dimension of the mesh to be generated"); - params.addRequiredParam>("dx", "Intervals in the X direction"); - params.addParam>( - "ix", "Number of grids in all intervals in the X direction (default to all one)"); - params.addParam>( - "dy", "Intervals in the Y direction (required when dim>1 otherwise ignored)"); - params.addParam>( - "iy", "Number of grids in all intervals in the Y direction (default to all one)"); - params.addParam>( - "dz", "Intervals in the Z direction (required when dim>2 otherwise ignored)"); - params.addParam>( - "iz", "Number of grids in all intervals in the Z direction (default to all one)"); - params.addParam>("subdomain_id", "Block IDs (default to all zero)"); - - params.addClassDescription("This BlockCartesianGenerator creates a non-uniform Cartesian mesh in " - "the mesh block region."); + 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, + "num_side_layers>=1 & num_side_layers<5", + "Number of layers of off-processor side neighbors is reserved during mesh generation"); + MooseEnum partition("graph linear square", "graph", false); + params.addParam( + "partition", partition, "Which method (graph linear square) use to partition mesh"); + MooseEnum elem_types( + "EDGE EDGE2 EDGE3 EDGE4 QUAD QUAD4 QUAD8 QUAD9 TRI3 TRI6 HEX HEX8 HEX20 HEX27 TET4 TET10 " + "PRISM6 PRISM15 PRISM18 PYRAMID5 PYRAMID13 PYRAMID14"); // no default + params.addParam("elem_type", + elem_types, + "The type of element from libMesh to " + "generate (default: linear element for " + "requested dimension)"); + + params.addRangeCheckedParam( + "bias_x", + 1., + "bias_x>=0.5 & bias_x<=2", + "The amount by which to grow (or shrink) the cells in the x-direction."); + params.addRangeCheckedParam( + "bias_y", + 1., + "bias_y>=0.5 & bias_y<=2", + "The amount by which to grow (or shrink) the cells in the y-direction."); + params.addRangeCheckedParam( + "bias_z", + 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")), - _dx(getParam>("dx")), + _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")) { + 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("CartesianMeshGenerator"); + 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; - if (isParamValid("ix")) - params.set>("ix") = getParam>("ix"); - if (isParamValid("iy")) - params.set>("iy") = getParam>("iy"); - if (isParamValid("iz")) - params.set>("iz") = getParam>("iz"); - - if (isParamValid("dx")) - params.set>("dx") = getParam>("dx"); - if (isParamValid("dy")) - params.set>("dy") = getParam>("dy"); - if (isParamValid("dz")) - params.set>("dz") = getParam>("dz"); - if (isParamValid("subdomain_id")) - params.set>("subdomain_id") = - getParam>("subdomain_id"); + params.set("num_elements_x") = _nx; + params.set("num_elements_y") = _ny; + params.set("num_elements_z") = _nz; + + // params.set("num_cores_for_partition") = _num_cores_for_partition; // generate lower dimensional mesh from the given sideset - _build_mesh = - &addMeshSubgenerator("CartesianMeshGenerator", name() + "_cartesianmeshgenerator", params); + _build_mesh = &addMeshSubgenerator("DistributedRectilinearMeshGenerator", + name() + "_DistributedRectilinearmeshgenerator", + params); } std::unique_ptr BlockCartesianGenerator::generate() { - auto bbox_input = MeshTools::create_bounding_box(*_mesh_input); + // auto bbox_input = MeshTools::create_bounding_box(*_mesh_input); // auto bbox = MeshTools::create_bounding_box(_build_mesh); // Real diff = 0; diff --git a/test/tests/meshgenerators/block_cartesian_generator/block_cartesian_generator.i b/test/tests/meshgenerators/block_cartesian_generator/block_cartesian_generator.i index 16652af3eed4..88c936287861 100644 --- a/test/tests/meshgenerators/block_cartesian_generator/block_cartesian_generator.i +++ b/test/tests/meshgenerators/block_cartesian_generator/block_cartesian_generator.i @@ -8,22 +8,17 @@ xmax = 4 ymin = 0 ymax = 2.2 - nemesis = true - output = true [] [bcg] type = BlockCartesianGenerator input = 'gmg' dim = 2 - dx = '1.5 2.4 0.1' - dy = '1.3 0.9' - ix = '2 1 1' - iy = '2 3' - subdomain_id = '0 1 1 2 2 2' + nx = 6 + ny = 6 [] [] [Outputs] - + []