|
[Sponsors] |
Accessing dictionaries from constant folder in multi region solver |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
January 13, 2022, 11:18 |
Accessing dictionaries from constant folder in multi region solver
|
#1 |
New Member
Join Date: Jun 2018
Posts: 20
Rep Power: 8 |
Hello,
I wrote my own solver based on chtMultiRegionFoam. Therefore, I read dictionaries from the constant folder. Now I want to use more than one solid and one fluid region but I can't figure out how to acess the dictionaries for an arbitrary number of regions. I'm using of8. I tried: Code:
forAll(solidRegions, i) { fvMesh& mesh = solidRegions[i]; IOdictionary myProperties ( IOobject ( "myProperties", mesh.time().constant(), mesh, IOobject::MUST_READ_IF_MODIFIED, IOobject::NO_WRITE ) ); } Code:
forAll(solidRegions,i) { const scalar myScalar = readScalar(myProperties.lookup("myScalar")); } Code:
--> FOAM FATAL ERROR: request for dictionary myProperties from objectRegistry solid1 failed available objects of type dictionary are 3 ( fvSchemes fvSolution data ) Any hints about how to use dictionaries in a multi region solver are appreciated. Thanks. |
|
January 14, 2022, 05:24 |
|
#2 |
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,715
Rep Power: 40 |
Not really sure how you expect this to work. In the first loop you create and discard "myProperties" several times. At later stage you are hoping to access the variable from a different scope??? Consider the following standard C/C++ (not OpenFOAM-specific):
Code:
int foo = 100; if (true) { int bar = 200; } // print results { printf("foo = %d\n", foo); printf("bar = %d\n", bar); } |
|
January 14, 2022, 06:48 |
|
#3 |
New Member
Join Date: Jun 2018
Posts: 20
Rep Power: 8 |
Well, I believed that every dictionary "belongs" to a mesh. So while looping through the mesh regions I tried to create the same dictionary for every mesh region. I thought the respecitve dictionaries are only known "inside" their region and could be accessed later on while looping through the mesh regions again .
I want to make use of openFoam's dictionary function and easily define different properties for each physical region for the simulation in the case/constant folder. (basically like it's done with thermophysicalProperties or whatever). Can you tell me where I did go wrong and how to actually achieve this? Tanks! |
|
January 14, 2022, 09:45 |
|
#4 | |
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,715
Rep Power: 40 |
Quote:
You have the possibility to have the registered objects stored externally to the registry or actually stored on the registry. In your original code example, you added have "myProperties" as a local variable, which is indeed registered on the objectRegistry, but since that variable is local, it removes itself from the registry when it goes out of scope. So one possiblity: Code:
PtrList<IOdictionary> allMyProperties(solidRegions.size()); forAll(solidRegions, regioni) { auto& mesh = solidRegions[regioni]; allMyProperties.set ( regioni, new IOdictionary ( IOobject ( "myProperties", mesh.time().constant(), mesh, IOobject::MUST_READ_IF_MODIFIED, IOobject::NO_WRITE ) ) ); } Last edited by olesen; January 19, 2022 at 06:56. |
||
January 17, 2022, 11:46 |
|
#5 | |
New Member
Join Date: Jun 2018
Posts: 20
Rep Power: 8 |
Thank you! It works perfectly so far .
For my understanding: What's the advantage of storing the objects externally to the registry vs on the registry? There was just an "o" missing in your code. The following code works on of8 if anybody has the same issue as me: Quote:
|
||
January 19, 2022, 06:56 |
|
#6 | |
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,715
Rep Power: 40 |
Quote:
The answer is "depend". If you have things that you will mostly or only be accessing via the objectRegistry lookups in various places, then storing to the registry probably fits well with your needs. Perhaps for your case you would like to access them both via the registries AND as a linear list, the external storage makes sense. In some places, it is useful to check if a field exists (on the registry). If it doesn't, then create a local-scope autoPtr of the field and have it registered on the registry. When the autoPtr goes out of scope, its deletion will also remove the field from the registry. Gives a nice cleanup behaviour: leaves it on the registry if it already existed before, but also cleans up the local-scope one too. |
||
Tags |
chtmultiregionfoam, dictionary, multi regions, object registry |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
chtMultiRegionFoam solver stops without any error | amol_patel | OpenFOAM Running, Solving & CFD | 4 | July 5, 2024 02:41 |
Negative initial temperature error (chtMultiRegionFoam) | jebin | OpenFOAM Pre-Processing | 60 | July 17, 2022 06:10 |
chtMultiRegionFoam speed up | qwertz | OpenFOAM Running, Solving & CFD | 8 | September 18, 2021 07:16 |
PEMFC model with FLUENT | brahimchoice | FLUENT | 22 | April 19, 2020 16:44 |
problem with Min/max rho | tH3f0rC3 | OpenFOAM | 8 | July 31, 2019 10:48 |