-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTurbulentKepsSimulation.cpp
147 lines (114 loc) · 4.92 KB
/
TurbulentKepsSimulation.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
#include "TurbulentKepsSimulation.h"
#include "stencils/WallDistanceStencil.h"
TurbulentKepsSimulation::TurbulentKepsSimulation(Parameters ¶meters, TurbulentFlowField &flowField):
Simulation(parameters, flowField),
_turbulentFlowField(flowField),
_turbulentFghStencil(parameters),
_turbulentFghIterator(_turbulentFlowField, parameters, _turbulentFghStencil),
_turbulentViscosityStencil(parameters),
_turbulentViscosityIterator(_turbulentFlowField, parameters, _turbulentViscosityStencil, 1, 0),
_turbulentKepsStencil(parameters),
_turbulentKepsIterator(_turbulentFlowField, parameters, _turbulentKepsStencil, 1, 0),
_turbulentVtkStencil(parameters),
_turbulentVtkIterator(_turbulentFlowField, parameters, _turbulentVtkStencil, 1, 0),
_kepsBoundaryStencil(parameters),
_kepsBoundaryIterator(_turbulentFlowField, parameters, _kepsBoundaryStencil, 1, 0),
_maxNuStencil(parameters),
_maxNuFieldIterator(_turbulentFlowField,parameters,_maxNuStencil),
_maxNuBoundaryIterator(_turbulentFlowField,parameters,_maxNuStencil),
_fmuStencil(parameters),
_fmuIterator(_turbulentFlowField, parameters,_fmuStencil,1,0),
_parallelManagerTurbulent(_turbulentFlowField, parameters)
{
}
void TurbulentKepsSimulation::solveTimestep(){
// determine and set max. timestep which is allowed in this simulation
setTimeStep();
// compute k, eps, and viscosity
_fmuIterator.iterate();
_kepsBoundaryIterator.iterate();
_turbulentKepsIterator.iterate();
_turbulentFlowField.swapKeps();
_kepsBoundaryIterator.iterate();
_fmuIterator.iterate();
_turbulentViscosityIterator.iterate();
//_parallelManagerTurbulent.communicateViscosity();
// compute fgh
_turbulentFghIterator.iterate();
_wallFGHIterator.iterate();
// compute the right hand side
_rhsIterator.iterate();
// solve for pressure
_solver.solve();
// communicate pressure values
_parallelManagerTurbulent.communicatePressure();
// compute velocity
_velocityIterator.iterate();
// communicate velocity values
_parallelManagerTurbulent.communicateVelocity();
// Iterate for velocities on the boundary
_wallVelocityIterator.iterate();
// set obstacle boundaries
_obstacleIterator.iterate();
}
void TurbulentKepsSimulation::setTimeStep(){
const FLOAT cinematicviscosity=1.0/_parameters.flow.Re;
FLOAT localMin, globalMin;
assertion(_parameters.geometry.dim == 2 || _parameters.geometry.dim == 3);
FLOAT factor = 1.0/(_parameters.meshsize->getDxMin() * _parameters.meshsize->getDxMin()) +
1.0/(_parameters.meshsize->getDyMin() * _parameters.meshsize->getDyMin());
// determine maximum velocity
_maxUStencil.reset();
_maxUFieldIterator.iterate();
_maxUBoundaryIterator.iterate();
_maxNuStencil.reset();
_maxNuFieldIterator.iterate();
_maxNuBoundaryIterator.iterate();
if (_parameters.geometry.dim == 3) {
factor += 1.0/(_parameters.meshsize->getDzMin() * _parameters.meshsize->getDzMin());
_parameters.timestep.dt = 1.0 / _maxUStencil.getMaxValues()[2];
} else {
_parameters.timestep.dt = 1.0 / _maxUStencil.getMaxValues()[0];
}
localMin = std::min(_parameters.timestep.dt,
std::min(std::min(1.0/_maxNuStencil.getMaxValue(),
1.0 / _maxUStencil.getMaxValues()[0]),
1.0 / _maxUStencil.getMaxValues()[1]));
// Here, we select the type of operation before compiling. This allows to use the correct
// data type for MPI. Not a concern for small simulations, but useful if using heterogeneous
// machines.
globalMin = MY_FLOAT_MAX;
MPI_Allreduce(&localMin, &globalMin, 1, MY_MPI_FLOAT, MPI_MIN, PETSC_COMM_WORLD);
_parameters.timestep.dt = globalMin;
_parameters.timestep.dt *= _parameters.timestep.tau;
// To be moved to somewhere else, in case the formula works
_parameters.turbulence.gamma = _parameters.timestep.dt * std::max(_maxUStencil.getMaxValues()[0], _maxUStencil.getMaxValues()[1]);
_parameters.turbulence.gamma = 1;
}
void TurbulentKepsSimulation::plotVTK(int timeStep, std::string foldername) {
_turbulentVtkIterator.iterate();
_turbulentVtkStencil.write(this->_turbulentFlowField, timeStep, foldername);
}
void TurbulentKepsSimulation::initializeFlowField() {
Simulation::initializeFlowField();
WallDistanceStencil wds(_parameters);
FieldIterator<TurbulentFlowField> it(_turbulentFlowField, _parameters, wds);
it.iterate();
// Hardcoding initial values to 1 for now !!!!
FLOAT kin = 0.003;
FLOAT epsin = _parameters.turbulence.cmu * pow(kin, 1.5) / 0.03 / _parameters.geometry.lengthY;
if (_parameters.geometry.dim==2){
const int sizex = _flowField.getNx();
const int sizey = _flowField.getNy();
for (int i =1 ;i < sizex+3; i++) {
for (int j =1 ;j < sizey+3; j++) {
_turbulentFlowField.getDissipationRate().getScalar(i,j) = epsin;
_turbulentFlowField.getKineticEnergy().getScalar(i,j) = kin;
}
}
} else {
const int sizex = _flowField.getNx();
const int sizez = _flowField.getNz();
const int sizey = _flowField.getNy();
}
};