Skip to content

Commit dfe83be

Browse files
authored
Merge pull request #277 from loganoz/david_development
pAdaptationRL Gauss-Lobatto nodes test case and AdaptiveTimeStep for MixedRK scheme
2 parents 3cd7025 + 875086c commit dfe83be

22 files changed

Lines changed: 60750 additions & 1 deletion

.github/workflows/CI_parallel.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,6 +1015,23 @@ jobs:
10151015
# mpiexec -n 64 ./horses3d.ns ActuatorLineController.control
10161016
# if: '!cancelled()'
10171017

1018+
#
1019+
# 34) Cylinder with Reinforcement Learning p-adaptation and Gauss-Lobatto nodes
1020+
# --------------------------------------------
1021+
- name: Build Cylinder_pAdaptationRL_GaussLobatto
1022+
working-directory: ./Solver/test/NavierStokes/Cylinder_pAdaptationRL_GaussLobatto/SETUP
1023+
run: |
1024+
source /opt/intel/oneapi/setvars.sh || true
1025+
make MODE=${{matrix.mode}} COMPILER=${{matrix.compiler}} COMM=${{matrix.comm}} ENABLE_THREADS=${{matrix.enable_threads}} WITH_METIS=YES
1026+
if: '!cancelled()'
1027+
1028+
- name: Run Cylinder_pAdaptationRL_GaussLobatto
1029+
working-directory: ./Solver/test/NavierStokes/Cylinder_pAdaptationRL_GaussLobatto
1030+
run: |
1031+
source /opt/intel/oneapi/setvars.sh || true
1032+
mpiexec -n 64 ./horses3d.ns Cylinder_pAdaptationRL_GaussLobatto.control
1033+
if: '!cancelled()'
1034+
10181035
########################################################################
10191036
####### PARTICLES ########
10201037
########################################################################

.github/workflows/CI_sequential 2.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -804,3 +804,21 @@ jobs:
804804
./horses3d.ns Cylinder_AdaptiveTimeStep_pAdaptationRL.control
805805
if: '!cancelled()'
806806

807+
#
808+
# 34) Cylinder with Reinforcement Learning p-adaptation and Gauss-Lobatto nodes
809+
# --------------------------------------------
810+
811+
- name: Build Cylinder_pAdaptationRL_GaussLobatto
812+
working-directory: ./Solver/test/NavierStokes/Cylinder_pAdaptationRL_GaussLobatto/SETUP
813+
run: |
814+
source /opt/intel/oneapi/setvars.sh || true
815+
make MODE=${{matrix.mode}} COMPILER=${{matrix.compiler}} COMM=${{matrix.comm}} ENABLE_THREADS=${{matrix.enable_threads}} WITH_MKL=${{matrix.mkl}} WITH_HDF5=${{matrix.hdf5}}
816+
if: '!cancelled()'
817+
818+
- name: Run Cylinder_pAdaptationRL_GaussLobatto
819+
working-directory: ./Solver/test/NavierStokes/Cylinder_pAdaptationRL_GaussLobatto
820+
run: |
821+
source /opt/intel/oneapi/setvars.sh || true
822+
./horses3d.ns Cylinder_pAdaptationRL_GaussLobatto.control
823+
if: '!cancelled()'
824+

Solver/configure

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ TEST_CASES="./Euler/BoxAroundCircle \
8080
./NavierStokes/ActuatorLineInterpolation \
8181
./NavierStokes/ActuatorLineProjection \
8282
./NavierStokes/Cylinder_AdaptiveTimeStep_pAdaptationRL \
83+
./NavierStokes/Cylinder_pAdaptationRL_GaussLobatto \
8384
./NavierStokes/ABLBoundaryMapping \
8485
./NavierStokes/ActuatorLineController \
8586
./IncompressibleNS/Convergence \

Solver/src/libs/timeintegrator/ExplicitMethods.f90

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,14 @@ SUBROUTINE TakeMixedRKStep( mesh, particles, t, deltaT, ComputeTimeDerivative ,
276276
real(kind=RP), parameter :: b_RK14_4(N_STAGES_RK14_4) = [0.0000000000000000_RP, 0.0367762454319673_RP, 0.1249685262725025_RP, 0.2446177702277698_RP, 0.2476149531070420_RP, 0.2969311120382472_RP, 0.3978149645802642_RP, 0.5270854589440328_RP, 0.6981269994175695_RP, 0.8190890835352128_RP, 0.8527059887098624_RP, 0.8604711817462826_RP, 0.8627060376969976_RP, 0.8734213127600976_RP]
277277
real(kind=RP), parameter :: c_RK14_4(N_STAGES_RK14_4) = [0.0367762454319673_RP, 0.3136296607553959_RP, 0.1531848691869027_RP, 0.0030097086818182_RP, 0.3326293790646110_RP, 0.2440251405350864_RP, 0.3718879239592277_RP, 0.6204126221582444_RP, 0.1524043173028741_RP, 0.0760894927419266_RP, 0.0077604214040978_RP, 0.0024647284755382_RP, 0.0780348340049386_RP, 5.5059777270269628_RP]
278278

279+
logical :: updateQLowRK
280+
281+
if (present(dtAdaptation)) then
282+
updateQLowRK = dtAdaptation
283+
else
284+
updateQLowRK = .false.
285+
end if
286+
279287
allocate(phase1_mask(size(mesh % elements)))
280288
allocate(phase2_mask(size(mesh % elements)))
281289

@@ -287,10 +295,12 @@ SUBROUTINE TakeMixedRKStep( mesh, particles, t, deltaT, ComputeTimeDerivative ,
287295
!$omp parallel do schedule(runtime) reduction(+:phase1_count,phase2_count) private(id)
288296
do id = 1, size(mesh % elements)
289297
if ( all(mesh % elements(id) % storage % Q(1,:,:,:) > 1.0_RP - 1e-8_RP) ) then
298+
mesh % elements(id) % MLevel = 1 !required for adaptive time step
290299
phase1_mask(id) = .true.
291300
phase2_mask(id) = .false.
292301
phase1_count = phase1_count + 1
293302
else
303+
mesh % elements(id) % MLevel = 4 !required for adaptive time step
294304
phase1_mask(id) = .false.
295305
phase2_mask(id) = .true.
296306
phase2_count = phase2_count + 1
@@ -374,6 +384,18 @@ SUBROUTINE TakeMixedRKStep( mesh, particles, t, deltaT, ComputeTimeDerivative ,
374384
if (dts) call ComputePseudoTimeDerivative(mesh, tk, global_dt)
375385
end if
376386

387+
if (k==1 .and. updateQLowRK) then !For adaptive time step only, update QLowRK
388+
!$omp parallel do schedule(runtime)
389+
do id = 1, SIZE( mesh % elements )
390+
if (phase1_mask(id)) then
391+
#ifdef FLOW
392+
mesh % elements(id) % storage % QLowRK = mesh % elements(id) % storage % Q + dt_vec(id)*mesh % elements(id) % storage % QDot
393+
#endif
394+
end if
395+
end do ! id
396+
!$omp end parallel do
397+
end if
398+
377399
!$omp parallel do schedule(runtime)
378400
DO id = 1, SIZE( mesh % elements )
379401
if (phase1_mask(id)) then
@@ -433,6 +455,18 @@ SUBROUTINE TakeMixedRKStep( mesh, particles, t, deltaT, ComputeTimeDerivative ,
433455
if (dts) call ComputePseudoTimeDerivative(mesh, tk, global_dt)
434456
end if
435457

458+
if (k==1 .and. updateQLowRK) then !For adaptive time step only, update QLowRK
459+
!$omp parallel do schedule(runtime)
460+
do id = 1, SIZE( mesh % elements )
461+
if (phase2_mask(id)) then
462+
#ifdef FLOW
463+
mesh % elements(id) % storage % QLowRK = mesh % elements(id) % storage % Q + dt_vec(id)*mesh % elements(id) % storage % QDot
464+
#endif
465+
end if
466+
end do ! id
467+
!$omp end parallel do
468+
end if
469+
436470
!$omp parallel do schedule(runtime)
437471
DO id = 1, SIZE( mesh % elements )
438472
if (phase2_mask(id)) then
@@ -479,6 +513,18 @@ SUBROUTINE TakeMixedRKStep( mesh, particles, t, deltaT, ComputeTimeDerivative ,
479513
if (dts) call ComputePseudoTimeDerivative(mesh, tk, global_dt)
480514
end if
481515

516+
if (k==1 .and. updateQLowRK) then !For adaptive time step only, update QLowRK
517+
!$omp parallel do schedule(runtime)
518+
do id = 1, SIZE( mesh % elements )
519+
if (phase1_mask(id)) then
520+
#ifdef FLOW
521+
mesh % elements(id) % storage % QLowRK = mesh % elements(id) % storage % Q + deltaT*mesh % elements(id) % storage % QDot
522+
#endif
523+
end if
524+
end do ! id
525+
!$omp end parallel do
526+
end if
527+
482528
!$omp parallel do schedule(runtime)
483529
DO id = 1, SIZE( mesh % elements )
484530
if (phase1_mask(id)) then
@@ -538,6 +584,18 @@ SUBROUTINE TakeMixedRKStep( mesh, particles, t, deltaT, ComputeTimeDerivative ,
538584
if (dts) call ComputePseudoTimeDerivative(mesh, tk, global_dt)
539585
end if
540586

587+
if (k==1 .and. updateQLowRK) then !For adaptive time step only, update QLowRK
588+
!$omp parallel do schedule(runtime)
589+
do id = 1, SIZE( mesh % elements )
590+
if (phase2_mask(id)) then
591+
#ifdef FLOW
592+
mesh % elements(id) % storage % QLowRK = mesh % elements(id) % storage % Q + deltaT*mesh % elements(id) % storage % QDot
593+
#endif
594+
end if
595+
end do ! id
596+
!$omp end parallel do
597+
end if
598+
541599
!$omp parallel do schedule(runtime)
542600
DO id = 1, SIZE( mesh % elements )
543601
if (phase2_mask(id)) then

Solver/src/libs/timeintegrator/TimeIntegrator.f90

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,12 @@ SUBROUTINE constructTimeIntegrator(self,controlVariables, sem, initial_iter, ini
156156
if (MPI_Process % isRoot ) then
157157
write(STD_OUT,*) "Using 'ML-RK3' method with adaptive dt."
158158
end if
159+
case(MIXED_RK_NAME)
160+
if (MPI_Process % isRoot ) then
161+
write(STD_OUT,*) "Using 'MIXED-RK' method with adaptive dt."
162+
end if
159163
case default
160-
error stop "Error, only 'RK3' method is implemented for adaptive dt"
164+
error stop "Error, only 'RK3'-based methods are implemented for adaptive dt"
161165
end select
162166
else
163167
write(STD_OUT,*) "Using 'RK3' method with adaptive dt by default."
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
Flow equations = "NS"
2+
mesh file name = "MESH/cyl_circ.msh"
3+
Polynomial order = 2
4+
Number of time steps = 75
5+
Output Interval = 10
6+
Convergence tolerance = 1.d-10
7+
cfl = 0.1
8+
dcfl = 0.1
9+
mach number = 0.2
10+
Reynolds number = 40.0
11+
AOA theta = 0.0
12+
AOA phi = 0.0
13+
solution file name = "RESULTS/Cylinder.hsol"
14+
save gradients with solution = .false.
15+
restart = .false.
16+
restart file name = "RESULTS/Cylinder.hsol"
17+
riemann solver = roe
18+
simulation type = steady-state
19+
time integration = explicit
20+
explicit method = RK3
21+
Discretization nodes = Gauss-Lobatto
22+
23+
#define boundary cylinder
24+
type = NoSlipWall
25+
#end
26+
27+
#define boundary left__right
28+
type = FreeSlipWall
29+
#end
30+
31+
#define boundary inlet
32+
type = Inflow
33+
#end
34+
35+
#define boundary outlet
36+
type = Outflow
37+
#end
38+
39+
!-Adaptation-----------------------------------
40+
#define p-adaptation
41+
adaptation type = RL
42+
agent file = policy_padaptation_gauss_lobatto/p_adaptation_policy
43+
tolerance = 1d-2
44+
Nmax = [6, 6, 2]
45+
Nmin = [2, 2, 2]
46+
adjust nz = .FALSE.
47+
restart files = .FALSE.
48+
order across faces = N*2/3
49+
mode = iteration
50+
interval = 50
51+
#end
52+
!---------------------------------------------
53+
54+
#define surface monitor 1
55+
Name = cyl-drag
56+
Marker = cylinder
57+
Variable = drag
58+
Direction = [1.0,0.0,0.0]
59+
Reference surface = 1.0
60+
#end
61+
62+
#define surface monitor 2
63+
Name = cyl-lift
64+
Marker = cylinder
65+
Variable = lift
66+
Direction = [0.0,1.0,0.0]
67+
Reference surface = 1.0
68+
#end
69+
70+
#define probe 1
71+
Name = wake_u
72+
Position = [2.0,0.0,0.5]
73+
Variable = u
74+
#end

0 commit comments

Comments
 (0)