CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM

how to put if statement in between volScalarField and dimensionedScalar

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   August 21, 2021, 12:46
Default how to put if statement in between volScalarField and dimensionedScalar
  #1
New Member
 
Sourav Hossain
Join Date: Mar 2019
Posts: 25
Rep Power: 7
sourav8016 is on a distinguished road
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 )

Last edited by sourav8016; August 21, 2021 at 12:50. Reason: previous one was incomplete
sourav8016 is offline   Reply With Quote

Old   August 23, 2021, 04:06
Default
  #2
Senior Member
 
Join Date: Dec 2019
Location: Cologne, Germany
Posts: 355
Rep Power: 8
geth03 is on a distinguished road
Quote:
Originally Posted by sourav8016 View Post
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.
geth03 is offline   Reply With Quote

Old   August 23, 2021, 05:24
Default
  #3
New Member
 
Sourav Hossain
Join Date: Mar 2019
Posts: 25
Rep Power: 7
sourav8016 is on a distinguished road
Quote:
Originally Posted by geth03 View Post
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;
}
}
sourav8016 is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to change a dimensionedScalar into volScalarField purnp2 OpenFOAM Programming & Development 3 May 31, 2019 16:37
changing a volScalarField to a dimensionedScalar wschosta OpenFOAM Running, Solving & CFD 5 May 6, 2015 10:20
make a dimensionedScalar to be volScalarField sharonyue OpenFOAM Programming & Development 4 April 2, 2014 05:44
dimensionedScalar + volScalarField is evaluated elementwisely ? tianyikillua OpenFOAM Programming & Development 1 March 30, 2012 03:12
Confused about how OF handles operation between volScalarField and dimensionedScalar Edy OpenFOAM 3 September 30, 2010 10:07


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