10#include <petscviewerhdf5.h>
17 const YAML::Node &node)
27 PetscFunctionBeginUser;
29 ierr = PetscFinalized(&finalized); CHKERRV(ierr);
30 if (finalized)
return;
32 ierr =
destroy(); CHKERRV(ierr);
40 PetscFunctionBeginUser;
44 ierr = VecDestroy(&
df); CHKERRQ(ierr);
45 ierr = VecDestroy(&
f); CHKERRQ(ierr);
46 ierr = VecDestroy(&
rhsf); CHKERRQ(ierr);
47 ierr = MatDestroy(&
H); CHKERRQ(ierr);
48 ierr = MatDestroy(&
E); CHKERRQ(ierr);
49 ierr = MatDestroy(&
EBNH); CHKERRQ(ierr);
50 ierr = MatDestroy(&
BNH); CHKERRQ(ierr);
54 PetscFunctionReturn(0);
58 const YAML::Node &node)
62 PetscFunctionBeginUser;
71 ierr =
bodies->updateMeshIdx(
mesh); CHKERRQ(ierr);
88 config[
"output"].as<std::string>() +
89 "/forces-" + std::to_string(
ite) +
".txt",
93 ierr = PetscLogStageRegister(
"rhsForces", &
stageRHSForces); CHKERRQ(ierr);
94 ierr = PetscLogStageRegister(
96 ierr = PetscLogStageRegister(
99 ierr = PetscLogStagePop(); CHKERRQ(ierr);
101 PetscFunctionReturn(0);
109 PetscFunctionBeginUser;
128 ierr =
bc->updateGhostValues(
solution); CHKERRQ(ierr);
130 PetscFunctionReturn(0);
138 PetscFunctionBeginUser;
145 PetscFunctionReturn(0);
153 PetscFunctionBeginUser;
163 ierr = MatCreateVecs(R,
nullptr, &RDiag); CHKERRQ(ierr);
164 ierr = MatGetDiagonal(R, RDiag); CHKERRQ(ierr);
168 ierr = MatCreateVecs(MHat,
nullptr, &MHatDiag); CHKERRQ(ierr);
169 ierr = MatGetDiagonal(MHat, MHatDiag); CHKERRQ(ierr);
172 const YAML::Node &node =
config[
"parameters"];
173 std::string name = node[
"delta"].as<std::string>(
"ROMA_ET_AL_1999");
179 ierr = MatTranspose(
E, MAT_INITIAL_MATRIX, &
H); CHKERRQ(ierr);
182 ierr = MatDiagonalScale(
E,
nullptr, RDiag); CHKERRQ(ierr);
183 ierr = MatDiagonalScale(
E,
nullptr, MHatDiag); CHKERRQ(ierr);
196 N =
config[
"parameters"][
"BN"].as<PetscInt>(1);
202 BN,
H, MAT_INITIAL_MATRIX, PETSC_DEFAULT, &
BNH); CHKERRQ(ierr);
206 E,
BNH, MAT_INITIAL_MATRIX, PETSC_DEFAULT, &
EBNH); CHKERRQ(ierr);
209 ierr = VecDestroy(&RDiag); CHKERRQ(ierr);
210 ierr = VecDestroy(&MHatDiag); CHKERRQ(ierr);
211 ierr = MatDestroy(&MHat); CHKERRQ(ierr);
212 ierr = MatDestroy(&R); CHKERRQ(ierr);
213 ierr = MatDestroy(&BN); CHKERRQ(ierr);
215 PetscFunctionReturn(0);
223 PetscFunctionBeginUser;
225 ierr = DMCreateGlobalVector(
bodies->dmPack, &
f); CHKERRQ(ierr);
226 ierr = VecDuplicate(
f, &
df); CHKERRQ(ierr);
227 ierr = VecDuplicate(
f, &
rhsf); CHKERRQ(ierr);
229 PetscFunctionReturn(0);
237 PetscFunctionBeginUser;
245 ierr = MatMultAdd(
H,
f,
rhs1,
rhs1); CHKERRQ(ierr);
247 ierr = PetscLogStagePop(); CHKERRQ(ierr);
249 PetscFunctionReturn(0);
257 PetscFunctionBeginUser;
263 ierr = VecScale(
rhsf, -1.0); CHKERRQ(ierr);
265 ierr = PetscLogStagePop(); CHKERRQ(ierr);
267 PetscFunctionReturn(0);
275 PetscFunctionBeginUser;
282 ierr = PetscLogStagePop(); CHKERRQ(ierr);
284 PetscFunctionReturn(0);
292 PetscFunctionBeginUser;
298 PetscFunctionReturn(0);
306 PetscFunctionBeginUser;
308 ierr = PetscLogStagePush(
stageUpdate); CHKERRQ(ierr);
311 ierr = VecAXPY(
f, 1.0,
df); CHKERRQ(ierr);
313 ierr = PetscLogStagePop(); CHKERRQ(ierr);
315 PetscFunctionReturn(0);
320 const std::string &filePath)
324 PetscFunctionBeginUser;
328 ierr = PetscLogStagePush(
stageWrite); CHKERRQ(ierr);
332 ierr = PetscViewerCreate(
comm, &viewer); CHKERRQ(ierr);
333 ierr = PetscViewerSetType(viewer, PETSCVIEWERHDF5); CHKERRQ(ierr);
334 ierr = PetscViewerFileSetMode(viewer, FILE_MODE_APPEND); CHKERRQ(ierr);
335 ierr = PetscViewerFileSetName(viewer, filePath.c_str()); CHKERRQ(ierr);
338 ierr = PetscViewerHDF5PushGroup(viewer,
"/"); CHKERRQ(ierr);
341 ierr = PetscObjectSetName((PetscObject)
f,
"force"); CHKERRQ(ierr);
342 ierr = VecView(
f, viewer); CHKERRQ(ierr);
345 ierr = PetscViewerDestroy(&viewer); CHKERRQ(ierr);
347 ierr = PetscLogStagePop(); CHKERRQ(ierr);
349 PetscFunctionReturn(0);
354 const std::string &filePath)
358 PetscFunctionBeginUser;
364 ierr = PetscViewerCreate(
comm, &viewer); CHKERRQ(ierr);
365 ierr = PetscViewerSetType(viewer, PETSCVIEWERHDF5); CHKERRQ(ierr);
366 ierr = PetscViewerFileSetMode(viewer, FILE_MODE_READ); CHKERRQ(ierr);
367 ierr = PetscViewerFileSetName(viewer, filePath.c_str()); CHKERRQ(ierr);
370 ierr = PetscViewerHDF5PushGroup(viewer,
"/"); CHKERRQ(ierr);
373 ierr = PetscObjectSetName((PetscObject)
f,
"force"); CHKERRQ(ierr);
374 ierr = VecLoad(
f, viewer); CHKERRQ(ierr);
377 ierr = PetscViewerDestroy(&viewer); CHKERRQ(ierr);
379 PetscFunctionReturn(0);
389 PetscFunctionBeginUser;
391 ierr = PetscLogStagePush(
stageWrite); CHKERRQ(ierr);
397 ierr =
vSolver->getIters(nIters); CHKERRQ(ierr);
398 ierr =
vSolver->getResidual(res); CHKERRQ(ierr);
399 ierr = PetscViewerASCIIPrintf(
403 ierr =
pSolver->getIters(nIters); CHKERRQ(ierr);
404 ierr =
pSolver->getResidual(res); CHKERRQ(ierr);
405 ierr = PetscViewerASCIIPrintf(
409 ierr =
fSolver->getIters(nIters); CHKERRQ(ierr);
410 ierr =
fSolver->getResidual(res); CHKERRQ(ierr);
411 ierr = PetscViewerASCIIPrintf(
414 ierr = PetscLogStagePop(); CHKERRQ(ierr);
416 PetscFunctionReturn(0);
425 PetscFunctionBeginUser;
430 ierr =
bodies->calculateAvgForces(
f, fAvg); CHKERRQ(ierr);
432 ierr = PetscLogStagePop(); CHKERRQ(ierr);
434 ierr = PetscLogStagePush(
stageWrite); CHKERRQ(ierr);
437 ierr = PetscViewerASCIIPrintf(
forcesViewer,
"%10.8e\t",
t); CHKERRQ(ierr);
440 for (
int i = 0; i <
bodies->nBodies; ++i)
442 for (
int d = 0; d <
mesh->dim; ++d)
444 ierr = PetscViewerASCIIPrintf(
448 ierr = PetscViewerASCIIPrintf(
forcesViewer,
"\n"); CHKERRQ(ierr);
450 ierr = PetscLogStagePop(); CHKERRQ(ierr);
452 PetscFunctionReturn(0);
Mat E
Regularization operator.
PetscLogStage stageRHSForces
Log stage for assembling the RHS of the forces system.
Mat BNH
Projection operator for the forces.
petibm::type::BodyPack bodies
Pack of immersed bodies.
virtual PetscErrorCode writeLinSolversInfo()
Write numbers of iterations and residuals of solvers to file.
virtual PetscErrorCode applyNoSlip()
Update the velocity to satisfy the no-slip condition.
PetscViewer forcesViewer
ASCII PetscViewer object to output the forces.
virtual PetscErrorCode writeRestartDataHDF5(const std::string &filePath)
Write data required to restart a simulation into a HDF5 file.
Vec f
Vector to hold the forces at time step n.
virtual PetscErrorCode readRestartDataHDF5(const std::string &filePath)
Read data required to restart a simulation from a HDF5 file.
PetscErrorCode init(const MPI_Comm &world, const YAML::Node &node)
Initialize the decoupled IBPM solver.
DecoupledIBPMSolver()=default
Default constructor.
virtual PetscErrorCode createExtraOperators()
Assemble additional operators.
PetscLogStage stageSolveForces
Log stage for solving the forces system.
virtual PetscErrorCode writeForcesASCII()
Write the forces acting on the bodies into an ASCII file.
virtual PetscErrorCode solveForces()
Solve the system for the boundary forces.
PetscErrorCode destroy()
Manually destroy data.
PetscLogStage stageIntegrateForces
Log stage for integrating the Lagrangian forces.
Vec rhsf
Right-hand side of the forces system.
~DecoupledIBPMSolver()
Default destructor.
Vec df
Force-increment vector.
petibm::type::LinSolver fSolver
Linear solver for the Lagrangian forces.
virtual PetscErrorCode createExtraVectors()
Create additional vectors.
virtual PetscErrorCode assembleRHSForces()
Assemble the RHS vector of the system for the Lagrangian forces.
PetscErrorCode advance()
Advance the solution by one time step.
PetscErrorCode write()
Write solution and solver info to files.
virtual PetscErrorCode assembleRHSVelocity()
Assemble the RHS vector of the velocity system.
virtual PetscErrorCode updateForces()
Update the Lagrangian forces.
Mat EBNH
Left-hand side operator of the system for the forces.
petibm::type::Solution solution
Data object holding the velocity and pressure fields.
petibm::type::LinSolver pSolver
Poisson linear solver.
PetscReal nu
Viscous diffusion coefficient.
YAML::Node config
YAML configuration settings.
petibm::type::Boundary bc
Information about the domain boundaries.
virtual PetscErrorCode updatePressure()
virtual PetscErrorCode assembleRHSVelocity()
Assemble the RHS vector of the velocity system.
virtual PetscErrorCode readRestartDataHDF5(const std::string &filePath)
Read data required to restart a simulation from a HDF5 file.
PetscLogStage stageInitialize
Log stage for the initialization phase.
Vec rhs1
Right-hand side vector of the velocity system.
petibm::type::LinSolver vSolver
Velocity linear solver.
PetscReal dt
Time-step size.
Mat N
Convective operator (matrix-free).
virtual PetscErrorCode assembleRHSPoisson()
Assemble the RHS vector of the Poisson system.
MPI_Comm comm
MPI communicator.
virtual PetscErrorCode solvePoisson()
Solve the Poisson system.
virtual PetscErrorCode writeRestartDataHDF5(const std::string &filePath)
Write data required to restart a simulation into a HDF5 file.
petibm::type::TimeIntegration diffCoeffs
Time scheme for the diffusion terms.
virtual PetscErrorCode applyDivergenceFreeVelocity()
PetscLogStage stageRHSVelocity
Log stage for assembling the RHS of the velocity system.
PetscErrorCode write()
Write solution and solver info to files.
PetscErrorCode init(const MPI_Comm &world, const YAML::Node &node)
Initialize the Navier-Stokes solver.
PetscLogStage stageWrite
Log stage when write the solution fields.
PetscLogStage stageUpdate
Log stage for updating field variables.
PetscInt ite
Time-step index.
petibm::type::Mesh mesh
Structured Cartesian mesh object.
virtual PetscErrorCode solveVelocity()
Solve the velocity system.
PetscErrorCode destroy()
Manually destroy data.
virtual PetscErrorCode createPetscViewerASCII(const std::string &filePath, const PetscFileMode &mode, PetscViewer &viewer)
Create an ASCII PetscViewer.
PetscViewer solversViewer
ASCII PetscViewer object to output solvers info.
Definition of the class DecoupledIBPMSolver.
Prototype of Delta functions.
PetscErrorCode createBodyPack(const MPI_Comm &comm, const PetscInt &dim, const YAML::Node &node, type::BodyPack &bodies)
Factory function to create a pack of bodies.
PetscErrorCode createLinSolver(const std::string &solverName, const YAML::Node &node, type::LinSolver &solver)
A factory function for creating a LinSolver.
PetscErrorCode createMHead(const type::Mesh &mesh, Mat &MHead)
Create a matrix of cell widths of velocity points, .
PetscErrorCode createBnHead(const Mat &Op, const PetscReal &dt, const PetscReal &coeff, const PetscInt &n, Mat &BnHead)
Create non-normalized matrix of approximated , .
PetscErrorCode createDelta(const type::Mesh &mesh, const type::Boundary &bc, const type::BodyPack &bodies, const delta::DeltaKernel &kernel, const PetscInt &kernelSize, Mat &Op)
Create a Delta operator, .
PetscErrorCode createR(const type::Mesh &mesh, Mat &R)
Create a matrix of flux areas, .
std::vector< RealVec1D > RealVec2D
2D std::vector holding PetscReal.
PetscErrorCode getKernel(const std::string &name, DeltaKernel &kernel, PetscInt &size)
Get the delta kernel and size providing the name.
std::function< PetscReal(const PetscReal &r, const PetscReal &dr)> DeltaKernel
Typedef to choose the regularized delta kernel to use.