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