Commit 3ae1b336 authored by David Vincent's avatar David Vincent Committed by Jonathan Lambrechts
Browse files

The user can now identify each particle by means of particle ID when

adding a Particle at a point
parent 7f8bc8c4
......@@ -1003,7 +1003,7 @@ void connectivityMatrixPrint::CMPrinter(fullMatrix<double>* FM, const std::strin
}
/** Seed additional particles at a given point */
void particleArray::addParticlesAtPoint(dgGroupCollection* _group, int M, double x0, double y0, int iter, int status, int source_reef)
void particleArray::addParticlesAtPoint(dgGroupCollection* _group, int M, double x0, double y0, int iter, int status, int source_reef, int particleId)
{
//Get nb of existing particles
int existingNbParticles = _totalSeeded;
......@@ -1018,7 +1018,7 @@ void particleArray::addParticlesAtPoint(dgGroupCollection* _group, int M, double
//Seed particles
for (int i=0; i<M; i++) {
_particle_array.push_back( particle(x0, y0, iGroup, iElem, source_reef, status, iter) );
_particle_array.push_back( particle(x0, y0, iGroup, iElem, source_reef, status, iter, particleId) );
}
//Update counters
......@@ -1384,7 +1384,6 @@ void particleArray::printPositions(const std::string filename, const std::string
if (filetype == "dat") {
//Write to file as list
for (size_t m=0; m<_particle_array.size(); m++) {
//Only register if particle is of state 'status'
if (_particle_array[m].getState() == status) {
outFile << _particle_array[m].x() << " " << _particle_array[m].y() << " " << _particle_array[m].getSource() << std::endl;
}
......@@ -1397,7 +1396,12 @@ void particleArray::printPositions(const std::string filename, const std::string
for (size_t m=0; m<_particle_array.size(); m++) {
//Only register if particle is of state 'status'
if (_particle_array[m].getState() == status) {
outFile << "SP (" << _particle_array[m].x() <<","<< _particle_array[m].y() <<",0) {"<<_particle_array[m].getSource()<<"};" << std::endl;
if (_particle_array[m].getParticleId()==-1){
outFile << "SP (" << _particle_array[m].x() <<","<< _particle_array[m].y() <<",0) {"<<_particle_array[m].getSource()<<"};" << std::endl;
}
else{
outFile << "SP (" << _particle_array[m].x() <<","<< _particle_array[m].y() <<",0) {"<<_particle_array[m].getParticleId()<<"};" << std::endl;
}
}
}
outFile << "};"<<std::endl;
......@@ -1497,7 +1501,7 @@ void particleArray::saveState(const std::string &filename) {
_particle_array[m].getElementId(&iGroup, &iElem);
outFile << std::setprecision(17) << _particle_array[m].x() <<' '<< _particle_array[m].y();
outFile <<' '<< _particle_array[m].getState() <<' '<< _particle_array[m].getSource() <<' '<< _particle_array[m].getCompetency() <<' '<< iGroup <<' '<< iElem <<'\n';
outFile <<' '<< _particle_array[m].getState() <<' '<< _particle_array[m].getSource() <<' '<< _particle_array[m].getCompetency() <<' '<< iGroup <<' '<< iElem <<' '<< _particle_array[m].getParticleId()<<'\n';
}
std::cout << "Finished saving state of particle array to file " << filename << ".\n";
outFile.close();
......@@ -1527,11 +1531,11 @@ void particleArray::loadState(const std::string &filename) {
int m=0;
while (std::getline(inFile, line))
{
int state, sourceReef, competency, iGroup, iElem;
int state, sourceReef, competency, iGroup, iElem, particleId;
double x, y;
std::istringstream iss(line);
iss >> x >> y >> state >> sourceReef >> competency >> iGroup >> iElem;
iss >> x >> y >> state >> sourceReef >> competency >> iGroup >> iElem >> particleId;
// std::cout <<std::setprecision(17) <<' '<< x <<' '<< y <<' '<< state <<' '<< sourceReef <<' '<< competency <<' '<< iGroup <<' '<< iElem<<'\n';
......@@ -1540,6 +1544,7 @@ void particleArray::loadState(const std::string &filename) {
_particle_array[m].setSource(sourceReef);
_particle_array[m].setCompetency(competency);
_particle_array[m].setElementId(iGroup, iElem);
_particle_array[m].setParticleId(particleId);
m++;
}
if (m != _totalSeeded) std::cerr << "ERROR in particleArray.loadState: input file is corrupted. Filename is " << filename << ". Expecting "<< _totalSeeded <<" particles but we actually have "<< m <<" particles listed.\n";
......
......@@ -29,6 +29,7 @@ private:
int _source_reef, _sink_reef;
//Remember element and group Id particle is in:
int _groupId, _elementId;
int _particleId;
public:
// Default constructor
......@@ -42,8 +43,8 @@ public:
_groupId = -1;
_elementId = -1;
_competency = 0;
_particleId = -1;
}
// Cartesian constructor which SETS mesh element Id's
particle(double x0, double y0, int iGroup, int iElement, int status, int iter)
{
......@@ -72,7 +73,7 @@ public:
}
// Cartesian constructor which sets source reef AND mesh element Id's
particle(double x0, double y0, int iGroup, int iElement, int srcReef, int status, int iter)
particle(double x0, double y0, int iGroup, int iElement, int srcReef, int status, int iter, int particleId=-1)
{
_xcoord = x0;
_ycoord = y0;
......@@ -83,6 +84,7 @@ public:
_elementId = iElement;
_competency = 0;
_iter_seeded = iter;
_particleId = particleId;
}
// Cartesian constructor which sets source reef but NOT mesh element Id's (try not to use this, doesn't store element we're in)
......@@ -119,6 +121,10 @@ public:
{
return _source_reef;
}
int getParticleId()
{
return _particleId;
}
int getSink()
{
......@@ -162,6 +168,11 @@ public:
_sink_reef = sink;
}
void setParticleId(int particleId)
{
_particleId = particleId;
}
void setElementId(int iGroup, int iElement)
{
_groupId = iGroup;
......@@ -195,7 +206,7 @@ public:
}
/** Seed particles at a given point. */
void addParticlesAtPoint(dgGroupCollection* _group, int M, double x0, double y0, int iter, int status, int source_reef);
void addParticlesAtPoint(dgGroupCollection* _group, int M, double x0, double y0, int iter, int status, int source_reef, int particleId=-1);
/** Seed particles using a DofContainer.
* minNbParticlesPerHabitat gives the minimum number of particles to seed per habitat (different habitats are identified by having different integer values of the dof container in each element) */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment