Skip to content
  • 最新
  • 版块
  • 东岳流体
  • 随机看[请狂点我]
皮肤
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • 默认(不使用皮肤)
  • 不使用皮肤
折叠
CFD中文网

CFD中文网

  1. CFD中文网
  2. OpenFOAM
  3. codedsource源项不收敛

codedsource源项不收敛

已定时 已固定 已锁定 已移动 OpenFOAM
7 帖子 2 发布者 765 浏览
  • 从旧到新
  • 从新到旧
  • 最多赞同
回复
  • 在新帖中回复
登录后回复
此主题已被删除。只有拥有主题管理权限的用户可以查看。
  • 1 离线
    1 离线
    16c
    写于 最后由 编辑
    #1

    我在fvoptions里面想设置一个区域性的阻力源项 ,但是因为需要实现的结构比较特殊,所以没法用toposet去进行捕捉获取,然后知乎看见一个大佬用codedsource写的一个特定区域的动量源项合计自己试试去写一个这种,为了尝试设置的阻力源项可不可用我就toposet了一个区域合计试试,但是无论我的源项是纯数字还是仿darcy-forchheimer公式类型的他用interFoam跑都不收敛,找了好几天论坛视频啥的也找不到原因,vscode报错也只是给代码报错,偶尔代码看起来没错误但是跑起来就是不收敛。现在目前写的是如下这样的,因为回头要耦合dem,所以of版本是5.x。

    momentumSource
    {
         type            vectorCodedSource;
         active          yes;
         name            sourceTime;
            vectorCodedSourceCoeffs
            {
                selectionMode  cellZone;         // all;
                cellZone        pZone;
                fields          (U);
                codeInclude
                #{
                    
                #};
                codeCorrect
                #{
            //        Pout<< "**codeCorrect**" << endl;
                #};
                codeAddSup
                #{
           //         Pout<< "**codeAddSup**" << endl;
             
                   //    const vectorField& C = mesh_.C();
                    const scalarField& V = mesh_.V();
                      vectorField& Usource = eqn.source();
                      const vectorField& U = mesh().lookupObject<volVectorField>("U");
                      const scalarField& Rho = mesh().lookupObject<volScalarField>("rho");
                      const scalarField& nu = mesh().lookupObject<volScalarField>("nu");
                      const scalarField& magU = mag(U);
                        scalar A = 10;
                        scalar B = 10;
                        forAll(V,i)
                        {
                        Usource -= (A * nu * Rho + B * Rho * magU / 2) * U ;                 
                        }  
                    // Info << "***codeAddSup***" << nl;                                         
                                   
                #};
                codeSetValue
                #{
                   // Pout<< "**codeSetValue**" << endl;
                #};
                // Dummy entry. Make dependent on above to trigger recompilation
                code
                #{
                    $codeInclude
                    $codeCorrect
                    $codeAddSup
                    $codeSetValue
                #};
            }
            sourceTimeCoeffs
            {
                $vectorCodedSourceCoeffs;
            }
    }
    

    请各位大佬各位巨佬帮着指点一下哪里出现了问题。

    1 条回复 最后回复
  • 李东岳李 在线
    李东岳李 在线
    李东岳 管理员
    写于 最后由 李东岳 编辑
    #2

    fvOptions这个方程的正负号你关注一下,看看是不是写错了,跟常规是相反的。另外你还要关注一下网格体积,你看看是不是没考虑到。

    http://dyfluid.com/index.html
    需要帮助debug算例的看这个 https://cfd-china.com/topic/8018

    1 1 条回复 最后回复
  • 1 离线
    1 离线
    16c
    在 中回复了 李东岳 最后由 编辑
    #3

    @李东岳
    这个东西我也很奇怪,就是我看fluid mechanics 101的多孔介质视频 给出的多孔介质公式是
    b45cbd5d-7199-4001-8da1-9202ad78c559-image.png
    这个形式的,然后看动量方程里面各项基本都是力的形式,我之前就想当然在后面的公式里面多乘了个体积V,后来看of帮助文档里面写的是
    766c8839-ea13-44ac-8f0c-11b5b3c35efa-image.png
    我就又改成上面那个形式,但是感觉好像写完了之后无论哪个形式也不收敛。。。

    1 条回复 最后回复
  • 李东岳李 在线
    李东岳李 在线
    李东岳 管理员
    写于 最后由 编辑
    #4

    你这个看起来就是多加了一个阻力。你需要乘V,同时是正号。

    http://dyfluid.com/index.html
    需要帮助debug算例的看这个 https://cfd-china.com/topic/8018

    1 条回复 最后回复
  • 1 离线
    1 离线
    16c
    写于 最后由 编辑
    #5

    给源项公式改了一下,但是发现一个非常难受的事情,本身这个东西是仿照darcy-forchheimer写的,但是openfoam原生的模型的D和F可以提到1e10这么高的数量级,但是我这个写的感觉只能到1e2这样子,1e3开始就会浮点溢出,但是1e2这个水平只是能看出来这个特定区域确实有阻力存在,并不能实现极大多孔介质阻力并形成类固体区域的状态,所以就很好奇这个是什么情况,新改的代码是这样:

    momentumSource
    {
         type            vectorCodedSource;
         active          yes;
         name            sourceTime;
            vectorCodedSourceCoeffs
            {
                selectionMode   all;
              //  cellZone        pZone;
                fields          (U);
                codeInclude
                #{
                    
                #};
                codeCorrect
                #{
            //        Pout<< "**codeCorrect**" << endl;
                #};
                codeAddSup
                #{
           //         Pout<< "**codeAddSup**" << endl;
             
                   //    const vectorField& C = mesh_.C();
                      const scalarField& V = mesh_.V();
                      vectorField& Usource = eqn.source();
                      const vectorField& U = mesh().lookupObject<volVectorField>("U");
                      const scalarField& Rho = mesh().lookupObject<volScalarField>("rho");
                      const scalarField& nu = mesh().lookupObject<volScalarField>("nu");
                    //  const scalarField& magU = mag(U);
                    scalar A = 1e3;
                    scalar B = 1e3;
                  //  vector C(0,1e4,0);
                   
                       
                       
                        forAll(V,i)
                        {
                            const scalar x = mesh_.C()[i][0];
                            const scalar y = mesh_.C()[i][1];
            
                            if(x <  0.5 && x > 0 && y <  0.5 && y >  0.45)
    
                           {  
                            Usource[i] +=  (nu[i] * A + mag(U[i])* B * 0.5 ) * Rho[i] * U[i]* V[i];
                           
                              // Usource =  (A * U[i] + B * mag(U[i]) * U[i]) * V[i];       
                              //  Usource[i] += - C * V[i]; 
                           }
                        
                       
                        
                        }   
                    // Info << "***codeAddSup***" << nl;     
                    
                                                      
                                   
                #};
                codeSetValue
                #{
                   // Pout<< "**codeSetValue**" << endl;
                #};
                // Dummy entry. Make dependent on above to trigger recompilation
                code
                #{
                    $codeInclude
                    $codeCorrect
                    $codeAddSup
                    $codeSetValue
                #};
            }
            sourceTimeCoeffs
            {
                $vectorCodedSourceCoeffs;
            }
    }
    
    1 条回复 最后回复
  • 1 离线
    1 离线
    16c
    写于 最后由 16c 编辑
    #6

    interFoam跑完了的图是这样的
    inter.gif

    1 条回复 最后回复
  • 1 离线
    1 离线
    16c
    写于 最后由 编辑
    #7

    然后又去pimpleFoam跑了一下,代码改成这样的:

    
    momentumSource
    {
         type            vectorCodedSource;
         active          yes;
         name            sourceTime;
            vectorCodedSourceCoeffs
            {
                selectionMode   all;
              //  cellZone        pZone;
                fields          (U);
                codeInclude
                #{
                    
                #};
                codeCorrect
                #{
            //        Pout<< "**codeCorrect**" << endl;
                #};
                codeAddSup
                #{
           //         Pout<< "**codeAddSup**" << endl;
             
                   //    const vectorField& C = mesh_.C();
                      const scalarField& V = mesh_.V();
                      vectorField& Usource = eqn.source();
                      const vectorField& U = mesh().lookupObject<volVectorField>("U");
                     // const scalarField& Rho = mesh().lookupObject<volScalarField>("rho");
                      const scalarField& nu = mesh().lookupObject<volScalarField>("nu");
                    //  const scalarField& magU = mag(U);
                    scalar A = 1e2;
                    scalar B = 1e2;
                  //  vector C(0,1e4,0);
                   
                       
                       
                        forAll(V,i)
                        {
                            const scalar x = mesh_.C()[i][0];
                            const scalar y = mesh_.C()[i][1];
            
                            if(x <  0.5 && x > 0 && y <  0.5 && y >  0.45)
    
                           {  
                            Usource[i] +=  (1e-5 * A + mag(U[i])* B * 0.5 ) * U[i]* V[i];
                           
                              // Usource =  (A * U[i] + B * mag(U[i]) * U[i]) * V[i];       
                              //  Usource[i] += - C * V[i]; 
                           }
                        
                       
                        
                        }   
                    // Info << "***codeAddSup***" << nl;     
                    
                                                      
                                   
                #};
                codeSetValue
                #{
                   // Pout<< "**codeSetValue**" << endl;
                #};
                // Dummy entry. Make dependent on above to trigger recompilation
                code
                #{
                    $codeInclude
                    $codeCorrect
                    $codeAddSup
                    $codeSetValue
                #};
            }
            sourceTimeCoeffs
            {
                $vectorCodedSourceCoeffs;
            }
    }
    

    跑完的速度场是这样:
    pimple.gif

    就完全处于A和B只能在1e2这个数量级,但凡再大一点就直接浮点溢出了。。。完全不知道是咋回事。。

    1 条回复 最后回复

  • 登录

  • 登录或注册以进行搜索。
  • 第一个帖子
    最后一个帖子
0
  • 最新
  • 版块
  • 东岳流体
  • 随机看[请狂点我]