# How to change/set different boundary condition for particular cell region?

 Register Blogs Members List Search Today's Posts Mark Forums Read

 April 8, 2021, 06:30 How to change/set different boundary condition for particular cell region? #1 Member   Sunag R A Join Date: Jul 2019 Location: Bangalore, India Posts: 82 Rep Power: 6 Dear all, I am using OpenFoam 5.0 and working on heat transfer simulation using chtMultiRegionSimpleFoam solver. 1. I have a temperature data file which equals to the face center length of a particular region. This temp file has "0" temp in some regions and rest with variable temperature. (say out of 1000 temp values, 400 are 0s and rest are varying). This is a Dirichet BC. 2. I have used this temperature data and simulated it. But now, I need this "zero" temperature value to be changed to convection BC. I know the parameters for convection BC. But, how do I change the zero temperature cells to different boundary condition? 3. I checked with SetFields (FieldToCell), but I can only give scalar value there and not BC. I hope my question is understood. Any leads will be appreciated. Regards, Sunag R A.

 April 8, 2021, 13:06 #2 Member   Robin Kamenicky Join Date: Mar 2016 Posts: 74 Rep Power: 11 Hi Sunag, So if I understand right, you need to change Dirichlet BC to Robin BC at patch faces where 0 temperature exists. Are these faces geometrically neighbouring to each other so you can easily make a new patch from them and assign a different BC type? Kind regards, Robin

 April 8, 2021, 23:36 #3 Member   Sunag R A Join Date: Jul 2019 Location: Bangalore, India Posts: 82 Rep Power: 6 Dear Robin, Thank you very much for your reply. As the first part, yes you have understood correctly and yes I need to change BC where 0 temperature exists. As for second part, the faces are geometrically neighbouring, but the geometry takes arbitrary shape. I have attached two images of the images, one from top and isolated view. The blue color shows the 0 temperature where BC need to be changed. Isolated view: https://drive.google.com/file/d/13I6...ew?usp=sharing Top view: https://drive.google.com/file/d/1Jwr...ew?usp=sharing Regards, Sunag R A.

 April 9, 2021, 03:16 codedMixed bc #4 New Member   Simon Join Date: Jan 2014 Location: Freiburg, Germany Posts: 15 Rep Power: 12 Hi Sunag, maybe the codedMixed bc does the job for you... e.g for the T file changing fixed value to zeroGradient at t = 10 s: Code: ```boundaryField { patchName { type codedMixed; refValue uniform 0; refGradient uniform 0; valueFraction uniform 0; value uniform 0; name mixedBCname; code #{ const scalar t = this->db().time().value(); scalar Tair = 305; //scalar PI = Foam::constant::mathematical::pi; scalar w = 1; // w = 0 only gradient applies , w = 1 only fixedValue applies. if(t >= 10) { w=0; } this->refValue() = Tair; this->refGrad()=0; // zeroGradient this->valueFraction()=w; #}; } }```

 April 9, 2021, 03:36 #5 Member   Sunag R A Join Date: Jul 2019 Location: Bangalore, India Posts: 82 Rep Power: 6 Dear Robin, This looks good and advanced. I will definitely work with this and update you. But, I have few questions based on this code. 1. So, in this, w = 0 means it applies Robin function and w = 1, applies Dirichlet function from an external source implemented.? 2. As you have mentioned as example, after t=10s, it will be switched to w=0 meaning Robin funciton. I understand that. But, how to keep this robin funciton only for temp = 0, rest should be with Dirichet function only..!! 3. Also, how to run this code? I mean, should I include this in system/region or system folder? 4. Main Convection BC I am intended to give in place of temp = 0, is as below: type externalWallHeatFluxTemperature; mode coefficient; Ta constant 22; h uniform 10; kappaMethod solidThermo; value uniform 30; Thanks and Regards, Sunag R A.

April 9, 2021, 05:04
#6
New Member

Simon
Join Date: Jan 2014
Location: Freiburg, Germany
Posts: 15
Rep Power: 12
Quote:
 Originally Posted by sunagra27 Dear Robin,
Hi Sunag, it is Simon here ;-)

Quote:
 Originally Posted by sunagra27 1. So, in this, w = 0 means it applies Robin function and w = 1, applies Dirichlet function from an external source implemented.?
You can define any value for both here:
this->refValue() = Tair;

Quote:
 Originally Posted by sunagra27 2. As you have mentioned as example, after t=10s, it will be switched to w=0 meaning Robin funciton. I understand that. But, how to keep this robin funciton only for temp = 0, rest should be with Dirichet function only..!!
You can use (t>0). However I am not sure if this makes sense from a physical perspective...

Quote:
 Originally Posted by sunagra27 3. Also, how to run this code? I mean, should I include this in system/region or system folder?
As mentioned: Include the code in your bc file, e.g. 0/T/patchName

Quote:
 Originally Posted by sunagra27 4. Main Convection BC I am intended to give in place of temp = 0, is as below: type externalWallHeatFluxTemperature; mode coefficient; Ta constant 22; h uniform 10; kappaMethod solidThermo; value uniform 30;
Well, with this approach you only can define gradient and fixed value.

So I think you have to check the source code of externalWallHeatFluxTemperature and calculate the gradient and define it manually as mentioned in 1.

Good luck! Simon

 April 10, 2021, 15:13 #7 Member   Robin Kamenicky Join Date: Mar 2016 Posts: 74 Rep Power: 11 Hi Sunag, Simon gave definitely a great tip. You can think about codedMixed BC. Certainly, other option would be to code your own boundary condition. I have seen that externalWallHeatFluxTemperature BC actually inherits from mixedFvPatchScalarField so you might start from that if the coded one would not be appropriate for some reason. If you want to study mixed boundary conditions a typical one is InletOultet, where - Positive flux (out of domain): apply zero-gradient condition - Negative flux (into of domain): apply the "inletValue" fixed-value That should not be difficult to understand. Kind regards, Robin

 April 13, 2021, 23:31 #8 Member   Sunag R A Join Date: Jul 2019 Location: Bangalore, India Posts: 82 Rep Power: 6 Dear Simon, Sorry for late reply. Thank you so much for your reply with suggestions. I will try to work on this. But, I am using chtMultiRegionSimpleFoam, so I don't think t>0 will work. But I need when temp(fieldvalue) = 0, the BC should change. Based on "PatchName", well how to create a Patch where the FieldValue = 0.? After this only, I can implement right? I think since it is new to me, it will be difficult for me to understand and implement. Will work on this. Regards, Sunag R A.

 April 13, 2021, 23:33 #9 Member   Sunag R A Join Date: Jul 2019 Location: Bangalore, India Posts: 82 Rep Power: 6 Hi Robin, Sorry for late reply. I will check with mixedFvPatchScalarFieldand and try to work with this. Regards, Sunag R A.

 April 14, 2021, 02:24 #10 Member   Sunag R A Join Date: Jul 2019 Location: Bangalore, India Posts: 82 Rep Power: 6 Dear Robin and Simon, I am thinking to create the patch using TopoSet or setSet using 1. Creating FaceLabel and then create faceSet from those labels and finally create faceZoneSet so that creates a patch. 2. My idea is to get the faceLabels where the surface temp BC is 0 and then implement in the topoSet. But my question is, 1. How to get the faceLabel values? I checked in postProcessing after running the simulation for 1 iteration. I get the faceCenter values and not FaceLabels. 2. Once I get the faceLabel, is it possible to use #include in topoSet so that it directly access the corresponding faceLabels? I do not know this method works on that, but I think my understanding is quite clear in this context. Regards, Sunag R A.

April 14, 2021, 04:58
#11
Member

Robin Kamenicky
Join Date: Mar 2016
Posts: 74
Rep Power: 11
Hi Sunag

Quote:
 How to get the faceLabel values? I checked in postProcessing after running the simulation for 1 iteration. I get the faceCenter values and not FaceLabels.
You can have a look how mesh is treated in OpenFOAM.
If you use more regions then go in constant/region/polymesh/boundary.

An example is here:
Code:
```*--------------------------------*- C++ -*----------------------------------*\
| =========                 |                                                 |
| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |
|  \\    /   O peration     | Version:  v1906                                 |
|   \\  /    A nd           | Web:      www.OpenFOAM.com                      |
|    \\/     M anipulation  |                                                 |
\*---------------------------------------------------------------------------*/
FoamFile
{
version     2.0;
format      ascii;
class       polyBoundaryMesh;
location    "constant/region/polyMesh";
object      boundary;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

3
(
walls
{
type            wall;
physicalType    wall;
nFaces          4445;
startFace       80760;
}
maxY
{
type            patch;
physicalType    patch;
nFaces          1225;
startFace       85205;
}
fluid_to_solid
{
type            mappedWall;
inGroups        1(wall);
nFaces          510;
startFace       86430;
sampleMode      nearestPatchFaceAMI;
sampleRegion    solid;
samplePatch     solid_to_fluid;
}
)

// ************************************************************************* //```
There are the patches you use. Choose the patch you are interested in, find related startFace number. This number is a label of the first patch face. Then go into the time/region/field, find the patch and the faces values you see are labeled incrementing by one from the startFace. These are the labels

Certainly a question is how to get those where T is zero. Currently I am not sure about any utility, but I will have a look. Otherwise a python or bash scripts should be straight forward to write.

These labels you can then probably use in topoSetDict and then use createPatch command. I am just not sure how will OpenFOAM treat (label) your new patch if the patch faces are going to be scattered around and will not be neighbouring. You can give a try. That is the reason why I thought about the previous way.

Quote:
 2. Once I get the faceLabel, is it possible to use #include in topoSet so that it directly access the corresponding faceLabels?
If anything, then you can include just configuration files. The code will not be compiled again. Similarly to post-processing tools.

Maybe Simon will have another idea.

Kind regards,
Robin

April 14, 2021, 06:12
#12
Member

Sunag R A
Join Date: Jul 2019
Location: Bangalore, India
Posts: 82
Rep Power: 6
Dear Robin,

Below is my list of patches obtained after splitRegionMesh.

Quote:
 3 ( gland { type patch; inGroups 1 ( wall ); nFaces 23044; startFace 1432292; } chestwall { type patch; inGroups 1 ( wall ); nFaces 9661; startFace 1455336; } gland_to_tumor { type mappedWall; inGroups 1 ( wall ); nFaces 270; startFace 1464997; sampleMode nearestPatchFace; sampleRegion tumor; samplePatch tumor_to_gland; } )
In this, the gland has 23044 faces which is the surface which contains the temperature values. What I am trying to say is:

1. Split this gland region into two patches using topoSet. One with variable temp and other with zero temperature (As shown in the figures attached previously). So that, I can apply BC separately for each.

2. For this, I thought of accessing the faces of this region with Temp=0 and then implement in toposet. I have faceCentres of this region, so I thought of splitting into two patches separately using faceCentres itself through python (This can be done). But can I use faceCentres only to createPatch in topoSet or faceLabels are necessary?

3. In the previous method as u mentioned, it is quite complicated for me, but I am trying to understand it. But since mine is steady flow, I think t>0 or t>10s dosent work for this case. Also, I need to say where it can be differentiated between temp and time if I can understand properly.

Regards,
Sunag R A.

April 17, 2021, 12:21
#13
Member

Robin Kamenicky
Join Date: Mar 2016
Posts: 74
Rep Power: 11
Hi Sunag,

Quote:
 2. For this, I thought of accessing the faces of this region with Temp=0 and then implement in toposet. I have faceCentres of this region, so I thought of splitting into two patches separately using faceCentres itself through python (This can be done). But can I use faceCentres only to createPatch in topoSet or faceLabels are necessary?
I suppose you do not need facelabels you can also use something like this for toposet

Code:
```
name    pointNearest1;
type    pointSet;
action  new;
source  nearestToPoint;
points(
(0 0 0)
(0 0 1)
);```
and this

Code:
```
name    pointFace1;
type    pointSet;
action  new;
source  pointToFace;
option  all;
sets
(
pointNearest1
);```
That means you make first pointSet from points and then faceSet from the pointSet. Then you can create the patch from the face set. I have not tried but it worth to try.
Just make yourself sure, it did what you expect. Also, the code is based on ESI group version, but I guess it should be same or very similar.

Quote:
 3. In the previous method as u mentioned, it is quite complicated for me, but I am trying to understand it. But since mine is steady flow, I think t>0 or t>10s dosent work for this case. Also, I need to say where it can be differentiated between temp and time if I can understand properly.
The time does not matter. It was just meant to tell the boundary condition when to start to apply the Robin condition. The time can be an iterratio number in your case. Or you start the simulation from the point you want to have the Robin boundary condition and you do not need the if condition at all.

Regards,
Robin

April 19, 2021, 06:06
#14
Member

Sunag R A
Join Date: Jul 2019
Location: Bangalore, India
Posts: 82
Rep Power: 6
Dear Robin,

Thank you very much for your suggestion.

1. With respect to the pointSet creation, I could access the points where Temp = 0 and then implemented in topoSet as follows.

Quote:
 { name pointNearest1; type pointSet; action new; source nearestToPoint; sourceInfo { points ( #include "pointsPatch1"; ); } }

After running topoSet, this assignment does work and create a file pointsPatch1 in constant/polymesh/sets as expected. But it throws an error as below.

Quote:
 --> FOAM FATAL IO ERROR: keyword name is undefined in dictionary "/home/simulation/system/topoSetDict.actions" file: /home/simulation/system/topoSetDict.actions From function const Foam::entry& Foam::dictionary::lookupEntry(const Foam::word&, bool, bool) const in file db/dictionary/dictionary.C at line 566. FOAM exiting

Where do I put the keyword "name" in the assignment.? What am I missing here?

Regards,

Sunag R A.

April 19, 2021, 06:12
#15
Member

Sunag R A
Join Date: Jul 2019
Location: Bangalore, India
Posts: 82
Rep Power: 6
Dear Simon and Robin,

I did work with codedMixed BC as suggested from your code.

1. I looked at a brief description of how does CodedMixed work in the image attached along with this thread.

2. I tried to work with the following steps in boundaryField.

a. Get the faceCentres mesh details of the surface.
b. Put a condition to say if the faceCentres temp value==0, then apply convection.

3. I do not whether it is correct way or not, but the implementation is as follows. I know this below implementation does not work, but any suggestion is appreciated.

Quote:
 Patchname { //type fixedValue; //value #include "actualSkinData"; type codedMixed; refValue uniform 0; refGradient uniform 0; valueFraction uniform 0; value uniform 0; name mixedBC; code #{ const fvPatch& boundaryPatch = patch(); const vectorField& Cf = boundaryPatch.Cf(); scalarField& field = *this; field = patchInternalField(); //field = #include "actualSkinData"; scalar T = 0; scalar Tair = 22; const scalar t = this -> db().time().value(); forAll(Cf, faceI) { if ( (Cf[faceI].T() == 0) ) { //Apply convection BC } } #}; }

How do I proceed with this? The term "actualSkinData" represents the temp file externally applied. The scalar T here is the temperature value.

I have attached the image link for reference of the code which I found:

Regards,
Sunag R A.

April 20, 2021, 05:17
#16
Member

Robin Kamenicky
Join Date: Mar 2016
Posts: 74
Rep Power: 11
Hi Sunagra,

How does look whole topoSetDict you wrote?

Quote:
 Where do I put the keyword "name" in the assignment.? What am I missing here?
It should be like this
Code:
``` actions

( {
name pointNearest1;
type pointSet;
action new;
source nearestToPoint;
sourceInfo
points
(     #include "pointsPatch1";
);
}
{name    pointFace1;
type    pointSet;
action  new;
source  pointToFace;

option  all;
sets

(pointNearest1
);
}

);```

Kind regards,
Robin

April 21, 2021, 04:44
#17
Member

Sunag R A
Join Date: Jul 2019
Location: Bangalore, India
Posts: 82
Rep Power: 6
Dear Robin,

I have implemented the pointToFace in topoSet and its working fine currently.

Also, in the next phase, I also done with createPatch using the faceSet obtained from topoSet. This is also working fine, and now, the surface domain is splitted into two BC's (one with temp ==0 and other temp >0).

1. But I have one issue in the nFaces obtained in constant/polymesh/boundary.

Below is the topoSet implementation.

Code:
```      {
name pointNearest1;
type pointSet;
action new;
source nearestToPoint;
sourceInfo
{
points
(
#include "pointsPatch1"
);
}
}

{
name    pointFace1;
type    faceSet;
action  new;
source  pointToFace;
sourceInfo
{
option all;
set pointNearest1;
}
}```
2. The issue is that before the splitting of the surface, the nFaces = 23044. After splitting, the nFaces = 14635 with Temp > 0 and rest with temp = 0. Well, this is expected.

3. But, for BC applied from external temp file, the length of temp value from faceCenters for temp>0 is 14476. So, after splitting the region nFaces and this temperature should match as per our problem. Else, during simulation it shows as,

size 14476 is not equal to the given value of 14635. (It might be difficult to understand what I might be saying).

4. This might have occured since the pointToFace has created faces from points obtained. So, may be there might be some mismatch.

5. Is there a possibility to create faceSet from faces and faceCentres ??

Faces example:
Quote:
 3 ( 5(0 1 2 3 4) 4(5 6 7 8) 4(9 10 11 12) )
Regards,

Sunag R A.

Last edited by sunagra27; April 21, 2021 at 08:54.

April 25, 2021, 06:47
#18
Member

Robin Kamenicky
Join Date: Mar 2016
Posts: 74
Rep Power: 11
Hi Sunag,

Quote:
 3. But, for BC applied from external temp file, the length of temp value from faceCenters for temp>0 is 14476. So, after splitting the region nFaces and this temperature should match as per our problem. Else, during simulation it shows as, size 14476 is not equal to the given value of 14635. (It might be difficult to understand what I might be saying).
Question is how have you got the list of points in the file pointsPatch1. They should be based on the BC, right. I guess those are patch face centers of patch faces having T > 0.

Quote:
 4. This might have occured since the pointToFace has created faces from points obtained. So, may be there might be some mismatch.
According to documentation, it does not create new faces. "A topoSetFaceSource to select faces with any point or any edge within a given pointSet(s)."

Quote:
 5. Is there a possibility to create faceSet from faces and faceCentres ??
You can have a look here for some options. https://develop.openfoam.com/Develop...em/topoSetDict

Kind regards,
Robin

April 25, 2021, 23:59
#19
Member

Sunag R A
Join Date: Jul 2019
Location: Bangalore, India
Posts: 82
Rep Power: 6
Hi Robin,

Quote:
 Originally Posted by Robin.Kamenicky Question is how have you got the list of points in the file pointsPatch1. They should be based on the BC, right. I guess those are patch face centers of patch faces having T > 0.

I obtained list of points in this way.

1. I applied external temperature BC to skin where T is variable and T = 0 as mentioned before. From this, I ran simulation for 1 iteration. During this process, I used "functions" in controlDict to get the value of surfaces.

2. After 1 iterated simulation, I get faceCentres, points, scalar Field T in the post-Process folder.

3. Using these points, I took points only with T = 0 (As I had temp values externally, I could coorelate these two and segregate the points).

4. From these points where T= 0, I thought of creating faces from PointToFace and from this FaceSet. (In the sense, I think these points create faces where T=0 only).

5. After this FaceSet, I used createToPatch and then used splitMesh.

Quote:
 Originally Posted by Robin.Kamenicky According to documentation, it does not create new faces. "A topoSetFaceSource to select faces with any point or any edge within a given pointSet(s)."

I do not need new faces, I just need the faces where T=0 is applied. I think points does a pretty good job. But, I am unable to understand why it is not considering all the points where T=0. I could see this visually too.

Quote:
 Originally Posted by Robin.Kamenicky You can have a look here for some options. https://develop.openfoam.com/Development/openfoam/-/blob/master/tutorials/incompressible/pisoFoam/RAS/cavity/system/topoSetDict

The topoSet has several utilities, but none shows the creation of faceSet from faces and faceCentres. But, there is one such utility which uses faceLabels to create faceSet.

But how do I get the faceLabels of the surface? There is one post related to this where I have put the link below, but for this where should I write the code to obtain the faceIDs?

Link: How to get face IDs of a boundary

Kind regards,
Sunag R A.

April 30, 2021, 16:05
#20
Member

Robin Kamenicky
Join Date: Mar 2016
Posts: 74
Rep Power: 11
Hi Sunag,

Certainly somewhere is a mistake, but it is getting difficult to spot without the case.

Quote:
 2. After 1 iterated simulation, I get faceCentres, points, scalar Field T in the post-Process folder. 3. Using these points, I took points only with T = 0 (As I had temp values externally, I could coorelate these two and segregate the points).
What points do you mean by points (face vertices)? It would be good to do pointSet from patch faceCentres so it gives you same number of faces as you give it the points.

Quote:
 The topoSet has several utilities, but none shows the creation of faceSet from faces and faceCentres. But, there is one such utility which uses faceLabels to create faceSet.
Faces can be defined by labels or vertices. Eventually can be founnd by any point which is included in the face.

Quote:
 But how do I get the faceLabels of the surface? There is one post related to this where I have put the link below, but for this where should I write the code to obtain the faceIDs?
I have written previously, how patch faces labels can be determined.
Nevertheless, I assume that you access the patch already in your function in ControlDict and that you also iterate over the patch faces. Then you can try to do something like this
Code:
```forAll(mesh.boundary()[patch], facei)
{

const label& face = boundaryMesh[patch].start() + facei;
}

```