Non-uniform Boundary Conditions
Hello There,
I am new to OpenFoam, modelling natural air convection in an enclosed box. A few walls in my boundaries have non-uniform temperatures. I like to impose a boundary condition with a temperature profile as a function of height on my walls (e.g. T=2*z+298 [K]). How do I changed the T boundary condition file for this purpose? Do I need to add any other files in any directories that this problem is set up? |
AAA,
If you are using OF 2.0+, take a look at codedFixedValue BC. If you are using older versions, or want more flexibility, search for swak4Foam. Good luck and Tarif kon! |
Thank You Soheil,
I found many such header and C files codedFixedValue*.* under openfoam sub directories. Can you recommend which files, exactly, have to be modified? and do you have an example code that modifies fixed value boundary conditions? Thanks, aaa |
You only need to modify your BC files, i.e. 0/T. Take a look at tutorials/incompressible/simpleFoam/pipeCyclic/0.org/U to get an idea, and also search for codedFixedValue in this forum. It is not the most user-friendly syntax, but you should be able to get it working.
|
As another suggestion, maybe you would want to look into the utility funkSetBoundaryField or groovyBC that is part of the tool set "swiss army knife for foam" (a.k.a. swak4Foam).
|
Hello FOAMers,
After much investigation, I was finally able to implement codedFixedValue boundary condition for my problem. I decided to provide a "how to" instruction so others can benefit from my experience. Such examples are lacking in the OpenFOAM documentation as well as online forums, so hopefully more complete examples will emerge. The most recent versions of OpenFOAM (2.x.x and later) are able to construct, on-the-fly, new boundary conditions (e.g. codedFixedValueFvPatchField which is derived from fixedValueFvPatchField). This is very useful since you only need to make changes to your boundary condition file (e.g. 0/T for temperature). This saves some trouble so you don't have to install third party packages like Swak4Foam or GroovyBC which at times are incompatible with your version of OpenFOAM. Step 1: codedFixedValue boundary condition method attempts to load a shared library using case-supplied C++ code, so you need to allow your FOAM to execute user written code. You should switch "allowSystemOperations" in .../etc/controlDict from "0" to "1". So edit controlDict before proceeding to the next step. (e.g. sudo gedit /opt/openfoam211/etc/controlDict if OpenFOAM is installed under root directory) Step 2: modify the boundary condition file (e.g. 0/T for temperature) and supply as many patches with source code as you need. An example is provided below: FoamFile { version 2.0; format ascii; class volScalarField; location "0"; object T; } dimensions [0 0 0 1 0 0 0]; internalField uniform 253; boundaryField { leftWindow { type codedFixedValue; value $internalField; redirectType leftWindowBC; code #{ vector dir=vector(0,0,1); scalarField var=patch().Cf()&dir; scalarField value=var*40+245; operator==(value); #} } rightWindow { type codedFixedValue; value $internalField; redirectType rightWindowBC; code #{ vector dir=vector(0,0,1); scalarField var=patch().Cf()&dir; scalarField value=var*40+250; operator==(value); #} } insulation { type zeroGradient; } } In the above example the temperature profiles on vertical windows are evaluated as T=40z+245 [K] for left window and T=40z+250 [K] on right window. "type codedFixedValue" is essential to define so the compiler understands what to do with the code. "value $internalField" deserves a little explanation. Although you are calculating the boundary value using the code, you need this specified so the compiler at least has a starting value to work with (e.g. when plotting boundary values using paraView at time 0). In this case the "uniform 253" value is substituted for the very start. But for later times the code is used to evaluate the boundary. "redirectType leftWindowBC" assigns a name for this boundary patch. It is absolutely critical you use a different name for each new boundary patch definition. The "code #{ ... #}" part is just C++ language and you have to make sure the code is consistent with the libraries you want to load it on. Take a look at examples elsewhere or the libraries themselves to ensure your code is compatible. Step 3: call your desired solver in the case directory (e.g. buoyantBoussinesqPimpleFoam). The solver automatically compiles coded boundaries and creates a folder called "dynamicCode". If you examine the contents, you see for each boundary patch that you defined, there is a folder with the same assigned name and all the required *.C, *.H, and other files necessary. If your custom code is not consistent with the OpenFOAM libraries, then you get an error message why. Then the solver iterations automatically begin. Note: it is absolutely important that you are comfortable with coding a patch that the OpenFOAM libraries understand. Otherwise you are in trouble! Good Luck and thanks to everyone who contributed to this post! |
Sorry. I am new in openFoam. Your example is not working for mi. I have obtained the following error: FOAM FATAL IO ERROR: Cannot find patchField entry for...
Could you please post your entire code?. Thank you very much |
Hi Ancolli,
It has been a long time since I used OpenFOAM and I do not have it on my current system to provide the entire case directory. I suggest you follow my previous instructions carefully, especially the beginning 2 steps. Also make sure your version of OpenFOAM supports codedFixedValue boundary conditions. I hope this helps! aaa |
When you use this approach, should the boundary be specified as leftWindow or leftWindowBC in the blockMeshDict file?
Thanks! |
Also, to make the code run properly I believe there needs to be a ; after #} i.e.
#}; |
Hello,
As far as I remember both leftWindow or leftWindowBC are just names and not C++ programming syntax, so as long as you are consistent to use the same name in the linked files you should be fine. As far as syntax, be my guest, it has been a long time since I did any C++ programming Cheers aaa |
hi
Quote:
I am a new too and face the similar error as you .did you solve the problem ? Thanks Lyn |
Quote:
FoamFile { version 2.0; format ascii; class volScalarField; location "0"; //nuevo// object T; } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // dimensions [0 0 0 1 0 0 0]; internalField uniform 253; boundaryField { inlet { type fixedValue; value uniform 253; } outlet { type zeroGradient; } upperWall { type zeroGradient; } lowerWall { type codedFixedValue; value $internalField; redirectType lowerWallBC; code #{ vector dir=vector(1,0,0); scalarField var=patch().Cf()&dir; scalarField value=var*40+250; operator==(value); #} } frontAndBack { type empty; } } // ************************************************** *********************** // |
Quote:
Maybe the trouble is not from the code .Anything else setting should I make ? Best wishes lyn |
Hello all,
I am running icoFoam on flow over cylinder at Re=120 case and am expecting Karman vortex street. I need a inlet velocity perturbation of any kind to trigger the onset of this shedding event. OpenFOAM 2.3 is used. I've been trying to implement the linear profile on my inlet velocity boundary conditions but so far no luck. I simply followed the steps and change the initial 0/U file to: Code:
inlet Code:
Using dynamicCode for patch inlet on field U at line 19 in "/tmp/jhwang/1_cylinder_v10_D0.01_timeVaryBC/0/U.boundaryField.inlet" JHW |
I think your problem is at var*10+10
You are trying to add one double to a field. I would try generating a scalarField of the same size as var where every element is 10 then adding it to var. If you're not sure how to initialize a new scalarField you can just always just make one by copying var again like scalarField var2 = var; then do int num = var2.size() and loop over the elements of var2 making each one of them 10. I'm fairly certain this is not the best way to do this but it will work. |
Quote:
JHW |
I re-read your post and if I understand correctly this is a velocity boundary condition so operator needs to be set equal to a 3 component vectorField rather than a scalarField.
|
Hi ajnewman,
Thanks a lot for the reply. I think that is very much the problem. Can you be so kind and point me to some documentation I can read in order to understand how to write a velocity boundary condition to a patch? Or where is the class vectorField defined? I am new to OpenFOAM and rusty on C++. Thanks Sincerely, JHW |
Assuming that the x_3 component is the one you wish to specify do something like
operator == (vector(0,0,1)*10 + vector(0,0,10)); You may also want to look at http://www.cfd-online.com/Forums/ope...onditions.html |
All times are GMT -4. The time now is 20:47. |