/*---------------------------------------------------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     |
    \\  /    A nd           | Copyright (C) 2013-2016 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
    SLFMFoam

Description
    Steady Laminar Flamelet Model(SLFM) solver for turbulent combustion. SLFM 
    assumes a turbulent flame composed of thin stretched laminar flamelets.
    Each flamelet library is generated by external program and imported by 
    the solver.
    
References
    A.Y. Klimenko, R.W. Bilger, Progress in Energy and Combustion Science 25 (1999) 595-687
    N. Peters, Turbulent Combustion, Cambridge University Press (2000)

Contact
    POSTECH combustion lab.
    huh@postech.ac.kr

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

#include "fvCFD.H"
#include "turbulentFluidThermoModel.H"
#include "rhoChemistryCombustion.H" 
#include "fvOptions.H"
#include "simpleControl.H"
#include "FlameStructure/FlameStructure.H"
#include "interpolateXY.H" 
#include "Math.H" //Mathematical functions for CMC (AMC, gammaln, TDMA)
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

int main(int argc, char *argv[])
{

    #include "setRootCase.H"
    #include "createTime.H"
    #include "createMesh.H"

    #include "createControl.H"
    #include "createFields.H"
    #include "createFieldRefs.H"
    #include "BetaPDF.H" //make detailed integration space and perform beta-pdf integration

    #include "createFvOptions.H"
    #include "initContinuityErrs.H"

    turbulence->validate();

    //SLFM
    #include "readSLFMlib.H" //read SLFM library 
    BetaPDF bpdf(SLFMdict);
    #include "preIntegration.H" //AMC C1 coefficient pdf integration

    Info<< "\nStarting time loop\n" << endl;


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

    Info<< "\nStarting time loop\n" << endl;

    while (simple.loop())
    {
        Info<< "Time = " << runTime.timeName() << nl << endl;

        // --- Pressure-velocity SIMPLE corrector loop
        {
            #include "UEqn.H"
            #include "Mixturefraction.H" //mean mixture fraction
            #include "MixturefractionVar.H" //mean mixture fraction variance 
            #include "setSDR.H" //calculate scalar dissipation rate
            #include "updateT_RHO.H" //update temperature and density
            #include "pEqn.H"
        }

        turbulence->correct();

            #include "updateYi.H" //update species
        if(runTime.write() == true)
        {
            rho.write();
            #include "updateYi.H" //update species
            forAll(postSpecieIndices, yi)
            {
                const label y = postSpecieIndices[yi];
                Y[y].write();
            }
        }

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

    Info<< "End\n" << endl;

    return 0;
}


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