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

pointer of scalar in openfoam

Register Blogs Community New Posts Updated Threads Search

Like Tree2Likes
  • 1 Post By Zeppo
  • 1 Post By Zeppo

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   March 28, 2020, 05:11
Default pointer of scalar in openfoam
  #1
Senior Member
 
Mehdi Babamehdi
Join Date: Jan 2011
Posts: 158
Rep Power: 15
mb.pejvak is on a distinguished road
when I define a aray of a List by using dynamic memory allocation, the compiler throw errors which seem for List<scalar> we can not define dynamic array. If so, How is it possible to do it?
randomValue is an array generated by random generator library. and posX (-Y, -Z) are given scalars.

Code:
List<List<scalar>> injected;

List<scalar>* rndParticle = new List<scalar>[numberOfObject_];
double factorOfSafty = 1.5;
scalar minDist_ = 10;



for(int i = 0; i < numberOfObject_; ++i)
{          
      rndParticle->push_back(*(randomValue++));
      rndParticle->push_back(posX_); 
      rndParticle->push_back(posY_ - numberOfObject_ * minDist_ * factorOfSafty     / 2 + i * minDist_ * factorOfSafty);        
      rndParticle->push_back(posZ_ - numberOfObject_ * minDist_ * factorOfSafty     / 2 + i * minDist_ * factorOfSafty);
      injected.push_back(*rndParticle);
      ++rndParticle;
  }
mb.pejvak is offline   Reply With Quote

Old   March 28, 2020, 09:30
Default
  #2
Senior Member
 
Zeppo's Avatar
 
Sergei
Join Date: Dec 2009
Posts: 261
Rep Power: 22
Zeppo will become famous soon enough
class List is not a class from standard c++ library, it is merely a part of OF. There's no push_back() method in there. Use append() (https://cpp.openfoam.org/v3/a07589_source.html#l00097).
mb.pejvak likes this.
Zeppo is offline   Reply With Quote

Old   March 28, 2020, 11:28
Default
  #3
Senior Member
 
Mehdi Babamehdi
Join Date: Jan 2011
Posts: 158
Rep Power: 15
mb.pejvak is on a distinguished road
@zeppo Thanks a lot. Another problem I have is also converting scalar to int/double. Do you know how I can do it?
mb.pejvak is offline   Reply With Quote

Old   March 28, 2020, 14:50
Default
  #4
Senior Member
 
Zeppo's Avatar
 
Sergei
Join Date: Dec 2009
Posts: 261
Rep Power: 22
Zeppo will become famous soon enough
There's not need in conversion from scalar to double. It is done automatically. scalar is a typedef (or #define, need to check it out in the sources) for either double or float depending on the option (double by default) chosen at the stage of OF compilation. Use scalar in place of double wherever you can and you'll be just fine. IF you need to conver scalar (double) to int just do it in a regular way with possible loss of pressision:
Code:
scalar myScalar(...);
int myInt ((int)myScalar);
mb.pejvak likes this.

Last edited by Zeppo; March 29, 2020 at 09:50. Reason: misprint corrected
Zeppo is offline   Reply With Quote

Reply

Tags
dynamic array, list, pointer


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
Frequently Asked Questions about Installing OpenFOAM wyldckat OpenFOAM Installation 3 November 14, 2023 12:58
How to contribute to the community of OpenFOAM users and to the OpenFOAM technology wyldckat OpenFOAM 17 November 10, 2017 16:54
OpenFOAM v3.0+ ?? SBusch OpenFOAM 22 December 26, 2016 15:24
OpenFOAM Training, London, Chicago, Munich, Houston 2016-2017 cfd.direct OpenFOAM Announcements from Other Sources 0 September 14, 2016 04:19
New OpenFOAM Forum Structure jola OpenFOAM 2 October 19, 2011 07:55


All times are GMT -4. The time now is 16:18.