Skip to content

Commit 5c63f8d

Browse files
authoredJan 22, 2022
Merge pull request #21 from su2code/develop
Develop
2 parents 27840a0 + c0fce31 commit 5c63f8d

23 files changed

+19717
-0
lines changed
 

‎design/Species_Transport/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
The necessary files for this tutorial are over at /incompressible_flow/Inc_Species_Transport

‎incompressible_flow/Inc_Species_Transport/1__FFD-box-writing/mesh_out.su2

+7,244
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../primitiveVenturi.su2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2+
% %
3+
% SU2 configuration file %
4+
% Case description: Species mixing with 3 species, i.e. 2 transport equations %
5+
% Author: T. Kattmann %
6+
% Institution: Bosch Thermotechniek B.V. %
7+
% Date: 2021/10/14 %
8+
% File Version 7.2.1 "Blackbird" %
9+
% %
10+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
11+
12+
% ------------- DIRECT, ADJOINT, AND LINEARIZED PROBLEM DEFINITION ------------%
13+
%
14+
SOLVER= INC_RANS
15+
KIND_TURB_MODEL= SST
16+
%
17+
% ---------------- INCOMPRESSIBLE FLOW CONDITION DEFINITION -------------------%
18+
%
19+
INC_DENSITY_MODEL= CONSTANT
20+
INC_DENSITY_INIT= 1.1766
21+
%
22+
INC_VELOCITY_INIT= ( 1.00, 0.0, 0.0 )
23+
%
24+
INC_ENERGY_EQUATION= YES
25+
INC_TEMPERATURE_INIT= 300.0
26+
%
27+
INC_NONDIM= INITIAL_VALUES
28+
%
29+
% -------------------- FLUID PROPERTIES ------------------------------------- %
30+
%
31+
FLUID_MODEL= CONSTANT_DENSITY
32+
%
33+
CONDUCTIVITY_MODEL= CONSTANT_CONDUCTIVITY
34+
THERMAL_CONDUCTIVITY_CONSTANT= 0.0357
35+
%
36+
PRANDTL_LAM= 0.72
37+
TURBULENT_CONDUCTIVITY_MODEL= NONE
38+
PRANDTL_TURB= 0.90
39+
%
40+
VISCOSITY_MODEL= CONSTANT_VISCOSITY
41+
MU_CONSTANT= 1.716E-5
42+
%
43+
% -------------------- BOUNDARY CONDITION DEFINITION --------------------------%
44+
%
45+
MARKER_HEATFLUX= ( wall, 0.0 )
46+
MARKER_SYM= ( axis )
47+
%
48+
SPECIFIED_INLET_PROFILE= NO
49+
INLET_FILENAME= inlet_venturi.dat
50+
INC_INLET_TYPE= VELOCITY_INLET VELOCITY_INLET
51+
MARKER_INLET= ( gas_inlet, 300, 1.0, 1.0, 0.0, 0.0,\
52+
air_axial_inlet, 300, 1.0, 0.0, -1.0, 0.0 )
53+
SPECIES_USE_STRONG_BC= NO
54+
MARKER_INLET_SPECIES= (gas_inlet, 0.5, 0.5,\
55+
air_axial_inlet, 0.6, 0.0 )
56+
%
57+
INC_OUTLET_TYPE= PRESSURE_OUTLET
58+
MARKER_OUTLET= ( outlet, 0.0 )
59+
%
60+
% ------------- COMMON PARAMETERS DEFINING THE NUMERICAL METHOD ---------------%
61+
%
62+
NUM_METHOD_GRAD= WEIGHTED_LEAST_SQUARES
63+
%
64+
CFL_NUMBER= 2000
65+
CFL_REDUCTION_SPECIES= 1.0
66+
CFL_REDUCTION_TURB= 1.0
67+
%
68+
% Run commented Iter for good results
69+
ITER= 1000
70+
%
71+
% ------------------------ LINEAR SOLVER DEFINITION ---------------------------%
72+
%
73+
LINEAR_SOLVER= FGMRES
74+
LINEAR_SOLVER_PREC= ILU
75+
LINEAR_SOLVER_ERROR= 1E-8
76+
LINEAR_SOLVER_ITER= 5
77+
78+
% -------------------- FLOW NUMERICAL METHOD DEFINITION -----------------------%
79+
%
80+
CONV_NUM_METHOD_FLOW= FDS
81+
MUSCL_FLOW= YES
82+
SLOPE_LIMITER_FLOW = NONE
83+
TIME_DISCRE_FLOW= EULER_IMPLICIT
84+
%
85+
% -------------------- SCALAR TRANSPORT ---------------------------------------%
86+
%
87+
KIND_SCALAR_MODEL= PASSIVE_SCALAR
88+
DIFFUSIVITY_MODEL= CONSTANT_DIFFUSIVITY
89+
DIFFUSIVITY_CONSTANT= 0.001
90+
%
91+
CONV_NUM_METHOD_SPECIES= SCALAR_UPWIND
92+
MUSCL_SPECIES= NO
93+
SLOPE_LIMITER_SPECIES = NONE
94+
%
95+
TIME_DISCRE_SPECIES= EULER_IMPLICIT
96+
%
97+
SPECIES_INIT= 1.0, 0.0
98+
SPECIES_CLIPPING= YES
99+
SPECIES_CLIPPING_MIN= 0.0, 0.0
100+
SPECIES_CLIPPING_MAX= 1.0, 1.0
101+
%
102+
% -------------------- TURBULENT TRANSPORT ---------------------------------------%
103+
%
104+
CONV_NUM_METHOD_TURB= SCALAR_UPWIND
105+
MUSCL_TURB= NO
106+
%
107+
% --------------------------- CONVERGENCE PARAMETERS --------------------------%
108+
%
109+
CONV_FIELD= RMS_PRESSURE, RMS_VELOCITY-X, RMS_VELOCITY-Y, RMS_TKE, RMS_SPECIES
110+
CONV_RESIDUAL_MINVAL= -18
111+
CONV_STARTITER= 10
112+
%
113+
% ------------------------- INPUT/OUTPUT INFORMATION --------------------------%
114+
%
115+
MESH_FILENAME= primitiveVenturi.su2
116+
%
117+
SCREEN_OUTPUT= INNER_ITER WALL_TIME \
118+
RMS_PRESSURE RMS_VELOCITY-X RMS_VELOCITY-Y RMS_TKE RMS_DISSIPATION RMS_SPECIES_0 RMS_SPECIES_1 \
119+
LINSOL_ITER LINSOL_RESIDUAL \
120+
LINSOL_ITER_TURB LINSOL_RESIDUAL_TURB \
121+
LINSOL_ITER_SPECIES LINSOL_RESIDUAL_SPECIES \
122+
SURFACE_SPECIES_VARIANCE
123+
SCREEN_WRT_FREQ_INNER= 10
124+
%
125+
HISTORY_OUTPUT= ITER RMS_RES LINSOL SPECIES_COEFF SPECIES_COEFF_SURF
126+
CONV_FILENAME= history
127+
MARKER_ANALYZE= gas_inlet, air_axial_inlet, outlet
128+
MARKER_ANALYZE_AVERAGE= AREA
129+
%
130+
OUTPUT_FILES= RESTART_ASCII, PARAVIEW_MULTIBLOCK
131+
VOLUME_OUTPUT= RESIDUAL, PRIMITIVE
132+
OUTPUT_WRT_FREQ= 1000
133+
%
134+
RESTART_SOL= NO
135+
READ_BINARY_RESTART= NO
136+
RESTART_FILENAME= restart
137+
SOLUTION_FILENAME= solution
138+
%
139+
WRT_PERFORMANCE= YES
140+
%
141+
% -------------------- FREE-FORM DEFORMATION PARAMETERS -----------------------%
142+
%
143+
% FFD box definition: 3D case (FFD_BoxTag, X1, Y1, Z1, X2, Y2, Z2, X3, Y3, Z3, X4, Y4, Z4,
144+
% X5, Y5, Z5, X6, Y6, Z6, X7, Y7, Z7, X8, Y8, Z8)
145+
% 2D case (FFD_BoxTag, X1, Y1, 0.0, X2, Y2, 0.0, X3, Y3, 0.0, X4, Y4, 0.0,
146+
% 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)
147+
% Start at the lowest leftest corner and turn counter-clockwise
148+
FFD_DEFINITION= (BOX, \
149+
0.065, 0.01, 0.0, \
150+
0.15, 0.01, 0.0 \
151+
0.15, 0.02, 0.0, \
152+
0.065, 0.02, 0.0, \
153+
0.0, 0.0 ,0.0, \
154+
0.0 ,0.0, 0.0, \
155+
0.0, 0.0, 0.0, \
156+
0.0, 0.0, 0.0 )
157+
%
158+
% FFD box degree: 3D case (i_degree, j_degree, k_degree)
159+
% 2D case (i_degree, j_degree, 0)
160+
FFD_DEGREE= (6, 1, 0)
161+
%
162+
DV_KIND= FFD_SETTING
163+
%
164+
% Marker of the surface in which we are going apply the shape deformation
165+
% NOTE: for deformation the outlet should be a MARKER_SYM to hinder the mesh being ripped apart.
166+
DV_MARKER= ( wall )
167+
%
168+
% Parameters of the shape deformation
169+
% - FFD_SETTING ( 1.0 )
170+
% - FFD_CONTROL_POINT ( FFD_BoxTag, i_Ind, j_Ind, k_Ind, x_Disp, y_Disp, z_Disp )
171+
DV_PARAM= ( 1.0 )
172+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../1__FFD-box-writing/mesh_out.su2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,232 @@
1+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2+
% %
3+
% SU2 configuration file %
4+
% Case description: Species mixing with 3 species, i.e. 2 transport equations %
5+
% Author: T. Kattmann %
6+
% Institution: Bosch Thermotechniek B.V. %
7+
% Date: 2021/10/14 %
8+
% File Version 7.2.1 "Blackbird" %
9+
% %
10+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
11+
12+
% ------------- DIRECT, ADJOINT, AND LINEARIZED PROBLEM DEFINITION ------------%
13+
%
14+
SOLVER= INC_RANS
15+
KIND_TURB_MODEL= SST
16+
%
17+
% ---------------- INCOMPRESSIBLE FLOW CONDITION DEFINITION -------------------%
18+
%
19+
INC_DENSITY_MODEL= CONSTANT
20+
INC_DENSITY_INIT= 1.1766
21+
%
22+
INC_VELOCITY_INIT= ( 1.00, 0.0, 0.0 )
23+
%
24+
INC_ENERGY_EQUATION= YES
25+
INC_TEMPERATURE_INIT= 300.0
26+
%
27+
INC_NONDIM= INITIAL_VALUES
28+
%
29+
% -------------------- FLUID PROPERTIES ------------------------------------- %
30+
%
31+
FLUID_MODEL= CONSTANT_DENSITY
32+
%
33+
CONDUCTIVITY_MODEL= CONSTANT_CONDUCTIVITY
34+
THERMAL_CONDUCTIVITY_CONSTANT= 0.0357
35+
%
36+
PRANDTL_LAM= 0.72
37+
TURBULENT_CONDUCTIVITY_MODEL= NONE
38+
PRANDTL_TURB= 0.90
39+
%
40+
VISCOSITY_MODEL= CONSTANT_VISCOSITY
41+
MU_CONSTANT= 1.716E-5
42+
%
43+
% -------------------- BOUNDARY CONDITION DEFINITION --------------------------%
44+
%
45+
MARKER_HEATFLUX= ( wall, 0.0 )
46+
% make outlet a sym-marker to ensure a nice mesh deformation
47+
MARKER_SYM= ( axis, outlet )
48+
%
49+
SPECIFIED_INLET_PROFILE= NO
50+
INLET_FILENAME= inlet_venturi.dat
51+
INC_INLET_TYPE= VELOCITY_INLET VELOCITY_INLET
52+
MARKER_INLET= ( gas_inlet, 300, 1.0, 1.0, 0.0, 0.0,\
53+
air_axial_inlet, 300, 1.0, 0.0, -1.0, 0.0 )
54+
SPECIES_USE_STRONG_BC= NO
55+
MARKER_INLET_SPECIES= (gas_inlet, 0.5, 0.5,\
56+
air_axial_inlet, 0.6, 0.0 )
57+
%
58+
%INC_OUTLET_TYPE= PRESSURE_OUTLET
59+
%MARKER_OUTLET= ( outlet, 0.0 )
60+
%
61+
% ------------- COMMON PARAMETERS DEFINING THE NUMERICAL METHOD ---------------%
62+
%
63+
NUM_METHOD_GRAD= WEIGHTED_LEAST_SQUARES
64+
%
65+
CFL_NUMBER= 2000
66+
CFL_REDUCTION_SPECIES= 1.0
67+
CFL_REDUCTION_TURB= 1.0
68+
%
69+
% Run commented Iter for good results
70+
ITER= 1000
71+
%
72+
% ------------------------ LINEAR SOLVER DEFINITION ---------------------------%
73+
%
74+
LINEAR_SOLVER= FGMRES
75+
LINEAR_SOLVER_PREC= ILU
76+
LINEAR_SOLVER_ERROR= 1E-8
77+
LINEAR_SOLVER_ITER= 5
78+
79+
% -------------------- FLOW NUMERICAL METHOD DEFINITION -----------------------%
80+
%
81+
CONV_NUM_METHOD_FLOW= FDS
82+
MUSCL_FLOW= YES
83+
SLOPE_LIMITER_FLOW = NONE
84+
TIME_DISCRE_FLOW= EULER_IMPLICIT
85+
%
86+
% -------------------- SCALAR TRANSPORT ---------------------------------------%
87+
%
88+
KIND_SCALAR_MODEL= PASSIVE_SCALAR
89+
DIFFUSIVITY_MODEL= CONSTANT_DIFFUSIVITY
90+
DIFFUSIVITY_CONSTANT= 0.001
91+
%
92+
CONV_NUM_METHOD_SPECIES= SCALAR_UPWIND
93+
MUSCL_SPECIES= NO
94+
SLOPE_LIMITER_SPECIES = NONE
95+
%
96+
TIME_DISCRE_SPECIES= EULER_IMPLICIT
97+
%
98+
SPECIES_INIT= 1.0, 0.0
99+
SPECIES_CLIPPING= YES
100+
SPECIES_CLIPPING_MIN= 0.0, 0.0
101+
SPECIES_CLIPPING_MAX= 1.0, 1.0
102+
%
103+
% -------------------- TURBULENT TRANSPORT ---------------------------------------%
104+
%
105+
CONV_NUM_METHOD_TURB= SCALAR_UPWIND
106+
MUSCL_TURB= NO
107+
%
108+
% --------------------------- CONVERGENCE PARAMETERS --------------------------%
109+
%
110+
CONV_FIELD= RMS_PRESSURE, RMS_VELOCITY-X, RMS_VELOCITY-Y, RMS_TKE, RMS_SPECIES
111+
CONV_RESIDUAL_MINVAL= -18
112+
CONV_STARTITER= 10
113+
%
114+
% ------------------------- INPUT/OUTPUT INFORMATION --------------------------%
115+
%
116+
MESH_FILENAME= primitiveVenturi.su2
117+
%
118+
SCREEN_OUTPUT= INNER_ITER WALL_TIME \
119+
RMS_PRESSURE RMS_VELOCITY-X RMS_VELOCITY-Y RMS_TKE RMS_DISSIPATION RMS_SPECIES_0 RMS_SPECIES_1 \
120+
LINSOL_ITER LINSOL_RESIDUAL \
121+
LINSOL_ITER_TURB LINSOL_RESIDUAL_TURB \
122+
LINSOL_ITER_SPECIES LINSOL_RESIDUAL_SPECIES \
123+
SURFACE_SPECIES_VARIANCE
124+
SCREEN_WRT_FREQ_INNER= 10
125+
%
126+
HISTORY_OUTPUT= ITER RMS_RES LINSOL SPECIES_COEFF SPECIES_COEFF_SURF
127+
CONV_FILENAME= history
128+
MARKER_ANALYZE= gas_inlet, air_axial_inlet, outlet
129+
MARKER_ANALYZE_AVERAGE= AREA
130+
%
131+
OUTPUT_FILES= RESTART_ASCII, PARAVIEW_MULTIBLOCK
132+
VOLUME_OUTPUT= RESIDUAL, PRIMITIVE
133+
OUTPUT_WRT_FREQ= 1000
134+
%
135+
RESTART_SOL= NO
136+
READ_BINARY_RESTART= NO
137+
RESTART_FILENAME= restart
138+
SOLUTION_FILENAME= solution
139+
%
140+
WRT_PERFORMANCE= YES
141+
%
142+
% -------------------- FREE-FORM DEFORMATION PARAMETERS -----------------------%
143+
%
144+
% Tolerance of the Free-Form Deformation point inversion
145+
FFD_TOLERANCE= 1E-10
146+
%
147+
% Maximum number of iterations in the Free-Form Deformation point inversion
148+
FFD_ITERATIONS= 500
149+
%
150+
% FFD box definition: 3D case (FFD_BoxTag, X1, Y1, Z1, X2, Y2, Z2, X3, Y3, Z3, X4, Y4, Z4,
151+
% X5, Y5, Z5, X6, Y6, Z6, X7, Y7, Z7, X8, Y8, Z8)
152+
% 2D case (FFD_BoxTag, X1, Y1, 0.0, X2, Y2, 0.0, X3, Y3, 0.0, X4, Y4, 0.0,
153+
% 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)
154+
% Start at the lowest leftest corner and turn counter-clockwise
155+
FFD_DEFINITION= (BOX, \
156+
0.065, 0.01, 0.0, \
157+
0.15, 0.01, 0.0 \
158+
0.15, 0.02, 0.0, \
159+
0.065, 0.02, 0.0, \
160+
0.0, 0.0 ,0.0, \
161+
0.0 ,0.0, 0.0, \
162+
0.0, 0.0, 0.0, \
163+
0.0, 0.0, 0.0 )
164+
%
165+
% FFD box degree: 3D case (i_degree, j_degree, k_degree)
166+
% 2D case (i_degree, j_degree, 0)
167+
FFD_DEGREE= (6, 1, 0)
168+
%
169+
% Surface grid continuity at the intersection with the faces of the FFD boxes.
170+
% To keep a particular level of surface continuity, SU2 automatically freezes the right
171+
% number of control point planes (NO_DERIVATIVE, 1ST_DERIVATIVE, 2ND_DERIVATIVE, USER_INPUT)
172+
FFD_CONTINUITY= USER_INPUT
173+
%
174+
% Definition of the FFD planes to be frozen in the FFD (x,y,z).
175+
% Value from 0 FFD degree in that direction. Pick a value larger than degree if you don't want to fix any plane.
176+
%FFD_FIX_I= (0,2,3)
177+
%FFD_FIX_J= (0,2,3)
178+
%FFD_FIX_K= (0,2,3)
179+
180+
% ----------------------- DESIGN VARIABLE PARAMETERS --------------------------%
181+
%
182+
DV_KIND= FFD_CONTROL_POINT_2D, FFD_CONTROL_POINT_2D, FFD_CONTROL_POINT_2D, FFD_CONTROL_POINT_2D, FFD_CONTROL_POINT_2D, FFD_CONTROL_POINT_2D, FFD_CONTROL_POINT_2D, FFD_CONTROL_POINT_2D, FFD_CONTROL_POINT_2D, FFD_CONTROL_POINT_2D
183+
%
184+
% Marker of the surface in which we are going apply the shape deformation
185+
% NOTE: for deformation the outlet should be a MARKER_SYM to hinder the mesh being ripped apart.
186+
DV_MARKER= ( wall )
187+
%
188+
% Parameters of the shape deformation
189+
% - FFD_SETTING ( 1.0 )
190+
% - FFD_CONTROL_POINT_2D ( FFD_BoxTag, i_Ind, j_Ind, x_Disp, y_Disp )
191+
DV_PARAM= (BOX, 2, 0, 0.0, 1.0); (BOX, 3, 0, 0.0, 1.0); (BOX, 4, 0, 0.0, 1.0); (BOX, 5, 0, 0.0, 1.0); (BOX, 6, 0, 0.0, 1.0); (BOX, 2, 1, 0.0, 1.0); (BOX, 3, 1, 0.0, 1.0); (BOX, 4, 1, 0.0, 1.0); (BOX, 5, 1, 0.0, 1.0); (BOX, 6, 1, 0.0, 1.0)
192+
% Excluded FFD points that are fixed to keep a nice geometry
193+
%DV_PARAM= (BOX, 0, 0, 0.0, 1.0); (BOX, 1, 0, 0.0, 1.0); (BOX, 0, 1, 0.0, 1.0); (BOX, 1, 1, 0.0, 1.0);
194+
%
195+
% Value of the shape deformation
196+
% first row: lower row y-direction
197+
% second row: upper row y-direction
198+
DV_VALUE= 0.003, 0.003, 0.004, 0.005, 0.005, \
199+
0.003, 0.003, 0.004, 0.005, 0.005
200+
201+
% ------------------------ GRID DEFORMATION PARAMETERS ------------------------%
202+
%
203+
% Linear solver or smoother for implicit formulations (FGMRES, RESTARTED_FGMRES, BCGSTAB)
204+
DEFORM_LINEAR_SOLVER= FGMRES
205+
%
206+
% Preconditioner of the Krylov linear solver (ILU, LU_SGS, JACOBI)
207+
DEFORM_LINEAR_SOLVER_PREC= ILU
208+
%
209+
% Number of smoothing iterations for mesh deformation
210+
DEFORM_LINEAR_SOLVER_ITER= 1000
211+
%
212+
% Number of nonlinear deformation iterations (surface deformation increments)
213+
DEFORM_NONLINEAR_ITER= 1
214+
%
215+
% Minimum residual criteria for the linear solver convergence of grid deformation
216+
DEFORM_LINEAR_SOLVER_ERROR= 1E-14
217+
%
218+
% Print the residuals during mesh deformation to the console (YES, NO)
219+
DEFORM_CONSOLE_OUTPUT= YES
220+
%
221+
% Deformation coefficient (linear elasticity limits from -1.0 to 0.5, a larger
222+
% value is also possible)
223+
DEFORM_COEFF = 0.0
224+
%
225+
% Type of element stiffness imposed for FEA mesh deformation (INVERSE_VOLUME,
226+
% WALL_DISTANCE, CONSTANT_STIFFNESS)
227+
DEFORM_STIFFNESS_TYPE= WALL_DISTANCE
228+
%
229+
% Deform the grid only close to the surface. It is possible to specify how much
230+
% of the volumetric grid is going to be deformed in meters or inches (1E6 by default)
231+
DEFORM_LIMIT = 1E6
232+
%
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
# FADO script: Finite Differences vs adjoint run
2+
3+
from FADO import *
4+
5+
# Design variables ----------------------------------------------------- #
6+
7+
nDV = 10
8+
ffd = InputVariable(0.0,PreStringHandler("DV_VALUE="),nDV)
9+
10+
# Parameters ----------------------------------------------------------- #
11+
12+
# The master config `configMaster.cfg` serves as an SU2 adjoint regression test.
13+
# For a correct gradient validation we need to exchange some options
14+
15+
# switch from direct to adjoint mode and adapt settings.
16+
enable_direct = Parameter([""], LabelReplacer("%__DIRECT__"))
17+
enable_adjoint = Parameter([""], LabelReplacer("%__ADJOINT__"))
18+
enable_not_def = Parameter([""], LabelReplacer("%__NOT_DEF__"))
19+
enable_def = Parameter([""], LabelReplacer("%__DEF__"))
20+
21+
# Switch Objective Functions
22+
OF_SpecVar = Parameter([""], LabelReplacer("%__OF_SpecVar__"))
23+
24+
# Evaluations ---------------------------------------------------------- #
25+
26+
# Define a few often used variables
27+
ncores="2"
28+
configMaster="species3_primitiveVenturi.cfg"
29+
meshName="primitiveVenturi.su2"
30+
31+
# Note that correct SU2 version needs to be in PATH
32+
33+
def_command = "SU2_DEF " + configMaster
34+
cfd_command = "mpirun -n " + ncores + " SU2_CFD " + configMaster
35+
36+
cfd_ad_command = "mpirun -n " + ncores + " SU2_CFD_AD " + configMaster
37+
dot_ad_command = "mpirun -n " + ncores + " SU2_DOT_AD " + configMaster
38+
39+
max_tries = 1
40+
41+
# mesh deformation
42+
deform = ExternalRun("DEFORM",def_command,True) # True means sym links are used for addData
43+
deform.setMaxTries(max_tries)
44+
deform.addConfig(configMaster)
45+
deform.addData(meshName)
46+
deform.addExpected("mesh_out.su2")
47+
deform.addParameter(enable_def)
48+
49+
# direct run
50+
direct = ExternalRun("DIRECT",cfd_command,True)
51+
direct.setMaxTries(max_tries)
52+
direct.addConfig(configMaster)
53+
direct.addData("DEFORM/mesh_out.su2",destination=meshName)
54+
direct.addData("solution.csv")
55+
direct.addExpected("restart.csv")
56+
direct.addParameter(enable_direct)
57+
direct.addParameter(enable_not_def)
58+
59+
# adjoint run
60+
adjoint = ExternalRun("ADJOINT",cfd_ad_command,True)
61+
adjoint.setMaxTries(max_tries)
62+
adjoint.addConfig(configMaster)
63+
adjoint.addData("DEFORM/mesh_out.su2", destination=meshName)
64+
# add all primal solution files
65+
adjoint.addData("DIRECT/restart.csv", destination="solution.csv")
66+
adjoint.addExpected("restart_adj_specvar.csv")
67+
adjoint.addParameter(enable_adjoint)
68+
adjoint.addParameter(enable_not_def)
69+
adjoint.addParameter(OF_SpecVar)
70+
71+
# gradient projection
72+
dot = ExternalRun("DOT",dot_ad_command,True)
73+
dot.setMaxTries(max_tries)
74+
dot.addConfig(configMaster)
75+
dot.addData("DEFORM/mesh_out.su2", destination=meshName)
76+
dot.addData("ADJOINT/restart_adj_specvar.csv", destination="solution_adj_specvar.csv")
77+
dot.addExpected("of_grad.csv")
78+
dot.addParameter(enable_def)
79+
dot.addParameter(OF_SpecVar) # necessary for correct file extension
80+
81+
# Functions ------------------------------------------------------------ #
82+
83+
specVar = Function("specVar", "DIRECT/history.csv",LabeledTableReader("\"Species_Variance\""))
84+
specVar.addInputVariable(ffd,"DOT/of_grad.csv",TableReader(None,0,(1,0))) # all rows, col 0, don't read the header
85+
specVar.addValueEvalStep(deform)
86+
specVar.addValueEvalStep(direct)
87+
specVar.addGradientEvalStep(adjoint)
88+
specVar.addGradientEvalStep(dot)
89+
90+
# Driver --------------------------------------------------------------- #
91+
92+
# The input variable is the constraint tolerance which is not used for our purpose of finite differences
93+
driver = ExteriorPenaltyDriver(0.005)
94+
driver.addObjective("min", specVar)
95+
96+
driver.setWorkingDirectory("DOE")
97+
driver.preprocessVariables()
98+
driver.setStorageMode(True,"DSN_")
99+
100+
his = open("doe.csv","w",1)
101+
driver.setHistorian(his)
102+
103+
# Simulation Runs ------------------------------------------------------ #
104+
105+
# Primal simulation for each deformed DV
106+
for iLoop in range(0, nDV, 1):
107+
print("Computing deformed primal ", iLoop, "/", nDV-1)
108+
x = driver.getInitial()
109+
x[iLoop] = 1e-8 # DV_VALUE, FD-step
110+
driver.fun(x)
111+
#end
112+
113+
# Undeformed/initial primal last in order to have the correct solution in
114+
# the WorkindDirectory for the following adjoint
115+
print("Computing baseline primal")
116+
x = driver.getInitial()
117+
driver.fun(x) # baseline evaluation
118+
119+
# Compute discrete adjoint gradient
120+
print("Computing discrete adjoint gradient")
121+
driver.grad(x)
122+
123+
his.close()
124+
125+
# For results run `python postprocess.py` to get screen output
126+
# of the differences between primal and adjoint simulation.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Compute and print absolute difference between Discrete Adjoint
2+
# and Finite Difference gradient. Prints also percentage difference.
3+
#
4+
# Run this script after `python gradient_validation.py` successfully finished
5+
6+
import pandas as pd
7+
import math
8+
9+
def printGradVal(FDgrad, DAgrad):
10+
"""
11+
Print Gradient Comparison to screen between DA and FD.
12+
13+
Input:
14+
FDgrad: array with the Finite Difference gradient
15+
DAgrad: array with the Discrete Adjoint gradient
16+
"""
17+
# Check that both arrays have the same length and deduce a size parameter
18+
assert(DAgrad.size == FDgrad.size)
19+
20+
# absolute difference
21+
absoluteDiff = DAgrad - FDgrad
22+
# relative difference in percent
23+
relDiffPercent = (DAgrad - FDgrad)/abs(DAgrad) * 100
24+
# sign change
25+
sign = lambda x : math.copysign(1, x)
26+
signChange = [sign(DA) != sign(FD) for DA,FD in zip(DAgrad,FDgrad)]
27+
28+
print('+-----------+-------------------+-------------------+-------------------+-------------------+-------------+')
29+
print('| DV number | DA gradient | FD gradient | absolute diff | relative diff [%] | sign change |')
30+
print('+-----------+-------------------+-------------------+-------------------+-------------------+-------------+')
31+
32+
for iDV in range(0, DAgrad.size, 1):
33+
print('|{0:10d} |{1:18.10f} |{2:18.10f} |{3:18.10f} |{4:18.10f} |{5:12} |'.format(iDV, DAgrad[iDV], FDgrad[iDV], absoluteDiff[iDV], relDiffPercent[iDV], signChange[iDV]))
34+
35+
print('+-----------+-------------------+-------------------+-------------------+-------------------+-------------+')
36+
# printGradVal
37+
38+
if __name__ == "__main__":
39+
40+
# FDStep has to match with the value in the gradient_validation script
41+
FDstep = 1e-8
42+
43+
# Load Discrete Adjont gradient
44+
DAvals_specVar = pd.read_csv("DOE/DOT/of_grad.csv")
45+
46+
DAstring_specVar = 'SURFACE_SPECIES_VARIANCE gradient '
47+
48+
DAgrad_specVar = DAvals_specVar[DAstring_specVar].values
49+
nDV = DAgrad_specVar.size
50+
51+
# Load primal values and create FD gradient
52+
FDvals = pd.read_csv("doe.his")
53+
54+
FDstring_specVar = ' specVar'
55+
56+
# Note that the FDvals have the baseline value written in its last position
57+
FDgrad_specVar = (FDvals[FDstring_specVar].values[:nDV] - FDvals[FDstring_specVar].values[nDV]) / FDstep
58+
59+
# Legend
60+
print("absolute diff = DAgrad - FDgrad")
61+
print("relative diff = (DAgrad - FDgrad) / abs(DAgrad) * 100")
62+
63+
print(DAstring_specVar)
64+
printGradVal(FDgrad_specVar, DAgrad_specVar)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../1__FFD-box-writing/mesh_out.su2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../solution.csv
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,234 @@
1+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2+
% %
3+
% SU2 configuration file %
4+
% Case description: Species mixing with 3 species, i.e. 2 transport equations %
5+
% Author: T. Kattmann %
6+
% Institution: Bosch Thermotechniek B.V. %
7+
% Date: 2021/10/14 %
8+
% File Version 7.2.1 "Blackbird" %
9+
% %
10+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
11+
12+
% ------------- DIRECT, ADJOINT, AND LINEARIZED PROBLEM DEFINITION ------------%
13+
%
14+
SOLVER= INC_RANS
15+
KIND_TURB_MODEL= SST
16+
%
17+
%__OF_SpecVar__OBJECTIVE_FUNCTION= SURFACE_SPECIES_VARIANCE
18+
%__OF_SpecVar__OBJECTIVE_WEIGHT= 1.0
19+
%
20+
% ---------------- INCOMPRESSIBLE FLOW CONDITION DEFINITION -------------------%
21+
%
22+
INC_DENSITY_MODEL= CONSTANT
23+
INC_DENSITY_INIT= 1.1766
24+
%
25+
INC_VELOCITY_INIT= ( 1.00, 0.0, 0.0 )
26+
%
27+
INC_ENERGY_EQUATION= YES
28+
INC_TEMPERATURE_INIT= 300.0
29+
%
30+
INC_NONDIM= INITIAL_VALUES
31+
%
32+
% -------------------- FLUID PROPERTIES ------------------------------------- %
33+
%
34+
FLUID_MODEL= CONSTANT_DENSITY
35+
%
36+
CONDUCTIVITY_MODEL= CONSTANT_CONDUCTIVITY
37+
THERMAL_CONDUCTIVITY_CONSTANT= 0.0357
38+
%
39+
PRANDTL_LAM= 0.72
40+
TURBULENT_CONDUCTIVITY_MODEL= NONE
41+
PRANDTL_TURB= 0.90
42+
%
43+
VISCOSITY_MODEL= CONSTANT_VISCOSITY
44+
MU_CONSTANT= 1.716E-5
45+
%
46+
% -------------------- BOUNDARY CONDITION DEFINITION --------------------------%
47+
%
48+
MARKER_HEATFLUX= ( wall, 0.0 )
49+
%__NOT_DEF__MARKER_SYM= ( axis )
50+
%__DEF__MARKER_SYM= (axis, outlet)
51+
%
52+
SPECIFIED_INLET_PROFILE= NO
53+
INLET_FILENAME= inlet_venturi.dat
54+
INC_INLET_TYPE= VELOCITY_INLET VELOCITY_INLET
55+
MARKER_INLET= ( gas_inlet, 300, 1.0, 1.0, 0.0, 0.0,\
56+
air_axial_inlet, 300, 1.0, 0.0, -1.0, 0.0 )
57+
SPECIES_USE_STRONG_BC= NO
58+
MARKER_INLET_SPECIES= (gas_inlet, 0.5, 0.5,\
59+
air_axial_inlet, 0.6, 0.0 )
60+
%
61+
%__NOT_DEF__INC_OUTLET_TYPE= PRESSURE_OUTLET
62+
%__NOT_DEF__MARKER_OUTLET= ( outlet, 0.0 )
63+
%
64+
% ------------- COMMON PARAMETERS DEFINING THE NUMERICAL METHOD ---------------%
65+
%
66+
NUM_METHOD_GRAD= WEIGHTED_LEAST_SQUARES
67+
%
68+
%__DIRECT__CFL_NUMBER= 2000
69+
%__ADJOINT__CFL_NUMBER= 500
70+
CFL_REDUCTION_SPECIES= 1.0
71+
CFL_REDUCTION_TURB= 1.0
72+
%
73+
% Run commented Iter for good results
74+
ITER= 1000
75+
%
76+
% ------------------------ LINEAR SOLVER DEFINITION ---------------------------%
77+
%
78+
LINEAR_SOLVER= FGMRES
79+
LINEAR_SOLVER_PREC= ILU
80+
LINEAR_SOLVER_ERROR= 1E-8
81+
%__DIRECT__LINEAR_SOLVER_ITER= 5
82+
%__ADJOINT__LINEAR_SOLVER_ITER= 20
83+
84+
% -------------------- FLOW NUMERICAL METHOD DEFINITION -----------------------%
85+
%
86+
CONV_NUM_METHOD_FLOW= FDS
87+
MUSCL_FLOW= YES
88+
SLOPE_LIMITER_FLOW = NONE
89+
TIME_DISCRE_FLOW= EULER_IMPLICIT
90+
%
91+
% -------------------- SCALAR TRANSPORT ---------------------------------------%
92+
%
93+
KIND_SCALAR_MODEL= PASSIVE_SCALAR
94+
DIFFUSIVITY_MODEL= CONSTANT_DIFFUSIVITY
95+
DIFFUSIVITY_CONSTANT= 0.001
96+
%
97+
CONV_NUM_METHOD_SPECIES= SCALAR_UPWIND
98+
MUSCL_SPECIES= NO
99+
SLOPE_LIMITER_SPECIES = NONE
100+
%
101+
TIME_DISCRE_SPECIES= EULER_IMPLICIT
102+
%
103+
SPECIES_INIT= 1.0, 0.0
104+
SPECIES_CLIPPING= YES
105+
SPECIES_CLIPPING_MIN= 0.0, 0.0
106+
SPECIES_CLIPPING_MAX= 1.0, 1.0
107+
%
108+
% -------------------- TURBULENT TRANSPORT ---------------------------------------%
109+
%
110+
CONV_NUM_METHOD_TURB= SCALAR_UPWIND
111+
MUSCL_TURB= NO
112+
%
113+
% --------------------------- CONVERGENCE PARAMETERS --------------------------%
114+
%
115+
CONV_FIELD= RMS_PRESSURE, RMS_VELOCITY-X, RMS_VELOCITY-Y, RMS_TKE, RMS_SPECIES
116+
CONV_RESIDUAL_MINVAL= -18
117+
CONV_STARTITER= 10
118+
%
119+
% ------------------------- INPUT/OUTPUT INFORMATION --------------------------%
120+
%
121+
MESH_FILENAME= primitiveVenturi.su2
122+
%
123+
%__DIRECT__SCREEN_OUTPUT= INNER_ITER WALL_TIME RMS_PRESSURE RMS_VELOCITY-X RMS_VELOCITY-Y RMS_TKE RMS_DISSIPATION RMS_SPECIES_0 RMS_SPECIES_1 LINSOL_ITER LINSOL_RESIDUAL LINSOL_ITER_TURB LINSOL_RESIDUAL_TURB LINSOL_ITER_SPECIES LINSOL_RESIDUAL_SPECIES SURFACE_SPECIES_VARIANCE
124+
%__ADJOINT__SCREEN_OUTPUT= INNER_ITER WALL_TIME RMS_ADJ_PRESSURE RMS_ADJ_VELOCITY-X RMS_ADJ_VELOCITY-Y RMS_ADJ_TKE RMS_ADJ_DISSIPATION RMS_ADJ_SPECIES_0 RMS_ADJ_SPECIES_1
125+
SCREEN_WRT_FREQ_INNER= 10
126+
%
127+
HISTORY_OUTPUT= ITER RMS_RES LINSOL SPECIES_COEFF SPECIES_COEFF_SURF
128+
CONV_FILENAME= history
129+
MARKER_ANALYZE= outlet
130+
MARKER_ANALYZE_AVERAGE= MASSFLUX
131+
%
132+
OUTPUT_FILES= RESTART_ASCII, PARAVIEW_MULTIBLOCK
133+
VOLUME_OUTPUT= RESIDUAL, PRIMITIVE
134+
OUTPUT_WRT_FREQ= 1000
135+
%
136+
GRAD_OBJFUNC_FILENAME= of_grad.csv
137+
%
138+
%__DIRECT__RESTART_SOL= YES
139+
READ_BINARY_RESTART= NO
140+
RESTART_FILENAME= restart
141+
SOLUTION_FILENAME= solution
142+
%
143+
WRT_PERFORMANCE= YES
144+
OUTPUT_PRECISION= 16
145+
%
146+
% -------------------- FREE-FORM DEFORMATION PARAMETERS -----------------------%
147+
%
148+
% Tolerance of the Free-Form Deformation point inversion
149+
FFD_TOLERANCE= 1E-10
150+
%
151+
% Maximum number of iterations in the Free-Form Deformation point inversion
152+
FFD_ITERATIONS= 500
153+
%
154+
% FFD box definition: 3D case (FFD_BoxTag, X1, Y1, Z1, X2, Y2, Z2, X3, Y3, Z3, X4, Y4, Z4,
155+
% X5, Y5, Z5, X6, Y6, Z6, X7, Y7, Z7, X8, Y8, Z8)
156+
% 2D case (FFD_BoxTag, X1, Y1, 0.0, X2, Y2, 0.0, X3, Y3, 0.0, X4, Y4, 0.0,
157+
% 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)
158+
% Start at the lowest leftest corner and turn counter-clockwise
159+
FFD_DEFINITION= (BOX, \
160+
0.065, 0.01, 0.0, \
161+
0.15, 0.01, 0.0 \
162+
0.15, 0.02, 0.0, \
163+
0.065, 0.02, 0.0, \
164+
0.0, 0.0 ,0.0, \
165+
0.0 ,0.0, 0.0, \
166+
0.0, 0.0, 0.0, \
167+
0.0, 0.0, 0.0 )
168+
%
169+
% FFD box degree: 3D case (i_degree, j_degree, k_degree)
170+
% 2D case (i_degree, j_degree, 0)
171+
FFD_DEGREE= (6, 1, 0)
172+
%
173+
% Surface grid continuity at the intersection with the faces of the FFD boxes.
174+
% To keep a particular level of surface continuity, SU2 automatically freezes the right
175+
% number of control point planes (NO_DERIVATIVE, 1ST_DERIVATIVE, 2ND_DERIVATIVE, USER_INPUT)
176+
FFD_CONTINUITY= USER_INPUT
177+
%
178+
% Definition of the FFD planes to be frozen in the FFD (x,y,z).
179+
% Value from 0 FFD degree in that direction. Pick a value larger than degree if you don't want to fix any plane.
180+
%FFD_FIX_I= (0,2,3)
181+
%FFD_FIX_J= (0,2,3)
182+
%FFD_FIX_K= (0,2,3)
183+
184+
% ----------------------- DESIGN VARIABLE PARAMETERS --------------------------%
185+
%
186+
DV_KIND= FFD_CONTROL_POINT_2D, FFD_CONTROL_POINT_2D, FFD_CONTROL_POINT_2D, FFD_CONTROL_POINT_2D, FFD_CONTROL_POINT_2D, FFD_CONTROL_POINT_2D, FFD_CONTROL_POINT_2D, FFD_CONTROL_POINT_2D, FFD_CONTROL_POINT_2D, FFD_CONTROL_POINT_2D
187+
%
188+
% Marker of the surface in which we are going apply the shape deformation
189+
% NOTE: for deformation the outlet should be a MARKER_SYM to hinder the mesh being ripped apart.
190+
DV_MARKER= ( wall )
191+
%
192+
% Parameters of the shape deformation
193+
% - FFD_SETTING ( 1.0 )
194+
% - FFD_CONTROL_POINT ( FFD_BoxTag, i_Ind, j_Ind, k_Ind, x_Disp, y_Disp, z_Disp )
195+
DV_PARAM= (BOX, 2, 0, 0.0, 1.0); (BOX, 3, 0, 0.0, 1.0); (BOX, 4, 0, 0.0, 1.0); (BOX, 5, 0, 0.0, 1.0); (BOX, 6, 0, 0.0, 1.0); (BOX, 2, 1, 0.0, 1.0); (BOX, 3, 1, 0.0, 1.0); (BOX, 4, 1, 0.0, 1.0); (BOX, 5, 1, 0.0, 1.0); (BOX, 6, 1, 0.0, 1.0)
196+
% Excluded FFD points that are fixed to keep a nice geometry
197+
%DV_PARAM= (BOX, 0, 0, 0.0, 1.0); (BOX, 1, 0, 0.0, 1.0); (BOX, 0, 1, 0.0, 1.0); (BOX, 1, 1, 0.0, 1.0);
198+
%
199+
% Value of the shape deformation
200+
% first row: lower row y-direction
201+
% second row: upper row y-direction
202+
DV_VALUE= 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0
203+
%
204+
% ------------------------ GRID DEFORMATION PARAMETERS ------------------------%
205+
%
206+
% Linear solver or smoother for implicit formulations (FGMRES, RESTARTED_FGMRES, BCGSTAB)
207+
DEFORM_LINEAR_SOLVER= FGMRES
208+
%
209+
% Preconditioner of the Krylov linear solver (ILU, LU_SGS, JACOBI)
210+
DEFORM_LINEAR_SOLVER_PREC= ILU
211+
%
212+
% Number of smoothing iterations for mesh deformation
213+
DEFORM_LINEAR_SOLVER_ITER= 1000
214+
%
215+
% Number of nonlinear deformation iterations (surface deformation increments)
216+
DEFORM_NONLINEAR_ITER= 1
217+
%
218+
% Minimum residual criteria for the linear solver convergence of grid deformation
219+
DEFORM_LINEAR_SOLVER_ERROR= 1E-14
220+
%
221+
% Print the residuals during mesh deformation to the console (YES, NO)
222+
DEFORM_CONSOLE_OUTPUT= YES
223+
%
224+
% Deformation coefficient (linear elasticity limits from -1.0 to 0.5, a larger
225+
% value is also possible)
226+
DEFORM_COEFF = 0.0
227+
%
228+
% Type of element stiffness imposed for FEA mesh deformation (INVERSE_VOLUME,
229+
% WALL_DISTANCE, CONSTANT_STIFFNESS)
230+
DEFORM_STIFFNESS_TYPE= WALL_DISTANCE
231+
%
232+
% Deform the grid only close to the surface. It is possible to specify how much
233+
% of the volumetric grid is going to be deformed in meters or inches (1E6 by default)
234+
DEFORM_LIMIT = 1E6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# 06.12.2021 T. Kattmann
2+
#
3+
# Create symlinks for primal solution and FFD-Box of all desings in a separate folder.
4+
# The links are renamed, such that the optimization progress can be visualized as a time series.
5+
# Currently for PARAVIEW_MULTIBLOCK.
6+
7+
import os
8+
import shutil
9+
10+
def make_dst_filename(i, front_string, trailing_string):
11+
if i<10:
12+
number= "00" + str(i)
13+
elif i<100:
14+
number= "0" + str(i)
15+
elif i<1000:
16+
number= str(i)
17+
else:
18+
raise ValueError("More than 1000 Designs.")
19+
20+
return front_string + number + trailing_string
21+
22+
if __name__ == '__main__':
23+
# create folder to link files into
24+
dir= "visu_files"
25+
if os.path.exists(dir):
26+
shutil.rmtree(dir)
27+
os.makedirs(dir)
28+
29+
# create list with folder names
30+
baseFolder = "./"
31+
sub_folders = [name for name in os.listdir(baseFolder) if os.path.isdir(os.path.join(baseFolder, name))]
32+
DSN_folders = [folder for folder in sub_folders if 'DSN' in folder]
33+
print(DSN_folders)
34+
35+
# loop trough folders and symlink files
36+
for i,folder in enumerate(DSN_folders):
37+
# check if file exists
38+
sym_file= DSN_folders[i] + "/DIRECT/species3_primitiveVenturi/zone_0/Internal.vtu"
39+
sym_file2= DSN_folders[i] + "/DEFORM/ffd_boxes_def_0.vtk"
40+
if os.path.exists(sym_file):
41+
os.symlink("../" + sym_file, dir + make_dst_filename(i, "/visu_", ".vtu"))
42+
os.symlink("../" + sym_file2, dir + make_dst_filename(i, "/ffd_", ".vtk"))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# 06.12.2021 T. Kattmann
2+
#
3+
# Compute gradient norm for each design iteration and saves the gradient norm into a csv file.
4+
5+
import numpy as np
6+
import os
7+
import pandas as pd
8+
9+
if __name__ == '__main__':
10+
# Create list with folder names
11+
baseFolder = "./"
12+
sub_folders = [name for name in os.listdir(baseFolder) if os.path.isdir(os.path.join(baseFolder, name))]
13+
DSN_folders = [folder for folder in sub_folders if 'DSN' in folder]
14+
15+
# Initialize array of gradient Norms
16+
gradientNormVector = np.zeros(len(DSN_folders))
17+
18+
# loop through all Design folder
19+
for i,folder in enumerate(DSN_folders):
20+
# check if gradient file exists
21+
gradFilename = baseFolder + folder + "/DOT/of_grad.csv"
22+
if os.path.exists(gradFilename):
23+
# Read the gradient file and store gradient norm
24+
df = pd.read_csv(gradFilename)
25+
gradient = df.values
26+
gradientNormVector[i] = np.linalg.norm(gradient)
27+
else:
28+
# Write a NaN as in Paraview these values are omitted
29+
gradientNormVector[i] = np.nan
30+
31+
print(gradientNormVector)
32+
df = pd.DataFrame({"ITER" : range(len(DSN_folders)), "Gradient Norm" : gradientNormVector})
33+
df.to_csv("gradient_norm.csv", index=False)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
# FADO script: Shape Optimization with Species Variance OF
2+
3+
from FADO import *
4+
5+
# Design variables ----------------------------------------------------- #
6+
7+
nDV = 10
8+
ffd = InputVariable(0.0,PreStringHandler("DV_VALUE="),nDV)
9+
ffd = InputVariable(np.zeros((nDV,)),ArrayLabelReplacer("__FFD_PTS__"), 0, np.ones(nDV), -0.0075,0.0075)
10+
11+
# Parameters ----------------------------------------------------------- #
12+
13+
# The master config `configMaster.cfg` serves as an SU2 adjoint regression test.
14+
# For a correct gradient validation we need to exchange some options
15+
16+
# switch from direct to adjoint mode and adapt settings.
17+
enable_direct = Parameter([""], LabelReplacer("%__DIRECT__"))
18+
enable_adjoint = Parameter([""], LabelReplacer("%__ADJOINT__"))
19+
enable_not_def = Parameter([""], LabelReplacer("%__NOT_DEF__"))
20+
enable_def = Parameter([""], LabelReplacer("%__DEF__"))
21+
22+
# Switch Objective Functions
23+
OF_SpecVar = Parameter([""], LabelReplacer("%__OF_SpecVar__"))
24+
25+
# Evaluations ---------------------------------------------------------- #
26+
27+
# Define a few often used variables
28+
ncores="2"
29+
configMaster="species3_primitiveVenturi.cfg"
30+
meshName="primitiveVenturi.su2"
31+
32+
# Note that correct SU2 version needs to be in PATH
33+
34+
def_command = "SU2_DEF " + configMaster
35+
cfd_command = "mpirun -n " + ncores + " SU2_CFD " + configMaster
36+
37+
cfd_ad_command = "mpirun -n " + ncores + " SU2_CFD_AD " + configMaster
38+
dot_ad_command = "mpirun -n " + ncores + " SU2_DOT_AD " + configMaster
39+
40+
max_tries = 1
41+
42+
# mesh deformation
43+
deform = ExternalRun("DEFORM",def_command,True) # True means sym links are used for addData
44+
deform.setMaxTries(max_tries)
45+
deform.addConfig(configMaster)
46+
deform.addData(meshName)
47+
deform.addExpected("mesh_out.su2")
48+
deform.addParameter(enable_def)
49+
50+
# direct run
51+
direct = ExternalRun("DIRECT",cfd_command,True)
52+
direct.setMaxTries(max_tries)
53+
direct.addConfig(configMaster)
54+
direct.addData("DEFORM/mesh_out.su2",destination=meshName)
55+
direct.addData("solution.csv")
56+
direct.addExpected("restart.csv")
57+
direct.addParameter(enable_direct)
58+
direct.addParameter(enable_not_def)
59+
60+
# adjoint run
61+
adjoint = ExternalRun("ADJOINT",cfd_ad_command,True)
62+
adjoint.setMaxTries(max_tries)
63+
adjoint.addConfig(configMaster)
64+
adjoint.addData("DEFORM/mesh_out.su2", destination=meshName)
65+
# add all primal solution files
66+
adjoint.addData("DIRECT/restart.csv", destination="solution.csv")
67+
adjoint.addExpected("restart_adj_specvar.csv")
68+
adjoint.addParameter(enable_adjoint)
69+
adjoint.addParameter(enable_not_def)
70+
adjoint.addParameter(OF_SpecVar)
71+
72+
# gradient projection
73+
dot = ExternalRun("DOT",dot_ad_command,True)
74+
dot.setMaxTries(max_tries)
75+
dot.addConfig(configMaster)
76+
dot.addData("DEFORM/mesh_out.su2", destination=meshName)
77+
dot.addData("ADJOINT/restart_adj_specvar.csv", destination="solution_adj_specvar.csv")
78+
dot.addExpected("of_grad.csv")
79+
dot.addParameter(enable_def)
80+
dot.addParameter(OF_SpecVar) # necessary for correct file extension
81+
82+
# Functions ------------------------------------------------------------ #
83+
84+
specVar = Function("specVar", "DIRECT/history.csv",LabeledTableReader("\"Species_Variance\""))
85+
specVar.addInputVariable(ffd,"DOT/of_grad.csv",TableReader(None,0,(1,0))) # all rows, col 0, don't read the header
86+
specVar.addValueEvalStep(deform)
87+
specVar.addValueEvalStep(direct)
88+
specVar.addGradientEvalStep(adjoint)
89+
specVar.addGradientEvalStep(dot)
90+
specVar.setDefaultValue(0.0)
91+
92+
# Driver --------------------------------------------------------------- #
93+
94+
driver = ScipyDriver()
95+
#printDocumentation(driver.addObjective)
96+
# min = minimization of OF
97+
# avgT = function to be optimized
98+
# 1.0 = scale, optimizer will see funcVal*scale, Can be used to scale the gradient from of_grad
99+
driver.addObjective("min", specVar, 0.5)
100+
101+
driver.setWorkingDirectory("OPTIM")
102+
#printDocumentation(driver.setEvaluationMode)
103+
# True = parallel evaluation mode
104+
# 2.0 = driver will check every 2sec whether it can start a new eval
105+
driver.setEvaluationMode(False,2.0)
106+
#printDocumentation(driver.setStorageMode)
107+
# True = keep all designs
108+
# DSN_ = folder prefix
109+
driver.setStorageMode(True,"DSN_")
110+
#printDocumentation(driver.setFailureMode)
111+
# SOFT = if func eval fails, just the default val will be taken
112+
driver.setFailureMode("SOFT")
113+
114+
his = open("optim.csv","w",1)
115+
driver.setHistorian(his)
116+
117+
# Optimization, SciPy -------------------------------------------------- #
118+
119+
import scipy.optimize
120+
121+
driver.preprocess()
122+
x = driver.getInitial()
123+
124+
options = {'disp': True, 'ftol': 1e-10, 'maxiter': 25}
125+
126+
optimum = scipy.optimize.minimize(driver.fun, x, method="SLSQP", jac=driver.grad,\
127+
constraints=driver.getConstraints(), bounds=driver.getBounds(), options=options)
128+
129+
his.close()
130+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../1__FFD-box-writing/mesh_out.su2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../solution.csv
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,235 @@
1+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2+
% %
3+
% SU2 configuration file %
4+
% Case description: Species mixing with 3 species, i.e. 2 transport equations %
5+
% Author: T. Kattmann %
6+
% Institution: Bosch Thermotechniek B.V. %
7+
% Date: 2021/10/14 %
8+
% File Version 7.2.1 "Blackbird" %
9+
% %
10+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
11+
12+
% ------------- DIRECT, ADJOINT, AND LINEARIZED PROBLEM DEFINITION ------------%
13+
%
14+
SOLVER= INC_RANS
15+
KIND_TURB_MODEL= SST
16+
%
17+
%__OF_SpecVar__OBJECTIVE_FUNCTION= SURFACE_SPECIES_VARIANCE
18+
%__OF_SpecVar__OBJECTIVE_WEIGHT= 1.0
19+
%
20+
% ---------------- INCOMPRESSIBLE FLOW CONDITION DEFINITION -------------------%
21+
%
22+
INC_DENSITY_MODEL= CONSTANT
23+
INC_DENSITY_INIT= 1.1766
24+
%
25+
INC_VELOCITY_INIT= ( 1.00, 0.0, 0.0 )
26+
%
27+
INC_ENERGY_EQUATION= YES
28+
INC_TEMPERATURE_INIT= 300.0
29+
%
30+
INC_NONDIM= INITIAL_VALUES
31+
%
32+
% -------------------- FLUID PROPERTIES ------------------------------------- %
33+
%
34+
FLUID_MODEL= CONSTANT_DENSITY
35+
%
36+
CONDUCTIVITY_MODEL= CONSTANT_CONDUCTIVITY
37+
THERMAL_CONDUCTIVITY_CONSTANT= 0.0357
38+
%
39+
PRANDTL_LAM= 0.72
40+
TURBULENT_CONDUCTIVITY_MODEL= NONE
41+
PRANDTL_TURB= 0.90
42+
%
43+
VISCOSITY_MODEL= CONSTANT_VISCOSITY
44+
MU_CONSTANT= 1.716E-5
45+
%
46+
% -------------------- BOUNDARY CONDITION DEFINITION --------------------------%
47+
%
48+
MARKER_HEATFLUX= ( wall, 0.0 )
49+
%__NOT_DEF__MARKER_SYM= ( axis )
50+
%__DEF__MARKER_SYM= (axis, outlet)
51+
%
52+
SPECIFIED_INLET_PROFILE= NO
53+
INLET_FILENAME= inlet_venturi.dat
54+
INC_INLET_TYPE= VELOCITY_INLET VELOCITY_INLET
55+
MARKER_INLET= ( gas_inlet, 300, 1.0, 1.0, 0.0, 0.0,\
56+
air_axial_inlet, 300, 1.0, 0.0, -1.0, 0.0 )
57+
SPECIES_USE_STRONG_BC= NO
58+
MARKER_INLET_SPECIES= (gas_inlet, 0.5, 0.5,\
59+
air_axial_inlet, 0.6, 0.0 )
60+
%
61+
%__NOT_DEF__INC_OUTLET_TYPE= PRESSURE_OUTLET
62+
%__NOT_DEF__MARKER_OUTLET= ( outlet, 0.0 )
63+
%
64+
% ------------- COMMON PARAMETERS DEFINING THE NUMERICAL METHOD ---------------%
65+
%
66+
NUM_METHOD_GRAD= WEIGHTED_LEAST_SQUARES
67+
%
68+
%__DIRECT__CFL_NUMBER= 2000
69+
%__ADJOINT__CFL_NUMBER= 500
70+
CFL_REDUCTION_SPECIES= 1.0
71+
CFL_REDUCTION_TURB= 1.0
72+
%
73+
% Run commented Iter for good results
74+
ITER= 500
75+
%
76+
% ------------------------ LINEAR SOLVER DEFINITION ---------------------------%
77+
%
78+
LINEAR_SOLVER= FGMRES
79+
LINEAR_SOLVER_PREC= ILU
80+
LINEAR_SOLVER_ERROR= 1E-8
81+
%__DIRECT__LINEAR_SOLVER_ITER= 5
82+
%__ADJOINT__LINEAR_SOLVER_ITER= 20
83+
84+
% -------------------- FLOW NUMERICAL METHOD DEFINITION -----------------------%
85+
%
86+
CONV_NUM_METHOD_FLOW= FDS
87+
MUSCL_FLOW= YES
88+
SLOPE_LIMITER_FLOW = NONE
89+
TIME_DISCRE_FLOW= EULER_IMPLICIT
90+
%
91+
% -------------------- SCALAR TRANSPORT ---------------------------------------%
92+
%
93+
KIND_SCALAR_MODEL= PASSIVE_SCALAR
94+
DIFFUSIVITY_MODEL= CONSTANT_DIFFUSIVITY
95+
DIFFUSIVITY_CONSTANT= 0.001
96+
%
97+
CONV_NUM_METHOD_SPECIES= SCALAR_UPWIND
98+
MUSCL_SPECIES= NO
99+
SLOPE_LIMITER_SPECIES = NONE
100+
%
101+
TIME_DISCRE_SPECIES= EULER_IMPLICIT
102+
%
103+
SPECIES_INIT= 1.0, 0.0
104+
SPECIES_CLIPPING= YES
105+
SPECIES_CLIPPING_MIN= 0.0, 0.0
106+
SPECIES_CLIPPING_MAX= 1.0, 1.0
107+
%
108+
% -------------------- TURBULENT TRANSPORT ---------------------------------------%
109+
%
110+
CONV_NUM_METHOD_TURB= SCALAR_UPWIND
111+
MUSCL_TURB= NO
112+
%
113+
% --------------------------- CONVERGENCE PARAMETERS --------------------------%
114+
%
115+
CONV_FIELD= RMS_PRESSURE, RMS_VELOCITY-X, RMS_VELOCITY-Y, RMS_TKE, RMS_SPECIES
116+
CONV_RESIDUAL_MINVAL= -18
117+
CONV_STARTITER= 10
118+
%
119+
% ------------------------- INPUT/OUTPUT INFORMATION --------------------------%
120+
%
121+
MESH_FILENAME= primitiveVenturi.su2
122+
%
123+
%__DIRECT__SCREEN_OUTPUT= INNER_ITER WALL_TIME RMS_PRESSURE RMS_VELOCITY-X RMS_VELOCITY-Y RMS_TKE RMS_DISSIPATION RMS_SPECIES_0 RMS_SPECIES_1 LINSOL_ITER LINSOL_RESIDUAL LINSOL_ITER_TURB LINSOL_RESIDUAL_TURB LINSOL_ITER_SPECIES LINSOL_RESIDUAL_SPECIES SURFACE_SPECIES_VARIANCE
124+
%__ADJOINT__SCREEN_OUTPUT= INNER_ITER WALL_TIME RMS_ADJ_PRESSURE RMS_ADJ_VELOCITY-X RMS_ADJ_VELOCITY-Y RMS_ADJ_TKE RMS_ADJ_DISSIPATION RMS_ADJ_SPECIES_0 RMS_ADJ_SPECIES_1
125+
SCREEN_WRT_FREQ_INNER= 10
126+
%
127+
HISTORY_OUTPUT= ITER RMS_RES LINSOL SPECIES_COEFF SPECIES_COEFF_SURF
128+
CONV_FILENAME= history
129+
MARKER_ANALYZE= outlet
130+
MARKER_ANALYZE_AVERAGE= MASSFLUX
131+
%
132+
OUTPUT_FILES= RESTART_ASCII, PARAVIEW_MULTIBLOCK
133+
VOLUME_OUTPUT= RESIDUAL, PRIMITIVE
134+
OUTPUT_WRT_FREQ= 1000
135+
%
136+
GRAD_OBJFUNC_FILENAME= of_grad.csv
137+
%
138+
%__DIRECT__RESTART_SOL= YES
139+
READ_BINARY_RESTART= NO
140+
RESTART_FILENAME= restart
141+
SOLUTION_FILENAME= solution
142+
%
143+
WRT_PERFORMANCE= YES
144+
OUTPUT_PRECISION= 16
145+
%
146+
% -------------------- FREE-FORM DEFORMATION PARAMETERS -----------------------%
147+
%
148+
% Tolerance of the Free-Form Deformation point inversion
149+
FFD_TOLERANCE= 1E-10
150+
%
151+
% Maximum number of iterations in the Free-Form Deformation point inversion
152+
FFD_ITERATIONS= 500
153+
%
154+
% FFD box definition: 3D case (FFD_BoxTag, X1, Y1, Z1, X2, Y2, Z2, X3, Y3, Z3, X4, Y4, Z4,
155+
% X5, Y5, Z5, X6, Y6, Z6, X7, Y7, Z7, X8, Y8, Z8)
156+
% 2D case (FFD_BoxTag, X1, Y1, 0.0, X2, Y2, 0.0, X3, Y3, 0.0, X4, Y4, 0.0,
157+
% 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)
158+
% Start at the lowest leftest corner and turn counter-clockwise
159+
FFD_DEFINITION= (BOX, \
160+
0.065, 0.01, 0.0, \
161+
0.15, 0.01, 0.0 \
162+
0.15, 0.02, 0.0, \
163+
0.065, 0.02, 0.0, \
164+
0.0, 0.0 ,0.0, \
165+
0.0 ,0.0, 0.0, \
166+
0.0, 0.0, 0.0, \
167+
0.0, 0.0, 0.0 )
168+
%
169+
% FFD box degree: 3D case (i_degree, j_degree, k_degree)
170+
% 2D case (i_degree, j_degree, 0)
171+
FFD_DEGREE= (6, 1, 0)
172+
%
173+
% Surface grid continuity at the intersection with the faces of the FFD boxes.
174+
% To keep a particular level of surface continuity, SU2 automatically freezes the right
175+
% number of control point planes (NO_DERIVATIVE, 1ST_DERIVATIVE, 2ND_DERIVATIVE, USER_INPUT)
176+
FFD_CONTINUITY= USER_INPUT
177+
%
178+
% Definition of the FFD planes to be frozen in the FFD (x,y,z).
179+
% Value from 0 FFD degree in that direction. Pick a value larger than degree if you don't want to fix any plane.
180+
%FFD_FIX_I= (0,2,3)
181+
%FFD_FIX_J= (0,2,3)
182+
%FFD_FIX_K= (0,2,3)
183+
184+
% ----------------------- DESIGN VARIABLE PARAMETERS --------------------------%
185+
%
186+
DV_KIND= FFD_CONTROL_POINT_2D, FFD_CONTROL_POINT_2D, FFD_CONTROL_POINT_2D, FFD_CONTROL_POINT_2D, FFD_CONTROL_POINT_2D, FFD_CONTROL_POINT_2D, FFD_CONTROL_POINT_2D, FFD_CONTROL_POINT_2D, FFD_CONTROL_POINT_2D, FFD_CONTROL_POINT_2D
187+
%
188+
% Marker of the surface in which we are going apply the shape deformation
189+
% NOTE: for deformation the outlet should be a MARKER_SYM to hinder the mesh being ripped apart.
190+
DV_MARKER= ( wall )
191+
%
192+
% Parameters of the shape deformation
193+
% - FFD_SETTING ( 1.0 )
194+
% - FFD_CONTROL_POINT ( FFD_BoxTag, i_Ind, j_Ind, k_Ind, x_Disp, y_Disp, z_Disp )
195+
DV_PARAM= (BOX, 2, 0, 0.0, 1.0); (BOX, 3, 0, 0.0, 1.0); (BOX, 4, 0, 0.0, 1.0); (BOX, 5, 0, 0.0, 1.0); (BOX, 6, 0, 0.0, 1.0); (BOX, 2, 1, 0.0, 1.0); (BOX, 3, 1, 0.0, 1.0); (BOX, 4, 1, 0.0, 1.0); (BOX, 5, 1, 0.0, 1.0); (BOX, 6, 1, 0.0, 1.0)
196+
% Excluded FFD points that are fixed to keep a nice geometry
197+
%DV_PARAM= (BOX, 0, 0, 0.0, 1.0); (BOX, 1, 0, 0.0, 1.0); (BOX, 0, 1, 0.0, 1.0); (BOX, 1, 1, 0.0, 1.0);
198+
%
199+
% Value of the shape deformation
200+
% first row: lower row y-direction
201+
% second row: upper row y-direction
202+
%DV_VALUE= 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0
203+
DV_VALUE= __FFD_PTS__
204+
%
205+
% ------------------------ GRID DEFORMATION PARAMETERS ------------------------%
206+
%
207+
% Linear solver or smoother for implicit formulations (FGMRES, RESTARTED_FGMRES, BCGSTAB)
208+
DEFORM_LINEAR_SOLVER= FGMRES
209+
%
210+
% Preconditioner of the Krylov linear solver (ILU, LU_SGS, JACOBI)
211+
DEFORM_LINEAR_SOLVER_PREC= ILU
212+
%
213+
% Number of smoothing iterations for mesh deformation
214+
DEFORM_LINEAR_SOLVER_ITER= 1000
215+
%
216+
% Number of nonlinear deformation iterations (surface deformation increments)
217+
DEFORM_NONLINEAR_ITER= 1
218+
%
219+
% Minimum residual criteria for the linear solver convergence of grid deformation
220+
DEFORM_LINEAR_SOLVER_ERROR= 1E-14
221+
%
222+
% Print the residuals during mesh deformation to the console (YES, NO)
223+
DEFORM_CONSOLE_OUTPUT= YES
224+
%
225+
% Deformation coefficient (linear elasticity limits from -1.0 to 0.5, a larger
226+
% value is also possible)
227+
DEFORM_COEFF = 0.0
228+
%
229+
% Type of element stiffness imposed for FEA mesh deformation (INVERSE_VOLUME,
230+
% WALL_DISTANCE, CONSTANT_STIFFNESS)
231+
DEFORM_STIFFNESS_TYPE= WALL_DISTANCE
232+
%
233+
% Deform the grid only close to the surface. It is possible to specify how much
234+
% of the volumetric grid is going to be deformed in meters or inches (1E6 by default)
235+
DEFORM_LIMIT = 1E6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2+
% %
3+
% SU2 configuration file %
4+
% Case description: Discrete Adjiont Species mixing with 3 species %
5+
% Author: T. Kattmann %
6+
% Institution: Bosch Thermotechniek B.V. %
7+
% Date: 2021/10/14 %
8+
% File Version 7.2.1 "Blackbird" %
9+
% %
10+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
11+
12+
% ------------- DIRECT, ADJOINT, AND LINEARIZED PROBLEM DEFINITION ------------%
13+
%
14+
SOLVER= INC_RANS
15+
KIND_TURB_MODEL= SST
16+
%
17+
OBJECTIVE_FUNCTION= SURFACE_SPECIES_VARIANCE
18+
OBJECTIVE_WEIGHT= 1.0
19+
%
20+
% ---------------- INCOMPRESSIBLE FLOW CONDITION DEFINITION -------------------%
21+
%
22+
INC_DENSITY_MODEL= CONSTANT
23+
INC_DENSITY_INIT= 1.1766
24+
%
25+
INC_VELOCITY_INIT= ( 1.00, 0.0, 0.0 )
26+
%
27+
INC_ENERGY_EQUATION= YES
28+
INC_TEMPERATURE_INIT= 300.0
29+
%
30+
INC_NONDIM= INITIAL_VALUES
31+
%
32+
% -------------------- FLUID PROPERTIES ------------------------------------- %
33+
%
34+
FLUID_MODEL= CONSTANT_DENSITY
35+
%
36+
CONDUCTIVITY_MODEL= CONSTANT_CONDUCTIVITY
37+
THERMAL_CONDUCTIVITY_CONSTANT= 0.0357
38+
%
39+
PRANDTL_LAM= 0.72
40+
TURBULENT_CONDUCTIVITY_MODEL= NONE
41+
PRANDTL_TURB= 0.90
42+
%
43+
VISCOSITY_MODEL= CONSTANT_VISCOSITY
44+
MU_CONSTANT= 1.716E-5
45+
%
46+
% -------------------- BOUNDARY CONDITION DEFINITION --------------------------%
47+
%
48+
MARKER_HEATFLUX= ( wall, 0.0 )
49+
MARKER_SYM= ( axis )
50+
%
51+
SPECIFIED_INLET_PROFILE= NO
52+
INLET_FILENAME= inlet_venturi.dat
53+
INC_INLET_TYPE= VELOCITY_INLET VELOCITY_INLET
54+
MARKER_INLET= ( gas_inlet, 300, 1.0, 1.0, 0.0, 0.0,\
55+
air_axial_inlet, 300, 1.0, 0.0, -1.0, 0.0 )
56+
SPECIES_USE_STRONG_BC= NO
57+
MARKER_INLET_SPECIES= (gas_inlet, 0.5, 0.5,\
58+
air_axial_inlet, 0.6, 0.0 )
59+
%
60+
INC_OUTLET_TYPE= PRESSURE_OUTLET
61+
MARKER_OUTLET= ( outlet, 0.0 )
62+
%
63+
% ------------- COMMON PARAMETERS DEFINING THE NUMERICAL METHOD ---------------%
64+
%
65+
NUM_METHOD_GRAD= WEIGHTED_LEAST_SQUARES
66+
%
67+
% Note that the CFL-Number was dramatically reduced compared to the primal.
68+
% This was necessary to ensure proper convergence. It is not necessary to do
69+
% this for a reasonably accurate gradient validation though.
70+
CFL_NUMBER= 500
71+
CFL_REDUCTION_SPECIES= 1.0
72+
CFL_REDUCTION_TURB= 1.0
73+
%
74+
% Run commented Iter for good results
75+
ITER= 50
76+
%
77+
% ------------------------ LINEAR SOLVER DEFINITION ---------------------------%
78+
%
79+
LINEAR_SOLVER= FGMRES
80+
LINEAR_SOLVER_PREC= ILU
81+
LINEAR_SOLVER_ERROR= 1E-8
82+
LINEAR_SOLVER_ITER= 20
83+
84+
% -------------------- FLOW NUMERICAL METHOD DEFINITION -----------------------%
85+
%
86+
CONV_NUM_METHOD_FLOW= FDS
87+
MUSCL_FLOW= YES
88+
SLOPE_LIMITER_FLOW = NONE
89+
TIME_DISCRE_FLOW= EULER_IMPLICIT
90+
%
91+
% -------------------- SCALAR TRANSPORT ---------------------------------------%
92+
%
93+
KIND_SCALAR_MODEL= PASSIVE_SCALAR
94+
DIFFUSIVITY_MODEL= CONSTANT_DIFFUSIVITY
95+
DIFFUSIVITY_CONSTANT= 0.001
96+
%
97+
CONV_NUM_METHOD_SPECIES= SCALAR_UPWIND
98+
MUSCL_SPECIES= NO
99+
SLOPE_LIMITER_SPECIES = NONE
100+
%
101+
TIME_DISCRE_SPECIES= EULER_IMPLICIT
102+
%
103+
SPECIES_INIT= 1.0, 0.0
104+
SPECIES_CLIPPING= YES
105+
SPECIES_CLIPPING_MIN= 0.0, 0.0
106+
SPECIES_CLIPPING_MAX= 1.0, 1.0
107+
%
108+
% -------------------- TURBULENT TRANSPORT ---------------------------------------%
109+
%
110+
CONV_NUM_METHOD_TURB= SCALAR_UPWIND
111+
MUSCL_TURB= NO
112+
%
113+
% --------------------------- CONVERGENCE PARAMETERS --------------------------%
114+
%
115+
CONV_FIELD= RMS_PRESSURE, RMS_VELOCITY-X, RMS_VELOCITY-Y, RMS_TKE, RMS_SPECIES
116+
CONV_RESIDUAL_MINVAL= -18
117+
CONV_STARTITER= 10
118+
%
119+
% ------------------------- INPUT/OUTPUT INFORMATION --------------------------%
120+
%
121+
MESH_FILENAME= primitiveVenturi.su2
122+
%
123+
SCREEN_OUTPUT= INNER_ITER WALL_TIME RMS_ADJ_PRESSURE RMS_ADJ_VELOCITY-X RMS_ADJ_VELOCITY-Y RMS_ADJ_TKE RMS_ADJ_DISSIPATION RMS_ADJ_SPECIES_0 RMS_ADJ_SPECIES_1
124+
SCREEN_WRT_FREQ_INNER= 10
125+
%
126+
HISTORY_OUTPUT= ITER RMS_RES LINSOL
127+
CONV_FILENAME= history
128+
MARKER_ANALYZE= outlet
129+
MARKER_ANALYZE_AVERAGE= MASSFLUX
130+
%
131+
OUTPUT_FILES= RESTART_ASCII, PARAVIEW_MULTIBLOCK
132+
VOLUME_OUTPUT= RESIDUAL, PRIMITIVE
133+
OUTPUT_WRT_FREQ= 1000
134+
%
135+
GRAD_OBJFUNC_FILENAME= of_grad.csv
136+
%
137+
RESTART_SOL= NO
138+
READ_BINARY_RESTART= NO
139+
RESTART_FILENAME= restart
140+
SOLUTION_FILENAME= solution
141+
%
142+
WRT_PERFORMANCE= YES
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
// ----------------------------------------------------------------------------------- //
2+
// Tobias Kattmann, 09.09.2021, 2D Venturi Primitive for faster debugging
3+
// ----------------------------------------------------------------------------------- //
4+
5+
// Evoque Meshing Algorithm?
6+
Do_Meshing= 1; // 0=false, 1=true
7+
// Write Mesh files in .su2 format
8+
Write_mesh= 1; // 0=false, 1=true
9+
10+
// Geometric inputs
11+
gas_inlet_diameter= 0.015;
12+
air_inlet_diameter= 0.015;
13+
gas_tube_length=0.045;
14+
air_tube_length=0.045;
15+
downstream_length= 0.09;
16+
17+
// Mesh sizing inputs
18+
Nwall= 30; // Nodes for all spacings
19+
gridsize= 0.1; // Later on not important as structured mesh is achieved
20+
21+
// ----------------------------------------------------------------------------------- //
22+
// POINTS
23+
24+
// Starting in the origin, which is the most low-left point, and going clockwise.
25+
// Gas inlet
26+
Point(1) = {0, 0, 0, gridsize};
27+
Point(2) = {0, gas_inlet_diameter, 0, gridsize};
28+
//
29+
Point(3) = {gas_tube_length, gas_inlet_diameter, 0, gridsize};
30+
// Air inlet
31+
Point(4) = {gas_tube_length, gas_inlet_diameter+air_tube_length, 0, gridsize};
32+
Point(5) = {gas_tube_length+air_inlet_diameter, gas_inlet_diameter+air_tube_length, 0, gridsize};
33+
//
34+
Point(6) = {gas_tube_length+air_inlet_diameter, gas_inlet_diameter, 0, gridsize};
35+
// outlet
36+
Point(7) = {gas_tube_length+air_inlet_diameter+downstream_length, gas_inlet_diameter, 0, gridsize};
37+
Point(8) = {gas_tube_length+air_inlet_diameter+downstream_length, 0, 0, gridsize};
38+
//
39+
Point(9) = {gas_tube_length+air_inlet_diameter, 0, 0, gridsize};
40+
Point(10) = {gas_tube_length, 0, 0, gridsize};
41+
42+
// ----------------------------------------------------------------------------------- //
43+
// LINES
44+
45+
// Gas inlet box, clockwise
46+
Line(1) = {1,2};
47+
Line(2) = {2,3};
48+
Line(3) = {3,10};
49+
Line(4) = {10,1};
50+
51+
// air inlet box, clockwise
52+
Line(5) = {3,4};
53+
Line(6) = {4,5};
54+
Line(7) = {5,6};
55+
Line(8) = {6,3};
56+
57+
// downstream box, clockwise
58+
Line(9) = {6,7};
59+
Line(10) = {7,8};
60+
Line(11) = {8,9};
61+
Line(12) = {9,6};
62+
63+
// remaining lower middle box line
64+
Line(13) = {9,10};
65+
66+
// ----------------------------------------------------------------------------------- //
67+
// SURFACES (and Lineloops)
68+
Curve Loop(1) = {1, 2, 3, 4}; Plane Surface(1) = {1}; // Gas inlet box
69+
Curve Loop(2) = {5, 6, 7, 8}; Plane Surface(2) = {2}; // air inlet box
70+
Curve Loop(3) = {9, 10, 11, 12}; Plane Surface(3) = {3}; // downstream box
71+
Curve Loop(4) = {8, 3, -13, 12}; Plane Surface(4) = {4}; // middle box
72+
73+
// make structured mesh with transfinite Lines
74+
// NOTE: The usage of Nwall and the progression has to be tuned again for any changes.
75+
Transfinite Line{1,-3,12,-10} = Nwall Using Progression 0.9; // Spacing to the wall of the long tube, progression towards top wall
76+
Transfinite Line{2,-4} = Nwall Using Progression 0.9; // Downstream spacing of gas inlet, progression towards air inlet
77+
78+
Transfinite Line{6,-8,-13} = Nwall Using Bump 0.1; // Spacing to the wall of the air inlet tube, progression towards side walls
79+
Transfinite Line{-5,7} = Nwall Using Progression 0.9; // Downstream spacing of air inlet, progression towards gas inlet
80+
81+
Transfinite Line{-9,11} = Nwall Using Progression 0.9; // Downstream spacing of air inlet, progressio
82+
83+
// ----------------------------------------------------------------------------------- //
84+
// PHYSICAL GROUPS
85+
86+
Physical Line("gas_inlet") = {1};
87+
Physical Line("air_axial_inlet") = {6};
88+
Physical Line("outlet") = {10};
89+
Physical Line("axis") = {4,13,11};
90+
Physical Line("wall") = {2,5,7,9};
91+
92+
Physical Surface("fluid") = {1,2,3,4};
93+
94+
// ----------------------------------------------------------------------------------- //
95+
// Meshing
96+
Transfinite Surface "*";
97+
Recombine Surface "*";
98+
99+
If (Do_Meshing == 1)
100+
Mesh 1; Mesh 2;
101+
EndIf
102+
103+
// ----------------------------------------------------------------------------------- //
104+
// Write .su2 meshfile
105+
If (Write_mesh == 1)
106+
107+
Mesh.Format = 42; // .su2 mesh format,
108+
Save "primitiveVenturi.su2";
109+
110+
EndIf
111+

‎incompressible_flow/Inc_Species_Transport/primitiveVenturi.su2

+7,178
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
# ------------------------------------------------------------------------------------------------ #
2+
# T. Kattmann, 28.09.2021, restart_validation.sh
3+
#
4+
# This script validates that the steady restarts work perfectly in SU2.
5+
# For the primal-only restart and the primal restart for the adjoint.
6+
# ------------------------------------------------------------------------------------------------ #
7+
8+
# Prepare useful variable-strings that run primal and adjoint code
9+
code_dir=$SU2_RUN
10+
num_cores=1
11+
config="species3_primitiveVenturi.cfg"
12+
adapt_config="adapt_fluid.cfg"
13+
# Iteration number at which to compare restart with full iter. Note this value is the actual screen iteration number, so for FullIter we have to set ITER=compare_iter+1.
14+
compare_iter=10
15+
echo "ITER: $compare_iter"
16+
compare_iter_plus1=$((compare_iter + 1))
17+
18+
# ITER for SingleZone-steady, OUTER_ITER for multizone-steady
19+
iter_string="ITER"
20+
21+
run_command_primal=" mpirun -n $num_cores $code_dir/SU2_CFD $adapt_config"
22+
run_command_adjoint=" mpirun -n $num_cores $code_dir/SU2_CFD_AD $adapt_config"
23+
24+
echo $run_command_primal
25+
echo $run_command_adjoint
26+
27+
# Extract MESH_FILENAME= name from the provided $config . This is necessary in order to link it into the folders
28+
# The "^" in the grep signals the beginning of the line so that commented out lines are disregarded ( https://unix.stackexchange.com/questions/60994/how-to-grep-lines-which-does-not-begin-with-or )
29+
# The cut command extract everyhing between the first and next "="-char ( https://stackoverflow.com/questions/15148796/get-string-after-character )
30+
# The xargs command trims any unnecessary whitespaces from the string ( https://stackoverflow.com/questions/369758/how-to-trim-whitespace-from-a-bash-variable )
31+
mesh=$(grep "^MESH_FILENAME=" $config | cut -d "=" -f2 | xargs)
32+
echo $mesh
33+
34+
# set folder names
35+
FullIter_dir="1__FullIter"
36+
FullMinus1Iter_dir="2__FullMinus1Iter"
37+
PrimalRestart_dir="3__PrimalRestart"
38+
AdjointRestart_dir="4__AdjointRestart"
39+
40+
echo "Deleting old folders for a fresh test."
41+
rm -r $FullIter_dir $FullMinus1Iter_dir $PrimalRestart_dir $AdjointRestart_dir
42+
43+
link_config="ln -s ../*.cfg ."
44+
echo $link_config
45+
link_mesh="ln -s ../$mesh"
46+
echo $link_mesh
47+
48+
link_restart0="ln -s ../$FullMinus1Iter_dir/restart.csv solution.csv"
49+
link_restart1="ln -s ../$FullMinus1Iter_dir/restart.csv solution.csv"
50+
51+
# ------------------------------------------------------------------------------------------------ #
52+
# Run FullIter and FullMinus1Iter in parallel
53+
54+
mkdir $FullIter_dir
55+
cd $FullIter_dir
56+
$link_config
57+
$link_mesh
58+
# Change ITER number. The ^ ensures that the string start at the beginning of the line, such that other *ITER= are not changed
59+
sed "s/^$iter_string=.*/$iter_string=$compare_iter_plus1/g" $config > $adapt_config
60+
echo "Running full primal."
61+
$run_command_primal > CFD.log &
62+
cd ..
63+
64+
mkdir $FullMinus1Iter_dir
65+
cd $FullMinus1Iter_dir
66+
$link_config
67+
$link_mesh
68+
# Change ITER number
69+
sed "s/^$iter_string=.*/$iter_string=$compare_iter/g" $config > $adapt_config
70+
echo "Running full-1 primal."
71+
$run_command_primal > CFD.log
72+
cd ..
73+
74+
# ------------------------------------------------------------------------------------------------ #
75+
# Run primal and adjoint restart in parallel
76+
77+
mkdir $PrimalRestart_dir
78+
cd $PrimalRestart_dir
79+
$link_config
80+
$link_mesh
81+
$link_restart0
82+
$link_restart1
83+
# Change ITER number to 1
84+
sed "s/^$iter_string=.*/$iter_string=1/g" $config > $adapt_config
85+
sed -i "s/RESTART_SOL=.*/RESTART_SOL= YES/g" $adapt_config
86+
#sed -i "s/RESTART_ITER=.*/RESTART_ITER= $compare_iter/g" $adapt_config # only applies to unsteady simulations
87+
echo "Running restarted primal."
88+
$run_command_primal > CFD.log &
89+
cd ..
90+
91+
mkdir $AdjointRestart_dir
92+
cd $AdjointRestart_dir
93+
$link_config
94+
$link_mesh
95+
$link_restart0
96+
$link_restart1
97+
# Change ITER number
98+
sed "s/^$iter_string=.*/$iter_string=1/g" $config > $adapt_config
99+
echo "Running adjoint."
100+
$run_command_adjoint > CFD_AD.log
101+
cd ..
102+
103+
104+
# ------------------------------------------------------------------------------------------------ #
105+
# Postproces results: Print residuals to screen. Remove delimiter using sed and the xargs cuts unnecessary spaces
106+
delimiter=","
107+
remove_delimiter="sed "s/$delimiter//g""
108+
history_file="history.csv"
109+
tail -n 1 $FullIter_dir/$history_file | $remove_delimiter | xargs > output.txt
110+
tail -n 1 $PrimalRestart_dir/$history_file | $remove_delimiter | xargs >> output.txt
111+
delimiter="|"
112+
remove_delimiter="sed "s/$delimiter//g""
113+
# retrieve line number
114+
adj_lineNumber=$(sed -n '/rms_Flow/=' $AdjointRestart_dir/CFD_AD.log)
115+
# $((..)) necessary to expand number
116+
sed -n $((adj_lineNumber + 2))p $AdjointRestart_dir/CFD_AD.log | $remove_delimiter | xargs >> output.txt
117+
cat output.txt

‎incompressible_flow/Inc_Species_Transport/solution.csv

+3,511
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2+
% %
3+
% SU2 configuration file %
4+
% Case description: Species mixing with 3 species, i.e. 2 transport equations %
5+
% Author: T. Kattmann %
6+
% Institution: Bosch Thermotechniek B.V. %
7+
% Date: 2021/10/14 %
8+
% File Version 7.2.1 "Blackbird" %
9+
% %
10+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
11+
12+
% ------------- DIRECT, ADJOINT, AND LINEARIZED PROBLEM DEFINITION ------------%
13+
%
14+
SOLVER= INC_RANS
15+
KIND_TURB_MODEL= SST
16+
%
17+
% ---------------- INCOMPRESSIBLE FLOW CONDITION DEFINITION -------------------%
18+
%
19+
INC_DENSITY_MODEL= CONSTANT
20+
INC_DENSITY_INIT= 1.1766
21+
%
22+
INC_VELOCITY_INIT= ( 1.00, 0.0, 0.0 )
23+
%
24+
INC_ENERGY_EQUATION= YES
25+
INC_TEMPERATURE_INIT= 300.0
26+
%
27+
INC_NONDIM= INITIAL_VALUES
28+
%
29+
% -------------------- FLUID PROPERTIES ------------------------------------- %
30+
%
31+
FLUID_MODEL= CONSTANT_DENSITY
32+
%
33+
CONDUCTIVITY_MODEL= CONSTANT_CONDUCTIVITY
34+
THERMAL_CONDUCTIVITY_CONSTANT= 0.0357
35+
%
36+
PRANDTL_LAM= 0.72
37+
TURBULENT_CONDUCTIVITY_MODEL= NONE
38+
PRANDTL_TURB= 0.90
39+
%
40+
VISCOSITY_MODEL= CONSTANT_VISCOSITY
41+
MU_CONSTANT= 1.716E-5
42+
%
43+
% -------------------- BOUNDARY CONDITION DEFINITION --------------------------%
44+
%
45+
MARKER_HEATFLUX= ( wall, 0.0 )
46+
MARKER_SYM= ( axis )
47+
%
48+
SPECIFIED_INLET_PROFILE= NO
49+
INLET_FILENAME= inlet_venturi.dat
50+
INC_INLET_TYPE= VELOCITY_INLET VELOCITY_INLET
51+
MARKER_INLET= ( gas_inlet, 300, 1.0, 1.0, 0.0, 0.0,\
52+
air_axial_inlet, 300, 1.0, 0.0, -1.0, 0.0 )
53+
SPECIES_USE_STRONG_BC= NO
54+
MARKER_INLET_SPECIES= (gas_inlet, 0.5, 0.5,\
55+
air_axial_inlet, 0.6, 0.0 )
56+
%
57+
INC_OUTLET_TYPE= PRESSURE_OUTLET
58+
MARKER_OUTLET= ( outlet, 0.0 )
59+
%
60+
% ------------- COMMON PARAMETERS DEFINING THE NUMERICAL METHOD ---------------%
61+
%
62+
NUM_METHOD_GRAD= WEIGHTED_LEAST_SQUARES
63+
%
64+
CFL_NUMBER= 2000
65+
CFL_REDUCTION_SPECIES= 1.0
66+
CFL_REDUCTION_TURB= 1.0
67+
%
68+
% Run commented Iter for good results
69+
ITER= 1000
70+
%
71+
% ------------------------ LINEAR SOLVER DEFINITION ---------------------------%
72+
%
73+
LINEAR_SOLVER= FGMRES
74+
LINEAR_SOLVER_PREC= ILU
75+
LINEAR_SOLVER_ERROR= 1E-8
76+
LINEAR_SOLVER_ITER= 5
77+
78+
% -------------------- FLOW NUMERICAL METHOD DEFINITION -----------------------%
79+
%
80+
CONV_NUM_METHOD_FLOW= FDS
81+
MUSCL_FLOW= YES
82+
SLOPE_LIMITER_FLOW = NONE
83+
TIME_DISCRE_FLOW= EULER_IMPLICIT
84+
%
85+
% -------------------- SCALAR TRANSPORT ---------------------------------------%
86+
%
87+
KIND_SCALAR_MODEL= PASSIVE_SCALAR
88+
DIFFUSIVITY_MODEL= CONSTANT_DIFFUSIVITY
89+
DIFFUSIVITY_CONSTANT= 0.001
90+
%
91+
CONV_NUM_METHOD_SPECIES= SCALAR_UPWIND
92+
MUSCL_SPECIES= NO
93+
SLOPE_LIMITER_SPECIES = NONE
94+
%
95+
TIME_DISCRE_SPECIES= EULER_IMPLICIT
96+
%
97+
SPECIES_INIT= 1.0, 0.0
98+
SPECIES_CLIPPING= YES
99+
SPECIES_CLIPPING_MIN= 0.0, 0.0
100+
SPECIES_CLIPPING_MAX= 1.0, 1.0
101+
%
102+
% -------------------- TURBULENT TRANSPORT ---------------------------------------%
103+
%
104+
CONV_NUM_METHOD_TURB= SCALAR_UPWIND
105+
MUSCL_TURB= NO
106+
%
107+
% --------------------------- CONVERGENCE PARAMETERS --------------------------%
108+
%
109+
CONV_FIELD= RMS_PRESSURE, RMS_VELOCITY-X, RMS_VELOCITY-Y, RMS_TKE, RMS_SPECIES
110+
CONV_RESIDUAL_MINVAL= -18
111+
CONV_STARTITER= 10
112+
%
113+
% ------------------------- INPUT/OUTPUT INFORMATION --------------------------%
114+
%
115+
MESH_FILENAME= primitiveVenturi.su2
116+
%
117+
SCREEN_OUTPUT= INNER_ITER WALL_TIME \
118+
RMS_PRESSURE RMS_VELOCITY-X RMS_VELOCITY-Y RMS_TKE RMS_DISSIPATION RMS_SPECIES_0 RMS_SPECIES_1 \
119+
LINSOL_ITER LINSOL_RESIDUAL \
120+
LINSOL_ITER_TURB LINSOL_RESIDUAL_TURB \
121+
LINSOL_ITER_SPECIES LINSOL_RESIDUAL_SPECIES \
122+
SURFACE_SPECIES_0
123+
SCREEN_WRT_FREQ_INNER= 10
124+
%
125+
HISTORY_OUTPUT= ITER RMS_RES LINSOL SPECIES_COEFF SPECIES_COEFF_SURF
126+
CONV_FILENAME= history
127+
MARKER_ANALYZE= gas_inlet, air_axial_inlet, outlet
128+
MARKER_ANALYZE_AVERAGE= AREA
129+
%
130+
OUTPUT_FILES= RESTART_ASCII, PARAVIEW_MULTIBLOCK
131+
VOLUME_OUTPUT= RESIDUAL, PRIMITIVE
132+
OUTPUT_WRT_FREQ= 1000
133+
%
134+
RESTART_SOL= NO
135+
READ_BINARY_RESTART= NO
136+
RESTART_FILENAME= restart
137+
SOLUTION_FILENAME= solution
138+
%
139+
WRT_PERFORMANCE= YES

0 commit comments

Comments
 (0)
Please sign in to comment.