Skip to content

Commit

Permalink
Add StitchedMesh closes idaholab#8308
Browse files Browse the repository at this point in the history
  • Loading branch information
friedmud committed Jan 11, 2017
1 parent 406b8fc commit ef51f22
Show file tree
Hide file tree
Showing 10 changed files with 239 additions and 0 deletions.
62 changes: 62 additions & 0 deletions framework/include/mesh/StitchedMesh.h
@@ -0,0 +1,62 @@
/****************************************************************/
/* DO NOT MODIFY THIS HEADER */
/* MOOSE - Multiphysics Object Oriented Simulation Environment */
/* */
/* (c) 2010 Battelle Energy Alliance, LLC */
/* ALL RIGHTS RESERVED */
/* */
/* Prepared by Battelle Energy Alliance, LLC */
/* Under Contract No. DE-AC07-05ID14517 */
/* With the U. S. Department of Energy */
/* */
/* See COPYRIGHT for full restrictions */
/****************************************************************/

#ifndef STITCHEDMESH_H
#define STITCHEDMESH_H

#include "MooseMesh.h"

#include "libmesh/serial_mesh.h"

class StitchedMesh;

template<>
InputParameters validParams<StitchedMesh>();

/**
* Reads an arbitrary set of meshes and attempts to "stitch" (join) them
* along boundaries.
*/
class StitchedMesh : public MooseMesh
{
public:
StitchedMesh(const InputParameters & parameters);
StitchedMesh(const StitchedMesh & other_mesh);
virtual ~StitchedMesh();

virtual MooseMesh & clone() const override;

virtual void buildMesh() override;

protected:
/// The mesh files to read
const std::vector<MeshFileName> & _files;

/// Whether or not to clear (remove) the stitched boundary IDs
const bool & _clear_stitched_boundary_ids;

/// The raw data from the input file
const std::vector<BoundaryName> & _stitch_boundaries;

/// A transformed version of _stitch_boundaries into a more logical "pairwise" structure
std::vector<std::pair<BoundaryName, BoundaryName>> _stitch_boundaries_pairs;

// Pointer to the original "real" mesh to be stitched into
ReplicatedMesh * _original_mesh;

/// The meshes to be stitched together. The first entry will be the "real" mesh
std::vector<std::unique_ptr<ReplicatedMesh>> _meshes;
};

#endif /* STITCHEDMESH_H */
2 changes: 2 additions & 0 deletions framework/src/base/Moose.C
Expand Up @@ -30,6 +30,7 @@
#include "TiledMesh.h"
#include "ImageMesh.h"
#include "PatternedMesh.h"
#include "StitchedMesh.h"

// MeshModifiers
#include "MeshExtruder.h"
Expand Down Expand Up @@ -461,6 +462,7 @@ registerObjects(Factory & factory)
registerMesh(TiledMesh);
registerMesh(ImageMesh);
registerMesh(PatternedMesh);
registerMesh(StitchedMesh);

// mesh modifiers
registerMeshModifier(MeshExtruder);
Expand Down
108 changes: 108 additions & 0 deletions framework/src/mesh/StitchedMesh.C
@@ -0,0 +1,108 @@
/****************************************************************/
/* DO NOT MODIFY THIS HEADER */
/* MOOSE - Multiphysics Object Oriented Simulation Environment */
/* */
/* (c) 2010 Battelle Energy Alliance, LLC */
/* ALL RIGHTS RESERVED */
/* */
/* Prepared by Battelle Energy Alliance, LLC */
/* Under Contract No. DE-AC07-05ID14517 */
/* With the U. S. Department of Energy */
/* */
/* See COPYRIGHT for full restrictions */
/****************************************************************/

#include "StitchedMesh.h"
#include "Parser.h"
#include "InputParameters.h"

// libMesh includes
#include "libmesh/mesh_modification.h"
#include "libmesh/serial_mesh.h"
#include "libmesh/exodusII_io.h"

template<>
InputParameters validParams<StitchedMesh>()
{
InputParameters params = validParams<MooseMesh>();
params.addRequiredParam<std::vector<MeshFileName>>("files", "The name of the mesh files to read. These mesh files will be 'stitched' into the current mesh in this order.");

params.addRequiredParam<std::vector<BoundaryName>>("stitch_boundaries", "Pairs of boundary names (one after the other) to stitch together for each step.");

params.addParam<bool>("clear_stitched_boundary_ids", true, "Whether or not to erase the boundary IDs after they've been used for stitching.");

params.addClassDescription("Reads in all of the given meshes and stitches them all together into one mesh.");

return params;
}

StitchedMesh::StitchedMesh(const InputParameters & parameters) :
MooseMesh(parameters),
_files(getParam<std::vector<MeshFileName> >("files")),
_clear_stitched_boundary_ids(getParam<bool>("clear_stitched_boundary_ids")),
_stitch_boundaries(getParam<std::vector<BoundaryName>>("stitch_boundaries"))
{
// The StitchedMesh class only works with ReplicatedMesh
errorIfDistributedMesh("StitchedMesh");

// Get the original mesh
_original_mesh = dynamic_cast<ReplicatedMesh *>(&getMesh());
if (!_original_mesh)
mooseError("StitchedMesh does not support DistributedMesh");

// Read the first mesh into the original mesh... then we'll stitch all of the others into that
_original_mesh->read(_files[0]);

_meshes.reserve(_files.size() - 1);

// Read in all of the other meshes
for (auto i = beginIndex(_files, 1); i < _files.size(); ++i)
{
_meshes.emplace_back(libmesh_make_unique<ReplicatedMesh>(_communicator));
auto & mesh = _meshes.back();

mesh->read(_files[i]);
}

if (_stitch_boundaries.size() % 2 != 0)
mooseError("There must be an even amount of stitch_boundaries in " << name());

_stitch_boundaries_pairs.reserve(_stitch_boundaries.size() / 2);

// Make pairs out of the boundary names
for (auto i = beginIndex(_stitch_boundaries); i < _stitch_boundaries.size(); i += 2)
_stitch_boundaries_pairs.emplace_back(_stitch_boundaries[i], _stitch_boundaries[i+1]);
}

StitchedMesh::StitchedMesh(const StitchedMesh & other_mesh) :
MooseMesh(other_mesh),
_files(other_mesh._files),
_clear_stitched_boundary_ids(other_mesh._clear_stitched_boundary_ids),
_stitch_boundaries(other_mesh._stitch_boundaries)
{
}

StitchedMesh::~StitchedMesh()
{
}

MooseMesh &
StitchedMesh::clone() const
{
return *(new StitchedMesh(*this));
}

void
StitchedMesh::buildMesh()
{
// Stich 'em
for (auto i = beginIndex(_meshes); i < _meshes.size(); i++)
{
auto & boundary_pair = _stitch_boundaries_pairs[i];

BoundaryID first = getBoundaryID(boundary_pair.first);
BoundaryID second = getBoundaryID(boundary_pair.second);

_original_mesh->stitch_meshes(*_meshes[i], first, second, TOLERANCE, _clear_stitched_boundary_ids);
}
}
Binary file added test/tests/mesh/stitched_mesh/center.e
Binary file not shown.
12 changes: 12 additions & 0 deletions test/tests/mesh/stitched_mesh/generator.i
@@ -0,0 +1,12 @@
# Just used to generate the mesh files for the test
# run with --mesh-only

[Mesh]
type = GeneratedMesh
dim = 2
xmin = 2
xmax = 3
nx = 5
ny = 5
construct_node_list_from_side_list = false
[]
Binary file not shown.
Binary file added test/tests/mesh/stitched_mesh/left.e
Binary file not shown.
Binary file added test/tests/mesh/stitched_mesh/right.e
Binary file not shown.
48 changes: 48 additions & 0 deletions test/tests/mesh/stitched_mesh/stitched_mesh.i
@@ -0,0 +1,48 @@
[Mesh]
type = StitchedMesh
files = 'left.e center.e right.e'
stitch_boundaries = 'right left right left'
parallel_type = 'replicated'
[]

[Variables]
[./u]
[../]
[]

[Kernels]
[./diff]
type = Diffusion
variable = u
[../]
[]

[BCs]
[./left]
type = DirichletBC
variable = u
boundary = left
value = 0
[../]
[./right]
type = DirichletBC
variable = u
boundary = right
value = 1
[../]
[]

[Executioner]
type = Steady

# Preconditioned JFNK (default)
solve_type = 'PJFNK'


petsc_options_iname = '-pc_type -pc_hypre_type'
petsc_options_value = 'hypre boomeramg'
[]

[Outputs]
exodus = true
[]
7 changes: 7 additions & 0 deletions test/tests/mesh/stitched_mesh/tests
@@ -0,0 +1,7 @@
[Tests]
[./test]
type = 'Exodiff'
input = 'stitched_mesh.i'
exodiff = 'stitched_mesh_out.e'
[../]
[]

0 comments on commit ef51f22

Please sign in to comment.