Welcome! Log In Create A New Profile

Advanced

A data processor writing a std::vector

Posted by hjunghjung  
A data processor writing a std::vector
June 19, 2018 03:39AM
Hi all,

I don't know if the forum is no longer active or not, but I would like to ask a question if anyone can help me writing a data processor.

I would like to have a data processor that spits out a std::vector that can be accessed outside of the data processor. Here is the code I wrote.


Language: C++
template<typename T, template<typename U> class Descriptor> class ComputeScatteredRho3D : public BoxProcessingFunctional3D_L<T,Descriptor> { public: ComputeScatteredRho3D(std::vector<std::vector<int> > &locationVector_, std::vector<T> &rhoVector_, plint len_) : locationVector(locationVector_), rhoVector(rhoVector_), len(len_) {} virtual void process(Box3D domain, BlockLattice3D<T,Descriptor> &lattice) { for (plint i=0; i<len; ++i) { plint iX = locationVector[i][0]; plint iY = locationVector[i][1]; plint iZ = locationVector[i][2]; rhoVector[i] = lattice.get(iX,iY,iZ).computeDensity(); } } void getRhoVector(std::vector<T> &vect) { for (plint i=0; i<len; ++i) { vect[i] = rhoVector[i]; } } virtual ComputeScatteredRho3D<T,Descriptor>* clone() const { return new ComputeScatteredRho3D<T,Descriptor>(*this); } void getTypeOfModification(std::vector<modif::ModifT>& modified) const { modified[0] = modif::nothing; } private: std::vector<std::vector<int> > locationVector; std::vector<T> rhoVector; plint len; };     void getScatteredDensity3D(MultiBlockLattice3D<T,AVDES>& lattice, vector<vector<int>>& locationVector, vector<T>& newVector) { plint len = locationVector.size(); ComputeScatteredRho3D<T,AVDES> *aaa = new ComputeScatteredRho3D<T,AVDES> (locationVector, newVector, len); applyProcessingFunctional(aaa, lattice.getBoundingBox(), lattice); aaa->getRhoVector(newVector); delete(aaa); }

locationVector is a vector storing location information of a domain.
I want to have an access to rhoVector outside of the data processor using a function getRhoVector. However, it seems like the rhoVector is destroyed after the function applyProcessingFunctional.
Can anyone give me advice on solving this problem? Any help would be greatly appreciated.

Best,
hjung



Edited 1 time(s). Last edit at 06/19/2018 03:41AM by hjung.
Sorry, you do not have permission to post/reply in this forum.