IOSS 2.0
Loading...
Searching...
No Matches
Ioex_DecompositionData.h
Go to the documentation of this file.
1/*
2 * Copyright(C) 1999-2024 National Technology & Engineering Solutions
3 * of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
4 * NTESS, the U.S. Government retains certain rights in this software.
5 *
6 * See packages/seacas/LICENSE for details
7 */
8#pragma once
9
10#include <exodusII.h>
11#if defined PARALLEL_AWARE_EXODUS
12
13#include "Ioss_CodeTypes.h"
14#include <vector>
15
16#include "ioex_export.h"
17#if !defined(NO_PARMETIS_SUPPORT)
18#include <parmetis.h>
19#endif
20
21#undef MPICPP
22#if !defined(NO_ZOLTAN_SUPPORT)
23#include <zoltan_cpp.h>
24#endif
25#include "Ioss_Decomposition.h"
26#include "Ioss_Map.h"
28
29namespace Ioss {
30 class Field;
31 class ElementBlock;
32} // namespace Ioss
33namespace Ioex {
34 struct IOEX_EXPORT BlockFieldData
35 {
36 int64_t id{0};
37 size_t comp_count{0};
38 Ioss::NameList var_name;
39 std::vector<size_t> var_index;
40
41 BlockFieldData() : id(0), comp_count(0) {}
42 BlockFieldData(const int64_t id_) : id(id_), comp_count(0) {}
43 BlockFieldData(const int64_t id_, size_t comp_count_) : id(id_), comp_count(comp_count_) {}
44 };
45
46 class IOEX_EXPORT DecompositionDataBase
47 {
48 public:
49 DecompositionDataBase(Ioss_MPI_Comm comm) : comm_(comm) {}
50 DecompositionDataBase(const DecompositionDataBase &) = delete;
51 DecompositionDataBase &operator=(const DecompositionDataBase &) = delete;
52
53 virtual ~DecompositionDataBase() = default;
54 IOSS_NODISCARD virtual int int_size() const = 0;
55 virtual void decompose_model(int filePtr, const std::string &filename) = 0;
56 IOSS_NODISCARD virtual size_t ioss_node_count() const = 0;
57 IOSS_NODISCARD virtual size_t ioss_elem_count() const = 0;
58
59 IOSS_NODISCARD virtual int spatial_dimension() const = 0;
60 IOSS_NODISCARD virtual size_t global_node_count() const = 0;
61 IOSS_NODISCARD virtual size_t global_elem_count() const = 0;
62
63 IOSS_NODISCARD virtual size_t decomp_node_offset() const = 0;
64 IOSS_NODISCARD virtual size_t decomp_node_count() const = 0;
65 IOSS_NODISCARD virtual size_t decomp_elem_offset() const = 0;
66 IOSS_NODISCARD virtual size_t decomp_elem_count() const = 0;
67
68 IOSS_NODISCARD virtual std::vector<double> &centroids() = 0;
69 IOSS_NODISCARD virtual std::vector<float> &weights() = 0;
70
71 Ioss_MPI_Comm comm_;
72
73 int m_processor{0};
74 int m_processorCount{0};
75
76 std::vector<Ioss::BlockDecompositionData> el_blocks;
77 std::vector<Ioss::SetDecompositionData> node_sets;
78 std::vector<Ioss::SetDecompositionData> side_sets;
79
80 IOSS_NODISCARD const Ioss::SetDecompositionData &get_decomp_set(ex_entity_type type,
81 ex_entity_id id) const;
82
83 template <typename T>
84 void communicate_node_data(T *file_data, T *ioss_data, size_t comp_count) const;
85
86 template <typename T>
87 void communicate_element_data(T *file_data, T *ioss_data, size_t comp_count) const;
88
89 void get_block_connectivity(int filePtr, void *data, int64_t id, size_t blk_seq,
90 size_t nnpe) const;
91
92 void read_elem_proc_map(int filePtr, void *data) const;
93
94 void get_node_entity_proc_data(void *entity_proc, const Ioss::MapContainer &node_map,
95 bool do_map) const;
96
97 int get_set_mesh_var(int filePtr, ex_entity_type type, ex_entity_id id,
98 const Ioss::Field &field, void *ioss_data) const;
99
100 int get_set_mesh_double(int filePtr, ex_entity_type type, ex_entity_id id,
101 const Ioss::Field &field, double *ioss_data) const;
102
103 IOSS_NODISCARD virtual size_t get_commset_node_size() const = 0;
104
105 virtual int get_node_coordinates(int filePtr, double *ioss_data,
106 const Ioss::Field &field) const = 0;
107 virtual int get_one_attr(int exoid, ex_entity_type obj_type, ex_entity_id obj_id,
108 int attrib_index, double *attrib) const = 0;
109 virtual int get_attr(int exoid, ex_entity_type obj_type, ex_entity_id obj_id, size_t attr_count,
110 double *attrib) const = 0;
111 virtual int get_var(int filePtr, int step, ex_entity_type type, int var_index, ex_entity_id id,
112 int64_t num_entity, std::vector<double> &data) const = 0;
113 virtual int get_user_map(int exoid, ex_entity_type obj_type, ex_entity_id id, int map_index,
114 size_t offset, size_t num_entity, void *map_data) const = 0;
115 };
116
117 template <typename INT> class DecompositionData : public DecompositionDataBase
118 {
119 public:
120 DecompositionData(const Ioss::PropertyManager &props, Ioss_MPI_Comm communicator);
121
122 IOSS_NODISCARD int int_size() const { return sizeof(INT); }
123
124 void decompose_model(int filePtr, const std::string &filename);
125
126 IOSS_NODISCARD int spatial_dimension() const { return m_decomposition.m_spatialDimension; }
127
128 IOSS_NODISCARD size_t global_node_count() const { return m_decomposition.global_node_count(); }
129 IOSS_NODISCARD size_t global_elem_count() const { return m_decomposition.global_elem_count(); }
130
131 IOSS_NODISCARD size_t ioss_node_count() const { return m_decomposition.ioss_node_count(); }
132 IOSS_NODISCARD size_t ioss_elem_count() const { return m_decomposition.ioss_elem_count(); }
133
134 IOSS_NODISCARD size_t decomp_node_offset() const { return m_decomposition.file_node_offset(); }
135 IOSS_NODISCARD size_t decomp_node_count() const { return m_decomposition.file_node_count(); }
136 IOSS_NODISCARD size_t decomp_elem_offset() const { return m_decomposition.file_elem_offset(); }
137 IOSS_NODISCARD size_t decomp_elem_count() const { return m_decomposition.file_elem_count(); }
138
139 IOSS_NODISCARD std::vector<double> &centroids() { return m_decomposition.m_centroids; }
140 IOSS_NODISCARD std::vector<float> &weights() { return m_decomposition.m_weights; }
141
142 template <typename T>
143 void communicate_element_data(T *file_data, T *ioss_data, size_t comp_count) const
144 {
145 m_decomposition.communicate_element_data(file_data, ioss_data, comp_count);
146 }
147
148 template <typename T>
149 void communicate_set_data(T *file_data, T *ioss_data, const Ioss::SetDecompositionData &set,
150 size_t comp_count) const
151 {
152 m_decomposition.communicate_set_data(file_data, ioss_data, set, comp_count);
153 }
154
155 template <typename T>
156 void communicate_node_data(T *file_data, T *ioss_data, size_t comp_count) const
157 {
158 m_decomposition.communicate_node_data(file_data, ioss_data, comp_count);
159 }
160
161 void get_block_connectivity(int filePtr, INT *data, int64_t id, size_t blk_seq,
162 size_t nnpe) const;
163
164 IOSS_NODISCARD size_t get_commset_node_size() const
165 {
166 return m_decomposition.m_nodeCommMap.size() / 2;
167 }
168
169 int get_attr(int filePtr, ex_entity_type obj_type, ex_entity_id id, size_t attr_count,
170 double *attrib) const;
171 int get_one_attr(int filePtr, ex_entity_type obj_type, ex_entity_id id, int attrib_index,
172 double *attrib) const;
173
174 int get_var(int filePtr, int step, ex_entity_type type, int var_index, ex_entity_id id,
175 int64_t num_entity, std::vector<double> &data) const;
176
177 int get_user_map(int exoid, ex_entity_type obj_type, ex_entity_id id, int map_index,
178 size_t offset, size_t num_entity, void *map_data) const;
179
180 template <typename T>
181 int get_set_mesh_var(int filePtr, ex_entity_type type, ex_entity_id id,
182 const Ioss::Field &field, T *ioss_data) const;
183
184 IOSS_NODISCARD size_t get_block_seq(ex_entity_type type, ex_entity_id id) const;
185 IOSS_NODISCARD size_t get_block_element_count(size_t blk_seq) const;
186 IOSS_NODISCARD size_t get_block_element_offset(size_t blk_seq) const;
187
188 void create_implicit_global_map(const std::vector<int> &owning_proc,
189 std::vector<int64_t> &global_implicit_map, Ioss::Map &node_map,
190 int64_t *locally_owned_count, int64_t *processor_offset);
191
192 // global_index is 1-based index into global list of nodes [1..global_node_count]
193 // return value is 1-based index into local list of nodes on this
194 // processor (ioss-decomposition)
195 IOSS_NODISCARD size_t node_global_to_local(size_t global_index) const
196 {
197 return m_decomposition.node_global_to_local(global_index);
198 }
199
200 IOSS_NODISCARD size_t elem_global_to_local(size_t global_index) const
201 {
202 return m_decomposition.elem_global_to_local(global_index);
203 }
204
205 private:
206#if !defined(NO_ZOLTAN_SUPPORT)
207 void zoltan_decompose(const std::string &method);
208#endif
209
210#if !defined(NO_PARMETIS_SUPPORT)
211 void metis_decompose(const std::string &method, const std::vector<INT> &element_dist);
212
213 void internal_metis_decompose(const std::string &method, idx_t *element_dist, idx_t *pointer,
214 idx_t *adjacency, idx_t *elem_partition);
215#endif
216
217 void simple_decompose(const std::string &method, const std::vector<INT> &element_dist)
218 {
219 m_decomposition.simple_decompose(method, element_dist);
220 }
221
222 void simple_node_decompose(const std::string &method, const std::vector<INT> &node_dist);
223
224 template <typename T>
225 int handle_sset_df(int filePtr, ex_entity_id id, const Ioss::Field &field, T *ioss_data) const;
226
227 int get_one_set_attr(int filePtr, ex_entity_type type, ex_entity_id id, int attr_index,
228 double *ioss_data) const;
229 int get_one_node_attr(int filePtr, ex_entity_id id, int attr_index, double *ioss_data) const;
230 int get_one_elem_attr(int filePtr, ex_entity_id id, int attr_index, double *ioss_data) const;
231
232 int get_set_attr(int filePtr, ex_entity_type type, ex_entity_id id, size_t comp_count,
233 double *ioss_data) const;
234 int get_node_attr(int filePtr, ex_entity_id id, size_t comp_count, double *ioss_data) const;
235 int get_elem_attr(int filePtr, ex_entity_id id, size_t comp_count, double *ioss_data) const;
236
237 int get_elem_map(int filePtr, ex_entity_id blk_id, int map_index, size_t offset, size_t count,
238 void *ioss_data) const;
239 int get_node_map(int filePtr, int map_index, size_t offset, size_t count,
240 void *ioss_data) const;
241
242 int get_node_var(int filePtr, int step, int var_index, ex_entity_id id, int64_t num_entity,
243 std::vector<double> &ioss_data) const;
244
245 int get_elem_var(int filePtr, int step, int var_index, ex_entity_id id, int64_t num_entity,
246 std::vector<double> &ioss_data) const;
247
248 int get_set_var(int filePtr, int step, int var_index, ex_entity_type type, ex_entity_id id,
249 int64_t num_entity, std::vector<double> &ioss_data) const;
250
251 IOSS_NODISCARD bool i_own_node(size_t node) const
252 {
253 // T/F if the node with global index `node` is owned by this processors ioss-decomp.
254 return m_decomposition.i_own_node(node);
255 }
256
257 IOSS_NODISCARD bool i_own_elem(size_t elem) const
258 // T/F if the element with global index `elem` is owned by this processors ioss-decomp.
259 {
260 return m_decomposition.i_own_elem(elem);
261 }
262
263 void build_global_to_local_elem_map() { m_decomposition.build_global_to_local_elem_map(); }
264
265 void get_element_block_communication()
266 {
267 m_decomposition.get_element_block_communication(el_blocks);
268 }
269
270 void generate_adjacency_list(int filePtr, Ioss::Decomposition<INT> &decomposition);
271
272 void get_common_set_data(int filePtr, ex_entity_type set_type,
273 std::vector<Ioss::SetDecompositionData> &sets,
274 const std::string &set_type_name);
275
276 void get_nodeset_data(int filePtr, size_t set_count);
277
278 void get_sideset_data(int filePtr, size_t set_count);
279
280 void calculate_element_centroids(int filePtr, const std::vector<INT> &node_dist);
281#if !defined(NO_ZOLTAN_SUPPORT)
282 void get_local_element_list(const ZOLTAN_ID_PTR &export_global_ids, size_t export_count);
283#endif
284
285 void get_shared_node_list() { m_decomposition.get_shared_node_list(); }
286
287 int get_node_coordinates(int filePtr, double *ioss_data, const Ioss::Field &field) const;
288
289 void get_local_node_list() { m_decomposition.get_local_node_list(); }
290
291 public:
292 Ioss::Decomposition<INT> m_decomposition;
293 };
294
295 class IOEX_EXPORT ElementBlockBatchReader
296 {
297 public:
298 ElementBlockBatchReader(const DecompositionDataBase *decompDB);
299
300 IOSS_NODISCARD size_t
301 get_connectivity_size(const std::vector<int64_t> &blocks_subset_index) const;
302
303 IOSS_NODISCARD std::vector<size_t>
304 get_connectivity(int filePtr, const std::vector<int64_t> &blocks_subset_index,
305 void *data) const;
306
307 IOSS_NODISCARD std::vector<size_t>
308 get_offset(const std::vector<int64_t> &blocks_subset_index,
309 const std::vector<int> &block_component_count) const;
310
311 void get_field_data(int filePtr, void *data, const std::vector<int64_t> &blocks_subset_index,
312 size_t step, const std::vector<BlockFieldData> &block_data) const;
313
314 private:
315 const DecompositionDataBase *m_decompositionDB{nullptr};
316 Ioss::ElementBlockBatchOffset m_batchOffset;
317
318 template <typename INT>
319 std::vector<size_t> get_connectivity_impl(int filePtr,
320 const std::vector<int64_t> &blocks_subset_index,
321 void *data) const;
322
323 template <typename INT>
324 void get_field_data_impl(int filePtr, void *iossData,
325 const std::vector<int64_t> &blocks_subset_index, size_t step,
326 const std::vector<BlockFieldData> &block_data) const;
327
328 template <typename INT>
329 std::vector<size_t>
330 get_connectivity_file_offset(const std::vector<int64_t> &blocks_subset_index) const;
331
332 template <typename INT>
333 std::vector<size_t> get_file_offset(const std::vector<int64_t> &blocks_subset_index,
334 const std::vector<int> &block_component_count) const;
335
336 std::vector<int>
337 get_connectivity_component_count(const std::vector<int64_t> &blocks_subset_index) const;
338
339 std::vector<int>
340 get_block_component_count(const std::vector<int64_t> &blockSubsetIndex,
341 const std::vector<BlockFieldData> &blockFieldData) const;
342
343 template <typename INT>
344 void load_field_data(int filePtr, double *fileData,
345 const std::vector<int64_t> &blockSubsetIndex, size_t step,
346 const std::vector<BlockFieldData> &blockFieldData,
347 const std::vector<int> &blockComponentCount,
348 const std::vector<size_t> &fileConnOffset) const;
349 };
350} // namespace Ioex
351#endif
#define IOSS_NODISCARD
Definition Ioss_CodeTypes.h:55
int Ioss_MPI_Comm
Definition Ioss_CodeTypes.h:64
Definition Ioss_Decomposition.h:180
Definition Ioss_Decomposition.h:140
Holds metadata for bulk data associated with a GroupingEntity.
Definition Ioss_Field.h:25
Definition Ioss_Map.h:46
A collection of Ioss::Property objects.
Definition Ioss_PropertyManager.h:36
Definition Ioss_Decomposition.h:92
A namespace for the exodus database format.
Definition Ioex_BaseDatabaseIO.C:209
The main namespace for the Ioss library.
Definition Ioad_DatabaseIO.C:40
Ioss::NameList NameList
Definition Ioss_ChangeSetFactory.h:25
std::vector< int64_t > MapContainer
Definition Ioss_Map.h:29
int64_t id(Ioss::GroupingEntity *entity)
Definition io_info.C:133