Skip to content

Commit

Permalink
Working progress on MeshGenerator
Browse files Browse the repository at this point in the history
  • Loading branch information
MengnanLi91 committed Feb 22, 2023
1 parent e412c97 commit cfe5939
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 63 deletions.
47 changes: 31 additions & 16 deletions framework/include/meshgenerators/BlockCartesianGenerator.h
Expand Up @@ -27,24 +27,39 @@ class BlockCartesianGenerator : public MeshGenerator
protected:
/// The dimension of the mesh
MooseEnum _dim;
/// Intervals in x direction
std::vector<Real> _dx;
/// Number of grids in all intervals in x direction
std::vector<unsigned int> _ix;
/// Intervals in y direction
std::vector<Real> _dy;
/// Number of grids in all intervals in y direction
std::vector<unsigned int> _iy;
/// Intervals in z direction
std::vector<Real> _dz;
/// Number of grids in all intervals in z direction
std::vector<unsigned int> _iz;
/// Block IDs
std::vector<unsigned int> _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<MeshBase> * _build_mesh;
/// Name of the base mesh
std::unique_ptr<MeshBase> & _mesh_input;

int _nx, _ny, _nz;
};
125 changes: 86 additions & 39 deletions framework/src/meshgenerators/BlockCartesianGenerator.C
Expand Up @@ -14,75 +14,122 @@
#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);

InputParameters
BlockCartesianGenerator::validParams()
{
InputParameters params = MeshGenerator::validParams();
params.addClassDescription("This BlockCartesianGenerator creates a Cartesian mesh using "
"DistributedRectilinearMeshGenerator in "
"the mesh block region.");
params.addRequiredParam<MeshGeneratorName>("input", "The mesh we want to modify");
MooseEnum dims("1=1 2 3");
params.addRequiredParam<MooseEnum>("dim", dims, "The dimension of the mesh to be generated");

params.addRequiredParam<std::vector<Real>>("dx", "Intervals in the X direction");
params.addParam<std::vector<unsigned int>>(
"ix", "Number of grids in all intervals in the X direction (default to all one)");
params.addParam<std::vector<Real>>(
"dy", "Intervals in the Y direction (required when dim>1 otherwise ignored)");
params.addParam<std::vector<unsigned int>>(
"iy", "Number of grids in all intervals in the Y direction (default to all one)");
params.addParam<std::vector<Real>>(
"dz", "Intervals in the Z direction (required when dim>2 otherwise ignored)");
params.addParam<std::vector<unsigned int>>(
"iz", "Number of grids in all intervals in the Z direction (default to all one)");
params.addParam<std::vector<unsigned int>>("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<dof_id_type>("nx", 1, "Number of elements in the X direction");
params.addParam<dof_id_type>("ny", 1, "Number of elements in the Y direction");
params.addParam<dof_id_type>("nz", 1, "Number of elements in the Z direction");

params.addParam<processor_id_type>(
"num_cores_for_partition",
0,
"Number of cores for partitioning the graph (dafaults to the number of MPI ranks)");

params.addRangeCheckedParam<unsigned>(
"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<MooseEnum>(
"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<MooseEnum>("elem_type",
elem_types,
"The type of element from libMesh to "
"generate (default: linear element for "
"requested dimension)");

params.addRangeCheckedParam<Real>(
"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<Real>(
"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<Real>(
"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<MooseEnum>("dim")),
_dx(getParam<std::vector<Real>>("dx")),
_nx(declareMeshProperty("num_elements_x", getParam<dof_id_type>("nx"))),
_ny(declareMeshProperty("num_elements_y", getParam<dof_id_type>("ny"))),
_nz(declareMeshProperty("num_elements_z", getParam<dof_id_type>("nz"))),
// _num_cores_for_partition(getParam<processor_id_type>("num_cores_for_partition")),
_bias_x(getParam<Real>("bias_x")),
_bias_y(getParam<Real>("bias_y")),
_bias_z(getParam<Real>("bias_z")),
// _num_parts_per_compute_node(getParam<processor_id_type>("num_cores_per_compute_node")),
_partition_method(getParam<MooseEnum>("partition")),
_num_side_layers(getParam<unsigned>("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<MooseEnum>("dim") = _dim;
params.set<Real>("xmin") = xmin;
params.set<Real>("ymin") = ymin;
params.set<Real>("zmin") = zmin;
params.set<Real>("xmax") = xmax;
params.set<Real>("ymax") = ymax;
params.set<Real>("zmax") = zmax;

if (isParamValid("ix"))
params.set<std::vector<unsigned int>>("ix") = getParam<std::vector<unsigned int>>("ix");
if (isParamValid("iy"))
params.set<std::vector<unsigned int>>("iy") = getParam<std::vector<unsigned int>>("iy");
if (isParamValid("iz"))
params.set<std::vector<unsigned int>>("iz") = getParam<std::vector<unsigned int>>("iz");

if (isParamValid("dx"))
params.set<std::vector<Real>>("dx") = getParam<std::vector<Real>>("dx");
if (isParamValid("dy"))
params.set<std::vector<Real>>("dy") = getParam<std::vector<Real>>("dy");
if (isParamValid("dz"))
params.set<std::vector<Real>>("dz") = getParam<std::vector<Real>>("dz");
if (isParamValid("subdomain_id"))
params.set<std::vector<unsigned int>>("subdomain_id") =
getParam<std::vector<unsigned int>>("subdomain_id");
params.set<dof_id_type>("num_elements_x") = _nx;
params.set<dof_id_type>("num_elements_y") = _ny;
params.set<dof_id_type>("num_elements_z") = _nz;

// params.set<processor_id_type>("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<MeshBase>
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;
Expand Down
Expand Up @@ -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]

[]

0 comments on commit cfe5939

Please sign in to comment.