Navigation

    CFD中文网

    CFD中文网

    • Login
    • Search
    • 最新

    OpenFOAM小代码

    OpenFOAM
    13
    32
    7562
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • 霜
      霜染丹枫 @Zhong-combustion last edited by

      @Zhong-combustion 你好,我目前也在用LES做加热管流的湍流研究,关于湍流入口的设置看了一些资料,如有兴趣,可以加个qq:1191364394,共同学习探讨。

      1 Reply Last reply Reply Quote
      • Z
        Zhy2022 last edited by

        东岳老师您好,请问如果是两相流中相分数(比如alpha.particle)随时间变化,它在codeFixedValue中应该怎么定义呢?

        李东岳 1 Reply Last reply Reply Quote
        • 李东岳
          李东岳 管理员 @Zhy2022 last edited by

          @Zhy2022 codedFixedValue上面不是有嘛,你举一反三一下咩

          线上CFD课程 7月1日报名截止 http://dyfluid.com/class.html
          CFD高性能服务器 http://dyfluid.com/servers.html

          Z 2 Replies Last reply Reply Quote
          • Z
            Zhy2022 @李东岳 last edited by

            @东岳 东岳老师,没能找出报错原因:135: ,只能再来麻烦一下您:

            INLET1
                {
                    type            codedFixedValue;
                    value           $internalField;
                    name            stepInjection;
                    redictType      variedValue;
                    code
                    #{
                         scalar alphapar = this->patch().fluid().phase();
            
                         scalar t = this->db().time().value();
                   
                         if(t >= 0 && t<=5)
                         {
                              alphapar = 0;
                         }
                         
                         else
            	     {
            	          alphapar = 0.15;
            	     }
            
            	     operator==(alphapar)
            
                     #};
                    
                }
            

            56e49c26-63f1-479c-bd8e-d479760394d9-image.png

            1 Reply Last reply Reply Quote
            • Z
              Zhy2022 @李东岳 last edited by

              @东岳 东岳老师,问题已解决!无法编译与文件路径有关
              ee3e6b1d-91b1-4633-879c-41502c56cf20-image.png

              1 Reply Last reply Reply Quote
              • V
                veen last edited by

                fvOption小工具

                根据GitHub上一个python脚本改写了一个生成fvOption的小工具 https://github.com/Veenxz/fvSchemes
                用Foam没有多久,各位大佬可以多提提意见。

                # version 2.0
                # Based on https://github.com/Carlopasquinucci/fvSchemes
                # Generation by Veenxz
                # relaesed under license GPL GNU 3.0
                
                steady = True
                pseudo_transient = False
                precision = 2    # First order 1 or Second order 2
                unbounded = False
                LUST = False
                secondorder = True
                
                maxOrtho = 80
                maxSkew = 20
                
                # Header and Footer
                h = [
                    "/*--------------------------------*- C++ -*----------------------------------*|",
                    "| =========                 |                                                 |",
                    "| \\\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |",
                    "|  \\\    /   O peration     | Website:  https://openfoam.org                  |",
                    "|   \\\  /    A nd           | Version:  7                                     |",
                    "|    \\\/     M anipulation  |                                                 |",
                    "\*---------------------------------------------------------------------------*/",
                    "FoamFile", "{", "    version     2.0;", "    format      ascii;",
                    "    class       dictionary;", '    location    "system";', "    object      fvSchemes;",
                    "}",
                    "// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //",
                    ""
                ]
                footer = '\n// ************************************************************************* //'
                
                nonOrthogonalCorrectors = 1
                if (maxOrtho) > 80:
                    print(
                        'Warning: mesh is not so nice. Use 3 nonOrthogonalCorrectors in fvSolution file'
                    )
                    nonOrthogonalCorrectors = 3
                if (maxSkew) > 8:
                    print('Warning: mesh is not so nice')
                
                if (maxOrtho) > 80:
                
                    gradSchemes = (
                        '{\n    default          cellLimited Gauss linear 0.5;\n'
                           '    grad(U)          faceLimited Gauss linear 1.0;\n}'
                    )
                    divSchemes = (
                        '{\n    div(phi,U)       Gauss linearUpwind grad(U);\n'
                           '    div(phi,omega)   Gauss upwind;\n'
                           '    div(phi,k)       Gauss upwind;\n'
                           '    div(phi,e)       Gauss upwind;\n'
                           '    div((nuEff*dev(T(grad(U))))) Gauss linear;\n}'
                    )
                    laplacianSchemes = (
                        '{\n    default          Gauss linear limited 0.333;\n}'
                    )
                    snGradSchemes = (
                        '{\n    default          Gauss linear limited 0.333;\n}'
                    )
                
                    blending = 0.2
                    nonOrthogonalCorrectors = 3
                
                if (maxOrtho) > 70:
                
                    gradSchemes = (
                        '{\n    default          cellLimited Gauss linear 0.5;\n'
                           '    grad(U)          cellLimited Gauss linear 1.0;\n}'
                    )
                    divSchemes = (
                        '{\n    div(phi,U)       Gauss linearUpwind grad(U);\n'
                           '    div(phi,omega)   Gauss linearUpwind grad(omega);\n'
                           '    div(phi,k)       Gauss linearUpwind grad(k);\n'
                           '    div(phi,e)       Gauss linearUpwind grad(e);\n'
                           '    div((nuEff*dev(T(grad(U))))) Gauss linear;\n}'
                    )
                    laplacianSchemes = (
                        '{\n    default          Gauss linear limited 0.5;\n}'
                    )
                    snGradSchemes = (
                        '{\n    default          Gauss linear limited 0.5;\n}'
                    )
                
                    blending = 0.5
                    nonOrthogonalCorrectors = 3
                
                if (maxOrtho) > 60:
                
                    gradSchemes = (
                        '{\n    default          cellMDLimited Gauss linear 0.5;\n'
                           '    grad(U)          cellMDLimited Gauss linear 0.5;\n}'
                    )
                    divSchemes = (
                        '{\n    div(phi,U)       Gauss linearUpwind grad(U);\n'
                           '    div(phi,omega)   Gauss linearUpwind grad(omega);\n'
                           '    div(phi,k)       Gauss linearUpwind grad(k);\n'
                           '    div(phi,e)       Gauss linearUpwind grad(e);\n'
                           '    div((nuEff*dev(T(grad(U))))) Gauss linear;\n}'
                    )
                    laplacianSchemes = (
                        '{\n    default          Gauss linear limited 0.777;\n} '
                    )
                    snGradSchemes = (
                        '{\n    default          Gauss linear limited 0.777;\n} '
                    )
                
                    blending = 0.7
                    nonOrthogonalCorrectors = 2
                
                if (maxOrtho) > 0:
                
                    gradSchemes = (
                        '{\n    default          cellMDLimited Gauss linear 0;\n'
                           '    grad(U)          cellMDLimited Gauss linear 0.333;\n}'
                    )
                    divSchemes = (
                        '{\n    div(phi,U)       Gauss linearUpwind grad(U);\n'
                           '    div(phi,omega)   Gauss linearUpwind grad(omega);\n'
                           '    div(phi,k)       Gauss linearUpwind grad(k);\n'
                           '    div(phi,e)       Gauss linearUpwind grad(e);\n'
                           '    div((nuEff*dev(T(grad(U))))) Gauss linear;\n}'
                    )
                    laplacianSchemes = (
                        '{\n    default          Gauss linear limited 0.95;\n}'
                    )
                    snGradSchemes = (
                        '{\n    default          Gauss linear limited 0.95;\n}'
                    )
                
                    blending = 0.8
                    nonOrthogonalCorrectors = 1
                
                if (LUST):
                    gradSchemes = (
                        '{\n    default          Gauss linear;\n'
                           '    grad(U)          cellMDLimited leastSquares 1;\n}'
                    )
                    divSchemes = (
                        '{\n    div(phi,U)       Gauss LUST grad(U);\n'
                           '    div(phi,omega)   Gauss LUST grad(omega);\n'
                           '    div(phi,k)       Gauss LUST grad(k);\n'
                           '    div(phi,e)       Gauss LUST grad(e);\n'
                           '    div((nuEff*dev(T(grad(U))))) Gauss linear;\n}'
                    )
                    laplacianSchemes = (
                        '{\n    default          Gauss linear corrected;\n}'
                    )
                    snGradSchemes = (
                        '{\n    default          Gauss linear corrected;\n}'
                    )
                    
                    blending = 0.9
                    nonOrthogonalCorrectors = 1
                
                if (steady):
                    ddtSchemes = (
                        '{\n    default          steadyState;\n}'
                    )
                    if (pseudo_transient):
                                ddtSchemes = (
                                    '{\n    default          localEuler;\n}'
                                )
                else:
                    ddtSchemes = (
                        '{\n    default           CrankNicolson ' + str(blending) + ' ;\n}'
                    )
                    if precision == 1:
                        ddtSchemes = (
                            '{\n    default           Euler;\n}'
                        )
                    if (unbounded):
                        ddtSchemes = (
                            '{\n    default           backward;\n}'
                        )
                
                
                wallDist = (
                    "{\n    method           meshWave;\n}"
                )
                
                #open fvSchemes and write inside
                
                f = open("fvSchemes", "w")
                
                for i in h:
                	f.write(i + "\n")
                
                f.write("ddtSchemes" + "\n")
                f.write(ddtSchemes + "\n")
                f.write("\n")
                f.write("gradSchemes" + "\n")
                f.write(gradSchemes + "\n")
                f.write("\n")
                f.write("divSchemes" + "\n")
                f.write(divSchemes + "\n")
                f.write("\n")
                f.write("laplacianSchemes" + "\n")
                f.write(laplacianSchemes + "\n")
                f.write("\n")
                f.write("snGradSchemes" + "\n")
                f.write(snGradSchemes + "\n")
                f.write("\n")
                f.write("wallDist" + "\n")
                f.write(wallDist + "\n")
                f.write(footer)
                
                f.close()
                
                print('File fvSchemes created')
                
                
                李东岳 V 2 Replies Last reply Reply Quote
                • 李东岳
                  李东岳 管理员 @veen last edited by

                  @veen 厉害厉害 :146: :146:

                  线上CFD课程 7月1日报名截止 http://dyfluid.com/class.html
                  CFD高性能服务器 http://dyfluid.com/servers.html

                  1 Reply Last reply Reply Quote
                  • V
                    veen @veen last edited by

                    @veen 这个代码还有些格式没法用……我回头测试了再放到github大家看仓库里边的代码就好了。

                    1 Reply Last reply Reply Quote
                    • H
                      hongjiewang last edited by

                      @李东岳 在 OpenFOAM小代码 中说:

                      IOField<scalar> utau
                      (
                      IOobject
                      (
                      "utau",
                      runTime.constant(),
                      "../postProcessing",
                      mesh,
                      IOobject::NO_READ,
                      IOobject::AUTO_WRITE
                      ),
                      scalarField(totalFSize,0.0)
                      );

                      请问老师,如果我想要在postProcessing中输出一个标量,他只是一个数,并不是场量,我应该怎么定义他的类型。上面这种方法是不是只适应于场量的输出。我想输出的是下面c的数值。

                      const volScalarField& b = mesh().lookupObject<volScalarField>("alpha.liquid");
                      scalar c= b.weightedAverage(mesh().V()).value();
                      
                      李东岳 1 Reply Last reply Reply Quote
                      • 李东岳
                        李东岳 管理员 @hongjiewang last edited by

                        @hongjiewang

                            IOList<scalar> utau
                            (
                                IOobject
                                (
                                    "utau",
                                    runTime.constant(),
                                    "../postProcessing",
                                    mesh,
                                    IOobject::NO_READ,
                                    IOobject::AUTO_WRITE 
                                ),
                                1
                            );
                            
                            utau[0] = b.weightedAverage(mesh().V()).value();
                        

                        线上CFD课程 7月1日报名截止 http://dyfluid.com/class.html
                        CFD高性能服务器 http://dyfluid.com/servers.html

                        H vbcwl 3 Replies Last reply Reply Quote
                        • H
                          hongjiewang @李东岳 last edited by

                          @李东岳

                            totalLiquid
                            {        
                                  libs            (utilityFunctionObjects);
                                  type            coded;
                                  name            totalLiquid;
                                  enabled         true;
                                  writeControl    timeStep;
                                  writeInterval   1;
                                  
                                  codeOptions
                                  #{
                                      -I$(LIB_SRC)/meshTools/lnInclude
                                  #};
                          
                                  codeExecute
                                  #{
                          
                                      const volScalarField& b =
                                          mesh().lookupObject<volScalarField>("alpha.liquid");
                          
                                      IOList<scalar> liquidFraction
                                      (
                                          IOobject
                                          (
                                              "liquidFraction",
                                              mesh().time().constant(),
                                              "../postProcessing",
                                              mesh(),
                                              IOobject::NO_READ,
                                              IOobject::AUTO_WRITE
                                          ),
                                          1
                                      );
                                      liquidFraction[0] = b.weightedAverage(mesh().V()).value();
                                  #};
                              }
                          

                          东岳老师,我这样添加到controlDict里,运行后postProcessing里并没有出现liquidFraction的值。
                          1618213472(1).png

                          H 1 Reply Last reply Reply Quote
                          • H
                            hongjiewang @hongjiewang last edited by hongjiewang

                            @hongjiewang 在 OpenFOAM小代码 中说:

                            @李东岳

                              totalLiquid
                              {        
                                    libs            (utilityFunctionObjects);
                                    type            coded;
                                    name            totalLiquid;
                                    enabled         true;
                                    writeControl    timeStep;
                                    writeInterval   1;
                                    
                                    codeOptions
                                    #{
                                        -I$(LIB_SRC)/meshTools/lnInclude
                                    #};
                            
                                    codeExecute
                                    #{
                            
                                        const volScalarField& b =
                                            mesh().lookupObject<volScalarField>("alpha.liquid");
                            
                                        IOList<scalar> liquidFraction
                                        (
                                            IOobject
                                            (
                                                "liquidFraction",
                                                mesh().time().constant(),
                                                "../postProcessing",
                                                mesh(),
                                                IOobject::NO_READ,
                                                IOobject::AUTO_WRITE
                                            ),
                                            1
                                        );
                                        liquidFraction[0] = b.weightedAverage(mesh().V()).value();
                                    #};
                                }
                            

                            东岳老师,我这样添加到controlDict里,运行后postProcessing里并没有出现liquidFraction的值。
                            1618213472(1).png

                            需要修改两个部分,
                            1.在下方添加 .write()
                            2.将codeExecute改为codeWrite
                            之后就可以得到想要的相含量结果。

                            1 Reply Last reply Reply Quote
                            • H
                              hongjiewang @李东岳 last edited by

                              @李东岳

                              FoamFile
                              {
                                  version     2.0;
                                  format      ascii;
                                  class       scalarField;
                                  location    "constant/../postProcessing";
                                  object      totalLiquid;
                              }
                              // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
                              
                              1(0.2)
                              

                              麻烦老师再帮我看一下,为什么每次都只会输出一个时刻的值,不会随时间增加输出的

                              1 Reply Last reply Reply Quote
                              • 李东岳
                                李东岳 管理员 last edited by 李东岳

                                meanDiameter
                                    {
                                        type            coded;
                                        libs            ("libutilityFunctionObjects.so");
                                        name            error;
                                    
                                        codeExecute
                                        #{
                                            const volScalarField& d =
                                                mesh().lookupObject<volScalarField>("d.alpha.oil");
                                
                                            scalar d32 = d.weightedAverage(mesh().V()).value();
                                    
                                            if (Pstream::master())
                                            {
                                                std::ofstream file;
                                                file.open ("d32", std::ofstream::out | std::ofstream::app);
                                                file << mesh().time().timeName() << " " << d32 << "\n";
                                                file.close();
                                            }
                                        #};
                                    }
                                

                                我最近也凑巧要用这个,我用的上面这种方式。

                                线上CFD课程 7月1日报名截止 http://dyfluid.com/class.html
                                CFD高性能服务器 http://dyfluid.com/servers.html

                                1 Reply Last reply Reply Quote
                                • 五好青年
                                  五好青年 @李东岳 last edited by

                                  @李东岳
                                  请问东岳老师:135:

                                  (1) 东岳老师,您上面写的:codedFixedValue
                                  (2) yfclark朋友,上面写的:CodeStream

                                  在自定义边界条件方面,这两个有啥区别啊,我研究了几天没想明白

                                  I am a CFD machine with no emotions. Welcome to browse my Bilibili, search: seeeeeeeeeeer

                                  五好青年 1 Reply Last reply Reply Quote
                                  • 五好青年
                                    五好青年 @五好青年 last edited by

                                    @yfclark
                                    朋友,您好:

                                    codedFixedValue和CodeStream

                                    你知道在自定义边界条件方面,这两个有啥区别啊,我研究了几天没想明白

                                    I am a CFD machine with no emotions. Welcome to browse my Bilibili, search: seeeeeeeeeeer

                                    李东岳 1 Reply Last reply Reply Quote
                                    • 李东岳
                                      李东岳 管理员 @五好青年 last edited by

                                      codedFixedValue更简单,直接用

                                      code
                                              #{
                                                  operator==(min(10, 0.1*this->db().time().value()));
                                              #};
                                      

                                      就可以赋值。CodeStream更普适性,我见过一些代码用CodeStream对内部场进行初始化。比如建立U的内部场与空间的函数。

                                      线上CFD课程 7月1日报名截止 http://dyfluid.com/class.html
                                      CFD高性能服务器 http://dyfluid.com/servers.html

                                      H 1 Reply Last reply Reply Quote
                                      • H
                                        hongjiewang @李东岳 last edited by

                                        @李东岳 目前我需要将温度边界和压力边界定义为随相含量变化的一个场。我只可以做到变化之后的也是同一类边界条件,但是像下图中的气相区压力是第一类边界条件,液相区温度是第二类边界条件。请问这种变边界类型的边界应该怎么定义~1632279639(1).png

                                        H 1 Reply Last reply Reply Quote
                                        • H
                                          hongjiewang @hongjiewang last edited by hongjiewang

                                          @hongjiewang 在 OpenFOAM小代码 中说:

                                          @李东岳 目前我需要将温度边界和压力边界定义为随相含量变化的一个场。我只可以做到变化之后的也是同一类边界条件,但是像下图中的气相区压力是第一类边界条件,液相区温度是第二类边界条件。请问这种变边界类型的边界应该怎么定义~1632279639(1).png

                                          已解决压力的~但是温度的第二类和第三类的转换还没有解决~

                                          1 Reply Last reply Reply Quote
                                          • Referenced by  李东岳 李东岳 
                                          • 疏
                                            疏影横斜水清浅 last edited by

                                            你好,请问const polyPatch& cPatch = mesh.boundaryMesh()[patchID];与const fvPatch& cPatch = mesh.boundary()[patchID];有什么不同?

                                            1 Reply Last reply Reply Quote
                                            • D
                                              Dingcy @李东岳 last edited by

                                              @李东岳 在 OpenFOAM小代码 中说:

                                              //const fvBoundaryMesh& boundaryMesh = boundaryPatch.boundaryMesh();
                                              //const fvMesh& mesh = boundaryMesh.mesh();

                                              我想用codedFixedValue,写一个壁面的边界条件,壁面都是wall,而不是patch,所以这里想用这两个命令,但是编译过程中总是提示9e34b123-be2b-4f45-bace-a18c0fd0bd1e-image.png我是不是应该声明点啥呢?我也查了网上的,发现全是在inlet使用这个功能,然后入口是patch

                                              我希望我得到的少一点,少一点,再少一点......

                                              李东岳 1 Reply Last reply Reply Quote
                                              • 李东岳
                                                李东岳 管理员 @Dingcy last edited by

                                                @dingcy

                                                const polyPatch& cPatch = mesh.boundaryMesh()[patchID]
                                                

                                                类似这个?

                                                线上CFD课程 7月1日报名截止 http://dyfluid.com/class.html
                                                CFD高性能服务器 http://dyfluid.com/servers.html

                                                D 1 Reply Last reply Reply Quote
                                                • D
                                                  Dingcy @李东岳 last edited by

                                                  @李东岳 好像不是这个0acf9421-5d4d-4d1a-8874-380f51687e50-image.png 又显示了mesh没有声明....

                                                  我希望我得到的少一点,少一点,再少一点......

                                                  1 Reply Last reply Reply Quote
                                                  • vbcwl
                                                    vbcwl @李东岳 last edited by

                                                    @李东岳 能请教下这个具体怎么使用么?我没能输出utau:chouchou:

                                                    LBE

                                                    李东岳 1 Reply Last reply Reply Quote
                                                    • 李东岳
                                                      李东岳 管理员 @vbcwl last edited by

                                                      @vbcwl 上面那些代码么。上面那些代码都需要自己写到代码里面去。还不是简单的使用。需要有编程基础,这些代码起到一定的提示作用。

                                                      线上CFD课程 7月1日报名截止 http://dyfluid.com/class.html
                                                      CFD高性能服务器 http://dyfluid.com/servers.html

                                                      1 Reply Last reply Reply Quote
                                                      • First post
                                                        Last post

                                                      CFD中文网 | 东岳流体 | 京ICP备15017992号-2
                                                      论坛登录问题反馈可联系 li.dy@dyfluid.com