关于库中网格信息读取的相关问题



  • 请问想要rigidBodyDynamics库中调用到某patch网格面上的信息。现在想到的方法是在库中找相关的继承函数,再类似mesh.boundaryMesh()。但是这个想法没能实现。请问这种思路是否可行。或者OpenFOAM中是否存在类似直接调用constant/polyMesh中网格信息的操作~希望能给出建议~



  • 没问题呀,可以参考applications/test/mesh/Test-mesh.C文件

    /*---------------------------------------------------------------------------*\
      =========                 |
      \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
       \\    /   O peration     | Website:  https://openfoam.org
        \\  /    A nd           | Copyright (C) 2011-2018 OpenFOAM Foundation
         \\/     M anipulation  |
    -------------------------------------------------------------------------------
    License
        This file is part of OpenFOAM.
    
        OpenFOAM is free software: you can redistribute it and/or modify it
        under the terms of the GNU General Public License as published by
        the Free Software Foundation, either version 3 of the License, or
        (at your option) any later version.
    
        OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
        ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
        FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
        for more details.
    
        You should have received a copy of the GNU General Public License
        along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
    
    \*---------------------------------------------------------------------------*/
    
    #include "argList.H"
    #include "fvMesh.H"
    #include "volFields.H"
    #include "surfaceFields.H"
    
    using namespace Foam;
    
    // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
    // Main program:
    
    int main(int argc, char *argv[])
    {
    
        #include "setRootCase.H"
        #include "createTime.H"
    
        Info<< "Create mesh, no clear-out\n" << endl;
        fvMesh mesh
        (
            IOobject
            (
                fvMesh::defaultRegion,
                runTime.timeName(),
                runTime,
                IOobject::MUST_READ
            )
        );
    
        Info<< mesh.C() << endl;
        Info<< mesh.V() << endl;
    
        surfaceVectorField Cf = mesh.Cf();
    
        Info<< Cf << endl;
    
        // Test construct from cellShapes
        {
            pointField points(mesh.points());
            cellShapeList shapes(mesh.cellShapes());
    
            const polyBoundaryMesh& pbm = mesh.boundaryMesh();
    
            faceListList boundaryFaces(pbm.size());
            forAll(pbm, patchi)
            {
                boundaryFaces[patchi] = pbm[patchi];
            }
            wordList boundaryPatchNames(pbm.names());
            PtrList<dictionary> boundaryDicts(pbm.size());
            forAll(pbm, patchi)
            {
                OStringStream os;
                os << pbm[patchi];
                IStringStream is(os.str());
                boundaryDicts.set(patchi, new dictionary(is));
            }
    
            word defaultBoundaryPatchName = "defaultFaces";
            word defaultBoundaryPatchType = emptyPolyPatch::typeName;
    
            fvMesh newMesh
            (
                IOobject
                (
                    "newMesh",
                    runTime.timeName(),
                    runTime,
                    Foam::IOobject::NO_READ
                ),
                Xfer<pointField>(points),
                shapes,
                boundaryFaces,
                boundaryPatchNames,
                boundaryDicts,
                defaultBoundaryPatchName,
                defaultBoundaryPatchType
            );
    
            Info<< newMesh.C() << endl;
            Info<< newMesh.V() << endl;
    
            surfaceVectorField Cf = newMesh.Cf();
    
            Info<< Cf << endl;
        }
    
    
        Info<< "End\n" << endl;
    
        return 0;
    }
    
    
    // ************************************************************************* //
    


  • @freevector 谢谢老师~ 我找到了一个方法,用lookup指针去找model_.time().lookupObject<fvMesh>("region0"),您的方法我有个地方不太理解,就是runTime提示没有申明,不太明白什么意思~


Log in to reply
 

京ICP备15017992号-2