www.mooseframework.org
BreakMeshByBlockBase.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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 "BreakMeshByBlockBase.h"
11 #include "MooseMesh.h"
12 
13 template <>
16 {
18  params.addParam<std::string>(
19  "interface_name",
20  "interface",
21  "the name of the new interface. Cannot be used whit `split_interface=true`");
22  params.addParam<bool>("split_interface",
23  false,
24  "If true, it create a "
25  "different interface for each block pair.");
26  params.addClassDescription("This is the base class used to split a monolithic"
27  "mesh by blocks pairs");
28  return params;
29 }
30 
32  : MeshModifier(parameters),
33  _interface_name(getParam<std::string>("interface_name")),
34  _split_interface(getParam<bool>("split_interface"))
35 {
36 }
37 
38 void
40 {
41  mooseError("BreakMeshByBlockBase should never be called directly!"
42  "Always use one of its derived classes");
43 }
44 
45 void
47 {
48  // check input consistency
49  if (getParam<bool>("split_interface") && _pars.isParamSetByUser("interface_name"))
50  {
51  mooseError("if split_interface == true, the new interface_name"
52  " cannot be specified by the user. It will be autoamtically assigned");
53  }
54 }
55 
58 {
59  const std::set<BoundaryID> & currentBoundaryIds = _mesh_ptr->getBoundaryIDs();
60  bool freeBoundaryNotFound = true;
61  BoundaryID freeId;
62  for (freeId = 0; freeId < std::numeric_limits<BoundaryID>::max(); freeId++)
63  {
64  if (currentBoundaryIds.count(freeId) == 0)
65  {
66  // bid is not in the set, boundaryID is free
67  freeBoundaryNotFound = false;
68  break;
69  }
70  }
71 
72  if (freeBoundaryNotFound)
73  mooseError("Too many boundaries. Maximum limit exceeded!");
74 
75  return freeId;
76 }
77 
78 std::string
79 BreakMeshByBlockBase::generateBoundaryName(const subdomain_id_type & masterBlockID,
80  const subdomain_id_type & slaveBlockID)
81 {
82  std::string master_block_name = _mesh_ptr->getSubdomainName(masterBlockID);
83  std::string slave_block_name = _mesh_ptr->getSubdomainName(slaveBlockID);
84  if (master_block_name.empty())
85  master_block_name = "Block" + std::to_string(masterBlockID);
86  if (slave_block_name.empty())
87  slave_block_name = "Block" + std::to_string(slaveBlockID);
88 
89  return master_block_name + "_" + slave_block_name;
90 }
91 
92 void
94  const std::string & boundaryName)
95 {
96  _bName_bID_set.insert(std::pair<std::string, int>(boundaryName, boundaryID));
97 }
98 
99 void
100 BreakMeshByBlockBase::findBoundaryNameAndInd(const subdomain_id_type & masterBlockID,
101  const subdomain_id_type & slaveBlockID,
102  std::string & boundaryName,
103  BoundaryID & boundaryID,
104  BoundaryInfo & boundary_info)
105 {
106  // TODO need to be updated if distributed mesh is implemented
107  // comments are left to ease implementation
108 
109  // mpi barrier
110  // first check which boundary name will be created
111  boundaryName = generateBoundaryName(masterBlockID, slaveBlockID);
112 
113  // check if the boundary name already exist
114  bool checkBoundaryAlreadyExist = false;
115  for (auto b : _bName_bID_set)
116  {
117  if (b.first.compare(boundaryName) == 0)
118  {
119  boundaryID = b.second;
120  checkBoundaryAlreadyExist = true;
121  }
122  }
123 
124  if (checkBoundaryAlreadyExist)
125  {
126  // mpi barrier end
127  return;
128  }
129  else
130  {
131  boundaryID = findFreeBoundaryId();
132  mapBoundaryIdAndBoundaryName(boundaryID, boundaryName);
133 
134  boundary_info.sideset_name(boundaryID) = boundaryName;
135 
136  return;
137  }
138 }
InputParameters validParams< BreakMeshByBlockBase >()
MeshModifiers are objects that can modify or add to an existing mesh.
Definition: MeshModifier.h:25
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
void mooseError(Args &&... args) const
Definition: MooseObject.h:147
MooseMesh * _mesh_ptr
Pointer to the mesh.
Definition: MeshModifier.h:68
BoundaryID findFreeBoundaryId()
this method finds the first free boundary id
void checkInputParameter()
check that if split_interface==true interface_id and interface_name are not set by the user...
boundary_id_type BoundaryID
std::string generateBoundaryName(const subdomain_id_type &, const subdomain_id_type &)
this method generate the boundary name by assembling subdomain names
const InputParameters & _pars
Parameters of this object, references the InputParameters stored in the InputParametersWarehouse.
Definition: MooseObject.h:174
virtual void modify() override
Pure virtual modify function MUST be overridden by children classes.
bool isParamSetByUser(const std::string &name) const
Method returns true if the parameter was by the user.
BreakMeshByBlockBase(const InputParameters &parameters)
void mapBoundaryIdAndBoundaryName(BoundaryID &, const std::string &)
this method save the boundary name/id pair
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump...
std::vector< BoundaryID > getBoundaryIDs(const Elem *const elem, const unsigned short int side) const
Returns a vector of boundary IDs for the requested element on the requested side. ...
Definition: MooseMesh.C:2153
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an option parameter and a documentation string to the InputParameters object...
void findBoundaryNameAndInd(const subdomain_id_type &, const subdomain_id_type &, std::string &, BoundaryID &, BoundaryInfo &)
given the master and slave blocks this method return the appropriate boundary id and name ...
InputParameters validParams< MeshModifier >()
Definition: MeshModifier.C:15
std::set< std::pair< std::string, BoundaryID > > _bName_bID_set
const std::string & getSubdomainName(SubdomainID subdomain_id)
Return the name of a block given an id.
Definition: MooseMesh.C:1124