PetIBM 0.5.4
Toolbox and applications of the immersed-boundary method for distributed-memory architectures
rigidkinematics.cpp
Go to the documentation of this file.
1
10#include <iomanip>
11
12#include "rigidkinematics.h"
13
15 const YAML::Node &node)
16{
17 init(world, node);
18} // RigidKinematicsSolver
19
21{
22 PetscErrorCode ierr;
23 PetscBool finalized;
24
25 PetscFunctionBeginUser;
26
27 ierr = PetscFinalized(&finalized); CHKERRV(ierr);
28 if (finalized) return;
29
30 ierr = destroy(); CHKERRV(ierr);
31} // ~RigidKinematicsSolver
32
33// destroy data
35{
36 PetscErrorCode ierr;
37
38 PetscFunctionBeginUser;
39
40 ierr = DecoupledIBPMSolver::destroy(); CHKERRQ(ierr);
41 ierr = VecDestroy(&UB); CHKERRQ(ierr);
42
43 PetscFunctionReturn(0);
44} // destroy
45
46// initialize the decoupled IBPM solver for moving rigid bodies
47PetscErrorCode RigidKinematicsSolver::init(const MPI_Comm &world,
48 const YAML::Node &node)
49{
50 PetscErrorCode ierr;
51
52 PetscFunctionBeginUser;
53
54 ierr = DecoupledIBPMSolver::init(world, node); CHKERRQ(ierr);
55
56 ierr = PetscLogStagePush(stageInitialize); CHKERRQ(ierr);
57
58 ierr = PetscLogStageRegister("moveIB", &stageMoveIB); CHKERRQ(ierr);
59
60 ierr = VecDuplicate(f, &UB); CHKERRQ(ierr);
61 ierr = VecSet(UB, 0.0); CHKERRQ(ierr);
62
63 ierr = PetscLogStagePop(); CHKERRQ(ierr); // end of stageInitialize
64
65 PetscFunctionReturn(0);
66} // init
67
68// advance the solution by one time step
70{
71 PetscErrorCode ierr;
72
73 PetscFunctionBeginUser;
74
75 // note: use of `t + dt` because `t` is update in the Navier-Stokes method
76 ierr = moveBodies(t + dt); CHKERRQ(ierr);
77
78 ierr = DecoupledIBPMSolver::advance(); CHKERRQ(ierr);
79
80 PetscFunctionReturn(0);
81} // advance
82
83// write the solution, solver info, and body points to files
85{
86 PetscErrorCode ierr;
87
88 PetscFunctionBeginUser;
89
90 ierr = DecoupledIBPMSolver::write(); CHKERRQ(ierr);
91
92 if (ite % nsave == 0)
93 {
94 ierr = PetscLogStagePush(stageWrite); CHKERRQ(ierr);
95
96 ierr = writeBodies(); CHKERRQ(ierr);
97
98 ierr = PetscLogStagePop(); CHKERRQ(ierr); // end of stageWrite
99 }
100
101 PetscFunctionReturn(0);
102} // write
103
104// read of write initial data
106{
107 PetscErrorCode ierr;
108
109 PetscFunctionBeginUser;
110
111 ierr = DecoupledIBPMSolver::ioInitialData(); CHKERRQ(ierr);
112
113 ierr = writeBodies(); CHKERRQ(ierr);
114
115 PetscFunctionReturn(0);
116} // ioInitialData
117
118// update Lagrangian points, boundary velocity, and operators
119PetscErrorCode RigidKinematicsSolver::moveBodies(const PetscReal &ti)
120{
121 PetscErrorCode ierr;
122
123 PetscFunctionBeginUser;
124
125 ierr = PetscLogStagePush(stageMoveIB); CHKERRQ(ierr);
126
127 ierr = setCoordinatesBodies(ti); CHKERRQ(ierr);
128 ierr = setVelocityBodies(ti); CHKERRQ(ierr);
129 ierr = bodies->updateMeshIdx(mesh); CHKERRQ(ierr);
130 if (E != PETSC_NULL) {ierr = MatDestroy(&E); CHKERRQ(ierr);}
131 if (H != PETSC_NULL) {ierr = MatDestroy(&H); CHKERRQ(ierr);}
132 if (BNH != PETSC_NULL) {ierr = MatDestroy(&BNH); CHKERRQ(ierr);}
133 if (EBNH != PETSC_NULL) {ierr = MatDestroy(&EBNH); CHKERRQ(ierr);}
134 ierr = createExtraOperators(); CHKERRQ(ierr);
135 ierr = fSolver->setMatrix(EBNH); CHKERRQ(ierr);
136
137 ierr = PetscLogStagePop(); CHKERRQ(ierr); // end of stageMoveIB
138
139 PetscFunctionReturn(0);
140} // moveBodies
141
142// assemble the right-hand side of the system for the Lagrangian forces
144{
145 PetscErrorCode ierr;
146
147 PetscFunctionBeginUser;
148
149 ierr = PetscLogStagePush(stageRHSForces); CHKERRQ(ierr);
150
151 // rhsf = UB - E u^{**}
152 ierr = MatMult(E, solution->UGlobal, rhsf); CHKERRQ(ierr);
153 ierr = VecScale(rhsf, -1.0); CHKERRQ(ierr);
154 ierr = VecAYPX(rhsf, 1.0, UB); CHKERRQ(ierr);
155
156 ierr = PetscLogStagePop(); CHKERRQ(ierr);
157
158 PetscFunctionReturn(0);
159} // assembleRHSForces
160
161// write the coordinates of the Lagrangian points into files
163{
164 PetscErrorCode ierr;
165
166 PetscFunctionBeginUser;
167
168 std::string directory = config["output"].as<std::string>(".");
169 std::stringstream ss_ite;
170 ss_ite << std::setfill('0') << std::setw(7) << ite;
171 std::string filepath;
172 for (PetscInt i = 0; i < bodies->nBodies; ++i)
173 {
174 petibm::type::SingleBody &body = bodies->bodies[i];
175 filepath = directory + "/" + body->name + "_" + ss_ite.str();
176 std::stringstream ss_suffix;
177 ss_suffix << "." << body->dim << "D";
178 filepath = filepath + ss_suffix.str();
179 ierr = body->writeBody(filepath); CHKERRQ(ierr);
180 }
181
182 PetscFunctionReturn(0);
183} // writeBodies
Mat E
Regularization operator.
Definition: decoupledibpm.h:69
PetscLogStage stageRHSForces
Log stage for assembling the RHS of the forces system.
Definition: decoupledibpm.h:87
Mat BNH
Projection operator for the forces.
Definition: decoupledibpm.h:75
petibm::type::BodyPack bodies
Pack of immersed bodies.
Definition: decoupledibpm.h:60
PetscErrorCode ioInitialData()
Read or write initial data.
Mat H
Spreading operator.
Definition: decoupledibpm.h:66
Vec f
Vector to hold the forces at time step n.
Definition: decoupledibpm.h:78
PetscErrorCode init(const MPI_Comm &world, const YAML::Node &node)
Initialize the decoupled IBPM solver.
virtual PetscErrorCode createExtraOperators()
Assemble additional operators.
PetscErrorCode destroy()
Manually destroy data.
Vec rhsf
Right-hand side of the forces system.
Definition: decoupledibpm.h:84
petibm::type::LinSolver fSolver
Linear solver for the Lagrangian forces.
Definition: decoupledibpm.h:63
PetscErrorCode advance()
Advance the solution by one time step.
PetscErrorCode write()
Write solution and solver info to files.
Mat EBNH
Left-hand side operator of the system for the forces.
Definition: decoupledibpm.h:72
petibm::type::Solution solution
Data object holding the velocity and pressure fields.
Definition: navierstokes.h:95
PetscReal t
Time value.
Definition: navierstokes.h:119
YAML::Node config
YAML configuration settings.
Definition: navierstokes.h:86
PetscInt nsave
Frequency at which the solution fields are written to files.
Definition: navierstokes.h:128
PetscLogStage stageInitialize
Log stage for the initialization phase.
Definition: navierstokes.h:185
PetscReal dt
Time-step size.
Definition: navierstokes.h:113
PetscLogStage stageWrite
Log stage when write the solution fields.
Definition: navierstokes.h:203
PetscInt ite
Time-step index.
Definition: navierstokes.h:116
petibm::type::Mesh mesh
Structured Cartesian mesh object.
Definition: navierstokes.h:89
PetscErrorCode init(const MPI_Comm &world, const YAML::Node &node)
Initialize the decoupled IBPM solver with moving rigid bodies.
PetscErrorCode ioInitialData()
Read or write initial data.
Vec UB
Prescribed boundary velocity vector.
PetscLogStage stageMoveIB
Log stage for moving the bodies.
virtual PetscErrorCode setVelocityBodies(const PetscReal &ti)
Update the velocity of the Lagrangian points.
virtual PetscErrorCode writeBodies()
Write the coordinates of the Lagrangian points for each body.
~RigidKinematicsSolver()
Default destructor.
RigidKinematicsSolver()=default
Default constructor.
PetscErrorCode write()
Write solution, solver info, and body points to files.
PetscErrorCode destroy()
Manually destroy data.
PetscErrorCode advance()
Advance the solution by one time step.
virtual PetscErrorCode assembleRHSForces()
Assemble the right-hand side of the system for the forces.
virtual PetscErrorCode setCoordinatesBodies(const PetscReal &ti)
Update the position of the Lagrangian points.
virtual PetscErrorCode moveBodies(const PetscReal &ti)
Move the bodies and update the solver state.
std::shared_ptr< body::SingleBodyBase > SingleBody
Definition of type::SingleBody.
Definition: singlebody.h:206
Definition of the class RigidKinematicsSolver.