CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM (https://www.cfd-online.com/Forums/openfoam/)
-   -   magnitude of a volVectorField !!? (https://www.cfd-online.com/Forums/openfoam/86474-magnitude-volvectorfield.html)

 T.D. March 23, 2011 13:12

magnitude of a volVectorField !!?

hi foamers,

I have a volVectorField Wrel, and a volScalarField gammadot (of same dimensions)

I need to get the volScalarField rhok,
where rhok= (2*magnitude(Wrel) ) / (gammadot+magnitude(Wrel))
so i tried the following:

but it didn't work !!!! it compiles well, but when i run it it gives this error:

Quote:
any ideas ???

thanks

T.D.

 benk March 23, 2011 14:32

I think you're going to end up with a list of values from mag(Wrel) (1 value for each point in your mesh), so you'll have to do a forAll loop to capture that:

Code:

```//define rhok as a volScalarField first forAll(rhok, i) { rhok[i]=2*mag(Wrel[i])/(gammadot+mag(Wrel[i])); }```

 akidess March 24, 2011 03:26

Are you sure gammadot+mag(Wrel) is never zero?

 T.D. March 24, 2011 04:22

hi guys,
thanks benk and akidess, i tried what you said (benk you forgot "[i]" for gammadot )
finally it was a division by zero error, but i didn't pay attention, and in compiler it says 'uninterpreted error'.
Any way here it is
Quote:
 forAll(rhok, i) { rhok[i]=2*mag(Wrel[i])/(gammadot[i]+mag(Wrel[i])+epsilon); } where epsilon is a very small value. It works !
Thanks

Best Regards,
T.D.

 niklas March 24, 2011 04:30

try this

dimensionedScalar WSmall("WSmall", Wrel.dimension(), 1.0e-15);

 sabin.ceuca March 24, 2011 04:54

Hi,
I would try this out:
forAll(mesh.cells(), celli)
{
}

Regards,

 T.D. March 24, 2011 05:14

hi, sabin.ceuca
this what i have done exactly as you mensioned:
forAll(mesh.cells(), celli)
{