CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (http://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   Problem with pow and volScalarField (http://www.cfd-online.com/Forums/openfoam-programming-development/101543-problem-pow-volscalarfield.html)

 _Stefan_ May 7, 2012 08:15

Problem with pow and volScalarField

Hi,

I want to implement an new Order to Calculate the Viscosity nu.

Ostwald Waele Potential Function

tau = k * strain rate ^n

k and n are model Parameter and depend on rho
k=a*rho+b
n=c*rho+d

I got a, b, c, d from some experiments.

The equation for the rotation rheometer:

nu = tau / strain rate

What I have done:
Code:

```//read strain rate     tmp<volScalarField> sr(strainRate()); //Parameter     dimensionedScalar ka_("ka_",dimensionSet(0,2,-1,0,0,0,0), 0.1202);     dimensionedScalar kb_("kb_",dimensionSet(1,-1,-1,0,0,0,0), 24.912);       dimensionedScalar na_("na_",dimensionSet(-1,3,0,0,0,0,0), 0.0005);     dimensionedScalar nb_("nb_",dimensionSet(0,0,0,0,0,0,0), 0.2246); //read ScalarFeldes rho_ps     const tmp <volScalarField> & rhoCalc = U_.mesh().lookupObject<volScalarField>("rho_ps"); //calculation n and k     volScalarField K = ka_ * rhoCalc + kb_;     volScalarField N = na_ * rhoCalc + nb_; //Calculation nu     tmp <volScalarField> nu = K * Foam::pow(max(tone * sr(),VSMALL),N-1.);```
tone is only a dimensioned scalar with 1[s] to make sr() dimensionless.

My Problem is that it did not compile.
If I change N in the pow function to an dimensioned scalar it works fine.
Is it possible that, Foam::pow (volScalarField, volScalarField) does not work?

Here the error massage:

/SimSoftware/OpenFOAM/OpenFOAM-1.5/src/OpenFOAM/lnInclude/GeometricScalarField.C:189: error: no matching function for call to ‘Foam::dimensioned<double>::dimensioned(const char [2], double, const Foam::dimensionSet&)’
/SimSoftware/OpenFOAM/OpenFOAM-1.5/src/OpenFOAM/lnInclude/dimensionedType.C:107: note: candidates are: Foam::dimensioned<Type>::dimensioned(const Foam::word&, const Foam::dimensionSet&, Foam::Istream&) [with Type = double]
/SimSoftware/OpenFOAM/OpenFOAM-1.5/src/OpenFOAM/lnInclude/dimensionedType.C:94: note: Foam::dimensioned<Type>::dimensioned(const Foam::word&, Foam::Istream&) [with Type = double]
/SimSoftware/OpenFOAM/OpenFOAM-1.5/src/OpenFOAM/lnInclude/dimensionedType.C:82: note: Foam::dimensioned<Type>::dimensioned(Foam::Istream &) [with Type = double]
/SimSoftware/OpenFOAM/OpenFOAM-1.5/src/OpenFOAM/lnInclude/dimensionedType.H:95: note: Foam::dimensioned<Type>::dimensioned(const Type&) [with Type = double]
/SimSoftware/OpenFOAM/OpenFOAM-1.5/src/OpenFOAM/lnInclude/dimensionedType.C:69: note: Foam::dimensioned<Type>::dimensioned(const Foam::word&, const Foam::dimensioned<Type>&) [with Type = double]
/SimSoftware/OpenFOAM/OpenFOAM-1.5/src/OpenFOAM/lnInclude/dimensionedType.C:55: note: Foam::dimensioned<Type>::dimensioned(const Foam::word&, const Foam::dimensionSet&, Type) [with Type = double]
/SimSoftware/OpenFOAM/OpenFOAM-1.5/src/OpenFOAM/lnInclude/dimensionedScalarFwd.H:42: note: Foam::dimensioned<double>::dimensioned(const Foam::dimensioned<double>&)

 benk May 7, 2012 09:33

Quote:
 Originally Posted by _Stefan_ (Post 359722) Is it possible that, Foam::pow (volScalarField, volScalarField) does not work?
I'm not sure about the answer to your question, but my first instinct would be to do this sort of operation within a forAll loop

 _Stefan_ May 8, 2012 05:06

Thank you,

I think it is not the best way but it works:

Code:

```     Info << "calculate min strainrate" << endl;     volScalarField sr1 = max(sr()*tone,VSMALL);//[-]       Info << "forAll loop" << endl;     forAll(sr1, cellI)      {         N1[cellI] = Foam::pow(sr1[cellI],N[cellI]-1);     }     tmp <volScalarField> nu =    K * N1;```

 Cyp May 12, 2012 13:09

Did you try N.value() instead of N within the exponent ?

 _Stefan_ May 14, 2012 07:30

Hi Cyp,

I tried it but there are the Error:

error: ‘struct Foam::volScalarField’ has no member named ‘value’

 Cyp May 14, 2012 18:23

Yes, sorry, .value is valid if N is a dimensionedScalar.

in your case, if you already have declared A, B and C as volScalarField, you can performed :

Code:

`A.internalField() = Foam::pow(B.internalField(),C.internalField());`

The operation does not include the operation upon BC.

Best,
Cyp

 _Stefan_ May 15, 2012 04:39

Thanks, Cyp that is what I need. I also need the calculation on the boundary so I added:

Code:

```A.internalField() = Foam::pow(B.internalField(),C.internalField()); A.boundaryField() = Foam::pow(B.boundaryField(),C.boundaryField());```
And it works fine!

Quote:
 Originally Posted by _Stefan_ (Post 361121) Thanks, Cyp that is what I need. I also need the calculation on the boundary so I added: Code: ```A.internalField() = Foam::pow(B.internalField(),C.internalField()); A.boundaryField() = Foam::pow(B.boundaryField(),C.boundaryField());``` And it works fine!
Hi Stefan and Cyprien

I want to calculate the following relation.

A=min(0,c*B);

Which A and B are Volscalerfield and c diminesedscaler.
for the c i have used .value().

But I am receiving Eror when I have the B in the min function.
I have tried your suggestion but it does not work.

Could you help me?

Best
Mahdi

 Cyp August 7, 2012 07:45

Have you tried without any .value() ?

Else, I suggest to do :

A = c*min(0,B);

Yes I have tried, even for the follwing equations if I remove the .value() it is giving error.

A=min(0,c.value());
A.internalField()=min(0,c.value());
A.boundaryField()=min(0,c.value());

which is working because I removed the B. (but when I am adding the B it gives Error) .

 Cyp August 7, 2012 07:50

Quote:
 Originally Posted by mm.abdollahzadeh (Post 375803) Yes I have tried, even for the follwing equations if I remove the .value() it is giving error. A=min(0,c.value()); A.internalField()=min(0,c.value()); A.boundaryField()=min(0,c.value()); which is working because I removed the B. (but when I am adding the B it gives Error) .
see my edited post.

Thanks again ,,, I think the problem is not related the "c" .

the error is :

Code:

```error: no matching function for call to 'min(int, Foam::volScalarField&)' /home/mahdi/centFOAM//OpenFOAM/OpenFOAM-2.0.x/src/OpenFOAM/lnInclude/label.H:213:1: note: candidates are: char Foam::min(char, char) /home/mahdi/centFOAM//OpenFOAM/OpenFOAM-2.0.x/src/OpenFOAM/lnInclude/label.H:214:1: note:                short int Foam::min(short int, short int) /home/mahdi/centFOAM//OpenFOAM/OpenFOAM-2.0.x/src/OpenFOAM/lnInclude/label.H:215:1: note:                int Foam::min(int, int) /home/mahdi/centFOAM//OpenFOAM/OpenFOAM-2.0.x/src/OpenFOAM/lnInclude/label.H:216:1: note:                long int Foam::min(long int, long int) /home/mahdi/centFOAM//OpenFOAM/OpenFOAM-2.0.x/src/OpenFOAM/lnInclude/label.H:217:1: note:                long long int Foam::min(long long int, long long int) /home/mahdi/centFOAM//OpenFOAM/OpenFOAM-2.0.x/src/OpenFOAM/lnInclude/label.H:219:1: note:                unsigned char Foam::min(unsigned char, unsigned char) /home/mahdi/centFOAM//OpenFOAM/OpenFOAM-2.0.x/src/OpenFOAM/lnInclude/label.H:220:1: note:                short unsigned int Foam::min(short unsigned int, short unsigned int) /home/mahdi/centFOAM//OpenFOAM/OpenFOAM-2.0.x/src/OpenFOAM/lnInclude/label.H:221:1: note:                unsigned int Foam::min(unsigned int, unsigned int) /home/mahdi/centFOAM//OpenFOAM/OpenFOAM-2.0.x/src/OpenFOAM/lnInclude/label.H:222:1: note:                long unsigned int Foam::min(long unsigned int, long unsigned int) /home/mahdi/centFOAM//OpenFOAM/OpenFOAM-2.0.x/src/OpenFOAM/lnInclude/label.H:223:1: note:                long long unsigned int Foam::min(long long unsigned int, long long unsigned int) /home/mahdi/centFOAM//OpenFOAM/OpenFOAM-2.0.x/src/OpenFOAM/lnInclude/label.H:225:1: note:                long int Foam::min(int, long int) /home/mahdi/centFOAM//OpenFOAM/OpenFOAM-2.0.x/src/OpenFOAM/lnInclude/label.H:226:1: note:                long long int Foam::min(int, long long int) /home/mahdi/centFOAM//OpenFOAM/OpenFOAM-2.0.x/src/OpenFOAM/lnInclude/label.H:227:1: note:                long long int Foam::min(long long int, int) /home/mahdi/centFOAM//OpenFOAM/OpenFOAM-2.0.x/src/OpenFOAM/lnInclude/doubleFloat.H:78:1: note:                double Foam::min(double, double) /home/mahdi/centFOAM//OpenFOAM/OpenFOAM-2.0.x/src/OpenFOAM/lnInclude/doubleFloat.H:79:1: note:                double Foam::min(double, float) /home/mahdi/centFOAM//OpenFOAM/OpenFOAM-2.0.x/src/OpenFOAM/lnInclude/doubleFloat.H:80:1: note:                double Foam::min(float, double) /home/mahdi/centFOAM//OpenFOAM/OpenFOAM-2.0.x/src/OpenFOAM/lnInclude/doubleFloat.H:81:1: note:                float Foam::min(float, float) /home/mahdi/centFOAM//OpenFOAM/OpenFOAM-2.0.x/src/OpenFOAM/lnInclude/doubleFloat.H:82:1: note:                double Foam::min(double, int) /home/mahdi/centFOAM//OpenFOAM/OpenFOAM-2.0.x/src/OpenFOAM/lnInclude/doubleFloat.H:83:1: note:                double Foam::min(int, double) /home/mahdi/centFOAM//OpenFOAM/OpenFOAM-2.0.x/src/OpenFOAM/lnInclude/doubleFloat.H:84:1: note:                double Foam::min(double, long int) /home/mahdi/centFOAM//OpenFOAM/OpenFOAM-2.0.x/src/OpenFOAM/lnInclude/doubleFloat.H:85:1: note:                double Foam::min(long int, double) /home/mahdi/centFOAM//OpenFOAM/OpenFOAM-2.0.x/src/OpenFOAM/lnInclude/doubleFloat.H:86:1: note:                float Foam::min(float, int) /home/mahdi/centFOAM//OpenFOAM/OpenFOAM-2.0.x/src/OpenFOAM/lnInclude/doubleFloat.H:87:1: note:                float Foam::min(int, float) /home/mahdi/centFOAM//OpenFOAM/OpenFOAM-2.0.x/src/OpenFOAM/lnInclude/doubleFloat.H:88:1: note:                float Foam::min(float, long int) /home/mahdi/centFOAM//OpenFOAM/OpenFOAM-2.0.x/src/OpenFOAM/lnInclude/doubleFloat.H:89:1: note:                float Foam::min(long int, float) /home/mahdi/centFOAM//OpenFOAM/OpenFOAM-2.0.x/src/OpenFOAM/lnInclude/dimensionSet.H:214:29: note:                Foam::dimensionSet Foam::min(const Foam::dimensionSet&, const Foam::dimensionSet&)```

 Cyp August 7, 2012 08:04

Althought it is not very elegant, the following snippet should works:

Code:

```    forAll(A, cellI)     {       A[cellI] = min(0,c.value()*B[cellI]);     }```

thanks Cyprein, it works