CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   volScalarField to power of constant (https://www.cfd-online.com/Forums/openfoam-programming-development/140328-volscalarfield-power-constant.html)

PicklER August 13, 2014 07:34

volScalarField to power of constant
 
Hello (my first post)

I want to calculate:

rS=a0*P^rbn

in OpenFOAM, for a modified version of rhoCentralFoam. Where:

rS (0 1 -1 0 0 0 0) speed (m/s) volScalarField created by createFields

a0 (-1 2 1 0 0 0 0) read from thermophysicalProperties in test case as dimensionedScalar

P (1 -1 -2 0 0 0 0) pressure (kg/(ms^2)) created by createFields

rbn read from thermophysicalProperties in test case as dimensionedScalar, but is dimensionless and is some constant.

If I multiply a0 with P, then the dimensions change to (0 1 -1 0 0 0 0), which is correct for rS (0 1 -1 0 0 0 0) speed (m/s) volScalarField.

My problem is when I do P^rbn by using pow(P,rbn). Then the dimensions are altered.

My question: Is there a way to take a volScalarField such as P, to the power of a dimensionless scalar such as rbn without changing the dimensions??

Kind regards

PicklER August 19, 2014 03:11

I got a way to do this:

Store the dimensions of "p" as arDims
dimensionSet arDims(p.dimensions());

Make "p" dimensionless
p.dimensions().reset(dimless);

Perform calculation (resulting in desired dimension) (0 1 -1 0 0 0 0)
ar = a0*pow(p,rbn);

Restore the dimensions of "p".
p.dimensions().reset(arDims);

Hope this will help someone.
Vrede

jherb August 21, 2014 08:42

Have you tried to use: p.value()
This should give you the dimensionless values of the pressure field.

PicklER August 21, 2014 13:59

Hi jherb

Yes, I have tried "p.value()" (result below) and "p.val()", just to make sure.

Code:

srmFoamLam.C: In function ‘int main(int, char**)’:
srmFoamLam.C:88:23: error: ‘Foam::volScalarField’ has no member named ‘value’
  Info << "p.val "<< p.value() << endl;
                      ^

Thanks for idea though
Vrede

ngj August 21, 2014 15:47

Hallo,

One approach would be to do the following:

Code:

scalar exponent = 1.5;

// Perform on the internal part of the field
p.internalField() = Foam::pow(p.internalField(), exponent);

// Perform on the boundaries
forAll (p.boundaryField(), patchi)
{
    scalarField& pw = p.boundaryField()[patchi];
    pw = Foam::pow(pw, exponent);
}

p.correctBoundaryConditions();

Kind regards,

Niels

jherb August 22, 2014 15:44

Ok, googling I found: http://www.cfd-online.com/Forums/ope...tml#post476693

The correct method seems to be field()


All times are GMT -4. The time now is 06:28.