CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Running, Solving & CFD (https://www.cfd-online.com/Forums/openfoam-solving/)
-   -   how to program the formula ddy(ux)+ddx(uy) (https://www.cfd-online.com/Forums/openfoam-solving/66249-how-program-formula-ddy-ux-ddx-uy.html)

yan July 9, 2009 21:34

how to program the formula ddy(ux)+ddx(uy)
 
hi, foamers. i want to implement the formula ddy(ux)+ddx(uy) in program, can you tell how to write in source code? thanks

su_junwei July 10, 2009 20:20

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

isabel July 15, 2009 05:00

And do you know how to program this?

x / (x² + y²)

su_junwei July 15, 2009 05:49

const volVectorField & C=mesh.C();
volScalarField x=C.component(0);
volScalarField y=C.component(1);
your formulation
x/(sqr(x)+sqr(y))

Junwei

henrik July 15, 2009 06:18

or even simpler, if z is zero:

Code:

const volVectorField & C=mesh.C();
volScalarField res = C.component(vector::X)/magSqr(C);

Henrik

isabel July 24, 2009 11:09

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.

henrik July 24, 2009 12:30

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

isabel July 24, 2009 13:04

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 July 24, 2009 13:26

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) ???

henrik July 24, 2009 14:06

Isabel,

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

Henrik

N2a August 19, 2009 10:50

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

henrik August 19, 2009 13:11

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

sven August 21, 2009 13:55

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!

isabel October 13, 2010 02:55

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?





eugene October 18, 2010 07:39

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.

isabel October 18, 2010 09:21

Where can I check the constructors for a volVectorField?

jaswi October 18, 2010 09:45

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


All times are GMT -4. The time now is 19:18.