CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Pre-Processing

Non-uniform Boundary Conditions

Register Blogs Community New Posts Updated Threads Search

Like Tree21Likes

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   March 9, 2013, 17:20
Default Non-uniform Boundary Conditions
  #1
Member
 
Amir Abbas Aliabadi
Join Date: Mar 2013
Posts: 33
Rep Power: 13
amir.a.aliabadi is on a distinguished road
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?
amir.a.aliabadi is offline   Reply With Quote

Old   March 12, 2013, 14:40
Default
  #2
New Member
 
SV
Join Date: May 2009
Posts: 15
Rep Power: 17
Soheyl is on a distinguished road
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!
Soheyl is offline   Reply With Quote

Old   March 12, 2013, 15:47
Default
  #3
Member
 
Amir Abbas Aliabadi
Join Date: Mar 2013
Posts: 33
Rep Power: 13
amir.a.aliabadi is on a distinguished road
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
amir.a.aliabadi is offline   Reply With Quote

Old   March 12, 2013, 17:06
Default
  #4
New Member
 
SV
Join Date: May 2009
Posts: 15
Rep Power: 17
Soheyl is on a distinguished road
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.
Soheyl is offline   Reply With Quote

Old   March 12, 2013, 19:14
Default
  #5
Senior Member
 
Daniel P. Combest
Join Date: Mar 2009
Location: St. Louis, USA
Posts: 621
Rep Power: 0
chegdan will become famous soon enoughchegdan will become famous soon enough
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.
chegdan is offline   Reply With Quote

Old   March 14, 2013, 18:27
Default
  #6
Member
 
Amir Abbas Aliabadi
Join Date: Mar 2013
Posts: 33
Rep Power: 13
amir.a.aliabadi is on a distinguished road
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!
amir.a.aliabadi is offline   Reply With Quote

Old   January 30, 2014, 11:27
Default
  #7
Senior Member
 
Alejandro
Join Date: Jan 2014
Location: Argentina
Posts: 128
Rep Power: 12
ancolli is on a distinguished road
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
ancolli is offline   Reply With Quote

Old   January 30, 2014, 19:31
Default
  #8
Member
 
Amir Abbas Aliabadi
Join Date: Mar 2013
Posts: 33
Rep Power: 13
amir.a.aliabadi is on a distinguished road
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
amir.a.aliabadi is offline   Reply With Quote

Old   February 4, 2014, 13:21
Default
  #9
New Member
 
Join Date: Feb 2014
Posts: 12
Rep Power: 12
ajnewman is on a distinguished road
When you use this approach, should the boundary be specified as leftWindow or leftWindowBC in the blockMeshDict file?

Thanks!
ajnewman is offline   Reply With Quote

Old   February 4, 2014, 17:59
Default
  #10
New Member
 
Join Date: Feb 2014
Posts: 12
Rep Power: 12
ajnewman is on a distinguished road
Also, to make the code run properly I believe there needs to be a ; after #} i.e.
#};
ajnewman is offline   Reply With Quote

Old   February 4, 2014, 19:52
Default
  #11
Member
 
Amir Abbas Aliabadi
Join Date: Mar 2013
Posts: 33
Rep Power: 13
amir.a.aliabadi is on a distinguished road
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
amir.a.aliabadi is offline   Reply With Quote

Old   March 19, 2014, 03:32
Default hi
  #12
New Member
 
lynzhung
Join Date: Feb 2014
Posts: 6
Rep Power: 12
lynzhung is on a distinguished road
Quote:
Originally Posted by ancolli View 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

I am a new too and face the similar error as you .did you solve the problem ?

Thanks
Lyn
lynzhung is offline   Reply With Quote

Old   March 19, 2014, 08:02
Default
  #13
Senior Member
 
Alejandro
Join Date: Jan 2014
Location: Argentina
Posts: 128
Rep Power: 12
ancolli is on a distinguished road
Quote:
Originally Posted by lynzhung View Post
I am a new too and face the similar error as you .did you solve the problem ?

Thanks
Lyn
yes, but I do not remember. Searching on my folder I have found a slightly different problem. With only one boundary condition with variable Temperature. It works!.

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;
}
}

// ************************************************** *********************** //
ancolli is offline   Reply With Quote

Old   March 19, 2014, 22:53
Default
  #14
New Member
 
lynzhung
Join Date: Feb 2014
Posts: 6
Rep Power: 12
lynzhung is on a distinguished road
Quote:
Originally Posted by ancolli View Post
yes, but I do not remember. Searching on my folder I have found a slightly different problem. With only one boundary condition with variable Temperature. It works!.

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;
}
}

// ************************************************** *********************** //
Thank you for your replying .I can not find any different between your code and mine.And it does not work.
Maybe the trouble is not from the code .Anything else setting should I make ?

Best wishes
lyn
lynzhung is offline   Reply With Quote

Old   June 6, 2014, 22:28
Default
  #15
Member
 
J.-H. Wang
Join Date: Oct 2010
Posts: 72
Rep Power: 16
f0208secretx is on a distinguished road
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);
           #}; 
   }
During decomposePar I got the following error:
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.
Does this technique work in OF 2.3? Any idea on the problem? Thanks for any advise.


JHW
f0208secretx is offline   Reply With Quote

Old   June 6, 2014, 23:01
Default
  #16
New Member
 
Join Date: Feb 2014
Posts: 12
Rep Power: 12
ajnewman is on a distinguished road
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.
ajnewman is offline   Reply With Quote

Old   June 7, 2014, 01:52
Default
  #17
Member
 
J.-H. Wang
Join Date: Oct 2010
Posts: 72
Rep Power: 16
f0208secretx is on a distinguished road
Quote:
Originally Posted by ajnewman View Post
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.
I simply tried to remove the +10 part but it still doesn't work. Thanks for the answer but its probably not the problem.

JHW
f0208secretx is offline   Reply With Quote

Old   June 7, 2014, 02:05
Default
  #18
New Member
 
Join Date: Feb 2014
Posts: 12
Rep Power: 12
ajnewman is on a distinguished road
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.
f0208secretx likes this.
ajnewman is offline   Reply With Quote

Old   June 7, 2014, 10:58
Default
  #19
Member
 
J.-H. Wang
Join Date: Oct 2010
Posts: 72
Rep Power: 16
f0208secretx is on a distinguished road
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
f0208secretx is offline   Reply With Quote

Old   June 7, 2014, 12:37
Default
  #20
New Member
 
Join Date: Feb 2014
Posts: 12
Rep Power: 12
ajnewman is on a distinguished road
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
ajnewman is offline   Reply With Quote

Reply

Tags
non-uniform bc


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


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


All times are GMT -4. The time now is 15:40.