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

Reading a value from fvSolution into custom simpleFoam

Register Blogs Community New Posts Updated Threads Search

Like Tree4Likes
  • 4 Post By klausb

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   August 17, 2020, 10:08
Default Reading a value from fvSolution into custom simpleFoam
  #1
Senior Member
 
Klaus
Join Date: Mar 2009
Posts: 260
Rep Power: 22
klausb will become famous soon enough
I want to use an additional value in my custom simpleFoam solver but am not able to read it from the fvSolution dictionary "SIMPLE" section.

The default value should be 4. I tried:


Code:
    const int A_ = controlDict_.lookupOrDefault<label> ("A", 4);
With:


Code:
SIMPLE
{
    nNonOrthogonalCorrectors 0;
    pRefCell             0;
    pRefValue            0;
    A                    4;
}
I testetd it with const int A_ = 4; for a test and that worked so the problem is reading the value from the fvSolution dictionary. I am using OF7.
klausb is offline   Reply With Quote

Old   August 17, 2020, 10:58
Default
  #2
Senior Member
 
cdegroot's Avatar
 
Chris DeGroot
Join Date: Nov 2011
Location: Canada
Posts: 414
Rep Power: 17
cdegroot is on a distinguished road
It looks like you are trying to read the value from controlDict, not fvSolution.
__________________
Chris DeGroot, PhD, PEng
CEO, Maple Key Labs
www.maplekeylabs.com
cdegroot is offline   Reply With Quote

Old   August 17, 2020, 11:27
Default
  #3
Senior Member
 
Klaus
Join Date: Mar 2009
Posts: 260
Rep Power: 22
klausb will become famous soon enough
It's not that simple, I tried fvSolution too but the problem seems to be related to the definition of the dictionary to be accessed. Unfortunately I can only find examples related to custom dictionaries, not the standard ones.
klausb is offline   Reply With Quote

Old   August 17, 2020, 13:03
Default
  #4
Senior Member
 
cdegroot's Avatar
 
Chris DeGroot
Join Date: Nov 2011
Location: Canada
Posts: 414
Rep Power: 17
cdegroot is on a distinguished road
Fair enough, but aribitrarily trying to read it from the wrong dictionary is sure to fail!
__________________
Chris DeGroot, PhD, PEng
CEO, Maple Key Labs
www.maplekeylabs.com
cdegroot is offline   Reply With Quote

Old   August 17, 2020, 13:12
Default
  #5
Senior Member
 
Klaus
Join Date: Mar 2009
Posts: 260
Rep Power: 22
klausb will become famous soon enough
I tried different ways and dictionaries including a custom dictionary. I did it when I used pervious versions of OpenFOAM. Maybe something changed with OF7.
klausb is offline   Reply With Quote

Old   August 17, 2020, 13:13
Default
  #6
Senior Member
 
cdegroot's Avatar
 
Chris DeGroot
Join Date: Nov 2011
Location: Canada
Posts: 414
Rep Power: 17
cdegroot is on a distinguished road
Check out the class definition for fvSolution:

Code:
Class
    Foam::fvSolution
Description
    Selector class for finite volume solution solution.
    fvMesh is derived from fvSolution so that all fields have access to the
    fvSolution from the mesh reference they hold.
This implies you can get it from the mesh. If you look into fvMesh.C, this is how the fvSolution object is initialized:

Code:
fvSolution(static_cast<const objectRegistry&>(*this))
So, I would estimate that you could do the same thing, except replacing *this with an instance of your mesh. I haven't tested, so I'm curious if it would work.
__________________
Chris DeGroot, PhD, PEng
CEO, Maple Key Labs
www.maplekeylabs.com
cdegroot is offline   Reply With Quote

Old   August 18, 2020, 06:47
Default
  #7
Senior Member
 
Klaus
Join Date: Mar 2009
Posts: 260
Rep Power: 22
klausb will become famous soon enough
This is, how it worked:


Code:
    const word dictName("fvSolution");
    IOdictionary solutionDict
    (
        IOobject
        (
        dictName,
        runTime.system(), //folder where the fvSolution file is located 
        runTime,
        IOobject::MUST_READ
        )
    );

    dictionary& mysimplesubDict = solutionDict.subDict("mySIMPLE"); // subsection where the values are stored

    int A1_ = (mysimplesubDict.lookupOrDefault<label>("A1", 2));
    int A2_ = (mysimplesubDict.lookupOrDefault<label>("A2", 2));
klausb 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
Parallel Block Size Issue ChiefSeaBiscuit CONVERGE 5 July 22, 2016 14:03
OpenFOAM floating point Error upuli OpenFOAM Programming & Development 5 June 20, 2016 03:19
Cht tutorial in 15 braennstroem OpenFOAM Running, Solving & CFD 197 June 10, 2015 03:02
Possible Bug in pimpleFoam (or createPatch) (or fluent3DMeshToFoam) cfdonline2mohsen OpenFOAM 3 October 21, 2013 09:28
[GAMBIT] periodic faces not matching Aadhavan ANSYS Meshing & Geometry 6 August 31, 2013 11:25


All times are GMT -4. The time now is 19:09.