Navigation

    CFD中文网

    CFD中文网

    • Login
    • Search
    • 最新

    记录一些自己用过的代码

    OpenFOAM
    2
    6
    4152
    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.
    • 李东岳
      李东岳 管理员 last edited by 李东岳

      const fvPatchList& patches = mesh.boundary();
      
      forAll(patches, patch)
      {
      	Info << patches[patch].name() << nl;
              const fvPatch& currPatch = patches[patch];
              forAll(currPatch, face)
              {
      		Info << abs_[0].boundaryField()[patch][face] << nl;
      	}
      }
      

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

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

        OpenFOAM-4.x以前?反正是老的:

        const scalarField& psi = U.internalField(); 
        scalarField& psi = U.internalField(); 
        

        OpenFOAM-5.x, 4.x:

        const scalarField& psi = U.primitiveField(); 
        scalarField& psi = U.primitiveFieldRef(); 
        

        tmp旧式风格:

        tmp<volScalarField> tField = ... 
        volScalarField& non_const_field = tField(); 
        const volScalarField& const_field = tField(); 
        

        新式风格:

        tmp<volScalarField> tField = ... 
        volScalarField& non_const_field = tField().ref(); 
        const volScalarField& const_field = tField(); 
        

        旧式:

        const volScalarField::GeometricBoundaryField& bsf = field.boundaryField(); 
        volScalarField::GeometricBoundaryField& bsf = field.boundaryField(); 
        

        新式:

        const volScalarField::Boundary& bsf = field.boundaryField(); 
        volScalarField::Boundary& bsf = field.boundaryFieldRef(); 
        

        dimensionedInternalField已经被volScalarField::Internal替换
        https://www.openfoam.com/documentation/developer-upgrade-guide.php

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

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

              const labelUList& owner = mesh_.owner();
              const labelUList& neighbour = mesh_.neighbour();
          
              forAll(weis_, kth)
              {
                  forAll(sumWeisF[kth], cellI)
                  {
          
                      Info << "Current cell index is " << cellI << nl;
          
                      //- Loop the faces of cellI
                      forAll(mesh_.cells()[cellI], faceI)
                      {
                          //- Check if it is an internal face
                          if (mesh_.isInternalFace(mesh_.cells()[cellI][faceI]))   
                          {
                              label faceIndex = mesh_.cells()[cellI][faceI];
                              Info << " its faceIndex is " << faceIndex;
                              Info << ", and this face's owner is "
                                  << owner[faceIndex] << ", its neighbour is "
                                  << neighbour[faceIndex] << nl;
                          }
                      }
                      
                      Info << nl;
                  } 
              }
          

          输出如下:

          Current cell index is 851
           its faceIndex is 1684, and this face's owner is 851, its neighbour is 852
           its faceIndex is 1685, and this face's owner is 851, its neighbour is 896
           its faceIndex is 1596, and this face's owner is 806, its neighbour is 851
           its faceIndex is 1682, and this face's owner is 850, its neighbour is 851
          
          Current cell index is 852
           its faceIndex is 1686, and this face's owner is 852, its neighbour is 853
           its faceIndex is 1687, and this face's owner is 852, its neighbour is 897
           its faceIndex is 1598, and this face's owner is 807, its neighbour is 852
           its faceIndex is 1684, and this face's owner is 851, its neighbour is 852
          
          

          希望有用 :confused:

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

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

            const labelList& inletCells = mesh.boundary()["inlet"].faceCells();
            
            template<class Type>
            void zeroCells
            (
                GeometricField<Type, fvPatchField, volMesh>& vf,
                const labelList& cells
            )
            {
                forAll(cells, i)
                {
                    vf[cells[i]] = Zero;
                }
            }
            
            zeroCells(alpha, inletCells);
            

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

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

              输出边界条件类型:

              Info << alpha.boundaryField().types()[patch] << nl;
              

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

              1 Reply Last reply Reply Quote
              • 同学博
                同学博 last edited by

                亲测实用:140:

                1 Reply Last reply Reply Quote
                • First post
                  Last post

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