CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > OpenFOAM Programming & Development

scalar to double! get error!

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree5Likes
  • 1 Post By anishtain4
  • 1 Post By hk318i
  • 2 Post By Tobi
  • 1 Post By Jerryfan

Reply
 
LinkBack Thread Tools Display Modes
Old   June 27, 2016, 12:59
Default scalar to double! get error!
  #1
Member
 
SinaJ
Join Date: Nov 2009
Posts: 60
Rep Power: 8
sina_mech is on a distinguished road
Hi,

I'm trying to extract a double value of a velocity vector component (x-component), using the following code

Code:
scalar u = U[mycell].x();
scalar v = U[mycell].y();
scalar w = U[mycell].z();

double u1= u.value();
but I get an error:
Code:
error: ‚x‚ was not declared in this scope
Do you have any suggestion?
sina_mech is offline   Reply With Quote

Old   June 27, 2016, 19:38
Default
  #2
Member
 
SinaJ
Join Date: Nov 2009
Posts: 60
Rep Power: 8
sina_mech is on a distinguished road
Any comment?
sina_mech is offline   Reply With Quote

Old   June 27, 2016, 22:41
Default
  #3
Senior Member
 
Mahdi Hosseinali
Join Date: Apr 2009
Location: NB, Canada
Posts: 193
Rep Power: 9
anishtain4 is on a distinguished road
please report the full error, I guess you can just use your u value, don't need to define another value as u1.
sina_mech likes this.
anishtain4 is offline   Reply With Quote

Old   June 28, 2016, 11:37
Default
  #4
Member
 
SinaJ
Join Date: Nov 2009
Posts: 60
Rep Power: 8
sina_mech is on a distinguished road
Quote:
Originally Posted by anishtain4 View Post
please report the full error, I guess you can just use your u value, don't need to define another value as u1.
Code:
error: request for member ‚value‚ in ‚u‚, which is of non-class type ‚Foam::scalar {aka double}‚
   usina = u.value();
sina_mech is offline   Reply With Quote

Old   June 28, 2016, 14:34
Default
  #5
Senior Member
 
Hassan Kassem
Join Date: May 2010
Location: UK
Posts: 213
Rep Power: 10
hk318i is on a distinguished road
This should work
Code:
double u1 = u;
scalar is basically OF wrap of standard c++ double/float
sina_mech likes this.
__________________
@HIKassem | HassanKassem.me
hk318i is offline   Reply With Quote

Old   June 28, 2016, 14:39
Default
  #6
Member
 
SinaJ
Join Date: Nov 2009
Posts: 60
Rep Power: 8
sina_mech is on a distinguished road
Quote:
Originally Posted by hk318i View Post
This should work
Code:
double u1 = u;
scalar is basically OF wrap of standard c++ double/float
Thank you. It works now
sina_mech is offline   Reply With Quote

Old   June 29, 2016, 06:40
Default
  #7
Senior Member
 
Tobi's Avatar
 
Tobias Holzmann
Join Date: Oct 2010
Location: Leoben (Austria)
Posts: 1,397
Blog Entries: 5
Rep Power: 24
Tobi will become famous soon enoughTobi will become famous soon enough
Send a message via ICQ to Tobi Send a message via Skype™ to Tobi
By the way, why you do something like that?
As hk318i already stated, double and scalar are similar! This will only introduce a new operation of memory allocation etc. In addition I would use references instead of copy values!

Code:
scalar& u = u[cellI].x();
const scalar& u = u[cellI].x();
Or if you really want to have the explicit name "double"

Code:
double& u = u[cellI].x();
const double& u = u[cellI].x();
But why you should use "double" in OpenFOAM we use "scalar" and as we know a scalar is a double

Code:
using scalar = double;
sina_mech and hk318i like this.
__________________
Best regards,
Tobias Holzmann

Some interesting OpenFOAM tutorials and videos on www.Holzmann-cfd.de
Tobi is offline   Reply With Quote

Old   July 6, 2016, 02:45
Default
  #8
Member
 
Jerry
Join Date: Oct 2013
Location: Salt Lake City, UT, USA
Posts: 40
Rep Power: 4
Jerryfan is on a distinguished road
If you go to the source code of scalar, you will find that the scalar is the same thing as double. Besides, they add template specialization for pTraits<Scalar>.


In doubleScalar.H:
Quote:
typedef double doubleScalar;
Quote:
#define Scalar doubleScalar
And later in scalar.H:
Quote:
typedef doubleScalar scalar;
Therefore, scalar would be equivalent to double in this regard.

In Scalar.H:
Quote:
template<>
class pTraits<Scalar>
{....}
sina_mech likes this.
Jerryfan is offline   Reply With Quote

Reply

Thread Tools
Display Modes

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 On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Errors in UDF shashank312 Fluent UDF and Scheme Programming 6 May 30, 2013 20:30
Compile problem ivanyao OpenFOAM Running, Solving & CFD 1 October 12, 2012 09:31
Building OpenFOAM1.7.0 from source ata OpenFOAM Installation 42 May 14, 2012 20:48
How to install CGNS under windows xp? lzgwhy Main CFD Forum 1 January 11, 2011 19:44
How to get the max value of the whole field waynezw0618 OpenFOAM Running, Solving & CFD 4 June 17, 2008 05:07


All times are GMT -4. The time now is 15:58.