CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Running, Solving & CFD

Specifying nonuniform boundary condition

Register Blogs Community New Posts Updated Threads Search

Like Tree40Likes

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   September 14, 2005, 12:22
Default What is the format of the file
  #1
Senior Member
 
Maka Mohu
Join Date: Mar 2009
Posts: 305
Rep Power: 18
maka is on a distinguished road
What is the format of the file in which I can specify nonuniform boundary conditions? can any body give a sample?

Thanks,
Maka
Prosper likes this.
maka is offline   Reply With Quote

Old   September 14, 2005, 12:26
Default // Get index of patch lab
  #2
chen_jun
Guest
 
Posts: n/a
// Get index of patch
label inletPatchID = mesh.boundaryMesh().findPatchID("topMovingWall");

// Get reference to boundary value
const fvPatchVectorField& faceCentreshub = mesh.Cf().boundaryField()[inletPatchID];
fvPatchVectorField& movingWallU = U.boundaryField()[inletPatchID];

// loop over all hub faces
forAll(movingWallU, faceI)
{
// get coordinate for face centre
const vector& c = faceCentreshub[faceI];
vector p(0.5*(1+Foam::sin(40*M_PI*c[0]-M_PI/2)), 0, 0);
if (c[0]>0.025 &c[0]<0.075)
p = vector(1, 0, 0);

movingWallU[faceI] = p;
}
  Reply With Quote

Old   September 14, 2005, 13:01
Default Hi Chen Jun I am interest
  #3
ami
Guest
 
Posts: n/a
Hi Chen Jun

I am interested in considering nonuniform boundary conditions in my computations (e.g., a laminar Blasius boundary layer inflow condition along the free stream flow condition). Please can you specify the file name you described and how to use it?

thanks
  Reply With Quote

Old   September 15, 2005, 04:07
Default This thread actually belongs i
  #4
Senior Member
 
Håkan Nilsson
Join Date: Mar 2009
Location: Gothenburg, Sweden
Posts: 205
Rep Power: 18
hani is on a distinguished road
This thread actually belongs in preprocessing. Anyway, Chen actually describes the basics of how to set your boundary conditions. It is however a bit difficult to understand for a beginner. Let me, as a slightly more than beginner try to help you in a more detailed way (there might be other solutions also):

It is unlikely that there is such a boundary condition already implemented and distributed in OpenFoam. You will have to implement it yourself. This goes at least for less common bc's.

A suggestion on how to implement the steady bc (reads 0 and overwrites 0):

Step 1:
Copy the source directory of the particular solver that you want to use to your personal applications directory. For instance:
mkdir ~/OpenFOAM/hani-1.2/applications (if you don't have it)
cp -r OpenFOAM/OpenFOAM-1.2/applications/solvers/incompressible/simpleFoam ~/OpenFOAM/hani-1.2/applications/

Step 2:
Rename your copied directory to something that makes sence, for instance:
mv ~/OpenFOAM/hani-1.2/applications/simpleFoam ~/OpenFOAM/hani-1.2/applications/blasiusBC
Rename the .C-file in your blasiusBC directory to blasiusBC.C
Edit blasiusBC.C: Insert correct descriptions for Application and Description in the header of the file, for clarity. Remove everything in the main function except the include statements in the beginning. You may later on check which ones you actually need by commenting them and try to compile. The compiler error messages will guide you.

Step 3:
Implement your bc's using the directives that Chen gave you. This should be located after the include statements in the main function.
Write out the variables you have changed at the end of the main function:
// Force the write
U.write();
k.write();
epsilon.write();
phi.write();

Info<< "\n ExecutionTime = "
<< runTime.elapsedCpuTime()
<< " s\n" << endl;

Info<< "End" << endl;

return(0);

Step 4:
Edit blasiusBC/Make/files to make sure that the filenames blasiusBC is used instead of the name of the original application.

Step 5:
Compile.
Move to your blasiusBC directory and type
wmake

Step 6:
type:
rehash
to make the executable available.

Step 7:
Set your bc's by typing:
blasiusBC <root> <case>
which will change the files in your <root>/<case>/0 directory to include the bc's you defined in blasiusBC.

Step 8:
Run your case using the solver you need for the application. It will read the 0 directory and get the correct bc's.

Good luck!
Håkan.
hani is offline   Reply With Quote

Old   September 16, 2005, 08:37
Default Thanks all. Many thanks Hakan
  #5
Senior Member
 
Maka Mohu
Join Date: Mar 2009
Posts: 305
Rep Power: 18
maka is on a distinguished road
Thanks all. Many thanks Hakan for the detailed steps. It is very helpful.

Regards,
Maka
maka is offline   Reply With Quote

Old   September 16, 2005, 11:08
Default Thanks Hakan for the detailed
  #6
ami
Guest
 
Posts: n/a
Thanks Hakan for the detailed explications.
  Reply With Quote

Old   October 13, 2005, 12:44
Default Francois I'll have a go at
  #7
New Member
 
Hilary Spencer
Join Date: Mar 2009
Location: Reading, Berkshire, UK
Posts: 1
Rep Power: 0
hilaryspencer is on a distinguished road
Francois

I'll have a go at answering _some_ of your questions.

> Here are my questions:
>
> * is c[1] is the second component of the vector c on faceI ?

Yes! C and C++ arrays start at zero and (in OpenFOAM) go to size()-1

> * What are the differences between those two objects and two methods
> (C() and Cf()) of the mesh class:

In fvMesh.H it says:
//- Return cell centres as volVectorField
const volVectorField& C() const;

//- Return face centres as surfaceVectorField
const surfaceVectorField& Cf() const;

> * Finaly if I want to read an experimental profile of the x component
> of the velocity Ux=f(y) which is in a file and interpolate those
> values on the mesh to apply them on the x component of my inlet
> boundary velocity field. Is it easy or not ?

This may not be the easiest or most accurate solution -
you could create a 1d mesh with cell centres at the locations of your experimental profile. The Ux data could then be the experimental data

you could then create another case with a 1d mesh the same as your boundary of your (2d?) case
you could then use mapFields to interpolate from the first mesh to the second

then copy the interpolated data to the boundary condition of your 2d case (assuming the mesh is numbered in the same way for both - you'll have to make sure of this when you generate the 1d mesh)

> PS: more a C++ question, please don't laugh !!!
> Why is there sometimes an & (like after VectorField) and sometimes
> not (like scalarField)

Now this is a REALLY good question. One it took me AGES to understand
when there is an & after a name of a class it means that you are not creating a new one, you are just referring to one that all ready exists. It is therefore a reference

Example
int i = 0;
int& j = i; // j refers to i. No new data is created
j = 2; // actually sets i = 2 also
nishant.kumar likes this.
hilaryspencer is offline   Reply With Quote

Old   October 13, 2005, 12:58
Default Tanks Hilary for your help wit
  #8
Senior Member
 
Francois Beaubert
Join Date: Mar 2009
Location: Lille, France
Posts: 147
Rep Power: 17
francois is on a distinguished road
Tanks Hilary for your help with OpenFOAM and C++ !

I will study this problem carefully ... it's like an adventure for me ...

Have a nice day.
Francois
francois is offline   Reply With Quote

Old   December 13, 2005, 15:28
Default Hello! I'm trying to implemen
  #9
New Member
 
Aurelia Cure
Join Date: Mar 2009
Location: Lund, Sweden
Posts: 18
Rep Power: 17
aurelia is on a distinguished road
Hello!
I'm trying to implement non uniform bc at the inlet, following the step by step method of Håkan (thank you, by the way )
i compile with wmake, it seems to work
then the command rehash doesn't exist
and finaly, when i do step7, it doesn't change the values in the 0 directory
i suppose it's due to many mistake in c++
so i will be happy if one of you could take time to help me and check it

here is what i wrote in the main of the .c file, after all the include

/ Get index of patch
label inletPatchID = mesh.boundaryMesh().findPatchID("inlet");

// Get reference to boundary value
fvPatchVectorField& inletU = U.boundaryField()[inletPatchID];

// get coordinate for cell centre
const fvPatchVectorField& centre = mesh.C().boundaryField()[inletPatchID];
scalarField y = centre.component(vector::Y);
scalarField x = centre.component(vector::X);

// calculate inlet velocity
inletU = y*0.75/0.0051*vector (1,0,0)+x*0.75/0.0051*vector(0,1,0)+7.5*vector(0,0,1);

U.write();

Info<< "ExecutionTime = "
<< runTime.elapsedCpuTime()
<< " s\n\n" << endl;


Info<< "End\n" << endl;

return(0);
}


thanks
aurelia
aurelia is offline   Reply With Quote

Old   December 14, 2005, 05:22
Default In the statements: // calcu
  #10
Senior Member
 
Hrvoje Jasak
Join Date: Mar 2009
Location: London, England
Posts: 1,907
Rep Power: 33
hjasak will become famous soon enough
In the statements:

// calculate inlet velocity
inletU = y*0.75/0.0051*vector (1,0,0)+x*0.75/0.0051*vector(0,1,0)+7.5*vector(0,0,1);

try doing

inletU == ...; (the rest is the same).

I suspect your boundary condition for this patch is fixedValue.

Hrv
mm.abdollahzadeh likes this.
__________________
Hrvoje Jasak
Providing commercial FOAM/OpenFOAM and CFD Consulting: http://wikki.co.uk
hjasak is offline   Reply With Quote

Old   December 17, 2005, 14:59
Default Can we get a tutorial out of t
  #11
unoder
Guest
 
Posts: n/a
Can we get a tutorial out of this? I'm also new to both Foam and C++ and interested in learning...
  Reply With Quote

Old   January 4, 2006, 10:52
Default Hi, I tried to implement th
  #12
Senior Member
 
Fabian Braennstroem
Join Date: Mar 2009
Posts: 407
Rep Power: 19
braennstroem is on a distinguished road
Hi,

I tried to implement the version from aurelia. The compilation went fine, but applying the profile to an existing case in turbFoam I get:

...
Reading field U



--> FOAM FATAL IO ERROR : size 3 is not equal to the given value of 2438

file: turbFoam/smc/0/U::INLET from line 36 to line 42.

From function Field<type>::Field(const word& keyword, const dictionary& dict , const label s)
in file /home/fab/OpenFOAM/OpenFOAM-1.2/src/OpenFOAM/lnInclude/Field.C at li ne 225.

FOAM exiting



I adjusted 'inletPatchID' to the existing 'INLET' in my case. Would be nice, if anybody has an idea!

Greetings!
Fabian
braennstroem is offline   Reply With Quote

Old   May 3, 2008, 11:31
Default Some time ago already, however
  #13
Senior Member
 
Mark Couwenberg
Join Date: Mar 2009
Location: Netherlands
Posts: 130
Rep Power: 17
markc is on a distinguished road
Some time ago already, however I am experiencing the same problem. The error from Fabian is however caused by the fact that (probably) the 0/U file has non-uniform and three lines of vectors in it already, while the field is supposed to have 2438 faces and thus 2438 entries.
I think you have to include initContinuityErrs.H
However, even after this I am still not able to get things work. Changes are made to the internalFieldValues but not to boundary patches.

Any comments?
Once I succeed I will return with results.

Brgds,

Mark
markc is offline   Reply With Quote

Old   May 3, 2008, 14:18
Default Ok, I finally get it working.
  #14
Senior Member
 
Mark Couwenberg
Join Date: Mar 2009
Location: Netherlands
Posts: 130
Rep Power: 17
markc is on a distinguished road
Ok, I finally get it working. A small utility that is able to set nonuniform boundary conditions. For my case it is programmed to set gamma at 1 if Z coordinate is <0>0. However, users will be able to modify themselve.
The code is based on snippets found on this forum and very much resembles snippets in this thread. however 1 to 1 copying failed in my case. So here the full directory. hope it is useful for others.

attach{setBoundarygamma}

Brgds,

Mark
Mehdi3031 likes this.
markc is offline   Reply With Quote

Old   May 3, 2008, 14:19
Default Lets try WITH attachment this
  #15
Senior Member
 
Mark Couwenberg
Join Date: Mar 2009
Location: Netherlands
Posts: 130
Rep Power: 17
markc is on a distinguished road
Lets try WITH attachment this time
setBoundarygamma.zip
vsammartano and Mehdi3031 like this.
markc is offline   Reply With Quote

Old   October 11, 2008, 09:45
Default Hi guys, I'm trying to crea
  #16
New Member
 
Ravi Ramalho
Join Date: Mar 2009
Location: Recife, PE, Brazil
Posts: 5
Rep Power: 17
rres is on a distinguished road
Hi guys,

I'm trying to create a custom bc as told here, but I'm stuck. I want to set the values of U, k and epsilon at the inlet, but when I try to compile, it throws the folowing errors:
Quote:

'k' was not declared in this scope
'epsilon' was not declared in this scope
'faceCentreshub' was not declared in this scope
I don't know what libraries are required. I've searched the manuals, internet, forums and nothing. For God's sake, someone help me! It's driving me crazy!!!

Ravi
rres is offline   Reply With Quote

Old   October 11, 2008, 10:12
Default Hi, The kEpsilon.H has the
  #17
New Member
 
Ravi Ramalho
Join Date: Mar 2009
Location: Recife, PE, Brazil
Posts: 5
Rep Power: 17
rres is on a distinguished road
Hi,

The kEpsilon.H has the following declarations:

//- Return the turbulence kinetic energy
tmp<volscalarfield> k() const
//- Return the turbulence kinetic energy dissipation rate
tmp<volscalarfield> epsilon() const


But it seems that refers to cell volume values. I need the face values. Searching in the files (solvers) I found something like that: fvVectorMatrix divR = turbulence->divDevReff(U);
and I think that what I'm looking for is something like this.

Ravi
rres is offline   Reply With Quote

Old   October 14, 2008, 02:58
Default Hi Ravi, If you'll attach the
  #18
Senior Member
 
dmoroian's Avatar
 
Dragos
Join Date: Mar 2009
Posts: 648
Rep Power: 20
dmoroian is on a distinguished road
Hi Ravi,
If you'll attach the sources to your post, maybe someone will have a look at it, otherwise we can at most speculate the source of your error.

Dragos
dmoroian is offline   Reply With Quote

Old   November 13, 2008, 07:43
Default dear all, I have a simple g
  #19
New Member
 
Sebastian Schoeller
Join Date: Mar 2009
Posts: 1
Rep Power: 0
schoeller is on a distinguished road
dear all,

I have a simple geometry, which I model as a 2-phase liquid flow with interFoam solver. So far I have set boundary conditions manually using a text editor but it's just easier to have a function via command line at hand in order to do so.

Thus I followed the thread by on setBoundaryGamma and worked myself through it:

1. Using the instructions by Håkan Nilsson I copied the interFoam directory, renamed the files and applied my changes
2. Everything compiles with wmake
3. While executing setBoundaryGamma <patchname> from the project directory I receive the following error:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#0 Foam::error::printStack(Foam:stream&) in "/home/schoeller/OpenFOAM/OpenFOAM-1.5/lib/linuxGccDPOpt/libOpenFOAM.so"
#1 Foam::sigSegv::sigSegvHandler(int) in "/home/schoeller/OpenFOAM/OpenFOAM-1.5/lib/linuxGccDPOpt/libOpenFOAM.so"
#2 Uninterpreted: [0xb809b400]
#3 std::basic_string<char,>, std::allocator<char> >::basic_string(std::string const&) in "/home/schoeller/OpenFOAM/ThirdParty/gcc-4.3.1/platforms/linux/lib/libstdc++.so. 6"
#4 main in "/home/schoeller/OpenFOAM/OpenFOAM-1.5/applications/bin/linuxGccDPOpt/setBoundar yGamma"
#5 __libc_start_main in "/lib/tls/i686/cmov/libc.so.6"
#6 _start in "/home/schoeller/OpenFOAM/OpenFOAM-1.5/applications/bin/linuxGccDPOpt/setBoundar yGamma"
Segmentation fault

Does anybody have an idea why this could be?

* interFoam as a solver works fine with the case
* 'which gcc' tells me that it is using the compiler version from ThirdParty directory

The source code I used is as follows:

\*---------------------------------------------------------------------------*/
#include "fvCFD.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
int main(int argc, char *argv[])
{
argList::validArgs.append("patchName");
# include "setRootCase.H"
word patchName(args.args()[3]);
# include "createTime.H"
# include "createMesh.H"
# include "createFields.H"
# include "initContinuityErrs.H"

Info<< "This utility initializes gamma values for boundary patches based on" <<endl;
Info<<>=0 ==>gamma=0, z<o>gamma=1." <<endl;
Info<< "These settings are presently only changeable by modifying the source code." <<endl;
Info<< "Source code to be found in: OF/user/applications." <<endl;
Info<< "Change code (.C file) according your needs and in that directory run wmake." <<endl;
Info<< "\nStarting time loop\n" << endl;

// Get index of patch
label inletPatchID = mesh.boundaryMesh().findPatchID(patchName);
// Get reference to boundary value
//const fvPatchVectorField& centre = mesh.C().boundaryField()[inletPatchID];
const fvPatchVectorField& faceCentreshub = mesh.C().boundaryField()[inletPatchID];
//const fvPatchVectorField& faceCentreshub = mesh.Cf().boundaryField()[inletPatchID];
//Uncomment the line for your case: U for velocity cases, gamma for gamma cases
//fvPatchVectorField& Inlet = U.boundaryField()[inletPatchID];
fvPatchScalarField& targetPatch = gamma.boundaryField()[inletPatchID];
// loop over all hub faces
forAll(targetPatch, faceI)
{
// get coordinate for face centre
//const vector& c = centre[faceI];
const vector& c = faceCentreshub[faceI];
//vector p(0.5*(1+Foam::sin(40*M_PI*c[0]-M_PI/2)), 0, 0);
// c[0] is X coordinate, c[1] is Y coordinate, c[2] is Z coordinate
// Apply boundary condition based in one coordinate (X, Y, or Z).
if (c[1] < 0.3)
//if true: below watersurface
// loop over all hub faces
forAll(targetPatch, faceI)
{
// get coordinate for face centre
//const vector& c = centre[faceI];
const vector& c = faceCentreshub[faceI];
//vector p(0.5*(1+Foam::sin(40*M_PI*c[0]-M_PI/2)), 0, 0);
// c[0] is X coordinate, c[1] is Y coordinate, c[2] is Z coordinate
// Apply boundary condition based in one coordinate (X, Y, or Z).
if (c[1] < 0.3)
//if true: below watersurface
{
targetPatch[faceI] = scalar (1);
//Inlet[faceI] = vector (1, 0, 0);
}
//if false: at or above watersurface
else
{
targetPatch[faceI] = scalar (0);
//Inlet[faceI] = vector (10 ,0 ,0);
}
}
// Force the write
gamma.write();
//U.write();

Info<< "\n ExecutionTime = "
<< runTime.elapsedCpuTime()
<< " s\n" << endl;
Info<< "End" << endl;

return(0);
}
\*---------------------------------------------------------------------------*/

I would be very happy for any input.

Best wishes

Sebastian
schoeller is offline   Reply With Quote

Old   November 14, 2008, 13:54
Default Hi Sebastian, I have the ex
  #20
Senior Member
 
Mark Couwenberg
Join Date: Mar 2009
Location: Netherlands
Posts: 130
Rep Power: 17
markc is on a distinguished road
Hi Sebastian,

I have the experience that similar error messages can be due to very stupid small writing errors, either in filenames or e.g. patch names, or files being in the wrong place. Maybe it's something like this... Though it can be something completly else as well.

Brgds,

Mark
markc is offline   Reply With Quote

Reply


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
Specifying nonuniform initial condition msyaml OpenFOAM Running, Solving & CFD 65 April 25, 2016 05:23
Nonuniform initial condition using cellSetDict rinao OpenFOAM Running, Solving & CFD 6 January 9, 2013 01:42
Nonuniform boundary syntax juho OpenFOAM Running, Solving & CFD 1 December 11, 2008 17:13
Set nonuniform boundary values nikwin OpenFOAM Running, Solving & CFD 1 November 30, 2008 08:12
Nonuniform gradient boundary condition ankgupta8um OpenFOAM Running, Solving & CFD 1 March 14, 2006 02:34


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