Line data Source code
1 : //* This file is part of the MOOSE framework 2 : //* https://mooseframework.inl.gov 3 : //* 4 : //* All rights reserved, see COPYRIGHT for full restrictions 5 : //* https://github.com/idaholab/moose/blob/master/COPYRIGHT 6 : //* 7 : //* Licensed under LGPL 2.1, please see LICENSE for details 8 : //* https://www.gnu.org/licenses/lgpl-2.1.html 9 : 10 : #include "StitchedMesh.h" 11 : #include "Parser.h" 12 : #include "InputParameters.h" 13 : 14 : #include "MooseApp.h" 15 : 16 : #include "libmesh/mesh_modification.h" 17 : #include "libmesh/serial_mesh.h" 18 : #include "libmesh/exodusII_io.h" 19 : 20 : registerMooseObject("MooseApp", StitchedMesh); 21 : 22 : InputParameters 23 14293 : StitchedMesh::validParams() 24 : { 25 14293 : InputParameters params = MooseMesh::validParams(); 26 14293 : params.addRequiredParam<std::vector<MeshFileName>>( 27 : "files", 28 : "The name of the mesh files to read. These mesh files will be 'stitched' into the " 29 : "current mesh in this order."); 30 : 31 14293 : params.addRequiredParam<std::vector<BoundaryName>>( 32 : "stitch_boundaries", 33 : "Pairs of boundary names (one after the other) to stitch together for each step."); 34 : 35 42879 : params.addParam<bool>( 36 : "clear_stitched_boundary_ids", 37 28586 : true, 38 : "Whether or not to erase the boundary IDs after they've been used for stitching."); 39 : 40 14293 : params.addClassDescription( 41 : "Reads in all of the given meshes and stitches them all together into one mesh."); 42 : 43 14293 : return params; 44 0 : } 45 : 46 16 : StitchedMesh::StitchedMesh(const InputParameters & parameters) 47 : : MooseMesh(parameters), 48 16 : _files(getParam<std::vector<MeshFileName>>("files")), 49 16 : _clear_stitched_boundary_ids(getParam<bool>("clear_stitched_boundary_ids")), 50 32 : _stitch_boundaries(getParam<std::vector<BoundaryName>>("stitch_boundaries")) 51 : { 52 16 : if (_files.empty()) 53 4 : mooseError("Must specify at least one mesh file for StitchedMesh"); 54 : 55 : // The StitchedMesh class only works with ReplicatedMesh 56 12 : errorIfDistributedMesh("StitchedMesh"); 57 : 58 12 : if (_stitch_boundaries.size() % 2 != 0) 59 0 : mooseError("There must be an even amount of stitch_boundaries in ", name()); 60 : 61 12 : _stitch_boundaries_pairs.reserve(_stitch_boundaries.size() / 2); 62 : 63 : // Make pairs out of the boundary names 64 36 : for (MooseIndex(_stitch_boundaries) i = 0; i < _stitch_boundaries.size(); i += 2) 65 24 : _stitch_boundaries_pairs.emplace_back(_stitch_boundaries[i], _stitch_boundaries[i + 1]); 66 12 : } 67 : 68 0 : StitchedMesh::StitchedMesh(const StitchedMesh & other_mesh) 69 : : MooseMesh(other_mesh), 70 0 : _files(other_mesh._files), 71 0 : _clear_stitched_boundary_ids(other_mesh._clear_stitched_boundary_ids), 72 0 : _stitch_boundaries(other_mesh._stitch_boundaries) 73 : { 74 0 : } 75 : 76 : std::unique_ptr<MooseMesh> 77 0 : StitchedMesh::safeClone() const 78 : { 79 0 : return _app.getFactory().copyConstruct(*this); 80 : } 81 : 82 : void 83 11 : StitchedMesh::buildMesh() 84 : { 85 : // Get the original mesh 86 11 : _original_mesh = static_cast<ReplicatedMesh *>(&getMesh()); 87 : 88 : // Read the first mesh into the original mesh... then we'll stitch all of the others into that 89 11 : _original_mesh->read(_files[0]); 90 : 91 11 : _meshes.reserve(_files.size() - 1); 92 : 93 : // Read in all of the other meshes 94 33 : for (MooseIndex(_files) i = 1; i < _files.size(); ++i) 95 : { 96 22 : _meshes.emplace_back(std::make_unique<ReplicatedMesh>(_communicator)); 97 22 : auto & mesh = _meshes.back(); 98 : 99 22 : mesh->read(_files[i]); 100 : } 101 : 102 : // Stich 'em 103 33 : for (MooseIndex(_meshes) i = 0; i < _meshes.size(); i++) 104 : { 105 22 : auto & boundary_pair = _stitch_boundaries_pairs[i]; 106 : 107 22 : BoundaryID first = getBoundaryID(boundary_pair.first); 108 22 : BoundaryID second = getBoundaryID(boundary_pair.second); 109 : 110 22 : _original_mesh->stitch_meshes( 111 22 : *_meshes[i], first, second, TOLERANCE, _clear_stitched_boundary_ids); 112 : } 113 11 : }