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

Reading Scalar within an OF class

Register Blogs Community New Posts Updated Threads Search

Like Tree4Likes
  • 2 Post By Tobi
  • 1 Post By sisetrun
  • 1 Post By sisetrun

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   June 20, 2017, 03:13
Default Reading Scalar within an OF class
  #1
Member
 
Sebastian Trunk
Join Date: Mar 2015
Location: Erlangen, Germany
Posts: 60
Rep Power: 11
sisetrun is on a distinguished road
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);
in the KinematicParcel.C at line 305.

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")
    );
Or in other words, how can I access a dimensioned scalar from a file/dictionary within a class?

Thanks a lot!

Best regards

Last edited by sisetrun; June 20, 2017 at 09:06.
sisetrun is offline   Reply With Quote

Old   June 20, 2017, 09:07
Default
  #2
Super Moderator
 
Tobi's Avatar
 
Tobias Holzmann
Join Date: Oct 2010
Location: Tussenhausen
Posts: 2,708
Blog Entries: 6
Rep Power: 51
Tobi has a spectacular aura aboutTobi has a spectacular aura aboutTobi has a spectacular aura about
Send a message via ICQ to Tobi Send a message via Skype™ to Tobi
Hi,

you have access to registered objects using that line:

Code:
volScalarField test = this->db().lookupObject<volScalarField>("myField");
However, I am not sure if you can use that for dimensionedScalars.
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(...);
Then in the kinematicParcel.C file you can get access to that value:
Code:
const scalarIOList& tmp = this->db().lookupObject<scalarIOList>("myScalar");

const dimensionedScalar DIFFUSION ("myDimScalar", dimLess, tmp);

// Further calculation
Hope this helps you.
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");
sisetrun and ZZW like this.
__________________
Keep foaming,
Tobias Holzmann
Tobi is offline   Reply With Quote

Old   June 23, 2017, 08:51
Default
  #3
Member
 
Sebastian Trunk
Join Date: Mar 2015
Location: Erlangen, Germany
Posts: 60
Rep Power: 11
sisetrun is on a distinguished road
Once again, thank you Tobias.
I will give it a try...

Have a nice weekend
Tobi likes this.

Last edited by sisetrun; June 29, 2017 at 02:40.
sisetrun is offline   Reply With Quote

Old   June 29, 2017, 02:43
Default
  #4
Member
 
Sebastian Trunk
Join Date: Mar 2015
Location: Erlangen, Germany
Posts: 60
Rep Power: 11
sisetrun is on a distinguished road
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.
Tobi likes this.

Last edited by sisetrun; June 29, 2017 at 07:09.
sisetrun is offline   Reply With Quote

Old   June 29, 2017, 07:07
Default
  #5
Super Moderator
 
Tobi's Avatar
 
Tobias Holzmann
Join Date: Oct 2010
Location: Tussenhausen
Posts: 2,708
Blog Entries: 6
Rep Power: 51
Tobi has a spectacular aura aboutTobi has a spectacular aura aboutTobi has a spectacular aura about
Send a message via ICQ to Tobi Send a message via Skype™ to Tobi
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
Tobi is offline   Reply With Quote

Old   March 9, 2022, 11:07
Default
  #6
Member
 
UOCFD
Join Date: Oct 2020
Posts: 40
Rep Power: 5
uosilos is on a distinguished road
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_;
But it shows this error , Any idea??

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
      |   ^
uosilos is offline   Reply With Quote

Old   March 10, 2022, 09:24
Default
  #7
Super Moderator
 
Tobi's Avatar
 
Tobias Holzmann
Join Date: Oct 2010
Location: Tussenhausen
Posts: 2,708
Blog Entries: 6
Rep Power: 51
Tobi has a spectacular aura aboutTobi has a spectacular aura aboutTobi has a spectacular aura about
Send a message via ICQ to Tobi Send a message via Skype™ to Tobi
The constructor you are calling does not exist.
__________________
Keep foaming,
Tobias Holzmann
Tobi is offline   Reply With Quote

Reply


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
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


All times are GMT -4. The time now is 20:55.