46 logger(
DEBUG,
"ParticleHandler::ParticleHandler() finished");
68 logger(
DEBUG,
"ParticleHandler::ParticleHandler(const ParticleHandler &PH) finished");
91 logger(
DEBUG,
"ParticleHandler::operator = (const ParticleHandler& rhs) finished");
104 logger(
DEBUG,
"ParticleHandler::~ParticleHandler() finished");
124 logger(
WARN,
"WARNING: The particle with ID % that is added in "
125 "ParticleHandler::addObject does not have a species yet."
126 "Please make sure that you have "
127 "set the species somewhere in the driver code.", P->
getId());
155 #ifdef CONTACT_LIST_HGRID
168 #ifdef CONTACT_LIST_HGRID
179 logger(
WARN,
"No particles, so cannot compute the smallest particle.");
182 Mdouble min = std::numeric_limits<Mdouble>::max();
186 if (particle->getInteractionRadius() < min)
198 logger(
WARN,
"No particles, so cannot compute the largest particle.");
201 Mdouble max = -std::numeric_limits<Mdouble>::max();
205 if (particle->getInteractionRadius() > max)
221 logger(
WARN,
"No particles to return in getSmallestParticle()");
234 logger(
WARN,
"No particles to set get_LargestParticle()");
246 logger(
WARN,
"No particles to set getFastestParticle()" );
250 Mdouble maxSpeed = -std::numeric_limits<Mdouble>::max();
253 if ((pLoop->getVelocity().getLength()) > maxSpeed)
255 maxSpeed = pLoop->getVelocity().getLength();
268 sumRadius += p->getRadius();
282 logger(
WARN,
"No getLowestPositionComponentParticle(const int i) since there are no particles.");
286 Mdouble min = std::numeric_limits<Mdouble>::max();
289 if (pLoop->getPosition().getComponent(i) < min)
291 min = pLoop->getPosition().getComponent(i);
307 logger(
WARN,
"No getHighestPositionComponentParticle(const int i) since there are no particles.");
311 Mdouble max = -std::numeric_limits<Mdouble>::max();
314 if (pLoop->getPosition().getComponent(i) > max)
316 max = pLoop->getPosition().getComponent(i);
333 logger(
WARN,
"No getLowestVelocityComponentParticle(const int i) since there are no particles");
337 Mdouble min = std::numeric_limits<Mdouble>::max();
340 if (pLoop->getVelocity().getComponent(i) < min)
342 min = pLoop->getVelocity().getComponent(i);
358 logger(
WARN,
"No getHighestVelocityComponentParticle(const int i) since there are no particles");
362 Mdouble max = -std::numeric_limits<Mdouble>::max();
365 if (pLoop->getVelocity().getComponent(i) > max)
367 max = pLoop->getVelocity().getComponent(i);
381 logger(
WARN,
"No particles to set getLightestParticle()");
385 Mdouble minMass = std::numeric_limits<Mdouble>::max();
388 if (pLoop->getMass() < minMass)
390 minMass = pLoop->getMass();
411 if (type ==
"BaseParticle"||type ==
"BP"||isdigit(type[0]))
415 else if (type ==
"LiquidFilmParticle")
421 logger(
ERROR,
"Particle type % not understood in restart file. Particle has not been read.", type);
433 logger.log(
Log::DEBUG,
"ParticleHandler::readObject(is): reading type %.", type);
434 if (type ==
"BaseParticle")
445 else if (type ==
"LiquidFilmParticle")
456 else if (type ==
"ThermalParticle")
468 else if (type ==
"BP")
479 else if (isdigit(type[0]))
485 logger(
ERROR,
"Particle type % not understood in restart file: You need to add this particle to ParticleHandler::readObject.", type);
502 std::stringstream line(std::stringstream::in | std::stringstream::out);
510 unsigned int indSpecies;
511 Mdouble radius, inverseMass, inverseInertia;
512 Vec3D position, velocity, orientation, angularVelocity;
515 position.
X = atof(type.c_str());
517 line >> position.
Y >> position.
Z >> velocity >> radius >> orientation >> angularVelocity >> inverseMass >> inverseInertia >> indSpecies;
520 particle.setSpecies(
getDPMBase()->speciesHandler.getObject(indSpecies));
521 particle.setPosition(position);
522 particle.setVelocity(velocity);
523 particle.setRadius(radius);
524 particle.setOrientation(orientation);
525 particle.setAngularVelocity(angularVelocity);
526 if (inverseMass == 0.0)
527 particle.fixParticle();
530 particle.setInertia(1./inverseInertia);
541 os << (*it) << std::endl;
594 if (particle->getIndSpecies() == indSpecies)
596 particle->getSpecies()->computeMass(particle);
605 particle->getSpecies()->computeMass(particle);
614 return "ParticleHandler";
625 static unsigned fileCounter = 0;
631 file.open(fileName.c_str(), std::ios::out);
635 logger(
WARN,
"Error in writeToFile: file % could not be opened", fileName);
638 file <<
"<?xml version=\"1.0\"?>\n\n";
639 file <<
"<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\">\n";
640 file <<
"<UnstructuredGrid>\n";
641 file <<
"<Piece NumberOfPoints=\"" << this->
getNumberOfObjects() <<
"\" NumberOfCells=\"" << 0 <<
"\">\n";
642 file <<
"<Points>\n";
643 file <<
" <DataArray type=\"Float32\" Name=\"Position\" NumberOfComponents=\"3\" format=\"ascii\">\n";
644 for (
const auto& p: *
this)
646 file <<
'\t' << p->getPosition() <<
'\n';
648 file <<
" </DataArray>\n";
649 file <<
"</Points>\n";
650 file <<
"<PointData Vectors=\"vector\">\n";
651 file <<
" <DataArray type=\"Float32\" Name=\"Velocity\" NumberOfComponents=\"3\" format=\"ascii\">\n";
653 for (
const auto& p: *
this)
655 file <<
'\t' << p->getVelocity() <<
'\n';
657 file <<
" </DataArray>\n";
658 file <<
" <DataArray type=\"Float32\" Name=\"Radius\" format=\"ascii\">\n";
660 for (
const auto& p: *
this)
662 file <<
'\t' << p->getRadius() <<
'\n';
664 file <<
" </DataArray>\n";
665 file <<
" <DataArray type=\"Float32\" Name=\"SpeciesType\" format=\"ascii\">\n";
667 for (
const auto& p: *
this)
669 file <<
'\t' << p->getIndSpecies() <<
'\n';
671 file <<
" </DataArray>\n";
672 file <<
" <DataArray type=\"Float32\" Name=\"Info\" format=\"ascii\">\n";
674 for (
const auto& p: *
this)
678 file <<
" </DataArray>\n";
686 for (
const auto &p: *
this)
688 for (
auto f : p->getFieldVTK(i))
689 file <<
'\t' << f <<
'\n';
691 file <<
" </DataArray>\n";
694 file <<
"</PointData>\n";
696 file <<
" <DataArray type=\"Int32\" Name=\"connectivity\" format=\"ascii\">\n";
697 file <<
" </DataArray>\n";
698 file <<
" <DataArray type=\"Int32\" Name=\"offsets\" format=\"ascii\">\n";
699 file <<
" </DataArray>\n";
700 file <<
" <DataArray type=\"UInt8\" Name=\"types\" format=\"ascii\">\n";
701 file <<
" </DataArray>\n";
702 file <<
"</Cells>\n";
703 file <<
"</Piece>\n";
704 file <<
"</UnstructuredGrid>\n";
705 file <<
"</VTKFile>\n";
BaseParticle * getLargestParticle() const
Gets a pointer to the largest BaseParticle (by interactionRadius) in this ParticleHandler.
unsigned int getId() const
Returns the unique identifier of any particular object.
virtual void hGridUpdateParticle(BaseParticle *obj UNUSED)
no implementation but can be overidden in its derived classes.
void checkExtremaOnDelete(BaseParticle *P)
Checks if the extrema of this ParticleHandler needs updating when a particle is deleted.
void write(std::ostream &os) const
virtual void hGridInsertParticle(BaseParticle *obj UNUSED)
no implementation but can be overidden in its derived classes.
Mdouble X
the vector components
void writeVTK() const
Writes all particles into a vtk file format (unstructured grid), consisting of particle positions...
virtual void removeObject(unsigned const int index)
Removes a BaseParticle from the ParticleHandler.
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
void checkExtrema(BaseParticle *P)
Checks if the extrema of this ParticleHandler needs updating.
void setDPMBase(DPMBase *DPMBase)
Sets the problem that is solved using this handler.
BaseParticle * getLowestVelocityComponentParticle(const int i) const
Gets a pointer to the particle with the lowest velocity in direction i in this ParticleHandler.
const ParticleSpecies * getSpecies() const
Returns a pointer to the species of this BaseInteractable.
std::string getName() const
Returns the name of the handler, namely the string "ParticleHandler".
void setHandler(ParticleHandler *handler)
Sets the pointer to the particle's ParticleHandler.
BaseParticle * getLightestParticle() const
Gets a pointer to the lightest BaseParticle (by mass) in this ParticleHandler.
void computeMass(BaseParticle *p) const
Compute Particle mass function, which required a reference to the Species vector. It computes the Par...
void computeAllMasses()
Computes the mass for all BaseParticle in this ParticleHandler.
void readObject(std::istream &is)
Reads BaseParticle into the ParticleHandler from restart data.
void setSpecies(const ParticleSpecies *species)
BaseParticle * smallestParticle_
A pointer to the smallest BaseParticle (by interactionRadius) in this ParticleHandler.
void removeLastObject()
Removes the last Object from the BaseHandler.
void clear()
Empties the whole ParticleHandler by removing all BaseParticle.
BaseParticle * getSmallestParticle() const
Gets a pointer to the smallest BaseParticle (by interactionRadius) in this ParticleHandler.
void getLineFromStringStream(std::istream &in, std::stringstream &out)
Reads a line from one stringstream into another, and prepares the latter for reading in...
virtual void removeObject(unsigned const int id)
Removes an Object from the BaseHandler.
void removeLastObject()
Removes the last BaseParticle from the ParticleHandler.
BaseParticle * getObject(const unsigned int id)
Gets a pointer to the Object at the specified index in the BaseHandler.
virtual void addObject(BaseParticle *P)
Adds a BaseParticle to the ParticleHandler.
void readOldObject(std::string type, std::istream &is)
Reads BaseParticle into the ParticleHandler from old-style restart data.
ParticleHandler()
Default constructor, it creates an empty ParticleHandler.
BaseParticle * largestParticle_
A pointer to the largest BaseParticle (by interactionRadius) in this ParticleHandler.
~ParticleHandler()
Destructor, it destructs the ParticleHandler and all BaseParticle it contains.
BaseParticle * getHighestVelocityComponentParticle(const int i) const
Gets a pointer to the particle with the highest velocity in direction i in this ParticleHandler.
std::enable_if<!std::is_pointer< U >::value, U * >::type copyAndAddObject(const U &object)
Creates a copy of a Object and adds it to the BaseHandler.
std::vector< BaseParticle * > objects_
The actual list of Object pointers.
Container to store the pointers to all objects that one creates in a simulation.
unsigned int getNumberOfObjects() const
Gets the number of Object in this BaseHandler.
Container to store all BaseParticle.
std::string to_string(const T &n)
virtual void hGridRemoveParticle(BaseParticle *obj UNUSED)
no implementation but can be overidden in its derived classes.
virtual std::string getTypeVTK(unsigned i) const
virtual double getInfo(const BaseParticle &P) const
A virtual method that allows the user to overrride and set what is written into the info column in th...
void computeSmallestParticle()
Computes the smallest particle (by interaction radius) and sets it in smallestParticle_.
BaseParticle * getHighestPositionComponentParticle(const int i) const
Gets a pointer to the particle with the highest coordinates in direction i in this ParticleHandler...
virtual MERCURY_DEPRECATED void oldRead(std::istream &is)
deprecated version of the read function.
void setId(BaseParticle *object, unsigned int id)
This function sets the id and ensures that nextId is a bigger value than id.
void computeLargestParticle()
Computes the largest particle (by interaction radius) and sets it in largestParticle_.
Mdouble getMeanRadius() const
Gets a pointer to the fastest BaseParticle in this ParticleHandler.
virtual void addObject(T *object)
Adds a new Object to the BaseHandler.
virtual std::string getNameVTK(unsigned i) const
unsigned int getIndSpecies() const
Returns the index of the Species of this BaseInteractable.
BaseParticle * getLastObject()
Gets a pointer to the last Object in this BaseHandler.
void copyContentsFromOtherHandler(const BaseHandler< BaseParticle > &BH)
Function that copies the contents (vector of pointers, maxObject_, nextId_, DPMBase_) from one handle...
Implementation of a 3D vector (by Vitaliy).
static BaseParticle * getNewObject(const std::string &type)
DPMBase * getDPMBase()
Gets the problem that is solved using this handler.
virtual unsigned getNumberOfFieldsVTK() const
BaseParticle * getLowestPositionComponentParticle(const int i) const
Gets a pointer to the particle with the lowest coordinates in direction i in this ParticleHandler...
Mdouble getInteractionRadius() const
Returns the particle's interaction radius, which might be different from radius_ (e.g., when dealing with wet particles)
const std::string & getName() const
Returns the name of the file. Does not allow to change it though.
ParticleHandler operator=(const ParticleHandler &rhs)
Assignment operator.
void clear()
Empties the whole BaseHandler by removing all Objects and setting all other variables to 0...
BaseParticle * getFastestParticle() const
Gets a pointer to the fastest BaseParticle in this ParticleHandler.