CFD Online Discussion Forums

CFD Online Discussion Forums (
-   OpenFOAM Programming & Development (
-   -   accessing value in BC of another patch (

Katl December 1, 2011 06:02

accessing value in BC of another patch

I would like to use/access a value (an integer called sonderBw) which is specified in the boundary conditions of a patch (in my case the upstreamPatch) within the boundary condition of another patch (downstreamPatch).
The goal is to make a loop through all patches in order to find the matching patch with a specific value of sonderBw_

hope anybody can help me

btw. I'm using my own BCs

deepsterblue December 1, 2011 12:43

It's certainly possible, but at what level do you intend to do this - a higher solver level (eg. icoFoam) or within the BC itself?

Katl December 1, 2011 15:41

within the BC itself

deepsterblue December 1, 2011 16:10

The polyPatch/fvPatch class has a boundaryMesh() member function which can be used to loop over all patches. Then, you can use the isA<> template test (take a look at typeInfo.H) to check for specific patch types, and refCast<> to convert a generic polyPatch/fvPatch into your specific BC type.

If your data member (sonderBw_) is private within the BC, you would want to provide an access interface to it so that it can be modified externally.

This appears to be a pretty round-about approach, but it will get the job done. I would also look into storing sonderBw_ member centrally (using the objectRegistry), and update that at a global level, but it's all just a matter of preference, really.

Katl December 3, 2011 12:45

how do I use isA<> template test and refCast<> ?
I'm using U.boundaryField()[j] to loop over all patches j. Is it also possible to use these functions in my case? Or are there other possibilities?

Sorry, but I'm still new to openFoam and the codes.

Ola Widlund December 5, 2011 05:14

Hi Kathrin,

What you want to do is rather common and not very difficult. For example, go through the source code for the BC called "totalTemperature" (class totalTemperatureFvPatchScalarField). In there you will see that you can easily pick up a pointer references to other fields, and use them as you like.


All times are GMT -4. The time now is 03:37.