InterFoam  setFields for a nonrectangular 3D domain
Hello All,
I have been working with OF1.5 and using interFoam. My domain is a cylindrical tube with the axis aligned with the gravity vector. The tube is closed at the bottom and I need to initialize the flowfield such that half of the tube is filled with liquid. When I run setfields, I can only prescribe dimensions of a box. I used dimensions for a box that would encapsulate the cylindrical region that I needed to initialize, but setFields does not work. Doesn't throw an exception either. Any ideas on how I can handle this problem is appreciated. Thanks. Aravind 
Hi!
I would use funkySetFields, with which you can set all kind of shape for fields using regular expressions. You need to install it separately, just follow the instructions in the previous link. If you want to set a cylinder you probably have to do something like the following (it's just a first guess!): Code:
funkySetFields field alpha1 expression 1 time 0 keepPatches condition "pow(pos().x,2) + pow(pos().y,2) < pow(0.1,2) && 0 < pos().z < 0.2"

Hi Gijsbert,
Thanks for your reply. I'll try this over the weekend and write back in the forum as to how it worked! Aravind 
Hi Gijsbert,
i am trying to simulate a round jet in a rectangular cartesian mesh for some validation study. I am using funkySetFields to set the alpha1 =1 in a round shape using your approach specified above. The command I use is :\ funkySetFields field alpha1 expression 1 time 0 keepPatches valuePatches "inletWall" condition "pow(pos().x2.1e3,2) + pow(pos().y2.1e3,2) < pow(0.1e3,2)" This command generates a circular inlet with alpha1 =1. But it also generates a alpha1=1 field in the z direction till the end of the domain.Where as I want the alpha1=1 only in one cell in the zdirection. Because it is my flow direction. So i tried your approach funkySetFields field alpha1 expression 1 time 0 valuePatches "inletWall" condition "pow(pos().x2.1e3,2) + pow(pos().y2.1e3,2) < pow(0.1e3,2) && 0<pos().z<2e3" But this gives a syntax error. could you please tell me where am I going wrong. regards K.Suresh kumar 
0<pos().z<2e3
This is not valid afaik. I think you should replace this with: (pos().z>0) && (pos().z<2e3) 
Hi Bernhard,
That correction solved my problem and that was exactly what I wanted to do. Thankyou very much for your prompt and accurate response. Now I want to set a parabolic velocity profile on that round inlet. Should I use funkysetFields or groovvyBc. To me it looks like funkySetFields is more appropriate. I will try using funkySetFields. If you have any experience on how to do this, any hints are welcome. Thanks and Happy holidays regards K.Suresh kumar 
Hi Suresh,
I think you should use groovvyBc to set up parabolic velocity profile at the inlet since it is the boundary condition which have to be used during your simulation. FunkysetFields is only for creating the initial field at 0 time step. Regards, Duong 
1 Attachment(s)
Hi Duong,
Thanks for your suggestion. I already looked for the groovyBC and it looks like a powerful tool to set inlet boundary coniditon. But I found that the groovyBC is used to set the boundary condition as parabolic or some condition on a complete patch. But in my case I want to set the parabolic velocity condition only on the round inlet(alpha=1) that I have defined on the inlet patch using funkysetfields. So the other part of my mesh other than the (alpha1=1) on the inlet patch should have a velocity of 0 (or wall) . Thanks for your help and any suggestions on how to set the parabolic inlet will be very helpful. I use interFoam for running the simulation regards K.Suresh kumar 
Hi Suresh,
I think what you can do might be like this: atmosphere { type groovyBC; valueExpression "(gamma+internalField(gamma))*0.5*normal()"; value uniform (0 0 0); } but instead of linear, make something like gamma*{your parabolic function}. Then when gamma = 0 > vel = 0 and gamma = 1: you have your parabolic velocity. You can find more detail in section 4.1.3 in http://openfoamwiki.net/index.php/Contrib_groovyBC Merry Christmas. Cheers, Duong 
Hi Duong,
Thankyou very much for your idea. I tried your approach. First I did a test with: My U file internalField uniform (0 0 0); boundaryField { inletWall { type groovyBC; valueExpression "(alpha1+internalField(alpha1))*0.5*normal()"; value uniform (0 0 20); timelines (); } atmosphere { type fixedValue; value uniform (0 0 0); } } here since my flow is in the +z direction. I specified 20 in the value uniform (0 0 20). I am not sure if this is where I have to define the velocity. It is still running. I will check after sometime. The second approach for setting a parabolic velocity. I did something like this. internalField uniform (0 0 0); boundaryField { inletWall { type groovyBC; variables "rpm=0.0;Un=20;c=vector(2.1e3,2.1e3,0);n=sum(normal())/mag(sum(normal()));p=pos()c;r=mag(p)+1.0e10;R=max(r);xt=vector(n.y,n.x,0);xT=xt/mag(xt);yt=vector(n.x*n.z,n.y*n.z,n.x*n.x+n.y*n.y);yT=yt/mag(yt);"; valueExpression "(alpha1+internalField(alpha1))*{Un*normal()*(1pow(r/R,2)) + (rpm*pi/30)*((p & yT)*xT  (p & xT)*yT)}"; value uniform (0 0 0); timelines (); } atmosphere { type fixedValue; value uniform (0 0 0); } } But his gives me an error, when I run the solver: > FOAM FATAL ERROR: The expected return type scalar is different from the stored result type "vector" From function tmp<Field<Type> > ExpressionResult::getResult() in file lnInclude/ExpressionResultI.H at line 76. FOAM aborting #0 Foam::error::printStack(Foam::Ostream&) in "/home/kumar/OpenFOAM/OpenFOAM1.6.x/lib/linux64GccDPOpt/libOpenFOAM.so" #1 Foam::error::abort() in "/home/kumar/OpenFOAM/OpenFOAM1.6.x/lib/linux64GccDPOpt/libOpenFOAM.so" #2 Foam::Field<double>* Foam::PatchValueExpressionDriver::getField<double> (Foam::string const&) in "/home/kumar/OpenFOAM/kumar1.6.x/lib/linux64GccDPOpt/libswak4FoamParsers.so" #3 parserPatch::PatchValueExpressionParser::parse() in "/home/kumar/OpenFOAM/kumar1.6.x/lib/linux64GccDPOpt/libswak4FoamParsers.so" #4 Foam::PatchValueExpressionDriver::parse(std::strin g const&) in "/home/kumar/OpenFOAM/kumar1.6.x/lib/linux64GccDPOpt/libswak4FoamParsers.so" #5 Foam::CommonValueExpressionDriver::evaluateVariabl e(Foam::word const&, Foam::string const&) in "/home/kumar/OpenFOAM/kumar1.6.x/lib/linux64GccDPOpt/libswak4FoamParsers.so" #6 Foam::CommonValueExpressionDriver::addVariables(Fo am::string const&, bool) in "/home/kumar/OpenFOAM/kumar1.6.x/lib/linux64GccDPOpt/libswak4FoamParsers.so" #7 Foam::groovyBCFvPatchField<Foam::Vector<double> >::updateCoeffs() in "/home/kumar/OpenFOAM/kumar1.6.x/lib/linux64GccDPOpt/libgroovyBC.so" Any suggestions on where I am wrong, will be very helpful. regards K.Suresh kumar 
Hi Duong,
The linear profile case is running correctly by using the format you told me. I checked some initial results, it seems to be ok. Now I will work on the parabolic velocity profile case and try to fix it. Thanks again for your explanation. bye regards K.Suresh kumar 
Hi Duong,
I tried different expressions for setting the parabolic velocity profile on the defined alpha1=1 inital field using groovyBC, but failed. The flat or uniform profile case is running properly. It will be really helpful, if you give me some idea on how to set the parabolic velocity function. bye regards K.Suresh kumar 
1 Attachment(s)
Hi Kumar,
I was on vacation so ... :D. But, here is my solution: inlet { type groovyBC; variables "yp=pos().y;zp=pos().z;quad=(pow((yp5e4)/1e4,2)+pow((zp5e4)/1e4,2))+1;"; valueExpression "alpha1*vector(1*quad,0,0)"; value uniform (1 0 0); } I made a simple parabolic velocity profile on the alpha1 area and tested it. You can take a look at the figure in the attachment. I think you can modify these things to get what you want. I am sorry that I did not have time to check your implementation. But just give it to try. Cheers, Duong 
Hi Duong,
Thankyou very much for your explanation. I have one more question. I am not exactly able to figure out your expression because I cannot see the coordinate system in the figure you have attached. It would be really helpful to set the same condition in my case if you give me some explanation on the variables you have used. like quad=(pow((yp5e4)/1e4,2)+pow((zp5e4)/1e4,2))+1 Since i am not that familiar with the syntax, sorry for the basic question. I am going to implement it straight away and check if it is working. Thanks for you reply. bye regards K.Suresh kumar 
Hi Kumar,
I make the inlet for a channel case 10x1x1mm. Therefore, the plane you see in the attachment is the inlet 1x1mm. What I did is set up a velocity profile based on the sphere with the center at (0,0.5,0.5)mm and radius of 0.1mm. The mathematical of my implementation is: quad = ((y5e4)/1e4)^2+((z5e4)/1e4)^2+1; U = alpha1*quad; I divide the term by 1e4 just to make it easier to demonstrate and also make the term ((y5e4)/1e4)^2+((z5e4)/1e4)^2 not so small comparing to 1. That's it. Hope it will help. Cheers, Duong 
Hello Duong,
I have succesfully generated the uniform profile and the parabolic profile using your instructions. Thanks for the clear explanations. goodluck bye regards K.Suresh kumar 
SetFields for a nonrectangular 3D domain
Hi every body
My domain is a cylindrical object in a bath of fluid and its axis aligned with the gravity vector. The bath is half full and the fluid is around the cylinder. Can any one help me with a code for FunkySetFiels? Thanks Mahyar 
For gods sake, write something more, describe what problem you have. How do you expect people to help you out without more details? It's like saying "I'm bleeding" without saying what happened and where.

2 Attachment(s)
Hi again
Sorry, I am new in openFOAm. As I told I have a solid cylinder in a middle of a rectangular bath of liquid. The liquid bath is half full and 3/4 of the cylinder's length is in the fluid of bath and rest of it is outside of it in the air so I have two fluid in the system, air and a liquid. Actually I have to move the cylinder with a constant velocity to study the behavior of the system and specially fluid. Now I want to define liquid as my second fluid in the system ( I set the first fluid as air), I was wondering how can I define liquid in my system. I saw a code foe the fluid in the cylinder in this page, but in my system the liquid is around the cylinder. I just do not know the code for this geometry in the funkySetFields and if I want to use ZoneToCell or regionToCell as an other option, I just do not know how to do that. I put a figure of the geometry. It is symmetrical and I try to simulate a quarter of it for saving time so I can define a quarter of the cylinder as a boundary which cause a curve wall in the left and I could not use BoxToCell option. I put a figure for this condition as well. I appreciate any help. mahyar 
I cannot help you directly since I've never run a case like yours, but I can direct you to the right sources.
First of all go over to interFoam solver examples; go to tutorials folder and study those cases. I believe there is a damBreak and one more case. I'm also sure if you search here for interFoam you will find plenty of different examples. In terms of rotational nature of you case I won't be much help to you. Nonetheless, I think you can assign velocity field to you fluid boundary  it's just an idea  this way you could define preassigned rotational field. Study always from very basic cases make sure you understand them then proceed to the case you are solving. I wish you good luck! K 
All times are GMT 4. The time now is 11:32. 