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
12using namespace libMesh;
13
14std::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
38std::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
55std::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
73std::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 ReplicatedMesh & mesh = *meshes[pattern[i][j]];
84 if (!mesh.preparation().has_cached_elem_data)
86 mesh.subdomain_ids(mesh_blks);
87 blks.insert(mesh_blks.begin(), mesh_blks.end());
88 }
89 return blks;
90}
91
92std::map<SubdomainID, unsigned int>
94 const bool has_assembly_boundary,
95 const std::set<subdomain_id_type> background_blk_ids,
96 const std::set<SubdomainID> & blks)
97{
98 std::map<SubdomainID, unsigned int> blks_duct;
99 if (has_assembly_boundary)
100 {
101 std::set<SubdomainID> mesh_blks;
102 mesh.subdomain_ids(mesh_blks);
103 unsigned int i = 0;
104 for (const auto mesh_blk : mesh_blks)
105 if (!blks.count(mesh_blk) && !background_blk_ids.count(mesh_blk))
106 blks_duct[mesh_blk] = i++;
107 // delete the first entry because it is for surrouding regions between the assembly duct and pin
108 if (background_blk_ids.size() == 0)
109 blks_duct.erase(blks_duct.begin());
110 }
111 return blks_duct;
112}
113
114void
116 MeshBase & mesh,
117 const unsigned int extra_id_index,
119 const bool use_exclude_id,
120 const std::vector<bool> & exclude_ids,
121 const bool has_assembly_boundary,
122 const std::set<subdomain_id_type> background_block_ids,
123 const std::vector<std::unique_ptr<ReplicatedMesh>> & input_meshes,
124 const std::vector<std::vector<unsigned int>> & pattern,
125 const std::vector<std::vector<dof_id_type>> & id_pattern)
126{
127 std::vector<dof_id_type> integer_ids;
128 // get reporting ID map
129 // assumes that the entire mesh has elements of each individual mesh sequentially ordered.
130 if (assign_type == AssignType::cell)
131 integer_ids = getCellwiseIntegerIDs(input_meshes, pattern, use_exclude_id, exclude_ids);
132 else if (assign_type == AssignType::pattern)
133 integer_ids = getPatternIntegerIDs(input_meshes, pattern);
134 else if (assign_type == AssignType::manual)
135 integer_ids = getManualIntegerIDs(input_meshes, pattern, id_pattern);
136
137 if (has_assembly_boundary)
138 {
139 // setup assembly duct information
140 const std::set<SubdomainID> blks = getCellBlockIDs(input_meshes, pattern);
141 const unsigned int duct_boundary_id =
142 *std::max_element(integer_ids.begin(), integer_ids.end()) + 1;
143 const std::map<SubdomainID, unsigned int> blks_duct =
144 getDuckBlockIDs(mesh, has_assembly_boundary, background_block_ids, blks);
145
146 // assign reporting IDs to individual elements
147 unsigned int i = 0;
148 unsigned int id = integer_ids[i];
149 unsigned old_id = id;
150 for (auto elem : mesh.element_ptr_range())
151 {
152 auto blk = elem->subdomain_id();
153 // check whether the current element belongs to duct/surrouding regions or not
154 if (!blks.count(blk))
155 {
156 // check whether the current element belongs to surroudning or duct regions
157 if (!blks_duct.count(blk))
158 // if the current element belongs to the surronding region
159 elem->set_extra_integer(extra_id_index, old_id);
160 else
161 // if the current element belongs to the duct region
162 elem->set_extra_integer(extra_id_index, duct_boundary_id + blks_duct.at(blk));
163 }
164 else
165 {
166 // if the current element belongs to pin regions
167 elem->set_extra_integer(extra_id_index, id);
168 ++i;
169 old_id = id;
170 if (i < integer_ids.size())
171 id = integer_ids[i];
172 }
173 }
174 }
175 else
176 {
177 // assign reporting IDs to individual elements
178 unsigned int i = 0;
179 for (auto & elem : mesh.element_ptr_range())
180 elem->set_extra_integer(extra_id_index, integer_ids[i++]);
181 }
182}
unsigned int count
static constexpr dof_id_type invalid_id
Preparation preparation() const
void subdomain_ids(std::set< subdomain_id_type > &ids, const bool global=true) const
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
The following methods are specializations for using the Parallel::packed_range_* routines for a vecto...
if(subdm)
uint8_t dof_id_type