Debian Codegraph @

packages/seacas/applications/nem_slice/elb.h

raw
1 /*
2 * Copyright(C) 1999-2025 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 "elb_elem.h"
11 #include "vector_data.h"
12 #include <cstdio>
13 #include <exodusII.h>
14 #include <string>
15 #include <vector>
16
17 #define ELB_VERSION "5.05 (2025-02-04)"
18 #define UTIL_NAME "nem_slice"
19 #define ELB_FALSE 0
20 #define ELB_TRUE 1
21
22 /*
23 * Constants for memory allocation of graph structures. The smaller these
24 * values, the more memory-efficient the code will be. Larger values
25 * will likely speed execution and prevent swap thrashing.
26 */
27 #define SURND_ALLOC 8
28 #define ADJ_ALLOC 8
29 #define MEM_CHUNK_SIZE 16 /* Value MUST be >= 2 */
30 #define MEM_GROWTH 1.5
31
32 #define MAX_INP_LINE 10240
33
34 #if (__cplusplus >= 201703L)
35 #define FALL_THROUGH [[fallthrough]]
36 #elif defined(__GNUC__) && __GNUC__ >= 7 && !__INTEL_COMPILER
37 #define FALL_THROUGH [[gnu::fallthrough]]
38 #else
39 #define FALL_THROUGH ((void)0)
40 #endif /* __GNUC__ >= 7 */
41
42 template <typename INT> void vec_free(std::vector<INT> &V)
43 {
44 V.clear();
45 V.shrink_to_fit();
46 }
47
48 /* Prototype for timing function */
49 extern double get_time();
50
51 /* Machine types */
52 enum class MachineType { INVALID, MESH, HCUBE, HYPERCUBE, CLUSTER };
53
54 /* Structure used for the description of the machine for which the
55 * load balance is to be constructed. */
56 struct Machine_Description
57 {
58 MachineType type{MachineType::INVALID};
59 int num_dims{-1};
60 int dim[3]{-1, -1, -1};
61 int num_boxes{-1}; /* added for cluster type machines */
62 int procs_per_box{-1}; /* added for cluster type machines, if there is only
63 one box, then this is the same as num_procs */
64 int num_procs{-1};
65 };
66
67 /* Load balance types */
68 enum class Balance {
69 INVALID,
70 MULTIKL,
71 SPECTRAL,
72 INERTIAL,
73 LINEAR,
74 RANDOM,
75 SCATTERED,
76 INFILE,
77 KL_REFINE,
78 NO_REFINE,
79 NUM_SECTS,
80 CNCT_DOM,
81 OUTFILE,
82 ZPINCH,
83 BRICK,
84 ZOLTAN_RCB,
85 ZOLTAN_RIB,
86 ZOLTAN_HSFC,
87 IGNORE_Z
88 };
89
90 /* Structure used for the description of what type of load balance is
91 * to be performed. */
92 template <typename INT> struct LB_Description
93 {
94 Balance type{-1};
95 int ignore_z{0};
96 Balance refine{-1};
97 int num_sects{-1};
98 int cnctd_dom{-1};
99 int outfile{-1};
100 std::string file{};
101
102 /* Calculated quantities */
103 int *vertex2proc{nullptr};
104
105 /* Nodal */
106 std::vector<std::vector<INT>> int_nodes{};
107 std::vector<std::vector<INT>> bor_nodes{};
108 std::vector<std::vector<INT>> ext_nodes{};
109 std::vector<std::vector<INT>> ext_procs{};
110
111 /* Elemental */
112 std::vector<std::vector<std::vector<INT>>> born_procs{};
113 std::vector<std::vector<INT>> int_elems{};
114 std::vector<std::vector<INT>> bor_elems{};
115 std::vector<std::vector<INT>> e_cmap_elems{};
116 std::vector<std::vector<INT>> e_cmap_sides{};
117 std::vector<std::vector<INT>> e_cmap_procs{};
118 std::vector<std::vector<INT>> e_cmap_neigh{};
119 };
120
121 enum class DecompType { NODAL, ELEMENTAL };
122
123 /* Structure for the problem description. */
124 struct Problem_Description
125 {
126 DecompType type{-1};
127 int read_coords{-1};
128 int coarse_flag{-1};
129 int alloc_graph{-1};
130 size_t num_vertices{0};
131 int vis_out{-1};
132 int skip_checks{-1}; /* put in to skip some error checks for some meshes */
133 int face_adj{-1}; /* true if using face definition of adjacencies */
134 int partial_adj{0}; /* true if allowing partial (3/4) of nodes to */
135 /* determine adjacencies */
136 int selected_change_set{0};
137 int global_mech{-1}; /* true if looking for mechanisms in original mesh */
138 int local_mech{-1}; /* true if looking for mechanisms in subdivided mesh */
139 int find_cnt_domains{-1}; /* true if finding number of connected domains in a graph */
140 int mech_add_procs{-1}; /* adds processors in cases of mechanisms */
141 int dsd_add_procs{-1}; /* adds processors in cases of disconnected subdomains */
142 int no_sph{-1};
143 int fix_columns{0}; /* detect, fix vertical column partitioning */
144 char *groups{nullptr};
145 std::vector<int> group_no{};
146 int num_groups{-1};
147 int int64db{0}; /* integer types for output mesh database */
148 int int64api{0}; /* integer types for exodus api calls */
149 };
150
151 /* Solver options */
152 enum class SolverOptions { INVALID, TOLER, USE_RQI, VMAX };
153
154 /* Structure for parameters needed for the Eigensolver in Chaco */
155 struct Solver_Description
156 {
157 double tolerance{-1.0};
158 SolverOptions rqi_flag{SolverOptions::INVALID};
159 int vmax{-1};
160 };
161
162 /* Weighting options */
163 /*
164 * NOTE: the position of NO_WEIGHT, READ_EXO, EL_BLK, and EWGT_ON
165 * should not be changed. These are the possible values for the
166 * "type" variable in the Weight struct. They need to b 0, 1, 2, & 4
167 * to allow bit masking for the type. The other variables are not
168 * currently used in the type, but are needed since they appear
169 * on the command line.
170 */
171 enum WeightingOptions { NO_WEIGHT, READ_EXO, EL_BLK, VAR_INDX, EDGE_WGT, TIME_INDX, VAR_NAME };
172
173 /* Structure used to store information about the weighting scheme, if
174 * any, that is to be used. */
175 struct Weight_Description
176 {
177 int type{-1}; /* See weight type below for possible types */
178 int ow_read{0}; /* 1 if element block settings overwrite exodus file read */
179
180 std::string exo_filename{};
181 std::string exo_varname{};
182
183 int exo_tindx{-1};
184 int exo_vindx{-1};
185
186 /* Variable parameters */
187 int nvals{0};
188
189 /* vectors to hold element block weights */
190 std::vector<int> elemblk{}; /* Id of element block */
191 std::vector<int> elemblk_wgt{}; /* Weight of that element block */
192
193 /* vector to indicate if weight value has already been overwritten */
194 std::vector<int> ow{};
195
196 std::vector<int> vertices{};
197 std::vector<float> edges{};
198 };
199
200 /* Structure used to store information about the FEM mesh */
201 template <typename INT> struct Mesh_Description
202 {
203 size_t num_nodes{0};
204 size_t num_elems{0};
205 size_t num_dims{0};
206 size_t num_el_blks{0};
207 std::vector<INT> eb_cnts{};
208 std::vector<INT> eb_ids{};
209 std::vector<INT> eb_npe{};
210 std::vector<ElementType> eb_type{};
211 size_t num_node_sets{0};
212 size_t num_side_sets{0};
213 size_t max_np_elem{0};
214 size_t ns_list_len{0};
215 char title[MAX_LINE_LENGTH + 1]{};
216 std::vector<float> coords{};
217 std::vector<ElementType> elem_type{};
218 INT **connect{nullptr};
219 };
220
221 /* Structure for handling meshes with spheres */
222 struct Sphere_Info
223 {
224 size_t num{0};
225 std::vector<int> adjust{};
226 std::vector<int> begin{};
227 std::vector<int> end{};
228 };
229
230 /* Structure used to store various information about the graph */
231 template <typename INT> struct Graph_Description
232 {
233 size_t nadj{0};
234 int max_nsur{0};
235 std::vector<INT> adj{};
236 std::vector<INT> start{};
237 std::vector<std::vector<INT>> sur_elem;
238 };
239
240 /* Various constants */
241
242 #define UTIL_NAME "nem_slice"
243
244 /* ISSUES options */
245 enum class Issues { LOCAL_ISSUES, GLOBAL_ISSUES };