PetIBM 0.5.4
Toolbox and applications of the immersed-boundary method for distributed-memory architectures
singlebody.cpp
Go to the documentation of this file.
1
8#include <petibm/io.h>
9#include <petibm/singlebody.h>
11
12namespace petibm
13{
14namespace body
15{
16SingleBodyBase::SingleBodyBase(const MPI_Comm &inComm, const PetscInt &inDim,
17 const std::string &inName,
18 const std::string &inFilePath)
19{
20 // set up the name
21 name = inName;
22
23 // store the path of input file
24 filePath = inFilePath;
25
26 // store MPI information
27 comm = inComm;
28 MPI_Comm_size(comm, &mpiSize);
29 MPI_Comm_rank(comm, &mpiRank);
30
31 // save the dimension
32 dim = inDim;
33
34 // allocate vectors
37} // SingleBodyBase
38
40{
41 PetscErrorCode ierr;
42 PetscBool finalized;
43
44 PetscFunctionBeginUser;
45
46 ierr = PetscFinalized(&finalized); CHKERRV(ierr);
47 if (finalized) return;
48
49 ierr = DMDestroy(&da); CHKERRV(ierr);
50 comm = MPI_COMM_NULL;
51} // ~SingleBodyBase
52
54{
55 PetscFunctionBeginUser;
56 PetscErrorCode ierr;
57
58 dim = -1;
59 name = filePath = info = "";
60 nPts = nLclPts = bgPt = edPt = 0;
61 type::RealVec2D().swap(coords);
62 type::IntVec2D().swap(meshIdx);
63 ierr = DMDestroy(&da); CHKERRQ(ierr);
64 comm = MPI_COMM_NULL;
65 mpiSize = mpiRank = 0;
68
69 PetscFunctionReturn(0);
70} // destroy
71
72PetscErrorCode SingleBodyBase::printInfo() const
73{
74 PetscErrorCode ierr;
75
76 PetscFunctionBeginUser;
77
78 ierr = io::print(info); CHKERRQ(ierr);
79
80 PetscFunctionReturn(0);
81} // printInfo
82
83PetscErrorCode createSingleBody(const MPI_Comm &comm, const PetscInt &dim,
84 const std::string &type,
85 const std::string &name,
86 const std::string &filePath,
87 type::SingleBody &body)
88{
89 PetscFunctionBeginUser;
90
91 if (type == "points")
92 body = std::make_shared<SingleBodyPoints>(comm, dim, name, filePath);
93 else
94 SETERRQ1(PETSC_COMM_WORLD, PETSC_ERR_ARG_WRONG,
95 "The type of body file \"%s\" is not recognized!\n",
96 type.c_str());
97
98 PetscFunctionReturn(0);
99} // createSingleBody
100
101} // end of namespace body
102
103} // end of namespace petibm
PetscInt nPts
Total number of Lagrangian points.
Definition: singlebody.h:47
std::string name
Name of the body.
Definition: singlebody.h:41
PetscInt edPt
Global index of the last local Lagrangian point.
Definition: singlebody.h:68
MPI_Comm comm
MPI communicator.
Definition: singlebody.h:180
PetscMPIInt mpiRank
Rank of the local process.
Definition: singlebody.h:186
PetscMPIInt mpiSize
Total number of processes.
Definition: singlebody.h:183
PetscInt bgPt
Global index of the first local Lagrangian point.
Definition: singlebody.h:65
PetscInt dim
Number of dimensions.
Definition: singlebody.h:38
virtual PetscErrorCode destroy()
Manually destroy data.
Definition: singlebody.cpp:53
DM da
Parallel layout of the body (as a 1D DMDA object).
Definition: singlebody.h:71
PetscErrorCode printInfo() const
Print information about the body.
Definition: singlebody.cpp:72
type::IntVec1D offsetsAllProcs
Offset on each process.
Definition: singlebody.h:192
type::IntVec2D meshIdx
Index of the closest Eulerian mesh cell for each local Lagrangian point.
Definition: singlebody.h:62
type::IntVec1D nLclAllProcs
Vector with the number of local unknowns on each process.
Definition: singlebody.h:189
std::string filePath
Path of the file with the body coordinates.
Definition: singlebody.h:44
type::RealVec2D coords
Coordinates of ALL Lagrangian points.
Definition: singlebody.h:50
SingleBodyBase()=default
Default constructor.
std::string info
String with information about the body.
Definition: singlebody.h:74
PetscInt nLclPts
Local number of Lagrangian points.
Definition: singlebody.h:56
virtual ~SingleBodyBase()
Default destructor.
Definition: singlebody.cpp:39
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.
Definition: singlebody.cpp:83
std::shared_ptr< body::SingleBodyBase > SingleBody
Definition of type::SingleBody.
Definition: singlebody.h:206
PetscErrorCode print(const std::string &info)
Print information of a parallel object to standard output.
Definition: io.cpp:120
std::vector< IntVec1D > IntVec2D
2D std::vector holding PetscInt.
Definition: type.h:135
std::vector< RealVec1D > RealVec2D
2D std::vector holding PetscReal.
Definition: type.h:142
std::vector< PetscInt > IntVec1D
1D std::vector holding PetscInt.
Definition: type.h:133
Prototypes of I/O functions.
A toolbox for building flow solvers.
Definition: bodypack.h:52
body::SingleBodyBase, type::SingleBody factory function.
Definition of body::SingleBodyPoints.