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

multiplication of scalar and volVectorField

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
Old   March 26, 2012, 11:29
Default multiplication of scalar and volVectorField
  #1
Member
 
Join Date: Jun 2011
Posts: 35
Rep Power: 6
mikeP is on a distinguished road
Hi,
I use following two methods in order to get the multiplication of Reynolds number and drag coefficient. (Drag coefficient, Cd, here is assumed constant scalar here for convenience)

Code:
Re = (magUr*dp*rhoa)/mua;
CdRe = 0.5*Re;
Code:
Re = (magUr*dp*rhoa)/mua;
forAll (Re, celli) 
{
     CdRe[celli] = 0.5*Re[celli];
}
These should give the same volScalarField, CdRe.
However, when I use these two code parts, I get different velocity field results at the end.
Are these two code parts exactly the same? or can they give different results when I, let's say, interpolate them?

Last edited by mikeP; March 27, 2012 at 04:13.
mikeP is offline   Reply With Quote

Old   March 26, 2012, 21:39
Default
  #2
Senior Member
 
David Gaden
Join Date: Apr 2009
Location: Winnipeg, Canada
Posts: 397
Rep Power: 12
marupio is on a distinguished road
Are you sure you're dealing with a volVectorField? I didn't think you could access the internal field directly with operator[], I thought you had to use Re.field() or Re.dimensionedField() first.

You could be missing the operations on the boundaryField.

If you are dealing with vectorFields and vectors, the two pieces of code you show are equivalent, except that the indexed loop is about 10x slower. The operators are optimized with fancy pointer loops, register keywords, and special accommodations for vector machines.
__________________
~~~
Follow me on twitter @DavidGaden
marupio is offline   Reply With Quote

Old   March 27, 2012, 04:12
Default
  #3
Member
 
Join Date: Jun 2011
Posts: 35
Rep Power: 6
mikeP is on a distinguished road
Dear David,

I am terribly sorry, now I noticed it. It is volScalarField, of course, not volVectorField.

Indeed, at the end, velocity field at the outlet is wrong if I use the second method. So, can it be due to the fact that I do not update the boundary field?

Let me explain it a little more: I am using a modified version of bubbleFoam, where I changed the definition of drag coefficient and relative reynolds number. When I use the first example above, my velocity field is reasonable. However, this option does not allow me to modify the Cd*Re cell by cell. But when I use the second example, although it should do the same effect, it does not. Velocity values are not correct at the outlet boundary. So, do you think it may be because I do not update the boundary field? How can I get the same results in both cases?

Thank you
mikeP is offline   Reply With Quote

Old   March 27, 2012, 05:31
Default
  #4
Member
 
Join Date: Jun 2011
Posts: 35
Rep Power: 6
mikeP is on a distinguished road
What I want to do is this:

Let's say I have a volScalarField Re:


Code:
FoamFile

{

    version     2.0;

    format      ascii;

    class       volScalarField;

    location    "1";

    object      Re;

}

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //



dimensions      [0 0 0 0 0 0 0];



internalField   nonuniform List<scalar> 

5

(

298.831

300.729

302.117

303.149

303.901

)

;



boundaryField

{

    ground

    {

        type            zeroGradient;

    }

    top

    {

        type            zeroGradient;

    }

    outlet

    {

        type            zeroGradient;

    }

    inlet

    {

        type            zeroGradient;

    }

    defaultFaces

    {

        type            empty;

    }

}
Suppose I have another volScalarField CdRe. (which is the multiplication of reynolds number and drag coefficient)

I want to modify CdRe cell by cell depending on the Re values, so that I can use it in my equations.
mikeP is offline   Reply With Quote

Old   March 27, 2012, 11:49
Default
  #5
Member
 
Join Date: Jun 2011
Posts: 35
Rep Power: 6
mikeP is on a distinguished road
I may have solved it.

I added this line after forall loop:

CdRe.correctBoundaryConditions();

Now it seems to be working fine.
Thank you!
mikeP is offline   Reply With Quote

Old   March 27, 2012, 12:34
Default
  #6
Senior Member
 
David Gaden
Join Date: Apr 2009
Location: Winnipeg, Canada
Posts: 397
Rep Power: 12
marupio is on a distinguished road
You should try to stay away from indexed loops on the internal field whenever possible. They are slow. Try to use full-field operators.
__________________
~~~
Follow me on twitter @DavidGaden
marupio is offline   Reply With Quote

Reply

Thread Tools
Display Modes

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 On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Climbing inlet pressure with simpleFoam and directMappedPatches chegdan OpenFOAM Running, Solving & CFD 1 January 2, 2012 20:35


All times are GMT -4. The time now is 00:55.