20 const std::string &name,
21 const std::string &filePath)
28 const std::string &name,
29 const std::string &filePath)
33 PetscFunctionBeginUser;
40 SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_FILE_READ,
41 "The dimension of Lagrangian points are different than that "
42 "of the background mesh!\n");
58 PetscFunctionReturn(0);
64 DMDALocalInfo lclInfo;
66 PetscFunctionBeginUser;
68 ierr = DMDACreate1d(
comm, DM_BOUNDARY_NONE,
nPts,
dim, 0,
nullptr, &
da);
70 ierr = DMSetUp(
da); CHKERRQ(ierr);
72 ierr = DMDAGetLocalInfo(
da, &lclInfo); CHKERRQ(ierr);
81 MPIU_INT,
comm); CHKERRQ(ierr);
87 for (PetscMPIInt r =
mpiSize - 1; r > 0; r--)
89 for (PetscMPIInt r = 1; r <
mpiSize; r++)
92 PetscFunctionReturn(0);
97 PetscFunctionBeginUser;
100 for (PetscInt i =
bgPt, c = 0; i <
edPt; ++i, ++c)
102 for (PetscInt d = 0; d <
dim; ++d)
104 if (mesh->min[d] >=
coords[i][d] || mesh->max[d] <=
coords[i][d])
106 SETERRQ3(PETSC_COMM_WORLD, PETSC_ERR_MAX_VALUE,
107 "body coordinate %g is outside domain [%g, %g] !",
108 coords[i][d], mesh->min[d], mesh->max[d]);
111 meshIdx[c][d] = std::upper_bound(mesh->coord[4][d],
112 mesh->coord[4][d] + mesh->n[4][d],
114 mesh->coord[4][d] - 1;
118 PetscFunctionReturn(0);
124 std::stringstream ss;
126 PetscFunctionBeginUser;
131 ss << std::string(80,
'=') << std::endl;
132 ss <<
"Body " <<
name <<
":" << std::endl;
133 ss << std::string(80,
'=') << std::endl;
134 ss <<
"\tInput mesh file: " <<
filePath << std::endl << std::endl;
135 ss <<
"\tDimension: " <<
dim << std::endl << std::endl;
136 ss <<
"\tTotal number of Lagrangian points: " <<
nPts << std::endl
138 ss <<
"\tBody is distributed to " <<
mpiSize <<
" processes"
141 ss <<
"\tDistribution of Lagrangian points:" << std::endl << std::endl;
144 ss <<
"\t\tRank " <<
mpiRank <<
":" << std::endl;
145 ss <<
"\t\t\tNumber of points: " <<
nLclPts << std::endl;
146 ss <<
"\t\t\tRange of points: [" <<
bgPt <<
", " <<
edPt <<
")"
151 ierr = MPI_Barrier(
comm); CHKERRQ(ierr);
153 PetscFunctionReturn(0);
157 PetscMPIInt &
p)
const
159 PetscFunctionBeginUser;
161 if ((i < 0) || (i >=
nPts))
162 SETERRQ2(
comm, PETSC_ERR_ARG_SIZ,
163 "Index %d of Lagrangian point on the body %s is out of range.",
171 PetscFunctionReturn(0);
178 PetscFunctionBeginUser;
180 if ((i < 0) || (i >=
nPts))
181 SETERRQ2(
comm, PETSC_ERR_ARG_SIZ,
182 "Index %d of Lagrangian point on the body %s is out of range.",
185 if ((dof < 0) || (dof >=
dim))
186 SETERRQ2(
comm, PETSC_ERR_ARG_SIZ,
187 "DoF %d is not correct. The dimension is %d.", dof,
dim);
192 PetscFunctionReturn(0);
200 PetscFunctionBeginUser;
204 PetscFunctionReturn(0);
212 PetscFunctionBeginUser;
218 ierr = DMDAVecGetArrayDOF(
da, f, &fArry); CHKERRQ(ierr);
220 for (PetscInt i =
bgPt; i <
edPt; ++i)
222 for (PetscInt dof = 0; dof <
dim; ++dof)
228 ierr = MPI_Barrier(
comm); CHKERRQ(ierr);
230 ierr = MPI_Allreduce(fAvgLocal.data(), fAvg.data(),
dim, MPIU_REAL, MPI_SUM,
231 comm); CHKERRQ(ierr);
233 ierr = DMDAVecRestoreArrayDOF(
da, f, &fArry); CHKERRQ(ierr);
235 PetscFunctionReturn(0);
242 PetscFunctionBeginUser;
248 PetscFunctionReturn(0);
256 PetscFunctionBeginUser;
259 ierr = PetscViewerCreate(
comm, &viewer); CHKERRQ(ierr);
260 ierr = PetscViewerSetType(viewer, PETSCVIEWERASCII); CHKERRQ(ierr);
261 ierr = PetscViewerFileSetMode(viewer, FILE_MODE_WRITE); CHKERRQ(ierr);
262 ierr = PetscViewerFileSetName(viewer, filepath.c_str()); CHKERRQ(ierr);
265 for (PetscInt k = 0; k <
nPts; ++k)
267 ierr = PetscViewerASCIIPrintf(
268 viewer,
"%10.8e\t%10.8e\t%10.8e\n",
274 for (PetscInt k = 0; k <
nPts; ++k)
276 ierr = PetscViewerASCIIPrintf(
277 viewer,
"%10.8e\t%10.8e\n",
282 SETERRQ(PETSC_COMM_WORLD, PETSC_ERR_FILE_WRITE,
283 "Function only supports 2D and 3D bodies.\n");
284 ierr = PetscViewerDestroy(&viewer); CHKERRQ(ierr);
286 PetscFunctionReturn(0);
Base (abstract) class for a single body.
PetscInt nPts
Total number of Lagrangian points.
std::string name
Name of the body.
PetscInt edPt
Global index of the last local Lagrangian point.
MPI_Comm comm
MPI communicator.
PetscMPIInt mpiRank
Rank of the local process.
type::RealVec2D coords0
Initial coordinates of ALL Lagrangian points.
PetscMPIInt mpiSize
Total number of processes.
PetscInt bgPt
Global index of the first local Lagrangian point.
PetscInt dim
Number of dimensions.
DM da
Parallel layout of the body (as a 1D DMDA object).
type::IntVec1D offsetsAllProcs
Offset on each process.
type::IntVec2D meshIdx
Index of the closest Eulerian mesh cell for each local Lagrangian point.
type::IntVec1D nLclAllProcs
Vector with the number of local unknowns on each process.
std::string filePath
Path of the file with the body coordinates.
type::RealVec2D coords
Coordinates of ALL Lagrangian points.
std::string info
String with information about the body.
PetscInt nLclPts
Local number of Lagrangian points.
virtual PetscErrorCode writeBody(const std::string &filepath)
virtual PetscErrorCode updateMeshIdx(const type::Mesh &mesh)
Get the index of closest Eulerian mesh cell for each local Lagrangian point.
PetscErrorCode createInfoString()
Create a string used to print information about the body.
PetscErrorCode init(const MPI_Comm &comm, const PetscInt &dim, const std::string &name, const std::string &filePath)
Initialize the body, reading coordinates from given file.
virtual PetscErrorCode getGlobalIndex(const PetscInt &i, const PetscInt &dof, PetscInt &idx) const
Get the global index of a Lagrangian point in a DMDA object given its degree of freedom.
SingleBodyPoints(const MPI_Comm &comm, const PetscInt &dim, const std::string &name, const std::string &filePath)
Constructor. Initialize a single body.
PetscErrorCode createDMDA()
Create a parallel layout (1D DMDA object) of the body.
virtual PetscErrorCode findProc(const PetscInt &i, PetscMPIInt &p) const
Get the process id owning a given Lagrangian point.
virtual PetscErrorCode readBody(const std::string &filepath)
virtual PetscErrorCode calculateAvgForces(const Vec &f, type::RealVec1D &fAvg) const
Calculate the averaged force of this body.
std::shared_ptr< mesh::MeshBase > Mesh
Type definition of Mesh.
PetscErrorCode readLagrangianPoints(const std::string &file, PetscInt &nPts, type::RealVec2D &coords)
Read the number Lagrangian points and their coordinates from a file.
std::vector< IntVec1D > IntVec2D
2D std::vector holding PetscInt.
std::vector< PetscInt > IntVec1D
1D std::vector holding PetscInt.
std::vector< PetscReal > RealVec1D
1D std::vector holding PetscReal.
Prototypes of I/O functions.
A toolbox for building flow solvers.
Definition of body::SingleBodyPoints.