08、【算例】openfoam溃坝

打印 上一主题 下一主题

主题 983|帖子 983|积分 2949

7.1 溃坝

官网
目录:$FOAM_TUTORIALS/multiphase/interFoam/laminar/damBreak
7.1.1 介绍

本案例使用interFoam两相算法,基于流体体积分数(VOF)法,每个网格中的相体积分数(alpha)通过求解一个组分运输方程确定。物理属性基于这个相分数通过加权平均计算。

7.1.2 网格生成
  1. blockMesh
复制代码
7.1.3 边界条件

最顶端atmosphere边界设置为patch
  1. // 0/U
  2. boundaryField
  3. {
  4.         ...
  5.     atmosphere
  6.     {
  7.         type            pressureInletOutletVelocity; // 对所有分量应用zeroGradient条件,当流动为入流时,对边界切向的分量应用fixedValue;
  8.         value           uniform (0 0 0);
  9.     }
  10.     defaultFaces
  11.     {
  12.         type            empty;
  13.     }
  14. }
  15. // 0/p_rgh
  16. boundaryField
  17. {
  18.         ...
  19.     atmosphere
  20.     {
  21.         type            totalPressure; // 一种fixedValue条件,利用指定的总压p0和当地速度U计算获得;
  22.         p0              uniform 0;
  23.     }
  24.     defaultFaces
  25.     {
  26.         type            empty;
  27.     }
  28. }
  29. // 0/alpha.water.orig
  30. boundaryField
  31. {
  32.         ...
  33.     atmosphere
  34.     {
  35.         type            inletOutlet; // 出流时为zeroGradient,入流时则为fixedValue条件;
  36.         inletValue      uniform 0;
  37.         value           uniform 0;
  38.     }
  39.     defaultFaces
  40.     {
  41.         type            empty;
  42.     }
  43. }
  44. // ************************************************************************* //
复制代码
所有壁面边界处,压力场采用fixedFluxPressure边界条件,它自动调整压力梯度使边界通量符合速度边界条件
  1. boundaryField
  2. {
  3.     leftWall
  4.     {
  5.         type            fixedFluxPressure; //
  6.         value           uniform 0;
  7.     }
  8.     rightWall
  9.     {
  10.         type            fixedFluxPressure;
  11.         value           uniform 0;
  12.     }
  13.     lowerWall
  14.     {
  15.         type            fixedFluxPressure;
  16.         value           uniform 0;
  17.     }
  18. }
复制代码
defaultFaces代表此2维问题的前后面,像往常一样,是empty类型
  1.     defaultFaces
  2.     {
  3.         type            empty;
  4.     }
复制代码
7.1.4 设置初场

相当于fluent中的patch,patch出一个水域。
boxToCell通过定义一个最小和最大的向量来创建一个盒子区域,在此区域内为水相,water被设置为1.
在执行setFields之前,先备份0目录下的alpha.water.org(备份文件)为alpha.water。因为setFields工具从文件读取场并重新定义这些场,然后把它们重新写入文件,原始文件会被覆盖,所以需要备份。
  1. /*--------------------------------*- C++ -*----------------------------------*\
  2.   =========                 |
  3.   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
  4.    \\    /   O peration     | Website:  https://openfoam.org
  5.     \\  /    A nd           | Version:  9
  6.      \\/     M anipulation  |
  7. \*---------------------------------------------------------------------------*/
  8. FoamFile
  9. {
  10.     format      ascii;
  11.     class       dictionary;
  12.     location    "system";
  13.     object      setFieldsDict;
  14. }
  15. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
  16. defaultFieldValues
  17. (
  18.     volScalarFieldValue alpha.water 0 // 场内默认为空气
  19. );
  20. regions
  21. (
  22.     boxToCell
  23.     {
  24.         box (0 0 -1) (0.1461 0.292 1); // 对应坐标如下
  25.         fieldValues
  26.         (
  27.             volScalarFieldValue alpha.water 1
  28.         );
  29.     }
  30. );
  31. // ************************************************************************* //
复制代码


使用paraFoam -builtin后处理查看
7.1.5 流体特性

constant/transportProperties
  1. /*--------------------------------*- C++ -*----------------------------------*\
  2.   =========                 |
  3.   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
  4.    \\    /   O peration     | Website:  https://openfoam.org
  5.     \\  /    A nd           | Version:  9
  6.      \\/     M anipulation  |
  7. \*---------------------------------------------------------------------------*/
  8. FoamFile
  9. {
  10.     format      ascii;
  11.     class       dictionary;
  12.     location    "constant";
  13.     object      transportProperties;
  14. }
  15. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
  16. phases (water air); // 两相
  17. water
  18. {
  19.     transportModel  Newtonian; // 牛顿流体
  20.     nu              1e-06; // 运动粘度
  21.     rho             1000; // 密度
  22. }
  23. air
  24. {
  25.     transportModel  Newtonian;
  26.     nu              1.48e-05;
  27.     rho             1;
  28. }
  29. sigma            0.07; // 表面张力
  30. // ************************************************************************* //
复制代码
Newtonian为牛顿流体,CrossPowerLawCoeffs为非牛顿流体。
重力场
  1. /*--------------------------------*- C++ -*----------------------------------*\
  2.   =========                 |
  3.   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
  4.    \\    /   O peration     | Website:  https://openfoam.org
  5.     \\  /    A nd           | Version:  9
  6.      \\/     M anipulation  |
  7. \*---------------------------------------------------------------------------*/
  8. FoamFile
  9. {
  10.     format      ascii;
  11.     class       uniformDimensionedVectorField;
  12.     location    "constant";
  13.     object      g;
  14. }
  15. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
  16. dimensions      [0 1 -2 0 0 0 0];
  17. value           (0 -9.81 0);
  18. // ************************************************************************* //
复制代码
7.1.6 湍流模型
  1. /*--------------------------------*- C++ -*----------------------------------*\
  2.   =========                 |
  3.   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
  4.    \\    /   O peration     | Website:  https://openfoam.org
  5.     \\  /    A nd           | Version:  9
  6.      \\/     M anipulation  |
  7. \*---------------------------------------------------------------------------*/
  8. FoamFile
  9. {
  10.     format      ascii;
  11.     class       dictionary;
  12.     location    "constant";
  13.     object      momentumTransport;
  14. }
  15. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
  16. simulationType  laminar;  // 层流
  17. // ************************************************************************* //
复制代码
7.1.7 时间步长

设置adjustTimeStep为on,表示自动调整时间步长,并设置最大库郎书和最大相场库郎数为1.
设置writeContral为adjustableRunTime,表示强制调整一时间点正好为输出结果的时间。因为自动调整时间步长之后,如果按照固定时间步长间隔保存结果会比较乱,所以需要强制调整。
  1. /*--------------------------------*- C++ -*----------------------------------*\
  2.   =========                 |
  3.   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
  4.    \\    /   O peration     | Website:  https://openfoam.org
  5.     \\  /    A nd           | Version:  9
  6.      \\/     M anipulation  |
  7. \*---------------------------------------------------------------------------*/
  8. FoamFile
  9. {
  10.     format      ascii;
  11.     class       dictionary;
  12.     location    "system";
  13.     object      controlDict;
  14. }
  15. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
  16. application     interFoam;
  17. startFrom       startTime;
  18. startTime       0;
  19. stopAt          endTime;
  20. endTime         1;
  21. deltaT          0.001;
  22. writeControl    adjustableRunTime; // 重点
  23. writeInterval   0.05;
  24. purgeWrite      0;
  25. writeFormat     binary;
  26. writePrecision  6;
  27. writeCompression off;
  28. timeFormat      general;
  29. timePrecision   6;
  30. runTimeModifiable yes;
  31. adjustTimeStep  yes; // 重点
  32. maxCo           1; // 重点
  33. maxAlphaCo      1; // 重点
  34. maxDeltaT       1;
  35. // ************************************************************************* //
复制代码
7.1.8 离散求解
  1. /*--------------------------------*- C++ -*----------------------------------*\
  2.   =========                 |
  3.   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
  4.    \\    /   O peration     | Website:  https://openfoam.org
  5.     \\  /    A nd           | Version:  9
  6.      \\/     M anipulation  |
  7. \*---------------------------------------------------------------------------*/
  8. FoamFile
  9. {
  10.     format      ascii;
  11.     class       dictionary;
  12.     location    "system";
  13.     object      fvSchemes;
  14. }
  15. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
  16. ddtSchemes
  17. {
  18.     default         Euler;
  19. }
  20. gradSchemes
  21. {
  22.     default         Gauss linear;
  23. }
  24. divSchemes
  25. {
  26.     div(rhoPhi,U)  Gauss linearUpwind grad(U);
  27.     div(phi,alpha)  Gauss interfaceCompression vanLeer 1;
  28.     div(((rho*nuEff)*dev2(T(grad(U))))) Gauss linear;
  29. }
  30. laplacianSchemes
  31. {
  32.     default         Gauss linear corrected;
  33. }
  34. interpolationSchemes
  35. {
  36.     default         linear;
  37. }
  38. snGradSchemes
  39. {
  40.     default         corrected;
  41. }
  42. // ************************************************************************* //
复制代码
7.1.9 矩阵求解

nAlphaSubCycles:a方程中子循环的数目,子循环是一个给定时间步内对一个方程附加求解。可以再不降低时间步长的情况下保证解的稳定性。
  1. /*--------------------------------*- C++ -*----------------------------------*\
  2.   =========                 |
  3.   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
  4.    \\    /   O peration     | Website:  https://openfoam.org
  5.     \\  /    A nd           | Version:  9
  6.      \\/     M anipulation  |
  7. \*---------------------------------------------------------------------------*/
  8. FoamFile
  9. {
  10.     format      ascii;
  11.     class       dictionary;
  12.     location    "system";
  13.     object      fvSolution;
  14. }
  15. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
  16. solvers
  17. {
  18.     "alpha.water.*"
  19.     {
  20.         nAlphaCorr      2;
  21.         nAlphaSubCycles 1;
  22.         MULESCorr       yes;
  23.         nLimiterIter    5;
  24.         solver          smoothSolver;
  25.         smoother        symGaussSeidel;
  26.         tolerance       1e-8;
  27.         relTol          0;
  28.     }
  29.     "pcorr.*"
  30.     {
  31.         solver          PCG;
  32.         preconditioner  DIC;
  33.         tolerance       1e-5;
  34.         relTol          0;
  35.     }
  36.     p_rgh
  37.     {
  38.         solver          PCG;
  39.         preconditioner  DIC;
  40.         tolerance       1e-07;
  41.         relTol          0.05;
  42.     }
  43.     p_rghFinal
  44.     {
  45.         $p_rgh;
  46.         relTol          0;
  47.     }
  48.     U
  49.     {
  50.         solver          smoothSolver;
  51.         smoother        symGaussSeidel;
  52.         tolerance       1e-06;
  53.         relTol          0;
  54.     }
  55. }
  56. PIMPLE
  57. {
  58.     momentumPredictor   no;
  59.     nOuterCorrectors    1;
  60.     nCorrectors         3;
  61.     nNonOrthogonalCorrectors 0;
  62. }
  63. relaxationFactors
  64. {
  65.     equations
  66.     {
  67.         ".*" 1;
  68.     }
  69. }
  70. // ************************************************************************* //
复制代码
7.1.10 计算
  1. interFoam | tee log
复制代码

7.1.11 并行计算

如果采用并行计算,程序根据system/decomposeParDict求解.
numberOfSubdomains:指定算例分割子区域数量,即处理器数
simpleCoeffs中,应满足x * y = numberOfSubdomains
这个算例使用2个处理器并行计算。
  1. /*--------------------------------*- C++ -*----------------------------------*\
  2.   =========                 |
  3.   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
  4.    \\    /   O peration     | Website:  https://openfoam.org
  5.     \\  /    A nd           | Version:  9
  6.      \\/     M anipulation  |
  7. \*---------------------------------------------------------------------------*/
  8. FoamFile
  9. {
  10.     format      ascii;
  11.     class       dictionary;
  12.     location    "system";
  13.     object      decomposeParDict;
  14. }
  15. // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
  16. numberOfSubdomains 2; // 重点
  17. method          simple;
  18. simpleCoeffs
  19. {
  20.     n               (1 2 1); // 重点
  21. }
  22. hierarchicalCoeffs
  23. {
  24.     n               (1 1 1);
  25.     order           xyz;
  26. }
  27. manualCoeffs
  28. {
  29.     dataFile        "";
  30. }
  31. distributed     no;
  32. roots           ( );
  33. // ************************************************************************* //
复制代码
如果使用4个,我这里使用的虚拟机,会报错,提示核数不够。
分割
  1. decomposePar
复制代码

并行计算
  1. mpirun -np 2 interFoam -parallel > log
复制代码

查看paraFoam -builtin -case processor0,为一半

合并结果
  1. reconstructPar
复制代码

后处理
  1. paraFoam -builtin
复制代码


免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

吴旭华

金牌会员
这个人很懒什么都没写!
快速回复 返回顶部 返回列表