| 1324 | } // copyVecToArray |
| 1325 | |
| 1326 | void |
| 1327 | CIBMethod::copyArrayToVec(Vec b, |
| 1328 | double* array, |
| 1329 | const std::vector<unsigned>& struct_ids, |
| 1330 | const int data_depth, |
| 1331 | const int array_rank) |
| 1332 | { |
| 1333 | if (struct_ids.empty()) return; |
| 1334 | const auto num_structs = static_cast<unsigned>(struct_ids.size()); |
| 1335 | |
| 1336 | // Get the Lagrangian indices of the structures. |
| 1337 | std::vector<int> map; |
| 1338 | PetscInt total_nodes = 0; |
| 1339 | for (unsigned k = 0; k < num_structs; ++k) |
| 1340 | { |
| 1341 | total_nodes += getNumberOfNodes(struct_ids[k]); |
| 1342 | } |
| 1343 | map.reserve(total_nodes); |
| 1344 | for (unsigned k = 0; k < num_structs; ++k) |
| 1345 | { |
| 1346 | const std::pair<int, int>& lag_idx_range = d_struct_lag_idx_range[struct_ids[k]]; |
| 1347 | const unsigned struct_nodes = getNumberOfNodes(struct_ids[k]); |
| 1348 | for (unsigned j = 0; j < struct_nodes; ++j) |
| 1349 | { |
| 1350 | map.push_back(lag_idx_range.first + j); |
| 1351 | } |
| 1352 | } |
| 1353 | |
| 1354 | // Map the Lagrangian indices into PETSc indices |
| 1355 | const int struct_ln = getStructuresLevelNumber(); |
| 1356 | d_l_data_manager->mapLagrangianToPETSc(map, struct_ln); |
| 1357 | |
| 1358 | // Wrap the array in a PETSc Vec |
| 1359 | PetscInt size = total_nodes * data_depth; |
| 1360 | int rank = IBTK_MPI::getRank(); |
| 1361 | PetscInt array_local_size = 0; |
| 1362 | if (rank == array_rank) array_local_size = size; |
| 1363 | Vec array_vec; |
| 1364 | VecCreateMPIWithArray(PETSC_COMM_WORLD, /*blocksize*/ 1, array_local_size, PETSC_DECIDE, array, &array_vec); |
| 1365 | |
| 1366 | // Create index sets to define global index mapping. |
| 1367 | std::vector<PetscInt> vec_indices, array_indices; |
| 1368 | vec_indices.reserve(size); |
| 1369 | array_indices.reserve(size); |
| 1370 | for (PetscInt j = 0; j < total_nodes; ++j) |
| 1371 | { |
| 1372 | PetscInt petsc_idx = map[j]; |
| 1373 | for (int d = 0; d < data_depth; ++d) |
| 1374 | { |
| 1375 | array_indices.push_back(j * data_depth + d); |
| 1376 | vec_indices.push_back(petsc_idx * data_depth + d); |
| 1377 | } |
| 1378 | } |
| 1379 | IS is_vec; |
| 1380 | IS is_array; |
| 1381 | ISCreateGeneral(PETSC_COMM_SELF, size, &vec_indices[0], PETSC_COPY_VALUES, &is_vec); |
| 1382 | ISCreateGeneral(PETSC_COMM_SELF, size, &array_indices[0], PETSC_COPY_VALUES, &is_array); |
| 1383 |
no test coverage detected