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!那這個階段算是勉強的完成了吧。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章