网格体积



  • 请问有哪位大神提取过网格体积吗????


  • 管理员

    mesh.V()

    可以输出网格体积



  • @赵一铭 赵老师,那网格的坐标呢,x,y,z



  • @飞火流星jyj

        //class: fvMesh
        Info << "\n-Class: fvMesh--------" << endl;
    
        //- Return the object registry - resolve conflict polyMesh/lduMesh.
            //  Type: virtual const objectRegistry &
        Info << mesh.thisDb() << endl;
    
        //- Return reference to name.
            //  Type: const word &
        Info << mesh.name() << endl;
    
        //- Return reference to boundary mesh.
            //  Type: const fvBoundaryMesh &
        mesh.boundary();
    
        //- Internal face owner.
            // Type: const labelUList &
        labelList owners(mesh.owner());
    
        //- Internal face neighbour.
            //  Type: const labelUList &
        labelList neighbours(mesh.neighbour());
    
        //- Return cell volumes.
            //  Type: const DimensionedField< scalar, volMesh > &
        Info << mesh.V() << endl;
    
        //- Return old-time cell volumes.
            //  Type: const DimensionedField< scalar, volMesh > &
        Info << mesh.V0() << endl;
    
        //- Return old-old-time cell volumes.
            //  Type: const DimensionedField< scalar, volMesh > &
        Info << mesh.V00() << endl;
    
        //- Return sub-cycle cell volumes.
            //  Type: tmp< DimensionedField< scalar, volMesh > >
        Info << mesh.Vsc() << endl;
    
        //- Return sub-cycle old-time cell volumes.
            //  Type: tmp< DimensionedField< scalar, volMesh > >
        Info << mesh.Vsc0() << endl;
    
        //- Return cell face area vectors.
            //  Type: const surfaceVectorField &
        Info << mesh.Sf() << endl;
    
        //- Return cell face area magnitudes.
            //  Type: const surfaceScalarField &
        Info << mesh.magSf() << endl;
    
        //- Return cell face motion fluxes.
            //  Type: const surfaceScalarField &
        Info << mesh.phi() << endl;
    
        //- Return cell centres as volVectorField.
            //  Type: const volVectorField &
        Info << mesh.C() << endl;
    
        //- Return face centres as surfaceVectorField.
            //  Type: const surfaceVectorField &
        Info << mesh.Cf() << endl;
    
        //- Return face deltas as surfaceVectorField.
            //  Type: tmp< surfaceVectorField >
        Info << mesh.delta() << endl;  
    
        Info << "----------------------\n" << endl;
    
    // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
        //class: fvMesh
    
        pointField points(mesh.points());
        faceList faces(mesh.faces());
        cellList cells(mesh.cells());    
        
    
    
    // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
        //Class: point = vector
        Info << "\n-Class: point---------" << endl;
        point &pt(points[3]);
        Info << "pt = " << pt << endl;
        //- Return x component
        Info << "pt.x() = " << pt.x() << endl;
        //- Return y component
        Info << "pt.y() = " << pt.y() << endl;
        //- Return z component
        Info << "pt.z() = " << pt.z() << endl;
        Info << "----------------------\n" << endl;
    
    
    // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
        //class: edge
        Info << "\n-Class: edges----------" << endl;
        edge eg(faces[1].faceEdge(1)), eg_(faces[1].faceEdge(3));
        label pt_1(eg.start()), &pt_2(eg.end());
        Info << "eg = " << eg << endl;
        //- Return start vertex label
        Info << "eg.start() = " << pt_1 << endl;
        //- Return end vertex label
        Info << "eg.end() = " << pt_2 << endl;
        //- Given one vertex, return the other
        Info << "eg.otherVertex(eg.end()) = " << eg.otherVertex(pt_2) << endl;
        //- Return common vertex
            //  - -1: no common vertex
        Info << "eg.commonVertex(eg_) = " << eg.commonVertex(eg_) << endl;
        //- Return reverse edge
        Info << "eg.reverseEdge() = " << eg.reverseEdge() << endl;
        //- Return centre (centroid)
        Info << "eg.centre(points) = " << eg.centre(points) << endl;
        //- Return the vector (end - start)
        Info << "eg.vec(points) = " << eg.vec(points) << endl;
        //- Return scalar magnitude
        Info << "eg.mag(points) = " << eg.mag(points) << endl;
        //- Return edge line
        Info << "eg.line(points) = " << eg.line(points) << endl;
        //- compare edges
            //  Returns:
            //  -  0: different
            //  - +1: identical
            //  - -1: same edge, but different orientation
        Info << "Foam::edge::compare(eg, eg.reverseEdge()) = " 
             << Foam::edge::compare(eg, eg.reverseEdge()) << endl;
        Info << "----------------------\n" << endl;
    
    
    // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
        //class: face
        Info << "\n-Class: face----------" << endl;
        face &fe(faces[4]);
        Info << "fe = " << fe << endl;
        //- Return true if the face is empty
        Info << "fe.empty() = " << fe.empty() << endl;
        //- Return No. of points corresponding to this face
        Info << "fe.size() = " << fe.size() << endl;
        //- Return first point
        Info << "fe.first() = " << fe.first() << endl;
        //- Return last point
        Info << "fe.last() = " << fe.last() << endl;
        //- Return n-th point
        Info << "fe.operator[](0) = " << fe.operator[](0) << endl;
        //- Return the points corresponding to this face
        Info << "fe.points(points) = " << fe.points(points) << endl;
        //- Centre point of face
        Info << "fe.centre(points) = " << fe.centre(points) << endl;
        //- Calculate average value at centroid of face
        Info << "fe.average(points, points) = " 
             << fe.average(points, points) << endl;
        //- Magnitude of face area
        Info << "fe.mag(points) = " << fe.mag(points) << endl;
        //- Vector normal; magnitude is equal to area of face
        Info << "fe.normal(points) = " << fe.normal(points) << endl;
        //- Return face with reverse direction
            //  The starting points of the original and reverse face are identical.
        Info << "fe.reverseFace() = " << fe.reverseFace() << endl;
        //- Which vertex on face (face index given a global index)
            //  returns -1 if not found
        Info << "fe.which(1966) = " << fe.which(1966) << endl;
        //- Next vertex on face
        Info << "fe.nextLabel(1) = " << fe.nextLabel(1) << endl;
        //- Previous vertex on face
        Info << "fe.prevLabel(1) = " << fe.prevLabel(1) << endl;
        //- Return number of edges
        Info << "fe.nEdges() = " << fe.nEdges() << endl;
        //- Return edges in face point ordering,
            //  i.e. edges()[0] is edge between [0] and [1]
        Info << "fe.edges() = " << fe.edges() << endl;
        //- Return n-th face edge
        Info << "fe.faceEdge(1) = " << fe.faceEdge(1) << endl;
        //- Return the edge direction on the face
            //  Returns:
            //  -  0: edge not found on the face
            //  - +1: forward (counter-clockwise) on the face
            //  - -1: reverse (clockwise) on the face
        Info << "fe.edgeDirection(fe.faceEdge(1)) = " 
             << fe.edgeDirection(fe.faceEdge(1)) << endl;
        //- compare faces
            //   0: different
            //  +1: identical
            //  -1: same face, but different orientation
        Info << "Foam::face::compare(fe, fe) = " 
             << Foam::face::compare(fe, fe) << endl;
        Info << "----------------------\n" << endl;
    
    
    // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
        //class: cell
        Info << "\n-Class: cell----------" << endl;
        cell &cl(cells[100]);
        Info << "cl = " << cl << endl;
        //- Return true if the cell is empty
        Info << "cl.empty() = " << cl.empty() << endl;
        //- Return No. of faces corresponding to this cell
        Info << "cl.size() = " << cl.size() << endl;
        //- Return first face
        Info << "cl.first() = " << cl.first() << endl;
        //- Return last face
        Info << "cl.last() = " << cl.last() << endl;
        //- Return n-th face
        Info << "cl.operator[](0) = " << cl.operator[](0) << endl;
        //- Return number of faces
        Info << "cl.nFaces() = " << cl.nFaces() << endl;
        //- Return labels of cell vertices
        Info << "cl.labels(faces) = " << cl.labels(faces) << endl;
        //- Return the cell vertices
        Info << "cl.points(faces, points) = " << cl.points(faces, points) << endl;
        //- Return cell edges
        Info << "cl.edges(faces) = " << cl.edges(faces) << endl;
        //- Returns cell centre
        Info << "cl.centre(points, faces) = " << cl.centre(points, faces) << endl;
        //- Returns cell volume
        Info << "cl.mag(points, faces) = " << cl.mag(points, faces) << endl;
        Info << "----------------------\n" << endl;
    


  • @飞火流星jyj 我贴了一些我自己的测试代码:laughing:



  • @队长别开枪 十分感谢,我回去好好看看:laughing:



  • @队长别开枪网格体积 中说:

    上半年年度最佳代码 :cheeky:



  • @赵一铭

    能指点我一下吗,实在不知道该怎么做



  • @zhanghan

    volScalarField volume
    {
        IOobject
            (
                "volume",
                runTime.timeName(),
                mesh,
                IOobject::NO_READ,
                IOobject::AUTO_WRITE
            ),
            mesh.V()
    }
    

    把上面的代码复制进去你的代码测试一下,我没测试。可以添加在createFields.H中。



  • @李东岳 李老师我测试了下

     Info<< "Reading volume\n" << endl;
    volScalarField volume
    (
        IOobject
            (
                "volume",
                runTime.timeName(),
                mesh,
                IOobject::NO_READ,
                IOobject::AUTO_WRITE
            ),
            mesh.V()
    );
    

    提示错误是:

     no matching function for call to ‘Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>::GeometricField(Foam::IOobject, const Foam::DimensionedField<double, Foam::volMesh>&)’
     );
    

    没有这种类型



  • volScalarField volume
    (
        IOobject
    	(
    		"volume",
    		runTime.timeName(),
    		mesh,
    		IOobject::NO_READ,
    		IOobject::AUTO_WRITE
    	),
    	mesh,
    	scalar(0.0)
    );
    volume.internalField() = mesh.V(); 
    

    试试这个



  • 如果是OpenFOAM-4.x,应该是:

    volume.ref() = mesh.V(); 
    


  • @李东岳 李老师可以了,3.0.x没问题,生成的数据是怎么排列的呢?



  • @队长别开枪 请问您测试过吗,我测试了在createField.H加入

    Info << "\n-Class: cell----------" << endl;
        cell &cl(cells[100]);
    Info << "cl.centre(points, faces) = " << cl.centre(points, faces) << endl;
    

    报错如下:

    createFields.H:33:14: error: ‘cells’ was not declared in this scope
         cell &cl(cells[100]);
                  ^
    createFields.H:34:52: error: ‘points’ was not declared in this scope
     Info << "cl.centre(points, faces) = " << cl.centre(points, faces) << endl;
                                                        ^
    createFields.H:34:60: error: ‘faces’ was not declared in this scope
     Info << "cl.centre(points, faces) = " << cl.centre(points, faces) << endl;
                                                                ^
    

    怎么修改就好了



  • @飞火流星jyj 我今晚或者明天把整个测试代码发上来吧:happy:



  • @队长别开枪 好的,十分感谢



  • @飞火流星jyj
    别用cl.centre()

    这个东西和mesh.C()似乎不一样,OF有两种中心,几何重心和FVM意义上的中心。二者在三维网格有warp的情况下有一些微小的差别。



  • @程迪 好的,一个是polymesh的一个是扩展的FvMesh,那我该用哪个表示出某网格的x,y,z,这该怎么写啊



  • @飞火流星jyj
    GeometricField类型有一个component函数,返回的是分量,参数是direction,实际上类型是char/uint_8,你试试’x’,‘y’,'z’或者1,2,3就好。



  • @程迪 请问怎么查看是0,1,2还是1,2,3这样的编号:confused:


登录后回复
 

与 CFD 中国 的连接断开,我们正在尝试重连,请耐心等待