| 531 | } // copyVecToArray |
| 532 | |
| 533 | void |
| 534 | CIBStrategy::copyFreeDOFsVecToArray(Vec b, double* array, const std::vector<unsigned>& struct_ids, const int array_rank) |
| 535 | { |
| 536 | if (struct_ids.empty()) return; |
| 537 | const int num_structs = static_cast<int>(struct_ids.size()); |
| 538 | |
| 539 | // Get the mapping of indices in the two vectors. |
| 540 | updateFreeDOFsMapping(); |
| 541 | std::vector<int> map_vec, map_array; |
| 542 | map_vec.reserve(num_structs * s_max_free_dofs); |
| 543 | map_array.reserve(num_structs * s_max_free_dofs); |
| 544 | int local_counter = 0; |
| 545 | for (int part = 0; part < num_structs; ++part) |
| 546 | { |
| 547 | const unsigned struct_id = struct_ids[part]; |
| 548 | int struct_free_dofs = 0; |
| 549 | const FreeRigidDOFVector& solve_dofs = getSolveRigidBodyVelocity(struct_id, struct_free_dofs); |
| 550 | |
| 551 | for (int k = 0; k < s_max_free_dofs; ++k, ++local_counter) |
| 552 | { |
| 553 | if (solve_dofs[k]) |
| 554 | { |
| 555 | map_array.push_back(local_counter); |
| 556 | } |
| 557 | } |
| 558 | |
| 559 | if (!struct_free_dofs) continue; |
| 560 | |
| 561 | const int& idx_begin = d_free_dofs_map[struct_id].first; |
| 562 | const int& idx_end = d_free_dofs_map[struct_id].second; |
| 563 | for (int i = idx_begin; i < idx_end; ++i) |
| 564 | { |
| 565 | map_vec.push_back(i); |
| 566 | } |
| 567 | } |
| 568 | int idx_size = static_cast<int>(map_vec.size()); |
| 569 | #if !defined(NDEBUG) |
| 570 | TBOX_ASSERT(idx_size == static_cast<int>(map_array.size())); |
| 571 | #endif |
| 572 | |
| 573 | // Wrap the raw data in a PETSc Vec. |
| 574 | int rank = IBTK_MPI::getRank(); |
| 575 | PetscInt array_size = num_structs * s_max_free_dofs; |
| 576 | PetscInt array_local_size = 0; |
| 577 | if (rank == array_rank) array_local_size = array_size; |
| 578 | Vec array_vec; |
| 579 | VecCreateMPIWithArray(PETSC_COMM_WORLD, /*blocksize*/ 1, array_local_size, PETSC_DECIDE, array, &array_vec); |
| 580 | VecSet(array_vec, 0.0); |
| 581 | VecAssemblyBegin(array_vec); |
| 582 | VecAssemblyEnd(array_vec); |
| 583 | |
| 584 | // Create index sets to define global index mapping of the two vectors. |
| 585 | IS is_vec; |
| 586 | IS is_array; |
| 587 | ISCreateGeneral(PETSC_COMM_SELF, idx_size, &map_vec[0], PETSC_COPY_VALUES, &is_vec); |
| 588 | ISCreateGeneral(PETSC_COMM_SELF, idx_size, &map_array[0], PETSC_COPY_VALUES, &is_array); |
| 589 | |
| 590 | // Scatter values |
no test coverage detected