|
[Sponsors] |
June 20, 2017, 03:13 |
Reading Scalar within an OF class
|
#1 |
Member
Sebastian Trunk
Join Date: Mar 2015
Location: Erlangen, Germany
Posts: 60
Rep Power: 11 |
Hey Foamers,
I am currently working on a modified kinematicParcel in OF 2.3. I would like to add a molecular diffusion to the Code:
dt *= dCorr/d *p.trackToFace(p.position() + dCorr*U_/magU + DIFFUSION), td); Therefore, I want to read a dimension scalar from the transportProperties dict. Is there a way to read this scalar without the classical way (see below) since I do not want to run createMesh.H everytime the function is called... In the KinematicParcel.C there is no construction of a mesh/time. The mesh is constructed much later when the solver is called. Code:
Info << "Reading transportProperties \n" << endl; IOdictionary transportProperties ( IOobject ( "transportProperties", runTime.constant(), mesh, IOobject::MUST_READ_IF_MODIFIED, IOobject::NO_WRITE ) ); dimensionedScalar Diffusion ( transportProperties.lookup("Diffusion") ); Thanks a lot! Best regards Last edited by sisetrun; June 20, 2017 at 09:06. |
|
June 20, 2017, 09:07 |
|
#2 |
Super Moderator
Tobias Holzmann
Join Date: Oct 2010
Location: Tussenhausen
Posts: 2,708
Blog Entries: 6
Rep Power: 51 |
Hi,
you have access to registered objects using that line: Code:
volScalarField test = this->db().lookupObject<volScalarField>("myField"); What you can do in your library is to build a dictionary and store it. Then you can easily access the lookup functionality of that object and thus you can read the value in the dictionary. Therefore you have to add that object to the header file and initialize it while calling the constructors. Thats it. The constructor itself should have access to the mesh and time (indirectly). However, I never went into that classes so maybe I am wrong here but the way above is working (but I guess not with dimensionedScalars but you could use an scalarIOList which is available in the database. There you could put your scalar and build a dimensioned scalar in the kinematicParcel.C file. E.g. createFields.H Code:
scalarIOList myScalar ( IOobject ( "myScalar", runTime.timeName(), mesh, IOobject::NO_READ, IOobject::NO_WRITE ), 1 // only one entry in the list ); myScalar[0] = dict.lookup(...); Code:
const scalarIOList& tmp = this->db().lookupObject<scalarIOList>("myScalar"); const dimensionedScalar DIFFUSION ("myDimScalar", dimLess, tmp); // Further calculation Good luck By the way. If it is a template class you have to access it differently (for FOAM-4.x) Code:
const scalarIOList& tmp = this->db().template lookupBoject<scalarIOList>("myScalar");
__________________
Keep foaming, Tobias Holzmann |
|
June 23, 2017, 08:51 |
|
#3 |
Member
Sebastian Trunk
Join Date: Mar 2015
Location: Erlangen, Germany
Posts: 60
Rep Power: 11 |
Once again, thank you Tobias.
I will give it a try... Have a nice weekend Last edited by sisetrun; June 29, 2017 at 02:40. |
|
June 29, 2017, 02:43 |
|
#4 |
Member
Sebastian Trunk
Join Date: Mar 2015
Location: Erlangen, Germany
Posts: 60
Rep Power: 11 |
I managed it in a different way...
Just as information if anybody has the same issue: In the files of kinematicParcel, I added the variable to the constantProperties and adjusted all constructors and member functions. Now the I am able to use Dmol() (Diffusion) as a function which returns the Dmol from the propertiesDict in the constant folder. Last edited by sisetrun; June 29, 2017 at 07:09. |
|
June 29, 2017, 07:07 |
|
#5 |
Super Moderator
Tobias Holzmann
Join Date: Oct 2010
Location: Tussenhausen
Posts: 2,708
Blog Entries: 6
Rep Power: 51 |
Yes, of course that is a better way
Finally there are more ways you can handle that. Well done and good to know that it is working.
__________________
Keep foaming, Tobias Holzmann |
|
March 9, 2022, 11:07 |
|
#6 |
Member
UOCFD
Join Date: Oct 2020
Posts: 40
Rep Power: 5 |
I have included this code in my BC
Code:
#include "scalarIOList.H" const fvMesh& mesh_ = this->internalField().mesh(); scalarIOList copyOpenFraction ( IOobject ( "copyOpenFraction", mesh_.time(), mesh_, IOobject::NO_READ, IOobject::NO_WRITE ), 1 ); copyOpenFraction[0] = openFraction_; Code:
error: no matching function for call to ‘Foam::IOobject::IOobject(const char [17], const Foam::Time&, const Foam::fvMesh&, Foam::IOobject::readOption, Foam::IOobject::writeOption)’ 357 | ), 1 | ^ |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
problem during mpi in server: expected Scalar, found on line 0 the word 'nan' | muth | OpenFOAM Running, Solving & CFD | 3 | August 27, 2018 04:18 |
[Commercial meshers] Problem converting fluent mesh | vinz | OpenFOAM Meshing & Mesh Conversion | 28 | October 12, 2015 06:37 |
compressible flow in turbocharger | riesotto | OpenFOAM | 50 | May 26, 2014 01:47 |
Possible Bug in pimpleFoam (or createPatch) (or fluent3DMeshToFoam) | cfdonline2mohsen | OpenFOAM | 3 | October 21, 2013 09:28 |
Problem in running ICEM grid in Openfoam | Tarak | OpenFOAM | 6 | September 9, 2011 17:51 |