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