08、【算例】openfoam溃坝

yizhihongxing

7.1 溃坝

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

7.1.1 介绍

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

7.1.2 网格生成

blockMesh

7.1.3 边界条件

最顶端atmosphere边界设置为patch

// 0/U
boundaryField
{
	...
    atmosphere
    {
        type            pressureInletOutletVelocity; // 对所有分量应用zeroGradient条件,当流动为入流时,对边界切向的分量应用fixedValue;
        value           uniform (0 0 0);
    }
    defaultFaces
    {
        type            empty;
    }
}

// 0/p_rgh
boundaryField
{
	...
    atmosphere
    {
        type            totalPressure; // 一种fixedValue条件,利用指定的总压p0和当地速度U计算获得;
        p0              uniform 0;
    }

    defaultFaces
    {
        type            empty;
    }
}

// 0/alpha.water.orig
boundaryField
{
	...
    atmosphere
    {
        type            inletOutlet; // 出流时为zeroGradient,入流时则为fixedValue条件;
        inletValue      uniform 0;
        value           uniform 0;
    }

    defaultFaces
    {
        type            empty;
    }
}
// ************************************************************************* //

所有壁面边界处,压力场采用fixedFluxPressure边界条件,它自动调整压力梯度使边界通量符合速度边界条件

boundaryField
{
    leftWall
    {
        type            fixedFluxPressure; // 
        value           uniform 0;
    }

    rightWall
    {
        type            fixedFluxPressure;
        value           uniform 0;
    }

    lowerWall
    {
        type            fixedFluxPressure;
        value           uniform 0;
    }
}

defaultFaces代表此2维问题的前后面,像往常一样,是empty类型

    defaultFaces
    {
        type            empty;
    }

7.1.4 设置初场

相当于fluent中的patch,patch出一个水域。
boxToCell通过定义一个最小和最大的向量来创建一个盒子区域,在此区域内为水相,water被设置为1.
在执行setFields之前,先备份0目录下的alpha.water.org(备份文件)为alpha.water。因为setFields工具从文件读取场并重新定义这些场,然后把它们重新写入文件,原始文件会被覆盖,所以需要备份。

/*--------------------------------*- C++ -*----------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     | Website:  https://openfoam.org
    \\  /    A nd           | Version:  9
     \\/     M anipulation  |
\*---------------------------------------------------------------------------*/
FoamFile
{
    format      ascii;
    class       dictionary;
    location    "system";
    object      setFieldsDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

defaultFieldValues
(
    volScalarFieldValue alpha.water 0 // 场内默认为空气
);

regions
(
    boxToCell
    {
        box (0 0 -1) (0.1461 0.292 1); // 对应坐标如下
        fieldValues
        (
            volScalarFieldValue alpha.water 1
        );
    }
);
// ************************************************************************* //

image.png
image.png

使用paraFoam -builtin后处理查看

7.1.5 流体特性

constant/transportProperties

/*--------------------------------*- C++ -*----------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     | Website:  https://openfoam.org
    \\  /    A nd           | Version:  9
     \\/     M anipulation  |
\*---------------------------------------------------------------------------*/
FoamFile
{
    format      ascii;
    class       dictionary;
    location    "constant";
    object      transportProperties;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

phases (water air); // 两相

water
{
    transportModel  Newtonian; // 牛顿流体
    nu              1e-06; // 运动粘度
    rho             1000; // 密度
}

air
{
    transportModel  Newtonian;
    nu              1.48e-05;
    rho             1;
}

sigma            0.07; // 表面张力

// ************************************************************************* //

Newtonian为牛顿流体,CrossPowerLawCoeffs为非牛顿流体。

重力场

/*--------------------------------*- C++ -*----------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     | Website:  https://openfoam.org
    \\  /    A nd           | Version:  9
     \\/     M anipulation  |
\*---------------------------------------------------------------------------*/
FoamFile
{
    format      ascii;
    class       uniformDimensionedVectorField;
    location    "constant";
    object      g;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

dimensions      [0 1 -2 0 0 0 0];
value           (0 -9.81 0);


// ************************************************************************* //

7.1.6 湍流模型

/*--------------------------------*- C++ -*----------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     | Website:  https://openfoam.org
    \\  /    A nd           | Version:  9
     \\/     M anipulation  |
\*---------------------------------------------------------------------------*/
FoamFile
{
    format      ascii;
    class       dictionary;
    location    "constant";
    object      momentumTransport;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

simulationType  laminar;  // 层流


// ************************************************************************* //

7.1.7 时间步长

设置adjustTimeStep为on,表示自动调整时间步长,并设置最大库郎书和最大相场库郎数为1.
设置writeContral为adjustableRunTime,表示强制调整一时间点正好为输出结果的时间。因为自动调整时间步长之后,如果按照固定时间步长间隔保存结果会比较乱,所以需要强制调整。

/*--------------------------------*- C++ -*----------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     | Website:  https://openfoam.org
    \\  /    A nd           | Version:  9
     \\/     M anipulation  |
\*---------------------------------------------------------------------------*/
FoamFile
{
    format      ascii;
    class       dictionary;
    location    "system";
    object      controlDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

application     interFoam;

startFrom       startTime;

startTime       0;

stopAt          endTime;

endTime         1;

deltaT          0.001;

writeControl    adjustableRunTime; // 重点

writeInterval   0.05;

purgeWrite      0;

writeFormat     binary;

writePrecision  6;

writeCompression off;

timeFormat      general;

timePrecision   6;

runTimeModifiable yes;

adjustTimeStep  yes; // 重点

maxCo           1; // 重点
maxAlphaCo      1; // 重点

maxDeltaT       1;


// ************************************************************************* //

7.1.8 离散求解

/*--------------------------------*- C++ -*----------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     | Website:  https://openfoam.org
    \\  /    A nd           | Version:  9
     \\/     M anipulation  |
\*---------------------------------------------------------------------------*/
FoamFile
{
    format      ascii;
    class       dictionary;
    location    "system";
    object      fvSchemes;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

ddtSchemes
{
    default         Euler;
}

gradSchemes
{
    default         Gauss linear;
}

divSchemes
{
    div(rhoPhi,U)  Gauss linearUpwind grad(U);
    div(phi,alpha)  Gauss interfaceCompression vanLeer 1;
    div(((rho*nuEff)*dev2(T(grad(U))))) Gauss linear;
}

laplacianSchemes
{
    default         Gauss linear corrected;
}

interpolationSchemes
{
    default         linear;
}

snGradSchemes
{
    default         corrected;
}


// ************************************************************************* //

7.1.9 矩阵求解

nAlphaSubCycles:a方程中子循环的数目,子循环是一个给定时间步内对一个方程附加求解。可以再不降低时间步长的情况下保证解的稳定性。

/*--------------------------------*- C++ -*----------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     | Website:  https://openfoam.org
    \\  /    A nd           | Version:  9
     \\/     M anipulation  |
\*---------------------------------------------------------------------------*/
FoamFile
{
    format      ascii;
    class       dictionary;
    location    "system";
    object      fvSolution;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

solvers
{
    "alpha.water.*"
    {
        nAlphaCorr      2;
        nAlphaSubCycles 1;

        MULESCorr       yes;
        nLimiterIter    5;

        solver          smoothSolver;
        smoother        symGaussSeidel;
        tolerance       1e-8;
        relTol          0;
    }

    "pcorr.*"
    {
        solver          PCG;
        preconditioner  DIC;
        tolerance       1e-5;
        relTol          0;
    }

    p_rgh
    {
        solver          PCG;
        preconditioner  DIC;
        tolerance       1e-07;
        relTol          0.05;
    }

    p_rghFinal
    {
        $p_rgh;
        relTol          0;
    }

    U
    {
        solver          smoothSolver;
        smoother        symGaussSeidel;
        tolerance       1e-06;
        relTol          0;
    }
}

PIMPLE
{
    momentumPredictor   no;
    nOuterCorrectors    1;
    nCorrectors         3;
    nNonOrthogonalCorrectors 0;
}

relaxationFactors
{
    equations
    {
        ".*" 1;
    }
}


// ************************************************************************* //

7.1.10 计算

interFoam | tee log

800

7.1.11 并行计算

如果采用并行计算,程序根据system/decomposeParDict求解.
numberOfSubdomains:指定算例分割子区域数量,即处理器数
simpleCoeffs中,应满足x * y = numberOfSubdomains
这个算例使用2个处理器并行计算。

/*--------------------------------*- C++ -*----------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     | Website:  https://openfoam.org
    \\  /    A nd           | Version:  9
     \\/     M anipulation  |
\*---------------------------------------------------------------------------*/
FoamFile
{
    format      ascii;
    class       dictionary;
    location    "system";
    object      decomposeParDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

numberOfSubdomains 2; // 重点

method          simple;

simpleCoeffs
{
    n               (1 2 1); // 重点
}

hierarchicalCoeffs
{
    n               (1 1 1);
    order           xyz;
}

manualCoeffs
{
    dataFile        "";
}

distributed     no;

roots           ( );


// ************************************************************************* //

如果使用4个,我这里使用的虚拟机,会报错,提示核数不够。

分割

decomposePar

image.png
并行计算

mpirun -np 2 interFoam -parallel > log

image.png
查看paraFoam -builtin -case processor0,为一半
800
合并结果

reconstructPar

800
后处理

paraFoam -builtin

800

原文链接:https://www.cnblogs.com/dbai/p/17278927.html

本站文章如无特殊说明,均为本站原创,如若转载,请注明出处:08、【算例】openfoam溃坝 - Python技术站

(0)
上一篇 2023年4月18日
下一篇 2023年4月18日

相关文章

  • STL容器之queue

    是什么 循环队列, FIFO先进先出 怎么用 初始化 //C11 deque<int> deq{1,2,3,4,5}; //拷贝构造,可以拷贝deque queue<int> que(deq); //100个5 queue<int> que2(100,5); //运算符重载 que2 = que; 操作 //队尾添加元素 …

    C++ 2023年4月17日
    00
  • C++ 并发编程实战 第二章 线程管控

    第二章 线程管控 std::thread 简介 构造和析构函数 /// 默认构造 /// 创建一个线程,什么也不做 thread() noexcept; /// 带参构造 /// 创建一个线程,以 A 为参数执行 F 函数 template <class Fn, class… Args> explicit thread(Fn&&amp…

    C++ 2023年4月17日
    00
  • C++ 入门

    001 c++ 如何工作 任何以 # 开头的语句,都是预处理语句,所谓的预处理语句,在编译之前,就已经被处理了 关键字 include:找到 <> 文件(通常称为“头文件”),然后将 <> 中的所有内容拷贝到现在的文件里 main()比较特殊,虽然它的返回值类型是 int,但它不一定需要返回值,如果不设置返回值,默认返回 0 <…

    C++ 2023年5月11日
    00
  • 【Visual Leak Detector】源码文件概览

    说明 使用 VLD 内存泄漏检测工具辅助开发时整理的学习笔记。本篇对 VLD 源码包中的各文件用途做个概述。同系列文章目录可见 《内存泄漏检测工具》目录 目录 说明 1. 整体概览 2. 文件夹 .teamcity 3 文件夹 lib 3.1 文件夹 cppformat(生成 libformat) 3.2 文件夹 dbghelp 3.3 文件夹 gtest(…

    C++ 2023年4月24日
    00
  • Qt-FFmpeg开发-视频播放(5)

    音视频/FFmpeg #Qt Qt-FFmpeg开发-视频播放【软/硬解码 + OpenGL显示YUV/NV12】 目录 音视频/FFmpeg #Qt Qt-FFmpeg开发-视频播放【软/硬解码 + OpenGL显示YUV/NV12】 1、概述 2、实现效果 3、FFmpeg硬解码流程 4、优化av_hwframe_transfer_data()性能低问题…

    C++ 2023年4月17日
    00
  • C++的拓扑排序实现

    template<typename T = CString, typename _Data = CString> struct Union_node//!< 节点 { Union_node() :nColor(0) {} std::vector<Union_node*> vecNodeSon; T key;//!< 关键数…

    C++ 2023年4月22日
    00
  • 二分查找算法讲解及其C++代码实现

    二分查找算法是一种常用的查找算法,也被称为折半查找。它可以在有序的数组或列表中快速查找需要的元素。 算法描述: 首先确定数组的中间位置mid=(left+right)/2; 然后将要查找的值key与中间位置的值进行比较; 如果key等于中间位置的值,则查找成功,返回mid; 如果key小于中间位置的值,则在左半部分继续查找; 如果key大于中间位置的值,则在…

    C++ 2023年4月30日
    00
  • 驱动开发:内核使用IO/DPC定时器

    本章将继续探索驱动开发中的基础部分,定时器在内核中同样很常用,在内核中定时器可以使用两种,即IO定时器,以及DPC定时器,一般来说IO定时器是DDK中提供的一种,该定时器可以为间隔为N秒做定时,但如果要实现毫秒级别间隔,微秒级别间隔,就需要用到DPC定时器,如果是秒级定时其两者基本上无任何差异,本章将简单介绍IO/DPC这两种定时器的使用技巧。 首先来看IO…

    C++ 2023年4月18日
    00
合作推广
合作推广
分享本页
返回顶部