16 const YAML::Node &node)
26 PetscFunctionBeginUser;
28 ierr = PetscFinalized(&finalized); CHKERRV(ierr);
29 if (finalized)
return;
31 ierr = DMDestroy(&
dmPack); CHKERRV(ierr);
39 PetscFunctionBeginUser;
43 std::vector<type::SingleBody>().swap(
bodies);
44 ierr = DMDestroy(&
dmPack); CHKERRQ(ierr);
52 PetscFunctionReturn(0);
56 const YAML::Node &node)
60 PetscFunctionBeginUser;
64 ierr = MPI_Comm_size(
comm, &
mpiSize); CHKERRQ(ierr);
65 ierr = MPI_Comm_rank(
comm, &
mpiRank); CHKERRQ(ierr);
71 if (!node[
"bodies"].IsDefined())
72 SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONG,
73 "No key \"bodies\" found in the YAML node provided for "
74 "initializing a BodyPack instance.\n");
76 nBodies = node[
"bodies"].size();
90 for (PetscInt i = 0; i <
nBodies; ++i)
92 std::string name, filePath, type;
95 name = node[
"bodies"][i][
"name"].as<std::string>(
"body" +
100 type = node[
"bodies"][i][
"type"].as<std::string>(
"points");
103 if (!node[
"bodies"][i][
"file"].IsDefined())
104 SETERRQ1(PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONG,
105 "No key \"file\" found in the YAML node of the body "
109 filePath = node[
"bodies"][i][
"file"].as<std::string>();
113 if (filePath[0] !=
'/')
114 filePath = node[
"directory"].as<std::string>() +
"/" + filePath;
119 for (PetscMPIInt r = 0; r <
mpiSize; ++r)
130 for (PetscMPIInt r =
mpiSize - 1; r > 0; r--)
132 for (PetscMPIInt r = 1; r <
mpiSize; r++)
141 PetscFunctionReturn(0);
148 PetscFunctionBeginUser;
150 ierr = DMCompositeCreate(
comm, &
dmPack); CHKERRQ(ierr);
152 for (PetscInt i = 0; i <
nBodies; ++i)
154 ierr = DMCompositeAddDM(
dmPack,
bodies[i]->da); CHKERRQ(ierr);
157 PetscFunctionReturn(0);
164 PetscFunctionBeginUser;
168 ierr = body->updateMeshIdx(mesh); CHKERRQ(ierr);
171 PetscFunctionReturn(0);
176 PetscFunctionBeginUser;
180 std::stringstream ss;
181 ss << std::string(80,
'=') << std::endl;
182 ss <<
"Body Pack:" << std::endl;
183 ss << std::string(80,
'=') << std::endl;
184 ss <<
"\tDimension: " <<
dim << std::endl << std::endl;
185 ss <<
"\tNumber of bodies: " <<
nBodies << std::endl << std::endl;
186 ss <<
"\tName of bodies: [";
187 for (PetscInt i = 0; i <
nBodies; ++i) ss <<
bodies[i]->name <<
", ";
188 ss <<
"]" << std::endl;
192 PetscFunctionReturn(0);
199 PetscFunctionBeginUser;
203 for (PetscInt i = 0; i <
nBodies; ++i)
205 ierr =
bodies[i]->printInfo(); CHKERRQ(ierr);
208 PetscFunctionReturn(0);
212 const PetscInt &ptIdx,
213 PetscMPIInt &proc)
const
217 PetscFunctionBeginUser;
219 if ((bIdx < 0) || (bIdx >=
nBodies))
220 SETERRQ2(
comm, PETSC_ERR_ARG_SIZ,
221 "Body index %d is out of range. Total number of bodies is %d.",
224 ierr =
bodies[bIdx]->findProc(ptIdx, proc); CHKERRQ(ierr);
226 PetscFunctionReturn(0);
230 const PetscInt &ptIdx,
236 PetscFunctionBeginUser;
238 if ((bIdx < 0) || (bIdx >=
nBodies))
239 SETERRQ2(
comm, PETSC_ERR_ARG_SIZ,
240 "Body index %d is out of range. Total number of bodies is %d.",
243 ierr =
bodies[bIdx]->getGlobalIndex(ptIdx, dof, idx); CHKERRQ(ierr);
245 PetscFunctionReturn(0);
254 PetscFunctionBeginUser;
258 PetscFunctionReturn(0);
262 const PetscInt &ptIdx,
268 PetscInt unPackedIdx;
270 PetscFunctionBeginUser;
272 ierr =
findProc(bIdx, ptIdx,
p); CHKERRQ(ierr);
274 ierr =
getGlobalIndex(bIdx, ptIdx, dof, unPackedIdx); CHKERRQ(ierr);
280 idx += (unPackedIdx -
bodies[bIdx]->offsetsAllProcs[
p]);
282 PetscFunctionReturn(0);
291 PetscFunctionBeginUser;
295 PetscFunctionReturn(0);
303 PetscFunctionBeginUser;
305 std::vector<Vec> unPacked(
nBodies);
310 DMCompositeGetAccessArray(
dmPack, f,
nBodies,
nullptr, unPacked.data());
313 for (PetscInt i = 0; i <
nBodies; ++i)
316 ierr =
bodies[i]->calculateAvgForces(unPacked[i], fAvg[i]);
320 ierr = DMCompositeRestoreAccessArray(
dmPack, f,
nBodies,
nullptr,
321 unPacked.data()); CHKERRQ(ierr);
323 PetscFunctionReturn(0);
329 PetscFunctionBeginUser;
331 bodies = std::make_shared<BodyPackBase>(comm, dim, node);
333 PetscFunctionReturn(0);
body::BodyPackBase, type::BodyPack, and factory function.
PetscInt nLclPts
Total number of local Lagrangian points.
PetscMPIInt mpiSize
Total number of processes.
std::string info
String used to print information.
PetscErrorCode printInfo() const
Print information about the bodies.
BodyPackBase()=default
Default constructor.
type::IntVec1D nLclAllProcs
Number of local packed variables of all processes.
virtual PetscErrorCode destroy()
Manually destroy data.
PetscErrorCode getPackedGlobalIndex(const PetscInt &bIdx, const PetscInt &ptIdx, const PetscInt &dof, PetscInt &idx) const
Find packed global index of a DoF of Lagrangian point of a body.
PetscErrorCode createInfoString()
Create a string used to print information.
MPI_Comm comm
Reference to the MPI communicator.
PetscErrorCode calculateAvgForces(const Vec &f, type::RealVec2D &fAvg)
Calculate the averaged force of each body.
virtual ~BodyPackBase()
Default destructor.
PetscErrorCode createDmPack()
Create DMComposite object for all bodies.
PetscMPIInt mpiRank
Rank of the local process.
std::vector< type::SingleBody > bodies
Vector of SingleBody objects.
type::IntVec1D offsetsAllProcs
Offsets of packed variables of all processes.
PetscErrorCode updateMeshIdx(const type::Mesh &mesh)
Get the index of closest Eulerian mesh cell for each local Lagrangian point.
PetscErrorCode getGlobalIndex(const PetscInt &bIdx, const PetscInt &ptIdx, const PetscInt &dof, PetscInt &idx) const
Find unpacked global index of a DoF of Lagrangian point of a body.
DM dmPack
DMComposite of DMDA objects of all SingleBody objects.
PetscErrorCode findProc(const PetscInt &bIdx, const PetscInt &ptIdx, PetscMPIInt &proc) const
Find which process owns the target Lagrangian point of target body.
PetscInt nPts
Total number of Lagrangian points.
PetscErrorCode init(const MPI_Comm &comm, const PetscInt &dim, const YAML::Node &node)
Initialize the pack of bodies.
PetscInt nBodies
Number of bodies in this pack.
PetscErrorCode createBodyPack(const MPI_Comm &comm, const PetscInt &dim, const YAML::Node &node, type::BodyPack &bodies)
Factory function to create a pack of bodies.
std::shared_ptr< body::BodyPackBase > BodyPack
Definition of type::BodyPack.
PetscErrorCode createSingleBody(const MPI_Comm &comm, const PetscInt &dim, const std::string &type, const std::string &name, const std::string &filePath, type::SingleBody &body)
Factory function to create a single body.
std::shared_ptr< mesh::MeshBase > Mesh
Type definition of Mesh.
PetscErrorCode print(const std::string &info)
Print information of a parallel object to standard output.
std::vector< RealVec1D > RealVec2D
2D std::vector holding PetscReal.
std::vector< PetscInt > IntVec1D
1D std::vector holding PetscInt.
Prototypes of I/O functions.
A toolbox for building flow solvers.