|
[Sponsors] |
April 6, 2020, 00:41 |
pointer to volScalarField
|
#1 |
New Member
Join Date: Apr 2020
Posts: 3
Rep Power: 6 |
Hello everyone,
In C++, we can assign a pointer to an array, for example: double a[3] = {1,2,4}; double *p =a; Then we can use p to access the array elements. So, my question is there a pointer to volScalarFiled type variable, like volScalarField p? |
|
April 6, 2020, 07:34 |
|
#2 |
Member
Join Date: Dec 2018
Location: Darmstadt, Germany
Posts: 87
Rep Power: 7 |
Hey Joe,
in OF, it is vary rare to encounter a raw array, unless you are working with low level libraries. However is it always possible to define a pointer to a volScalarField and use the field by derefencing the pointer. I don't recommend doing this in OF, since they are better alternatives like autoPtr and tmp which implement so called smart-pointer classes. It is much safer to use these pointer classes, especially when passing pointers around. Hope this helps. RP |
|
April 6, 2020, 20:09 |
|
#3 | |
New Member
Join Date: Apr 2020
Posts: 3
Rep Power: 6 |
Quote:
Thanks for your reply, since I'm not familiar with the autoPtr and tmp, I decide to use the reference to do it. My code is as following, class GetSet{ public: double getUx(int m) const{return Ux_[m];} double getUy(int m) const{return Uy_[m];} double getUz(int m) const{return Uz_[m];} double getP(int m) const{return p_[m];} GetSet(const volScalarField& Ux,const volScalarField& Uy, const volScalarField& Uz,const volScalarField& p) { Ux_ = Ux; Uy_ = Uy; Uz_ = Uz; p_ = p; } private: volScalarField Ux_; volScalarField Uy_; volScalarField Uz_; volScalarField p_; }; I want to use this class by GetSet* gset = new GetSet(Ux,Uy,Uz,p); and use gset->getUx(m) to get the values, but it seems that the form of the constructor has no match function (Ux,Uy and Uz have already been registered), does anybody know how to fix this problem? Thanks a lot! |
||
April 7, 2020, 14:01 |
|
#4 |
Senior Member
Mark Olesen
Join Date: Mar 2009
Location: https://olesenm.github.io/
Posts: 1,694
Rep Power: 40 |
Still not really sure what you are attempting, but if you need then to be write-modifiable, then store your Ux_, Uy_ etc as references (volScalarField&). If they are to be read-only, store as const references.
What you currently had would make a full local copy of your fields (probably not what you want). |
|
April 7, 2020, 15:50 |
|
#5 | |
New Member
Join Date: Apr 2020
Posts: 3
Rep Power: 6 |
Quote:
Thank you so much for your reply!! I've solved this problem! Have a good day! Joe |
||
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Error message | Bruno_Jorge | Main CFD Forum | 1 | February 5, 2019 11:12 |
namespace Foam | Argen | OpenFOAM | 4 | February 5, 2019 08:55 |
execFlowFunctionObjects - unknown field problem | Toorop | OpenFOAM Post-Processing | 16 | March 14, 2016 03:25 |
writing execFlowFunctionObjects | immortality | OpenFOAM Post-Processing | 30 | September 15, 2013 06:16 |
Pasing VolScalarField pointer to solve(), is this possible? | arkangel | OpenFOAM Programming & Development | 0 | March 15, 2011 13:07 |