|
[Sponsors] |
August 24, 2020, 06:42 |
How to extract scalar members from a class ?
|
#1 | |
Senior Member
|
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:
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 10:41. |
||
August 26, 2020, 13:02 |
|
#2 |
Senior Member
Adhiraj
Join Date: Sep 2010
Location: Karnataka, India
Posts: 187
Rep Power: 15 |
What type of variables are these?
How do you define them? |
|
August 26, 2020, 14:12 |
|
#3 | |
Senior Member
|
Thank you for your reply.
I have declared it in my custom solver under the following location: Quote:
|
||
August 29, 2020, 17:40 |
|
#4 |
Member
Ran
Join Date: Aug 2016
Posts: 69
Rep Power: 9 |
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 |
|
August 30, 2020, 02:50 |
|
#5 |
Senior Member
|
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 |
|
August 31, 2020, 00:18 |
|
#6 |
Senior Member
|
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; |
|
August 31, 2020, 10:18 |
|
#7 | |||
Senior Member
|
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:
Quote:
Quote:
Kindly share your thoughts about it please. Thank you |
||||
August 31, 2020, 11:14 |
|
#8 |
Senior Member
|
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, |
|
August 31, 2020, 11:28 |
|
#9 |
Senior Member
|
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 |
|
August 31, 2020, 11:58 |
|
#10 |
Senior Member
|
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. |
|
August 31, 2020, 12:35 |
|
#11 | |
Senior Member
|
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:
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. |
||
September 1, 2020, 04:50 |
|
#12 |
Senior Member
|
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);"... |
|
September 1, 2020, 05:17 |
|
#13 |
Senior Member
|
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); 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 ============================ |
|
September 1, 2020, 07:02 |
|
#14 | |||
Senior Member
|
Hello snak,
Sorry for the difficulties caused. Thank you for your time and elaborate info. Quote:
~/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:
~/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:
Thank you again ^^ |
||||
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Error in New Surface reaction model (Having multiple reactions) | surajkvs | OpenFOAM Programming & Development | 2 | May 23, 2023 21:21 |
Extract a member function from a class of different solver for "Source Term" | Kummi | OpenFOAM | 7 | December 26, 2019 22:32 |
FATAL ERROR:Maximum number of iterations exceeded | zqlhzx | OpenFOAM Running, Solving & CFD | 4 | July 13, 2016 15:53 |
dimensionedScalar as class member | Seeker | OpenFOAM Programming & Development | 2 | March 29, 2013 05:57 |
is internalField(U) equivalent to zeroGradient? | immortality | OpenFOAM Running, Solving & CFD | 7 | March 29, 2013 01:27 |