CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Post-Processing (https://www.cfd-online.com/Forums/openfoam-post-processing/)
-   -   Total liquid volume fraction vs Time (https://www.cfd-online.com/Forums/openfoam-post-processing/219661-total-liquid-volume-fraction-vs-time.html)

Pavithra August 4, 2019 07:24

Total liquid volume fraction vs Time
 
Hello Everyone,



I am simulating melting process by modifying buoyantBoussinesqPimpleFoam. I have calculated the total liquid volume fraction as follows:


Code:

dimensionedScalar tlf = (sum(mesh.V()*lf))/(sum(mesh.V()));

where,

lf is the local liquid volume fraction.



Now, I want to write a dat/xy file to plot tlf vs time. Kindly, please guide me to achieve this.



Thank You.

anon_q August 4, 2019 18:01

You can store your data tlf values in an array and save it to a file.

Code:


//Before entering the time loop decalre the hashTable
HashTable<scalar, word> tlfValues;

//Inside the time loop
word t = runTime.timeName();
tlfValues.insert(t, sum(mesh.V()*lf))/(sum(mesh.V()));
...
// Outside the time loop, save the hash table to a file
OFstream myfile("./tlfvalues");
myfile() << tlfValues;


Pavithra August 4, 2019 22:13

Quote:

Originally Posted by Evren Linda (Post 741067)
You can store your data tlf values in an array and save it to a file.

Code:


//Before entering the time loop decalre the hashTable
HashTable<scalar, word> tlfValues;

//Inside the time loop
word t = runTime.timeName();
tlfValues.insert(t, sum(mesh.V()*lf))/(sum(mesh.V()));
...
// Outside the time loop, save the hash table to a file
OFstream myfile("./tlfvalues");
myfile() << tlfValues;


Respected Mam,

Thank you so much for your kind help. I tried the code you provided. But, I am unable to compile after adding the code.

My solver.C file is as follows:
Code:

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

#include "fvCFD.H"
#include "fvOptions.H"
#include "pimpleControl.H"

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

int main(int argc, char *argv[])
{
    #include "postProcess.H"

    #include "setRootCaseLists.H"
    #include "createTime.H"
    #include "createMesh.H"
    #include "createControl.H"
    #include "createFields.H"
    #include "createTimeControls.H"
    #include "CourantNo.H"
    #include "setInitialDeltaT.H"
    #include "initContinuityErrs.H"

    // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
    //Before entering the time loop decalre the hashTable
        HashTable<scalar, word> tlfValues;


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

        while (runTime.run())
        {
            #include "readTimeControls.H"
            #include "CourantNo.H"
            #include "setDeltaT.H"

            runTime++;

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

        //update the latent heat content after inner each loop       
        volScalarField DHnew = DH;

            // --- Pressure-velocity PIMPLE corrector loop
            while (pimple.loop())
                {
                        #include "UEqn.H"
         
                        // --- Pressure corrector loop
                        while (pimple.correct())
                        {
                              #include "pEqn.H"
                        }

                    #include "TEqn.H"

                    //Inside the time loop
                    word t = runTime.timeName();
                    tlfValues.insert(t, (sum(mesh.V()*lf))/(sum(mesh.V())));

                }

        //calculate the total liquid fraction       
        dimensionedScalar tlf = (sum(mesh.V()*lf))/(sum(mesh.V()));

        runTime.write();

            Info<< nl << endl;

        //print the total liquid fraction
            Info<< "Total Liquid Fraction = " << tlf.value() << endl;

            Info<< nl << endl;

        //print the execution time
            Info<< "ExecutionTime = " << runTime.elapsedCpuTime() << " s";

        Info<< nl << endl;
       
        //print the clock time
            Info<< "  ClockTime = " << runTime.elapsedClockTime() << " s";
           
        Info<< nl << endl;
        }

        // Outside the time loop, save the hash table to a file
    OFstream myfile("./tlfvalues");
    myfile() << tlfValues;


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

        return 0;
}

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

The error message is as follows:


Code:

meltFoam.C: In function 'int main(int, char**)':
meltFoam.C:105:63: error: no matching function for call to 'Foam::HashTable<double, Foam::word>::insert(Foam::word&, Foam::dimensioned<double>)'
        tlfValues.insert(t, (sum(mesh.V()*lf))/(sum(mesh.V())));
                                                              ^
In file included from /opt/openfoam6/src/OpenFOAM/lnInclude/HashTable.H:560:0,
                from /opt/openfoam6/src/OpenFOAM/lnInclude/runTimeSelectionTables.H:41,
                from /opt/openfoam6/src/OpenFOAM/lnInclude/token.H:49,
                from /opt/openfoam6/src/OpenFOAM/lnInclude/UListIO.C:28,
                from /opt/openfoam6/src/OpenFOAM/lnInclude/UList.C:233,
                from /opt/openfoam6/src/OpenFOAM/lnInclude/UList.H:484,
                from /opt/openfoam6/src/OpenFOAM/lnInclude/List.H:43,
                from /opt/openfoam6/src/OpenFOAM/lnInclude/labelList.H:48,
                from /opt/openfoam6/src/OpenFOAM/lnInclude/UPstream.H:42,
                from /opt/openfoam6/src/OpenFOAM/lnInclude/Pstream.H:42,
                from /opt/openfoam6/src/OpenFOAM/lnInclude/parRun.H:35,
                from /opt/openfoam6/src/finiteVolume/lnInclude/fvCFD.H:4,
                from meltFoam.C:48:
/opt/openfoam6/src/OpenFOAM/lnInclude/HashTableI.H:79:13: note: candidate: bool Foam::HashTable<T, Key, Hash>::insert(const Key&, const T&) [with T = double; Key = Foam::word; Hash = Foam::string::hash]
 inline bool Foam::HashTable<T, Key, Hash>::insert
            ^~~~
/opt/openfoam6/src/OpenFOAM/lnInclude/HashTableI.H:79:13: note:  no known conversion for argument 2 from 'Foam::dimensioned<double>' to 'const double&'
/opt/openfoam6/wmake/rules/General/transform:25: recipe for target 'Make/linux64GccDPInt32Opt/meltFoam.o' failed
make: *** [Make/linux64GccDPInt32Opt/meltFoam.o] Error 1

Kindly, please help me.

Thank You.

anon_q August 5, 2019 07:26

Sorry, I forgot to call the value() method of dimensionedScalar variable tlf.
Code:

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

#include "fvCFD.H"
#include "fvOptions.H"
#include "pimpleControl.H"

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

int main(int argc, char *argv[])
{
    #include "postProcess.H"

    #include "setRootCaseLists.H"
    #include "createTime.H"
    #include "createMesh.H"
    #include "createControl.H"
    #include "createFields.H"
    #include "createTimeControls.H"
    #include "CourantNo.H"
    #include "setInitialDeltaT.H"
    #include "initContinuityErrs.H"

    // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
    //Before entering the time loop decalre the hashTable
    HashTable<scalar, word> tlfValues;

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

        while (runTime.run())
        {
            #include "readTimeControls.H"
            #include "CourantNo.H"
            #include "setDeltaT.H"

            runTime++;

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

        //update the latent heat content after inner each loop       
        volScalarField DHnew = DH;

            // --- Pressure-velocity PIMPLE corrector loop
            while (pimple.loop())
                {
                        #include "UEqn.H"
         
                        // --- Pressure corrector loop
                        while (pimple.correct())
                        {
                              #include "pEqn.H"
                        }

                    #include "TEqn.H"

                    //Inside the time loop
                }

        // These lines must be outside the pimple loop               
        word t = runTime.timeName();
        dimensionedScalar tlf = sum(mesh.V()*lf))/(sum(mesh.V());
        tlfValues.insert(t, tlf.value());


        runTime.write();

            Info<< nl << endl;

        //print the total liquid fraction
            Info<< "Total Liquid Fraction = " << tlf.value() << endl;

            Info<< nl << endl;

        //print the execution time
            Info<< "ExecutionTime = " << runTime.elapsedCpuTime() << " s";

        Info<< nl << endl;
       
        //print the clock time
            Info<< "  ClockTime = " << runTime.elapsedClockTime() << " s";
           
        Info<< nl << endl;
        }

        // Outside the time loop, save the hash table to a file
   OFstream myfile("./tlfvalues");
    myFile() << "time\t" << "tlf" << endl;

    // Write the tlfValues to the file sorted by time
    for (word ti : tlfValues.sortedToc())
    {
        myfile() << ti << "\t" << tlfValues[ti] << endl;
    }
 



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

        return 0;
}

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

I haven't tested that, but you can just try to compile it.

Pavithra August 5, 2019 21:52

Good morning mam,

Thank you so much. It worked perfect.

Thank You.

With Thanks,
Pavithra.

anon_q August 6, 2019 11:22

Just to solve the issue of sorting, we have to change the key to scalar (double) instead of word (string).

Code:

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

#include "fvCFD.H"
#include "fvOptions.H"
#include "pimpleControl.H"

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

int main(int argc, char *argv[])
{
    #include "postProcess.H"

    #include "setRootCaseLists.H"
    #include "createTime.H"
    #include "createMesh.H"
    #include "createControl.H"
    #include "createFields.H"
    #include "createTimeControls.H"
    #include "CourantNo.H"
    #include "setInitialDeltaT.H"
    #include "initContinuityErrs.H"

    // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
    //Before entering the time loop decalre the hashTable
    HashTable<scalar, scalar, Hash<scalar>> tlfValues;

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

        while (runTime.run())
        {
            #include "readTimeControls.H"
            #include "CourantNo.H"
            #include "setDeltaT.H"

            runTime++;

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

        //update the latent heat content after inner each loop       
        volScalarField DHnew = DH;

            // --- Pressure-velocity PIMPLE corrector loop
            while (pimple.loop())
                {
                        #include "UEqn.H"
         
                        // --- Pressure corrector loop
                        while (pimple.correct())
                        {
                              #include "pEqn.H"
                        }

                    #include "TEqn.H"

                    //Inside the time loop
                }

        // These lines must be outside the pimple loop               
        scalar t = runTime.value();
        dimensionedScalar tlf = sum(mesh.V()*lf))/(sum(mesh.V());
        tlfValues.insert(t, tlf.value());


        runTime.write();

            Info<< nl << endl;

        //print the total liquid fraction
            Info<< "Total Liquid Fraction = " << tlf.value() << endl;

            Info<< nl << endl;

        //print the execution time
            Info<< "ExecutionTime = " << runTime.elapsedCpuTime() << " s";

        Info<< nl << endl;
       
        //print the clock time
            Info<< "  ClockTime = " << runTime.elapsedClockTime() << " s";
           
        Info<< nl << endl;
        }

        // Outside the time loop, save the hash table to a file
   OFstream myfile("./tlfvalues");
    myFile() << "time\t" << "tlf" << endl;

    // Write the tlfValues to the file sorted by time
    for (scalar ti : tlfValues.sortedToc())
    {
        myfile() << ti << "\t" << tlfValues[ti] << endl;
    }
 



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

        return 0;
}

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


Pavithra August 6, 2019 21:25

Thank you so much mam. It works perfect.

Pavithra August 7, 2019 07:06

2 Attachment(s)
Hi Everyone,

I have attached the solver which I was trying to make.

The solver is based on buoyantBoussinesqPimpleFoam. The enthalpy-porosity method proposed by Voller & Brent has been employed.

This solver can be used for isothermal and non-isothermal melting.

The solvers perform adequately well for Gallium melting case and 1-D Stefan problem.

The solver is compiled and tested in OF v6.

Any advice or suggestions for improvements are welcome.

Also, please give me a direction to make this solver work in parallel. At present, this solver works well in single core but, crashes while using mpirun.

Thank You.

- Pavithra

Pavithra August 8, 2019 04:40

4 Attachment(s)
Hi Everyone,

I am attaching the results of some validation cases, herewith.

I have attached the solver, cases and results. Any suggestions for improvements are welcome.

Thank You.

- Pavithra


All times are GMT -4. The time now is 20:06.