|
[Sponsors] |
March 9, 2013, 17:20 |
Non-uniform Boundary Conditions
|
#1 |
Member
Amir Abbas Aliabadi
Join Date: Mar 2013
Posts: 33
Rep Power: 13 |
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? |
|
March 12, 2013, 14:40 |
|
#2 |
New Member
SV
Join Date: May 2009
Posts: 15
Rep Power: 17 |
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! |
|
March 12, 2013, 15:47 |
|
#3 |
Member
Amir Abbas Aliabadi
Join Date: Mar 2013
Posts: 33
Rep Power: 13 |
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 |
|
March 12, 2013, 17:06 |
|
#4 |
New Member
SV
Join Date: May 2009
Posts: 15
Rep Power: 17 |
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.
|
|
March 12, 2013, 19:14 |
|
#5 |
Senior Member
Daniel P. Combest
Join Date: Mar 2009
Location: St. Louis, USA
Posts: 621
Rep Power: 0 |
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).
Last edited by chegdan; March 12, 2013 at 19:52. |
|
March 14, 2013, 18:27 |
|
#6 |
Member
Amir Abbas Aliabadi
Join Date: Mar 2013
Posts: 33
Rep Power: 13 |
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! |
|
January 30, 2014, 11:27 |
|
#7 |
Senior Member
Alejandro
Join Date: Jan 2014
Location: Argentina
Posts: 128
Rep Power: 12 |
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 |
|
January 30, 2014, 19:31 |
|
#8 |
Member
Amir Abbas Aliabadi
Join Date: Mar 2013
Posts: 33
Rep Power: 13 |
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 |
|
February 4, 2014, 13:21 |
|
#9 |
New Member
Join Date: Feb 2014
Posts: 12
Rep Power: 12 |
When you use this approach, should the boundary be specified as leftWindow or leftWindowBC in the blockMeshDict file?
Thanks! |
|
February 4, 2014, 17:59 |
|
#10 |
New Member
Join Date: Feb 2014
Posts: 12
Rep Power: 12 |
Also, to make the code run properly I believe there needs to be a ; after #} i.e.
#}; |
|
February 4, 2014, 19:52 |
|
#11 |
Member
Amir Abbas Aliabadi
Join Date: Mar 2013
Posts: 33
Rep Power: 13 |
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 |
|
March 19, 2014, 03:32 |
hi
|
#12 | |
New Member
lynzhung
Join Date: Feb 2014
Posts: 6
Rep Power: 12 |
Quote:
I am a new too and face the similar error as you .did you solve the problem ? Thanks Lyn |
||
March 19, 2014, 08:02 |
|
#13 | |
Senior Member
Alejandro
Join Date: Jan 2014
Location: Argentina
Posts: 128
Rep Power: 12 |
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; } } // ************************************************** *********************** // |
||
March 19, 2014, 22:53 |
|
#14 | |
New Member
lynzhung
Join Date: Feb 2014
Posts: 6
Rep Power: 12 |
Quote:
Maybe the trouble is not from the code .Anything else setting should I make ? Best wishes lyn |
||
June 6, 2014, 22:28 |
|
#15 |
Member
J.-H. Wang
Join Date: Oct 2010
Posts: 72
Rep Power: 16 |
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 { type codedFixedValue; value $internalField; redirectType inletBC; code #{ vector dir=vector(0,0,1); scalarField var=patch().Cf()&dir; scalarField value=var*10+10; operator==(value); #}; } 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" Creating new library in "dynamicCode/inletBC/platforms/linux64Gcc48DPOpt/lib/libinletBC_a19a66754309cd299efbab21ef5acdb0b4c99e71.so" Invoking "wmake -s libso /tmp/jhwang/1_cylinder_v10_D0.01_timeVaryBC/dynamicCode/inletBC" wmakeLnInclude: linking include files to ./lnInclude Making dependency list for source file fixedValueFvPatchFieldTemplate.C /tmp/jhwang/1_cylinder_v10_D0.01_timeVaryBC/0/U.boundaryField.inlet: In member function ‘virtual void Foam::inletBCFixedValueFvPatchVectorField::updateCoeffs()’: /tmp/jhwang/1_cylinder_v10_D0.01_timeVaryBC/0/U.boundaryField.inlet:31:19: error: no matching function for call to ‘Foam::inletBCFixedValueFvPatchVectorField::operator==(Foam::scalarField&)’ /tmp/jhwang/1_cylinder_v10_D0.01_timeVaryBC/0/U.boundaryField.inlet:31:19: note: candidates are: In file included from /home/jw969/OpenFOAM/OpenFOAM-2.3.0/src/finiteVolume/lnInclude/fvPatchField.H:588:0, from /home/jw969/OpenFOAM/OpenFOAM-2.3.0/src/finiteVolume/lnInclude/fixedValueFvPatchField.H:58, from /home/jw969/OpenFOAM/OpenFOAM-2.3.0/src/finiteVolume/lnInclude/fixedValueFvPatchFields.H:29, from fixedValueFvPatchFieldTemplate.H:38, from fixedValueFvPatchFieldTemplate.C:26: /home/jw969/OpenFOAM/OpenFOAM-2.3.0/src/finiteVolume/lnInclude/fvPatchField.C:558:6: note: void Foam::fvPatchField<Type>::operator==(const Foam::fvPatchField<Type>&) [with Type = Foam::Vector<double>] void Foam::fvPatchField<Type>::operator== ^ /home/jw969/OpenFOAM/OpenFOAM-2.3.0/src/finiteVolume/lnInclude/fvPatchField.C:558:6: note: no known conversion for argument 1 from ‘Foam::scalarField {aka Foam::Field<double>}’ to ‘const Foam::fvPatchField<Foam::Vector<double> >&’ /home/jw969/OpenFOAM/OpenFOAM-2.3.0/src/finiteVolume/lnInclude/fvPatchField.C:568:6: note: void Foam::fvPatchField<Type>::operator==(const Foam::Field<Type>&) [with Type = Foam::Vector<double>] void Foam::fvPatchField<Type>::operator== ^ /home/jw969/OpenFOAM/OpenFOAM-2.3.0/src/finiteVolume/lnInclude/fvPatchField.C:568:6: note: no known conversion for argument 1 from ‘Foam::scalarField {aka Foam::Field<double>}’ to ‘const Foam::Field<Foam::Vector<double> >&’ /home/jw969/OpenFOAM/OpenFOAM-2.3.0/src/finiteVolume/lnInclude/fvPatchField.C:578:6: note: void Foam::fvPatchField<Type>::operator==(const Type&) [with Type = Foam::Vector<double>] void Foam::fvPatchField<Type>::operator== ^ /home/jw969/OpenFOAM/OpenFOAM-2.3.0/src/finiteVolume/lnInclude/fvPatchField.C:578:6: note: no known conversion for argument 1 from ‘Foam::scalarField {aka Foam::Field<double>}’ to ‘const Foam::Vector<double>&’ make: *** [Make/linux64Gcc48DPOpt/fixedValueFvPatchFieldTemplate.o] Error 1 --> FOAM FATAL IO ERROR: Failed wmake "dynamicCode/inletBC/platforms/linux64Gcc48DPOpt/lib/libinletBC_a19a66754309cd299efbab21ef5acdb0b4c99e71.so" file: /tmp/jhwang/1_cylinder_v10_D0.01_timeVaryBC/0/U.boundaryField.inlet from line 19 to line 23. From function codedBase::createLibrary(..) in file db/dynamicLibrary/codedBase/codedBase.C at line 213. JHW |
|
June 6, 2014, 23:01 |
|
#16 |
New Member
Join Date: Feb 2014
Posts: 12
Rep Power: 12 |
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. |
|
June 7, 2014, 01:52 |
|
#17 | |
Member
J.-H. Wang
Join Date: Oct 2010
Posts: 72
Rep Power: 16 |
Quote:
JHW |
||
June 7, 2014, 02:05 |
|
#18 |
New Member
Join Date: Feb 2014
Posts: 12
Rep Power: 12 |
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.
|
|
June 7, 2014, 10:58 |
|
#19 |
Member
J.-H. Wang
Join Date: Oct 2010
Posts: 72
Rep Power: 16 |
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 |
|
June 7, 2014, 12:37 |
|
#20 |
New Member
Join Date: Feb 2014
Posts: 12
Rep Power: 12 |
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 |
|
Tags |
non-uniform bc |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
How to set uniform heating boundary condition? | Sargam05 | OpenFOAM | 0 | September 11, 2012 11:09 |
Need help with boundary conditions: open to atmosphere | Wolle | OpenFOAM | 2 | April 11, 2011 08:32 |
Pressure instability with rhoSimpleFoam | daniel_mills | OpenFOAM Running, Solving & CFD | 44 | February 17, 2011 18:08 |
Boundary condition setting for non-premixed combustion using reactingFoam | skyopener | OpenFOAM | 0 | May 23, 2010 23:55 |
A problem about setting boundary conditions | lyang | Main CFD Forum | 0 | September 19, 1999 19:29 |