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

Accessing boundary patch dictionary within thermodynamic library

Register Blogs Community New Posts Updated Threads Search

Like Tree3Likes
  • 1 Post By Tobi
  • 1 Post By wyldckat
  • 1 Post By wyldckat

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   November 3, 2018, 06:11
Default Accessing boundary patch dictionary within thermodynamic library
  #1
Super Moderator
 
Tobi's Avatar
 
Tobias Holzmann
Join Date: Oct 2010
Location: Bad Wörishofen
Posts: 2,711
Blog Entries: 6
Rep Power: 52
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 all and dear Foamers,

today I am stuck with a simple problem that I cannot resolve myself even though, I went through Doxgen and so on; actually the problem is related to the fact that I never saw something like that inside the source code . To keep it short. I want to access the boundary dictionary of a patch inside a new thermodynamic library.

The field can be accessed easily within my thermodynamic library (I make it very detailed now):

Code:
const volScalarField& myField = this->myField_;
After that, we have the volScalarField which is a GeometricField. So I checked Doxygen, and we find that we can use the function boundaryField() to get the Boundary object and while checking the Boundary class, we get the hint that we can use the operator operator[]. to return a <T> object; defined in public functions in the UPtrList<T> class. Let us consider that I want to have the dictonary of the first patch inside the file, e.g., T; the label is 0 (Attention! I assume that the order of the patch names inside the constant/polyMesh/boundary and the T file are identical). The access to the boundary is as follows:

Code:
//- I get the dictionary of the T-File of the first boundary
Info<< myField.boundaryField()[0] << endl;

//- I want to get a dictionary of the first boundary in the T-File for further analysis; NOT WORKING
const dictionary& foo = myField.boundaryField()[0];
By the way, the T-File looks as follows and I want to lookup the myNewValue quantity.

Code:
/*--------------------------------*- C++ -*----------------------------------*\ 
| =========                 |                                                 | 
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           | 
|  \\    /   O peration     | Version:  dev                                   | 
|   \\  /    A nd           | Web:      www.OpenFOAM.org                      | 
|    \\/     M anipulation  |                                                 | 
\*---------------------------------------------------------------------------*/ 
FoamFile                                                                        
{                                                                               
    version     2.0;                                                            
    format      ascii;                                                          
    class       volScalarField;                                                 
    object      T;                                                              
}                                                                               
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 
                                                                                
dimensions      [0 0 0 1 0 0 0];                                                
                                                                                
internalField   uniform 300;                                                    
                                                                                
boundaryField                                                                   
{                                                                               
    myWalls                                                                       
    {                                                                           
        type            zeroGradient;             
        myNewValue hehehe;
    }                                                                           
                                                                                
    inletTop                                                                    
    {                                                                           
        type            fixedValue;                                             
        value           uniform 305;                                            
    }                                                                            .
.
.
.
My questions

  • How can I get the patch-dictionary of my T file
  • How can I derive the functionalities via Doxygen; right now I cannot figure out how to get the access.
  • Or the other way around, while using Info<< this->T_.boundaryField()[0] << endl; which function is called?


Thank you in advance,
atulkjoy likes this.
__________________
Keep foaming,
Tobias Holzmann
Tobi is offline   Reply With Quote

Old   November 3, 2018, 09:39
Default
  #2
Senior Member
 
zhangyan's Avatar
 
Yan Zhang
Join Date: May 2014
Posts: 120
Rep Power: 12
zhangyan is on a distinguished road
After lots of errors, I got an answer
Code:
IOobject T_Header
(
    "T",
    this->mesh().time().timeName(),
    this->mesh(),
    IOobject::MUST_READ
);
IOdictionary T_File(T_Header);

scalar abc = readScalar(T_File.subDict("boundaryField").subDict("myWalls").lookup("myNewValue"));
Change the class in the Header of "T", from volScalarField to dictionary before running your case.
__________________
https://openfoam.top
zhangyan is offline   Reply With Quote

Old   November 3, 2018, 09:43
Default
  #3
Senior Member
 
zhangyan's Avatar
 
Yan Zhang
Join Date: May 2014
Posts: 120
Rep Power: 12
zhangyan is on a distinguished road
Here are some records:
Code:
error: class "Foam::fvPatchField<Foam::scalar={Foam::doubleScalar={double}}>" has no member "name"  
Info<<T_.boundaryField()[0].name()<<endl;
Code:
error: class "Foam::GeometricField<Type, PatchField, GeoMesh>::Boundary [with Type=Foam::scalar={Foam::doubleScalar={double}}, PatchField=Foam::fvPatchField, GeoMesh=Foam::volMesh]" has no member "name"  
Info<<T_.boundaryField().name()<<endl;
Code:
Info<<T_.boundaryField()[0]<<endl;
Code:
type            fixedValue;
value           uniform 29800;
Code:
Info<<T_.boundaryField()<<endl;
Code:
6
(
    type            fixedValue;
    value           uniform 29800;

    type            fixedValue;
    value           uniform 290;

    type            fixedValue;
    value           uniform 2981;

    type            zeroGradient;

    type            zeroGradient;

    type            zeroGradient;

)
My "T":
Code:
boundaryField
{
    inner
    {
        type            fixedValue;
        value           uniform 29800;
    }
    outer
    {
        type            fixedValue;
        value           uniform 290;
    }
    coflow
    {
        type            fixedValue;
        value           uniform 2981;
    }
    bluffBody
    {
        type            zeroGradient;
    }
    airBC
    {
        type            zeroGradient;
    }
    outlet
    {
        type            zeroGradient;
    }
}
__________________
https://openfoam.top
zhangyan is offline   Reply With Quote

Old   November 3, 2018, 09:59
Default
  #4
Super Moderator
 
Tobi's Avatar
 
Tobias Holzmann
Join Date: Oct 2010
Location: Bad Wörishofen
Posts: 2,711
Blog Entries: 6
Rep Power: 52
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
Quote:
Originally Posted by zhangyan View Post
After lots of errors, I got an answer
Code:
IOobject T_Header
(
    "T",
    this->mesh().time().timeName(),
    this->mesh(),
    IOobject::MUST_READ
);
IOdictionary T_File(T_Header);

scalar abc = readScalar(T_File.subDict("boundaryField").subDict("myWalls").lookup("myNewValue"));
Change the class in the Header of "T", from volScalarField to dictionary before running your case.

Hi, thanks for the checks. Okay that is a nice hack. I was not even thinking to build a new IOobject and use that as the object for looking up. Trying it now. Thanks again; sometimes I am thinking to complicated and try to avoid building new objects However, there should be away to access that stuff:
Code:
Info<< T_.boundaryField()[0] << endl;
__________________
Keep foaming,
Tobias Holzmann
Tobi is offline   Reply With Quote

Old   November 3, 2018, 14:53
Default
  #5
Super Moderator
 
Tobi's Avatar
 
Tobias Holzmann
Join Date: Oct 2010
Location: Bad Wörishofen
Posts: 2,711
Blog Entries: 6
Rep Power: 52
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
Okay, it works, but if you stop your solver and restart, it does not work again because the volScalarField is placed again in the field. Furthermore, we induce ParaView problems.
__________________
Keep foaming,
Tobias Holzmann
Tobi is offline   Reply With Quote

Old   November 3, 2018, 16:54
Default
  #6
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,981
Blog Entries: 45
Rep Power: 128
wyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to all
Greetings to all!

@Tobi: I don't have enough time to create a complete example, but here is the outline on how to do this in a way that works and abides to OpenFOAM's way of doing things:
  1. The boundary conditions do not store the dictionary as an internal variable, therefore you should create a new boundary condition class that derives from the one you want to derive from.
    • Alternatively, you may prefer to simply rely on a new field and have a single new class that has the desired dictionary entries. You can even have said new class that simply reads and writes the dict itself, without parsing said entries on its own.
  2. The new part of the code that needs these new keywords that are associated to a boundary condition, you need the access to the field, so the usual lookup mechanisms for said field:
    1. If you want a field that is part of a model, you need to ask the model for that field... see for example the yPlus function object: https://github.com/OpenFOAM/OpenFOAM...s/yPlus.C#L174 and https://github.com/OpenFOAM/OpenFOAM...us/yPlus.C#L70
    2. Or use a direct lookup: https://github.com/OpenFOAM/OpenFOAM...ressure.C#L166
    • If you went with the alternative, you can either load the field on its own or have the case set-up to rely on the "readFields" function object to load the new field and then rely on lookup to retrieve the field.
      • The advantage of relying on "readFields" is that it stays on-RAM throughout the whole simulation and you can use the "writeObjects" function object to write the field when you want to later on.
      • "decomposePar" doesn't need "readFields", so make sure to use the option "-noFunctionObjects" with it, if I remember the name correctly.
  3. So how to you finally access the complete dictionary for each boundary? Needs two working parts:
    1. The new class needs to provide either the methods that provide the entries you want or needs to provide a single method that provides the access to the internal variable that has the dictionary (keep in mind that you have to create it, "fvPatch" does not store it by default).
    2. Finally, you need to rely on type casting to gain access to the boundary condition the way you want to, as exemplified in the function object yPlus: https://github.com/OpenFOAM/OpenFOAM...us/yPlus.C#L90
You can also mix and match some of these features; for example, if you want to only access specific settings that are already provided in the default boundary condition (e.g. one of the wall function boundary conditions), you don't need to modify the boundary condition, you only need to follow the same strategy as the last step 3.2.

Best regards,
Bruno
Tobi likes this.
__________________
wyldckat is offline   Reply With Quote

Old   November 3, 2018, 18:36
Default
  #7
Super Moderator
 
Tobi's Avatar
 
Tobias Holzmann
Join Date: Oct 2010
Location: Bad Wörishofen
Posts: 2,711
Blog Entries: 6
Rep Power: 52
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 Bruno,


thanks for your feedback. As always, very exclusive -- the whole forum is updated by your knowledge right now. After your post, I remembered an easy accessible way Bernhard told me once. I did the following that works out perfectly now:


Boundary Condition
  1. Adding a new IOList<word> object
  2. Initialize the IOList<word> with an object of size one such as:
Code:
    methodName_
    (
        IOobject
        (
            "methodName",
            p.boundaryMesh().mesh().time().timeName(),
            p.boundaryMesh().mesh(),
            IOobject::NO_READ,
            IOobject::NO_WRITE
        ),
        1
    )
 
    methodName_[0] = "whatEverIWantToStore";

Thermodynamic Library

  1. Easy access via:
Code:
    if (this->T_.mesh().foundObject<IOList<word>>("methodName"))
    {
        Info<< "found" << endl;
    }
    else
    {
        Info<< "not found" << endl;
    }
__________________
Keep foaming,
Tobias Holzmann
Tobi is offline   Reply With Quote

Old   November 3, 2018, 21:34
Default
  #8
Retired Super Moderator
 
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,981
Blog Entries: 45
Rep Power: 128
wyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to allwyldckat is a name known to all
Oh, OK, I thought you wanted to have the data come through the fields, along with binding the information to the boundary conditions...

But that does remind me that we can append new dictionary data to existing dictionaries, as long as they are "dictionaries". For example, I was able sometime ago to bind additional dictionary data to the matrix solver blocks during runtime, even though the data is not written to fvSolution. That way I was able to exchange internal matrix solver data (the normalization factor to be specific) with the application-solver, without the need to rely on global variables. It's a fairly nice metadata storage feature in OpenFOAM as well
Tobi likes this.
wyldckat is offline   Reply With Quote

Old   November 5, 2018, 04:50
Default
  #9
Super Moderator
 
Tobi's Avatar
 
Tobias Holzmann
Join Date: Oct 2010
Location: Bad Wörishofen
Posts: 2,711
Blog Entries: 6
Rep Power: 52
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
Quote:
Originally Posted by wyldckat View Post
Oh, OK, I thought you wanted to have the data come through the fields, along with binding the information to the boundary conditions...
Hi Bruno, yes that was my first intention. However, based on the lack of C++ knowledge, the way I choose is easier . But an interesting point is the extension of already available dictionaries. After your hint, I re-read the IOobject/dictionary class. I will keep that in mind because it seems to be a better/reasonable solution in some cases.
__________________
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
[Other] dynamicTopoFVMesh and pointDisplacement RandomUser OpenFOAM Meshing & Mesh Conversion 6 April 26, 2018 08:30
Question about adaptive timestepping Guille1811 CFX 25 November 12, 2017 18:38
Question about heat transfer coefficient setting for CFX Anna Tian CFX 1 June 16, 2013 07:28
[mesh manipulation] Using createPatch in place of couplePatches sripplinger OpenFOAM Meshing & Mesh Conversion 8 November 13, 2009 08:14
CheckMeshbs errors ivanyao OpenFOAM Running, Solving & CFD 2 March 11, 2009 03:34


All times are GMT -4. The time now is 16:48.