Skip to content

Commit 1f4fa7d

Browse files
Fixed bug, now passes test in serial
1 parent a7c9aae commit 1f4fa7d

File tree

2 files changed

+45
-40
lines changed

2 files changed

+45
-40
lines changed

Code/Source/solver/RobinBC.cpp

Lines changed: 44 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,21 @@ void RobinBC::initialize_from_vtp(const std::string& vtp_file_path)
302302
#ifdef debug_robin_bc_data
303303
dmsg << "Finished loading Robin BC data" << std::endl;
304304
#endif
305+
306+
// In case we are running sequentially, we need to fill the local arrays
307+
// and the global node map as well, because distribute is not called in sequential mode.
308+
local_stiffness_.resize(global_num_nodes_);
309+
local_damping_.resize(global_num_nodes_);
310+
for (int i = 0; i < global_num_nodes_; i++) {
311+
local_stiffness_(i) = global_stiffness_(i);
312+
local_damping_(i) = global_damping_(i);
313+
}
314+
315+
// Initialize global node map, in case we are running sequentially
316+
global_node_map_.clear();
317+
for (int i = 0; i < global_num_nodes_; i++) {
318+
global_node_map_[face_->gN(i)] = i;
319+
}
305320
}
306321

307322
double RobinBC::get_stiffness(int node_id) const
@@ -332,16 +347,19 @@ double RobinBC::get_damping(int node_id) const
332347

333348
int RobinBC::get_local_index(int global_node_id) const
334349
{
335-
auto it = global_node_map_.find(global_node_id);
336-
if (it == global_node_map_.end()) {
337-
throw std::runtime_error("Global node ID " + std::to_string(global_node_id) +
338-
" not found in global-to-local map.");
350+
if (spatially_variable) {
351+
auto it = global_node_map_.find(global_node_id);
352+
if (it == global_node_map_.end()) {
353+
throw std::runtime_error("Global node ID " + std::to_string(global_node_id) +
354+
" not found in global-to-local map.");
355+
}
356+
return it->second;
357+
} else {
358+
return 0;
339359
}
340-
return it->second;
341360
}
342361

343362

344-
345363
int RobinBC::find_vtp_point_index(double x, double y, double z,
346364
const Array<double>& vtp_points) const
347365
{
@@ -371,43 +389,30 @@ int RobinBC::find_vtp_point_index(double x, double y, double z,
371389

372390
void RobinBC::distribute(const ComMod& com_mod, const CmMod& cm_mod, const cmType& cm, const faceType& face)
373391
{
392+
#define debug_robin_bc_data_distribute
393+
#ifdef debug_robin_bc_data_distribute
394+
DebugMsg dmsg(__func__, cm.idcm());
395+
dmsg << "Distributing Robin BC data" << std::endl;
396+
#endif
374397

375398
// Update face pointer. This face is the portion of the global face that is owned by this process.
376399
face_ = &face;
377400

378401
bool is_slave = cm.slv(cm_mod);
379402

380403
// First communicate whether data is spatially variable
381-
#ifdef debug_robin_bc_data
382-
DebugMsg dmsg(__func__, cm.idcm());
383-
dmsg << "Distributing whether data is spatially variable" << std::endl;
384-
#endif
385404
cm.bcast(cm_mod, &spatially_variable);
386405

387406
// Communicate VTP file path if data is spatially variable
388407
if (spatially_variable) {
389-
#ifdef debug_robin_bc_data
390-
dmsg << "Distributing VTP file path" << std::endl;
391-
#endif
392408
cm.bcast(cm_mod, vtp_file_path_);
393409
}
394410

395411
// Communicate global number of nodes
396-
#ifdef debug_robin_bc_data
397-
dmsg << "Distributing global number of nodes" << std::endl;
398-
#endif
399412
cm.bcast(cm_mod, &global_num_nodes_);
400413

414+
// Initialize local storage
401415
if (spatially_variable) {
402-
// Initialize local storage
403-
#ifdef debug_robin_bc_data
404-
dmsg << "Checking face pointer..." << std::endl;
405-
if (face_ == nullptr) {
406-
dmsg << "WARNING: face_ is nullptr!" << std::endl;
407-
} else {
408-
dmsg << "face_ is valid, name: " << face_->name << std::endl;
409-
}
410-
#endif
411416

412417
if (face_ == nullptr) {
413418
throw std::runtime_error("face_ is nullptr during distribute");
@@ -416,14 +421,14 @@ void RobinBC::distribute(const ComMod& com_mod, const CmMod& cm_mod, const cmTyp
416421
// Number of nodes on the face on this processor
417422
local_num_nodes_ = face_->nNo;
418423

419-
#ifdef debug_robin_bc_data
424+
#ifdef debug_robin_bc_data_distribute
420425
dmsg << "Resizing local arrays to " << local_num_nodes_ << std::endl;
421426
#endif
422427
local_stiffness_.resize(local_num_nodes_);
423428
local_damping_.resize(local_num_nodes_);
424429

425430
// Each processor collects the nodal positions and global node IDs of its associated face portion
426-
#ifdef debug_robin_bc_data
431+
#ifdef debug_robin_bc_data_distribute
427432
dmsg << "Collecting local nodal positions" << std::endl;
428433
dmsg << "face_->name: " << face_->name;
429434
dmsg << "face_->nNo: " << face_->nNo;
@@ -437,20 +442,20 @@ void RobinBC::distribute(const ComMod& com_mod, const CmMod& cm_mod, const cmTyp
437442
local_positions.set_col(i, com_mod.x.col(face_->gN(i)));
438443
}
439444

440-
#ifdef debug_robin_bc_data
445+
#ifdef debug_robin_bc_data_distribute
441446
dmsg << "Local global IDs: " << local_global_ids << std::endl;
442447
dmsg << "Local positions: " << local_positions << std::endl;
443448
#endif
444449

445450
// Gather number of nodes from each processor to master
446-
#ifdef debug_robin_bc_data
451+
#ifdef debug_robin_bc_data_distribute
447452
dmsg << "Gathering number of nodes from each process to master" << std::endl;
448453
#endif
449454
Vector<int> proc_num_nodes(cm.np());
450455
cm.gather(cm_mod, &local_num_nodes_, 1, proc_num_nodes.data(), 1, 0);
451456

452457
// Calculate displacements for gatherv/scatterv and compute total number of nodes
453-
#ifdef debug_robin_bc_data
458+
#ifdef debug_robin_bc_data_distribute
454459
dmsg << "Calculating displacements for gatherv/scatterv and computing total number of nodes" << std::endl;
455460
#endif
456461
Vector<int> displs(cm.np());
@@ -465,15 +470,15 @@ void RobinBC::distribute(const ComMod& com_mod, const CmMod& cm_mod, const cmTyp
465470
Vector<double> all_stiffness, all_damping;
466471
if (!is_slave) {
467472
// Resize receive buffers based on total number of nodes
468-
#ifdef debug_robin_bc_data
473+
#ifdef debug_robin_bc_data_distribute
469474
dmsg << "Resizing receive buffers based on total number of nodes" << std::endl;
470475
#endif
471476
all_positions.resize(3, total_num_nodes);
472477
all_stiffness.resize(total_num_nodes);
473478
all_damping.resize(total_num_nodes);
474479

475480
// Gather all positions to master using gatherv
476-
#ifdef debug_robin_bc_data
481+
#ifdef debug_robin_bc_data_distribute
477482
dmsg << "Gathering all positions to master using gatherv" << std::endl;
478483
#endif
479484
for (int d = 0; d < 3; d++) {
@@ -489,21 +494,21 @@ void RobinBC::distribute(const ComMod& com_mod, const CmMod& cm_mod, const cmTyp
489494
}
490495

491496
// Get VTP points for position matching
492-
#ifdef debug_robin_bc_data
497+
#ifdef debug_robin_bc_data_distribute
493498
dmsg << "Getting VTP points for position matching" << std::endl;
494499
#endif
495500
Array<double> vtp_points = vtp_data_->get_points();
496501

497502
// Look up data for all nodes using point matching
498-
#ifdef debug_robin_bc_data
503+
#ifdef debug_robin_bc_data_distribute
499504
dmsg << "Looking up data for all nodes using point matching" << std::endl;
500505
#endif
501506
for (int i = 0; i < total_num_nodes; i++) {
502507
int vtp_idx = find_vtp_point_index(all_positions(0,i), all_positions(1,i), all_positions(2,i),
503508
vtp_points);
504509
all_stiffness(i) = global_stiffness_(vtp_idx);
505510
all_damping(i) = global_damping_(vtp_idx);
506-
#ifdef debug_robin_bc_data
511+
#ifdef debug_robin_bc_data_distribute
507512
dmsg << "Global stiffness value at node " << i << ": " << all_stiffness(i) << std::endl;
508513
dmsg << "Global damping value at node " << i << ": " << all_damping(i) << std::endl;
509514
#endif
@@ -529,14 +534,14 @@ void RobinBC::distribute(const ComMod& com_mod, const CmMod& cm_mod, const cmTyp
529534
cm.scatterv(cm_mod, all_stiffness, proc_num_nodes, displs, local_stiffness_, 0);
530535
cm.scatterv(cm_mod, all_damping, proc_num_nodes, displs, local_damping_, 0);
531536

532-
#ifdef debug_robin_bc_data
537+
#ifdef debug_robin_bc_data_distribute
533538
dmsg << "Local stiffness: " << local_stiffness_ << std::endl;
534539
dmsg << "Local damping: " << local_damping_ << std::endl;
535540
#endif
536541

537542
// Build mapping from face global node IDs to local array indices so we can
538543
// get data from a global node ID
539-
#ifdef debug_robin_bc_data
544+
#ifdef debug_robin_bc_data_distribute
540545
dmsg << "Building global node map from local global IDs" << std::endl;
541546
#endif
542547
global_node_map_.clear();
@@ -545,7 +550,7 @@ void RobinBC::distribute(const ComMod& com_mod, const CmMod& cm_mod, const cmTyp
545550
}
546551

547552
// Check if local arrays and node positions are consistent
548-
#ifdef debug_robin_bc_data
553+
#ifdef debug_robin_bc_data_distribute
549554
dmsg << "Checking if local arrays and node positions are consistent" << std::endl;
550555
for (int i = 0; i < local_num_nodes_; i++) {
551556
dmsg << "Local global ID: " << local_global_ids(i) << std::endl;
@@ -580,7 +585,7 @@ void RobinBC::distribute(const ComMod& com_mod, const CmMod& cm_mod, const cmTyp
580585
// Mark as defined
581586
defined_ = true;
582587

583-
#ifdef debug_robin_bc_data
588+
#ifdef debug_robin_bc_data_distribute
584589
dmsg << "Finished distributing Robin BC data" << std::endl;
585590
dmsg << "Number of nodes on this processor: " << local_num_nodes_ << std::endl;
586591
#endif

Code/Source/solver/baf_ini.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ void bc_ini(const ComMod& com_mod, const CmMod& cm_mod, bcType& lBc, faceType& l
261261
int nsd = com_mod.nsd;
262262
int tnNo = com_mod.tnNo;
263263

264-
#define debug_bc_ini
264+
#define n_debug_bc_ini
265265
#ifdef debug_bc_ini
266266
DebugMsg dmsg(__func__, com_mod.cm.idcm());
267267
dmsg.banner();

0 commit comments

Comments
 (0)