Skip to content

Commit a113149

Browse files
committed
update buoyancy
1 parent d91bb62 commit a113149

File tree

4 files changed

+52
-70
lines changed

4 files changed

+52
-70
lines changed

SU2_CFD/src/iteration/CFluidIteration.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ bool CFluidIteration::Monitor(COutput* output, CIntegration**** integration, CGe
238238
output->SetHistoryOutput(geometry[val_iZone][val_iInst][MESH_0], solver[val_iZone][val_iInst][MESH_0],
239239
config[val_iZone], config[val_iZone]->GetTimeIter(), config[val_iZone]->GetOuterIter(),
240240
config[val_iZone]->GetInnerIter());
241-
241+
242242
StopCalc = output->GetConvergence();
243243

244244
/* --- Checking convergence of Fixed CL mode to target CL, and perform finite differencing if needed --*/
@@ -345,12 +345,12 @@ void CFluidIteration::ComputeTurboPerformance(CSolver***** solver, CGeometry****
345345
bladesPrimitives.push_back(bladePrimitives);
346346
}
347347
TurbomachineryPerformance->ComputeTurbomachineryPerformance(bladesPrimitives);
348-
348+
349349
auto nSpan = config_container[ZONE_0]->GetnSpanWiseSections();
350350
auto InState = TurbomachineryPerformance->GetBladesPerformances().at(ZONE_0).at(nSpan)->GetInletState();
351351
nSpan = config_container[nZone-1]->GetnSpanWiseSections();
352352
auto OutState = TurbomachineryPerformance->GetBladesPerformances().at(nZone-1).at(nSpan)->GetOutletState();
353-
353+
354354
TurbomachineryStagePerformance->ComputePerformanceStage(InState, OutState, config_container[nZone-1]);
355355
}
356356
}
@@ -658,7 +658,6 @@ void CFluidIteration::SetDualTime_Aeroelastic(CConfig* config) const {
658658
Marker_Tag = config->GetMarker_All_TagBound(iMarker);
659659
if (Marker_Tag == Monitoring_Tag) { owner = 1; break;
660660
} owner = 0;
661-
662661

663662
}
664663
plunge = config->GetAeroelastic_plunge(iMarker_Monitoring);

TestCases/py_wrapper/custom_source_buoyancy/lam_buoyancy_cavity.cfg

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
%
1313
SOLVER= INC_NAVIER_STOKES
1414
KIND_TURB_MODEL= NONE
15-
MATH_PROBLEM= DIRECT
16-
RESTART_SOL= NO
15+
RESTART_SOL= YES
1716

1817
% ---------------- INCOMPRESSIBLE FLOW CONDITION DEFINITION -------------------%
1918
%
@@ -47,6 +46,7 @@ THERMAL_CONDUCTIVITY_CONSTANT= 0.0246295028571
4746

4847
% ----------------------- BODY FORCE DEFINITION -------------------------------%
4948
%
49+
% switch off body force, we now do this with the python wrapper
5050
BODY_FORCE= NO
5151
BODY_FORCE_VECTOR= ( 0.0, -9.81, 0.0 )
5252

@@ -67,12 +67,12 @@ MARKER_MONITORING= ( NONE )
6767
% ------------- COMMON PARAMETERS DEFINING THE NUMERICAL METHOD ---------------%
6868
%
6969
NUM_METHOD_GRAD= GREEN_GAUSS
70-
CFL_NUMBER= 50
70+
CFL_NUMBER= 100
7171
CFL_ADAPT= NO
72-
CFL_ADAPT_PARAM= ( 1.5, 0.5, 15.0, 1e10)
72+
CFL_ADAPT_PARAM= ( 0.9, 1.1, 10.0,10000, 1.0e-3)
7373
MAX_DELTA_TIME= 1E6
7474
RK_ALPHA_COEFF= ( 0.66667, 0.66667, 1.000000 )
75-
ITER=6
75+
ITER=1
7676

7777
% ------------------------ LINEAR SOLVER DEFINITION ---------------------------%
7878
%
@@ -93,7 +93,7 @@ TIME_DISCRE_FLOW= EULER_IMPLICIT
9393
% --------------------------- CONVERGENCE PARAMETERS --------------------------%
9494
%
9595
CONV_RESIDUAL_MINVAL= -12
96-
CONV_STARTITER= 10
96+
CONV_STARTITER= 1
9797
CONV_CAUCHY_ELEMS= 100
9898
CONV_CAUCHY_EPS= 1E-6
9999

@@ -113,6 +113,9 @@ VOLUME_ADJ_FILENAME= adjoint
113113
GRAD_OBJFUNC_FILENAME= of_grad.dat
114114
SURFACE_FILENAME= surface_flow
115115
SURFACE_ADJ_FILENAME= surface_adjoint
116-
OUTPUT_WRT_FREQ= 100
117-
SCREEN_OUTPUT= (OUTER_ITER,INNER_ITER, RMS_PRESSURE, RMS_VELOCITY-X, RMS_VELOCITY-Y, RMS_TEMPERATURE)
116+
OUTPUT_WRT_FREQ= 10
117+
SCREEN_OUTPUT= (INNER_ITER, RMS_PRESSURE, RMS_VELOCITY-X, RMS_VELOCITY-Y, RMS_TEMPERATURE)
118+
119+
WRT_PERFORMANCE= YES
120+
PYTHON_CUSTOM_SOURCE= YES
118121

TestCases/py_wrapper/custom_source_buoyancy/run.py

Lines changed: 33 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,17 @@
2626

2727
import sys
2828
import pysu2
29-
from mpi4py import MPI
29+
import numpy as np
3030

31+
# with mpi:
32+
from mpi4py import MPI
33+
comm = MPI.COMM_WORLD
34+
rank = comm.Get_rank()
35+
# without mpi:
36+
# comm = 0
3137

3238
def main():
33-
"""
34-
custom source to add buoyancy term.
35-
"""
36-
# parallel
37-
comm = MPI.COMM_WORLD
38-
# serial
39-
#comm = 0
39+
4040

4141
# Initialize the primal driver of SU2, this includes solver preprocessing.
4242
try:
@@ -45,83 +45,65 @@ def main():
4545
print('A TypeError occured in pysu2.CSinglezoneDriver : ', exception)
4646
raise
4747

48-
print("\n------------------------------ Begin Solver -----------------------------")
49-
sys.stdout.flush()
48+
if rank == 0:
49+
print("\n------------------------------ Begin Solver -----------------------------")
50+
sys.stdout.flush()
5051

5152
# we need to add a source term to the energy equation. For this, we need to get the solver and the variable first.
5253
# we then loop over all points and for these points, we add the source term
5354
nDim = driver.GetNumberDimensions()
5455

5556
# index to the flow solver
5657
iSOLVER = driver.GetSolverIndices()['INC.FLOW']
57-
#print("index of flow solver = ",iSOLVER)
5858

5959
# all the indices and the map to the names of the primitives
6060
primindex = driver.GetPrimitiveIndices()
61-
#print("indices of primitives=",primindex)
62-
#print("number of primitives:",len(primindex))
63-
64-
#print("number of elements:",driver.GetNumberElements())
6561

6662
nVars = driver.GetNumberSolverVars(iSOLVER)
67-
#print("number of solver variables:",nVars)
6863
varindex = primindex.copy()
69-
for prim in varindex.copy():
70-
if varindex[prim] >=nVars:
71-
del varindex[prim]
72-
varindex = dict(sorted(varindex.items(), key=lambda item: item[1]))
73-
64+
#for prim in varindex.copy():
65+
# if varindex[prim] >=nVars:
66+
# del varindex[prim]
67+
#varindex = dict(sorted(varindex.items(), key=lambda item: item[1]))
7468

75-
76-
print("solver variable names:",varindex)
7769
iDENSITY = primindex.get("DENSITY")
78-
print("index of density = ",iDENSITY)
79-
80-
index_Vel = varindex.get("VELOCITY_X")
81-
print("index of velocity = ",index_Vel)
82-
custom_source_vector = [0.0 for i in range(nVars)]
83-
print("custom source vector = ", custom_source_vector)
70+
#index_Vel = varindex.get("VELOCITY_X")
8471

85-
#print("max. number of inner iterations: ",driver.GetNumberInnerIter());
86-
#print("max nr of outer iterations: ",driver.GetNumberOuterIter());
87-
88-
# is in domain: isdomain = driver.GetNodeDomain(iPoint)
89-
#for i_vertex in range(n_vertex)
90-
#AllSolutions = driver.GetAllSolutions(iSOLVER)
9172
Body_Force_Vector = [0.0, -9.81, 0.0]
9273
DensityInc_0 = driver.GetDensity_FreeStreamND()
93-
#print("rho freestream = ",DensityInc_0)
9474
Force_Ref = driver.GetForce_Ref()
95-
#print("reference force = ",Force_Ref)
9675

97-
Iter = driver.GetNumberInnerIter()
98-
print("1. inner iterations = ",Iter)
76+
# super important to actually push the commands.
77+
sys.stdout.flush()
78+
79+
# run N iterations
80+
for inner_iter in range(11):
81+
if (rank==0):
82+
print("python iteration ", inner_iter)
9983

100-
for inner_iter in range(Iter):
10184
# set the source term, per point
102-
print(driver.GetNumberNodes() - driver.GetNumberHaloNodes())
10385
for i_node in range(driver.GetNumberNodes() - driver.GetNumberHaloNodes()):
104-
#SolutionVector = driver.GetSolutionVector(iSOLVER,i_node)
105-
PrimitiveVector = driver.GetPrimitiveVector(iSOLVER,i_node)
106-
DensityInc_i = PrimitiveVector[iDENSITY]
86+
DensityInc_i = driver.Primitives()(i_node,iDENSITY)
10787

10888
for iDim in range(nDim):
109-
custom_source_vector[iDim+1] = -(DensityInc_i - DensityInc_0) * Body_Force_Vector[iDim] / Force_Ref
110-
111-
#driver.SetPointCustomSource(iSOLVER, i_node, custom_source_vector)
89+
custom_source_vector = (DensityInc_i - DensityInc_0) * Body_Force_Vector[iDim] / Force_Ref
90+
driver.UserDefinedSource(iSOLVER).Set(i_node,iDim+1,custom_source_vector)
11291

113-
print(" *** inner iteration:",inner_iter)
11492
driver.Preprocess(inner_iter)
115-
116-
# Run one time iteration.
11793
driver.Run()
94+
11895
driver.Postprocess()
11996
driver.Update()
12097

12198
# Monitor the solver and output solution to file if required.
122-
#driver.Monitor(inner_iter)
99+
#stopcalc = driver.Monitor(inner_iter)
123100
driver.Output(inner_iter)
124101

102+
#if (stopcalc):
103+
# if (rank==0):
104+
# "Max iterations or convergence criteria reached, stopping."
105+
# break;
106+
125107
# Finalize the solver and exit cleanly.
126108
driver.Finalize()
127109

TestCases/py_wrapper/turbulent_premixed_psi/psi.cfg

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ AXISYMMETRIC= YES
6767
SPECIFIED_INLET_PROFILE= YES
6868
INLET_MATCHING_TOLERANCE=1e-4
6969
INLET_FILENAME= inlet.dat
70-
%INLET_INTERPOLATION_FUNCTION= LINEAR_1D
7170
INC_INLET_TYPE= VELOCITY_INLET
7271
INC_INLET_DAMPING= 0.1
7372
MARKER_INLET= ( inlet, 673, 40.0, 1.0, 0.0, 0.0)
@@ -82,9 +81,10 @@ MARKER_OUTLET= ( outlet, 0.0 )
8281
%
8382
NUM_METHOD_GRAD= WEIGHTED_LEAST_SQUARES
8483
%
85-
CFL_NUMBER= 10.0
84+
CFL_NUMBER= 2.00
8685
CFL_REDUCTION_SPECIES= 1.0
8786
CFL_REDUCTION_TURB= 1.0
87+
%CFL_ADAPT= YES
8888
CFL_ADAPT= YES
8989
CFL_ADAPT_PARAM= ( 0.95, 1.01, 1.0, 250, 1.0e-4, 0)
9090

@@ -95,7 +95,7 @@ ITER= 1
9595
%
9696
LINEAR_SOLVER= FGMRES
9797
LINEAR_SOLVER_PREC= ILU
98-
LINEAR_SOLVER_ERROR= 1E-8
98+
LINEAR_SOLVER_ERROR= 1E-12
9999
LINEAR_SOLVER_ITER= 10
100100

101101
% -------------------- FLOW NUMERICAL METHOD DEFINITION -----------------------%
@@ -131,7 +131,6 @@ SPECIES_CLIPPING_MAX= 1.0
131131
%
132132
CONV_NUM_METHOD_TURB= BOUNDED_SCALAR
133133
MUSCL_TURB= NO
134-
135134
%
136135
% --------------------------- CONVERGENCE PARAMETERS --------------------------%
137136
%
@@ -141,9 +140,7 @@ CONV_STARTITER= 10
141140
%
142141
% ------------------------- INPUT/OUTPUT INFORMATION --------------------------%
143142
%
144-
%MESH_FILENAME= psi_coarse.su2
145143
MESH_FILENAME= psi.su2
146-
%MESH_FILENAME= psi_fine.su2
147144
%
148145
SCREEN_OUTPUT= INNER_ITER WALL_TIME \
149146
RMS_PRESSURE RMS_VELOCITY-X RMS_VELOCITY-Y RMS_TKE RMS_DISSIPATION RMS_SPECIES_0 \
@@ -158,11 +155,12 @@ MARKER_ANALYZE= gas_inlet, air_axial_inlet, outlet
158155
MARKER_ANALYZE_AVERAGE= AREA
159156
%
160157
OUTPUT_FILES= RESTART, PARAVIEW_MULTIBLOCK
161-
VOLUME_OUTPUT= RESIDUAL, PRIMITIVE
158+
VOLUME_OUTPUT= RESIDUAL, PRIMITIVE, SPECIES_UDS_0
162159
OUTPUT_WRT_FREQ= 100
163160
%
164161
READ_BINARY_RESTART= YES
165162
RESTART_FILENAME= restart
166163
SOLUTION_FILENAME= solution
167164
%
168165
WRT_PERFORMANCE= YES
166+
PYTHON_CUSTOM_SOURCE= YES

0 commit comments

Comments
 (0)