Skip to content

Commit

Permalink
Address review: use applySpecificParams, params += and improve doco
Browse files Browse the repository at this point in the history
Co-Authored-By: Guillaume Giudicelli <guillaume.giudicelli@gmail.com>
Co-Authored-By: roystgnr <2367346+roystgnr@users.noreply.github.com>

Fix typo in OverlayMeshGenerator.md
  • Loading branch information
MengnanLi91 committed Jan 29, 2024
1 parent 59a23d9 commit 056122a
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 75 deletions.
Expand Up @@ -4,7 +4,7 @@

## 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).
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.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

Expand Down
8 changes: 8 additions & 0 deletions framework/include/meshgenerators/OverlayMeshGenerator.h
@@ -1,4 +1,12 @@
//* 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 "libmesh/mesh_generation.h"
Expand Down
109 changes: 36 additions & 73 deletions framework/src/meshgenerators/OverlayMeshGenerator.C
Expand Up @@ -6,8 +6,12 @@
//*
//* 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_generation.h"
#include "libmesh/unstructured_mesh.h"
Expand All @@ -16,54 +20,18 @@
#include "libmesh/mesh_tools.h"

registerMooseObject("MooseApp", OverlayMeshGenerator);

InputParameters
OverlayMeshGenerator::validParams()
{
InputParameters params = MeshGenerator::validParams();
params.addClassDescription("This OverlayMeshGenerator creates a Cartesian mesh using "
"DistributedRectilinearMeshGenerator in "
"the mesh block region.");

params += DistributedRectilinearMeshGenerator::validParams();
params.addRequiredParam<MeshGeneratorName>("input", "The base mesh we want to overlay");
MooseEnum dims("1=1 2 3");
params.addRequiredParam<MooseEnum>(
"dim", dims, "The dimension of the mesh to be generated"); // Make this parameter required
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 = MooseMesh::elemTypes();
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.addClassDescription("Creates a Cartesian mesh overlaying "
"the input mesh region.");

return params;
}

Expand All @@ -78,35 +46,30 @@ OverlayMeshGenerator::OverlayMeshGenerator(const InputParameters & parameters)

_input_mesh = &getMeshByName(_mesh_name);

auto params = _app.getFactory().getValidParams("DistributedRectilinearMeshGenerator");

params.set<MooseEnum>("dim") = _dim;

params.set<dof_id_type>("nx") = getParam<dof_id_type>("nx");
params.set<dof_id_type>("ny") = getParam<dof_id_type>("ny");
params.set<dof_id_type>("nz") = getParam<dof_id_type>("nz");

params.set<Real>("xmin") = 0;
params.set<Real>("ymin") = 0;
params.set<Real>("zmin") = 0;
params.set<Real>("xmax") = 1;
params.set<Real>("ymax") = 1;
params.set<Real>("zmax") = 1;

params.set<Real>("bias_x") = getParam<Real>("bias_x");
params.set<Real>("bias_y") = getParam<Real>("bias_y");
params.set<Real>("bias_z") = getParam<Real>("bias_z");

params.set<unsigned>("num_side_layers") = getParam<unsigned>("num_side_layers");
params.set<processor_id_type>("num_cores_for_partition") =
getParam<processor_id_type>("num_cores_for_partition");

params.set<MooseEnum>("partition") = getParam<MooseEnum>("partition");
params.set<MooseEnum>("elem_type") = getParam<MooseEnum>("elem_type");
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",
params);
input_params);
_build_mesh = &getMeshByName(_mesh_name + "_distributedrectilinearmeshgenerator");
}
std::unique_ptr<MeshBase>
Expand All @@ -126,13 +89,13 @@ OverlayMeshGenerator::generate()
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 translate_factor;
translate_factor = bbox_input.min();
RealVectorValue translation_vector;
translation_vector = bbox_input.min();

// translate
if (translate_factor(0) != 0 || translate_factor(1) != 0 || translate_factor(2) != 0)
if (translation_vector(0) != 0 || translation_vector(1) != 0 || translation_vector(2) != 0)
MeshTools::Modification::translate(
*build_mesh, translate_factor(0), translate_factor(1), translate_factor(2));
*build_mesh, translation_vector(0), translation_vector(1), translation_vector(2));

return dynamic_pointer_cast<MeshBase>(build_mesh);
}
2 changes: 1 addition & 1 deletion test/tests/meshgenerators/overlay_mesh_generator/tests
Expand Up @@ -2,7 +2,7 @@
issues = '#23513'
design = 'meshgenerators/OverlayMeshGenerator.md'
[Test]
requirement = 'The system shall be able to create a distributedrectilinear mesh overlaying with the given mesh.'
requirement = 'The system shall be able to create in a distributed manner a rectilinear mesh overlaying with the given mesh.'
type = 'Exodiff'
input = 'overlay_mesh_generator.i'
cli_args = '--mesh-only'
Expand Down

0 comments on commit 056122a

Please sign in to comment.