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

Method copyVecToArray

src/IB/CIBMethod.cpp:1253–1324  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1251} // computeNetRigidGeneralizedForce
1252
1253void
1254CIBMethod::copyVecToArray(Vec b,
1255 double* array,
1256 const std::vector<unsigned int>& struct_ids,
1257 const int data_depth,
1258 const int array_rank)
1259{
1260 if (struct_ids.empty()) return;
1261 const auto num_structs = static_cast<unsigned>(struct_ids.size());
1262
1263 // Get the Lagrangian indices of the structures.
1264 std::vector<int> map;
1265 PetscInt total_nodes = 0;
1266 for (unsigned k = 0; k < num_structs; ++k)
1267 {
1268 total_nodes += getNumberOfNodes(struct_ids[k]);
1269 }
1270 map.reserve(total_nodes);
1271 for (unsigned k = 0; k < num_structs; ++k)
1272 {
1273 const std::pair<int, int>& lag_idx_range = d_struct_lag_idx_range[struct_ids[k]];
1274 const unsigned struct_nodes = getNumberOfNodes(struct_ids[k]);
1275 for (unsigned j = 0; j < struct_nodes; ++j)
1276 {
1277 map.push_back(lag_idx_range.first + j);
1278 }
1279 }
1280
1281 // Map the Lagrangian indices into PETSc indices
1282 const int struct_ln = getStructuresLevelNumber();
1283 d_l_data_manager->mapLagrangianToPETSc(map, struct_ln);
1284
1285 // Wrap the raw data in a PETSc Vec
1286 PetscInt size = total_nodes * data_depth;
1287 int rank = IBTK_MPI::getRank();
1288 PetscInt array_local_size = 0;
1289 if (rank == array_rank) array_local_size = size;
1290 Vec array_vec;
1291 VecCreateMPIWithArray(PETSC_COMM_WORLD, /*blocksize*/ 1, array_local_size, PETSC_DECIDE, array, &array_vec);
1292
1293 // Create index sets to define global index mapping.
1294 std::vector<PetscInt> vec_indices, array_indices;
1295 vec_indices.reserve(size);
1296 array_indices.reserve(size);
1297 for (PetscInt j = 0; j < total_nodes; ++j)
1298 {
1299 PetscInt petsc_idx = map[j];
1300 for (int d = 0; d < data_depth; ++d)
1301 {
1302 array_indices.push_back(j * data_depth + d);
1303 vec_indices.push_back(petsc_idx * data_depth + d);
1304 }
1305 }
1306 IS is_vec;
1307 IS is_array;
1308 ISCreateGeneral(PETSC_COMM_SELF, size, &vec_indices[0], PETSC_COPY_VALUES, &is_vec);
1309 ISCreateGeneral(PETSC_COMM_SELF, size, &array_indices[0], PETSC_COPY_VALUES, &is_array);
1310

Callers 1

solveSystemMethod · 0.45

Calls 5

mapLagrangianToPETScMethod · 0.80
emptyMethod · 0.45
sizeMethod · 0.45
reserveMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected