A data processor writing a std::vector

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.

[code=“cpp”]
template<typename T, template class Descriptor>
class ComputeScatteredRho3D : public BoxProcessingFunctional3D_L<T,Descriptor>
{
public:
ComputeScatteredRho3D(std::vector<std::vector > &locationVector_, std::vector &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 &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::vectormodif::ModifT& modified) const {
modified[0] = modif::nothing;
}
private:
std::vector<std::vector > locationVector;
std::vector rhoVector;
plint len;
};

void getScatteredDensity3D(MultiBlockLattice3D<T,AVDES>& lattice,
vector<vector>& locationVector,
vector& 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

Hi, I also met this problem in the learning process? I wonder if you have solved this problem?

Hi.

That would be applicable if you write “std::vector rhoVector” as “std::vector &rhoVector” in your private definition. That would be a reference to your outside variable.

Otherwise, you can create a new applyProcessingFunctional to accept a reference of your data processor. This version of applyProcessingFunctional accepts a dynamic pointer as an argument that would be destructed automatically at the end of the function.

Best,
Mengyu