https://mooseframework.inl.gov
BreakMeshByBlockGeneratorBase.C
Go to the documentation of this file.
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 
11 #include "InputParameters.h"
12 
15 {
17 
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 creates 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 
29  return params;
30 }
31 
33  : MeshGenerator(parameters),
34  _interface_name(getParam<std::string>("interface_name")),
35  _split_interface(getParam<bool>("split_interface"))
36 {
37  // check input consistency
38  if (getParam<bool>("split_interface") && _pars.isParamSetByUser("interface_name"))
39  {
40  mooseError("if split_interface == true, the new interface_name"
41  " cannot be specified by the user. It will be automatically assigned");
42  }
43 }
44 
47 {
48  const std::set<boundary_id_type> & currentBoundaryIds =
49  mesh.get_boundary_info().get_boundary_ids();
50  bool freeBoundaryNotFound = true;
51  boundary_id_type freeId;
52  for (freeId = 0; freeId < std::numeric_limits<boundary_id_type>::max(); freeId++)
53  {
54  if (currentBoundaryIds.count(freeId) == 0)
55  {
56  // bid is not in the set, boundaryID is free
57  freeBoundaryNotFound = false;
58  break;
59  }
60  }
61 
62  if (freeBoundaryNotFound)
63  mooseError("Too many boundaries. Maximum limit exceeded!");
64 
65  return freeId;
66 }
67 
68 std::string
70  const subdomain_id_type & primaryBlockID,
71  const subdomain_id_type & secondaryBlockID)
72 {
73  std::string primary_block_name = mesh.subdomain_name(primaryBlockID);
74  std::string secondary_block_name = mesh.subdomain_name(secondaryBlockID);
75  if (primary_block_name.empty())
76  primary_block_name = "Block" + std::to_string(primaryBlockID);
77  if (secondary_block_name.empty())
78  secondary_block_name = "Block" + std::to_string(secondaryBlockID);
79 
80  return primary_block_name + "_" + secondary_block_name;
81 }
82 
83 void
85  const std::string & boundaryName)
86 {
87  _bName_bID_set.insert(std::pair<std::string, int>(boundaryName, boundaryID));
88 }
89 
90 void
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  boundaryName = generateBoundaryName(mesh, primaryBlockID, secondaryBlockID);
104 
105  // check if the boundary name already exist
106  bool checkBoundaryAlreadyExist = false;
107  for (auto b : _bName_bID_set)
108  {
109  if (b.first.compare(boundaryName) == 0)
110  {
111  boundaryID = b.second;
112  checkBoundaryAlreadyExist = true;
113  }
114  }
115 
116  if (checkBoundaryAlreadyExist)
117  {
118  // mpi barrier end
119  return;
120  }
121  else
122  {
123  boundaryID = findFreeBoundaryId(mesh);
124  mapBoundaryIdAndBoundaryName(boundaryID, boundaryName);
125 
126  boundary_info.sideset_name(boundaryID) = boundaryName;
127 
128  return;
129  }
130 }
void findBoundaryNameAndInd(MeshBase &mesh, const subdomain_id_type &, const subdomain_id_type &, std::string &, boundary_id_type &, BoundaryInfo &)
given the primary and secondary blocks this method return the appropriate boundary id and name ...
MeshBase & mesh
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
auto max(const L &left, const R &right)
int8_t boundary_id_type
std::set< std::pair< std::string, BoundaryID > > _bName_bID_set
BreakMeshByBlockGeneratorBase(const InputParameters &parameters)
static InputParameters validParams()
Definition: MeshGenerator.C:23
bool isParamSetByUser(const std::string &name) const
Method returns true if the parameter was set by the user.
void mapBoundaryIdAndBoundaryName(boundary_id_type &, const std::string &)
this method save the boundary name/id pair
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
const InputParameters & _pars
Parameters of this object, references the InputParameters stored in the InputParametersWarehouse.
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...
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object...
BoundaryID findFreeBoundaryId(MeshBase &mesh)
this method finds the first free boundary id
std::string generateBoundaryName(MeshBase &mesh, const subdomain_id_type &, const subdomain_id_type &)
this method generate the boundary name by assembling subdomain names
MeshGenerators are objects that can modify or add to an existing mesh.
Definition: MeshGenerator.h:32