interfaceHeight函数运行过慢
-
使用OpenFOAM进行波浪相关的模拟时,可以在controlDict中加入interfaceHeight函数用于监测指定点的水位。但是,我在实际操作的时候,发现这个函数执行的很慢,执行这个函数的所需要的时间超过甚至远远超过计算本身的时间,如下:
Courant Number mean: 0.0145703 max: 0.124671 Interface Courant Number mean: 0.000203796 max: 0.0781427 Time = 0.008s smoothSolver: Solving for alpha.water, Initial residual = 0.000118531, Final residual = 7.40804e-08, No Iterations 2 Phase-1 volume fraction = 0.374025 Min(alpha.water) = -8.12552e-19 Max(alpha.water) = 1.00006 MULES: Correcting alpha.water Phase-1 volume fraction = 0.374025 Min(alpha.water) = -8.12552e-19 Max(alpha.water) = 1.00006 GAMGPCG: Solving for p_rgh, Initial residual = 0.00868385, Final residual = 2.67972e-08, No Iterations 4 time step continuity errors : sum local = 4.14175e-08, global = 2.02918e-10, cumulative = -1.12194e-10 GAMGPCG: Solving for p_rgh, Initial residual = 1.29705e-06, Final residual = 2.96176e-08, No Iterations 2 time step continuity errors : sum local = 4.57363e-08, global = -1.53322e-10, cumulative = -2.65516e-10 GAMGPCG: Solving for p_rgh, Initial residual = 6.67786e-08, Final residual = 6.96381e-09, No Iterations 1 time step continuity errors : sum local = 1.07541e-08, global = -5.90717e-12, cumulative = -2.71423e-10 GAMGPCG: Solving for p_rgh, Initial residual = 6.86536e-09, Final residual = 6.86536e-09, No Iterations 0 time step continuity errors : sum local = 1.06021e-08, global = -3.32298e-12, cumulative = -2.74746e-10 GAMGPCG: Solving for p_rgh, Initial residual = 6.89503e-09, Final residual = 6.89503e-09, No Iterations 0 time step continuity errors : sum local = 1.06479e-08, global = -3.29207e-12, cumulative = -2.78038e-10 smoothSolver: Solving for omega, Initial residual = 7.42141e-05, Final residual = 6.82499e-14, No Iterations 2 smoothSolver: Solving for k, Initial residual = 0.0516569, Final residual = 7.73297e-11, No Iterations 2 ExecutionTime = 6.89933 s ClockTime = 7 s Courant Number mean: 0.0143844 max: 0.161192 Interface Courant Number mean: 0.000206902 max: 0.0959385 Time = 0.01s smoothSolver: Solving for alpha.water, Initial residual = 0.000116747, Final residual = 7.13809e-08, No Iterations 2 Phase-1 volume fraction = 0.374029 Min(alpha.water) = -7.96187e-19 Max(alpha.water) = 1.00006 MULES: Correcting alpha.water Phase-1 volume fraction = 0.374029 Min(alpha.water) = -7.96187e-19 Max(alpha.water) = 1.00005 GAMGPCG: Solving for p_rgh, Initial residual = 0.00847643, Final residual = 2.22443e-08, No Iterations 4 time step continuity errors : sum local = 3.41315e-08, global = 7.51256e-11, cumulative = -2.02913e-10 GAMGPCG: Solving for p_rgh, Initial residual = 1.13271e-06, Final residual = 2.23769e-08, No Iterations 2 time step continuity errors : sum local = 3.42998e-08, global = -1.07007e-10, cumulative = -3.0992e-10 GAMGPCG: Solving for p_rgh, Initial residual = 5.84797e-08, Final residual = 6.46225e-09, No Iterations 1 time step continuity errors : sum local = 9.90576e-09, global = -7.74622e-12, cumulative = -3.17666e-10 GAMGPCG: Solving for p_rgh, Initial residual = 6.54525e-09, Final residual = 6.54525e-09, No Iterations 0 time step continuity errors : sum local = 1.0033e-08, global = -5.40963e-12, cumulative = -3.23076e-10 GAMGPCG: Solving for p_rgh, Initial residual = 6.63002e-09, Final residual = 6.63002e-09, No Iterations 0 time step continuity errors : sum local = 1.01629e-08, global = -5.3822e-12, cumulative = -3.28458e-10 smoothSolver: Solving for omega, Initial residual = 7.40885e-05, Final residual = 6.80869e-14, No Iterations 2 smoothSolver: Solving for k, Initial residual = 0.0380602, Final residual = 5.72495e-11, No Iterations 2 ExecutionTime = 7.1329 s ClockTime = 7 s Courant Number mean: 0.0142562 max: 0.195744 Interface Courant Number mean: 0.000209995 max: 0.11138 Time = 0.012s smoothSolver: Solving for alpha.water, Initial residual = 0.000115473, Final residual = 6.95493e-08, No Iterations 2 Phase-1 volume fraction = 0.374034 Min(alpha.water) = -7.82009e-19 Max(alpha.water) = 1.00005 MULES: Correcting alpha.water Phase-1 volume fraction = 0.374034 Min(alpha.water) = -7.82009e-19 Max(alpha.water) = 1.00005 GAMGPCG: Solving for p_rgh, Initial residual = 0.00833594, Final residual = 2.20133e-08, No Iterations 4 time step continuity errors : sum local = 3.35881e-08, global = 6.65894e-11, cumulative = -2.61868e-10 GAMGPCG: Solving for p_rgh, Initial residual = 1.03929e-06, Final residual = 1.72629e-08, No Iterations 2 time step continuity errors : sum local = 2.63105e-08, global = -8.49734e-11, cumulative = -3.46842e-10 GAMGPCG: Solving for p_rgh, Initial residual = 5.45841e-08, Final residual = 6.2677e-09, No Iterations 1 time step continuity errors : sum local = 9.55294e-09, global = -8.59065e-12, cumulative = -3.55433e-10 GAMGPCG: Solving for p_rgh, Initial residual = 6.57944e-09, Final residual = 6.57944e-09, No Iterations 0 time step continuity errors : sum local = 1.00281e-08, global = -6.37149e-12, cumulative = -3.61804e-10 GAMGPCG: Solving for p_rgh, Initial residual = 6.73188e-09, Final residual = 6.73188e-09, No Iterations 0 time step continuity errors : sum local = 1.02604e-08, global = -6.34536e-12, cumulative = -3.68149e-10 smoothSolver: Solving for omega, Initial residual = 7.39683e-05, Final residual = 6.82984e-14, No Iterations 2 smoothSolver: Solving for k, Initial residual = 0.0301565, Final residual = 4.5122e-11, No Iterations 2 ExecutionTime = 12.7735 s ClockTime = 13 s
0.008秒计算结束后没有写出,0.01秒后有interfaceHeight的写出,然后可以看到ClockTime的差值有明显区别,输出12个点的波高的时间远超计算一步的时间。
目前OpenFOAM 6/8/10和OpenFOAM v2106、2112都有这个现象,修改interfaceHeight的插值方法基本没有影响,同样的修改分块方式也没有。结构网格和非结构网格的输出速度有不显著的差异,结构网格好像会快一点,但没快到哪里去。
有大佬知道是为什么吗?或者如果想加快速度有什么办法或者替代的函数吗?
-
我可能知道是哪里的问题了,在interfaceHeight中会有一个插值的操作:
autoPtr<interpolation<scalar>> interpolator ( interpolation<scalar>::New(interpolationScheme_, alpha) );
(OpenFOAM 10 interfaceHeight 的完整代码参见这里,其他版本的也都有这个过程)
这好像是一个对全局进行插值的操作,也就是说,每次需要对一个点的水位(或者浪高)进行计算的时候都会进行一次全局alpha的插值。而且,同一个function下的不同点也是要分别进行插值而不是共用一个插值结果,然后就会特别慢。比较快的解决方法是用sample代替interfaceHeight,输出一条或若干条与重力方向平行的线上的alpha的值,然后计算完成后编程处理得到水位随时间的变化。推荐使用这一个现成的python代码,计算中输出基本不占时间,后处理也很快,和interfaceHeight得到的数据几乎完全一致,至少画成折线图看不出区别,完全重合了。
这个代码可能是ESI推荐的方法,因为不同于基金会版本的波浪模拟中使用interfaceHeight,ESI波浪模拟中使用的就是sample。但是需要注意的是,可能是因为版本变化或function的具体设置问题,这个代码在处理.xy文件时在分割列时会出错(报错是在49行,报错原因时列数越界),需要把第46行delimiter="\t"修改成delimiter="\s+"。
-