MCPcopy Create free account
hub / github.com/IBAMR/IBAMR / copyFreeDOFsArrayToVec

Method copyFreeDOFsArrayToVec

src/IB/CIBStrategy.cpp:616–683  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

614} // copyArrayToVec
615
616void
617CIBStrategy::copyFreeDOFsArrayToVec(Vec b, double* array, const std::vector<unsigned>& struct_ids, const int array_rank)
618{
619 if (struct_ids.empty()) return;
620 const int num_structs = static_cast<int>(struct_ids.size());
621
622 // Get the mapping of indices in the two vectors.
623 updateFreeDOFsMapping();
624 std::vector<int> map_vec, map_array;
625 map_vec.reserve(num_structs * s_max_free_dofs);
626 map_array.reserve(num_structs * s_max_free_dofs);
627 int local_counter = 0;
628 for (int part = 0; part < num_structs; ++part)
629 {
630 const unsigned struct_id = struct_ids[part];
631 int struct_free_dofs = 0;
632 const FreeRigidDOFVector& solve_dofs = getSolveRigidBodyVelocity(struct_id, struct_free_dofs);
633
634 for (int k = 0; k < s_max_free_dofs; ++k, ++local_counter)
635 {
636 if (solve_dofs[k])
637 {
638 map_array.push_back(local_counter);
639 }
640 }
641
642 if (!struct_free_dofs) continue;
643
644 const int& idx_begin = d_free_dofs_map[struct_id].first;
645 const int& idx_end = d_free_dofs_map[struct_id].second;
646 for (int i = idx_begin; i < idx_end; ++i)
647 {
648 map_vec.push_back(i);
649 }
650 }
651 int idx_size = static_cast<int>(map_vec.size());
652#if !defined(NDEBUG)
653 TBOX_ASSERT(idx_size == static_cast<int>(map_array.size()));
654#endif
655
656 // Wrap the raw data in a PETSc Vec.
657 int rank = IBTK_MPI::getRank();
658 PetscInt array_size = num_structs * s_max_free_dofs;
659 PetscInt array_local_size = 0;
660 if (rank == array_rank) array_local_size = array_size;
661 Vec array_vec;
662 VecCreateMPIWithArray(PETSC_COMM_WORLD, /*blocksize*/ 1, array_local_size, PETSC_DECIDE, array, &array_vec);
663
664 // Create index sets to define global index mapping of the two vectors.
665 IS is_vec;
666 IS is_array;
667 ISCreateGeneral(PETSC_COMM_SELF, idx_size, &map_vec[0], PETSC_COPY_VALUES, &is_vec);
668 ISCreateGeneral(PETSC_COMM_SELF, idx_size, &map_array[0], PETSC_COPY_VALUES, &is_array);
669
670 // Scatter values
671 VecScatter ctx;
672 VecScatterCreate(array_vec, is_array, b, is_vec, &ctx);
673 VecScatterBegin(ctx, array_vec, b, INSERT_VALUES, SCATTER_FORWARD);

Callers 1

solveBodySystemMethod · 0.80

Calls 4

emptyMethod · 0.45
sizeMethod · 0.45
reserveMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected