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 "BreakMeshByBlockGeneratorBase.h" 11 : #include "InputParameters.h" 12 : 13 : InputParameters 14 14737 : BreakMeshByBlockGeneratorBase::validParams() 15 : { 16 14737 : InputParameters params = MeshGenerator::validParams(); 17 : 18 14737 : params.addParam<std::string>( 19 : "interface_name", 20 : "interface", 21 : "the name of the new interface. Cannot be used whit `split_interface=true`"); 22 44211 : params.addParam<bool>("split_interface", 23 29474 : false, 24 : "If true, it creates a " 25 : "different interface for each block pair."); 26 14737 : params.addClassDescription("This is the base class used to split a monolithic" 27 : "mesh by blocks pairs"); 28 : 29 14737 : return params; 30 0 : } 31 : 32 236 : BreakMeshByBlockGeneratorBase::BreakMeshByBlockGeneratorBase(const InputParameters & parameters) 33 : : MeshGenerator(parameters), 34 236 : _interface_name(getParam<std::string>("interface_name")), 35 472 : _split_interface(getParam<bool>("split_interface")) 36 : { 37 : // check input consistency 38 236 : if (getParam<bool>("split_interface") && _pars.isParamSetByUser("interface_name")) 39 : { 40 0 : mooseError("if split_interface == true, the new interface_name" 41 : " cannot be specified by the user. It will be automatically assigned"); 42 : } 43 236 : } 44 : 45 : boundary_id_type 46 2956 : BreakMeshByBlockGeneratorBase::findFreeBoundaryId(MeshBase & mesh) 47 : { 48 : const std::set<boundary_id_type> & currentBoundaryIds = 49 2956 : mesh.get_boundary_info().get_boundary_ids(); 50 2956 : bool freeBoundaryNotFound = true; 51 : boundary_id_type freeId; 52 129484 : for (freeId = 0; freeId < std::numeric_limits<boundary_id_type>::max(); freeId++) 53 : { 54 129484 : if (currentBoundaryIds.count(freeId) == 0) 55 : { 56 : // bid is not in the set, boundaryID is free 57 2956 : freeBoundaryNotFound = false; 58 2956 : break; 59 : } 60 : } 61 : 62 2956 : if (freeBoundaryNotFound) 63 0 : mooseError("Too many boundaries. Maximum limit exceeded!"); 64 : 65 2956 : return freeId; 66 : } 67 : 68 : std::string 69 2840 : BreakMeshByBlockGeneratorBase::generateBoundaryName(MeshBase & mesh, 70 : const subdomain_id_type & primaryBlockID, 71 : const subdomain_id_type & secondaryBlockID) 72 : { 73 2840 : std::string primary_block_name = mesh.subdomain_name(primaryBlockID); 74 2840 : std::string secondary_block_name = mesh.subdomain_name(secondaryBlockID); 75 2840 : if (primary_block_name.empty()) 76 2840 : primary_block_name = "Block" + std::to_string(primaryBlockID); 77 2840 : if (secondary_block_name.empty()) 78 2840 : secondary_block_name = "Block" + std::to_string(secondaryBlockID); 79 : 80 8520 : return primary_block_name + "_" + secondary_block_name; 81 2840 : } 82 : 83 : void 84 2840 : BreakMeshByBlockGeneratorBase::mapBoundaryIdAndBoundaryName(boundary_id_type & boundaryID, 85 : const std::string & boundaryName) 86 : { 87 2840 : _bName_bID_set.insert(std::pair<std::string, int>(boundaryName, boundaryID)); 88 2840 : } 89 : 90 : void 91 2840 : BreakMeshByBlockGeneratorBase::findBoundaryNameAndInd(MeshBase & mesh, 92 : const subdomain_id_type & primaryBlockID, 93 : const subdomain_id_type & secondaryBlockID, 94 : std::string & boundaryName, 95 : boundary_id_type & boundaryID, 96 : BoundaryInfo & boundary_info) 97 : { 98 : // TODO need to be updated if distributed mesh is implemented 99 : // comments are left to ease implementation 100 : 101 : // mpi barrier 102 : // first check which boundary name will be created 103 2840 : boundaryName = generateBoundaryName(mesh, primaryBlockID, secondaryBlockID); 104 : 105 : // check if the boundary name already exist 106 2840 : bool checkBoundaryAlreadyExist = false; 107 97552 : for (auto b : _bName_bID_set) 108 : { 109 94712 : if (b.first.compare(boundaryName) == 0) 110 : { 111 0 : boundaryID = b.second; 112 0 : checkBoundaryAlreadyExist = true; 113 : } 114 94712 : } 115 : 116 2840 : if (checkBoundaryAlreadyExist) 117 : { 118 : // mpi barrier end 119 0 : return; 120 : } 121 : else 122 : { 123 2840 : boundaryID = findFreeBoundaryId(mesh); 124 2840 : mapBoundaryIdAndBoundaryName(boundaryID, boundaryName); 125 : 126 2840 : boundary_info.sideset_name(boundaryID) = boundaryName; 127 : 128 2840 : return; 129 : } 130 : }