|
[Sponsors] | |||||
|
|
|
#1 |
|
Member
Join Date: Apr 2019
Location: India
Posts: 81
Rep Power: 8 ![]() |
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. |
|
|
|
|
|
|
|
|
#2 |
|
Senior Member
Join Date: Mar 2018
Posts: 115
Rep Power: 9 ![]() |
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;
Last edited by anon_q; August 4, 2019 at 20:02. |
|
|
|
|
|
|
|
|
#3 | |
|
Member
Join Date: Apr 2019
Location: India
Posts: 81
Rep Power: 8 ![]() |
Quote:
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;
}
// ************************************************************************* //
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
Thank You. |
||
|
|
|
||
|
|
|
#4 |
|
Senior Member
Join Date: Mar 2018
Posts: 115
Rep Power: 9 ![]() |
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;
}
// ************************************************************************* //
Last edited by anon_q; August 5, 2019 at 10:18. |
|
|
|
|
|
|
|
|
#5 |
|
Member
Join Date: Apr 2019
Location: India
Posts: 81
Rep Power: 8 ![]() |
Good morning mam,
Thank you so much. It worked perfect. Thank You. With Thanks, Pavithra. |
|
|
|
|
|
|
|
|
#6 |
|
Senior Member
Join Date: Mar 2018
Posts: 115
Rep Power: 9 ![]() |
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;
}
// ************************************************************************* //
Last edited by anon_q; August 6, 2019 at 14:03. |
|
|
|
|
|
|
|
|
#7 |
|
Member
Join Date: Apr 2019
Location: India
Posts: 81
Rep Power: 8 ![]() |
Thank you so much mam. It works perfect.
|
|
|
|
|
|
|
|
|
#8 |
|
Member
Join Date: Apr 2019
Location: India
Posts: 81
Rep Power: 8 ![]() |
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 Last edited by Pavithra; August 7, 2019 at 22:30. |
|
|
|
|
|
|
|
|
#9 |
|
Member
Join Date: Apr 2019
Location: India
Posts: 81
Rep Power: 8 ![]() |
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 |
|
|
|
|
|
|
|
|
#10 | |
|
New Member
Adarsh Thakur
Join Date: Sep 2024
Posts: 1
Rep Power: 0 ![]() |
Quote:
Thank You Adarsh |
||
|
|
|
||
![]() |
| Tags |
| global variable vs time, openfoam, postprocessing |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| [IHFOAM] The IHFOAM Thread | Phicau | OpenFOAM Community Contributions | 392 | September 8, 2023 19:10 |
| Moving mesh | Niklas Wikstrom (Wikstrom) | OpenFOAM Running, Solving & CFD | 122 | June 15, 2014 07:20 |
| InterFoam negative alpha | karasa03 | OpenFOAM | 7 | December 12, 2013 04:41 |
| Error in run Batch file | saba1366 | CFX | 4 | February 10, 2013 02:15 |
| interDyMFoam - change in volume fraction | gopala | OpenFOAM Running, Solving & CFD | 0 | April 27, 2009 11:46 |