Mercury3D Class Reference

This adds on the hierarchical grid code for 3D problems. More...

#include <Mercury3D.h>

+ Inheritance diagram for Mercury3D:

Public Member Functions

 Mercury3D ()
 This is the default constructor. All it does is set sensible defaults. More...
 
 Mercury3D (const DPMBase &other)
 Copy-constructor for creates an Mercury3D problem from an existing MD problem. More...
 
 Mercury3D (const Mercury3D &other)
 Copy-constructor. More...
 
void constructor ()
 Function that sets the SystemDimension and ParticleDimension to 3. More...
 
std::vector< BaseParticle * > hGridFindParticleContacts (const BaseParticle *obj) override
 Returns all particles that have a contact with a given particle. More...
 
- Public Member Functions inherited from MercuryBase
 MercuryBase ()
 This is the default constructor. It sets sensible defaults. More...
 
 ~MercuryBase () override
 This is the default destructor. More...
 
 MercuryBase (const MercuryBase &mercuryBase)
 Copy-constructor. More...
 
void constructor ()
 This is the actual constructor, it is called do both constructors above. More...
 
void hGridActionsBeforeTimeLoop () override
 This sets up the broad phase information, has to be done at this stage because it requires the particle size. More...
 
void hGridActionsBeforeTimeStep () override
 Performs all necessary actions before a time-step, like updating the particles and resetting all the bucket information, etc. More...
 
void read (std::istream &is, ReadOptions opt=ReadOptions::ReadAll) override
 Reads the MercuryBase from an input stream, for example a restart file. More...
 
void write (std::ostream &os, bool writeAllParticles=true) const override
 Writes all data into a restart file. More...
 
Mdouble getHGridCurrentMaxRelativeDisplacement () const
 Returns hGridCurrentMaxRelativeDisplacement_. More...
 
Mdouble getHGridTotalCurrentMaxRelativeDisplacement () const
 Returns hGridTotalCurrentMaxRelativeDisplacement_. More...
 
void setHGridUpdateEachTimeStep (bool updateEachTimeStep)
 Sets whether or not the HGrid must be updated every time step. More...
 
bool getHGridUpdateEachTimeStep () const final
 Gets whether or not the HGrid is updated every time step. More...
 
void setHGridMaxLevels (unsigned int HGridMaxLevels)
 Sets the maximum number of levels of the HGrid in this MercuryBase. More...
 
unsigned int getHGridMaxLevels () const
 Gets the maximum number of levels of the HGrid in this MercuryBase. More...
 
HGridMethod getHGridMethod () const
 Gets whether the HGrid in this MercuryBase is BOTTOMUP or TOPDOWN. More...
 
void setHGridMethod (HGridMethod hGridMethod)
 Sets the HGridMethod to either BOTTOMUP or TOPDOWN. More...
 
HGridDistribution getHGridDistribution () const
 Gets how the sizes of the cells of different levels are distributed. More...
 
void setHGridDistribution (HGridDistribution hGridDistribution)
 Sets how the sizes of the cells of different levels are distributed. More...
 
Mdouble getHGridCellOverSizeRatio () const
 Gets the ratio of the smallest cell over the smallest particle. More...
 
void setHGridCellOverSizeRatio (Mdouble cellOverSizeRatio)
 Sets the ratio of the smallest cell over the smallest particle. More...
 
bool hGridNeedsRebuilding ()
 Gets if the HGrid needs rebuilding before anything else happens. More...
 
virtual unsigned int getHGridTargetNumberOfBuckets () const
 Gets the desired number of buckets, which is the maximum of the number of particles and 10. More...
 
virtual Mdouble getHGridTargetMinInteractionRadius () const
 Gets the desired size of the smallest cells of the HGrid. More...
 
virtual Mdouble getHGridTargetMaxInteractionRadius () const
 Gets the desired size of the largest cells of the HGrid. More...
 
bool checkParticleForInteraction (const BaseParticle &P) final
 Checks if given BaseParticle has an interaction with a BaseWall or other BaseParticle. More...
 
bool checkParticleForInteractionLocal (const BaseParticle &P) final
 Checks if the given BaseParticle has an interaction with a BaseWall or other BaseParticles in a local domain. More...
 
virtual Mdouble userHGridCellSize (unsigned int level)
 Virtual function that enables inheriting classes to implement a function to let the user set the cell size of the HGrid. More...
 
void hGridInfo (std::ostream &os=std::cout) const
 Writes the info of the HGrid to the screen in a nice format. More...
 
- Public Member Functions inherited from DPMBase
void constructor ()
 A function which initialises the member variables to default values, so that the problem can be solved off the shelf; sets up a basic two dimensional problem which can be solved off the shelf. It is called in the constructor DPMBase(). More...
 
 DPMBase ()
 Constructor that calls the "void constructor()". More...
 
 DPMBase (const DPMBase &other)
 Copy constructor type-2. More...
 
virtual ~DPMBase ()
 virtual destructor More...
 
void autoNumber ()
 The autoNumber() function calls three functions: setRunNumber(), readRunNumberFromFile() and incrementRunNumberInFile(). More...
 
std::vector< int > get1DParametersFromRunNumber (int size_x) const
 This turns a counter into 1 index, which is a useful feature for performing 1D parameter study. The index run from 1:size_x, while the study number starts at 0 (initially the counter=1 in COUNTER_DONOTDEL) More...
 
std::vector< int > get2DParametersFromRunNumber (int size_x, int size_y) const
 This turns a counter into 2 indices which is a very useful feature for performing a 2D study. The indices run from 1:size_x and 1:size_y, while the study number starts at 0 ( initially the counter=1 in COUNTER_DONOTDEL) More...
 
std::vector< int > get3DParametersFromRunNumber (int size_x, int size_y, int size_z) const
 This turns a counter into 3 indices, which is a useful feature for performing a 3D parameter study. The indices run from 1:size_x, 1:size_y and 1:size_z, while the study number starts at 0 ( initially the counter=1 in COUNTER_DONOTDEL) More...
 
int launchNewRun (const char *name, bool quick=false)
 This launches a code from within this code. Please pass the name of the code to run. More...
 
void setRunNumber (int runNumber)
 This sets the counter/Run number, overriding the defaults. More...
 
int getRunNumber () const
 This returns the current value of the counter (runNumber_) More...
 
virtual void decompose ()
 Sends particles from processorId to the root processor. More...
 
void solve ()
 The work horse of the code. More...
 
void initialiseSolve ()
 Beginning of the solve routine, before time stepping. More...
 
void finaliseSolve ()
 End of the solve routine, after time stepping. More...
 
virtual void computeOneTimeStep ()
 Performs everything needed for one time step, used in the time-loop of solve(). More...
 
void checkSettings ()
 Checks if the essentials are set properly to go ahead with solving the problem. More...
 
void forceWriteOutputFiles ()
 Writes output files immediately, even if the current time step was not meant to be written. Also resets the last saved time step. More...
 
virtual void writeOutputFiles ()
 Writes simulation data to all the main Mercury files: .data, .ene, .fstat, .xballs and .restart (see the Mercury website for more details regarding these files). More...
 
void solve (int argc, char *argv[])
 The work horse of the code. Can handle flags from the command line. More...
 
virtual void setupInitialConditions ()
 This function allows to set the initial conditions for our problem to be solved, by default particle locations are randomly set. Remember particle properties must also be defined here. More...
 
virtual void writeXBallsScript () const
 This writes a script which can be used to load the xballs problem to display the data just generated. More...
 
virtual Mdouble getInfo (const BaseParticle &P) const
 A virtual function that returns some user-specified information about a particle. More...
 
ParticleVtkWritergetVtkWriter () const
 
virtual void writeRestartFile ()
 Stores all the particle data for current save time step to a "restart" file, which is a file simply intended to store all the information necessary to "restart" a simulation from a given time step (see also MercuryDPM.org for more information on restart files). More...
 
void writeDataFile ()
 
void writeEneFile ()
 
void writeFStatFile ()
 
void fillDomainWithParticles (unsigned N=50)
 
bool readRestartFile (ReadOptions opt=ReadOptions::ReadAll)
 Reads all the particle data corresponding to a given, existing . restart file (for more details regarding restart files, refer to the training materials on the MercuryDPM website).Returns true if it is successful, false otherwise. More...
 
int readRestartFile (std::string fileName, ReadOptions opt=ReadOptions::ReadAll)
 The same as readRestartFile(bool), but also reads all the particle data corresponding to the current saved time step. More...
 
virtual BaseWallreadUserDefinedWall (const std::string &type) const
 Allows you to read in a wall defined in a Driver directory; see USER/Luca/ScrewFiller. More...
 
virtual void readOld (std::istream &is)
 Reads all data from a restart file, e.g. domain data and particle data; old version. More...
 
bool readDataFile (std::string fileName="", unsigned int format=0)
 This allows particle data to be reloaded from data files. More...
 
bool readParAndIniFiles (std::string fileName)
 Allows the user to read par.ini files (useful to read files produced by the MDCLR simulation code - external to MercuryDPM) More...
 
bool readNextDataFile (unsigned int format=0)
 Reads the next data file with default format=0. However, one can modify the format based on whether the particle data corresponds to 3D or 2D data- see Visualising data in xballs. More...
 
void readNextFStatFile ()
 Reads the next fstat file. More...
 
bool findNextExistingDataFile (Mdouble tMin, bool verbose=true)
 Finds and opens the next data file, if such a file exists. More...
 
bool readArguments (int argc, char *argv[])
 Can interpret main function input arguments that are passed by the driver codes. More...
 
bool checkParticleForInteractionLocalPeriodic (const BaseParticle &P)
 
void readSpeciesFromDataFile (bool read=true)
 
void importParticlesAs (ParticleHandler &particleHandler, InteractionHandler &interactionHandler, const ParticleSpecies *species)
 Copies particles, interactions assigning species from a local simulation to a global one. Useful for the creation of a cluster. More...
 
MERCURYDPM_DEPRECATED FilegetDataFile ()
 The non const version. Allows one to edit the File::dataFile. More...
 
MERCURYDPM_DEPRECATED FilegetEneFile ()
 The non const version. Allows to edit the File::eneFile. More...
 
MERCURYDPM_DEPRECATED FilegetFStatFile ()
 The non const version. Allows to edit the File::fStatFile. More...
 
MERCURYDPM_DEPRECATED FilegetRestartFile ()
 The non const version. Allows to edit the File::restartFile. More...
 
MERCURYDPM_DEPRECATED FilegetStatFile ()
 The non const version. Allows to edit the File::statFile. More...
 
FilegetInteractionFile ()
 Return a reference to the file InteractionsFile. More...
 
MERCURYDPM_DEPRECATED const FilegetDataFile () const
 The const version. Does not allow for any editing of the File::dataFile. More...
 
MERCURYDPM_DEPRECATED const FilegetEneFile () const
 The const version. Does not allow for any editing of the File::eneFile. More...
 
MERCURYDPM_DEPRECATED const FilegetFStatFile () const
 The const version. Does not allow for any editing of the File::fStatFile. More...
 
MERCURYDPM_DEPRECATED const FilegetRestartFile () const
 The const version. Does not allow for any editing of the File::restartFile. More...
 
MERCURYDPM_DEPRECATED const FilegetStatFile () const
 The const version. Does not allow for any editing of the File::statFile. More...
 
const FilegetInteractionFile () const
 
const std::string & getName () const
 Returns the name of the file. Does not allow to change it though. More...
 
void setName (const std::string &name)
 Allows to set the name of all the files (ene, data, fstat, restart, stat) More...
 
void setName (const char *name)
 Calls setName(std::string) More...
 
void setSaveCount (unsigned int saveCount)
 Sets File::saveCount_ for all files (ene, data, fstat, restart, stat) More...
 
void setFileType (FileType fileType)
 Sets File::fileType_ for all files (ene, data, fstat, restart, stat) More...
 
void setOpenMode (std::fstream::openmode openMode)
 Sets File::openMode_ for all files (ene, data, fstat, restart, stat) More...
 
void resetFileCounter ()
 Resets the file counter for each file i.e. for ene, data, fstat, restart, stat) More...
 
void closeFiles ()
 Closes all files (ene, data, fstat, restart, stat) that were opened to read or write. More...
 
void setLastSavedTimeStep (unsigned int nextSavedTimeStep)
 Sets the next time step for all the files (ene, data, fstat, restart, stat) at which the data is to be written or saved. More...
 
Mdouble getTime () const
 Returns the current simulation time. More...
 
Mdouble getNextTime () const
 Returns the current simulation time. More...
 
unsigned int getNumberOfTimeSteps () const
 Returns the current counter of time-steps, i.e. the number of time-steps that the simulation has undergone so far. More...
 
void setTime (Mdouble time)
 Sets a new value for the current simulation time. More...
 
void setTimeMax (Mdouble newTMax)
 Sets a new value for the maximum simulation duration. More...
 
Mdouble getTimeMax () const
 Returns the maximum simulation duration. More...
 
void setLogarithmicSaveCount (Mdouble logarithmicSaveCountBase)
 Sets File::logarithmicSaveCount_ for all files (ene, data, fstat, restart, stat) More...
 
void setNToWrite (int nToWrite)
 set the number of elements to write to the screen More...
 
int getNToWrite () const
 get the number of elements to write to the More...
 
void setRotation (bool rotation)
 Sets whether particle rotation is enabled or disabled. More...
 
bool getRotation () const
 Indicates whether particle rotation is enabled or disabled. More...
 
MERCURYDPM_DEPRECATED void setWallsWriteVTK (FileType writeWallsVTK)
 Sets whether walls are written into a VTK file. More...
 
MERCURYDPM_DEPRECATED void setWallsWriteVTK (bool)
 Sets whether walls are written into a VTK file. More...
 
MERCURYDPM_DEPRECATED void setInteractionsWriteVTK (bool)
 Sets whether interactions are written into a VTK file. More...
 
void setParticlesWriteVTK (bool writeParticlesVTK)
 Sets whether particles are written in a VTK file. More...
 
void setSuperquadricParticlesWriteVTK (bool writeSuperquadricParticlesVTK)
 
MERCURYDPM_DEPRECATED FileType getWallsWriteVTK () const
 Returns whether walls are written in a VTK file. More...
 
bool getParticlesWriteVTK () const
 Returns whether particles are written in a VTK file. More...
 
bool getSuperquadricParticlesWriteVTK () const
 
Mdouble getXMin () const
 If the length of the problem domain in x-direction is XMax - XMin, then getXMin() returns XMin. More...
 
Mdouble getXMax () const
 If the length of the problem domain in x-direction is XMax - XMin, then getXMax() returns XMax. More...
 
Mdouble getYMin () const
 If the length of the problem domain in y-direction is YMax - YMin, then getYMin() returns YMin. More...
 
Mdouble getYMax () const
 If the length of the problem domain in y-direction is YMax - YMin, then getYMax() returns XMax. More...
 
Mdouble getZMin () const
 If the length of the problem domain in z-direction is ZMax - ZMin, then getZMin() returns ZMin. More...
 
Mdouble getZMax () const
 If the length of the problem domain in z-direction is ZMax - ZMin, then getZMax() returns ZMax. More...
 
Mdouble getXCenter () const
 
Mdouble getYCenter () const
 
Mdouble getZCenter () const
 
Vec3D getMin () const
 
Vec3D getMax () const
 
void setXMin (Mdouble newXMin)
 Sets the value of XMin, the lower bound of the problem domain in the x-direction. More...
 
void setYMin (Mdouble newYMin)
 Sets the value of YMin, the lower bound of the problem domain in the y-direction. More...
 
void setZMin (Mdouble newZMin)
 Sets the value of ZMin, the lower bound of the problem domain in the z-direction. More...
 
void setXMax (Mdouble newXMax)
 Sets the value of XMax, the upper bound of the problem domain in the x-direction. More...
 
void setYMax (Mdouble newYMax)
 Sets the value of YMax, the upper bound of the problem domain in the y-direction. More...
 
void setZMax (Mdouble newZMax)
 Sets the value of ZMax, the upper bound of the problem domain in the z-direction. More...
 
void setMax (const Vec3D &max)
 Sets the maximum coordinates of the problem domain. More...
 
void setMax (Mdouble, Mdouble, Mdouble)
 Sets the maximum coordinates of the problem domain. More...
 
void setDomain (const Vec3D &min, const Vec3D &max)
 Sets the minimum coordinates of the problem domain. More...
 
void setMin (const Vec3D &min)
 Sets the minimum coordinates of the problem domain. More...
 
void setMin (Mdouble, Mdouble, Mdouble)
 Sets the minimum coordinates of the problem domain. More...
 
void setTimeStep (Mdouble newDt)
 Sets a new value for the simulation time step. More...
 
Mdouble getTimeStep () const
 Returns the simulation time step. More...
 
void setNumberOfOMPThreads (int numberOfOMPThreads)
 
int getNumberOfOMPThreads () const
 
void setXBallsColourMode (int newCMode)
 Set the xballs output mode. More...
 
int getXBallsColourMode () const
 Get the xballs colour mode (CMode). More...
 
void setXBallsVectorScale (double newVScale)
 Set the scale of vectors in xballs. More...
 
double getXBallsVectorScale () const
 Returns the scale of vectors used in xballs. More...
 
void setXBallsAdditionalArguments (std::string newXBArgs)
 Set the additional arguments for xballs. More...
 
std::string getXBallsAdditionalArguments () const
 Returns the additional arguments for xballs. More...
 
void setXBallsScale (Mdouble newScale)
 Sets the scale of the view (either normal, zoom in or zoom out) to display in xballs. The default is fit to screen. More...
 
double getXBallsScale () const
 Returns the scale of the view in xballs. More...
 
void setGravity (Vec3D newGravity)
 Sets a new value for the gravitational acceleration. More...
 
Vec3D getGravity () const
 Returns the gravitational acceleration. More...
 
void setBackgroundDrag (Mdouble backgroundDrag)
 Simple access function to turn on a background drag. The force of particleVelocity*drag is applied (note, it allowd to be negaitve i.e. create energy) More...
 
const Mdouble getBackgroundDrag () const
 Return the background drag. More...
 
void setDimension (unsigned int newDim)
 Sets both the system dimensions and the particle dimensionality. More...
 
void setSystemDimensions (unsigned int newDim)
 Sets the system dimensionality. More...
 
unsigned int getSystemDimensions () const
 Returns the system dimensionality. More...
 
void setParticleDimensions (unsigned int particleDimensions)
 Sets the particle dimensionality. More...
 
unsigned int getParticleDimensions () const
 Returns the particle dimensionality. More...
 
std::string getRestartVersion () const
 This is to take into account for different Mercury versions. Returns the version of the restart file. More...
 
void setRestartVersion (std::string newRV)
 Sets restart_version. More...
 
bool getRestarted () const
 Returns the flag denoting if the simulation was restarted or not. More...
 
void setRestarted (bool newRestartedFlag)
 Allows to set the flag stating if the simulation is to be restarted or not. More...
 
bool getAppend () const
 Returns whether the "append" option is on or off. More...
 
void setAppend (bool newAppendFlag)
 Sets whether the "append" option is on or off. More...
 
Mdouble getElasticEnergy () const
 Returns the global elastic energy within the system. More...
 
Mdouble getKineticEnergy () const
 Returns the global kinetic energy stored in the system. More...
 
Mdouble getGravitationalEnergy () const
 Returns the global gravitational potential energy stored in the system. More...
 
Mdouble getRotationalEnergy () const
 JMFT Returns the global rotational energy stored in the system. More...
 
Mdouble getTotalEnergy () const
 
Mdouble getTotalMass () const
 JMFT: Return the total mass of the system, excluding fixed particles. More...
 
Vec3D getCentreOfMass () const
 JMFT: Return the centre of mass of the system, excluding fixed particles. More...
 
Vec3D getTotalMomentum () const
 JMFT: Return the total momentum of the system, excluding fixed particles. More...
 
double getCPUTime ()
 
double getWallTime ()
 
virtual void hGridInsertParticle (BaseParticle *obj UNUSED)
 
virtual void hGridUpdateParticle (BaseParticle *obj UNUSED)
 
virtual void hGridRemoveParticle (BaseParticle *obj UNUSED)
 
bool mpiIsInCommunicationZone (BaseParticle *particle)
 Checks if the position of the particle is in an mpi communication zone or not. More...
 
bool mpiInsertParticleCheck (BaseParticle *P)
 Function that checks if the mpi particle should really be inserted by the current domain. More...
 
void insertGhostParticle (BaseParticle *P)
 This function inserts a particle in the mpi communication boundaries. More...
 
void updateGhostGrid (BaseParticle *P)
 Checks if the Domain/periodic interaction distance needs to be updated and updates it accordingly. More...
 
virtual void gatherContactStatistics (unsigned int index1, int index2, Vec3D Contact, Mdouble delta, Mdouble ctheta, Mdouble fdotn, Mdouble fdott, Vec3D P1_P2_normal_, Vec3D P1_P2_tangential)
 //Not unsigned index because of possible wall collisions. More...
 
void setNumberOfDomains (std::vector< unsigned > direction)
 Sets the number of domains in x-,y- and z-direction. Required for parallel computations. More...
 
void splitDomain (DomainSplit domainSplit)
 
std::vector< unsigned > getNumberOfDomains ()
 returns the number of domains More...
 
DomaingetCurrentDomain ()
 Function that returns a pointer to the domain corresponding to the processor. More...
 
void removeOldFiles () const
 
void setMeanVelocity (Vec3D V_mean_goal)
 This function will help you set a fixed kinetic energy and mean velocity in your system. More...
 
void setMeanVelocityAndKineticEnergy (Vec3D V_mean_goal, Mdouble Ek_goal)
 This function will help you set a fixed kinetic energy and mean velocity in your system. More...
 
Mdouble getTotalVolume () const
 Get the total volume of the cuboid system. More...
 
Matrix3D getKineticStress () const
 Calculate the kinetic stress tensor in the system averaged over the whole volume. More...
 
Matrix3D getStaticStress () const
 Calculate the static stress tensor in the system averaged over the whole volume. More...
 
Matrix3D getTotalStress () const
 Calculate the total stress tensor in the system averaged over the whole volume. More...
 
virtual void handleParticleRemoval (unsigned int id)
 Handles the removal of particles from the particleHandler. More...
 
virtual void handleParticleAddition (unsigned int id, BaseParticle *p)
 
void writePythonFileForVTKVisualisation () const
 
void setWritePythonFileForVTKVisualisation (bool forceWritePythonFileForVTKVisualisation)
 
bool getWritePythonFileForVTKVisualisation () const
 
WallVTKWritergetWallVTKWriter ()
 

Protected Member Functions

void hGridFindContactsWithinTargetCell (int x, int y, int z, unsigned int l)
 Finds contacts between particles in the target cell. More...
 
void hGridFindContactsWithTargetCell (int x, int y, int z, unsigned int l, BaseParticle *obj)
 Finds contacts between the BaseParticle and the target cell. More...
 
void computeWallForces (BaseWall *w) override
 Compute contacts with a wall. More...
 
void hGridFindParticlesWithTargetCell (int x, int y, int z, unsigned int l, BaseParticle *obj, std::vector< BaseParticle * > &list)
 Finds particles within target cell and stores them in a list. More...
 
void hGridGetInteractingParticleList (BaseParticle *obj, std::vector< BaseParticle * > &list) override
 Obtains all neighbour particles of a given object, obtained from the hgrid. More...
 
void computeInternalForces (BaseParticle *obj) override
 Finds contacts with the BaseParticle; avoids multiple checks. More...
 
bool hGridHasContactsInTargetCell (int x, int y, int z, unsigned int l, const BaseParticle *obj) const
 Tests if the BaseParticle has contacts with other Particles in the target cell. More...
 
bool hGridHasParticleContacts (const BaseParticle *obj) override
 Tests if a BaseParticle has any contacts in the HGrid. More...
 
void hGridRemoveParticle (BaseParticle *obj) override
 Removes a BaseParticle from the HGrid. More...
 
void hGridUpdateParticle (BaseParticle *obj) override
 Updates the cell (not the level) of a BaseParticle. More...
 
- Protected Member Functions inherited from MercuryBase
void hGridRebuild ()
 This sets up the parameters required for the contact model. More...
 
void hGridInsertParticle (BaseParticle *obj) final
 Inserts a single Particle to current grid. More...
 
void hGridUpdateMove (BaseParticle *iP, Mdouble move) final
 Computes the relative displacement of the given BaseParticle and updates the currentMaxRelativeDisplacement_ accordingly. More...
 
void hGridActionsBeforeIntegration () override
 Resets the currentMaxRelativeDisplacement_ to 0. More...
 
void hGridActionsAfterIntegration () override
 This function has to be called before integrateBeforeForceComputation. More...
 
HGridgetHGrid ()
 Gets the HGrid used by this problem. More...
 
const HGridgetHGrid () const
 Gets the HGrid used by this problem, const version. More...
 
bool readNextArgument (int &i, int argc, char *argv[]) override
 Reads the next command line argument. More...
 
- Protected Member Functions inherited from DPMBase
virtual void computeAllForces ()
 Computes all the forces acting on the particles using the BaseInteractable::setForce() and BaseInteractable::setTorque() More...
 
virtual void computeInternalForce (BaseParticle *, BaseParticle *)
 Computes the forces between two particles (internal in the sense that the sum over all these forces is zero i.e. fully modelled forces) More...
 
virtual void computeExternalForces (BaseParticle *)
 Computes the external forces, such as gravity, acting on particles. More...
 
virtual void computeForcesDueToWalls (BaseParticle *, BaseWall *)
 Computes the forces on the particles due to the walls (normals are outward normals) More...
 
virtual void actionsOnRestart ()
 A virtual function where the users can add extra code which is executed only when the code is restarted. More...
 
virtual void actionsBeforeTimeLoop ()
 A virtual function. Allows one to carry out any operations before the start of the time loop. More...
 
virtual void actionsBeforeTimeStep ()
 A virtual function which allows to define operations to be executed before the new time step. More...
 
virtual void computeAdditionalForces ()
 A virtual function which allows to define operations to be executed prior to the OMP force collect. More...
 
virtual void actionsAfterSolve ()
 A virtual function which allows to define operations to be executed after the solve(). More...
 
virtual void actionsAfterTimeStep ()
 A virtual function which allows to define operations to be executed after time step. More...
 
void writeVTKFiles () const
 
virtual void outputXBallsData (std::ostream &os) const
 This function writes the location of the walls and particles in a format the XBalls program can read. For more information on the XBalls program, see Visualising data in xballs. More...
 
virtual void outputXBallsDataParticle (unsigned int i, unsigned int format, std::ostream &os) const
 This function writes out the particle locations into an output stream in a format the XBalls program can read. For more information on the XBalls program, see Visualising data in xballs. More...
 
virtual void writeEneHeader (std::ostream &os) const
 Writes a header with a certain format for ENE file. More...
 
virtual void writeFstatHeader (std::ostream &os) const
 Writes a header with a certain format for FStat file. More...
 
virtual void writeEneTimeStep (std::ostream &os) const
 Write the global kinetic, potential energy, etc. in the system. More...
 
virtual void initialiseStatistics ()
 
virtual void outputStatistics ()
 
void gatherContactStatistics ()
 
virtual void processStatistics (bool)
 
virtual void finishStatistics ()
 
virtual void integrateBeforeForceComputation ()
 Update particles' and walls' positions and velocities before force computation. More...
 
virtual void integrateAfterForceComputation ()
 Update particles' and walls' positions and velocities after force computation. More...
 
virtual void checkInteractionWithBoundaries ()
 There are a range of boundaries one could implement depending on ones' problem. This methods checks for interactions between particles and such range of boundaries. See BaseBoundary.h and all the boundaries in the Boundaries folder. More...
 
void setFixedParticles (unsigned int n)
 Sets a number, n, of particles in the particleHandler as "fixed particles". More...
 
virtual void printTime () const
 Displays the current simulation time and the maximum simulation duration. More...
 
virtual bool continueSolve () const
 A virtual function for deciding whether to continue the simulation, based on a user-specified criterion. More...
 
void outputInteractionDetails () const
 Displays the interaction details corresponding to the pointer objects in the interaction handler. More...
 
bool isTimeEqualTo (Mdouble time) const
 Checks whether the input variable "time" is the current time in the simulation. More...
 
void removeDuplicatePeriodicParticles ()
 Removes periodic duplicate Particles. More...
 
void checkAndDuplicatePeriodicParticles ()
 For simulations using periodic boundaries, checks and adds particles when necessary into the particle handler. See DPMBase.cc and PeriodicBoundary.cc for more details. More...
 
void performGhostParticleUpdate ()
 When the Verlet scheme updates the positions and velocities of particles, ghost particles will need an update as wel. Their status will also be updated accordingly. More...
 
void deleteGhostParticles (std::set< BaseParticle * > &particlesToBeDeleted)
 
void synchroniseParticle (BaseParticle *, unsigned fromProcessor=0)
 
void performGhostVelocityUpdate ()
 updates the final time-step velocity of the ghost particles More...
 
void setSoftStop ()
 function for setting sigaction constructor. More...
 

Additional Inherited Members

- Public Types inherited from DPMBase
enum class  ReadOptions : int { ReadAll , ReadNoInteractions , ReadNoParticlesAndInteractions }
 
enum class  DomainSplit {
  X , Y , Z , XY ,
  XZ , YZ , XYZ
}
 
- Static Public Member Functions inherited from DPMBase
static void incrementRunNumberInFile ()
 Increment the run Number (counter value) stored in the file_counter (COUNTER_DONOTDEL) by 1 and store the new value in the counter file. More...
 
static int readRunNumberFromFile ()
 Read the run number or the counter from the counter file (COUNTER_DONOTDEL) More...
 
static bool areInContact (const BaseParticle *pI, const BaseParticle *pJ)
 Checks if two particle are in contact or is there any positive overlap. More...
 
- Public Attributes inherited from DPMBase
SpeciesHandler speciesHandler
 A handler to that stores the species type i.e. LinearViscoelasticSpecies, etc. More...
 
RNG random
 This is a random generator, often used for setting up the initial conditions etc... More...
 
ParticleHandler particleHandler
 An object of the class ParticleHandler, contains the pointers to all the particles created. More...
 
ParticleHandler paoloParticleHandler
 Fake particleHandler created by Paolo needed temporary by just Paolo. More...
 
WallHandler wallHandler
 An object of the class WallHandler. Contains pointers to all the walls created. More...
 
BoundaryHandler boundaryHandler
 An object of the class BoundaryHandler which concerns insertion and deletion of particles into or from regions. More...
 
PeriodicBoundaryHandler periodicBoundaryHandler
 Internal handler that deals with periodic boundaries, especially in a parallel build. More...
 
DomainHandler domainHandler
 An object of the class DomainHandler which deals with parallel code. More...
 
InteractionHandler interactionHandler
 An object of the class InteractionHandler. More...
 
CGHandler cgHandler
 Object of the class cgHandler. More...
 
File dataFile
 An instance of class File to handle in- and output into a .data file. More...
 
File fStatFile
 An instance of class File to handle in- and output into a .fstat file. More...
 
File eneFile
 An instance of class File to handle in- and output into a .ene file. More...
 
File restartFile
 An instance of class File to handle in- and output into a .restart file. More...
 
File statFile
 An instance of class File to handle in- and output into a .stat file. More...
 
File interactionFile
 File class to handle in- and output into .interactions file. This file hold information about interactions. More...
 
Time clock_
 record when the simulation started More...
 
- Static Protected Member Functions inherited from DPMBase
static void signalHandler (int signal)
 signal handler function. More...
 

Detailed Description

This adds on the hierarchical grid code for 3D problems.

Constructor & Destructor Documentation

◆ Mercury3D() [1/3]

Mercury3D::Mercury3D ( )

This is the default constructor. All it does is set sensible defaults.

30 {
31  constructor();
32  logger(DEBUG, "Mercury3D::Mercury3D() finished");
33 }
Logger< MERCURYDPM_LOGLEVEL > logger("MercuryKernel")
Definition of different loggers with certain modules. A user can define its own custom logger here.
@ DEBUG
void constructor()
Function that sets the SystemDimension and ParticleDimension to 3.
Definition: Mercury3D.cc:59

References constructor(), DEBUG, and logger.

◆ Mercury3D() [2/3]

Mercury3D::Mercury3D ( const DPMBase other)
explicit

Copy-constructor for creates an Mercury3D problem from an existing MD problem.

Parameters
[in]otherDPMBase which has to be copied and converted to a Mercury3D.

Constructor that makes a Mercury3D out of a DPMBase. The "copy"-constructor of DPMBase has to be called because the link from DPMBase to MercuryBase is virtual.

53  : DPMBase(other), MercuryBase()
54 {
55  constructor();
56  logger(DEBUG, "Mercury3D::Mercury3D(DPMBase& other) constructor finished");
57 }
DPMBase()
Constructor that calls the "void constructor()".
Definition: DPMBase.cc:194
MercuryBase()
This is the default constructor. It sets sensible defaults.
Definition: MercuryBase.cc:31

References constructor(), DEBUG, and logger.

◆ Mercury3D() [3/3]

Mercury3D::Mercury3D ( const Mercury3D other)

Copy-constructor.

Parameters
[in]otherMercury3D that must be copied.

Copy constructor, note that the copy-constructor of DPMBase has to be called because the link from DPMBase to MercuryBase is virtual.

41  : DPMBase(other), MercuryBase(other)
42 {
43  logger(DEBUG, "Mercury3D::Mercury3D(Mercury3D& other) copy constructor finished.");
44 }

References DEBUG, and logger.

Member Function Documentation

◆ computeInternalForces()

void Mercury3D::computeInternalForces ( BaseParticle obj)
overrideprotectedvirtual

Finds contacts with the BaseParticle; avoids multiple checks.

Parameters
[in]objA pointer to the BaseParticle for which we want to check for contacts.

Computes all collision between given BaseParticle and all other particles in the grid. Please note that we're looking only one way, so that interactions are not detected twice.

Reimplemented from DPMBase.

225 {
226  HGrid* const hgrid = getHGrid();
227  const unsigned int startLevel = obj->getHGridLevel();
228 
229  if (getHGridMethod() == TOPDOWN)
230  {
231  int occupiedLevelsMask = hgrid->getOccupiedLevelsMask();
232  for (unsigned int level = 0; level <= startLevel && occupiedLevelsMask != 0; occupiedLevelsMask >>= 1, level++)
233  {
234  // If no objects at this level, go on to the next level
235  if ((occupiedLevelsMask & 1) == 0)
236  {
237  continue;
238  }
239 
240  if (level == startLevel)
241  {
242  const int x = obj->getHGridX();
243  const int y = obj->getHGridY();
244  const int z = obj->getHGridZ();
245 
246  hGridFindContactsWithinTargetCell(x, y, z, level);
247  hGridFindContactsWithTargetCell(x + 1, y - 1, z, level, obj);
248  hGridFindContactsWithTargetCell(x + 1, y, z, level, obj);
249  hGridFindContactsWithTargetCell(x + 1, y + 1, z, level, obj);
250  hGridFindContactsWithTargetCell(x + 1, y - 1, z + 1, level, obj);
251  hGridFindContactsWithTargetCell(x + 1, y, z + 1, level, obj);
252  hGridFindContactsWithTargetCell(x + 1, y + 1, z + 1, level, obj);
253  hGridFindContactsWithTargetCell(x + 1, y - 1, z - 1, level, obj);
254  hGridFindContactsWithTargetCell(x + 1, y, z - 1, level, obj);
255  hGridFindContactsWithTargetCell(x + 1, y + 1, z - 1, level, obj);
256  hGridFindContactsWithTargetCell(x, y + 1, z, level, obj);
257  hGridFindContactsWithTargetCell(x, y, z - 1, level, obj);
258  hGridFindContactsWithTargetCell(x, y + 1, z - 1, level, obj);
259  hGridFindContactsWithTargetCell(x, y + 1, z + 1, level, obj);
260  }
261  else
262  {
263  const Mdouble inv_size = getHGrid()->getInvCellSize(level);
264  const int xs = static_cast<int>(std::floor(
265  (obj->getPosition().X - obj->getMaxInteractionRadius()) * inv_size - 0.5));
266  const int xe = static_cast<int>(std::floor(
267  (obj->getPosition().X + obj->getMaxInteractionRadius()) * inv_size + 0.5));
268  const int ys = static_cast<int>(std::floor(
269  (obj->getPosition().Y - obj->getMaxInteractionRadius()) * inv_size - 0.5));
270  const int ye = static_cast<int>(std::floor(
271  (obj->getPosition().Y + obj->getMaxInteractionRadius()) * inv_size + 0.5));
272  const int zs = static_cast<int>(std::floor(
273  (obj->getPosition().Z - obj->getMaxInteractionRadius()) * inv_size - 0.5));
274  const int ze = static_cast<int>(std::floor(
275  (obj->getPosition().Z + obj->getMaxInteractionRadius()) * inv_size + 0.5));
276  for (int x = xs; x <= xe; ++x)
277  {
278  for (int y = ys; y <= ye; ++y)
279  {
280  for (int z = zs; z <= ze; ++z)
281  {
282  hGridFindContactsWithTargetCell(x, y, z, level, obj);
283  }
284  }
285  }
286  }
287  }
288  }
289  else
290  {
291  int occupiedLevelsMask = hgrid->getOccupiedLevelsMask() >> obj->getHGridLevel();
292  for (unsigned int level = startLevel; level < hgrid->getNumberOfLevels(); occupiedLevelsMask >>= 1, level++)
293  {
294  // If no objects in rest of grid, stop now
295  if (occupiedLevelsMask == 0)
296  {
297  break;
298  }
299 
300  // If no objects at this level, go on to the next level
301  if ((occupiedLevelsMask & 1) == 0)
302  {
303  continue;
304  }
305 
306  if (level == startLevel)
307  {
308  const int x = obj->getHGridX();
309  const int y = obj->getHGridY();
310  const int z = obj->getHGridZ();
311 
312  hGridFindContactsWithinTargetCell(x, y, z, level);
313  hGridFindContactsWithTargetCell(x + 1, y - 1, z, level, obj);
314  hGridFindContactsWithTargetCell(x + 1, y, z, level, obj);
315  hGridFindContactsWithTargetCell(x + 1, y + 1, z, level, obj);
316  hGridFindContactsWithTargetCell(x + 1, y - 1, z + 1, level, obj);
317  hGridFindContactsWithTargetCell(x + 1, y, z + 1, level, obj);
318  hGridFindContactsWithTargetCell(x + 1, y + 1, z + 1, level, obj);
319  hGridFindContactsWithTargetCell(x + 1, y - 1, z - 1, level, obj);
320  hGridFindContactsWithTargetCell(x + 1, y, z - 1, level, obj);
321  hGridFindContactsWithTargetCell(x + 1, y + 1, z - 1, level, obj);
322  hGridFindContactsWithTargetCell(x, y + 1, z, level, obj);
323  hGridFindContactsWithTargetCell(x, y, z - 1, level, obj);
324  hGridFindContactsWithTargetCell(x, y + 1, z - 1, level, obj);
325  hGridFindContactsWithTargetCell(x, y + 1, z + 1, level, obj);
326  }
327  else
328  {
329  const Mdouble inv_size = hgrid->getInvCellSize(level);
330  const int xs = static_cast<int>(std::floor(
331  (obj->getPosition().X - obj->getMaxInteractionRadius()) * inv_size - 0.5));
332  const int xe = static_cast<int>(std::floor(
333  (obj->getPosition().X + obj->getMaxInteractionRadius()) * inv_size + 0.5));
334  const int ys = static_cast<int>(std::floor(
335  (obj->getPosition().Y - obj->getMaxInteractionRadius()) * inv_size - 0.5));
336  const int ye = static_cast<int>(std::floor(
337  (obj->getPosition().Y + obj->getMaxInteractionRadius()) * inv_size + 0.5));
338  const int zs = static_cast<int>(std::floor(
339  (obj->getPosition().Z - obj->getMaxInteractionRadius()) * inv_size - 0.5));
340  const int ze = static_cast<int>(std::floor(
341  (obj->getPosition().Z + obj->getMaxInteractionRadius()) * inv_size + 0.5));
342  for (int x = xs; x <= xe; ++x)
343  {
344  for (int y = ys; y <= ye; ++y)
345  {
346  for (int z = zs; z <= ze; ++z)
347  {
348  hGridFindContactsWithTargetCell(x, y, z, level, obj);
349  }
350  }
351  }
352  }
353  }
354  }
355 }
double Mdouble
Definition: GeneralDefine.h:34
@ TOPDOWN
Definition: MercuryBase.h:45
const Vec3D & getPosition() const
Returns the position of this BaseInteractable.
Definition: BaseInteractable.h:218
unsigned int getHGridLevel() const
Returns particle's HGrid level.
Definition: BaseParticle.h:234
Mdouble getMaxInteractionRadius() const
Returns the particle's interaction radius, which might be different from radius_ (e....
Definition: BaseParticle.h:362
int getHGridY() const
Returns particle's HGrid cell Y-coordinate.
Definition: BaseParticle.h:272
int getHGridX() const
Returns particle's HGrid cell X-coordinate.
Definition: BaseParticle.h:265
int getHGridZ() const
Returns particle's HGrid cell Z-coordinate.
Definition: BaseParticle.h:279
In the HGrid class, here all information about the HGrid is stored.
Definition: HGrid.h:43
unsigned long getNumberOfLevels() const
Gets the number of levels of this HGrid.
Definition: HGrid.h:206
double getInvCellSize(unsigned int i) const
Gets 1/cellSize for the cells on level i.
Definition: HGrid.h:178
int getOccupiedLevelsMask() const
Gets the integer that represents which levels are occupied.
Definition: HGrid.h:213
void hGridFindContactsWithTargetCell(int x, int y, int z, unsigned int l, BaseParticle *obj)
Finds contacts between the BaseParticle and the target cell.
Definition: Mercury3D.cc:118
void hGridFindContactsWithinTargetCell(int x, int y, int z, unsigned int l)
Finds contacts between particles in the target cell.
Definition: Mercury3D.cc:73
HGridMethod getHGridMethod() const
Gets whether the HGrid in this MercuryBase is BOTTOMUP or TOPDOWN.
Definition: MercuryBase.h:204
HGrid * getHGrid()
Gets the HGrid used by this problem.
Definition: MercuryBase.h:311
Mdouble Y
Definition: Vector.h:66
Mdouble Z
Definition: Vector.h:66
Mdouble X
the vector components
Definition: Vector.h:66

References MercuryBase::getHGrid(), BaseParticle::getHGridLevel(), MercuryBase::getHGridMethod(), BaseParticle::getHGridX(), BaseParticle::getHGridY(), BaseParticle::getHGridZ(), HGrid::getInvCellSize(), BaseParticle::getMaxInteractionRadius(), HGrid::getNumberOfLevels(), HGrid::getOccupiedLevelsMask(), BaseInteractable::getPosition(), hGridFindContactsWithinTargetCell(), hGridFindContactsWithTargetCell(), TOPDOWN, Vec3D::X, Vec3D::Y, and Vec3D::Z.

Referenced by Mercury3Dclump::computeAllForces().

◆ computeWallForces()

void Mercury3D::computeWallForces ( BaseWall w)
overrideprotectedvirtual

Compute contacts with a wall.

Reimplemented from DPMBase.

618 {
619 
620  // if wall is not local, use the non-hGrid version for finding wall contacts
621  Vec3D min, max;
622  if (w->isLocal(min, max)==false)
623  {
624  return DPMBase::computeWallForces(w);
625  }
626 
627  //compute forces for all particles that are neither fixed or ghosts
628  if (getHGrid() == nullptr || getHGrid()->getNeedsRebuilding())
629  {
630  logger(INFO, "HGrid needs rebuilding for \"bool Mercury3D::hGridHasParticleContacts(BaseParticle *obj)\"");
631  hGridRebuild();
632  }
633 
634  HGrid* const hGrid = getHGrid();
635 
636  int occupiedLevelsMask = hGrid->getOccupiedLevelsMask();
637 
638  for (unsigned int level = 0; level < hGrid->getNumberOfLevels(); occupiedLevelsMask >>= 1, level++)
639  {
640  // If no objects in rest of grid, stop now
641  if (occupiedLevelsMask == 0)
642  {
643  logger(VERBOSE, "Level % and higher levels are empty", level);
644  break;
645  }
646 
647  // If no objects at this level, go on to the next level
648  if ((occupiedLevelsMask & 1) == 0)
649  {
650  logger(VERBOSE, "Level % is empty", level);
651  continue;
652  }
653 
654  const Mdouble inv_size = hGrid->getInvCellSize(level);
655  const int xs = static_cast<int>(std::floor(min.X * inv_size - 0.5));
656  const int xe = static_cast<int>(std::floor(max.X * inv_size + 0.5));
657  const int ys = static_cast<int>(std::floor(min.Y * inv_size - 0.5));
658  const int ye = static_cast<int>(std::floor(max.Y * inv_size + 0.5));
659  const int zs = static_cast<int>(std::floor(min.Z * inv_size - 0.5));
660  const int ze = static_cast<int>(std::floor(max.Z * inv_size + 0.5));
661  //logger(INFO, "Level % grid cells [%,%] x [%,%] x [%,%]", level, xs, xe, ys, ye, zs, ze);
662 
663  for (int x = xs; x <= xe; ++x)
664  {
665  for (int y = ys; y <= ye; ++y)
666  {
667  for (int z = zs; z <= ze; ++z)
668  {
669  // Loop through all objects in the bucket to find nearby objects
670  const unsigned int bucket = hGrid->computeHashBucketIndex(x, y, z, level);
671  BaseParticle* p = hGrid->getFirstBaseParticleInBucket(bucket);
672  while (p != nullptr)
673  {
674  if (!p->isFixed() && p->getPeriodicFromParticle() == nullptr &&
675  p->getHGridCell().equals(x, y, z, level))
676  {
677  //logger(INFO, "t % p % Size % level % cells % % %", getNumberOfTimeSteps(), p->getIndex(), hGrid->getCellSize(level), level, x,y,z);
679  //w->computeForces(p);
680  }
681  p = p->getHGridNextObject();
682  }
683  }
684  }
685  }
686  } //end for level
687 }
@ INFO
@ VERBOSE
Definition: BaseParticle.h:54
bool isFixed() const override
Is fixed Particle function. It returns whether a Particle is fixed or not, by checking its inverse Ma...
Definition: BaseParticle.h:93
const HGridCell & getHGridCell() const
Definition: BaseParticle.h:651
BaseParticle * getHGridNextObject() const
Returns pointer to next object in particle's HGrid level & cell.
Definition: BaseParticle.h:242
BaseParticle * getPeriodicFromParticle() const
Returns the 'original' particle this one's a periodic copy of.
Definition: BaseParticle.h:341
virtual bool isLocal(Vec3D &min, Vec3D &max) const
Definition: BaseWall.h:138
virtual void computeForcesDueToWalls(BaseParticle *, BaseWall *)
Computes the forces on the particles due to the walls (normals are outward normals)
Definition: DPMBase.cc:3179
virtual void computeWallForces(BaseWall *w)
Definition: DPMBase.cc:5427
bool equals(int x, int y, int z, unsigned int level) const
Checks if the given (x,y,z,level) is the same as the ones in this cell.
Definition: HGridCell.h:39
unsigned int computeHashBucketIndex(int x, int y, int z, unsigned int l) const
Computes hash bucket index in range [0, NUM_BUCKETS-1] for a 3D domain.
Definition: HGrid.h:76
const BaseParticle * getFirstBaseParticleInBucket(unsigned int i) const
Gets the first BaseParticle in the given bucket, const version.
Definition: HGrid.h:162
void hGridRebuild()
This sets up the parameters required for the contact model.
Definition: MercuryBase.cc:204
Definition: Vector.h:51

References DPMBase::computeForcesDueToWalls(), HGrid::computeHashBucketIndex(), DPMBase::computeWallForces(), HGridCell::equals(), HGrid::getFirstBaseParticleInBucket(), MercuryBase::getHGrid(), BaseParticle::getHGridCell(), BaseParticle::getHGridNextObject(), HGrid::getInvCellSize(), HGrid::getNumberOfLevels(), HGrid::getOccupiedLevelsMask(), BaseParticle::getPeriodicFromParticle(), MercuryBase::hGridRebuild(), INFO, BaseParticle::isFixed(), BaseWall::isLocal(), logger, VERBOSE, Vec3D::X, Vec3D::Y, and Vec3D::Z.

Referenced by Mercury3Dclump::computeAllForces().

◆ constructor()

void Mercury3D::constructor ( )

Function that sets the SystemDimension and ParticleDimension to 3.

60 {
63 }
void setParticleDimensions(unsigned int particleDimensions)
Sets the particle dimensionality.
Definition: DPMBase.cc:1448
void setSystemDimensions(unsigned int newDim)
Sets the system dimensionality.
Definition: DPMBase.cc:1417

References DPMBase::setParticleDimensions(), and DPMBase::setSystemDimensions().

Referenced by Mercury3D().

◆ hGridFindContactsWithinTargetCell()

void Mercury3D::hGridFindContactsWithinTargetCell ( int  x,
int  y,
int  z,
unsigned int  l 
)
protected

Finds contacts between particles in the target cell.

Parameters
[in]xCoordinate of the target cell in x direction.
[in]yCoordinate of the target cell in y direction.
[in]zCoordinate of the target cell in z direction.
[in]lLevel in the HGrid of the target cell.

Computes all collision between particles in the same bucket as cell (x,y,z,l), please note that all the particles are in the same cell.

Todo:
replace this generic check of the each bucket to checking only the object to avoid the critical
Bug:
TW: This check is not necessary, I believe. This is the most-expensive function in most codes (the two checks in this function slows down granular jet by 15%) and the selftests are not affected.
Bug:
DK: I do think this is necessary, for example: If two cells hash to the same bucket and a particle in one of these cells check for collisions with the other cell. Then due to the hashing collision it also gets all particles in it's own cell and thus generating false collisions.
74 {
75  HGrid* const hgrid = getHGrid();
76  const unsigned int bucket = hgrid->computeHashBucketIndex(x, y, z, l);
77 
79  //Check if this function is already applied to this bucket
80  bool bucketIsChecked;
81  #pragma omp critical
82  {
83  bucketIsChecked = hgrid->getBucketIsChecked(bucket);
84  hgrid->setBucketIsChecked(bucket);
85  }
86  if (bucketIsChecked) return;
87 
88  BaseParticle* p1 = hgrid->getFirstBaseParticleInBucket(bucket);
89  while (p1 != nullptr)
90  {
91  BaseParticle* p2 = p1->getHGridNextObject();
92  while (p2 != nullptr)
93  {
96  //Check if the BaseParticle* p1 and BaseParticle* p2 are really in the same cell (i.e. no hashing error has occurred)
97  if (p1->getHGridCell() == (p2->getHGridCell()))
98  {
99  computeInternalForce(p1, p2);
100  }
101  p2 = p2->getHGridNextObject();
102  }
103  p1 = p1->getHGridNextObject();
104  }
105 }
virtual void computeInternalForce(BaseParticle *, BaseParticle *)
Computes the forces between two particles (internal in the sense that the sum over all these forces i...
Definition: DPMBase.cc:3104
bool getBucketIsChecked(unsigned int i) const
Gets whether or not the bucket with index i is checked.
Definition: HGrid.h:132
void setBucketIsChecked(unsigned int i)
Sets that the bucket with the given index is checked to true.
Definition: HGrid.h:124

References HGrid::computeHashBucketIndex(), DPMBase::computeInternalForce(), HGrid::getBucketIsChecked(), HGrid::getFirstBaseParticleInBucket(), MercuryBase::getHGrid(), BaseParticle::getHGridCell(), BaseParticle::getHGridNextObject(), and HGrid::setBucketIsChecked().

Referenced by computeInternalForces().

◆ hGridFindContactsWithTargetCell()

void Mercury3D::hGridFindContactsWithTargetCell ( int  x,
int  y,
int  z,
unsigned int  l,
BaseParticle obj 
)
protected

Finds contacts between the BaseParticle and the target cell.

Parameters
[in]xThe coordinate of the target cell in x direction.
[in]yThe coordinate of the target cell in y direction.
[in]zThe coordinate of the target cell in z direction.
[in]lThe level in the HGrid of the target cell.
[in]objA pointer to the BaseParticle for which we want to have interactions.

Computes all collisions between given BaseParticle and particles in cell (x,y,z,l). This is done by first checking if the BaseParticle is indeed from another cell, then for all BaseParticle in the target cell it is checked what the forces between that BaseParticle and given BaseParticle are.

119 {
120  //Check if the object is not in the same cell as being checked, CheckCell_current should handle these cases.
121  //TW a speedcheck revealed that this check costs a 10% performance decrease; it's only a safety check, so I made it an assert.
122  logger.assert_debug(!obj->getHGridCell().equals(x, y, z, l),
123  "hGridFindContactsWithTargetCell should not be called if object is in the same cell");
124 
125  HGrid* const hgrid = getHGrid();
126 
127  // Calculate the bucket
128  const unsigned int bucket = hgrid->computeHashBucketIndex(x, y, z, l);
129 
130  // Loop through all objects in the bucket to find nearby objects
131  for (BaseParticle* p = hgrid->getFirstBaseParticleInBucket(bucket); p != nullptr; p = p->getHGridNextObject())
132  {
133  //This is the most-expensive function in most codes (the two checks in this function slows down granular jet by 15%). It is neccesary, for example: If two cells hash to the same bucket and a particle in one of these cells check for collisions with the other cell. Then due to the hashing collision it also gets all particles in it's own cell and thus generating false collisions.
134  //Check if the BaseParticle *p really is in the target cell (i.e. no hashing error has occurred)
135  //TW speedcheck revealed that this pre-check is cheaper than allowing computeInternalForces to sort out mismatches; even if a large number of hash cells (10*Np) is used.
136  if (p->getHGridCell().equals(x, y, z, l))
137  {
138  if (Vec3D::getDistanceSquared(p->getPosition(),obj->getPosition()) < mathsFunc::square(p->getMaxInteractionRadius()+obj->getMaxInteractionRadius()))
139  computeInternalForce(obj, p);
140  }
141  }
142 }
static Mdouble getDistanceSquared(const Vec3D &a, const Vec3D &b)
Calculates the squared distance between two Vec3D: .
Definition: Vector.h:311
T square(const T val)
squares a number
Definition: ExtendedMath.h:106

References HGrid::computeHashBucketIndex(), DPMBase::computeInternalForce(), HGridCell::equals(), Vec3D::getDistanceSquared(), HGrid::getFirstBaseParticleInBucket(), MercuryBase::getHGrid(), BaseParticle::getHGridCell(), BaseParticle::getHGridNextObject(), BaseParticle::getMaxInteractionRadius(), BaseInteractable::getPosition(), logger, and mathsFunc::square().

Referenced by computeInternalForces().

◆ hGridFindParticleContacts()

std::vector< BaseParticle * > Mercury3D::hGridFindParticleContacts ( const BaseParticle obj)
overridevirtual

Returns all particles that have a contact with a given particle.

Implements MercuryBase.

545 {
546  if (getHGrid() == nullptr || getHGrid()->getNeedsRebuilding())
547  {
548  logger(INFO, "HGrid needs rebuilding for \"bool Mercury3D::hGridHasParticleContacts(BaseParticle *obj)\"");
549  hGridRebuild();
550  }
551 
552  int occupiedLevelsMask = getHGrid()->getOccupiedLevelsMask();
553 
554  std::vector<BaseParticle*> particlesInContact;
555 
556  for (unsigned int level = 0; level < getHGrid()->getNumberOfLevels(); occupiedLevelsMask >>= 1, level++)
557  {
558  // If no objects in rest of grid, stop now
559  if (occupiedLevelsMask == 0)
560  {
561  logger(VERBOSE, "Level % and higher levels are empty", level);
562  break;
563  }
564 
565  // If no objects at this level, go on to the next level
566  if ((occupiedLevelsMask & 1) == 0)
567  {
568  logger(VERBOSE, "Level % is empty", level);
569  continue;
570  }
571 
572  const Mdouble inv_size = getHGrid()->getInvCellSize(level);
573  const int xs = static_cast<int>(std::floor(
574  (obj->getPosition().X - obj->getMaxInteractionRadius()) * inv_size - 0.5));
575  const int xe = static_cast<int>(std::floor(
576  (obj->getPosition().X + obj->getMaxInteractionRadius()) * inv_size + 0.5));
577  const int ys = static_cast<int>(std::floor(
578  (obj->getPosition().Y - obj->getMaxInteractionRadius()) * inv_size - 0.5));
579  const int ye = static_cast<int>(std::floor(
580  (obj->getPosition().Y + obj->getMaxInteractionRadius()) * inv_size + 0.5));
581  const int zs = static_cast<int>(std::floor(
582  (obj->getPosition().Z - obj->getMaxInteractionRadius()) * inv_size - 0.5));
583  const int ze = static_cast<int>(std::floor(
584  (obj->getPosition().Z + obj->getMaxInteractionRadius()) * inv_size + 0.5));
585 
586  logger(VERBOSE, "Level = % grid cells [%,%] x [%,%] x [%,%]", level, xs, xe, ys, ye, zs, ze);
587  for (int x = xs; x <= xe; ++x)
588  {
589  for (int y = ys; y <= ye; ++y)
590  {
591  for (int z = zs; z <= ze; ++z)
592  {
593  // Loop through all objects in the bucket to find nearby objects
594  const unsigned int bucket = getHGrid()->computeHashBucketIndex(x, y, z, level);
596  while (p != nullptr)
597  {
598  if (p->getHGridCell().equals(x, y, z, level))
599  {
600  if (areInContact(obj, p))
601  {
602  particlesInContact.push_back(p);
603  }
604  }
605  p = p->getHGridNextObject();
606  }
607  }
608  }
609  }
610  } //end for level
611 
612  return particlesInContact;
613 }
static bool areInContact(const BaseParticle *pI, const BaseParticle *pJ)
Checks if two particle are in contact or is there any positive overlap.
Definition: DPMBase.cc:1661

References DPMBase::areInContact(), HGrid::computeHashBucketIndex(), HGridCell::equals(), HGrid::getFirstBaseParticleInBucket(), MercuryBase::getHGrid(), BaseParticle::getHGridCell(), BaseParticle::getHGridNextObject(), HGrid::getInvCellSize(), BaseParticle::getMaxInteractionRadius(), HGrid::getNumberOfLevels(), HGrid::getOccupiedLevelsMask(), BaseInteractable::getPosition(), MercuryBase::hGridRebuild(), INFO, logger, VERBOSE, Vec3D::X, Vec3D::Y, and Vec3D::Z.

◆ hGridFindParticlesWithTargetCell()

void Mercury3D::hGridFindParticlesWithTargetCell ( int  x,
int  y,
int  z,
unsigned int  l,
BaseParticle obj,
std::vector< BaseParticle * > &  list 
)
protected

Finds particles within target cell and stores them in a list.

148 {
149  HGrid* const hgrid = getHGrid();
150 
151  // Calculate the bucket
152  const unsigned int bucket = hgrid->computeHashBucketIndex(x, y, z, l);
153 
154  // Loop through all objects in the bucket to find nearby objects
155  BaseParticle* p = hgrid->getFirstBaseParticleInBucket(bucket);
156  while (p != nullptr)
157  {
158  if (p->getHGridCell().equals(x, y, z, l))
159  {
160  list.push_back(p);
161  }
162  p = p->getHGridNextObject();
163  }
164 }

References HGrid::computeHashBucketIndex(), HGridCell::equals(), HGrid::getFirstBaseParticleInBucket(), MercuryBase::getHGrid(), BaseParticle::getHGridCell(), and BaseParticle::getHGridNextObject().

Referenced by hGridGetInteractingParticleList().

◆ hGridGetInteractingParticleList()

void Mercury3D::hGridGetInteractingParticleList ( BaseParticle obj,
std::vector< BaseParticle * > &  list 
)
overrideprotectedvirtual

Obtains all neighbour particles of a given object, obtained from the hgrid.

Bug:
find out why this is necessary; if this is not there, the code sometimes segfaults.

Reimplemented from DPMBase.

167 {
168  HGrid* hgrid = getHGrid();
169 
171  if (hGridNeedsRebuilding())
172  {
173  hGridRebuild();
174  hgrid = getHGrid();
175  }
176  logger(DEBUG, "hgrid %, object %", hgrid, obj);
177  int occupiedLevelsMask = hgrid->getOccupiedLevelsMask() >> obj->getHGridLevel();
178  for (unsigned int level = 0; level < hgrid->getNumberOfLevels(); level++)
179  {
180  // If no objects in rest of grid, stop now
181  if (occupiedLevelsMask == 0)
182  {
183  break;
184  }
185 
186  // If no objects at this level, go on to the next level
187  if ((occupiedLevelsMask & 1) == 0)
188  {
189  continue;
190  }
191 
192  const Mdouble inv_size = hgrid->getInvCellSize(level);
193  const int xs = static_cast<int>(std::floor(
194  (obj->getPosition().X - obj->getMaxInteractionRadius()) * inv_size - 0.5));
195  const int xe = static_cast<int>(std::floor(
196  (obj->getPosition().X + obj->getMaxInteractionRadius()) * inv_size + 0.5));
197  const int ys = static_cast<int>(std::floor(
198  (obj->getPosition().Y - obj->getMaxInteractionRadius()) * inv_size - 0.5));
199  const int ye = static_cast<int>(std::floor(
200  (obj->getPosition().Y + obj->getMaxInteractionRadius()) * inv_size + 0.5));
201  const int zs = static_cast<int>(std::floor(
202  (obj->getPosition().Z - obj->getMaxInteractionRadius()) * inv_size - 0.5));
203  const int ze = static_cast<int>(std::floor(
204  (obj->getPosition().Z + obj->getMaxInteractionRadius()) * inv_size + 0.5));
205  for (int x = xs; x <= xe; ++x)
206  {
207  for (int y = ys; y <= ye; ++y)
208  {
209  for (int z = zs; z <= ze; ++z)
210  {
211  hGridFindParticlesWithTargetCell(x, y, z, level, obj, list);
212  }
213  }
214  }
215  }
216 }
void hGridFindParticlesWithTargetCell(int x, int y, int z, unsigned int l, BaseParticle *obj, std::vector< BaseParticle * > &list)
Finds particles within target cell and stores them in a list.
Definition: Mercury3D.cc:146
bool hGridNeedsRebuilding()
Gets if the HGrid needs rebuilding before anything else happens.
Definition: MercuryBase.cc:496

References DEBUG, MercuryBase::getHGrid(), BaseParticle::getHGridLevel(), HGrid::getInvCellSize(), BaseParticle::getMaxInteractionRadius(), HGrid::getNumberOfLevels(), HGrid::getOccupiedLevelsMask(), BaseInteractable::getPosition(), hGridFindParticlesWithTargetCell(), MercuryBase::hGridNeedsRebuilding(), MercuryBase::hGridRebuild(), logger, Vec3D::X, Vec3D::Y, and Vec3D::Z.

◆ hGridHasContactsInTargetCell()

bool Mercury3D::hGridHasContactsInTargetCell ( int  x,
int  y,
int  z,
unsigned int  l,
const BaseParticle obj 
) const
protected

Tests if the BaseParticle has contacts with other Particles in the target cell.

Parameters
[in]xThe coordinate of the target cell in x direction.
[in]yThe coordinate of the target cell in y direction.
[in]zThe coordinate of the target cell in z direction.
[in]lThe level of the HGrid of the target cell.
[in]objA pointer to the BaseParticle which is checked for contacts.

Tests if there are any collisions between given BaseParticle and particles in cell (x, y, z, l).

457 {
458  // Loop through all objects in the bucket to find nearby objects
459  const unsigned int bucket = getHGrid()->computeHashBucketIndex(x, y, z, l);
460 
461  const BaseParticle* p = getHGrid()->getFirstBaseParticleInBucket(bucket);
462  while (p != nullptr)
463  {
464  if (p->getHGridCell().equals(x, y, z, l))
465  {
466  if (areInContact(obj, p))
467  {
468  return true;
469  }
470  }
471  //std::cout << "HERE!" << std::endl;
472  p = p->getHGridNextObject();
473  }
474  return false;
475 }

References DPMBase::areInContact(), HGrid::computeHashBucketIndex(), HGridCell::equals(), HGrid::getFirstBaseParticleInBucket(), MercuryBase::getHGrid(), BaseParticle::getHGridCell(), and BaseParticle::getHGridNextObject().

Referenced by hGridHasParticleContacts().

◆ hGridHasParticleContacts()

bool Mercury3D::hGridHasParticleContacts ( const BaseParticle obj)
overrideprotectedvirtual

Tests if a BaseParticle has any contacts in the HGrid.

Parameters
[in]objA pointer to the BaseParticle that is tested for contacts.

Tests if there are any collisions between the given BaseParticle and all other particles in the HGrid. Do this by going through all levels, find if there is a collision in any of the levels in any cell of the HGrid.

Implements MercuryBase.

486 {
487  if (getHGrid() == nullptr || getHGrid()->getNeedsRebuilding())
488  {
489  logger(INFO, "HGrid needs rebuilding for \"bool Mercury3D::hGridHasParticleContacts(BaseParticle *obj)\"");
490  hGridRebuild();
491  }
492 
493  int occupiedLevelsMask = getHGrid()->getOccupiedLevelsMask();
494 
495  for (unsigned int level = 0; level < getHGrid()->getNumberOfLevels(); occupiedLevelsMask >>= 1, level++)
496  {
497  // If no objects in rest of grid, stop now
498  if (occupiedLevelsMask == 0)
499  {
500  logger(VERBOSE, "Level % and higher levels are empty", level);
501  break;
502  }
503 
504  // If no objects at this level, go on to the next level
505  if ((occupiedLevelsMask & 1) == 0)
506  {
507  logger(VERBOSE, "Level % is empty", level);
508  continue;
509  }
510 
511  const Mdouble inv_size = getHGrid()->getInvCellSize(level);
512  const int xs = static_cast<int>(std::floor(
513  (obj->getPosition().X - obj->getMaxInteractionRadius()) * inv_size - 0.5));
514  const int xe = static_cast<int>(std::floor(
515  (obj->getPosition().X + obj->getMaxInteractionRadius()) * inv_size + 0.5));
516  const int ys = static_cast<int>(std::floor(
517  (obj->getPosition().Y - obj->getMaxInteractionRadius()) * inv_size - 0.5));
518  const int ye = static_cast<int>(std::floor(
519  (obj->getPosition().Y + obj->getMaxInteractionRadius()) * inv_size + 0.5));
520  const int zs = static_cast<int>(std::floor(
521  (obj->getPosition().Z - obj->getMaxInteractionRadius()) * inv_size - 0.5));
522  const int ze = static_cast<int>(std::floor(
523  (obj->getPosition().Z + obj->getMaxInteractionRadius()) * inv_size + 0.5));
524 
525  logger(VERBOSE, "Level = % grid cells [%,%] x [%,%] x [%,%]", level, xs, xe, ys, ye, zs, ze);
526  for (int x = xs; x <= xe; ++x)
527  {
528  for (int y = ys; y <= ye; ++y)
529  {
530  for (int z = zs; z <= ze; ++z)
531  {
532  if (hGridHasContactsInTargetCell(x, y, z, level, obj))
533  {
534  return true;
535  }
536  }
537  }
538  }
539  } //end for level
540 
541  return false;
542 }
bool hGridHasContactsInTargetCell(int x, int y, int z, unsigned int l, const BaseParticle *obj) const
Tests if the BaseParticle has contacts with other Particles in the target cell.
Definition: Mercury3D.cc:456

References MercuryBase::getHGrid(), HGrid::getInvCellSize(), BaseParticle::getMaxInteractionRadius(), HGrid::getNumberOfLevels(), HGrid::getOccupiedLevelsMask(), BaseInteractable::getPosition(), hGridHasContactsInTargetCell(), MercuryBase::hGridRebuild(), INFO, logger, VERBOSE, Vec3D::X, Vec3D::Y, and Vec3D::Z.

◆ hGridRemoveParticle()

void Mercury3D::hGridRemoveParticle ( BaseParticle obj)
overrideprotected

Removes a BaseParticle from the HGrid.

Parameters
[in]objA pointer to the BaseParticle that needs to be removed.

Removes the given BaseParticle from the HGrid.

423 {
424  HGrid* const hGrid = getHGrid();
425  if (hGrid)
426  {
427  const unsigned int bucket = hGrid->computeHashBucketIndex(obj->getHGridCell());
428  if (obj->getHGridPrevObject())
429  {
431  }
432  else
433  {
434  if (hGrid->getFirstBaseParticleInBucket(bucket) == obj)
435  {
436  hGrid->setFirstBaseParticleInBucket(bucket, obj->getHGridNextObject());
437  }
438  }
439 
440  if (obj->getHGridNextObject())
441  {
443  }
444  }
445 }
BaseParticle * getHGridPrevObject() const
Returns pointer to previous object in particle's HGrid level & cell.
Definition: BaseParticle.h:250
void setHGridNextObject(BaseParticle *p)
Sets the pointer to the next object in the particle's HGrid cell & level.
Definition: BaseParticle.h:480
void setHGridPrevObject(BaseParticle *p)
Sets the pointer to the previous object in the particle's HGrid cell & level.
Definition: BaseParticle.h:488
void setFirstBaseParticleInBucket(unsigned int i, BaseParticle *p)
Sets the first particle in bucket i to be the given BaseParticle.
Definition: HGrid.h:117

References HGrid::computeHashBucketIndex(), HGrid::getFirstBaseParticleInBucket(), MercuryBase::getHGrid(), BaseParticle::getHGridCell(), BaseParticle::getHGridNextObject(), BaseParticle::getHGridPrevObject(), HGrid::setFirstBaseParticleInBucket(), BaseParticle::setHGridNextObject(), and BaseParticle::setHGridPrevObject().

Referenced by hGridUpdateParticle(), and ChuteWithPeriodicInflow::integrateBeforeForceComputation().

◆ hGridUpdateParticle()

void Mercury3D::hGridUpdateParticle ( BaseParticle obj)
overrideprotected

Updates the cell (not the level) of a BaseParticle.

Parameters
[in]objA pointer to the BaseParticle that must be updated.

Updates the HGrid positions (x, y and z) of the given BaseParticle.

362 {
363  HGrid* const hGrid = getHGrid();
364  if (hGrid)
365  {
366  const unsigned int l = obj->getHGridLevel();
367  const Mdouble inv_size = hGrid->getInvCellSize(l);
368 
369  int x = static_cast<int>(std::floor(obj->getPosition().X * inv_size));
370  int y = static_cast<int>(std::floor(obj->getPosition().Y * inv_size));
371  int z = static_cast<int>(std::floor(obj->getPosition().Z * inv_size));
372 
373 #ifdef CONTACT_LIST_HGRID
374  if(obj->getHGridX() != x || obj->getHGridY() != y || obj->getHGridZ() != z)
375  {
376  int bucket = hGrid->computeHashBucketIndex(x, y, z, l);
377 
378  //First the object has to be removed
379  hGridRemoveParticle(obj);
380 
381  //Also remove all contact associated with it
382  getPossibleContactList().remove_ParticlePosibleContacts(obj);
383 
384  //And now reinserted
386  obj->setHGridPrevObject(nullptr);
387  if(hGrid->getFirstBaseParticleInBucket(bucket))
388  {
390  }
391  hGrid->setFirstBaseParticleInBucket(bucket,obj);
392 
393  obj->setHGridX(x);
394  obj->setHGridY(y);
395  obj->setHGridZ(z);
396  InsertObjAgainstGrid(obj);
397  }
398 #else
399  const unsigned int bucket = hGrid->computeHashBucketIndex(x, y, z, l);
400 
401  // this needs to be defined as #pragma omp critical if MercuryBase::hGridActionsBeforeTimeStep is parallelised; however, parallelising it make the code slower, not faster.
402  {
404  obj->setHGridPrevObject(nullptr);
405  if (hGrid->getFirstBaseParticleInBucket(bucket)) {
407  }
408  hGrid->setFirstBaseParticleInBucket(bucket, obj);
409  }
410 
411  obj->setHGridX(x);
412  obj->setHGridY(y);
413  obj->setHGridZ(z);
414 #endif
415  }
416 }
void setHGridZ(const int z)
Sets the particle's HGrid cell Z-coordinate.
Definition: BaseParticle.h:465
void setHGridX(const int x)
Sets the particle's HGrid cell X-coordinate.
Definition: BaseParticle.h:449
void setHGridY(const int y)
Sets the particle's HGrid cell Y-coordinate.
Definition: BaseParticle.h:457
void hGridRemoveParticle(BaseParticle *obj) override
Removes a BaseParticle from the HGrid.
Definition: Mercury3D.cc:422

References HGrid::computeHashBucketIndex(), HGrid::getFirstBaseParticleInBucket(), MercuryBase::getHGrid(), BaseParticle::getHGridLevel(), BaseParticle::getHGridX(), BaseParticle::getHGridY(), BaseParticle::getHGridZ(), HGrid::getInvCellSize(), BaseInteractable::getPosition(), hGridRemoveParticle(), HGrid::setFirstBaseParticleInBucket(), BaseParticle::setHGridNextObject(), BaseParticle::setHGridPrevObject(), BaseParticle::setHGridX(), BaseParticle::setHGridY(), BaseParticle::setHGridZ(), Vec3D::X, Vec3D::Y, and Vec3D::Z.

Referenced by ChuteWithPeriodicInflow::integrateBeforeForceComputation().


The documentation for this class was generated from the following files: