|
[Sponsors] |
Accessing fields calculated in a solver within a class |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
January 17, 2017, 11:19 |
Accessing fields calculated in a solver within a class
|
#1 |
Member
Alexander Nekris
Join Date: Feb 2015
Location: France
Posts: 32
Rep Power: 11 |
Dear OF users,
I use foam-extend-3.2 version. I would like to define an additional function in the class multiComponentMixture. This function contains a volScalarField calculated in a solver at each time step (in my case the field is rho). How can I access rho from within my new function? For example if the function looks like: Code:
Template<class ThermoType> void Foam::multiComponentMixture<ThermoType>::myFunction() { const volScalarField& Rho = db().lookupObject<volScalarField>(“rho”) forAll (Z_, n) { Z_[n] = Rho*some calculation; } } Can anybody help me? Is it even possible to access a “fresh” rho field of the last time step out of multiComponentMixture? Thanks in advance, Alex |
|
January 18, 2017, 11:31 |
|
#2 |
Member
Alexander Nekris
Join Date: Feb 2015
Location: France
Posts: 32
Rep Power: 11 |
I think I should precise my problem a bit more.
In several threads I’ve read, that the procedure above (the way I try to do it) works for BC classes, but I work here with a mixture class (multiComponentMixture). As far as I see my problem at the moment, in my custom mixture I have no direct access to the field rho, which is declared in the solver in createFields.H and recalculated each time step in the solver via rho = thermo.rho(). In my custom mixture I don’t want to change rho, I just need the current rho values of the last time step in my function. So, I somehow need to lookup rho from mesh, database, …? But if I try something like this I get the error that db or mesh or whatever I try, is not declared in this scope. So how can I declare it in my mixture class? |
|
January 19, 2017, 06:27 |
|
#3 |
Member
Alexander Nekris
Join Date: Feb 2015
Location: France
Posts: 32
Rep Power: 11 |
Ok, I think I resolved the problem.
As I assumed, I have somehow to declare the database. In my custom mixture class I have mass fraction fields Y[n]. I declared the db() via these mass fraction fields. I hope I didn’t mess up my code and everything will work fine. This is how I modified my function depicted above: Code:
Template<class ThermoType> void Foam::multiComponentMixture<ThermoType>::myFunction() { const objectRegistry& db = Y_[0].db(); const volScalarField& Rho = db.lookupObject<volScalarField>(“rho”) forAll (Z_, n) { Z_[n] = Rho*some calculation; } } My custom mixture class compiles fine and the solver compiles to. But I need to run the test case first to be sure, that it really works. I hope, that the rho field that I get is the latest (from the last time step) and not from the initial conditions. I don’t understand completely what I’ve done here. It would be nice if someone from advanced users would say something about it. |
|
January 24, 2017, 07:07 |
|
#4 |
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,715
Rep Power: 40 |
What you've come up with looks good. You have some volume field in your class (Y_), from which you have obtained the objectRegistry and used that to locate another field that is also registered on that database. The rho field that you will get is the reference to the density field at the current time-level.
|
|
January 26, 2017, 13:00 |
|
#5 |
Member
Alexander Nekris
Join Date: Feb 2015
Location: France
Posts: 32
Rep Power: 11 |
Hello Mark,
thank you for your reply. It is good to know, that it refers to the current time-level. |
|
March 8, 2017, 19:29 |
|
#6 |
Member
Zhiheng Wang
Join Date: Mar 2016
Posts: 72
Rep Power: 10 |
Use thermo.rho().internalField()[I]
Or thermo.rho().boundaryField()[I] Sent from my Lenovo K50a40 using CFD Online Forum mobile app |
|
March 8, 2017, 19:30 |
|
#7 |
Member
Zhiheng Wang
Join Date: Mar 2016
Posts: 72
Rep Power: 10 |
It's thermo.rho().boundaryField()[patchId][i]
Sent from my Lenovo K50a40 using CFD Online Forum mobile app |
|
July 12, 2017, 15:06 |
|
#8 | |
Member
Hooman
Join Date: Apr 2011
Posts: 35
Rep Power: 15 |
Quote:
I have kind of the same problem. I am adding a new model to simpleFoam (model M). I need to access a volume scalar field which will be calculated right before the very first iteration, let's call it A. How can I access this A field in my M.c file? Because obviously field A does not exist yet! Thank you very much! |
||
Tags |
access, class, field, solver |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
dsmcFoam setup | hherbol | OpenFOAM Pre-Processing | 1 | November 19, 2021 02:52 |
The udf.h headers are unable to open- in VISUAL STUDIO 13 | sanjeetlimbu | Fluent UDF and Scheme Programming | 4 | May 2, 2016 06:38 |
oopenFoam error | cyndy M | OpenFOAM Pre-Processing | 7 | March 30, 2016 09:03 |
deviation in calculated force between CFX solver and CFD post | murx | CFX | 2 | April 9, 2014 21:03 |
Errors running allwmake in OpenFOAM141dev with WM_COMPILE_OPTION%3ddebug | unoder | OpenFOAM Installation | 11 | January 30, 2008 21:30 |