CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM (https://www.cfd-online.com/Forums/openfoam/)
-   -   how to put if statement in between volScalarField and dimensionedScalar (https://www.cfd-online.com/Forums/openfoam/238070-how-put-if-statement-between-volscalarfield-dimensionedscalar.html)

sourav8016 August 21, 2021 12:46

how to put if statement in between volScalarField and dimensionedScalar
 
Hi Foamers,

I have to put a if statement in between a volScalarField and dimensionedScalar. The part of the code is :

//////////////////////////////////////////////////////////////
volScalarField y = mesh.C().component(vector::Y);

volScalarField u = ustar*(((1.0-Y0)/(Y0-Foam::log(Y0)-1.0))*Foam::log(y)/(h*Y0)));

if(y >= Y0*h && y <= h )
{
u = ustar*(((1.0-Y0)/(Y0-Foam::log(Y0)-1.0))*Foam::log(y/(h*Y0)));
}
else
{
u = 0.0;
}

dimensionedScalar Y0
(
transportProperties.lookup("Y0")
);

dimensionedScalar h
(
transportProperties.lookup("h")
);

//////////////////////////////////////////////////////////////////////////
u = u_*\frac{(1-Y_0)}{Y_0-\ln{Y_0}-1}\ln{\frac{y}{hY_0}} \,\text{for}\, Y_0h\leq y \leq h

//////////////////////////////////////////////////////////////////////////
After running the code I'm getting this error :

.C:82:24: error: no match for ‘operator<=’ (operand types are ‘Foam::volScalarField {aka Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>}’ and ‘Foam::dimensionedScalar {aka Foam::dimensioned<double>}’)
if(y >= Y0*h && y <= h )

geth03 August 23, 2021 04:06

Quote:

Originally Posted by sourav8016 (Post 810760)
Hi Foamers,

I have to put a if statement in between a volScalarField and dimensionedScalar. The part of the code is :

//////////////////////////////////////////////////////////////
volScalarField y = mesh.C().component(vector::Y);

volScalarField u = ustar*(((1.0-Y0)/(Y0-Foam::log(Y0)-1.0))*Foam::log(y)/(h*Y0)));

if(y >= Y0*h && y <= h )
{
u = ustar*(((1.0-Y0)/(Y0-Foam::log(Y0)-1.0))*Foam::log(y/(h*Y0)));
}
else
{
u = 0.0;
}

dimensionedScalar Y0
(
transportProperties.lookup("Y0")
);

dimensionedScalar h
(
transportProperties.lookup("h")
);

//////////////////////////////////////////////////////////////////////////
u = u_*\frac{(1-Y_0)}{Y_0-\ln{Y_0}-1}\ln{\frac{y}{hY_0}} \,\text{for}\, Y_0h\leq y \leq h

//////////////////////////////////////////////////////////////////////////
After running the code I'm getting this error :

.C:82:24: error: no match for ‘operator<=’ (operand types are ‘Foam::volScalarField {aka Foam::GeometricField<double, Foam::fvPatchField, Foam::volMesh>}’ and ‘Foam::dimensionedScalar {aka Foam::dimensioned<double>}’)
if(y >= Y0*h && y <= h )

you try to compare a value without dimensions with a value with dimensions,
so you are getting a dimension error. if you want to ignore it, which i do not recommend, you can just grab the values from both sides and compare the values. but the better way would be to fix the dimensions.

sourav8016 August 23, 2021 05:24

Quote:

Originally Posted by geth03 (Post 810807)
you try to compare a value without dimensions with a value with dimensions,
so you are getting a dimension error. if you want to ignore it, which i do not recommend, you can just grab the values from both sides and compare the values. but the better way would be to fix the dimensions.

Finally I have fixed it. Here is the code, that works well.
forAll(mesh.C(), i)
{
if((y[i] >= Y0.value()*h.value()) && (y[i] <= h.value()) )
{
u[i] = ustar.value()*(((1.0-Y0.value())/(Y0.value()-Foam::log(Y0.value())-1.0))*Foam::log(y[i]/(h.value()*Y0.value())));
}
else
{
u[i] = 0.0;
}
}


All times are GMT -4. The time now is 01:14.