Skip to content

Commit 2d53b33

Browse files
committed
Reorder elements in dual mesh so that they're in the same order as the corresponding nodes in the source mesh.
1 parent 61b2213 commit 2d53b33

File tree

1 file changed

+40
-14
lines changed

1 file changed

+40
-14
lines changed

src/Infrastructure/Mesh/src/ESMCI_MeshDual.C

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,12 @@ namespace ESMCI {
9090
}
9191
};
9292

93+
94+
bool less_by_data_index(const MeshObj *a, const MeshObj *b) {
95+
return (a->get_data_index() < b->get_data_index());
96+
}
97+
98+
9399

94100
void get_unique_elems_around_node(MeshObj *node, Mesh *mesh, std::vector<MDSS> &tmp_mdss, std::vector<PntS> &tmp_pntss,
95101
std::vector<UInt> &ids);
@@ -304,15 +310,28 @@ namespace ESMCI {
304310
nodes_used[i]=0;
305311
}
306312

313+
// Save source nodes in a vector
314+
std::vector<MeshObj *> src_nodes;
315+
src_nodes.reserve(src_mesh->num_nodes());
316+
MeshDB::iterator ni = src_mesh->node_begin(), ne = src_mesh->node_end();
317+
for (; ni != ne; ++ni) {
318+
MeshObj *node=&(*ni);
319+
320+
src_nodes.push_back(node);
321+
}
322+
323+
// Sort src_nodes by data index, so the elements in the output dual mesh
324+
// will have the same order as the nodes in the source mesh
325+
std::sort(src_nodes.begin(), src_nodes.end(), less_by_data_index);
326+
327+
307328
// Iterate through src nodes counting sizes
308329
// Note that the elems around the node are the maximum possible, it
309330
// could be less when actually counted and uniqued.
310331
int max_num_elems=0;
311332
int max_num_elemConn=0;
312333
int max_num_node_elems=0;
313-
MeshDB::iterator ni = src_mesh->node_begin(), ne = src_mesh->node_end();
314-
for (; ni != ne; ++ni) {
315-
MeshObj &node=*ni;
334+
for (MeshObj *node: src_nodes) {
316335

317336
// Only do local nodes
318337
// ALSO DO NON-LOCAL NODES, BECAUSE OTHERWISE YOU
@@ -322,7 +341,7 @@ namespace ESMCI {
322341

323342
// Get number of elems
324343
int num_node_elems=0;
325-
get_num_elems_around_node(&node, &num_node_elems);
344+
get_num_elems_around_node(node, &num_node_elems);
326345

327346
// If less than 3 (a triangle) then don't make an element
328347
if (num_node_elems < 3) continue;
@@ -377,9 +396,7 @@ namespace ESMCI {
377396
int conn_pos=0;
378397
int ec_pos=0;
379398
int eoc_pos=0;
380-
ni = src_mesh->node_begin();
381-
for (; ni != ne; ++ni) {
382-
MeshObj &node=*ni;
399+
for (MeshObj *node: src_nodes) {
383400

384401
// Only do local nodes
385402
// ALSO DO NON-LOCAL NODES, BECAUSE OTHERWISE YOU
@@ -394,7 +411,7 @@ namespace ESMCI {
394411

395412

396413
// Get list of element ids
397-
get_unique_elems_around_node(&node, src_mesh, tmp_mdss, tmp_pntss, new_elem_ids);
414+
get_unique_elems_around_node(node, src_mesh, tmp_mdss, tmp_pntss, new_elem_ids);
398415

399416
#ifdef DEBUG_UNIQUE_ELEMS
400417
{
@@ -412,23 +429,23 @@ namespace ESMCI {
412429
elemType[num_elems]=new_elem_ids.size();
413430

414431
// Save elemId
415-
elemId[num_elems]=node.get_id();
432+
elemId[num_elems]=node->get_id();
416433

417434
// Save owner
418-
elemOwner[num_elems]=node.get_owner();
435+
elemOwner[num_elems]=node->get_owner();
419436

420437
// printf("%d# eId=%d eT=%d ::",Par::Rank(),elemId[num_elems],elemType[num_elems]);
421438

422439
// Save coordinates
423-
double *coords=src_node_coords->data(node);
440+
double *coords=src_node_coords->data(*node);
424441
for (auto d=0; d<sdim; d++) {
425442
elemCoords[ec_pos]=coords[d];
426443
ec_pos++;
427444
}
428445

429446
// If present, save original coordinates
430447
if (elemOrigCoords && src_node_orig_coords) {
431-
double *orig_coords=src_node_orig_coords->data(node);
448+
double *orig_coords=src_node_orig_coords->data(*node);
432449
for (auto od=0; od<orig_sdim; od++) {
433450
elemOrigCoords[eoc_pos]=orig_coords[od];
434451
eoc_pos++;
@@ -437,13 +454,13 @@ namespace ESMCI {
437454

438455
// If present, save element mask value
439456
if (elemMaskVal && src_node_mask_val) {
440-
double *nmv=src_node_mask_val->data(node);
457+
double *nmv=src_node_mask_val->data(*node);
441458
elemMaskVal[num_elems]=*nmv;
442459
}
443460

444461
// If present, save element mask value
445462
if (elemMask && src_node_mask) {
446-
double *nm=src_node_mask->data(node);
463+
double *nm=src_node_mask->data(*node);
447464
elemMask[num_elems]=*nm;
448465
}
449466

@@ -901,11 +918,20 @@ namespace ESMCI {
901918

902919
int nnodes = topo->num_nodes;
903920
std::vector<MeshObj*> nconnect(nnodes, static_cast<MeshObj*>(0));
921+
922+
// For dist fix:
923+
// - e below is the data index
924+
// - What should it be for split elems?
925+
// + A: It looks like in mesh create code, the split elems are just interleaved.
926+
// I guess that I should just mimic that, so that there aren't issues.
927+
// If you want to change it, then both should be changed.
928+
904929

905930
// The object
906931
UInt eid = elemId[e];
907932
MeshObj *elem = new MeshObj(MeshObj::ELEMENT, eid, e);
908933

934+
// Get connectivity
909935
for (int n = 0; n < nnodes; ++n) {
910936

911937
// Get 0-based node index

0 commit comments

Comments
 (0)