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

how to program the formula ddy(ux)+ddx(uy)

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

Reply
 
LinkBack Thread Tools Display Modes
Old   July 9, 2009, 21:34
Default how to program the formula ddy(ux)+ddx(uy)
  #1
yan
New Member
 
yan
Join Date: Mar 2009
Posts: 2
Rep Power: 0
yan is on a distinguished road
hi, foamers. i want to implement the formula ddy(ux)+ddx(uy) in program, can you tell how to write in source code? thanks
yan is offline   Reply With Quote

Old   July 10, 2009, 20:20
Default
  #2
Senior Member
 
su_junwei's Avatar
 
su junwei
Join Date: Mar 2009
Location: Xi'an China
Posts: 151
Rep Power: 10
su_junwei is on a distinguished road
Send a message via MSN to su_junwei
you can try
volScalarField ux=u.component(0);
volScalarField uy=u.component(1);
volVectorField gradux=fvc::grad(ux);
volVectorField graduy=fvc::grad(uy);
your formulation:
gradux.component(1)+graduy.component(0);


or

volTensorField gradU=fvc::grad(U)
volSymmTensorField twoSymmGradu=twoSymm(gradU);
your formulation is
twoSymmGradu.component(1);
Junwei

Last edited by su_junwei; July 11, 2009 at 08:27.
su_junwei is offline   Reply With Quote

Old   July 15, 2009, 05:00
Default
  #3
Senior Member
 
isabel
Join Date: Apr 2009
Location: Spain
Posts: 171
Rep Power: 8
isabel is on a distinguished road
And do you know how to program this?

x / (x + y)
isabel is offline   Reply With Quote

Old   July 15, 2009, 05:49
Default
  #4
Senior Member
 
su_junwei's Avatar
 
su junwei
Join Date: Mar 2009
Location: Xi'an China
Posts: 151
Rep Power: 10
su_junwei is on a distinguished road
Send a message via MSN to su_junwei
const volVectorField & C=mesh.C();
volScalarField x=C.component(0);
volScalarField y=C.component(1);
your formulation
x/(sqr(x)+sqr(y))

Junwei
su_junwei is offline   Reply With Quote

Old   July 15, 2009, 06:18
Arrow
  #5
Senior Member
 
Henrik Rusche
Join Date: Mar 2009
Location: Braunschweig, Niedersachsen, Germany
Posts: 275
Rep Power: 9
henrik is on a distinguished road
or even simpler, if z is zero:

Code:
const volVectorField & C=mesh.C();
volScalarField res = C.component(vector::X)/magSqr(C);
Henrik
henrik is offline   Reply With Quote

Old   July 24, 2009, 11:09
Default
  #6
Senior Member
 
isabel
Join Date: Apr 2009
Location: Spain
Posts: 171
Rep Power: 8
isabel is on a distinguished road
Thank you very much. Sorry for disturb you again, but I have other problem:


I need a function_new which values x/(x + ) if x > 0 and 1 if x < 0
So I have tipped


const volVectorField & C = mesh.C();
volScalarField x = C.component(0);
volScalarField y = C.component(1);
volScalarField function = x/(sqrt(x)+sqrt(y));
volScalarField function_new = scalar(1);


forAll(x, gI)
{
if (x[gI] < 0)
function_new[gI] = 1;
else
function_new[gI] = function[gI];
}



I have no errors but “fuction_new” always is “1”.
I think that the error is that “gI” is not the word I have to type.
isabel is offline   Reply With Quote

Old   July 24, 2009, 12:30
Default
  #7
Senior Member
 
Henrik Rusche
Join Date: Mar 2009
Location: Braunschweig, Niedersachsen, Germany
Posts: 275
Rep Power: 9
henrik is on a distinguished road
Isabel,

the long answer is:

I do not see what's wrong. Try and put some Info-statements into the loop and if-statement.

the short answer is:

Code:
volScalarField function_new = max(function, scalar(0));

Henrik
henrik is offline   Reply With Quote

Old   July 24, 2009, 13:04
Default
  #8
Senior Member
 
isabel
Join Date: Apr 2009
Location: Spain
Posts: 171
Rep Power: 8
isabel is on a distinguished road
Thank you very much, Henrik. But my error continues. To see the error better, I have tipped this:

volScalarField x = C.component(0);
volScalarField function_new = scalar(1);


forAll(x,gI)
{
function_new[gI] = x[gI];
}


And when I execute, “function_new” always is 1 and should be equal to "x"

Why is always 1?
isabel is offline   Reply With Quote

Old   July 24, 2009, 13:26
Default
  #9
Senior Member
 
isabel
Join Date: Apr 2009
Location: Spain
Posts: 171
Rep Power: 8
isabel is on a distinguished road
Sorry Henrik, you were right. I have discovered that I was other different problem. These lines were Ok.
Only a last doubt, I don't know which is better: use forAll(x,gI) or forAll(x,celli) ???
isabel is offline   Reply With Quote

Old   July 24, 2009, 14:06
Default
  #10
Senior Member
 
Henrik Rusche
Join Date: Mar 2009
Location: Braunschweig, Niedersachsen, Germany
Posts: 275
Rep Power: 9
henrik is on a distinguished road
Isabel,

the difference between the two statements is only the name of the variable - Nothing else.

Henrik
henrik is offline   Reply With Quote

Old   August 19, 2009, 10:50
Default
  #11
N2a
New Member
 
Benjamin
Join Date: May 2009
Posts: 5
Rep Power: 8
N2a is on a distinguished road
Hi,
why is it not possible to do:

volVectorField Grad_X

volTensorField gradU=fvc::grad(U);


Info << gradU.T()*Grad_X << endl ;

It gaves me the following error:

no match for ‘operator*’ in ‘Foam::GeometricField<Type, PatchField, GeoMesh>::T() const [with Type = Foam::Tensor<double>, PatchField = Foam::fvPatchField, GeoMesh = Foam::volMesh]() * Grad_X’

On the other hand:
gradU.T() & Grad_X seems to give the correct result.


Thank you

Last edited by N2a; August 19, 2009 at 12:47.
N2a is offline   Reply With Quote

Old   August 19, 2009, 13:11
Default
  #12
Senior Member
 
Henrik Rusche
Join Date: Mar 2009
Location: Braunschweig, Niedersachsen, Germany
Posts: 275
Rep Power: 9
henrik is on a distinguished road
Dear N2a,


Please, have a look into the Programmer's Guide (P-24) and around.

"*" represents the outer product. Hence, tensor * vector = third rank tensor which are not implemented. Probably you want the inner product, ie. vector & tensor = vector.

Henrik
henrik is offline   Reply With Quote

Old   August 21, 2009, 13:55
Default
  #13
Member
 
Sven Winkler
Join Date: May 2009
Posts: 70
Rep Power: 8
sven is on a distinguished road
Can someone explain what the line

Code:
const volVectorField & C=mesh.C();
stands for? especially, what does the & sign mean?
How can I define a volVectorField with initial values, that is how can I define a volVectorField with defining a value of each of its components?
Thank you!
sven is offline   Reply With Quote

Old   October 13, 2010, 02:55
Default
  #14
Senior Member
 
isabel
Join Date: Apr 2009
Location: Spain
Posts: 171
Rep Power: 8
isabel is on a distinguished road
Hello everybody,

I need to define a surfaceScalarField vector (-1,0,0) which I have done as follows:

volVectorField vectorv = vector(-1,0,0);
surfaceScalarField vectors = mesh.Sf() & fvc::interpolate(vectorv);

But when I try to compile I have the following error in the first line:

levelSetEqn.H:73: error: conversion from ‘Foam::vector’ to non-scalar type ‘Foam::volVectorField’ requested

Does anybody know how can I define my surfaceScalarField?




isabel is offline   Reply With Quote

Old   October 18, 2010, 07:39
Default
  #15
Senior Member
 
Eugene de Villiers
Join Date: Mar 2009
Posts: 725
Rep Power: 12
eugene is on a distinguished road
Your surfaceScalarField definition is fine. Your volVectorField definition is not. Check the constructors for a volField and use one of them to construct your volVectorField.
eugene is offline   Reply With Quote

Old   October 18, 2010, 09:21
Default
  #16
Senior Member
 
isabel
Join Date: Apr 2009
Location: Spain
Posts: 171
Rep Power: 8
isabel is on a distinguished road
Where can I check the constructors for a volVectorField?
isabel is offline   Reply With Quote

Old   October 18, 2010, 09:45
Default
  #17
Senior Member
 
Join Date: Mar 2009
Posts: 248
Rep Power: 9
jaswi is on a distinguished road
Dear Isabel

What you really need is to create a volumetric vector field i.e. a field in which:

a vector is stored at the cell centre in the internalField;
a vector is stored at the face centre on the boundaryField;

What Eugene meant is that look for a previous declaration of some volVectorField and declare yours analogously.

You are getting an error because you are trying to convert a vector to a field. This is not possible because the field needs information about the mesh so that it can calculate the size of the field.

For your case your can do something like this :



volVectorField vectorV
(
IOobject
(
"vectorV",
runTime.timeName(),
mesh,
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
mesh,
dimensionedVector("vectorV", dimless, vector(x,y,z))
);


Above given is just one option. This will create a volVectorField named vectorV. At each location a dimensionless vector with the components x,y,z is stored . Also the boundaryField type of this field is by default set to calculated.

In case you want to have the same but a vector with dimensions then do the following:

volVectorField vectorV
(
IOobject
(
"vectorV",
runTime.timeName(),
mesh,
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
mesh,
dimensionedVector
(
"vectorV",
dimensionSet( 0, 1, -1, 0, 0, 0, 0 ),
vector(x,y,z)
)
);

Now you have field with vector at each location which has dimesnions of velocity.

Additionally if you want to presupply the boundaryField types then you can define:


volVectorField vectorV
(
IOobject
(
"vectorV",
runTime.timeName(),
mesh,
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
mesh,
dimensionedVector
(
"vectorV",
dimensionSet( 0, 1, -1, 0, 0, 0, 0 ),
vector(x,y,z)
),
fixedValueFvPatchVectorField::typeName
);

If you want to copy the boundaryField types of some already existing field then you can do something similar to what is done in the file interFoam/correctPhi.H. Have a look at that and you will understand how to do this .


Hope that will help.

Regards
jaswi
jaswi 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
CAE program for heat conducting Rogerio Fernandes Brito FLUENT 0 February 3, 2008 12:22
Problem in program tib FLUENT 0 January 28, 2004 15:13
How to write a simple program ?? kokey FLUENT 0 March 19, 2002 11:21
Benetton Formula 1 CD adapco Group Marketing CD-adapco 13 February 7, 2002 10:33
Any numerical triple integration program is available in Fortran? Radhakrishnan Main CFD Forum 3 March 4, 1999 02:03


All times are GMT -4. The time now is 21:33.