https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
PatchSidesetGenerator Class Reference

Subdivides a sidesets into smaller patches each of which is going to be a new patch. More...

#include <PatchSidesetGenerator.h>

Inheritance diagram for PatchSidesetGenerator:
[legend]

Public Types

typedef DataFileName DataFileParameterType
 

Public Member Functions

 PatchSidesetGenerator (const InputParameters &parameters)
 
std::unique_ptr< MeshBase > generate () override
 
unsigned int nPatches () const
 
std::unique_ptr< CSG::CSGBasegenerateInternalCSG ()
 
std::unique_ptr< MeshBase > generateInternal ()
 
const std::set< MeshGeneratorName > & getRequestedMeshGenerators () const
 
const std::set< MeshGeneratorName > & getRequestedMeshGeneratorsForSub () const
 
void addParentMeshGenerator (const MeshGenerator &mg, const AddParentChildKey)
 
void addChildMeshGenerator (const MeshGenerator &mg, const AddParentChildKey)
 
const std::set< const MeshGenerator *, Comparator > & getParentMeshGenerators () const
 
const std::set< const MeshGenerator *, Comparator > & getChildMeshGenerators () const
 
const std::set< const MeshGenerator *, Comparator > & getSubMeshGenerators () const
 
bool isParentMeshGenerator (const MeshGeneratorName &name, const bool direct=true) const
 
bool isChildMeshGenerator (const MeshGeneratorName &name, const bool direct=true) const
 
bool isNullMeshName (const MeshGeneratorName &name) const
 
bool hasSaveMesh () const
 
bool hasOutput () const
 
const std::string & getSavedMeshName () const
 
bool hasGenerateData () const
 
bool hasGenerateCSG () const
 
bool isDataOnly () const
 
virtual bool enabled () const
 
std::shared_ptr< MooseObjectgetSharedPtr ()
 
std::shared_ptr< const MooseObjectgetSharedPtr () const
 
bool isKokkosObject () const
 
MooseAppgetMooseApp () const
 
const std::string & type () const
 
const std::string & name () const
 
std::string typeAndName () const
 
MooseObjectParameterName uniqueParameterName (const std::string &parameter_name) const
 
MooseObjectName uniqueName () const
 
const InputParametersparameters () const
 
const hit::Node * getHitNode () const
 
bool hasBase () const
 
const std::string & getBase () const
 
const TgetParam (const std::string &name) const
 
std::vector< std::pair< T1, T2 > > getParam (const std::string &param1, const std::string &param2) const
 
const TqueryParam (const std::string &name) const
 
const TgetRenamedParam (const std::string &old_name, const std::string &new_name) const
 
T getCheckedPointerParam (const std::string &name, const std::string &error_string="") const
 
bool isParamValid (const std::string &name) const
 
bool isParamSetByUser (const std::string &name) const
 
void connectControllableParams (const std::string &parameter, const std::string &object_type, const std::string &object_name, const std::string &object_parameter) const
 
void paramError (const std::string &param, Args... args) const
 
void paramWarning (const std::string &param, Args... args) const
 
void paramWarning (const std::string &param, Args... args) const
 
void paramInfo (const std::string &param, Args... args) const
 
std::string messagePrefix (const bool hit_prefix=true) const
 
std::string errorPrefix (const std::string &) const
 
void mooseError (Args &&... args) const
 
void mooseDocumentedError (const std::string &repo_name, const unsigned int issue_num, Args &&... args) const
 
void mooseErrorNonPrefixed (Args &&... args) const
 
void mooseWarning (Args &&... args) const
 
void mooseWarning (Args &&... args) const
 
void mooseWarningNonPrefixed (Args &&... args) const
 
void mooseWarningNonPrefixed (Args &&... args) const
 
void mooseDeprecated (Args &&... args) const
 
void mooseDeprecated (Args &&... args) const
 
void mooseDeprecatedNoTrace (Args &&... args) const
 
void mooseInfo (Args &&... args) const
 
void callMooseError (std::string msg, const bool with_prefix, const hit::Node *node=nullptr, const bool show_trace=true) const
 
std::string getDataFileName (const std::string &param) const
 
std::string getDataFileNameByName (const std::string &relative_path) const
 
std::string getDataFilePath (const std::string &relative_path) const
 
const Parallel::Communicator & comm () const
 
processor_id_type n_processors () const
 
processor_id_type processor_id () const
 

Static Public Member Functions

static InputParameters validParams ()
 
static bool hasGenerateData (const InputParameters &params)
 
static bool hasGenerateCSG (const InputParameters &params)
 
static void callMooseError (MooseApp *const app, const InputParameters &params, std::string msg, const bool with_prefix, const hit::Node *node, const bool show_trace=true)
 
static void setHasGenerateData (InputParameters &params)
 
static void setHasGenerateCSG (InputParameters &params)
 

Public Attributes

 usingCombinedWarningSolutionWarnings
 
const ConsoleStream _console
 

Static Public Attributes

static const std::string data_only_param
 
static const std::string type_param
 
static const std::string name_param
 
static const std::string unique_name_param
 
static const std::string app_param
 
static const std::string moose_base_param
 
static const std::string kokkos_object_param
 
static constexpr auto SYSTEM
 
static constexpr auto NAME
 

Protected Member Functions

std::vector< BoundaryName > sidesetNameHelper (const std::string &base_name) const
 returns the name of the _n_patches subdivisions derived from _sideset
 
Elem * boundaryElementHelper (MeshBase &mesh, libMesh::ElemType type) const
 
void partition (MeshBase &mesh)
 a function for implementing custom partitioning
 
void checkPartitionAndCompress (MeshBase &mesh)
 Checks partitions and makes sure every partition has at least one elem.
 
virtual void generateData ()
 
virtual std::unique_ptr< CSG::CSGBasegenerateCSG ()
 
TcopyMeshProperty (const std::string &target_data_name, const std::string &source_data_name, const std::string &source_mesh)
 
TcopyMeshProperty (const std::string &source_data_name, const std::string &source_mesh)
 
std::unique_ptr< MeshBase > & getMesh (const std::string &param_name, const bool allow_invalid=false)
 
std::vector< std::unique_ptr< MeshBase > * > getMeshes (const std::string &param_name)
 
std::unique_ptr< MeshBase > & getMeshByName (const MeshGeneratorName &mesh_generator_name)
 
std::vector< std::unique_ptr< MeshBase > * > getMeshesByName (const std::vector< MeshGeneratorName > &mesh_generator_names)
 
std::unique_ptr< CSG::CSGBase > & getCSGBase (const std::string &param_name)
 
std::unique_ptr< CSG::CSGBase > & getCSGBaseByName (const MeshGeneratorName &mesh_generator_name)
 
std::vector< std::unique_ptr< CSG::CSGBase > * > getCSGBases (const std::string &param_name)
 
std::vector< std::unique_ptr< CSG::CSGBase > * > getCSGBasesByName (const std::vector< MeshGeneratorName > &mesh_generator_names)
 
void declareMeshForSub (const std::string &param_name)
 
void declareMeshesForSub (const std::string &param_name)
 
void declareMeshForSubByName (const MeshGeneratorName &mesh_generator_name)
 
void declareMeshesForSubByName (const std::vector< MeshGeneratorName > &mesh_generator_names)
 
std::unique_ptr< MeshBase > buildMeshBaseObject (unsigned int dim=libMesh::invalid_uint)
 
std::unique_ptr< ReplicatedMesh > buildReplicatedMesh (unsigned int dim=libMesh::invalid_uint)
 
std::unique_ptr< DistributedMesh > buildDistributedMesh (unsigned int dim=libMesh::invalid_uint)
 
void addMeshSubgenerator (const std::string &type, const std::string &name, Ts... extra_input_parameters)
 
void addMeshSubgenerator (const std::string &type, const std::string &name, InputParameters params)
 
void declareNullMeshName (const MeshGeneratorName &name)
 
void flagInvalidSolutionInternal (const InvalidSolutionID invalid_solution_id) const
 
InvalidSolutionID registerInvalidSolutionInternal (const std::string &message, const bool warning) const
 
const TgetMeshProperty (const std::string &data_name, const std::string &prefix)
 
const TgetMeshProperty (const std::string &data_name)
 
bool hasMeshProperty (const std::string &data_name, const std::string &prefix) const
 
bool hasMeshProperty (const std::string &data_name, const std::string &prefix) const
 
bool hasMeshProperty (const std::string &data_name) const
 
bool hasMeshProperty (const std::string &data_name) const
 
std::string meshPropertyName (const std::string &data_name) const
 
TdeclareMeshProperty (const std::string &data_name, Args &&... args)
 
TdeclareMeshProperty (const std::string &data_name, const T &data_value)
 
TdeclareMeshProperty (const std::string &data_name, Args &&... args)
 
TdeclareMeshProperty (const std::string &data_name, const T &data_value)
 
TsetMeshProperty (const std::string &data_name, Args &&... args)
 
TsetMeshProperty (const std::string &data_name, const T &data_value)
 
TsetMeshProperty (const std::string &data_name, Args &&... args)
 
TsetMeshProperty (const std::string &data_name, const T &data_value)
 

Static Protected Member Functions

static std::string meshPropertyName (const std::string &data_name, const std::string &prefix)
 

Protected Attributes

std::unique_ptr< MeshBase > & _input
 
unsigned int _dim
 dimensionality of the sidesets to partition
 
unsigned int _n_patches
 the number of patches that this sideset generator divides _sideset into
 
const BoundaryName & _sideset_name
 The sideset that will be subdivided.
 
MooseEnum _partitioner_name
 the name of the partitioner being used
 
BoundaryID _sideset
 The sideset that will be subdivided.
 
dof_id_type _n_boundary_mesh_elems
 number of elements of the boundary mesh
 
MooseMesh *const _mesh
 
const bool & _enabled
 
MooseApp_app
 
Factory_factory
 
ActionFactory_action_factory
 
const std::string & _type
 
const std::string & _name
 
const InputParameters_pars
 
const Parallel::Communicator & _communicator
 

Private Member Functions

virtual std::string meshPropertyPrefix (const std::string &) const override final
 
void checkGetMesh (const MeshGeneratorName &mesh_generator_name, const std::string &param_name) const
 
const MeshGeneratorName * getMeshGeneratorNameFromParam (const std::string &param_name, const bool allow_invalid) const
 
const std::vector< MeshGeneratorName > & getMeshGeneratorNamesFromParam (const std::string &param_name) const
 
RestartableDataValuesetMeshPropertyHelper (const std::string &data_name)
 
const RestartableDataValuegetMeshPropertyInternal (const std::string &data_name, const std::string &prefix) const
 
void mooseErrorInternal (Args &&... args) const
 

Static Private Member Functions

static const hit::Node * getHitNode (const InputParameters &params)
 
static std::string messagePrefix (const InputParameters &params, const bool hit_prefix)
 

Private Attributes

std::set< MeshGeneratorName > _requested_mesh_generators
 
std::set< MeshGeneratorName > _requested_mesh_generators_for_sub
 
std::vector< std::pair< std::string, std::unique_ptr< MeshBase > * > > _requested_meshes
 
std::vector< std::pair< std::string, std::unique_ptr< CSG::CSGBase > * > > _requested_csg_bases
 
std::unique_ptr< MeshBase > _null_mesh
 
std::unique_ptr< CSG::CSGBase_null_csg_base
 
std::set< const MeshGenerator *, Comparator > _parent_mesh_generators
 
std::set< const MeshGenerator *, Comparator > _child_mesh_generators
 
std::set< const MeshGenerator *, Comparator > _sub_mesh_generators
 
std::set< std::string > _null_mesh_names
 
const std::string & _save_with_name
 
const bool _data_only
 
const ParallelParamObject_parent
 
const MooseBase_si_moose_base
 
const FEProblemBase_si_problem
 
MooseApp_meta_data_app
 
const MooseObject *const _meta_data_object
 

Detailed Description

Subdivides a sidesets into smaller patches each of which is going to be a new patch.

Definition at line 21 of file PatchSidesetGenerator.h.

Constructor & Destructor Documentation

◆ PatchSidesetGenerator()

PatchSidesetGenerator::PatchSidesetGenerator ( const InputParameters parameters)

Definition at line 64 of file PatchSidesetGenerator.C.

66 _input(getMesh("input")),
67 _n_patches(getParam<unsigned int>("n_patches")),
68 _sideset_name(getParam<BoundaryName>("boundary")),
69 _partitioner_name(getParam<MooseEnum>("partitioner"))
70{
71}
std::unique_ptr< MeshBase > & getMesh(const std::string &param_name, const bool allow_invalid=false)
const InputParameters & parameters() const
MooseEnum _partitioner_name
the name of the partitioner being used
unsigned int _n_patches
the number of patches that this sideset generator divides _sideset into
const BoundaryName & _sideset_name
The sideset that will be subdivided.
std::unique_ptr< MeshBase > & _input

Member Function Documentation

◆ boundaryElementHelper()

Elem * PatchSidesetGenerator::boundaryElementHelper ( MeshBase &  mesh,
libMesh::ElemType  type 
) const
protected

Definition at line 369 of file PatchSidesetGenerator.C.

370{
371 std::unique_ptr<Elem> elem = libMesh::Elem::build(type);
372 if (elem->dim() < 3)
373 return mesh.add_elem(std::move(elem));
374
375 mooseError("Unsupported element type (libMesh elem_type enum): ", type);
376}
const std::string & type() const
void mooseError(Args &&... args) const
static std::unique_ptr< Elem > build(const ElemType type, Elem *p=nullptr)
MeshBase & mesh

Referenced by generate().

◆ checkPartitionAndCompress()

void PatchSidesetGenerator::checkPartitionAndCompress ( MeshBase &  mesh)
protected

Checks partitions and makes sure every partition has at least one elem.

If a partition is empty, it's removed and the remaining ones are "renamed"

Definition at line 318 of file PatchSidesetGenerator.C.

319{
320 std::set<processor_id_type> processor_ids;
321 for (auto & elem_ptr : mesh.active_element_ptr_range())
322 processor_ids.insert(elem_ptr->processor_id());
323
324 if (processor_ids.size() == _n_patches)
325 return;
326
327 // at least one partition does not have an elem assigned to it
328 // adjust _n_patches
329 _console << "Some partitions for side set " << _sideset
330 << " are empty. Adjusting number of patches from " << _n_patches << " to "
331 << processor_ids.size() << std::endl;
332 _n_patches = processor_ids.size();
333
334 // create a vector and sort it
335 std::vector<processor_id_type> processor_ids_vec;
336 for (auto & p : processor_ids)
337 processor_ids_vec.push_back(p);
338 std::sort(processor_ids_vec.begin(), processor_ids_vec.end());
339
340 // now remap the processor ids
341 std::map<processor_id_type, processor_id_type> processor_id_remap;
342 for (MooseIndex(processor_ids_vec.size()) j = 0; j < processor_ids_vec.size(); ++j)
343 processor_id_remap[processor_ids_vec[j]] = j;
344
345 for (auto & elem_ptr : mesh.active_element_ptr_range())
346 {
347 processor_id_type p = elem_ptr->processor_id();
348 const auto & it = processor_id_remap.find(p);
349 if (it == processor_id_remap.end())
350 mooseError("Parition id ", p, " not in processor_id_remap.");
351 elem_ptr->processor_id() = it->second;
352 }
353}
const Real p
const ConsoleStream _console
BoundaryID _sideset
The sideset that will be subdivided.
processor_id_type processor_id() const
uint8_t processor_id_type

Referenced by generate().

◆ generate()

std::unique_ptr< MeshBase > PatchSidesetGenerator::generate ( )
overridevirtual

Implements MeshGenerator.

Definition at line 74 of file PatchSidesetGenerator.C.

75{
76 std::unique_ptr<MeshBase> mesh = std::move(_input);
77
78 _mesh->errorIfDistributedMesh("PatchSidesetGenerator");
79
80 // Get a reference to our BoundaryInfo object for later use
81 BoundaryInfo & boundary_info = mesh->get_boundary_info();
82
83 // get dimensionality
84 _dim = mesh->mesh_dimension() - 1;
85
86 // get a list of all sides; vector of tuples (elem, loc_side, side_set)
87 auto side_list = boundary_info.build_active_side_list();
88
90 paramError("boundary",
91 "The provided boundary name or ID (" + _sideset_name +
92 ") does not exist in the mesh.");
93
95
96 // create a dim - 1 dimensional mesh
97 auto boundary_mesh = buildReplicatedMesh(mesh->mesh_dimension() - 1);
98 boundary_mesh->set_mesh_dimension(mesh->mesh_dimension() - 1);
99 boundary_mesh->set_spatial_dimension(mesh->mesh_dimension());
100
101 // nodes in the new mesh by boundary_node_id (index)
102 std::vector<Node *> boundary_nodes;
103 // a map from the node numbering on the volumetric mesh to the numbering
104 // on the boundary_mesh
105 std::map<dof_id_type, dof_id_type> mesh_node_id_to_boundary_node_id;
106 // a local counter keeping track of how many entries have been added to boundary_nodes
107 dof_id_type boundary_node_id = 0;
108 // a map from new element id in the boundary mesh to the element id/side/sideset
109 // tuple it came from
110 std::map<dof_id_type, std::tuple<dof_id_type, unsigned short int, boundary_id_type>>
111 boundary_elem_to_mesh_elem;
112 for (auto & side : side_list)
113 {
114 if (std::get<2>(side) == _sideset)
115 {
116 // the original volumetric mesh element
117 const Elem * elem = mesh->elem_ptr(std::get<0>(side));
118
119 // the boundary element
120 std::unique_ptr<const Elem> boundary_elem = elem->side_ptr(std::get<1>(side));
121
122 // an array that saves the boundary node ids of this elem in the right order
123 std::vector<dof_id_type> bnd_elem_node_ids(boundary_elem->n_nodes());
124
125 // loop through the nodes in boundary_elem
126 for (MooseIndex(boundary_elem->n_nodes()) j = 0; j < boundary_elem->n_nodes(); ++j)
127 {
128 const Node * node = boundary_elem->node_ptr(j);
129
130 // Is this node a new node?
131 if (mesh_node_id_to_boundary_node_id.find(node->id()) ==
132 mesh_node_id_to_boundary_node_id.end())
133 {
134 // yes, it is new, need to add it to the mesh_node_id_to_boundary_node_id map
135 mesh_node_id_to_boundary_node_id.insert(
136 std::pair<dof_id_type, dof_id_type>(node->id(), boundary_node_id));
137
138 // this adds this node to the boundary mesh and puts it at the right position
139 // in the boundary_nodes array
140 Point pt(*node);
141 boundary_nodes.push_back(boundary_mesh->add_point(pt, boundary_node_id));
142
143 // keep track of the boundary node for setting up the element
144 bnd_elem_node_ids[j] = boundary_node_id;
145
146 // increment the boundary_node_id counter
147 ++boundary_node_id;
148 }
149 else
150 bnd_elem_node_ids[j] = mesh_node_id_to_boundary_node_id.find(node->id())->second;
151 }
152
153 // all nodes for this element have been added, so we can add the element to the
154 // boundary mesh
155 Elem * new_bnd_elem = boundaryElementHelper(*boundary_mesh, boundary_elem->type());
156
157 // keep track of these new boundary elements in boundary_elem_to_mesh_elem
158 boundary_elem_to_mesh_elem.insert(
159 std::pair<dof_id_type, std::tuple<dof_id_type, unsigned short int, boundary_id_type>>(
160 new_bnd_elem->id(), side));
161
162 // set the nodes & subdomain_id of the new element by looping over the
163 // boundary_elem and then inserting its nodes into new_bnd_elem in the
164 // same order
165 for (MooseIndex(boundary_elem->n_nodes()) j = 0; j < boundary_elem->n_nodes(); ++j)
166 {
167 dof_id_type old_node_id = boundary_elem->node_ptr(j)->id();
168 if (mesh_node_id_to_boundary_node_id.find(old_node_id) ==
169 mesh_node_id_to_boundary_node_id.end())
170 mooseError("Node id", old_node_id, " not linked to new node id.");
171 dof_id_type new_node_id = mesh_node_id_to_boundary_node_id.find(old_node_id)->second;
172 new_bnd_elem->set_node(j, boundary_nodes[new_node_id]);
173 }
174 }
175 }
176
177 // partition the boundary mesh
178 boundary_mesh->prepare_for_use();
179 _n_boundary_mesh_elems = boundary_mesh->n_elem();
180 if (_partitioner_name == "grid")
181 partition(*boundary_mesh);
182 else
183 {
184 auto partitioner_enum = getParam<MooseEnum>("partitioner");
185 MooseMesh::setPartitioner(*boundary_mesh, partitioner_enum, false, _pars, *this);
186 boundary_mesh->partition(_n_patches);
187 }
188
189 // make sure every partition has at least one element; if not rename and adjust _n_patches
190 checkPartitionAndCompress(*boundary_mesh);
191
192 // prepare sideset names and boundary_ids added to mesh
193 std::vector<BoundaryName> sideset_names =
194 sidesetNameHelper(boundary_info.get_sideset_name(_sideset));
195
196 std::vector<boundary_id_type> boundary_ids =
197 MooseMeshUtils::getBoundaryIDs(*mesh, sideset_names, true);
198
199 mooseAssert(sideset_names.size() == _n_patches,
200 "sideset_names must have as many entries as user-requested number of patches.");
201 mooseAssert(boundary_ids.size() == _n_patches,
202 "boundary_ids must have as many entries as user-requested number of patches.");
203
204 // loop through all elements in the boundary mesh and assign the side of
205 // the _original_ element to the new sideset
206 for (const auto & elem : boundary_mesh->active_element_ptr_range())
207 {
208 const auto it = boundary_elem_to_mesh_elem.find(elem->id());
209 if (it == boundary_elem_to_mesh_elem.end())
210 mooseError("Element in the boundary mesh with id ",
211 elem->id(),
212 " not found in boundary_elem_to_mesh_elem.");
213
214 auto side = boundary_elem_to_mesh_elem.find(elem->id())->second;
215
216 mooseAssert(elem->processor_id() < boundary_ids.size(),
217 "Processor id larger than number of patches.");
218 boundary_info.add_side(
219 std::get<0>(side), std::get<1>(side), boundary_ids[elem->processor_id()]);
220 }
221
222 // make sure new boundary names are set
223 for (MooseIndex(boundary_ids.size()) j = 0; j < boundary_ids.size(); ++j)
224 {
225 boundary_info.sideset_name(boundary_ids[j]) = sideset_names[j];
226 boundary_info.nodeset_name(boundary_ids[j]) = sideset_names[j];
227 }
228
229 return mesh;
230}
MooseMesh *const _mesh
std::unique_ptr< ReplicatedMesh > buildReplicatedMesh(unsigned int dim=libMesh::invalid_uint)
void paramError(const std::string &param, Args... args) const
const InputParameters & _pars
void errorIfDistributedMesh(std::string name) const
static void setPartitioner(MeshBase &mesh_base, MooseEnum &partitioner, bool use_distributed_mesh, const InputParameters &params, MooseObject &context_obj)
unsigned int _dim
dimensionality of the sidesets to partition
void partition(MeshBase &mesh)
a function for implementing custom partitioning
Elem * boundaryElementHelper(MeshBase &mesh, libMesh::ElemType type) const
void checkPartitionAndCompress(MeshBase &mesh)
Checks partitions and makes sure every partition has at least one elem.
dof_id_type _n_boundary_mesh_elems
number of elements of the boundary mesh
std::vector< BoundaryName > sidesetNameHelper(const std::string &base_name) const
returns the name of the _n_patches subdivisions derived from _sideset
std::vector< BoundaryID > getBoundaryIDs(const libMesh::MeshBase &mesh, const std::vector< BoundaryName > &boundary_name, bool generate_unknown, const std::set< BoundaryID > &mesh_boundary_ids)
BoundaryID getBoundaryID(const BoundaryName &boundary_name, const MeshBase &mesh)
bool hasBoundaryNameOrID(const MeshBase &mesh, const BoundaryName &name_or_id)
uint8_t dof_id_type

◆ nPatches()

unsigned int PatchSidesetGenerator::nPatches ( ) const
inline

Definition at line 30 of file PatchSidesetGenerator.h.

30{ return _n_patches; }

Referenced by RadiationTransferAction::nPatch().

◆ partition()

void PatchSidesetGenerator::partition ( MeshBase &  mesh)
protected

a function for implementing custom partitioning

Definition at line 233 of file PatchSidesetGenerator.C.

234{
235 if (_partitioner_name == "grid")
236 {
237 // Figure out the physical bounds of the given mesh
238 auto bounding_box = MeshTools::create_bounding_box(mesh);
239 const auto & min = bounding_box.min();
240 const auto & max = bounding_box.max();
241 const auto & delta = max - min;
242
243 // set number of elements
244 std::vector<unsigned int> nelems(3);
245 if (_dim == 1)
246 {
247 // find the largest component in delta
248 unsigned int largest_id = 0;
249 Real largest = delta(0);
250 for (unsigned int j = 1; j < 3; ++j)
251 if (largest < delta(j))
252 {
253 largest = delta(j);
254 largest_id = j;
255 }
256
257 // set nelems now
258 nelems = {1, 1, 1};
259 nelems[largest_id] = _n_patches;
260 }
261 else
262 {
263 // find the smallest component in delta
264 unsigned int smallest_id = 0;
265 Real smallest = delta(0);
266 for (unsigned int j = 1; j < 3; ++j)
267 if (smallest > delta(j))
268 {
269 smallest = delta(j);
270 smallest_id = j;
271 }
272
273 // store the ids for the two larger dimensions
274 unsigned int id1 = 1, id2 = 2;
275 if (smallest_id == 1)
276 id1 = 0;
277 else if (smallest_id == 2)
278 id2 = 0;
279
280 // set number of elements
281 nelems[smallest_id] = 1;
282 nelems[id1] = std::round(std::sqrt(delta(id1) / delta(id2) * _n_patches));
283 nelems[id2] = std::round(std::sqrt(delta(id2) / delta(id1) * _n_patches));
284 const std::size_t final_n_patches = nelems[id1] * nelems[id2];
285 // We need to check if the number of requested patches and the number of
286 // actually created patches matches. If the two do not match, then a warning
287 // is printed.
288 if (_n_patches != final_n_patches)
289 {
290 _console << "Note: For creating radiation patches for boundary " << _sideset
291 << " using grid partitioner number of patches was changed from " << _n_patches
292 << " to " << final_n_patches << std::endl;
293 _n_patches = final_n_patches;
294 }
295 }
296
297 const Point delem(delta(0) / nelems[0], delta(1) / nelems[1], delta(2) / nelems[2]);
298 for (auto & elem_ptr : mesh.active_element_ptr_range())
299 {
300 const Point centroid = elem_ptr->vertex_average();
301 std::array<unsigned int, 3> ielem;
302 for (const auto i : make_range(LIBMESH_DIM))
303 {
304 const auto dist = centroid(i) - min(i);
305 ielem[i] = (std::abs(dist) < (libMesh::TOLERANCE * libMesh::TOLERANCE))
306 ? 0
307 : std::floor(dist / delem(i));
308 }
309 elem_ptr->processor_id() = ielem[0] + nelems[0] * (ielem[1] + ielem[2] * nelems[1]);
310 mooseAssert(elem_ptr->processor_id() < _n_patches, "Invalid processor id");
311 }
312 }
313 else
314 mooseError("Partitioner ", _partitioner_name, " not recognized.");
315}
auto max(const L &left, const R &right)
auto min(const L &left, const R &right)
int delta(unsigned int i, unsigned int j)
Delta function, which returns zero if $i\ne j$ and unity if $i=j$.
static constexpr Real TOLERANCE
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
IntRange< T > make_range(T beg, T end)

Referenced by generate().

◆ sidesetNameHelper()

std::vector< BoundaryName > PatchSidesetGenerator::sidesetNameHelper ( const std::string &  base_name) const
protected

returns the name of the _n_patches subdivisions derived from _sideset

Definition at line 356 of file PatchSidesetGenerator.C.

357{
358 std::vector<BoundaryName> rv;
359 for (unsigned int j = 0; j < _n_patches; ++j)
360 {
361 std::stringstream ss;
362 ss << base_name << "_" << j;
363 rv.push_back(ss.str());
364 }
365 return rv;
366}

Referenced by generate().

◆ validParams()

InputParameters PatchSidesetGenerator::validParams ( )
static

Definition at line 33 of file PatchSidesetGenerator.C.

34{
36
37 params.addRequiredParam<MeshGeneratorName>("input", "The mesh we want to modify");
38 params.addRequiredParam<BoundaryName>("boundary",
39 "The boundary that will be divided into patches");
40 params.addRequiredRangeCheckedParam<unsigned int>(
41 "n_patches", "n_patches>0", "Number of patches");
42
43 MooseEnum partitioning = MooseMesh::partitioning(); // default MOOSE partitioning
44 partitioning += "grid"; // ...but also add our own
45 params.addParam<MooseEnum>(
46 "partitioner",
47 partitioning,
48 "Specifies a mesh partitioner to use when splitting the mesh for a parallel computation.");
49
50 MooseEnum direction("x y z radial");
51 params.addParam<MooseEnum>("centroid_partitioner_direction",
52 direction,
53 "Specifies the sort direction if using the centroid partitioner. "
54 "Available options: x, y, z, radial");
55
56 params.addParamNamesToGroup("partitioner centroid_partitioner_direction", "Partitioning");
57
59 "Divides the given sideset into smaller patches of roughly equal size.");
60
61 return params;
62}
void addParamNamesToGroup(const std::string &space_delim_names, const std::string group_name)
void addRequiredRangeCheckedParam(const std::string &name, const std::string &parsed_function, const std::string &doc_string)
void addRequiredParam(const std::string &name, const std::string &doc_string)
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
void addClassDescription(const std::string &doc_string)
static InputParameters validParams()
static MooseEnum partitioning()

Member Data Documentation

◆ _dim

unsigned int PatchSidesetGenerator::_dim
protected

dimensionality of the sidesets to partition

Definition at line 50 of file PatchSidesetGenerator.h.

Referenced by generate(), and partition().

◆ _input

std::unique_ptr<MeshBase>& PatchSidesetGenerator::_input
protected

Definition at line 47 of file PatchSidesetGenerator.h.

Referenced by generate().

◆ _n_boundary_mesh_elems

dof_id_type PatchSidesetGenerator::_n_boundary_mesh_elems
protected

number of elements of the boundary mesh

Definition at line 65 of file PatchSidesetGenerator.h.

Referenced by generate().

◆ _n_patches

unsigned int PatchSidesetGenerator::_n_patches
protected

the number of patches that this sideset generator divides _sideset into

Definition at line 53 of file PatchSidesetGenerator.h.

Referenced by checkPartitionAndCompress(), generate(), nPatches(), partition(), and sidesetNameHelper().

◆ _partitioner_name

MooseEnum PatchSidesetGenerator::_partitioner_name
protected

the name of the partitioner being used

Definition at line 59 of file PatchSidesetGenerator.h.

Referenced by generate(), and partition().

◆ _sideset

BoundaryID PatchSidesetGenerator::_sideset
protected

The sideset that will be subdivided.

Definition at line 62 of file PatchSidesetGenerator.h.

Referenced by checkPartitionAndCompress(), generate(), and partition().

◆ _sideset_name

const BoundaryName& PatchSidesetGenerator::_sideset_name
protected

The sideset that will be subdivided.

Definition at line 56 of file PatchSidesetGenerator.h.

Referenced by generate().


The documentation for this class was generated from the following files: