CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM

How to extract scalar members from a class ?

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   August 24, 2020, 07:42
Question How to extract scalar members from a class ?
  #1
Senior Member
 
Kumaresh
Join Date: Oct 2016
Posts: 268
Rep Power: 8
Kummi is on a distinguished road
Send a message via Yahoo to Kummi
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

Last edited by Kummi; August 25, 2020 at 11:41.
Kummi is offline   Reply With Quote

Old   August 26, 2020, 14:02
Default
  #2
Senior Member
 
Adhiraj
Join Date: Sep 2010
Location: Maryland, United States
Posts: 184
Rep Power: 13
adhiraj is on a distinguished road
What type of variables are these?
How do you define them?
adhiraj is offline   Reply With Quote

Old   August 26, 2020, 15:12
Default
  #3
Senior Member
 
Kumaresh
Join Date: Oct 2016
Posts: 268
Rep Power: 8
Kummi is on a distinguished road
Send a message via Yahoo to Kummi
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.
Attached Files
File Type: gz conductivity.tar.gz (1.9 KB, 5 views)
Kummi is offline   Reply With Quote

Old   August 29, 2020, 18:40
Default
  #4
Member
 
Ran
Join Date: Aug 2016
Posts: 68
Rep Power: 7
random_ran is on a distinguished road
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).
__________________
Yours in CFD,

Ran
random_ran is offline   Reply With Quote

Old   August 30, 2020, 03:50
Default
  #5
Senior Member
 
Kumaresh
Join Date: Oct 2016
Posts: 268
Rep Power: 8
Kummi is on a distinguished road
Send a message via Yahoo to Kummi
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
Kummi is offline   Reply With Quote

Old   August 31, 2020, 01:18
Default
  #6
Member
 
shinji nakagawa
Join Date: Mar 2009
Location: Japan
Posts: 97
Blog Entries: 1
Rep Power: 15
snak is on a distinguished road
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.
snak is offline   Reply With Quote

Old   August 31, 2020, 11:18
Default
  #7
Senior Member
 
Kumaresh
Join Date: Oct 2016
Posts: 268
Rep Power: 8
Kummi is on a distinguished road
Send a message via Yahoo to Kummi
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
Kummi is offline   Reply With Quote

Old   August 31, 2020, 12:14
Default
  #8
Member
 
shinji nakagawa
Join Date: Mar 2009
Location: Japan
Posts: 97
Blog Entries: 1
Rep Power: 15
snak is on a distinguished road
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,
snak is offline   Reply With Quote

Old   August 31, 2020, 12:28
Default
  #9
Senior Member
 
Kumaresh
Join Date: Oct 2016
Posts: 268
Rep Power: 8
Kummi is on a distinguished road
Send a message via Yahoo to Kummi
Thank you for your reply, snak.
At the top of this thread, I attached the code details in the attachment.

How to extract scalar members from a class ?
Kindly check in your free time and give your suggestion please.
Thank you
Kummi is offline   Reply With Quote

Old   August 31, 2020, 12:58
Default
  #10
Member
 
shinji nakagawa
Join Date: Mar 2009
Location: Japan
Posts: 97
Blog Entries: 1
Rep Power: 15
snak is on a distinguished road
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.
snak is offline   Reply With Quote

Old   August 31, 2020, 13:35
Default
  #11
Senior Member
 
Kumaresh
Join Date: Oct 2016
Posts: 268
Rep Power: 8
Kummi is on a distinguished road
Send a message via Yahoo to Kummi
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.
Kummi is offline   Reply With Quote

Old   September 1, 2020, 05:50
Default
  #12
Member
 
shinji nakagawa
Join Date: Mar 2009
Location: Japan
Posts: 97
Blog Entries: 1
Rep Power: 15
snak is on a distinguished road
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 is offline   Reply With Quote

Old   September 1, 2020, 06:17
Default
  #13
Member
 
shinji nakagawa
Join Date: Mar 2009
Location: Japan
Posts: 97
Blog Entries: 1
Rep Power: 15
snak is on a distinguished road
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
snak is offline   Reply With Quote

Old   September 1, 2020, 08:02
Default
  #14
Senior Member
 
Kumaresh
Join Date: Oct 2016
Posts: 268
Rep Power: 8
Kummi is on a distinguished road
Send a message via Yahoo to Kummi
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 ^^
Kummi is offline   Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Error in New Surface reaction model (Having multiple reactions) surajkvs OpenFOAM Programming & Development 1 April 12, 2021 06:03
Extract a member function from a class of different solver for "Source Term" Kummi OpenFOAM 7 December 26, 2019 23:32
FATAL ERROR:Maximum number of iterations exceeded zqlhzx OpenFOAM Running, Solving & CFD 4 July 13, 2016 16:53
dimensionedScalar as class member Seeker OpenFOAM Programming & Development 2 March 29, 2013 06:57
is internalField(U) equivalent to zeroGradient? immortality OpenFOAM Running, Solving & CFD 7 March 29, 2013 02:27


All times are GMT -4. The time now is 07:36.