CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM (https://www.cfd-online.com/Forums/openfoam/)
-   -   How to extract scalar members from a class ? (https://www.cfd-online.com/Forums/openfoam/229775-how-extract-scalar-members-class.html)

Kummi August 24, 2020 07:42

How to extract scalar members from a class ?
 
Hello Foamers,
I'm currently working on a custom solver and there is something I can't figure out. The solver calculates thermal conductivity (K) based on various scalar variables (pi, pR, pT, px) as shown below.
Quote:

template<class thermo>
inline Foam::scalar Foam::conductivitySolidTransport<thermo>::K //thermal conductivity
(
const scalar T
) const
{
return
((1-pR)*(0.012848335*pow(T,0.5))) + (pT*(0.000496*T)) + (pi*(0.0000000000342*pow(T,3))) + (px*(0.00000000228*pow(T,3)));
}
Since, the thermal conductivity (K) is a field variable (volScalarField), the variable gets extracted and printed in every time folder while simulation runs and could able to plot easily in the post-processing. However, the scalar variables (pi, pR, pT, px) mentioned above are not extracted, since its not a field variable.
How to extract such scalar variables (pi, pR, pT, px) in OpenFOAM ?
My idea was to use an IOobject to write this variable in each time directory, but I can't figure out how.
Kindly someone suggest me some ideas or references.
Thank You

adhiraj August 26, 2020 14:02

What type of variables are these?
How do you define them?

Kummi August 26, 2020 15:12

1 Attachment(s)
Thank you for your reply.
I have declared it in my custom solver under the following location:
Quote:

~/OpenFOAM/OpenFOAM-2.1.1/myFoam/thermophysicalModels/solid/transport/conductivity
Solid Model --> Transport Property --> Conductivity (is fitted based on scalar variables) as found in the attachment.

random_ran August 29, 2020 18:40

This seems to be a general cpp issue: how to access a private variable
in a class. People usually write a getter to do that.

In your case, the easiest way to direct change the return value of this
function:

,----
| template<class thermo>
| inline Foam::scalar Foam::conductivitySolidTransport<thermo>::K //thermal conductivity
| (
| const scalar T
| ) const
|
| {
|
| return
|
| ((1-pR)*(0.012848335*pow(T,0.5))) + (pT*(0.000496*T)) + (pi*(0.0000000000342*pow(T,3))) + (px*(0.00000000228*pow(T,3)));
|
| }
`----

If you don't care about K, just


instead:

,----
| return
| ((1-pR)*(0.012848335*pow(T,0.5))) + (pT*(0.000496*T)) + (pi*(0.0000000000342*pow(T,3))) + (px*(0.00000000228*pow(T,3)));
`----

You can change this function to:

,----
| return
| pR;
`----

Then compile the code and run the simulation.

But you know, the output data "T" in the case you simulated is "pR".

You may also find all the code related to "thermal conductivity" change
the name of this function like K_my_tweak. As long as you can compile
the code, then you can later on revise the function to the variables of
your interest (pi, pR, pT, px).

Kummi August 30, 2020 03:50

Thank you for your response, Mr. Ran. Good strategy to deal with !!


But if my inner loop is not actually the original polynomial fit, sometimes the case may go misleading and leads to error in between. In that scenario, I couldn't able to track (pi, pR, pT, px) variables consistently and somewhere time consuming.
I'll proceed with your thoughts for now.

Indeed, looking for precise opt technique to proceed in nearby future.
Thank you again

snak August 31, 2020 01:18

Hi,


If you wanna see the scalar values, putting the line like below will work. You have to create functions to get these values in the model.


Code:

// solidTransport is the instance from your class
Info << "(pi, pR, pT, px) = (" << solidTransport.pi() << ", "
    <<  solidTransport.PR() << ", "
    <<  solidTransport.pt()  << ", "
    <<  solidTransport.px  << " )" <<endl;

You will see the values in log of your calculation. Small script will extract info you want.

Kummi August 31, 2020 11:18

Hello snak,
Thank you for your tips. But, I'm looking forward to check the variables (pi, pR, pT, px) output during my post-processing with respect to time.
However, I have checked your snippet to print the values of pi, pR, pT, px in terminal.
Quote:

// conductivitySolidTransport is the instance from your class
Info << "(pi, pR, pT, px) = (" << conductivitySolidTransport.pi() << ", "
<< conductivitySolidTransport.pR() << ", "
<< conductivitySolidTransport.pT() << ", "
<< conductivitySolidTransport.px() << " )" <<endl;
But it ends in error saying,

Quote:

/home/kummijai/OpenFOAM/OpenFOAM-2.1.1/cokeovenGasFOAM/thermophysicalModels/solid/lnInclude/conductivitySolidTransportI.H:106:63: error: expected primary-expression before ‘.’ token
/home/kummijai/OpenFOAM/OpenFOAM-2.1.1/cokeovenGasFOAM/thermophysicalModels/solid/lnInclude/conductivitySolidTransportI.H:107:35: error: expected primary-expression before ‘.’ token
If I removed the class "conductivitySolidTransport" from the snippet, I got this expected error as,
Quote:

/home/kummijai/OpenFOAM/OpenFOAM-2.1.1/cokeovenGasFOAM/thermophysicalModels/solid/lnInclude/conductivitySolidTransportI.H:107:12: error: there are no arguments to ‘pR’ that depend on a template parameter, so a declaration of ‘pR’ must be available [-fpermissive]
I tried surfing about the error in google, but I couldn't able to find anything yet.
Kindly share your thoughts about it please.
Thank you

snak August 31, 2020 12:14

Hi Kummi,

Without knowing the source code you use, giving further advice is out of the question.

My intension is to add output statement at the end of time loop in solver.

sorry,

Kummi August 31, 2020 12:28

Thank you for your reply, snak.
At the top of this thread, I attached the code details in the attachment.

https://www.cfd-online.com/Forums/op...tml#post781414
Kindly check in your free time and give your suggestion please.
Thank you

snak August 31, 2020 12:58

Hi Kummi,

What you attached is the code of library, isn't it? I do not understand how you declared the instance of conductivitySolidTransport in your solver.

My intention is
- create getter function (just return PR etc.) in the library,
- call the getter function from the solver,
- output the variables from the solver into the log.

Kummi August 31, 2020 13:35

Hello snak,
Basically, I'm resolving pyrolysis of coal (solid). For this solid model in my custom solver, the thermal conductivity is declared under the following location:
Quote:

~/OpenFOAM/OpenFOAM-2.1.1/myFoam/thermophysicalModels/solid/transport/conductivity
Here in this custom conductivity folder [in Attachment above], the thermal conductivity (K) is declared based on various scalar variables (pi, pR, pT, px).
You have talked about creating getter functions to get the values in the model. Could you please elaborate me further. Sorry to bother you.

Thank you for your reply.

snak September 1, 2020 05:50

Hi Kummi,

It is quite difficult to advice without knowing solver and library codes and a working example.

You have just shared the part of the library. I can not figure out the whole code structure. Lagrangian classes are deeply depending on each other...

On what solver is your custom solver based. Which standard solver is most similar?

Could you specify the standard tutorial case which is the base for your case?


What I want to know in the previous post is not the declaration of K() in the lib. The declaration of thermophysical instance in the SOLVER. something like " SLGThermo slgThermo(mesh, thermo);"...

snak September 1, 2020 06:17

Example: coalChemistryFoam solver

Changes in coalChemistryFoam.C (adding lines to extra output)
Code:

        runTime++;

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


        Info << "============================" << endl;
        // method 1
        //Info << "slgThermo.solids().properties()[0].K() = " << slgThermo.solids().properties()[0].K() << endl;
        //Info << "slgThermo.solids().properties()[1].K() = " << slgThermo.solids().properties()[1].K() << endl;
        // method2
        Info << "slgThermo.solids().properties()[0].writeData(Info):  ";
        slgThermo.solids().properties()[0].writeData(Info);
        Info << nl << "slgThermo.solids().properties()[1].writeData(Info):  ";
        slgThermo.solids().properties()[1].writeData(Info);     
        Info << nl << "============================" << nl << endl;


        rhoEffLagrangian = coalParcels.rhoEff() + limestoneParcels.rhoEff();
        pDyn = 0.5*rho*magSqr(U);

Log from the modified code(standard tutorial: simplifiedSiwek. CCoeffs is changed to 1000, 1000, 0.1, 0, 0.8.)
Code:

Starting time loop

Courant Number mean: 0 max: 0
deltaT = 0.000119047619
Time = 0.000119048

============================
slgThermo.solids().properties()[0].writeData(Info):  1000 1000 0.1 0 0.8
slgThermo.solids().properties()[1].writeData(Info):  2010 710 0.04 0 1
 ============================

You can output the values in the instance/class you use from the solver. You can output these values from the class but the control of the timing may be difficult

Kummi September 1, 2020 08:02

Hello snak,
Sorry for the difficulties caused. Thank you for your time and elaborate info.
Quote:

On what solver is your custom solver based. Which standard solver is most similar?
My source file comes from the following location [reactingOneDim.C]
~/OpenFOAM/OpenFOAM-2.1.1/myFoam/regionModels/pyrolysisModels/reactingOneDim.

This pyrolysis part from the above location act as a sub-model in fireFOAM solver. So, fireFOAM has no job here literally.
Quote:

Could you specify the standard tutorial case which is the base for your case?
Standard tutorial case comes from fireFOAM under the following location.
~/OpenFOAM/OpenFOAM-2.1.1/tutorials/combustion/fireFoam/les/oppositeBurningPanels

For your note, this tutorial is not completed adopted. Only the solid portion related to the pyrolysis is extracted and currently in use.
Quote:

What I want to know in the previous post is not the declaration of K() in the lib. The declaration of thermophysical instance in the SOLVER. something like " SLGThermo slgThermo(mesh, thermo);"...
Mine is based on solidThermo, if I'm not wrong. I'll still dig into your comments further and analyze. Kindly share your thoughts.
Thank you again ^^


All times are GMT -4. The time now is 03:59.