-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
precice.cpp
718 lines (672 loc) · 31.7 KB
/
precice.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
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
/*!
* \file precice.cpp
* \brief Adapter class for coupling SU2 with preCICE for FSI.
* \author Alexander Rusch
*/
#include "../include/precice.hpp"
Precice::Precice(const string& preciceConfigurationFileName, const std::string& preciceParticipantName,
const std::string& preciceReadDataName_, const std::string& preciceWriteDataName_,
const std::string& preciceMeshName_, int solverProcessIndex, int solverProcessSize,
CGeometry*** geometry_container, CSolver**** solver_container, CConfig** config_container,
CVolumetricMovement** grid_movement)
: solverProcessIndex(solverProcessIndex),
solverProcessSize(solverProcessSize),
solverInterface(preciceParticipantName, preciceConfigurationFileName, solverProcessIndex, solverProcessSize),
nDim(geometry_container[ZONE_0][MESH_0]->GetnDim()),
geometry_container(geometry_container),
solver_container(solver_container),
config_container(config_container),
grid_movement(grid_movement),
vertexIDs(NULL),
forceID(NULL),
displDeltaID(NULL),
forces(NULL),
displacements(NULL),
displacements_n(NULL),
displacementDeltas(NULL),
// For implicit coupling
coric(precice::constants::actionReadIterationCheckpoint()),
cowic(precice::constants::actionWriteIterationCheckpoint()),
processWorkingOnWetSurface(true),
verbosityLevel_high(config_container[ZONE_0]->GetpreCICE_VerbosityLevel_High()),
globalNumberWetSurfaces(config_container[ZONE_0]->GetpreCICE_NumberWetSurfaces()),
localNumberWetSurfaces(0),
// Get value (= index) of the marker corresponding to the wet surface
// It is implied, that only one marker is used for the entire wet surface, even if it is split into parts
valueMarkerWet(NULL),
vertexSize(NULL),
indexMarkerWetMappingLocalToGlobal(NULL),
preciceReadDataName(preciceReadDataName_),
preciceWriteDataName(preciceWriteDataName_),
preciceMeshName(preciceMeshName_),
// Variables for implicit coupling
nPoint(geometry_container[ZONE_0][MESH_0]->GetnPoint()),
nVar(solver_container[ZONE_0][MESH_0][FLOW_SOL]->GetnVar()),
Coord_Saved(NULL),
Coord_n_Saved(NULL),
Coord_n1_Saved(NULL),
Coord_p1_Saved(NULL),
GridVel_Saved(NULL),
GridVel_Grad_Saved(NULL),
dt_savedState(0),
StopCalc_savedState(false),
solution_Saved(NULL),
solution_time_n_Saved(NULL),
solution_time_n1_Saved(NULL) {
if (preciceReadDataName.find("Delta") == std::string::npos)
readDataType = ReadDataType::Displacement;
else
readDataType = ReadDataType::DisplacementDelta;
Coord_Saved = new double*[nPoint];
Coord_n_Saved = new double*[nPoint];
Coord_n1_Saved = new double*[nPoint];
Coord_p1_Saved = new double*[nPoint];
GridVel_Saved = new double*[nPoint];
GridVel_Grad_Saved = new double**[nPoint];
solution_Saved = new double*[nPoint];
solution_time_n_Saved = new double*[nPoint];
solution_time_n1_Saved = new double*[nPoint];
for (int iPoint = 0; iPoint < nPoint; iPoint++) {
Coord_Saved[iPoint] = new double[nDim];
Coord_n_Saved[iPoint] = new double[nDim];
Coord_n1_Saved[iPoint] = new double[nDim];
Coord_p1_Saved[iPoint] = new double[nDim];
GridVel_Saved[iPoint] = new double[nDim];
GridVel_Grad_Saved[iPoint] = new double*[nDim];
for (int iDim = 0; iDim < nDim; iDim++) {
GridVel_Grad_Saved[iPoint][iDim] = new double[nDim];
}
solution_Saved[iPoint] = new double[nVar];
solution_time_n_Saved[iPoint] = new double[nVar];
solution_time_n1_Saved[iPoint] = new double[nVar];
}
}
Precice::~Precice(void) {
for (int i = 0; i < localNumberWetSurfaces; i++) {
if (vertexIDs[i] != NULL) {
delete[] vertexIDs[i];
}
}
if (vertexIDs != NULL) {
delete[] vertexIDs;
}
if (forceID != NULL) {
delete[] forceID;
}
if (displDeltaID != NULL) {
delete[] displDeltaID;
}
if (valueMarkerWet != NULL) {
delete[] valueMarkerWet;
}
if (vertexSize != NULL) {
delete[] vertexSize;
}
if (indexMarkerWetMappingLocalToGlobal != NULL) {
delete[] indexMarkerWetMappingLocalToGlobal;
}
for (int iPoint = 0; iPoint < nPoint; iPoint++) {
if (Coord_Saved[iPoint] != NULL) {
delete[] Coord_Saved[iPoint];
}
if (Coord_n_Saved[iPoint] != NULL) {
delete[] Coord_n_Saved[iPoint];
}
if (Coord_n1_Saved[iPoint] != NULL) {
delete[] Coord_n1_Saved[iPoint];
}
if (Coord_p1_Saved[iPoint] != NULL) {
delete[] Coord_p1_Saved[iPoint];
}
if (GridVel_Saved[iPoint] != NULL) {
delete[] GridVel_Saved[iPoint];
}
for (int iDim = 0; iDim < nDim; iDim++) {
if (GridVel_Grad_Saved[iPoint][iDim] != NULL) {
delete[] GridVel_Grad_Saved[iPoint][iDim];
}
}
if (GridVel_Grad_Saved[iPoint] != NULL) {
delete[] GridVel_Grad_Saved[iPoint];
}
if (solution_Saved[iPoint] != NULL) {
delete[] solution_Saved[iPoint];
}
if (solution_time_n_Saved[iPoint] != NULL) {
delete[] solution_time_n_Saved[iPoint];
}
if (solution_time_n1_Saved[iPoint] != NULL) {
delete[] solution_time_n1_Saved[iPoint];
}
}
if (Coord_Saved != NULL) {
delete[] Coord_Saved;
}
if (Coord_n_Saved != NULL) {
delete[] Coord_n_Saved;
}
if (Coord_n1_Saved != NULL) {
delete[] Coord_n1_Saved;
}
if (Coord_p1_Saved != NULL) {
delete[] Coord_p1_Saved;
}
if (GridVel_Saved != NULL) {
delete[] GridVel_Saved;
}
if (GridVel_Grad_Saved != NULL) {
delete[] GridVel_Grad_Saved;
}
if (solution_Saved != NULL) {
delete[] solution_Saved;
}
if (solution_time_n_Saved != NULL) {
delete[] solution_time_n_Saved;
}
if (solution_time_n1_Saved != NULL) {
delete[] solution_time_n1_Saved;
}
if (displacements_n != NULL) {
delete[] displacements_n;
}
}
double Precice::initialize() {
if (verbosityLevel_high) {
cout << "Process #" << solverProcessIndex << "/" << solverProcessSize - 1 << ": Initializing preCICE..." << endl;
}
// Checking for dimensional consistency of SU2 and preCICE - Exit if not consistent
if (solverInterface.getDimensions() != geometry_container[ZONE_0][MESH_0]->GetnDim()) {
cout << "Dimensions of SU2 and preCICE are not equal! Now exiting..." << endl;
exit(EXIT_FAILURE);
}
int* meshID;
// Checking for number of wet surfaces - Exit if not cat least one wet surface defined
if (globalNumberWetSurfaces < 1) {
cout << "There must be at least one wet surface! Now exiting..." << endl;
exit(EXIT_FAILURE);
} else {
meshID = new int[globalNumberWetSurfaces];
forceID = new int[globalNumberWetSurfaces];
displDeltaID = new int[globalNumberWetSurfaces];
for (int i = 0; i < globalNumberWetSurfaces; i++) {
// Get preCICE meshIDs
meshID[i] = solverInterface.getMeshID(preciceMeshName + (i == 0 ? "" : to_string(i)));
}
}
// Determine the number of wet surfaces, that this process is working on, then loop over this number for all
// respective preCICE-related tasks
for (int i = 0; i < globalNumberWetSurfaces; i++) {
if (config_container[ZONE_0]->GetMarker_All_TagBound(config_container[ZONE_0]->GetpreCICE_WetSurfaceMarkerName() +
(i == 0 ? "" : to_string(i))) == -1) {
cout << "Process #" << solverProcessIndex << "/" << solverProcessSize - 1 << ": Does not work on "
<< config_container[ZONE_0]->GetpreCICE_WetSurfaceMarkerName() << (i == 0 ? "" : to_string(i)) << endl;
} else {
localNumberWetSurfaces++;
}
}
if (localNumberWetSurfaces < 1) {
cout << "Process #" << solverProcessIndex << "/" << solverProcessSize - 1
<< ": Does not work on the wet surface at all." << endl;
processWorkingOnWetSurface = false;
}
if (processWorkingOnWetSurface) {
// Store the wet surface marker values in an array, which has the size equal to the number of wet surfaces actually
// being worked on by this process
valueMarkerWet = new short[localNumberWetSurfaces];
indexMarkerWetMappingLocalToGlobal = new short[localNumberWetSurfaces];
int j = 0;
for (int i = 0; i < globalNumberWetSurfaces; i++) {
if (config_container[ZONE_0]->GetMarker_All_TagBound(config_container[ZONE_0]->GetpreCICE_WetSurfaceMarkerName() +
(i == 0 ? "" : to_string(i))) != -1) {
valueMarkerWet[j] = config_container[ZONE_0]->GetMarker_All_TagBound(
config_container[ZONE_0]->GetpreCICE_WetSurfaceMarkerName() + (i == 0 ? "" : to_string(i)));
indexMarkerWetMappingLocalToGlobal[j] = i;
j++;
}
}
vertexIDs = new int*[localNumberWetSurfaces];
}
if (processWorkingOnWetSurface) {
vertexSize = new unsigned long[localNumberWetSurfaces];
for (int i = 0; i < localNumberWetSurfaces; i++) {
vertexSize[i] = geometry_container[ZONE_0][MESH_0]->nVertex[valueMarkerWet[i]];
double coupleNodeCoord[vertexSize[i]][nDim]; /*--- coordinates of all nodes at the wet surface ---*/
unsigned long iNode; /*--- variable for storing the node indices - one at the time ---*/
// Loop over the vertices of the (each) boundary
for (int iVertex = 0; iVertex < vertexSize[i]; iVertex++) {
// Get node number (= index) to vertex (= node)
iNode = geometry_container[ZONE_0][MESH_0]->vertex[valueMarkerWet[i]][iVertex]->GetNode();
// Get coordinates for nodes
for (int iDim = 0; iDim < nDim; iDim++) {
coupleNodeCoord[iVertex][iDim] = geometry_container[ZONE_0][MESH_0]->node[iNode]->GetCoord(iDim);
if (verbosityLevel_high) {
cout << "Process #" << solverProcessIndex << "/" << solverProcessSize - 1
<< ": Initial coordinates of node (local index, global index, node color): (" << iVertex << ", "
<< iNode << ", " << geometry_container[ZONE_0][MESH_0]->node[iNode]->GetColor()
<< "): " << coupleNodeCoord[iVertex][iDim] << endl; /*--- for debugging purposes ---*/
}
}
}
// preCICE conform the coordinates of vertices (= points = nodes) at wet surface
double coords[vertexSize[i] * nDim];
for (int iVertex = 0; iVertex < vertexSize[i]; iVertex++) {
for (int iDim = 0; iDim < nDim; iDim++) {
coords[iVertex * nDim + iDim] = coupleNodeCoord[iVertex][iDim];
}
}
// preCICE internal
vertexIDs[i] = new int[vertexSize[i]];
solverInterface.setMeshVertices(meshID[indexMarkerWetMappingLocalToGlobal[i]], vertexSize[i], coords,
vertexIDs[i]);
forceID[indexMarkerWetMappingLocalToGlobal[i]] = solverInterface.getDataID(
preciceWriteDataName +
(indexMarkerWetMappingLocalToGlobal[i] == 0 ? "" : to_string(indexMarkerWetMappingLocalToGlobal[i])),
meshID[indexMarkerWetMappingLocalToGlobal[i]]);
displDeltaID[indexMarkerWetMappingLocalToGlobal[i]] = solverInterface.getDataID(
preciceReadDataName +
(indexMarkerWetMappingLocalToGlobal[i] == 0 ? "" : to_string(indexMarkerWetMappingLocalToGlobal[i])),
meshID[indexMarkerWetMappingLocalToGlobal[i]]);
if (readDataType == ReadDataType::Displacement) {
displacements_n = new double[vertexSize[i] * nDim];
for (int iVertex = 0; iVertex < vertexSize[i]; iVertex++) {
for (int iDim = 0; iDim < nDim; iDim++) {
displacements_n[iVertex * nDim + iDim] = 0; // Init with zeros
}
}
}
}
for (int i = 0; i < globalNumberWetSurfaces; i++) {
bool flag = false;
for (int j = 0; j < localNumberWetSurfaces; j++) {
if (indexMarkerWetMappingLocalToGlobal[j] == i) {
flag = true;
}
}
if (!flag) {
solverInterface.setMeshVertices(meshID[i], 0, NULL, NULL);
forceID[i] = solverInterface.getDataID(preciceWriteDataName + (i == 0 ? "" : to_string(i)), meshID[i]);
displDeltaID[i] = solverInterface.getDataID(preciceReadDataName + (i == 0 ? "" : to_string(i)), meshID[i]);
}
}
} else {
for (int i = 0; i < globalNumberWetSurfaces; i++) {
solverInterface.setMeshVertices(meshID[i], 0, NULL, NULL);
forceID[i] = solverInterface.getDataID(preciceWriteDataName + (i == 0 ? "" : to_string(i)), meshID[i]);
displDeltaID[i] = solverInterface.getDataID(preciceReadDataName + (i == 0 ? "" : to_string(i)), meshID[i]);
}
}
if (verbosityLevel_high) {
cout << "Process #" << solverProcessIndex << "/" << solverProcessSize - 1
<< ": There is grid movement (expected: 1): " << config_container[ZONE_0]->GetGrid_Movement()
<< endl; /*--- for debugging purposes ---*/
cout << "Process #" << solverProcessIndex << "/" << solverProcessSize - 1
<< ": Kind of grid movement (expected: 13): " << config_container[ZONE_0]->GetKind_GridMovement(ZONE_0)
<< endl; /*--- for debugging purposes ---*/
}
double precice_dt; /*--- preCICE timestep size ---*/
precice_dt = solverInterface.initialize();
if (verbosityLevel_high) {
cout << "Process #" << solverProcessIndex << "/" << solverProcessSize - 1 << ": ...done initializing preCICE!"
<< endl;
}
if (meshID != NULL) {
delete[] meshID;
}
return precice_dt;
}
double Precice::advance(double computedTimestepLength) {
if (processWorkingOnWetSurface) {
if (verbosityLevel_high) {
cout << "Process #" << solverProcessIndex << "/" << solverProcessSize - 1 << ": Advancing preCICE..." << endl;
}
// Get physical simulation information
bool incompressible = (config_container[ZONE_0]->GetKind_Regime() == INCOMPRESSIBLE);
bool viscous_flow = ((config_container[ZONE_0]->GetKind_Solver() == NAVIER_STOKES) ||
(config_container[ZONE_0]->GetKind_Solver() == RANS));
// Compute factorForces for redimensionalizing forces ("ND" = Non-Dimensional)
double* Velocity_Real = config_container[ZONE_0]->GetVelocity_FreeStream();
double Density_Real = config_container[ZONE_0]->GetDensity_FreeStream();
double* Velocity_ND = config_container[ZONE_0]->GetVelocity_FreeStreamND();
double Density_ND = config_container[ZONE_0]->GetDensity_FreeStreamND();
double Velocity2_Real = 0.0; /*--- denotes squared real velocity ---*/
double Velocity2_ND = 0.0; /*--- denotes squared non-dimensional velocity ---*/
// Compute squared values
for (int iDim = 0; iDim < nDim; iDim++) {
Velocity2_Real += Velocity_Real[iDim] * Velocity_Real[iDim];
Velocity2_ND += Velocity_ND[iDim] * Velocity_ND[iDim];
}
// Compute factor for redimensionalizing forces
double factorForces = Density_Real * Velocity2_Real / (Density_ND * Velocity2_ND);
if (verbosityLevel_high) {
cout << "Process #" << solverProcessIndex << "/" << solverProcessSize - 1
<< ": Factor for (non-/re-)dimensionalization of forces: " << factorForces
<< endl; /*--- for debugging purposes ---*/
}
for (int i = 0; i < localNumberWetSurfaces; i++) {
if (verbosityLevel_high) {
// 1. Compute forces
cout << "Process #" << solverProcessIndex << "/" << solverProcessSize - 1
<< ": Advancing preCICE: Computing forces for "
<< config_container[ZONE_0]->GetpreCICE_WetSurfaceMarkerName() << indexMarkerWetMappingLocalToGlobal[i]
<< "..." << endl;
}
// Some variables to be used:
unsigned long nodeVertex[vertexSize[i]];
double normalsVertex[vertexSize[i]][nDim];
double normalsVertex_Unit[vertexSize[i]][nDim];
double Area;
double Pn = 0.0; /*--- denotes pressure at a node ---*/
double Pinf = 0.0; /*--- denotes environmental (farfield) pressure ---*/
double** Grad_PrimVar =
NULL; /*--- denotes (u.A. velocity) gradients needed for computation of viscous forces ---*/
double Viscosity = 0.0;
double Tau[3][3];
double TauElem[3];
double forces_su2[vertexSize[i]][nDim]; /*--- forces will be stored such, before converting to simple array ---*/
/*--- Loop over vertices of coupled boundary ---*/
for (int iVertex = 0; iVertex < vertexSize[i]; iVertex++) {
// Get node number (= index) to vertex (= node)
nodeVertex[iVertex] = geometry_container[ZONE_0][MESH_0]
->vertex[valueMarkerWet[i]][iVertex]
->GetNode(); /*--- Store all nodes (indices) in a vector ---*/
// Get normal vector
for (int iDim = 0; iDim < nDim; iDim++) {
normalsVertex[iVertex][iDim] =
(geometry_container[ZONE_0][MESH_0]->vertex[valueMarkerWet[i]][iVertex]->GetNormal())[iDim];
}
// Unit normals
Area = 0.0;
for (int iDim = 0; iDim < nDim; iDim++) {
Area += normalsVertex[iVertex][iDim] * normalsVertex[iVertex][iDim];
}
Area = sqrt(Area);
for (int iDim = 0; iDim < nDim; iDim++) {
normalsVertex_Unit[iVertex][iDim] = normalsVertex[iVertex][iDim] / Area;
}
// Get the values of pressure and viscosity
Pn = solver_container[ZONE_0][MESH_0][FLOW_SOL]->node[nodeVertex[iVertex]]->GetPressure();
Pinf = solver_container[ZONE_0][MESH_0][FLOW_SOL]->GetPressure_Inf();
if (viscous_flow) {
Grad_PrimVar = solver_container[ZONE_0][MESH_0][FLOW_SOL]->node[nodeVertex[iVertex]]->GetGradient_Primitive();
Viscosity = solver_container[ZONE_0][MESH_0][FLOW_SOL]->node[nodeVertex[iVertex]]->GetLaminarViscosity();
}
// Calculate the forces_su2 in the nodes for the inviscid term --> Units of force (non-dimensional).
for (int iDim = 0; iDim < nDim; iDim++) {
forces_su2[iVertex][iDim] = -(Pn - Pinf) * normalsVertex[iVertex][iDim];
}
// Calculate the forces_su2 in the nodes for the viscous term
if (viscous_flow) {
// Divergence of the velocity
double div_vel = 0.0;
for (int iDim = 0; iDim < nDim; iDim++) {
div_vel += Grad_PrimVar[iDim + 1][iDim];
}
if (incompressible) {
div_vel = 0.0; /*--- incompressible flow is divergence-free ---*/
}
for (int iDim = 0; iDim < nDim; iDim++) {
for (int jDim = 0; jDim < nDim; jDim++) {
// Dirac delta
double Delta = 0.0;
if (iDim == jDim) {
Delta = 1.0;
}
// Viscous stress
Tau[iDim][jDim] = Viscosity * (Grad_PrimVar[jDim + 1][iDim] + Grad_PrimVar[iDim + 1][jDim]) -
2 / 3 * Viscosity * div_vel * Delta;
// Add Viscous component in the forces_su2 vector --> Units of force (non-dimensional).
forces_su2[iVertex][iDim] += Tau[iDim][jDim] * normalsVertex[iVertex][jDim];
}
}
}
// Rescale forces_su2 to SI units
for (int iDim = 0; iDim < nDim; iDim++) {
forces_su2[iVertex][iDim] = forces_su2[iVertex][iDim] * factorForces;
}
}
// convert forces_su2 into forces
forces = new double[vertexSize[i] * nDim];
for (int iVertex = 0; iVertex < vertexSize[i]; iVertex++) {
for (int iDim = 0; iDim < nDim; iDim++) {
// Do not write forces for duplicate nodes! -> Check wether the color of the node matches the MPI-rank of this
// process. Only write forces, if node originally belongs to this process.
if (geometry_container[ZONE_0][MESH_0]->node[nodeVertex[iVertex]]->GetColor() == solverProcessIndex) {
forces[iVertex * nDim + iDim] = forces_su2[iVertex][iDim];
} else {
forces[iVertex * nDim + iDim] = 0;
}
}
}
if (verbosityLevel_high) {
cout << "Process #" << solverProcessIndex << "/" << solverProcessSize - 1
<< ": Advancing preCICE: ...done computing forces for "
<< config_container[ZONE_0]->GetpreCICE_WetSurfaceMarkerName() << indexMarkerWetMappingLocalToGlobal[i]
<< endl;
}
// 2. Write forces
if (verbosityLevel_high) {
cout << "Process #" << solverProcessIndex << "/" << solverProcessSize - 1
<< ": Advancing preCICE: Writing forces for "
<< config_container[ZONE_0]->GetpreCICE_WetSurfaceMarkerName() << indexMarkerWetMappingLocalToGlobal[i]
<< "..." << endl;
}
// Load Ramping functionality: Reduce force vector before transferring by a ramping factor, which increases with
// the number of elapsed time steps; Achtung: ExtIter beginnt bei 0 (ohne Restart) und bei einem Restart
// (Startlösung) nicht bei 0, sondern bei der Startiterationsnummer
if (config_container[ZONE_0]->GetpreCICE_LoadRamping() &&
((config_container[ZONE_0]->GetExtIter() - config_container[ZONE_0]->GetUnst_RestartIter()) <
config_container[ZONE_0]->GetpreCICE_LoadRampingDuration())) {
if (verbosityLevel_high) {
cout << "Process #" << solverProcessIndex << "/" << solverProcessSize - 1
<< ": Load ramping factor in preCICE: "
<< config_container[ZONE_0]->GetExtIter() - config_container[ZONE_0]->GetUnst_RestartIter() + 1 << "/"
<< config_container[ZONE_0]->GetpreCICE_LoadRampingDuration() << endl;
}
*forces = *forces *
((config_container[ZONE_0]->GetExtIter() - config_container[ZONE_0]->GetUnst_RestartIter()) + 1) /
config_container[ZONE_0]->GetpreCICE_LoadRampingDuration();
}
solverInterface.writeBlockVectorData(forceID[indexMarkerWetMappingLocalToGlobal[i]], vertexSize[i], vertexIDs[i],
forces);
if (verbosityLevel_high) {
cout << "Process #" << solverProcessIndex << "/" << solverProcessSize - 1
<< ": Advancing preCICE: ...done writing forces for "
<< config_container[ZONE_0]->GetpreCICE_WetSurfaceMarkerName() << indexMarkerWetMappingLocalToGlobal[i]
<< "." << endl;
}
if (forces != NULL) {
delete[] forces;
}
}
// 3. Advance solverInterface
if (verbosityLevel_high) {
cout << "Process #" << solverProcessIndex << "/" << solverProcessSize - 1
<< ": Advancing preCICE: Advancing SolverInterface..." << endl;
}
double max_precice_dt;
max_precice_dt = solverInterface.advance(computedTimestepLength);
if (verbosityLevel_high) {
cout << "Process #" << solverProcessIndex << "/" << solverProcessSize - 1
<< ": Advancing preCICE: ...done advancing SolverInterface." << endl;
}
// displacements = new double[vertexSize*nDim]; //TODO: Delete later
for (int i = 0; i < localNumberWetSurfaces; i++) {
// 4. Read displacements/displacementDeltas
if (verbosityLevel_high) {
cout << "Process #" << solverProcessIndex << "/" << solverProcessSize - 1
<< ": Advancing preCICE: Reading displacement deltas for "
<< config_container[ZONE_0]->GetpreCICE_WetSurfaceMarkerName() << indexMarkerWetMappingLocalToGlobal[i]
<< "..." << endl;
}
double displacementDeltas_su2[vertexSize[i]][nDim]; /*--- displacementDeltas will be stored such, before
converting to simple array ---*/
switch (readDataType) {
case ReadDataType::DisplacementDelta: {
displacementDeltas = new double[vertexSize[i] * nDim];
solverInterface.readBlockVectorData(displDeltaID[indexMarkerWetMappingLocalToGlobal[i]], vertexSize[i],
vertexIDs[i], displacementDeltas);
break;
}
case ReadDataType::Displacement: {
displacements = new double[vertexSize[i] * nDim];
solverInterface.readBlockVectorData(displDeltaID[indexMarkerWetMappingLocalToGlobal[i]], vertexSize[i],
vertexIDs[i], displacements);
break;
}
default:
assert(false);
}
if (verbosityLevel_high) {
cout << "Process #" << solverProcessIndex << "/" << solverProcessSize - 1
<< ": Advancing preCICE: ...done reading displacement deltas for "
<< config_container[ZONE_0]->GetpreCICE_WetSurfaceMarkerName() << indexMarkerWetMappingLocalToGlobal[i]
<< "." << endl;
}
// 5. Set displacements/displacementDeltas
if (verbosityLevel_high) {
cout << "Process #" << solverProcessIndex << "/" << solverProcessSize - 1
<< ": Advancing preCICE: Setting displacement deltas for "
<< config_container[ZONE_0]->GetpreCICE_WetSurfaceMarkerName() << indexMarkerWetMappingLocalToGlobal[i]
<< "..." << endl;
}
// convert displacementDeltas into displacementDeltas_su2
switch (readDataType) {
case ReadDataType::DisplacementDelta: {
// convert displacementDeltas into displacementDeltas_su2
for (int iVertex = 0; iVertex < vertexSize[i]; iVertex++) {
for (int iDim = 0; iDim < nDim; iDim++) {
displacementDeltas_su2[iVertex][iDim] = displacementDeltas[iVertex * nDim + iDim];
}
}
break;
}
case ReadDataType::Displacement: {
for (int iVertex = 0; iVertex < vertexSize[i]; iVertex++) {
for (int iDim = 0; iDim < nDim; iDim++) {
displacementDeltas_su2[iVertex][iDim] =
displacements[iVertex * nDim + iDim] - displacements_n[iVertex * nDim + iDim];
if (solverInterface.isTimeWindowComplete()) {
displacements_n[iVertex * nDim + iDim] = displacements[iVertex * nDim + iDim];
}
}
}
break;
}
default:
assert(false);
}
if (displacementDeltas != NULL) {
delete[] displacementDeltas;
}
if (displacements != NULL) {
delete[] displacements;
}
// Set change of coordinates (i.e. displacementDeltas)
for (int iVertex = 0; iVertex < vertexSize[i]; iVertex++) {
geometry_container[ZONE_0][MESH_0]->vertex[valueMarkerWet[i]][iVertex]->SetVarCoord(
displacementDeltas_su2[iVertex]);
}
if (verbosityLevel_high) {
cout << "Process #" << solverProcessIndex << "/" << solverProcessSize - 1
<< ": Advancing preCICE: ...done setting displacement deltas for "
<< config_container[ZONE_0]->GetpreCICE_WetSurfaceMarkerName() << indexMarkerWetMappingLocalToGlobal[i]
<< "." << endl;
}
}
if (verbosityLevel_high) {
cout << "Process #" << solverProcessIndex << "/" << solverProcessSize - 1 << ": ...done advancing preCICE!"
<< endl;
}
return max_precice_dt;
} else {
if (verbosityLevel_high) {
cout << "Process #" << solverProcessIndex << "/" << solverProcessSize - 1 << ": Advancing preCICE..." << endl;
}
// 3. Advance solverInterface
if (verbosityLevel_high) {
cout << "Process #" << solverProcessIndex << "/" << solverProcessSize - 1
<< ": Advancing preCICE: Advancing SolverInterface..." << endl;
}
double max_precice_dt;
max_precice_dt = solverInterface.advance(computedTimestepLength);
if (verbosityLevel_high) {
cout << "Process #" << solverProcessIndex << "/" << solverProcessSize - 1
<< ": Advancing preCICE: ...done advancing SolverInterface." << endl;
cout << "Process #" << solverProcessIndex << "/" << solverProcessSize - 1 << ": ...done advancing preCICE!"
<< endl;
}
return max_precice_dt;
}
}
bool Precice::isCouplingOngoing() { return solverInterface.isCouplingOngoing(); }
bool Precice::isActionRequired(const string& action) { return solverInterface.isActionRequired(action); }
const string& Precice::getCowic() { return cowic; }
const string& Precice::getCoric() { return coric; }
void Precice::saveOldState(bool* StopCalc, double* dt) {
for (int iPoint = 0; iPoint < nPoint; iPoint++) {
for (int iVar = 0; iVar < nVar; iVar++) {
// Save solutions at last and current time step
solution_Saved[iPoint][iVar] = (solver_container[ZONE_0][MESH_0][FLOW_SOL]->node[iPoint]->GetSolution())[iVar];
solution_time_n_Saved[iPoint][iVar] =
(solver_container[ZONE_0][MESH_0][FLOW_SOL]->node[iPoint]->GetSolution_time_n())[iVar];
solution_time_n1_Saved[iPoint][iVar] =
(solver_container[ZONE_0][MESH_0][FLOW_SOL]->node[iPoint]->GetSolution_time_n1())[iVar];
}
for (int iDim = 0; iDim < nDim; iDim++) {
// Save coordinates at last, current and next time step
Coord_Saved[iPoint][iDim] = (geometry_container[ZONE_0][MESH_0]->node[iPoint]->GetCoord())[iDim];
Coord_n_Saved[iPoint][iDim] = (geometry_container[ZONE_0][MESH_0]->node[iPoint]->GetCoord_n())[iDim];
Coord_n1_Saved[iPoint][iDim] = (geometry_container[ZONE_0][MESH_0]->node[iPoint]->GetCoord_n1())[iDim];
Coord_p1_Saved[iPoint][iDim] = (geometry_container[ZONE_0][MESH_0]->node[iPoint]->GetCoord_p1())[iDim];
// Save grid velocity
GridVel_Saved[iPoint][iDim] = (geometry_container[ZONE_0][MESH_0]->node[iPoint]->GetGridVel())[iDim];
for (int jDim = 0; jDim < nDim; jDim++) {
// Save grid velocity gradient
GridVel_Grad_Saved[iPoint][iDim][jDim] =
(geometry_container[ZONE_0][MESH_0]->node[iPoint]->GetGridVel_Grad())[iDim][jDim];
}
}
}
// Save wether simulation should be stopped after the current iteration
StopCalc_savedState = *StopCalc;
// Save the time step size
dt_savedState = *dt;
// Writing task has been fulfilled successfully
solverInterface.markActionFulfilled(cowic);
}
void Precice::reloadOldState(bool* StopCalc, double* dt) {
for (int iPoint = 0; iPoint < nPoint; iPoint++) {
// Reload solutions at last and current time step
solver_container[ZONE_0][MESH_0][FLOW_SOL]->node[iPoint]->SetSolution(solution_Saved[iPoint]);
solver_container[ZONE_0][MESH_0][FLOW_SOL]->node[iPoint]->Set_Solution_time_n(solution_time_n_Saved[iPoint]);
solver_container[ZONE_0][MESH_0][FLOW_SOL]->node[iPoint]->Set_Solution_time_n1(solution_time_n1_Saved[iPoint]);
// Reload coordinates at last, current and next time step
geometry_container[ZONE_0][MESH_0]->node[iPoint]->SetCoord(Coord_n1_Saved[iPoint]);
geometry_container[ZONE_0][MESH_0]->node[iPoint]->SetCoord_n();
geometry_container[ZONE_0][MESH_0]->node[iPoint]->SetCoord_n1();
geometry_container[ZONE_0][MESH_0]->node[iPoint]->SetCoord(Coord_n_Saved[iPoint]);
geometry_container[ZONE_0][MESH_0]->node[iPoint]->SetCoord_n();
geometry_container[ZONE_0][MESH_0]->node[iPoint]->SetCoord_p1(Coord_p1_Saved[iPoint]);
geometry_container[ZONE_0][MESH_0]->node[iPoint]->SetCoord(Coord_Saved[iPoint]);
// Reload grid velocity
geometry_container[ZONE_0][MESH_0]->node[iPoint]->SetGridVel(GridVel_Saved[iPoint]);
// Reload grid velocity gradient
for (int iDim = 0; iDim < nDim; iDim++) {
for (int jDim = 0; jDim < nDim; jDim++) {
geometry_container[ZONE_0][MESH_0]->node[iPoint]->SetGridVel_Grad(iDim, jDim,
GridVel_Grad_Saved[iPoint][iDim][jDim]);
}
}
}
// Reload wether simulation should be stopped after current iteration
*StopCalc = StopCalc_savedState;
// Reload the time step size
*dt = dt_savedState;
// Reading task has been fulfilled successfully
solverInterface.markActionFulfilled(coric);
}
void Precice::finalize() {
cout << "Process #" << solverProcessIndex << "/" << solverProcessSize - 1 << ": Finalizing preCICE..." << endl;
solverInterface.finalize();
cout << "Process #" << solverProcessIndex << "/" << solverProcessSize - 1 << ": Done finalizing preCICE!" << endl;
}