-
Notifications
You must be signed in to change notification settings - Fork 237
/
fsi2.cpp
310 lines (292 loc) · 17.3 KB
/
fsi2.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
/**
* @file fsi2.cpp
* @brief This is the benchmark test of fluid-structure interaction.
* @details We consider a flow-induced vibration of an elastic beam behind a cylinder in 2D.
* The case can be found in Chi Zhang, Massoud Rezavand, Xiangyu Hu,
* Dual-criteria time stepping for weakly compressible smoothed particle hydrodynamics.
* Journal of Computation Physics 404 (2020) 109135.
* @author Chi Zhang and Xiangyu Hu
*/
#include "fsi2.h" // case file to setup the test case
#include "sphinxsys.h"
using namespace SPH;
//----------------------------------------------------------------------
// Main program starts here.
//----------------------------------------------------------------------
int main(int ac, char *av[])
{
//----------------------------------------------------------------------
// Build up SPHSystem and IO environment.
//----------------------------------------------------------------------
BoundingBox system_domain_bounds(Vec2d(-DL_sponge - BW, -BW), Vec2d(DL + BW, DH + BW));
SPHSystem sph_system(system_domain_bounds, resolution_ref);
sph_system.setRunParticleRelaxation(false); // Tag for run particle relaxation for body-fitted distribution
sph_system.setReloadParticles(true); // Tag for computation with save particles distribution
sph_system.handleCommandlineOptions(ac, av); // handle command line arguments
IOEnvironment io_environment(sph_system);
//----------------------------------------------------------------------
// Creating body, materials and particles.
//----------------------------------------------------------------------
FluidBody water_block(sph_system, makeShared<WaterBlock>("WaterBody"));
water_block.defineMaterial<WeaklyCompressibleFluid>(rho0_f, c_f, mu_f);
water_block.generateParticles<BaseParticles, Lattice>();
SolidBody wall_boundary(sph_system, makeShared<WallBoundary>("WallBoundary"));
wall_boundary.defineMaterial<Solid>();
wall_boundary.generateParticles<BaseParticles, Lattice>();
SolidBody insert_body(sph_system, makeShared<Insert>("InsertedBody"));
insert_body.defineAdaptationRatios(1.15, 2.0);
insert_body.defineBodyLevelSetShape()->writeLevelSet(sph_system);
insert_body.defineMaterial<SaintVenantKirchhoffSolid>(rho0_s, Youngs_modulus, poisson);
(!sph_system.RunParticleRelaxation() && sph_system.ReloadParticles())
? insert_body.generateParticles<BaseParticles, Reload>(insert_body.getName())
: insert_body.generateParticles<BaseParticles, Lattice>();
ObserverBody beam_observer(sph_system, "BeamObserver");
StdVec<Vecd> beam_observation_location = {0.5 * (BRT + BRB)};
beam_observer.generateParticles<ObserverParticles>(beam_observation_location);
ObserverBody fluid_observer(sph_system, "FluidObserver");
fluid_observer.generateParticles<ObserverParticles>(createObservationPoints());
//----------------------------------------------------------------------
// Run particle relaxation for body-fitted distribution if chosen.
//----------------------------------------------------------------------
if (sph_system.RunParticleRelaxation())
{
//----------------------------------------------------------------------
// Define body relation map used for particle relaxation.
//----------------------------------------------------------------------
InnerRelation insert_body_inner(insert_body);
//----------------------------------------------------------------------
// Methods used for particle relaxation.
//----------------------------------------------------------------------
using namespace relax_dynamics;
SimpleDynamics<RandomizeParticlePosition> random_insert_body_particles(insert_body);
RelaxationStepInner relaxation_step_inner(insert_body_inner);
BodyStatesRecordingToVtp write_insert_body_to_vtp(insert_body);
ReloadParticleIO write_particle_reload_files(insert_body);
//----------------------------------------------------------------------
// Particle relaxation starts here.
//----------------------------------------------------------------------
random_insert_body_particles.exec(0.25);
relaxation_step_inner.SurfaceBounding().exec();
write_insert_body_to_vtp.writeToFile(0);
//----------------------------------------------------------------------
// Relax particles of the insert body.
//----------------------------------------------------------------------
int ite_p = 0;
while (ite_p < 1000)
{
relaxation_step_inner.exec();
ite_p += 1;
if (ite_p % 200 == 0)
{
std::cout << std::fixed << std::setprecision(9) << "Relaxation steps for the inserted body N = " << ite_p << "\n";
write_insert_body_to_vtp.writeToFile(ite_p);
}
}
std::cout << "The physics relaxation process of inserted body finish !" << std::endl;
/** Output results. */
write_particle_reload_files.writeToFile(0);
return 0;
}
//----------------------------------------------------------------------
// Define body relation map.
// The contact map gives the topological connections between the bodies.
// Basically the the range of bodies to build neighbor particle lists.
// Generally, we first define all the inner relations, then the contact relations.
//----------------------------------------------------------------------
InnerRelation water_block_inner(water_block);
InnerRelation insert_body_inner(insert_body);
ContactRelation water_block_contact(water_block, RealBodyVector{&wall_boundary, &insert_body});
ContactRelation insert_body_contact(insert_body, {&water_block});
ContactRelation beam_observer_contact(beam_observer, {&insert_body});
ContactRelation fluid_observer_contact(fluid_observer, {&water_block});
//----------------------------------------------------------------------
// Combined relations built from basic relations
// and only used for update configuration.
//----------------------------------------------------------------------
ComplexRelation water_block_complex(water_block_inner, water_block_contact);
//----------------------------------------------------------------------
// Define the numerical methods used in the simulation.
// Note that there may be data dependence on the sequence of constructions.
// Generally, the geometric models or simple objects without data dependencies,
// such as gravity, should be initiated first.
// Then the major physical particle dynamics model should be introduced.
// Finally, the auxillary models such as time step estimator, initial condition,
// boundary condition and other constraints should be defined.
// For typical fluid-structure interaction, we first define structure dynamics,
// Then fluid dynamics and the corresponding coupling dynamics.
// The coupling with multi-body dynamics will be introduced at last.
//----------------------------------------------------------------------
SimpleDynamics<NormalDirectionFromBodyShape> wall_boundary_normal_direction(wall_boundary);
SimpleDynamics<NormalDirectionFromBodyShape> insert_body_normal_direction(insert_body);
InteractionWithUpdate<LinearGradientCorrectionMatrixInner> insert_body_corrected_configuration(insert_body_inner);
Dynamics1Level<solid_dynamics::Integration1stHalfPK2> insert_body_stress_relaxation_first_half(insert_body_inner);
Dynamics1Level<solid_dynamics::Integration2ndHalf> insert_body_stress_relaxation_second_half(insert_body_inner);
ReduceDynamics<solid_dynamics::AcousticTimeStep> insert_body_computing_time_step_size(insert_body);
BodyRegionByParticle beam_base(insert_body, makeShared<MultiPolygonShape>(createBeamBaseShape()));
SimpleDynamics<FixBodyPartConstraint> constraint_beam_base(beam_base);
//----------------------------------------------------------------------
// Algorithms of fluid dynamics.
//----------------------------------------------------------------------
Dynamics1Level<fluid_dynamics::Integration1stHalfWithWallRiemann> pressure_relaxation(water_block_inner, water_block_contact);
Dynamics1Level<fluid_dynamics::Integration2ndHalfWithWallNoRiemann> density_relaxation(water_block_inner, water_block_contact);
InteractionWithUpdate<fluid_dynamics::DensitySummationComplex> update_density_by_summation(water_block_inner, water_block_contact);
InteractionWithUpdate<fluid_dynamics::TransportVelocityCorrectionComplex<AllParticles>> transport_correction(water_block_inner, water_block_contact);
InteractionWithUpdate<fluid_dynamics::ViscousForceWithWall> viscous_force(water_block_inner, water_block_contact);
ReduceDynamics<fluid_dynamics::AdvectionViscousTimeStep> get_fluid_advection_time_step_size(water_block, U_f);
ReduceDynamics<fluid_dynamics::AcousticTimeStep> get_fluid_time_step_size(water_block);
BodyAlignedBoxByCell inflow_buffer(water_block, makeShared<AlignedBoxShape>(xAxis, Transform(Vec2d(buffer_translation)), buffer_halfsize));
SimpleDynamics<fluid_dynamics::InflowVelocityCondition<InflowVelocity>> parabolic_inflow(inflow_buffer);
PeriodicAlongAxis periodic_along_x(water_block.getSPHBodyBounds(), xAxis);
PeriodicConditionUsingCellLinkedList periodic_condition(water_block, periodic_along_x);
InteractionDynamics<fluid_dynamics::VorticityInner> compute_vorticity(water_block_inner);
//----------------------------------------------------------------------
// Algorithms of FSI.
//----------------------------------------------------------------------
solid_dynamics::AverageVelocityAndAcceleration average_velocity_and_acceleration(insert_body);
SimpleDynamics<solid_dynamics::UpdateElasticNormalDirection> insert_body_update_normal(insert_body);
InteractionWithUpdate<solid_dynamics::ViscousForceFromFluid> viscous_force_from_fluid(insert_body_contact);
InteractionWithUpdate<solid_dynamics::PressureForceFromFluid<decltype(density_relaxation)>> pressure_force_from_fluid(insert_body_contact);
//----------------------------------------------------------------------
// Define the configuration related particles dynamics.
//----------------------------------------------------------------------
ParticleSorting particle_sorting(water_block);
//----------------------------------------------------------------------
// Define the methods for I/O operations and observations of the simulation.
//----------------------------------------------------------------------
BodyStatesRecordingToVtp write_real_body_states(sph_system);
RegressionTestTimeAverage<ReducedQuantityRecording<QuantitySummation<Vecd>>> write_total_viscous_force_from_fluid(insert_body, "ViscousForceFromFluid");
RegressionTestDynamicTimeWarping<ObservedQuantityRecording<Vecd>> write_beam_tip_displacement("Position", beam_observer_contact);
ObservedQuantityRecording<Vecd> write_fluid_velocity("Velocity", fluid_observer_contact);
//----------------------------------------------------------------------
// Prepare the simulation with cell linked list, configuration
// and case specified initial condition if necessary.
//----------------------------------------------------------------------
/** initialize cell linked lists for all bodies. */
sph_system.initializeSystemCellLinkedLists();
/** periodic condition applied after the mesh cell linked list build up
* but before the configuration build up. */
periodic_condition.update_cell_linked_list_.exec();
/** initialize configurations for all bodies. */
sph_system.initializeSystemConfigurations();
/** computing surface normal direction for the wall. */
wall_boundary_normal_direction.exec();
/** computing surface normal direction for the insert body. */
insert_body_normal_direction.exec();
/** computing linear reproducing configuration for the insert body. */
insert_body_corrected_configuration.exec();
//----------------------------------------------------------------------
// Setup for time-stepping control
//----------------------------------------------------------------------
Real &physical_time = *sph_system.getSystemVariableDataByName<Real>("PhysicalTime");
size_t number_of_iterations = 0;
int screen_output_interval = 100;
Real end_time = 200.0;
Real output_interval = end_time / 200.0;
//----------------------------------------------------------------------
// Statistics for CPU time
//----------------------------------------------------------------------
TickCount t1 = TickCount::now();
TimeInterval interval;
//----------------------------------------------------------------------
// First output before the main loop.
//----------------------------------------------------------------------
write_real_body_states.writeToFile();
write_beam_tip_displacement.writeToFile(number_of_iterations);
//----------------------------------------------------------------------
// Main loop starts here.
//----------------------------------------------------------------------
while (physical_time < end_time)
{
Real integration_time = 0.0;
/** Integrate time (loop) until the next output time. */
while (integration_time < output_interval)
{
Real Dt = get_fluid_advection_time_step_size.exec();
update_density_by_summation.exec();
viscous_force.exec();
transport_correction.exec();
/** FSI for viscous force. */
viscous_force_from_fluid.exec();
/** Update normal direction on elastic body.*/
insert_body_update_normal.exec();
size_t inner_ite_dt = 0;
size_t inner_ite_dt_s = 0;
Real relaxation_time = 0.0;
while (relaxation_time < Dt)
{
Real dt = SMIN(get_fluid_time_step_size.exec(), Dt);
/** Fluid pressure relaxation */
pressure_relaxation.exec(dt);
/** FSI for pressure force. */
pressure_force_from_fluid.exec();
/** Fluid density relaxation */
density_relaxation.exec(dt);
/** Solid dynamics. */
inner_ite_dt_s = 0;
Real dt_s_sum = 0.0;
average_velocity_and_acceleration.initialize_displacement_.exec();
while (dt_s_sum < dt)
{
Real dt_s = SMIN(insert_body_computing_time_step_size.exec(), dt - dt_s_sum);
insert_body_stress_relaxation_first_half.exec(dt_s);
constraint_beam_base.exec();
insert_body_stress_relaxation_second_half.exec(dt_s);
dt_s_sum += dt_s;
inner_ite_dt_s++;
}
average_velocity_and_acceleration.update_averages_.exec(dt);
relaxation_time += dt;
integration_time += dt;
physical_time += dt;
parabolic_inflow.exec();
inner_ite_dt++;
}
if (number_of_iterations % screen_output_interval == 0)
{
std::cout << std::fixed << std::setprecision(9) << "N=" << number_of_iterations << " Time = "
<< physical_time
<< " Dt = " << Dt << " Dt / dt = " << inner_ite_dt << " dt / dt_s = " << inner_ite_dt_s << "\n";
}
number_of_iterations++;
/** Water block configuration and periodic condition. */
periodic_condition.bounding_.exec();
if (number_of_iterations % 100 == 0 && number_of_iterations != 1)
{
particle_sorting.exec();
}
water_block.updateCellLinkedList();
periodic_condition.update_cell_linked_list_.exec();
water_block_complex.updateConfiguration();
/** one need update configuration after periodic condition. */
insert_body.updateCellLinkedList();
insert_body_contact.updateConfiguration();
/** write run-time observation into file */
write_beam_tip_displacement.writeToFile(number_of_iterations);
}
TickCount t2 = TickCount::now();
/** write run-time observation into file */
compute_vorticity.exec();
write_real_body_states.writeToFile();
write_total_viscous_force_from_fluid.writeToFile(number_of_iterations);
fluid_observer_contact.updateConfiguration();
write_fluid_velocity.writeToFile(number_of_iterations);
TickCount t3 = TickCount::now();
interval += t3 - t2;
}
TickCount t4 = TickCount::now();
TimeInterval tt;
tt = t4 - t1 - interval;
std::cout << "Total wall time for computation: " << tt.seconds() << " seconds." << std::endl;
if (sph_system.GenerateRegressionData())
{
// The lift force at the cylinder is very small and not important in this case.
write_total_viscous_force_from_fluid.generateDataBase({1.0e-2, 1.0e-2}, {1.0e-2, 1.0e-2});
write_beam_tip_displacement.generateDataBase(1.0e-2);
}
else
{
write_total_viscous_force_from_fluid.testResult();
write_beam_tip_displacement.testResult();
}
return 0;
}