Permalink
Browse files

Merge pull request #12753 from leorachapuis/patterned_mesh_generator

MeshGenerator updates
  • Loading branch information...
permcody committed Jan 24, 2019
2 parents c4887fa + ddce5d2 commit a8d92956538852282f06c6c2fd1249936264e8e6
@@ -51,9 +51,9 @@ class PatternedMeshGenerator : public MeshGenerator
// Holds a mesh for each row, these will be stitched together in the end
std::vector<std::unique_ptr<ReplicatedMesh>> _row_meshes;

const Real _x_width;
const Real _y_width;
const Real _z_width;
Real _x_width;
Real _y_width;
Real _z_width;
};

#endif // PATTERNEDMESHGENERATOR_H
@@ -102,9 +102,6 @@ MeshExtruderGenerator::generate()
if (isParamValid("top_sideset"))
changeID(*mesh, getParam<std::vector<BoundaryName>>("top_sideset"), old_top);

// Update the dimension
mesh->set_mesh_dimension(source_mesh->mesh_dimension() + 1);

return dynamic_pointer_cast<MeshBase>(mesh);
}

@@ -15,6 +15,8 @@
#include "libmesh/distributed_mesh.h"
#include "libmesh/boundary_info.h"
#include "libmesh/mesh_modification.h"
#include "libmesh/mesh_tools.h"
#include "MooseMeshUtils.h"

registerMooseObject("MooseApp", PatternedMeshGenerator);

@@ -33,7 +35,6 @@ validParams<PatternedMeshGenerator>()
"z_width", 0, "z_width>=0", "The tile width in the z direction");

// Boundaries : user has to provide id or name for each boundary
// If an id is provided, any provided name for this particular boundary will be ignored.

// x boundary names
params.addParam<BoundaryName>("left_boundary", "left", "name of the left (x) boundary");
@@ -43,14 +44,6 @@ validParams<PatternedMeshGenerator>()
params.addParam<BoundaryName>("top_boundary", "top", "name of the top (y) boundary");
params.addParam<BoundaryName>("bottom_boundary", "bottom", "name of the bottom (y) boundary");

// x boundary ids
params.addParam<boundary_id_type>("left_boundary_id", "id of the left (x) boundary");
params.addParam<boundary_id_type>("right_boundary_id", "id of the right (x) boundary");

// y boundary ids
params.addParam<boundary_id_type>("top_boundary_id", "name of the top (y) boundary");
params.addParam<boundary_id_type>("bottom_boundary_id", "name of the bottom (y) boundary");

params.addRequiredParam<std::vector<std::vector<unsigned int>>>(
"pattern", "A double-indexed array starting with the upper-left corner");

@@ -88,25 +81,16 @@ PatternedMeshGenerator::generate()
// Data structure that holds each row
_row_meshes.resize(_pattern.size());

// Trying to get the boundaries by name
boundary_id_type left =
_meshes[0]->get_boundary_info().get_id_by_name(getParam<BoundaryName>("left_boundary"));
boundary_id_type right =
_meshes[0]->get_boundary_info().get_id_by_name(getParam<BoundaryName>("right_boundary"));
boundary_id_type top =
_meshes[0]->get_boundary_info().get_id_by_name(getParam<BoundaryName>("top_boundary"));
boundary_id_type bottom =
_meshes[0]->get_boundary_info().get_id_by_name(getParam<BoundaryName>("bottom_boundary"));

// For each boundary, check if the user provided an id
if (isParamValid("left_boundary_id"))
left = getParam<boundary_id_type>("left_boundary_id");
if (isParamValid("right_boundary_id"))
right = getParam<boundary_id_type>("right_boundary_id");
if (isParamValid("top_boundary_id"))
top = getParam<boundary_id_type>("top_boundary_id");
if (isParamValid("bottom_boundary_id"))
bottom = getParam<boundary_id_type>("bottom_boundary_id");
// Getting the boundaries provided by the user
std::vector<BoundaryName> boundary_names = {getParam<BoundaryName>("left_boundary"),
getParam<BoundaryName>("right_boundary"),
getParam<BoundaryName>("top_boundary"),
getParam<BoundaryName>("bottom_boundary")};

std::vector<boundary_id_type> ids =
MooseMeshUtils::getBoundaryIDs(*_meshes[0], boundary_names, true);

boundary_id_type left = ids[0], right = ids[1], top = ids[2], bottom = ids[3];

// Check if all the boundaries have been initialized
if (left == -123)
@@ -118,6 +102,16 @@ PatternedMeshGenerator::generate()
if (bottom == -123)
mooseError("The bottom boundary has not been initialized properly.");

// Check if the user has provided the x, y and z widths.
// If not (their value is 0 by default), compute them
auto bbox = MeshTools::create_bounding_box(*_meshes[0]);
if (_x_width == 0)
_x_width = bbox.max()(0) - bbox.min()(0);
if (_y_width == 0)
_y_width = bbox.max()(1) - bbox.min()(1);
if (_z_width == 0)
_z_width = bbox.max()(2) - bbox.min()(2);

// Build each row mesh
for (auto i = beginIndex(_pattern); i < _pattern.size(); ++i)
for (auto j = beginIndex(_pattern[i]); j < _pattern[i].size(); ++j)
@@ -17,6 +17,7 @@
#include "libmesh/bounding_box.h"
#include "libmesh/mesh_tools.h"
#include "libmesh/point.h"
#include "MooseMeshUtils.h"

#include <typeinfo>

@@ -97,16 +98,17 @@ StackGenerator::generate()
mooseError("Mesh from MeshGenerator : ", _input_names[i + 1], " is not in ", _dim, "D.");
}

boundary_id_type first =
mesh->get_boundary_info().get_id_by_name(getParam<BoundaryName>("top_boundary"));
boundary_id_type second =
mesh->get_boundary_info().get_id_by_name(getParam<BoundaryName>("bottom_boundary"));

// Getting the boundaries provided by the user
std::vector<BoundaryName> boundary_names = {getParam<BoundaryName>("top_boundary"),
getParam<BoundaryName>("bottom_boundary")};
if (dim == 3)
{
first = mesh->get_boundary_info().get_id_by_name(getParam<BoundaryName>("front_boundary"));
second = mesh->get_boundary_info().get_id_by_name(getParam<BoundaryName>("back_boundary"));
}
boundary_names = {getParam<BoundaryName>("front_boundary"),
getParam<BoundaryName>("back_boundary")};

std::vector<boundary_id_type> ids =
MooseMeshUtils::getBoundaryIDs(*_meshes[0], boundary_names, true);

boundary_id_type first = ids[0], second = ids[1];

// Getting the width of each mesh
std::vector<Real> heights;
@@ -24,13 +24,10 @@
0 1 0 0 0 0 0 0 0 0 0 0 1 0 ;
0 1 0 0 0 0 0 0 0 0 0 0 1 0 ;
0 0 0 0 0 0 0 0 0 0 0 0 0 0'
bottom_boundary_id = 1
right_boundary_id = 2
top_boundary_id = 3
left_boundary_id = 4
y_width = 1.2
x_width = 1.2
#parallel_type = replicated
bottom_boundary = 1
right_boundary = 2
top_boundary = 3
left_boundary = 4
[]
[]

0 comments on commit a8d9295

Please sign in to comment.