Skip to content

Commit 68e38bd

Browse files
committed
Clean udf arguments. Move step to Status. Fix a bug in check_vs_num.
1 parent 06ce149 commit 68e38bd

13 files changed

Lines changed: 45 additions & 44 deletions

File tree

example/X38/X38_julia.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ for i in 1:nt
6868
iterate!(amr) # Collision process and time marching.
6969
data_exchange!(ps4est, amr) # Update variables in ghost cells by MPI communication.
7070
check_for_convergence(amr)&&break # Check for convergence.
71-
check!(i,ps4est,amr) # Check for save and output simulation status to `stdout`.
71+
check!(ps4est,amr) # Check for save and output simulation status to `stdout`.
7272
end
7373

7474
save_result(ps4est,amr) # Save converging results.

example/X38/X38_text.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ for i in 1:nt
2020
KitAMR.iterate!(amr)
2121
KitAMR.data_exchange!(ps4est, amr)
2222
KitAMR.check_for_convergence(amr)&&break
23-
KitAMR.check!(i,ps4est,amr)
23+
KitAMR.check!(ps4est,amr)
2424
end
2525
KitAMR.save_result(ps4est,amr)
2626
KitAMR.finalize!(ps4est,amr)

example/X38/X38_udf.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using LinearAlgebra
2-
function amr_region(;ps_data,kwargs...)
2+
function amr_region(ps_data,level,amr) # dynamic
33
midpoint = ps_data.midpoint
44
ds = ps_data.ds
55
L = 1.0
@@ -8,7 +8,7 @@ function amr_region(;ps_data,kwargs...)
88
end
99
return false
1010
end
11-
function X38_buffer_IC(midpoint::Vector{Float64};kwargs...)
11+
function X38_buffer_IC(midpoint::Vector{Float64},::Global_Data)
1212
global_data = kwargs[:global_data]
1313
ib = global_data.config.IB[1]
1414
Ma = 8.

example/airfoil/airfoil.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ for i in 1:nt
5454
iterate!(amr)
5555
data_exchange!(ps4est, amr)
5656
check_for_convergence(amr)&&break
57-
check!(i,ps4est,amr)
57+
check!(ps4est,amr)
5858
end
5959
save_result(ps4est,amr)
6060
finalize!(ps4est,amr)

example/cylinder/cylinder.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ for i in 1:nt
5656
iterate!(amr)
5757
data_exchange!(ps4est, amr)
5858
check_for_convergence(amr)&&break
59-
check!(i,ps4est,amr)
59+
check!(ps4est,amr)
6060
# KitAMR.check_for_animsave!(ps4est,amr)
6161
# if amr.global_data.status.sim_time>3.0
6262
# break

example/cylinder/cylinder_udf.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ function shock_wave_region(midpoint,ds,global_data,level)
55
end
66
return false
77
end
8-
function amr_region(;ps_data,kwargs...)
8+
function amr_region(ps_data,level,amr)
99
midpoint = ps_data.midpoint
1010
if midpoint[1]>-5.0&&midpoint[1]<5.0&&midpoint[2]<5.0&&midpoint[2]>-5.0&&sum(midpoint.^2)>1.0
1111
return true
1212
end
1313
return false
1414
end
15-
function cylinder_buffer_IC(midpoint::Vector{Float64})
15+
function cylinder_buffer_IC(midpoint::Vector{Float64},::Global_Data)
1616
r = norm(midpoint)
1717
Ma = 5.0
1818
Tw = 1.0

example/sphere/sphere.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ for i in 1:nt
5858
iterate!(amr)
5959
data_exchange!(ps4est, amr)
6060
check_for_convergence(amr)&&break
61-
check!(i,ps4est,amr)
61+
check!(ps4est,amr)
6262
end
6363
save_result(ps4est,amr)
6464
finalize!(ps4est,amr)

example/sphere/sphere_udf.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function shock_wave_region(midpoint,ds,global_data,level)
88
end
99
return false
1010
end
11-
function sphere_buffer_IC(midpoint::Vector{Float64};kwargs...)
11+
function sphere_buffer_IC(midpoint::Vector{Float64},::Global_Data)
1212
r = norm(midpoint)
1313
Ma = 3.834
1414
Tw = 1.0+(5/3-1)*0.5*Ma^2

src/IO/Check.jl

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,29 @@
22
$(SIGNATURES)
33
Perform a check procedure. Simulation status will be output every `ST_CHECK_INTERVAL` steps.
44
"""
5-
function check!(i,ps4est,amr)
6-
if amr.global_data.status.residual.step%amr.global_data.config.solver.ST_CHECK_INTERVAL==0
7-
max_vs_num,total_phase_num = check_vs_num(amr)
8-
if MPI.Comm_rank(MPI.COMM_WORLD) == 0
9-
i+=1
10-
println("Iteration: $i")
11-
sim_time = amr.global_data.status.sim_time
12-
println("Simulation time: $sim_time")
13-
res = maximum(amr.global_data.status.residual.residual)
14-
println("Residual: $res")
15-
ref_vs_num = amr.global_data.status.max_vs_num
16-
println("MPI buffer size: $ref_vs_num")
17-
println("Maximum number of velocity grids: $max_vs_num")
18-
pp = PointerWrapper(ps4est)
19-
global_num_quadrants = pp.global_num_quadrants[]
20-
println("Total number of physical grids: $global_num_quadrants")
21-
println("Total number of phase grids: $total_phase_num")
22-
end
5+
function check!(ps4est,amr)
6+
if amr.global_data.status.step%amr.global_data.config.solver.ST_CHECK_INTERVAL==0
7+
execute_check(ps4est,amr)
238
check_for_save!(ps4est,amr)
249
end
2510
end
11+
function execute_check(ps4est,amr)
12+
max_vs_num,total_phase_num = check_vs_num(amr)
13+
if MPI.Comm_rank(MPI.COMM_WORLD) == 0
14+
println("Iteration: $(amr.global_data.status.step)")
15+
sim_time = amr.global_data.status.sim_time
16+
println("Simulation time: $sim_time")
17+
res = maximum(amr.global_data.status.residual.residual)
18+
println("Residual: $res")
19+
ref_vs_num = amr.global_data.status.max_vs_num
20+
println("MPI buffer size: $ref_vs_num")
21+
println("Maximum number of velocity grids: $max_vs_num")
22+
pp = PointerWrapper(ps4est)
23+
global_num_quadrants = pp.global_num_quadrants[]
24+
println("Total number of physical grids: $global_num_quadrants")
25+
println("Total number of phase grids: $total_phase_num")
26+
end
27+
end
2628
"""
2729
$(SIGNATURES)
2830
Start listening for the input from command line. Must be called before calling [`check_for_save!`](@ref).
@@ -175,7 +177,6 @@ function check_vs_num(amr::KitAMR_Data)
175177
for tree in trees
176178
for ps_data in tree
177179
isa(ps_data,InsideSolidData)&&continue
178-
ps_data.bound_enc<0&&continue
179180
vs_num = ps_data.vs_data.vs_num
180181
buffer[1] = max(buffer[1],vs_num)
181182
buffer[2] += vs_num

src/Solver/Finalize.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Update residuals.
44
"""
55
function residual_check!(ps_data::PS_Data,prim::Vector{Float64},global_data::Global_Data)
66
Res = global_data.status.residual
7-
Res.step%global_data.config.solver.ST_CHECK_INTERVAL!=0&&(return nothing)
7+
global_data.status.step%global_data.config.solver.ST_CHECK_INTERVAL!=0&&(return nothing)
88
@. Res.sumRes+=(prim-ps_data.prim).^2
99
@. Res.sumAvg+=abs(prim)
1010
return nothing
@@ -13,7 +13,7 @@ function residual_comm!(global_data::Global_Data)
1313
Res = global_data.status.residual
1414
fp = PointerWrapper(global_data.forest.p4est)
1515
N = fp.global_num_quadrants[]
16-
Res.step%global_data.config.solver.ST_CHECK_INTERVAL!=0&&(return nothing)
16+
global_data.status.step%global_data.config.solver.ST_CHECK_INTERVAL!=0&&(return nothing)
1717
MPI.Reduce!(Res.sumRes,(x,y)->x.+y,0,MPI.COMM_WORLD)
1818
MPI.Reduce!(Res.sumAvg,(x,y)->x.+y,0,MPI.COMM_WORLD)
1919
if MPI.Comm_rank(MPI.COMM_WORLD)==0

0 commit comments

Comments
 (0)