|
[Sponsors] |
March 28, 2020, 05:11 |
pointer of scalar in openfoam
|
#1 |
Senior Member
Mehdi Babamehdi
Join Date: Jan 2011
Posts: 158
Rep Power: 15 |
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; } |
|
March 28, 2020, 09:30 |
|
#2 |
Senior Member
Sergei
Join Date: Dec 2009
Posts: 261
Rep Power: 21 |
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).
|
|
March 28, 2020, 11:28 |
|
#3 |
Senior Member
Mehdi Babamehdi
Join Date: Jan 2011
Posts: 158
Rep Power: 15 |
@zeppo Thanks a lot. Another problem I have is also converting scalar to int/double. Do you know how I can do it?
|
|
March 28, 2020, 14:50 |
|
#4 |
Senior Member
Sergei
Join Date: Dec 2009
Posts: 261
Rep Power: 21 |
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); Last edited by Zeppo; March 29, 2020 at 09:50. Reason: misprint corrected |
|
Tags |
dynamic array, list, pointer |
|
|
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 |