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

Difference between 'internalField' and 'boundaryField'?

Register Blogs Community New Posts Updated Threads Search

Like Tree35Likes

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   January 26, 2011, 08:50
Post Difference between 'internalField' and 'boundaryField'?
  #1
New Member
 
Felix W.
Join Date: Jan 2011
Posts: 4
Rep Power: 15
Rusty Velo is on a distinguished road
Dear OFoamers,
as a new user of OpenFoam, I've maybe a very simple question .. but the OF-tutorial doesn't give a satisfying answer to me and I become more and more confused (as I tried to make some 'try and error calculations').

What does 'internalField' in e.g. a U-file describe ? And what is the difference between the 'internalField' and the 'boundaryField' (in detail) ?

Thanks in advance,
felix
omarozo, mizzou, granzer and 1 others like this.
Rusty Velo is offline   Reply With Quote

Old   January 26, 2011, 09:31
Default
  #2
Senior Member
 
Nima Samkhaniani
Join Date: Sep 2009
Location: Tehran, Iran
Posts: 1,267
Blog Entries: 1
Rep Power: 25
nimasam is on a distinguished road
consider pressure (p), it is defined as volScalarField
means it defines in center of each cell in domain. domain has two parts : domain content (internalField) and domain surrounding (boundaryField).

p.boundaryField() give you access to value in boundary, value in boundary would be surface center value. its helpful when you need the maximum, min, sum or average the value of a patch, so it returns a surfaceScalarField.
p.internalField() returns a scalarField (im not sure, check it ) , so it can be useful when you want to deal with internal value and keep boundary conditions unchanged.
nimasam is offline   Reply With Quote

Old   January 26, 2011, 09:36
Default
  #3
New Member
 
Dominic
Join Date: Jan 2011
Location: Leeds, UK
Posts: 25
Rep Power: 15
351Cleveland is on a distinguished road
Hi felix,

I'm quite new to OpenFoam myself, but I can give a shot at explaining the internalField condition.

For the velocity, U, the internalField characteristic is used to determine the properties of the fluid inside the computational domain. e.g. if the fluid is stationary and there is no velocity in any direction, the value will be uniform (0 0 0), whereas if we are addressing kinetic energy (scalar) and the initial conditions suggest there is some present, the value will be uniform x.

In short, as far as I know, (and hopefully right), this condition is simply used to assign the appropriate initial properties to the fluid not located at any of the boundaries.

Hope this helps.

Dom.
omarozo, alanaj5 and MaySea like this.
351Cleveland is offline   Reply With Quote

Old   January 26, 2011, 09:46
Default
  #4
Senior Member
 
Nima Samkhaniani
Join Date: Sep 2009
Location: Tehran, Iran
Posts: 1,267
Blog Entries: 1
Rep Power: 25
nimasam is on a distinguished road
beside if you just asking about U file in directory 0;
consider you are going to solve a differential equation you need to have boundary condition and initial condition, internalField defines initial condition it can be uniform or nonuniform and boundaryField defines boundary condtion which is mathematical boundary condition likes : fixed value ( means value in that patch is defined ) or zeroGradient ( gradient of the variable in that boundary is zero) look more in user guide
nimasam is offline   Reply With Quote

Old   January 26, 2011, 10:53
Default
  #5
New Member
 
Felix W.
Join Date: Jan 2011
Posts: 4
Rep Power: 15
Rusty Velo is on a distinguished road
Hi Nima, hi Dominic,
thanks for your fast replies ! These are exactly my missing information..

Nima: At the moment I'm only looking at some old cases to get known with all the different possibilities for all the settings.. but be sure, that I'll also read further in the user guide !

kind regards,
felix
Rusty Velo is offline   Reply With Quote

Old   August 7, 2012, 12:00
Default
  #6
Senior Member
 
mahdi abdollahzadeh
Join Date: Mar 2011
Location: Covilha,Portugal
Posts: 153
Rep Power: 15
mm.abdollahzadeh is on a distinguished road
Quote:
Originally Posted by nimasam View Post
consider pressure (p), it is defined as volScalarField
means it defines in center of each cell in domain. domain has two parts : domain content (internalField) and domain surrounding (boundaryField).

p.boundaryField() give you access to value in boundary, value in boundary would be surface center value. its helpful when you need the maximum, min, sum or average the value of a patch, so it returns a surfaceScalarField.
p.internalField() returns a scalarField (im not sure, check it ) , so it can be useful when you want to deal with internal value and keep boundary conditions unchanged.
Dear nima

Thanks for your clear description.
Could you please add also that what is the difference between dimensionedInternalField() and InternalField()?

I have the following equations. but when I am replacing the dimensionedInternalField() with InternalField() it gives the error. ( and there is no dimensionedboundaryField() ).

A.dimensionedInternalField()=min(scalar(0),B.dimen sionedInternalField()); A.boundaryField()=min(scalar(0),B.boundaryField()) ;

Best
Mahdi
Luttappy likes this.
mm.abdollahzadeh is offline   Reply With Quote

Old   August 7, 2012, 14:36
Default
  #7
Senior Member
 
Nima Samkhaniani
Join Date: Sep 2009
Location: Tehran, Iran
Posts: 1,267
Blog Entries: 1
Rep Power: 25
nimasam is on a distinguished road
you know variable has dimension, for example velocity dimension is {m/s}
OpenFOAM saves both variable values and its dimension,
so dimensionedInternalField() has besides value of InternalField(), its dimension too!

the error returns that you are going to compare a dimensionedvarible with a scalar,
it is not allowed, you should define your zero! as a dimensionedScalar with appropriate dimension
nimasam is offline   Reply With Quote

Old   August 7, 2012, 15:51
Default
  #8
Senior Member
 
mahdi abdollahzadeh
Join Date: Mar 2011
Location: Covilha,Portugal
Posts: 153
Rep Power: 15
mm.abdollahzadeh is on a distinguished road
Quote:
Originally Posted by nimasam View Post
you know variable has dimension, for example velocity dimension is {m/s}
OpenFOAM saves both variable values and its dimension,
so dimensionedInternalField() has besides value of InternalField(), its dimension too!

the error returns that you are going to compare a dimensionedvarible with a scalar,
it is not allowed, you should define your zero! as a dimensionedScalar with appropriate dimension
Thanks nima

But i was meaning that this formula is ok!
Code:
A.dimensionedInternalField()=min(scalar(0),B.dimen   sionedInternalField());
but this one is not ok

Code:
A.InternalField()=min(scalar(0),B.InternalField());
meth likes this.
mm.abdollahzadeh is offline   Reply With Quote

Old   August 7, 2012, 16:45
Default
  #9
Senior Member
 
Nima Samkhaniani
Join Date: Sep 2009
Location: Tehran, Iran
Posts: 1,267
Blog Entries: 1
Rep Power: 25
nimasam is on a distinguished road
and whats the error?
post the error here
nimasam is offline   Reply With Quote

Old   April 29, 2014, 13:40
Default
  #10
Member
 
CHARLES
Join Date: May 2013
Posts: 46
Rep Power: 13
CHARLES is on a distinguished road
I know this is an old thread but I have a question related to this subject...

I'm trying to write a forAll loop and I keep on getting errors no matter how I code it.

I tried coding it this way:
Code:
forAll(f1,celli)
{
    if (utau[celli] == 0.0) 
    {
    f1[celli] = exp(-0.5*xn[celli]*utau[celli]/nu());
    }else
    { f1[celli]= 0.0;
    }
}
But that yields the following error:
Code:
 error: cannot convert ‘Foam::tmp<Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh> >’ to ‘double’ in assignment
make: *** [Make/linux64GccDPOpt/SPLRRIP.o] Error 1
I have tried many combinations of .internalField() and .dimensionedInternalField() but I still get a similar error...

I understand that f1 is dimensionless, so I have also tried to use .value() instead of [celli] on xn and utau but when I do so, I get the following error:
Code:
SPLRRIP.C: In member function ‘virtual void Foam::incompressible::RASModels::SPLRRIP::correct()’:
SPLRRIP.C:458:26: error: ‘Foam::volScalarField’ has no member named ‘value’
SPLRRIP.C:458:39: error: ‘Foam::volScalarField’ has no member named ‘value’
make: *** [Make/linux64GccDPOpt/SPLRRIP.o] Error 1
What am I doing wrong?

Here is how I have defined utau, f1 and xn.
Code:
    xn
    (    
        IOobject
        (
            "xn",
            runTime_.timeName(),
            mesh_,
            IOobject::NO_READ,
            IOobject::AUTO_WRITE
        ),
        mesh_,
        dimensionedScalar("xn", dimLength, SMALL)
    ),
    utau
    (
        IOobject
        (
            "utau",
            runTime_.timeName(),
            mesh_,
            IOobject::NO_READ,
            IOobject::AUTO_WRITE
        ),
        mesh_,
        dimensionedScalar("utau", U_.dimensions(), 0.0)
    ),
    f1
    (
        IOobject
        (
            "f1",
            runTime_.timeName(),
            mesh_,
            IOobject::NO_READ,
            IOobject::AUTO_WRITE
        ),
        mesh_,
        dimensionedScalar("f1", dimless, 0.0)
    )


   xn = wallDist(mesh_).y(); //Normal distance to wall    

  const fvPatchList& Boundaries = mesh_.boundary();
    forAll(Boundaries, patchi) //loops through boundaries, patchi is the index
    {
        const fvPatch& currPatch = Boundaries[patchi]; //indexed boundary definition (current patch)
        if (isType<wallFvPatch>(currPatch))
        {
            utauw.boundaryField()[patchi] = 
            sqrt
                        (
                            nu()*mag(U_.boundaryField()[patchi].snGrad())
                        );
            forAll(currPatch, facei)
            {
                label faceCelli = currPatch.faceCells()[facei]; //indexed face in current patch
                // Assign utau[on indexed cell face] value from utauw[on boundary][at each boundary face]
                utau[faceCelli] = utauw.boundaryField()[patchi][facei];

            forAll(utau, celli) //assigns value of utau[at face] to utau[cells]
        {
            utau[celli] = utau[faceCelli];
            }
            }
         }    
     }
Thanks!
CHARLES is offline   Reply With Quote

Old   April 29, 2014, 14:14
Default
  #11
Senior Member
 
dkxls's Avatar
 
Armin
Join Date: Feb 2011
Location: Helsinki, Finland
Posts: 156
Rep Power: 19
dkxls will become famous soon enough
You are dividing by nu(). What is nu()? Is it a field? If so, then you need to access also for nu() the cell values.

In general it's a good idea to get a reference to the internal/boundary fields and loop through these ones. Something like this:
Code:
    scalarField& f1Cells = f1.internalField();

    forAll(f1Cells, cellI)
    {
        f1Cells[cellI] = ...
    }

    forAll(f1.boundaryField(), patchI)
    {
        fvPatchScalarField& pf1 = f1.boundaryField()[patchI];
        forAll(pf1, faceI)
        {
            pf1[faceI] = ...
        }
    }
babakflame and thosa like this.
dkxls is offline   Reply With Quote

Old   April 29, 2014, 14:26
Default
  #12
Member
 
CHARLES
Join Date: May 2013
Posts: 46
Rep Power: 13
CHARLES is on a distinguished road
Hello Armin,

I thought nu was the kinematic viscosity defined in constant > transportProperties. Since I'm running incompressible simulations, I assumed that nu() was just a constant value, which is why I wasn't trying to access the individual cell values.

However, I tried indexing nu():

Code:
scalarField& f1Cells =  f1.internalField();
forAll(f1Cells,celli)
{
    if (utau[celli] == 0.0) 
    {
    f1Cells[celli] = exp(-0.5*xn[celli]*utau[celli]/nu[celli]);
    }else
    { f1Cells[celli]= 0.0;
    }
}
I get the error:
Code:
SPLRRIP.C:459:58: error: invalid types ‘<unresolved overloaded function type>[Foam::label {aka int}]’ for array subscript
make: *** [Make/linux64GccDPOpt/SPLRRIP.o] Error 1
If I try to include the "()" in nu(), while indexing:
Code:
forAll(f1Cells,celli)
{
    if (utau[celli] == 0.0) 
    {
    f1Cells[celli] = exp(-0.5*xn[celli]*utau[celli]/nu()[celli]);
    }else
    { f1Cells[celli]= 0.0;
    }
}
I get :
Code:
SPLRRIP.C:459:60: error: no match for ‘operator[]’ in ‘Foam::incompressible::turbulenceModel::nu() const()[celli]’
make: *** [Make/linux64GccDPOpt/SPLRRIP.o] Error 1
CHARLES is offline   Reply With Quote

Old   April 29, 2014, 14:44
Default
  #13
Senior Member
 
dkxls's Avatar
 
Armin
Join Date: Feb 2011
Location: Helsinki, Finland
Posts: 156
Rep Power: 19
dkxls will become famous soon enough
Quote:
Originally Posted by CHARLES View Post
Code:
SPLRRIP.C:459:60: error: no match for ‘operator[]’ in ‘Foam::incompressible::turbulenceModel::nu() const()[celli]’
make: *** [Make/linux64GccDPOpt/SPLRRIP.o] Error 1
Apparently, nu() is not a field. I haven't checked the source code and I usually don't deal with the incompressible code anyways.

No idea, what goes wrong in your code. Are you sure the error is related to the code you posted initially? Maybe you recheck the line numbers in the error message and source code.
dkxls is offline   Reply With Quote

Old   April 29, 2014, 15:01
Default
  #14
Member
 
CHARLES
Join Date: May 2013
Posts: 46
Rep Power: 13
CHARLES is on a distinguished road
Thanks anyway Armin!

I know that the error is caused by the way that I am assigning the value to f1.
OpenFOAM doesn't like the f1[celli]=exp(...)
The reason (as far as I understand it) is that f1 is a field, but exp(...) returns a double. So, I'm trying to assign a 'double' to a cell within a field.

I think I may have figured out a solution to the initial problem... now I have another one

Coding it in the following way compiles (I know I should create a label but I'm testing for now):

Code:
forAll(f1,celli)
{
    if (utau[celli] == 0.0) 
    {
    f1.internalField() = exp(-0.5*xn[celli]*utau[celli]/nu());
    }else
    { f1.internalField()= scalar(0.0);
    }
}
Now the problem is that the simulation will stop on the first iteration with the following error:
Code:
Starting time loop

Time = 1e-05

DILUPBiCG:  Solving for Ux, Initial residual = 1, Final residual = 1.36617e-07, No Iterations 1
DILUPBiCG:  Solving for Uy, Initial residual = 1, Final residual = 1.36614e-07, No Iterations 1
DICPCG:  Solving for p, Initial residual = 0.999805, Final residual = 9.67079e-07, No Iterations 531
time step continuity errors : sum local = 3.21009e-14, global = 1.1476e-17, cumulative = 1.1476e-17
[0] 
[0] 
[0] --> FOAM FATAL ERROR: 
[0] Argument of trancendental function not dimensionless
[0] 
[0]     From function trans(const dimensionSet&)
[0]     in file dimensionSet/dimensionSet.C at line 424.
[0] 
FOAM parallel run aborting
[0]
CHARLES is offline   Reply With Quote

Old   April 29, 2014, 15:20
Default
  #15
Senior Member
 
dkxls's Avatar
 
Armin
Join Date: Feb 2011
Location: Helsinki, Finland
Posts: 156
Rep Power: 19
dkxls will become famous soon enough
Quote:
Originally Posted by CHARLES View Post
The reason (as far as I understand it) is that f1 is a field, but exp(...) returns a double. So, I'm trying to assign a 'double' to a cell within a field.

Does that make sense?
No it doesn't make sense.
f1 may be a field, but you can very well assign 'double' values to a cell. In fact when you do
Code:
f1Cells[cellI] = 3.141592;
you assign a 'double' to the cell.

Well, the solution for you is to bisect your code. Meaning, start with assigning 'double' values (e.g. 3.141592) to your cells and see if it compiles. If that works, add step by step more functions and see where it starts to go wrong.

Good luck!
dkxls is offline   Reply With Quote

Old   April 29, 2014, 15:25
Default
  #16
Senior Member
 
dkxls's Avatar
 
Armin
Join Date: Feb 2011
Location: Helsinki, Finland
Posts: 156
Rep Power: 19
dkxls will become famous soon enough
Quote:
Originally Posted by CHARLES View Post
Code:
forAll(f1,celli)
{
    if (utau[celli] == 0.0) 
    {
    f1.internalField() = exp(-0.5*xn[celli]*utau[celli]/nu());
    }else
    { f1.internalField()= scalar(0.0);
    }
}
That looks wrong!

Where is that code anyways? In a solver or a library?

Maybe you try to switch back to my initial example with the reference to the internal field and remove the nu(). Does that compile?
dkxls is offline   Reply With Quote

Old   April 29, 2014, 17:01
Default
  #17
Member
 
CHARLES
Join Date: May 2013
Posts: 46
Rep Power: 13
CHARLES is on a distinguished road
Armin,

The code is part of a turbulence model (LRR).
I tried doing
Code:
f1Cells[cellI]=3.141564
and the code compiled.

I removed nu() and substituted it with it's numerical value and it compiled and ran! So the whole problem was being caused by nu().

How would you access the value of nu so that the loop will adopt the numerical value for the current simulation?

The reason why I am confused is that I am able to access nu whenever it is outside of a loop.

For example, if I have
Code:
f1=exp(-0.5*xn*utau/nu());
there is no problem.
The problem arises when nu() is used in the loop...
CHARLES is offline   Reply With Quote

Old   April 30, 2014, 06:52
Default
  #18
Senior Member
 
dkxls's Avatar
 
Armin
Join Date: Feb 2011
Location: Helsinki, Finland
Posts: 156
Rep Power: 19
dkxls will become famous soon enough
Quote:
Originally Posted by CHARLES View Post
I removed nu() and substituted it with it's numerical value and it compiled and ran! So the whole problem was being caused by nu().
...
For example, if I have
Code:
f1=exp(-0.5*xn*utau/nu());
there is no problem.
The problem arises when nu() is used in the loop...
This brings me back to my first questions:
Quote:
Originally Posted by dkxls View Post
What is nu()? Is it a field?
Look up the return type of nu() and you will have the solution to your problem. Random testing will just waist your time here. My guess is that it is a tmp-field...
dkxls is offline   Reply With Quote

Old   April 30, 2014, 13:59
Default
  #19
Member
 
CHARLES
Join Date: May 2013
Posts: 46
Rep Power: 13
CHARLES is on a distinguished road
That is a great question... After looking in transportModels/incompressible/viscosityModels/Newtonian I have learned that nu() is in fact a tmp field:
Code:
  // Member Functions

        //- Return the laminar viscosity
        tmp<volScalarField> nu() const
        {
            return nu_;
        }
Is there anything in particular that you could suggest to fix this problem? As you can tell, I have no clue what is going on! :/
I don't understand why nu() can be accessed in a non-loop way but not from within a loop.

Thank you so much for taking the time to work through this with me.
CHARLES is offline   Reply With Quote

Old   May 2, 2014, 07:07
Default
  #20
Senior Member
 
dkxls's Avatar
 
Armin
Join Date: Feb 2011
Location: Helsinki, Finland
Posts: 156
Rep Power: 19
dkxls will become famous soon enough
Quote:
Originally Posted by CHARLES View Post
I don't understand why nu() can be accessed in a non-loop way but not from within a loop.
It is quite useful to learn how "tmp" works when your get to the "advanced" programming in OpenFOAM. See here:
http://openfoamwiki.net/index.php/OpenFOAM_guide/tmp
http://www.cfd-online.com/Forums/ope...acro-pain.html

A fix to your problem would be something like this:
Code:
const scalarField& nuCells = nu()().internalField();
In a loop you can then access the cell-values as usual:
Code:
f1Cells[cellI] = 3.141564*nuCells[cellI];
Milica and cryabroad like this.
dkxls is offline   Reply With Quote

Reply

Tags
boundaryfield, internalfield


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
boundary conditions for simpleFoam calculation foam_noob OpenFOAM Running, Solving & CFD 8 July 1, 2015 09:07
boundaryField vs. internalField sebonator OpenFOAM 10 January 24, 2011 17:43
solidWallHeatFluxTemperature at the solid solid interface in chtMultiRegionSimpleFoam maddalena OpenFOAM Running, Solving & CFD 43 January 11, 2011 03:39
buoyantSimpleRadiationFoam msarkar OpenFOAM 0 February 15, 2010 07:22
pipe flow with heat transfer Fabian OpenFOAM 2 December 12, 2009 05:53


All times are GMT -4. The time now is 16:50.