Debian Codegraph @

packages/seacas/applications/nem_slice/elb_graph.C

raw
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
9 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
10 * Functions contained in this file:
11 * generate_graph()
12 * find_surnd_elems()
13 * find_adjacency()
14 *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
15 #include "copy_string_cpp.h"
16 #include "elb.h" // for Problem_Description, etc
17 #include "elb_elem.h" // for get_elem_info, NNODES, etc
18 #include "elb_err.h" // for Gen_Error
19 #include "elb_graph.h"
20 #include "elb_util.h" // for in_list, find_inter
21 #include <cassert> // for assert
22 #include <cstddef> // for size_t
23 #include <cstdlib>
24 #include <fmt/format.h>
25 #include <fmt/ostream.h>
26 #include <sstream>
27 #include <vector> // for vector
28
29 /* Local function prototypes */
30 namespace {
31 template <typename INT>
32 int find_surnd_elems(Mesh_Description<INT> * /*mesh*/, Graph_Description<INT> * /*graph*/);
33
34 template <typename INT>
35 int find_adjacency(Problem_Description * /*problem*/, Mesh_Description<INT> * /*mesh*/,
36 Graph_Description<INT> * /*graph*/, Weight_Description * /*weight*/,
37 Sphere_Info * /*sphere*/);
38 } // namespace
39 /*****************************************************************************/
40 /*****************************************************************************/
41 /*****************************************************************************/
42 /* Function generate_graph() begins:
43 *----------------------------------------------------------------------------
44 * This function does the work to generate the graph from the FE mesh.
45 *****************************************************************************/
46 template int generate_graph(Problem_Description *problem, Mesh_Description<int> *mesh,
47 Graph_Description<int> *graph, Weight_Description *weight,
48 Sphere_Info *sphere);
49
50 template int generate_graph(Problem_Description *problem, Mesh_Description<int64_t> *mesh,
51 Graph_Description<int64_t> *graph, Weight_Description *weight,
52 Sphere_Info *sphere);
53
54 template <typename INT>
55 int generate_graph(Problem_Description *problem, Mesh_Description<INT> *mesh,
56 Graph_Description<INT> *graph, Weight_Description *weight, Sphere_Info *sphere)
57 {
58 double time1 = get_time();
59 /* Find the elements surrounding a node */
60 if (!find_surnd_elems(mesh, graph)) {
61 Gen_Error(0, "fatal: could not find surrounding elements");
62 return 0;
63 }
64 double time2 = get_time();
65 fmt::print(stderr, "Time to find surrounding elements: {}s\n", time2 - time1);
66
67 /* Find the adjacency, if required */
68 if (problem->alloc_graph == ELB_TRUE) {
69 if (!find_adjacency(problem, mesh, graph, weight, sphere)) {
70 Gen_Error(0, "fatal: could not find adjacency");
71 return 0;
72 }
73 time1 = get_time();
74 fmt::print(stderr, "Time to find the adjacency: {}s\n", time2 - time1);
75 }
76 return 1;
77 }
78
79 namespace {
80 /*****************************************************************************/
81 /*****************************************************************************/
82 /*****************************************************************************/
83 /* Function find_surnd_elems() begins:
84 *----------------------------------------------------------------------------
85 * This function finds the elements surrounding a given FEM node. In other
86 * words, this function generates a list of elements containing a given
87 * FEM node.
88 *****************************************************************************/
89 template <typename INT>
90 int find_surnd_elems(Mesh_Description<INT> *mesh, Graph_Description<INT> *graph)
91 {
92 std::vector<int> surround_count(mesh->num_nodes);
93 std::vector<size_t> last_element(mesh->num_nodes);
94
95 size_t sur_elem_total_size = 0;
96 /* Find the count of surrounding elements for each node in the mesh */
97 // The hope is that this code will speed up the entire routine even
98 // though we are iterating the complete connectivity array twice.
99 for (size_t ecnt = 0; ecnt < mesh->num_elems; ecnt++) {
100 int nnodes = get_elem_info(ElementInfo::NNODES, mesh->elem_type[ecnt]);
101 for (int ncnt = 0; ncnt < nnodes; ncnt++) {
102 INT node = mesh->connect[ecnt][ncnt];
103 assert(node < (INT)mesh->num_nodes);
104 /*
105 * in the case of degenerate elements, where a node can be
106 * entered into the connect table twice, need to check to
107 * make sure that this element is not already listed as
108 * surrounding this node
109 */
110 if (last_element[node] != ecnt + 1) {
111 last_element[node] = ecnt + 1;
112 surround_count[node]++;
113 sur_elem_total_size++;
114 }
115 }
116 } /* End "for(ecnt=0; ecnt < mesh->num_elems; ecnt++)" */
117
118 size_t v_size = sizeof(std::vector<INT>);
119 size_t vv_size = sizeof(std::vector<std::vector<INT>>);
120 size_t total = vv_size + mesh->num_nodes * v_size + sur_elem_total_size * sizeof(INT);
121 fmt::print(stderr, "\ttotal size of reverse connectivity array: {} entries ({} bytes).\n",
122 fmt::group_digits(sur_elem_total_size), fmt::group_digits(total));
123 vec_free(last_element);
124
125 // Attempt to reserve an array with this size...
126 double time1 = get_time();
127
128 graph->sur_elem.resize(mesh->num_nodes);
129 for (size_t ncnt = 0; ncnt < mesh->num_nodes; ncnt++) {
130 if (surround_count[ncnt] == 0) {
131 fmt::print(stderr, "WARNING: Node = {} has no elements\n", ncnt + 1);
132 }
133 else {
134 graph->sur_elem[ncnt].reserve(surround_count[ncnt]);
135 graph->max_nsur =
136 surround_count[ncnt] > graph->max_nsur ? surround_count[ncnt] : graph->max_nsur;
137 }
138 }
139 double time2 = get_time();
140
141 fmt::print(stderr,
142 "\tmemory allocated...({} seconds)\n"
143 "\tmax of {} elements per node\n",
144 time2 - time1, graph->max_nsur);
145
146 /* Find the surrounding elements for each node in the mesh */
147 for (size_t ecnt = 0; ecnt < mesh->num_elems; ecnt++) {
148 int nnodes = get_elem_info(ElementInfo::NNODES, mesh->elem_type[ecnt]);
149 for (int ncnt = 0; ncnt < nnodes; ncnt++) {
150 INT node = mesh->connect[ecnt][ncnt];
151
152 /*
153 * in the case of degenerate elements, where a node can be
154 * entered into the connect table twice, need to check to
155 * make sure that this element is not already listed as
156 * surrounding this node
157 */
158 if (graph->sur_elem[node].empty() || ecnt != (size_t)graph->sur_elem[node].back()) {
159 /* Add the element to the list */
160 graph->sur_elem[node].push_back(ecnt);
161 }
162 }
163 } /* End "for(ecnt=0; ecnt < mesh->num_elems; ecnt++)" */
164
165 #ifndef NDEBUG
166 for (size_t ncnt = 0; ncnt < mesh->num_nodes; ncnt++) {
167 assert(graph->sur_elem[ncnt].size() == (size_t)surround_count[ncnt]);
168 }
169 #endif
170 return 1;
171 }
172
173 /*****************************************************************************/
174 /*****************************************************************************/
175 /*****************************************************************************/
176 /* Function find_adjacency() begins:
177 *----------------------------------------------------------------------------
178 * This function finds adjacency (or graph) of the problem.
179 *****************************************************************************/
180 template <typename INT>
181 int find_adjacency(Problem_Description *problem, Mesh_Description<INT> *mesh,
182 Graph_Description<INT> *graph, Weight_Description *weight, Sphere_Info *sphere)
183 {
184 std::vector<INT> pt_list;
185 std::vector<INT> hold_elem;
186 INT side_nodes[MAX_SIDE_NODES + 2];
187 INT mirror_nodes[MAX_SIDE_NODES + 2];
188
189 static int count = 0;
190
191 int hflag1;
192 int hflag2;
193 int tflag1;
194 int tflag2;
195 /*-----------------------------Execution Begins------------------------------*/
196
197 /* Allocate memory necessary for the adjacency */
198 graph->start.resize(problem->num_vertices + 1);
199
200 for (int i = 0; i < MAX_SIDE_NODES + 2; i++) {
201 side_nodes[i] = -999;
202 mirror_nodes[i] = -999;
203 }
204
205 /* Find the adjacency for a nodal based decomposition */
206 if (problem->type == DecompType::NODAL) {
207 graph->nadj = 0;
208 for (size_t ncnt = 0; ncnt < mesh->num_nodes; ncnt++) {
209 graph->start[ncnt] = graph->nadj;
210 assert(graph->nadj == graph->adj.size());
211 for (size_t ecnt = 0; ecnt < graph->sur_elem[ncnt].size(); ecnt++) {
212 size_t elem = graph->sur_elem[ncnt][ecnt];
213 int nnodes = get_elem_info(ElementInfo::NNODES, mesh->elem_type[elem]);
214 for (int i = 0; i < nnodes; i++) {
215 INT entry = mesh->connect[elem][i];
216
217 if (ncnt != (size_t)entry && in_list(entry, graph->adj.size() - graph->start[ncnt],
218 &graph->adj[graph->start[ncnt]]) < 0) {
219 graph->adj.push_back(entry);
220 graph->nadj++;
221 }
222 }
223 } /* End "for(ecnt=0; ecnt < graph->nsur_elem[ncnt]; ecnt++)" */
224 } /* End "for(ncnt=0; ncnt < mesh->num_nodes; ncnt++)" */
225 }
226 /* Find the adjacency for a elemental based decomposition */
227 else {
228
229 /* for face adjacencies, need to allocate some memory */
230 if (problem->face_adj) {
231 /* allocate space to hold info about surrounding elements */
232 pt_list.resize(graph->max_nsur);
233 hold_elem.resize(graph->max_nsur);
234 }
235 graph->nadj = 0;
236 size_t cnt = 0;
237
238 /* tmp_element used to speed up the in_list calc */
239 std::vector<int> tmp_element(mesh->num_elems, -1);
240
241 /* Cycle through the elements */
242
243 int element_3d = 0;
244 int nnodes = mesh->num_dims;
245 int nsides = 0;
246
247 for (size_t ecnt = 0; ecnt < mesh->num_elems; ecnt++) {
248 ElementType etype = mesh->elem_type[ecnt];
249 ElementType etype_last = ElementType::NULL_EL;
250 if (etype != etype_last) {
251 etype_last = etype;
252 element_3d = is_3d_element(mesh->elem_type[ecnt]);
253 if (problem->face_adj == 0) {
254 nnodes = get_elem_info(ElementInfo::NNODES, etype);
255 }
256 nsides = get_elem_info(ElementInfo::NSIDES, etype);
257 }
258
259 if (etype != ElementType::SPHERE || problem->no_sph == 1) {
260 graph->start[cnt] = graph->nadj;
261 assert(graph->nadj == graph->adj.size());
262
263 /*
264 * now have to decide how to determine adjacency
265 * !face_adj - any element that connects to any node in this
266 * element is an adjacent element
267 * face_adj - a) for 3D elements only those that share an
268 * entire face with this element are considered
269 * adjacent
270 * b) do not connect 1D/2D elements to 3D elements
271 * c) 1D and 2D elements can connect to each other
272 */
273
274 /* If not forcing face adjaceny */
275 if (problem->face_adj == 0) {
276
277 /* ncnt = 0,...,7 for hex */
278 for (int ncnt = 0; ncnt < nnodes; ncnt++) {
279 /* node is the node number 'ncnt' of element 'ecnt' */
280 size_t node = mesh->connect[ecnt][ncnt];
281
282 /* i varies from 0 -> # of elements touching 'node' */
283 for (size_t i = 0; i < graph->sur_elem[node].size(); i++) {
284
285 /* 'entry' is element # i touching node 'node' */
286 INT entry = graph->sur_elem[node][i];
287
288 /* make sure we're not checking if the element
289 is connected to itself */
290 if (ecnt != (size_t)entry && mesh->elem_type[entry] != ElementType::SPHERE) {
291 /* If tmp_element[entry] != ecnt, then entry is not in list... */
292 if ((size_t)tmp_element[entry] != ecnt) {
293 #if 0
294 assert(in_list(entry, (graph->nadj)-(graph->start[cnt]),
295 (graph->adj)+(graph->start[cnt])) < 0);
296 #endif
297 tmp_element[entry] = ecnt;
298 (graph->nadj)++;
299 graph->adj.push_back(entry);
300 if (weight->type & WeightingOptions::EDGE_WGT) {
301 weight->edges.push_back(1.0);
302 }
303 }
304 else if (weight->type & WeightingOptions::EDGE_WGT) {
305 int iret = in_list(entry, (graph->nadj) - (graph->start[cnt]),
306 &graph->adj[graph->start[cnt]]);
307 assert(iret >= 0);
308 weight->edges[iret + (graph->start[cnt])] += 1.0F;
309 }
310 }
311 }
312 } /* End "for(ncnt=0; ...)" */
313 } /* End: "if (problem->face_adj == 0)" */
314
315 /* So if this is a 3-d element and we're forcing face
316 * adjacency, if it gets to this else below
317 *
318 * if this element is 1d/2d allow connections to 1d and 2d
319 * elements but not to 3d elements
320 *
321 */
322
323 else {
324 if (element_3d) {
325 /* need to check for hex's or tet's */
326
327 /*
328 * If the first element is a hex or tet, set flags
329 * hflag1/tflag1 to 1
330 */
331 hflag1 = is_hex(etype);
332 tflag1 = is_tet(etype);
333
334 /* check each side of this element */
335 for (int nscnt = 0; nscnt < nsides; nscnt++) {
336 /* get the list of nodes on this side set */
337 int side_cnt = ss_to_node_list(etype, mesh->connect[ecnt], (nscnt + 1), side_nodes);
338
339 /*
340 * now I need to determine how many side set nodes I
341 * need to use to determine if there is an element
342 * connected to this side.
343 *
344 * 2-D - need two nodes, so find one intersection
345 * 3-D - need three nodes, so find two intersections
346 * NOTE: must check to make sure that this number is not
347 * larger than the number of nodes on the sides (ie - SHELL).
348 */
349
350 nnodes = mesh->num_dims;
351
352 /*
353 * In case the number of nodes on this side are less
354 * than the minimum number, set nnodes to side_cnt,
355 * i.e., if a 3-D mesh contains a bar, then nnodes=3,
356 * and side_cnt = 2
357 */
358
359 if (nnodes > side_cnt) {
360 nnodes = side_cnt;
361 }
362
363 nnodes--; /* decrement to find the number of intersections */
364
365 size_t nelem = 0; /* reset this in case no intersections are needed */
366
367 /* copy the first array into temp storage */
368
369 #if 0
370 /* nhold is the number of elements touching node 0 on
371 the side of this element */
372 size_t nhold = graph->sur_elem[side_nodes[0]].size();
373
374 /* Now that we have the number of elements touching
375 side 0, get their element ids and store them in hold_elem */
376 for (size_t ncnt = 0; ncnt < nhold; ncnt++)
377 hold_elem[ncnt] = graph->sur_elem[side_nodes[0]][ncnt];
378 #endif
379 /*
380 * need to handle hex's differently because of
381 * the tet/hex combination
382 */
383
384 if (!hflag1) {
385 /* Get the number of elements ( and their ids )
386 that touch node (ncnt+1) and see if any elements touch
387 both node 0 and node (ncnt+1), and if so, return to nelem
388 the number of elements touching both nodes and their
389 indices in pt_list. When ncnt != 0, hold_elem and nhold
390 change */
391 size_t nhold = graph->sur_elem[side_nodes[0]].size();
392 for (size_t ncnt = 0; ncnt < nhold; ncnt++) {
393 hold_elem[ncnt] = graph->sur_elem[side_nodes[0]][ncnt];
394 }
395
396 for (int ncnt = 0; ncnt < nnodes; ncnt++) {
397 nelem = find_inter(Data(hold_elem), &graph->sur_elem[side_nodes[(ncnt + 1)]][0],
398 nhold, graph->sur_elem[side_nodes[(ncnt + 1)]].size(),
399 Data(pt_list));
400
401 /* If less than 2 ( 0 or 1 ) elements only
402 touch nodes 0 and ncnt+1 then try next side node, i.e.,
403 repeat loop ncnt */
404 if (nelem < 2) {
405 break;
406 }
407
408 nhold = nelem;
409 for (size_t i = 0; i < nelem; i++) {
410 hold_elem[i] = hold_elem[pt_list[i]];
411 }
412 }
413 }
414
415 /* If this element is a hex type */
416 else {
417
418 /*
419 * To handle hex's, check opposite corners. First check
420 * 1 and 3 and then 2 and 4. Only an element connected
421 * to this face will be connected to both corners. If there
422 * are tet's connected to this face, both will show up in
423 * one of the intersections (nothing will show up in the
424 * other intersection).
425 */
426
427 /* See if hexes share nodes 0 and nodes (ncnt+2) */
428 int inode = 0;
429 for (int ncnt = 0; ncnt < nnodes; ncnt++) {
430 nelem =
431 find_inter(&graph->sur_elem[side_nodes[inode]][0],
432 &graph->sur_elem[side_nodes[(ncnt + 2)]][0],
433 graph->sur_elem[side_nodes[inode]].size(),
434 graph->sur_elem[side_nodes[(ncnt + 2)]].size(), Data(pt_list));
435
436 /*
437 * If there are multiple elements in the intersection, then
438 * they must share the face, since the intersection is between
439 * the corner nodes. No element could connect with both of
440 * those nodes without being connected elsewhere.
441 */
442 if (nelem > 1) {
443
444 /* Then get the correct elements out of the hold array */
445 for (size_t i = 0; i < nelem; i++) {
446 hold_elem[i] = graph->sur_elem[side_nodes[inode]][pt_list[i]];
447 }
448 break;
449 }
450
451 /*
452 * if there aren't multiple elements in the intersection,
453 * then check the opposite corners (1 & 3)
454 */
455 inode = 1;
456 }
457 } /* "if (!hflag)" */
458
459 /*
460 * if there is an element on this side of ecnt, then there
461 * will be at least two elements in the intersection (one
462 * will be ecnt)
463 */
464 if (nelem > 1) {
465
466 /*
467 * now go through and check each element in the list
468 * to see if it is different than ecnt.
469 */
470
471 for (size_t i = 0; i < nelem; i++) {
472 size_t entry = hold_elem[i];
473
474 if (ecnt != entry) {
475
476 /*
477 * Need to verify that this side of ecnt is actually
478 * connected to a face of entry. The problem case is
479 * when an entire face of a shell (one of the ends)
480 * is connected to only an edge of a quad/tet
481 */
482
483 ElementType etype2 = mesh->elem_type[entry];
484
485 /* make sure this is a 3d element*/
486
487 if (is_3d_element(etype2)) {
488
489 /* need to check for hex's */
490 hflag2 = is_hex(etype2);
491
492 /* TET10 cannot connect to a HEX */
493 tflag2 = is_tet(etype2);
494
495 /* check here for tet/hex combinations */
496 int sid;
497 if ((tflag1 && hflag2) || (hflag1 && tflag2)) {
498 /*
499 * have to call a special function to get the side id
500 * in these cases. In both cases, the number of side
501 * nodes for the element will not be consistent with
502 * side_cnt, and:
503 *
504 * TET/HEX - side_nodes only contains three of the
505 * the side nodes of the hex.
506 *
507 * HEX/TET - Have to check that this tet shares a side
508 * with the hex.
509 */
510 sid = get_side_id_hex_tet(mesh->elem_type[entry], mesh->connect[entry],
511 side_cnt, side_nodes);
512 }
513 else {
514 /*
515 * get the side id of elem. Make sure that ecnt is
516 * trying to communicate to a valid side of elem
517 */
518
519 side_cnt = get_ss_mirror(etype, side_nodes, (nscnt + 1), mirror_nodes);
520
521 /*
522 * small kludge to handle 6 node faces butted up against
523 * 4 node faces
524 */
525
526 /* if this element 1 is a hexshell, then only
527 require 4 of the 6 nodes to match between elements
528 1 and 2 */
529 if (etype == ElementType::HEXSHELL && side_cnt == 6) {
530 side_cnt = 4;
531 }
532
533 /* side_cnt is the number of nodes on the face
534 of a particular element. This number is passed
535 to get_side_id and the error with two hexes
536 only sharing 3 nodes is in get_side_id
537 Additional comments can be found there */
538
539 /*
540 * in order to get the correct side order for elem,
541 * get the mirror of the side of ecnt
542 */
543
544 /* Based on elements intersecting, get the side
545 of element 1 that is connected to the element in the list
546 which it intersects with. The two elements must have
547 (originally) side_cnt nodes in common */
548
549 sid =
550 get_side_id(mesh->elem_type[entry], mesh->connect[entry], side_cnt,
551 mirror_nodes, problem->skip_checks, problem->partial_adj);
552 }
553
554 if (sid > 0) {
555 (graph->nadj)++;
556 graph->adj.push_back(entry);
557 if (weight->type & WeightingOptions::EDGE_WGT) {
558 /*
559 * the edge weight is the number of nodes in the
560 * connecting face
561 */
562 weight->edges.push_back(side_cnt);
563
564 /*
565 * have to put a kluge in here for the
566 * tet/hex problem
567 */
568 if (hflag1 && tflag2) {
569 (weight->edges.back())--;
570 }
571 }
572 }
573 else if ((sid < 0) && (!problem->skip_checks)) {
574 /*
575 * too many errors with bad meshes, print out
576 * more information here for diagnostics
577 */
578 std::string tmpstr;
579 std::string cmesg;
580 cmesg = "Error returned while getting side id for communication map.";
581 Gen_Error(0, cmesg);
582 cmesg = fmt::format("Element 1: {}", (ecnt + 1));
583 Gen_Error(0, cmesg);
584 nnodes = get_elem_info(ElementInfo::NNODES, etype);
585 cmesg = "connect table:";
586 for (int ii = 0; ii < nnodes; ii++) {
587 tmpstr = fmt::format(" {}", (size_t)(mesh->connect[ecnt][ii] + 1));
588 cmesg += tmpstr;
589 }
590 Gen_Error(0, cmesg);
591 cmesg = fmt::format("side id: {}", (nscnt + 1));
592 Gen_Error(0, cmesg);
593 cmesg = "side nodes:";
594 for (int ii = 0; ii < side_cnt; ii++) {
595 tmpstr = fmt::format(" {}", (size_t)(side_nodes[ii] + 1));
596 cmesg += tmpstr;
597 }
598 Gen_Error(0, cmesg);
599 cmesg = fmt::format("Element 2: {}", (entry + 1));
600 Gen_Error(0, cmesg);
601 nnodes = get_elem_info(ElementInfo::NNODES, etype2);
602 cmesg = "connect table:";
603 for (int ii = 0; ii < nnodes; ii++) {
604 tmpstr = fmt::format(" {}", (size_t)(mesh->connect[entry][ii] + 1));
605 cmesg += tmpstr;
606 }
607 Gen_Error(0, cmesg);
608 count++;
609 fmt::print("Now we have {} bad element connections.\n", count);
610 } /* End "if (sid > 0)" */
611 } /* End: "if(ecnt != entry)" */
612 }
613 } /* End: "for(i=0; i < nelem; i++)" */
614 } /* End: "if (nelem > 1)" */
615 } /* End: "for (nscnt = 0; nscnt < nsides; nscnt++)" */
616 } /* End: "if(element_3d)" */
617
618 else {
619
620 /* this is either a 2d or 1d element. Only allow attachments to other
621 * 1d or 2d elements
622 */
623
624 nnodes = get_elem_info(ElementInfo::NNODES, mesh->elem_type[ecnt]);
625
626 for (int ncnt = 0; ncnt < nnodes; ncnt++) {
627 /* node is the node number 'ncnt' of element 'ecnt' */
628 size_t node = mesh->connect[ecnt][ncnt];
629
630 /* i varies from 0 -> # of elements touching 'node' */
631 for (size_t i = 0; i < graph->sur_elem[node].size(); i++) {
632
633 /* 'entry' is element # i touching node 'node' */
634 INT entry = graph->sur_elem[node][i];
635
636 /* make sure we're not checking if the element
637 is connected to itself */
638 if (ecnt != (size_t)entry) {
639
640 /* now make sure that the entry is not a 3d element */
641 if (!is_3d_element(mesh->elem_type[entry])) {
642
643 int iret;
644 if ((iret = in_list(entry, graph->adj.size() - graph->start[cnt],
645 &graph->adj[graph->start[cnt]])) < 0) {
646
647 (graph->nadj)++;
648 graph->adj.push_back(entry);
649 if (weight->type & WeightingOptions::EDGE_WGT) {
650 weight->edges.push_back(1.0);
651 }
652 }
653 else if (weight->type & WeightingOptions::EDGE_WGT) {
654 weight->edges[iret + (graph->start[cnt])] += 1.0F;
655 }
656 }
657 } /* End: if(ecnt != entry) */
658 } /* for(i=0; i < graph->nsur_elem[node]; i++) */
659 } /* End "for(ncnt=0; ...)" */
660 } /* End: "else" (if !element_3d) */
661 } /* End: "else" (if face_adj != 0) */
662
663 cnt++;
664
665 } /* End "if(etype != SPHERE)" */
666 } /* End "for(ecnt=0; ecnt < mesh->num_elems; ecnt++)" */
667 }
668
669 graph->start[problem->num_vertices] = graph->adj.size();
670 graph->nadj = graph->adj.size();
671
672 if ((size_t)graph->start[problem->num_vertices] != graph->nadj) {
673 // Possibly an integer overflow... Output error message and stop.
674 std::ostringstream errmsg;
675 fmt::print(errmsg,
676 "fatal: Graph adjacency edge count ({}) exceeds chaco 32-bit integer range.\n",
677 graph->nadj);
678 Gen_Error(0, errmsg.str());
679 return 0;
680 }
681
682 /* Adjust for a mesh with spheres */
683 if (problem->type == DecompType::ELEMENTAL && sphere->num) {
684 /* Decrement adjacency entries */
685 for (auto &elem : graph->adj) {
686 for (size_t ecnt = 0; ecnt < mesh->num_el_blks; ecnt++) {
687 if (elem >= sphere->begin[ecnt] && elem < sphere->end[ecnt]) {
688 elem -= sphere->adjust[ecnt];
689 break;
690 }
691 }
692 }
693 }
694 return 1;
695 }
696 } // namespace