CFD Online Discussion Forums

CFD Online Discussion Forums (
-   OpenFOAM Pre-Processing (
-   -   Defining different "zones" in the same mesh (

Disco_Caine June 30, 2010 09:28

Defining different "zones" in the same mesh
Hello, I have a very simple wedge in which i would like to define 3 different conductivities. I could modify my case solver, but i dont know the command for it to check the x positions, i have something like this:

{ if (x>0.0105) {k[cellI]=1;}
if (x>0.0125) {k[cellI]=0;}

mind you, that is what i want to do. For that position in the x axis, change k (heat conductivity) for all the cells. IF it helps, or doesnt help, i have the regions clearly defined in the mesh (the boundary conditions are different for every zone).

Maybe with funkysetfields its easier?

Many thanks!


i tried doing this:

{ if (pos().x>0.0105 & pos().x<=0.0125) {k[cellI]=0.2;}
if (pos().x>0.0125) {k[cellI]=0.17;}

and im getting make error 1 when i try to compile the solver. Obviously, something is wrong with those lines. What could it be? I know i will keep hunting.

r08n June 30, 2010 09:46


Originally Posted by Disco_Caine (Post 265138)
{ if (x>0.0105) {k[cellI]=1;}
if (x>0.0125) {k[cellI]=0;}

I guess this should be like this (untested):

forAll (mesh.cellCentres(), cellI)
    if (mesh.cellCentres()[cellI].x() > 0.0105) k[cellI] = 1;
    // etc.


IF it helps, or doesnt help, i have the regions clearly defined in the mesh (the boundary conditions are different for every zone).
If k is defined as a field for which there are initial values, then it's clearly easier to use "setFields" (funky or not) and such.

Disco_Caine June 30, 2010 10:15

Well, with your code sintax it compiled. I will see if it did the trick and update the results briefly.

Disco_Caine July 2, 2010 09:59

I've managed to get a simulation running, however, i am now having a bit of trouble with the preprocessing part. I suppose i can keep this thread going rather than make a new one.

A small introduction:

As i said before, my mesh (an axisymmetric wedge) has 3 blocks. Now for 2 blocks i wanted to set different properties. And for the other block, i want to set different initial boundary conditions, and for that i am using funkySetFields (which is awesome by the way).

Ok, so my mesh is bi dimensional ( x and z) and this is what i wanna set up:

field T;
expression "52.96281*(pow(pos().z,0.262054))+273";
conditions "(pos().x < 0.0105)";
keepPatches 1;

It looks correct enough, the dimensions all match, the cell points make sense, etc. But its setting the field to the whole mesh, its clearly not following my condition (because, most likely, its written incorrectly). So i tried setting that field for that box, and then another field for the rest of the mesh, and it would just put this second field everywhere.

What am i doing wrong? Im really stuck on that.


Disco_Caine July 2, 2010 12:56

Ok, i am having serious problems defining anything for a given part of my mesh. And i believe its those pos().x conditions that are confusing me. Anyways, the situation right now is, in my solver i have this cell operation, but i wanna restrict to a particular set of cells. so i tried this (ill show the before and after):

bla bla bla

if (mesh.cellCentres()[cellI].x() < 0.0105)
bla bla bla;}

But now, its like my solver isnt doing anything. In paraFoam i can clearly see that x goes from 0 to 0.12, why doesnt it work? Any hints? Sintax issues?


Disco_Caine July 2, 2010 13:26

Update: the solver condition works! It was just a panic attack. Still no luck with funkySetFields, ill try setting the field in the solver.

Im sorry for the annoying number of posts, at least its only in this thread.

Linse September 24, 2010 05:27

convertToMeters set?
I do not know if that is the case here (and especially for funkySetFields), but:

If the different value goes everywhere within your domain, you should check if there is some measuring unit thingy in it.
E.g. I used blockMesh which usually uses meters as measuring unit. But it is also possible to use ¨convertToMeters¨, defining a conversion factor.

Point is: The conversion factor is used with blockMesh. But it is not used within setFields. So perhaps it is already the problem of one missing 0 (like 0.0105 instead of 0.00105) that could cause setFields being off-limits...

As I said: That was my experience with setFields, but perhaps it is the same for funkySetFields.

All times are GMT -4. The time now is 20:47.