https://mooseframework.inl.gov
ReportingIDGeneratorUtils.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 
12 using namespace libMesh;
13 
14 std::vector<dof_id_type>
16  const std::vector<std::unique_ptr<ReplicatedMesh>> & meshes,
17  const std::vector<std::vector<unsigned int>> & pattern,
18  const bool use_exclude_id,
19  const std::vector<bool> & exclude_ids)
20 {
21  dof_id_type n = 0;
22  for (MooseIndex(pattern) i = 0; i < pattern.size(); ++i)
23  for (MooseIndex(pattern[i]) j = 0; j < pattern[i].size(); ++j)
24  n += meshes[pattern[i][j]]->n_elem();
25  std::vector<dof_id_type> integer_ids;
26  integer_ids.reserve(n);
27  dof_id_type id = 0;
28  for (MooseIndex(pattern) i = 0; i < pattern.size(); ++i)
29  for (MooseIndex(pattern[i]) j = 0; j < pattern[i].size(); ++j)
30  {
31  const auto value =
32  (use_exclude_id && exclude_ids[pattern[i][j]]) ? DofObject::invalid_id : id++;
33  integer_ids.insert(integer_ids.end(), meshes[pattern[i][j]]->n_elem(), value);
34  }
35  return integer_ids;
36 }
37 
38 std::vector<dof_id_type>
40  const std::vector<std::unique_ptr<ReplicatedMesh>> & meshes,
41  const std::vector<std::vector<unsigned int>> & pattern)
42 {
43  dof_id_type n = 0;
44  for (MooseIndex(pattern) i = 0; i < pattern.size(); ++i)
45  for (MooseIndex(pattern[i]) j = 0; j < pattern[i].size(); ++j)
46  n += meshes[pattern[i][j]]->n_elem();
47  std::vector<dof_id_type> integer_ids;
48  integer_ids.reserve(n);
49  for (MooseIndex(pattern) i = 0; i < pattern.size(); ++i)
50  for (MooseIndex(pattern[i]) j = 0; j < pattern[i].size(); ++j)
51  integer_ids.insert(integer_ids.end(), meshes[pattern[i][j]]->n_elem(), pattern[i][j]);
52  return integer_ids;
53 }
54 
55 std::vector<dof_id_type>
57  const std::vector<std::unique_ptr<ReplicatedMesh>> & meshes,
58  const std::vector<std::vector<unsigned int>> & pattern,
59  const std::vector<std::vector<dof_id_type>> & id_pattern)
60 {
61  dof_id_type n = 0;
62  for (MooseIndex(pattern) i = 0; i < pattern.size(); ++i)
63  for (MooseIndex(pattern[i]) j = 0; j < pattern[i].size(); ++j)
64  n += meshes[pattern[i][j]]->n_elem();
65  std::vector<dof_id_type> integer_ids;
66  integer_ids.reserve(n);
67  for (MooseIndex(pattern) i = 0; i < pattern.size(); ++i)
68  for (MooseIndex(pattern[i]) j = 0; j < pattern[i].size(); ++j)
69  integer_ids.insert(integer_ids.end(), meshes[pattern[i][j]]->n_elem(), id_pattern[i][j]);
70  return integer_ids;
71 }
72 
73 std::set<SubdomainID>
75  const std::vector<std::unique_ptr<ReplicatedMesh>> & meshes,
76  const std::vector<std::vector<unsigned int>> & pattern)
77 {
78  std::set<SubdomainID> blks;
79  for (MooseIndex(pattern) i = 0; i < pattern.size(); ++i)
80  for (MooseIndex(pattern[i]) j = 0; j < pattern[i].size(); ++j)
81  {
82  std::set<SubdomainID> mesh_blks;
83  meshes[pattern[i][j]]->subdomain_ids(mesh_blks);
84  blks.insert(mesh_blks.begin(), mesh_blks.end());
85  }
86  return blks;
87 }
88 
89 std::map<SubdomainID, unsigned int>
91  const bool has_assembly_boundary,
92  const std::set<subdomain_id_type> background_blk_ids,
93  const std::set<SubdomainID> & blks)
94 {
95  std::map<SubdomainID, unsigned int> blks_duct;
96  if (has_assembly_boundary)
97  {
98  std::set<SubdomainID> mesh_blks;
99  mesh.subdomain_ids(mesh_blks);
100  unsigned int i = 0;
101  for (const auto mesh_blk : mesh_blks)
102  if (!blks.count(mesh_blk) && !background_blk_ids.count(mesh_blk))
103  blks_duct[mesh_blk] = i++;
104  // delete the first entry because it is for surrouding regions between the assembly duct and pin
105  if (background_blk_ids.size() == 0)
106  blks_duct.erase(blks_duct.begin());
107  }
108  return blks_duct;
109 }
110 
111 void
113  MeshBase & mesh,
114  const unsigned int extra_id_index,
115  const ReportingIDGeneratorUtils::AssignType assign_type,
116  const bool use_exclude_id,
117  const std::vector<bool> & exclude_ids,
118  const bool has_assembly_boundary,
119  const std::set<subdomain_id_type> background_block_ids,
120  const std::vector<std::unique_ptr<ReplicatedMesh>> & input_meshes,
121  const std::vector<std::vector<unsigned int>> & pattern,
122  const std::vector<std::vector<dof_id_type>> & id_pattern)
123 {
124  std::vector<dof_id_type> integer_ids;
125  // get reporting ID map
126  // assumes that the entire mesh has elements of each individual mesh sequentially ordered.
127  if (assign_type == AssignType::cell)
128  integer_ids = getCellwiseIntegerIDs(input_meshes, pattern, use_exclude_id, exclude_ids);
129  else if (assign_type == AssignType::pattern)
130  integer_ids = getPatternIntegerIDs(input_meshes, pattern);
131  else if (assign_type == AssignType::manual)
132  integer_ids = getManualIntegerIDs(input_meshes, pattern, id_pattern);
133 
134  if (has_assembly_boundary)
135  {
136  // setup assembly duct information
137  const std::set<SubdomainID> blks = getCellBlockIDs(input_meshes, pattern);
138  const unsigned int duct_boundary_id =
139  *std::max_element(integer_ids.begin(), integer_ids.end()) + 1;
140  const std::map<SubdomainID, unsigned int> blks_duct =
141  getDuckBlockIDs(mesh, has_assembly_boundary, background_block_ids, blks);
142 
143  // assign reporting IDs to individual elements
144  unsigned int i = 0;
145  unsigned int id = integer_ids[i];
146  unsigned old_id = id;
147  for (auto elem : mesh.element_ptr_range())
148  {
149  auto blk = elem->subdomain_id();
150  // check whether the current element belongs to duct/surrouding regions or not
151  if (!blks.count(blk))
152  {
153  // check whether the current element belongs to surroudning or duct regions
154  if (!blks_duct.count(blk))
155  // if the current element belongs to the surronding region
156  elem->set_extra_integer(extra_id_index, old_id);
157  else
158  // if the current element belongs to the duct region
159  elem->set_extra_integer(extra_id_index, duct_boundary_id + blks_duct.at(blk));
160  }
161  else
162  {
163  // if the current element belongs to pin regions
164  elem->set_extra_integer(extra_id_index, id);
165  ++i;
166  old_id = id;
167  if (i < integer_ids.size())
168  id = integer_ids[i];
169  }
170  }
171  }
172  else
173  {
174  // assign reporting IDs to individual elements
175  unsigned int i = 0;
176  for (auto & elem : mesh.element_ptr_range())
177  elem->set_extra_integer(extra_id_index, integer_ids[i++]);
178  }
179 }
std::vector< dof_id_type > getManualIntegerIDs(const std::vector< std::unique_ptr< libMesh::ReplicatedMesh >> &meshes, const std::vector< std::vector< unsigned int >> &pattern, const std::vector< std::vector< dof_id_type >> &id_pattern)
assign IDs based on user-defined mapping defined in id_pattern
void assignReportingIDs(MeshBase &mesh, const unsigned int extra_id_index, const ReportingIDGeneratorUtils::AssignType assign_type, const bool use_exclude_id, const std::vector< bool > &exclude_ids, const bool has_assembly_boundary, const std::set< subdomain_id_type > background_block_ids, const std::vector< std::unique_ptr< libMesh::ReplicatedMesh >> &input_meshes, const std::vector< std::vector< unsigned int >> &pattern, const std::vector< std::vector< dof_id_type >> &id_pattern)
assign the reporting IDs to the output mesh from the cartesian or hexagonal patterned mesh generator ...
dof_id_type n_elem(const MeshBase::const_element_iterator &begin, const MeshBase::const_element_iterator &end)
AssignType
Enum item for reporting id assign types.
std::map< SubdomainID, unsigned int > getDuckBlockIDs(const MeshBase &mesh, const bool has_assembly_boundary, const std::set< subdomain_id_type > background_blk_ids, const std::set< SubdomainID > &blks)
get list of block IDs for the assembly duck regions
std::vector< dof_id_type > getCellwiseIntegerIDs(const std::vector< std::unique_ptr< libMesh::ReplicatedMesh >> &meshes, const std::vector< std::vector< unsigned int >> &pattern, const bool use_exclude_id, const std::vector< bool > &exclude_ids)
assign IDs for each component in pattern in sequential order
MeshBase & mesh
The following methods are specializations for using the Parallel::packed_range_* routines for a vecto...
std::vector< dof_id_type > getPatternIntegerIDs(const std::vector< std::unique_ptr< libMesh::ReplicatedMesh >> &meshes, const std::vector< std::vector< unsigned int >> &pattern)
assign IDs for each input component type
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)
std::set< SubdomainID > getCellBlockIDs(const std::vector< std::unique_ptr< libMesh::ReplicatedMesh >> &meshes, const std::vector< std::vector< unsigned int >> &pattern)
get list of block IDs in input mesh cells
void subdomain_ids(std::set< subdomain_id_type > &ids, const bool global=true) const
static const dof_id_type invalid_id
static const std::complex< double > j(0, 1)
Complex number "j" (also known as "i")
assign the same reporting IDs for all tiles in the pattern with same input
uint8_t dof_id_type