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

scalar to double! get error!

Register Blogs Community New Posts Updated Threads Search

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

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   June 27, 2016, 12:59
Default scalar to double! get error!
  #1
Senior Member
 
SinaJ
Join Date: Nov 2009
Posts: 136
Rep Power: 16
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
Senior Member
 
SinaJ
Join Date: Nov 2009
Posts: 136
Rep Power: 16
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: 273
Rep Power: 18
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
Senior Member
 
SinaJ
Join Date: Nov 2009
Posts: 136
Rep Power: 16
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: Germany
Posts: 242
Rep Power: 17
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
Senior Member
 
SinaJ
Join Date: Nov 2009
Posts: 136
Rep Power: 16
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
Super Moderator
 
Tobi's Avatar
 
Tobias Holzmann
Join Date: Oct 2010
Location: Tussenhausen
Posts: 2,708
Blog Entries: 6
Rep Power: 51
Tobi has a spectacular aura aboutTobi has a spectacular aura aboutTobi has a spectacular aura about
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.
__________________
Keep foaming,
Tobias Holzmann
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: 52
Rep Power: 12
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


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
Building OpenFOAM1.7.0 from source ata OpenFOAM Installation 46 March 6, 2022 13:21
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
How to install CGNS under windows xp? lzgwhy Main CFD Forum 1 January 11, 2011 18: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 00:20.