chemFoam的源码提取

ok!经过一系列的铺垫,我们来尝试一下提取出openFOAM中的chemFoam程序的源码,然后用Makefile编译运行一下,这样可以帮助我们进行二次开发。

呃。。。这个怎么说呢。。。openFOAM一个单独算例的程序依赖深度超过我的预期了。首先程序编译的过程是有记录的,保存如下路径下的文件:

dyfluid@dyfluid:~/OpenFOAM/OpenFOAM-7/platforms/linux64GccDPInt32Opt/applications/solvers/combustion/chemFoam$ vim chemFoam.C.dep 

打开后内容如下:

$(OBJECTS_DIR)/chemFoam.C.dep: \\
chemFoam.C \\
$(WM_PROJECT_DIR)/src/finiteVolume/lnInclude/fvCFD.H \\
$(WM_PROJECT_DIR)/src/thermophysicalModels/reactionThermo/lnInclude/rhoReactionThermo.H \\
$(WM_PROJECT_DIR)/src/thermophysicalModels/chemistryModel/lnInclude/BasicChemistryModel.H \\
$(WM_PROJECT_DIR)/src/thermophysicalModels/reactionThermo/lnInclude/reactingMixture.H \\
$(WM_PROJECT_DIR)/src/thermophysicalModels/chemistryModel/lnInclude/chemistrySolver.H \\
$(WM_PROJECT_DIR)/src/OpenFOAM/lnInclude/OFstream.H \\
$(WM_PROJECT_DIR)/src/thermophysicalModels/specie/lnInclude/thermoPhysicsTypes.H \\
$(WM_PROJECT_DIR)/src/thermophysicalModels/reactionThermo/lnInclude/basicSpecieMixture.H \\
...

这个文件足足一千多行,记录了所有的编译依赖。我们观察一下程序的正文,chemFoam.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/>.

Application
    chemFoam

Description
    Solver for chemistry problems, designed for use on single cell cases to
    provide comparison against other chemistry solvers, that uses a single cell
    mesh, and fields created from the initial conditions.

\\*---------------------------------------------------------------------------*/

#include "fvCFD.H"               //finiteVolume/lnInclude
#include "rhoReactionThermo.H"  //reactionThermo/lnInclude
#include "BasicChemistryModel.H" //chemistryModel/lnInclude
#include "reactingMixture.H"    //reactionThermo/lnInclude
#include "chemistrySolver.H"     //chemistryModel/lnInclude
#include "OFstream.H"            //OpenFOAM/lnIncldue
#include "thermoPhysicsTypes.H" //specie/lnInclude
#include "basicSpecieMixture.H" //reactionThermo/lnInclude
#include "cellModeller.H"        //OpenFOAM/lnIncldue
#include "thermoTypeFunctions.H" //current dir

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
int main(int argc, char *argv[])
{
    argList::noParallel();

    #define CREATE_MESH createSingleCellMesh.H
    #define NO_CONTROL
    #include "postProcess.H"  //OpenFOAM/lnInclude

    #include "setRootCaseLists.H"    //OpenFOAM/lnIncldue
    #include "createTime.H"          //OpenFOAM/lnIncldue
    #include "createSingleCellMesh.H" //current dir
    #include "createFields.H"     //current dir
    #include "createFieldRefs.H"  //current dir
    #include "readInitialConditions.H" //current dir
    #include "createControls.H"        //current dir

    // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

    Info<< "\\nStarting time loop\\n" << endl;
    while (runTime.run())
    {
        #include "readControls.H" //current dir

        #include "setDeltaT.H" //current dir

        runTime++;
        Info<< "Time = " << runTime.timeName() << nl << endl;

        #include "solveChemistry.H" //current dir
        #include "YEqn.H"   //current dir
        #include "hEqn.H"   //current dir
        #include "pEqn.H"   //current dir

        #include "output.H" //current dir

        Info<< "ExecutionTime = " << runTime.elapsedCpuTime() << " s"
            << "  ClockTime = " << runTime.elapsedClockTime() << " s"
            << nl << endl;
    }

    Info << "Number of steps = " << runTime.timeIndex() << endl;
    Info << "End" << nl << endl;

    return 0;
}

// ************************************************************************* //

啊我这里本来非常天真的标记了每个头文件的路径,以为只有这些头文件。但是实际上,这些头文件中还会使用其他的头文件。最终总体使用的头文件总数还是很多的。预计总计有几万行的程序规模。

不过虽然多,但并不是完全没有规律,也并不是需要用到所有的源代码。需要使用的头文件只出现在如下几个文件夹中。

~/OpenFOAM/OpenFOAM-7/src/OpenFOAM
~/OpenFOAM/OpenFOAM-7/src/ODE
~/OpenFOAM/OpenFOAM-7/src/thermophysicalModels/basic
~/OpenFOAM/OpenFOAM-7/src/thermophysicalModels/specie
~/OpenFOAM/OpenFOAM-7/src/thermophysicalModels/chemistryModel
~/OpenFOAM/OpenFOAM-7/src/thermophysicalModels/reactionThermo
~/OpenFOAM/OpenFOAM-7/src/meshTools
~/OpenFOAM/OpenFOAM-7/src/finiteVolume
~/OpenFOAM/OpenFOAM-7/src/transportModels/compressible/

啊当然这也不少了,而且这个里面也并不是全部会用。另外,这里的文件夹中有一个规律,就是所有的代码都会出现两份,第一份分别放在各个文件夹中,表示各自的功能,然后最终所有的代码都会复制到同一个文件夹lnInclude中,例如ODE文件夹中的内容如下:

dyfluid@dyfluid:~/OpenFOAM/OpenFOAM-7/src/ODE$ ls
lnInclude  Make  ODESolvers  ODESystem

理论上我们将所有文件夹中的lnInclude都添加到chemFoam目录中,就可以不修改路径的直接编译执行。

OK!那这个阶段算是勉强的完成了吧。

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片

    暂无评论内容