41 #include <sys/types.h>
53 #include "DPMBaseXBalls.icc"
67 std::cerr <<
"A fatal error has occured"
68 <<
"\n Module :" << module
69 <<
"\n Message :" << message << std::endl;
122 #ifdef CONTACT_LIST_HGRID
123 possibleContactList=other.possibleContactList;
192 i->setTimeStamp(i->getTimeStamp() - diff);
207 logger(
ERROR,
"Error in setTimeMax, newTMax=%", newTMax);
221 #ifdef CONTACT_LIST_HGRID
224 return possibleContactList;
363 logger(
WARN,
"Warning in setXMin(%): value cannot be larger than xMax=%", xMin,
getXMax());
375 logger(
WARN,
"Warning in setYMin(%): value cannot be larger than yMax=%", yMin,
getYMax());
387 logger(
WARN,
"Warning in setZMin(%): value cannot be larger than zMax=%", zMin,
getZMax());
419 logger(
WARN,
"Warning in setXMax(%): value cannot be smaller than xMin=%", xMax,
getXMin());
431 logger(
WARN,
"Warning in setYMax(%): value cannot be smaller than yMin=%", yMax,
getYMin());
443 logger(
WARN,
"Warning in setZMax(%): value cannot be smaller than zMin=%", zMax,
getZMin());
458 logger(
ERROR,
"Error in setTimeStep, proposed time step %", timeStep);
564 if (newDim >= 1 && newDim <= 3)
568 logger(
ERROR,
"Error in setSystemDimensions, input argument is %", newDim);
585 if (particleDimensions >= 1 && particleDimensions <= 3)
591 logger(
WARN,
"Error in setParticleDimensions, input argument is %", particleDimensions);
664 elasticEnergy += c->getElasticEnergy();
666 return elasticEnergy;
679 kineticEnergy += .5 * p->getMass() * p->getVelocity().getLengthSquared();
682 return kineticEnergy;
688 Mdouble gravitationalEnergy = 0;
696 return gravitationalEnergy;
815 c->gatherContactStatistics();
888 std::cout <<
"t=" << std::setprecision(3) << std::left << std::setw(6) <<
getTime()
889 <<
", tmax=" << std::setprecision(3) << std::left << std::setw(6) <<
getTimeMax()
959 std::cerr <<
"MD problem constructor finished " << std::endl;
980 long width = os.precision() + 6;
981 os << std::setw(width) <<
"t" <<
" " << std::setw(width)
982 <<
"ene_gra" <<
" " << std::setw(width)
983 <<
"ene_kin" <<
" " << std::setw(width)
984 <<
"ene_rot" <<
" " << std::setw(width)
985 <<
"ene_ela" <<
" " << std::setw(width)
986 <<
"X_COM" <<
" " << std::setw(width)
987 <<
"Y_COM" <<
" " << std::setw(width)
988 <<
"Z_COM" << std::endl;
1019 os << std::numeric_limits<double>::quiet_NaN();
1027 os << std::numeric_limits<double>::quiet_NaN();
1037 c->writeToFStat(os);
1046 Mdouble ene_kin = 0, ene_elastic = 0, ene_rot = 0, ene_gra = 0, mass_sum = 0, x_masslength = 0, y_masslength = 0, z_masslength = 0;
1051 ene_kin += .5 * p->getMass() * p->getVelocity().getLengthSquared();
1052 ene_rot += .5 * p->getInertia() * p->getAngularVelocity().getLengthSquared();
1054 mass_sum += p->getMass();
1055 x_masslength += p->getMass() * p->getPosition().X;
1056 y_masslength += p->getMass() * p->getPosition().Y;
1057 z_masslength += p->getMass() * p->getPosition().Z;
1063 long width = os.precision() + 6;
1064 os << std::setw(width) <<
getTime()
1065 <<
" " << std::setw(width) << ene_gra
1066 <<
" " << std::setw(width) << ene_kin
1067 <<
" " << std::setw(width) << ene_rot
1068 <<
" " << std::setw(width) << ene_elastic
1069 <<
" " << std::setw(width)
1070 << (mass_sum != 0.0 ? x_masslength / mass_sum : std::numeric_limits<double>::quiet_NaN())
1071 <<
" " << std::setw(width)
1072 << (mass_sum != 0.0 ? y_masslength / mass_sum : std::numeric_limits<double>::quiet_NaN())
1073 <<
" " << std::setw(width)
1074 << (mass_sum != 0.0 ? z_masslength / mass_sum : std::numeric_limits<double>::quiet_NaN()) << std::endl;
1095 logger(
INFO,
"Writing python script for paraview visualisation");
1097 "#script to visualise the output of data2pvd of MercuryDPM in paraview.\n"
1098 "#usage: change the path below to your own path, open paraview\n"
1099 "#Tools->Python Shell->Run Script->VisualisationScript.py\n"
1100 "#or run paraview --script=VisualisationScript.py \n"
1102 "try: paraview.simple\n"
1103 "except: from paraview.simple import *\n"
1108 "particles = XMLUnstructuredGridReader(FileName=glob.glob('./"
1109 +
getName() +
"Particle_*.vtu'))\n"
1111 "walls = XMLUnstructuredGridReader(FileName=glob.glob('./"
1112 +
getName() +
"Wall_*.vtu'))\n"
1114 "interactions = XMLUnstructuredGridReader(FileName=glob.glob('./"
1115 +
getName() +
"Interaction_*.vtu'))\n"
1117 "#Make the glyph, see visualisation guide on the docs\n"
1118 "glyphP = Glyph(particles)\n"
1119 "glyphP.GlyphType = 'Sphere'\n"
1120 "glyphP.Scalars = 'Radius'\n"
1121 "glyphP.Vectors = 'None'\n"
1122 "glyphP.ScaleMode = 'scalar'\n"
1123 "glyphP.ScaleFactor = 2\n"
1124 "glyphP.GlyphMode = 'All Points'\n"
1126 "#Make the glyph, see visualisation guide on the docs\n"
1127 "glyphI = Glyph(interactions)\n"
1128 "glyphI.GlyphType = 'Sphere'\n"
1129 "glyphI.Scalars = 'ContactRadius'\n"
1130 "glyphI.Vectors = 'None'\n"
1131 "glyphI.ScaleMode = 'scalar'\n"
1132 "glyphI.ScaleFactor = 10\n"
1133 "glyphI.GlyphMode = 'All Points'\n"
1150 unsigned int format;
1160 std::cerr <<
"Unknown systemdimension" << std::endl;
1173 <<
" " << std::endl;
1185 <<
" " << std::endl;
1193 std::cerr <<
"Have output the properties of the problem to disk " << std::endl;
1210 std::cout <<
"Loading data file " << fileName <<
" failed" << std::endl;
1235 file.open(fileName, std::fstream::in);
1236 if (!file.is_open() || file.bad())
1252 file >> integerValue;
1254 if (integerValue == 0)
1270 }
else if (integerValue == 1)
1279 }
else if (integerValue == 5)
1292 }
else if (integerValue == 6)
1303 std::cerr <<
"Error in par.ini: line 1, value 1 is " << integerValue << std::endl;
1308 file >> integerValue;
1311 file >> doubleValue;
1318 file >> doubleValue;
1319 if (doubleValue < 0)
1324 file >> doubleValue;
1329 file >> doubleValue;
1330 if (doubleValue >= 0)
1333 unsigned int savecount =
static_cast<unsigned int>(round(doubleValue /
getTimeStep()));
1338 file >> doubleValue;
1339 savecount =
static_cast<unsigned int>(round(doubleValue /
getTimeStep()));
1349 std::cerr <<
"Error in par.ini: line 3, value 1 is " << doubleValue << std::endl;
1356 file >> doubleValue;
1364 S->setDensity(doubleValue);
1367 file >> doubleValue;
1368 S->setStiffness(doubleValue);
1371 file >> doubleValue;
1372 S->setDissipation(doubleValue);
1375 file >> doubleValue;
1376 if (doubleValue != 0.0)
1377 std::cerr <<
"Warning in par.ini: ignored background damping " << doubleValue << std::endl;
1382 file >> doubleValue;
1383 if (doubleValue != 0.0)
1384 std::cerr <<
"Warning in par.ini: ignored growth rate " << doubleValue << std::endl;
1387 file >> doubleValue;
1388 if (doubleValue != 0.0)
1389 std::cerr <<
"Warning in par.ini: ignored target volume_fraction " << doubleValue << std::endl;
1413 std::cout <<
"file " <<
dataFile.
getName() <<
" not found" << std::endl;
1474 std::cout <<
"Warning in readNextDataFile: particleHandler is empty, "
1475 "so newly created particles will be of BaseParticle type." << std::endl;
1497 std::cout <<
"Number of particles read from file "<<N << std::endl;
1506 std::stringstream line;
1532 Vec3D position, velocity;
1536 line >> position.
X >> position.
Z >> position.
Y >> velocity.
X >> velocity.
Z >> velocity.
Y >> radius
1538 p->setPosition(position);
1539 p->setVelocity(velocity);
1540 p->setOrientation(
Vec3D(0.0, 0.0, 0.0));
1541 p->setAngularVelocity(
Vec3D(0.0, 0.0, 0.0));
1542 p->setRadius(radius);
1549 std::stringstream line;
1555 Vec3D position, velocity, angle, angularVelocity;
1559 line >> position.
X >> position.
Y >> velocity.
X >> velocity.
Y >> radius >> angle.
Z >> angularVelocity.
Z
1561 p->setPosition(position);
1562 p->setVelocity(velocity);
1563 p->setOrientation(-angle);
1564 p->setAngularVelocity(-angularVelocity);
1565 p->setRadius(radius);
1572 std::stringstream line;
1576 Vec3D position, velocity, angle, angularVelocity;
1580 line >> position >> velocity >> radius >> angle >> angularVelocity;
1581 p->setPosition(position);
1582 p->setVelocity(velocity);
1583 p->setOrientation(angle);
1584 p->setAngularVelocity(angularVelocity);
1585 p->setRadius(radius);
1587 logger(
INFO,
"read % particles", particleHandler.getNumberOfObjects());
1593 std::stringstream line;
1597 Vec3D position, velocity, angle, angularVelocity;
1601 line >> position >> velocity >> radius >> angle >> angularVelocity >> dummy >> dummy;
1602 p->setPosition(position);
1603 p->setVelocity(velocity);
1604 p->setOrientation(angle);
1605 p->setAngularVelocity(angularVelocity);
1606 p->setRadius(radius);
1684 for (
auto i : interactions)
1725 std::vector<BaseInteraction*> interactions = w->getInteractionWith(pI,
getTime() +
getTimeStep(),
1728 for (
auto i : interactions)
1733 w->addForce(-i->getForce());
1739 w->addTorque(-i->getTorque() +
Vec3D::cross(w->getPosition() - i->getContactPoint(), i->getForce()));
1846 p->setForce(
Vec3D(0.0, 0.0, 0.0));
1847 p->setTorque(
Vec3D(0.0, 0.0, 0.0));
1851 w->setForce(
Vec3D(0.0, 0.0, 0.0));
1852 w->setTorque(
Vec3D(0.0, 0.0, 0.0));
1856 std::cerr <<
"Have all forces set to zero " << std::endl;
1872 #ifdef CONTACT_LIST_HGRID
1899 os <<
"restart_version " <<
"1.0";
1906 <<
" zMax " <<
getZMax() << std::endl
1924 os << (*w) << std::endl;
1927 os << (*b) << std::endl;
1934 for (
unsigned int i = 0; i < 2; i++)
1936 os <<
"..." << std::endl;
1944 for (
unsigned int i = 0; i < 2; i++)
1946 os <<
"..." << std::endl;
1959 if (strcmp(dummy.c_str(),
"restart_version"))
1962 logger.log(
Log::FATAL,
"Error in DPMBase::read(is): this is not a valid restart file");
1966 if (!restartVersion_.compare(
"1.0"))
1969 is >> dummy >>
xMin_
1983 std::stringstream line(std::stringstream::in | std::stringstream::out);
1986 if (!dummy.compare(
"writeVTK")) {
1991 if (!dummy.compare(
"random"))
2005 if (dummy.compare(
"Walls"))
2006 logger(
ERROR,
"DPMBase::read(is): Error during restart: 'Walls' argument could not be found.");
2011 for (
unsigned int i = 0; i < N; i++)
2020 if (dummy.compare(
"Boundaries"))
2021 logger(
ERROR,
"DPMBase::read(is): Error during restart: 'Boundaries' argument could not be found.");
2023 for (
unsigned int i = 0; i < N; i++)
2030 if (dummy.compare(
"Particles"))
2031 logger(
ERROR,
"DPMBase::read(is): Error during restart: 'Boundaries' argument could not be found.");
2035 for (
unsigned int i = 0; i < N; i++)
2045 }
else if (!restartVersion_.compare(
"3"))
2047 logger.log(
Log::INFO,
"DPMBase::read(is): restarting from an old restart file (restart_version %).",
2054 "Error in DPMBase::read(is): restart_version % cannot be read; use an older version of Mercury to upgrade the file",
2066 is >> dummy >> dummy;
2069 unsigned int saveCountData, saveCountEne, saveCountStat, saveCountFStat;
2070 unsigned int fileTypeFstat, fileTypeData, fileTypeEne, fileTypeRestart;
2071 is >> dummy >>
xMin_
2080 >> dummy >> saveCountData
2081 >> dummy >> saveCountEne
2082 >> dummy >> saveCountStat
2083 >> dummy >> saveCountFStat
2086 >> dummy >> fileTypeFstat
2087 >> dummy >> fileTypeData
2088 >> dummy >> fileTypeEne;
2100 if (!strcmp(dummy.c_str(),
"options_restart"))
2102 is >> fileTypeRestart;
2119 std::cerr <<
"Error in solve(): at least one species has to be defined" << std::endl;
2124 std::cerr <<
"Error in solve(): particleDimensions not specified" << std::endl;
2129 std::cerr <<
"Error in solve(): systemDimensions not specified" << std::endl;
2134 std::cerr <<
"Error in solve(): timeStep not specified" << std::endl;
2191 #ifdef CONTACT_LIST_HGRID
2209 logger(
DEBUG,
"Have created the particles initial conditions");
2220 std::stringstream name;
2228 setOpenMode(std::fstream::out | std::fstream::app);
2256 logger(
DEBUG,
"Have computed the initial values for the forces ");
2274 b->checkBoundaryBeforeTimeStep(
this);
2323 for (
int i = 1; i < argc; i += 2)
2325 std::cout <<
"interpreting input argument " << argv[i];
2326 for (
int j = i + 1; j < argc; j++)
2328 if (argv[j][0] ==
'-')
2330 std::cout <<
" " << argv[j];
2332 std::cout << std::endl;
2336 std::cerr <<
"Warning: not all arguments read correctly!" << std::endl;
2352 if (!strcmp(argv[i],
"-name"))
2355 }
else if (!strcmp(argv[i],
"-xmin"))
2358 }
else if (!strcmp(argv[i],
"-ymin"))
2361 }
else if (!strcmp(argv[i],
"-zmin"))
2364 }
else if (!strcmp(argv[i],
"-xmax"))
2367 }
else if (!strcmp(argv[i],
"-ymax"))
2370 }
else if (!strcmp(argv[i],
"-zmax"))
2376 }
else if (!strcmp(argv[i],
"-addS"))
2379 }
else if (!strcmp(argv[i],
"-addL"))
2382 }
else if (!strcmp(argv[i],
"-dt"))
2386 std::cout <<
" reset dt from " << old <<
" to " <<
getTimeStep() << std::endl;
2393 else if (!strcmp(argv[i],
"-tmax"))
2397 std::cout <<
" reset timeMax from " << old <<
" to " <<
getTimeMax() << std::endl;
2398 }
else if (!strcmp(argv[i],
"-saveCount"))
2401 setSaveCount(static_cast<unsigned int>(atoi(argv[i + 1])));
2403 std::cout <<
" reset saveCount from " << old <<
" to " <<
dataFile.
getSaveCount() << std::endl;
2404 }
else if (!strcmp(argv[i],
"-saveCountData"))
2407 }
else if (!strcmp(argv[i],
"-saveCountFStat"))
2410 }
else if (!strcmp(argv[i],
"-saveCountStat"))
2413 }
else if (!strcmp(argv[i],
"-saveCountEne"))
2416 }
else if (!strcmp(argv[i],
"-saveCountRestart"))
2419 }
else if (!strcmp(argv[i],
"-dim"))
2422 }
else if (!strcmp(argv[i],
"-gravity"))
2425 setGravity(
Vec3D(atof(argv[i + 1]), atof(argv[i + 2]), atof(argv[i + 3])));
2427 }
else if (!strcmp(argv[i],
"-fileType"))
2429 setFileType(static_cast<FileType>(atoi(argv[i + 1])));
2430 }
else if (!strcmp(argv[i],
"-fileTypeFStat"))
2433 }
else if (!strcmp(argv[i],
"-fileTypeRestart"))
2436 }
else if (!strcmp(argv[i],
"-fileTypeData"))
2439 }
else if (!strcmp(argv[i],
"-fileTypeStat"))
2442 }
else if (!strcmp(argv[i],
"-fileTypeEne"))
2445 }
else if (!strcmp(argv[i],
"-auto_number"))
2454 else if (!strcmp(argv[i],
"-restart") || !strcmp(argv[i],
"-r"))
2459 std::string filename;
2462 if (i + 1 >= argc || argv[i + 1][0] ==
'-')
2466 std::cout <<
getName() << std::endl;
2468 filename = argv[i + 1];
2471 if (filename.find(
".restart") == std::string::npos)
2473 filename = filename +
".restart";
2476 std::cout <<
"restart from " << filename << std::endl;
2478 }
else if (!strcmp(argv[i],
"-clean") || !strcmp(argv[i],
"-c"))
2480 std::cout <<
"Remove old " <<
getName() <<
".* files" << std::endl;
2483 std::ostringstream filename;
2484 std::vector<std::string> ext{
".restart",
".stat",
".fstat",
".data",
".ene",
".xballs"};
2485 for (
unsigned int j = 0; j < ext.size(); j++)
2489 filename <<
getName() << ext[j];
2490 if (!
remove(filename.str().c_str()))
2492 std::cout <<
" File " << filename.str() <<
" successfully deleted" << std::endl;
2497 filename <<
getName() << ext[j] <<
'.' << k;
2498 while (!
remove(filename.str().c_str()))
2500 std::cout <<
" File " << filename.str() <<
" successfully deleted" << std::endl;
2502 filename <<
getName() << ext[j] <<
'.' << ++k;
2508 while (!
remove(filename.str().c_str()))
2510 std::cout <<
" File " << filename.str() <<
" successfully deleted" << std::endl;
2516 }
else if (!strcmp(argv[i],
"-data"))
2518 std::string filename = argv[i + 1];
2569 else if (!strcmp(argv[i],
"-randomise") || !strcmp(argv[i],
"-randomize"))
2594 else if (!strcmp(argv[i],
"-append"))
2598 }
else if (!strcmp(argv[i],
"-fixedParticles"))
2612 else if (!strcmp(argv[i],
"-counter"))
2634 #ifdef MERCURY_USE_MPI
2637 MPIContainer& communicator = MPIContainer::Instance();
2638 int numberOfProcessors = communicator.getNumberOfProcessors();
2641 int *interactionList =
nullptr;
2642 if (communicator.getProcessorID() == 0)
2644 interactionList =
new int [numberOfProcessors];
2648 communicator.gather(localInteraction,interactionList);
2651 int globalInteraction = 1;
2652 if (communicator.getProcessorID() == 0)
2654 for (
int i = 0; i<numberOfProcessors; i++)
2656 if (interactionList[i] == 0)
2658 globalInteraction = 0;
2664 communicator.broadcast(globalInteraction);
2667 bool interaction = globalInteraction;
2682 std::vector<BaseParticle> pPeriodic;
2686 for (
int i=pPeriodic.size()-1; i>=0; --i) {
2688 pPeriodic.push_back(pPeriodic[i]);
2693 pPeriodic.push_back(p);
2729 if (w->getDistanceAndNormal(p, distance, normal))
2787 for (
unsigned int i = 0; i < N; i++)
2800 std::cout <<
"Interactions currently in the handler:" << std::endl;
2803 p->write(std::cout);
2804 std::cout << std::endl;
2805 std::cout <<
"Interaction " << p->getName() <<
" " << p->getId() <<
" between " << p->getP()->getId() <<
" and "
2806 << p->getI()->getId() << std::endl;
void writeVTK() const
Writes all particles into a vtk file format (unstructured grid), consisting of particle positions...
Mdouble timeMax_
Stores the duration of the simulation.
void setTime(Mdouble time)
Access function for the time.
BaseParticle * getLargestParticle() const
Gets a pointer to the largest BaseParticle (by interactionRadius) in this ParticleHandler.
virtual void actionsBeforeTimeLoop()
A virtual function. Allows one to carry out any operations before the start of the time loop...
unsigned int getId() const
Returns the unique identifier of any particular object.
void setXBallsVectorScale(double newVScale)
Set the scale of vectors in xballs.
virtual void write(std::ostream &os, bool writeAllParticles=true) const
Loads all MD data and plots statistics for all timesteps in the .data file.
FileType getWallsWriteVTK() const
Returns a flag indicating if particle rotation is enabled or disabled.
virtual void hGridUpdateParticle(BaseParticle *obj UNUSED)
no implementation but can be overidden in its derived classes.
void set(Vec3D normal, Mdouble distanceLeft, Mdouble distanceRight)
Defines a periodic wall.
void setXMax(Mdouble newXMax)
If the length of the problem domain in x-direction is XMax - XMin, this method sets XMax...
bool writeToFile(std::string filename, std::string filecontent)
Writes a string to a file.
void setWallsWriteVTK(FileType writeWallsVTK)
Allows to set the flag for enabling or disabling particle rotation in the simulations.
void write(std::ostream &os) const
void solve()
The work horse of the code.
Mdouble yMax_
If the length of the problem domain in y-direction is YMax - XMin, the above variable stores YMax...
virtual void hGridInsertParticle(BaseParticle *obj UNUSED)
no implementation but can be overidden in its derived classes.
int addL_
Stores the number of large particles that are to be added on restart.
The DPMBase header includes quite a few header files, defining all the handlers, which are essential...
Mdouble X
the vector components
each time-step will be written into/read from separate files numbered consecutively, with numbers padded by zeros to a minimum of four digits: name_.0000, name_.0001, ..
void writeVTK() const
Writes all particles into a vtk file format (unstructured grid), consisting of particle positions...
virtual void integrateAfterForceComputation()
Integration is done after force computations. We apply the Velocity verlet scheme. See http://en.wikipedia.org/wiki/Verlet_integration#Velocity_Verlet.
void checkAndDuplicatePeriodicParticles()
In case of periodic boundaries, the below methods checks and adds particles when necessary into the p...
void read(std::istream &is)
int getXBallsColourMode() const
Get the xball colour mode (CMode)
void setNextSavedTimeStep(unsigned int nextSavedTimeStep)
Sets the next time step for all the files (ene, data, fstat, restart, stat) at which the data is to b...
void setTimeMax(Mdouble newTMax)
Allows the upper time limit to be changed.
bool areInContact(const BaseParticle *pI, const BaseParticle *pJ) const
Checks if two particle are in contact or is there any positive overlap.
void constructor()
A function which initialises the member variables to default values, so that the problem can be solve...
void write(std::ostream &os) const
Writes the InteractionHandler to an output stream, for example a restart file.
unsigned int getSystemDimensions() const
Returns the dimension of the simulation. Note there is also a particle dimension. ...
bool readArguments(int argc, char *argv[])
Can interpret main function input arguments that are passed by the driver codes.
FileType getWriteVTK() const
FileType getFileType() const
Gets the file type e.g. NOFILE, ONEFILE and MULTIPLE FILES. File::fileType_.
int getAddLarge() const
returns the number of large particles that are to be added on restart.
void setAddLarge(int new_addL)
sets the number of large particles that are to be added on restart.
virtual void removeObject(unsigned const int index)
Removes a BaseParticle from the ParticleHandler.
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
unsigned int particleDimensions_
determines if 2D or 3D particle volume is used for mass calculations
bool readRestartFile(bool restarted=true)
Reads all the particle data corresponding to the current saved time step. Which is what the restart f...
void addForce(const Vec3D &addForce)
Adds an amount to the force on this BaseInteractable.
Mdouble yMin_
If the length of the problem domain in y-direction is YMax - YMin, the above variable stores YMin...
void setDPMBase(DPMBase *DPMBase)
Sets the problem that is solved using this handler.
void setYMin(Mdouble newYMin)
If the length of the problem domain in y-direction is YMax - YMin, this method sets YMin...
virtual void computeInternalForces(BaseParticle *i)
Computes the forces between particles (internal in the sense that the sum over all these forces is ze...
Mdouble getZMax() const
If the length of the problem domain in z-direction is ZMax - ZMin, then getZMax() returns ZMax...
Mdouble getXMin() const
If the length of the problem domain in x-direction is XMax - XMin, then getXMin() returns XMin...
const ParticleSpecies * getSpecies() const
Returns a pointer to the species of this BaseInteractable.
void setStorageCapacity(const unsigned int N)
Sets the storage capacity of this BaseHandler.
void setAddSmall(int new_addS)
sets the number of small particles that are to be added on restart.
unsigned int getParticleDimensions() const
Returns the particle dimensions.
bool readDataFile(const std::string fileName, unsigned int format=0)
This allows particle data to be reloaded from data files.
void setParticlesWriteVTK(bool writeParticlesVTK)
Allows to set the flag for enabling or disabling particle rotation in the simulations.
void computeAllMasses(unsigned int indSpecies)
Computes the mass for all BaseParticle of the given species in this ParticleHandler.
virtual void initialiseStatistics()
no implementation but can be overidden in its derived classes.
File restartFile
An instance of class File to handle in- and output into a .restart file.
Mdouble elasticEnergy_
used in force calculations
Mdouble getYMin() const
If the length of the problem domain in y-direction is YMax - YMin, then getYMin() returns YMin...
void setXBallsColourMode(int newCMode)
Set the xball output mode.
const std::vector< T * >::const_iterator end() const
Gets the end of the const_iterator over all BaseBoundary in this BaseHandler.
virtual void readOld(std::istream &is)
Reads all data from a restart file, e.g. domain data and particle data; old version.
void closeFiles()
Closes all files (ene, data, fstat, restart, stat) that were opened to read or write.
void setParticleDimensions(unsigned int particleDimensions)
Allows the dimension of the particle (f.e. for mass) to be changed. e.g. discs or spheres...
virtual ~DPMBase()
virtual destructor
virtual void actionsAfterTimeStep()
A virtual function which allows to define operations to be executed after time step.
void readObject(std::istream &is)
Reads BaseParticle into the ParticleHandler from restart data.
void unfix()
Unfix Particle function, which required a reference to the Species vector. It unfixes a Particle by c...
void setZMax(Mdouble newZMax)
If the length of the problem domain in z-direction is XMax - XMin, this method sets ZMax...
void write(std::ostream &os) const
Accepts an output stream read function, which accepts an input stream std::ostream.
bool openNextFile()
This function should be called before a data corresponding to the new time step is written or read...
void setSpecies(const ParticleSpecies *species)
void setDimension(unsigned int newDim)
Sets the system and particle dimension.
static Mdouble dot(const Vec3D &a, const Vec3D &b)
Calculates the dot product of two Vec3D: .
void setAppend(bool newAppendFlag)
Allows to set the append option.
virtual void writeOutputFiles()
Writes the simulation data onto all the files i.e. .data, .ene, .fstat ...
void setSystemDimensions(unsigned int newDim)
Allows for the dimension of the simulation to be changed.
Species< LinearViscoelasticNormalSpecies, SlidingFrictionSpecies > LinearViscoelasticSlidingFrictionSpecies
std::function< void(std::string, std::string)> onFatal
void setFileType(FileType fileType)
Sets File::fileType_ for all files (ene, data, fstat, restart, stat)
void read(std::istream &is)
Reads all objects from restart data.
virtual void write(std::ostream &os) const
Write all the species and mixed species to an output stream.
void setGravity(Vec3D newGravity)
Allows to modify the gravity vector.
T square(T val)
squares a number
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...
void logWriteAndDie(std::string module, std::string message)
todo strcmp relies on this, should be changed to more modern version
virtual bool getHGridUpdateEachTimeStep() const
bool rotation_
A flag to turn on/off particle rotation.
const Vec3D & getPosition() const
Returns the position of this BaseInteractable.
Stores information about interactions between two interactable objects; often particles but could be ...
void randomise()
sets the random variables such that they differ for each run
void eraseOldInteractions(Mdouble lastTimeStep)
erases interactions which have an old timestamp.
void setRunNumber(int runNumber)
This sets the counter/Run number, overriding the defaults.
bool getParticlesWriteVTK() const
Returns a flag indicating if particle rotation is enabled or disabled.
Mdouble zMax_
If the length of the problem domain in z-direction is ZMax - ZMin, the above variable stores ZMax...
FileType
With FileType options, one is able to choose if data is to be read/written from/into no or single or ...
bool restarted_
A bool to check if the simulation was restarted or not, ie. if setupInitialConditionsShould be run an...
const std::vector< T * >::const_iterator begin() const
Gets the begin of the const_iterator over all Object in this BaseHandler.
void actionsAfterTimeStep()
Defines a pair of periodic walls. Inherits from BaseBoundary.
BaseParticle * getPeriodicFromParticle() const
Returns the 'original' particle this one's a periodic copy of.
Mdouble getXMax() const
If the length of the problem domain in x-direction is XMax - XMin, then getXMax() returns XMax...
void clear()
Empties the whole ParticleHandler by removing all BaseParticle.
void setRotation(bool newRotFlag)
Allows to set the flag for enabling or disabling particle rotation in the simulations.
void readObject(std::istream &is)
Reads BaseWall into the WallHandler from restart data.
unsigned int getSaveCount() const
Gets File::saveCount_.
void setOpenMode(std::fstream::openmode openMode)
Sets File::openMode_ for all files (ene, data, fstat, restart, stat)
virtual void processStatistics(bool usethese UNUSED)
no implementation but can be overidden in its derived classes.
void close()
Closes the file by calling fstream_.close()
bool findNextExistingDataFile(Mdouble tMin, bool verbose=true)
Useful when fileType is chosen as Multiple Files or Multiple files with padded.
void setYMax(Mdouble newYMax)
If the length of the problem domain in y-direction is YMax - YMin, this method sets YMax...
unsigned int systemDimensions_
The dimensions of the simulation i.e. 2D or 3D.
void readObject(std::istream &is)
Reads BaseBoundary into the BoundaryHandler from restart data.
File eneFile
An instance of class File to handle in- and output into a .ene file.
Mdouble zMin_
If the length of the problem domain in z-direction is ZMax - ZMin, the above variable stores ZMin...
Mdouble getElasticEnergy() const
Returns the global elastic energy within the system.
Mdouble xMax_
If the length of the problem domain in x-direction is XMax - XMin, the above variable stores XMax...
Mdouble getGravitationalEnergy() const
Returns the global gravitational potential energy stored in the system.
unsigned int getCounter() const
In case of multiple files, File::getCounter() returns the the number (FILE::Counter_) of the next fil...
void removeObjectKeepingPeriodics(unsigned const int id)
Removes interactions of periodic particles when the periodic particles get deleted (see DPMBase::remo...
file will not be created/read
unsigned int ntimeSteps_
Stores the number of time steps.
virtual void writeEneTimestep(std::ostream &os) const
This function enables one to write the global energy available in the system after each time step...
std::fstream & getFstream()
Allows to access the member variable File::fstream_.
virtual void hGridActionsBeforeIntegration()
no implementation but can be overidden in its derived classes.
BaseParticle * getSmallestParticle() const
Gets a pointer to the smallest BaseParticle (by interactionRadius) in this ParticleHandler.
void write(std::ostream &os) const
bool getAppend() const
Returns the flag denoting if the append option is on or off.
virtual bool readNextArgument(int &i, int argc, char *argv[])
Interprets the i^th command-line argument.
virtual bool checkParticleForInteraction(const BaseParticle &P)
Checks if the particle having any interaction with walls or other particles.
void setName(const std::string &name)
Allows to set the name of all the files (ene, data, fstat, restart, stat)
Mdouble getDistance(const BaseParticle &p) const
Returns the distance of the wall to the particle.
void resetFileCounter()
Resets the file counter for each file i.e. for ene, data, fstat, restart, stat)
bool getRestarted() const
Returns the flag denoting if the simulation was restarted or not.
Mdouble getMass() const
Returns the particle's mass_.
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 addObject(ParticleSpecies *const S)
Adds a new ParticleSpecies to the SpeciesHandler.
int xBallsColourMode_
XBalls is a package to view the particle data. As an alternative MercuryDPM also supports Paraview...
BoundaryHandler boundaryHandler
An object of the class BoundaryHandler which concerns insertion and deletion of particles into or fro...
Mdouble xBallsScale_
sets the xballs argument scale (see XBalls/xballs.txt)
void setXMin(Mdouble newXMin)
If the length of the problem domain in x-direction is XMax - XMin, this method sets XMin...
ParticleHandler particleHandler
An object of the class ParticleHandler, contains the pointers to all the particles created...
int addS_
Stores the number of small particles that are to be added on restart.
void removeLastObject()
Removes the last BaseParticle from the ParticleHandler.
all data will be written into/ read from a single file called name_
Mdouble domainSize() const
T * getObject(const unsigned int id)
Gets a pointer to the Object at the specified index in the BaseHandler.
unsigned int getNtimeSteps() const
Returns the current counter of time steps.
void shiftPosition(BaseParticle *p) const
shifts the particle
Mdouble getKineticEnergy() const
Returns the global kinetic energy stored in the system.
virtual void outputXBallsDataParticle(const unsigned int i, const unsigned int format, std::ostream &os) const
This function writes out the particle locations into an output stream in a format the XBalls program ...
Mdouble time_
Stores the current simulation time.
void setRestartVersion(std::string newRV)
Sets restart_version.
Vec3D getGravity() const
Returns the gravity vector.
void checkSettings()
Checks if the essentials are set properly to go ahead with solving the problem.
virtual void hGridActionsBeforeTimeLoop()
A virtual function that allows one to carry out hGrid operations before the start of the time loop...
File fStatFile
An instance of class File to handle in- and output into a .fstat file.
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.
void read(std::istream &is)
Accepts an input stream std::istream.
bool readParAndIniFiles(const std::string fileName)
Allows the user to read par.ini files (useful to read MDCLR files)
void setSaveCount(unsigned int saveCount)
Sets File::saveCount_ for all files (ene, data, fstat, restart, stat)
static Vec3D cross(const Vec3D &a, const Vec3D &b)
Calculates the cross product of two Vec3D: .
virtual void computeAllForces()
Computes all the forces acting on the particles by using the setTorque and setForce methods...
File dataFile
An instance of class File to handle in- and output into a .data file.
Mdouble getRadius() const
Returns the particle's radius_.
bool readNextDataFile(unsigned int format=0)
Reads the next data file with default format=0. However, one can modify the format based on whether t...
void setZMin(Mdouble newZMin)
If the length of the problem domain in z-direction is ZMax - ZMin, this method sets ZMin...
virtual void actionsAfterSolve()
A virtual function which allows to define operations to be executed after the solve().
void setSaveCount(unsigned int saveCount)
Sets File::saveCount_.
virtual void printTime() const
Displays the current simulation time onto your screen for example.
unsigned int getNumberOfObjects() const
Gets the number of Object in this BaseHandler.
SpeciesHandler speciesHandler
A handler to that stores the species type i.e. elastic, linear visco-elastic... et cetera...
InteractionHandler interactionHandler
An object of the class InteractionHandler.
FileType writeWallsVTK_
A flag to turn on/off the vtk writer for walls.
virtual void writeXBallsScript() const
This writes a script which can be used to load the xballs problem to display the data just generated...
void outputInteractionDetails() const
Displays the interaction details corresponding to the pointer objects in the interaction handler...
void setXBallsAdditionalArguments(std::string newXBArgs)
Set the additional arguments for xballs.
void setFixedParticles(unsigned int n)
Mdouble getYMax() const
If the length of the problem domain in y-direction is YMax - YMin, then getYMax() returns XMax...
Mdouble xBallsVectorScale_
sets the xballs argument vscale (see XBalls/xballs.txt)
Mdouble xMin_
If the length of the problem domain in x-direction is XMax - XMin, the above variable stores XMin...
virtual void actionsBeforeTimeStep()
A virtual function which allows to define operations to be executed before the new time step...
LoggerOutput * loggerOutput
Declaration of the output functions. If the output needs to be redirected, please swap the loggerOutp...
Mdouble timeStep_
Stores the simulation time step.
void setFileType(FileType fileType)
Sets the type of file needed to write into or read from. File::fileType_.
void setRandomSeed(unsigned long int new_seed)
This is the seed for the random number generator. (note the call to seed_LFG is only required really ...
WallHandler wallHandler
An object of the class WallHandler. Contains pointers to all the walls created.
void setWriteVTK(FileType f)
RNG random
This is a random generator, often used for setting up the initial conditions etc...
std::string to_string_padded(unsigned int value)
Pads the number This function tries to pad the number to 4 digits, which is used when you create mult...
virtual void hGridRemoveParticle(BaseParticle *obj UNUSED)
no implementation but can be overidden in its derived classes.
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...
bool writeParticlesVTK_
A flag to turn on/off the vtk writer for particles.
virtual void actionsOnRestart()
A virtual function where the users can add extra code which is executed only when the code is restart...
void autoNumber()
The autoNumber() function is the trigger. It calls three functions. setRunNumber(), readRunNumberFromFile() and incrementRunNumberInFile().
virtual void writeEneHeader(std::ostream &os) const
Writes a header with a certain format for ENE file.
bool open()
Checks if the file stream fstream_ has any issues while opening. Alongside, it also increments the ne...
void set(Vec3D normal, Vec3D point)
Defines a standard wall, given an outward normal vector s.t. normal*x=normal*point for all x of the w...
Mdouble getZMin() const
If the length of the problem domain in z-direction is ZMax - ZMin, then getZMin() returns ZMin...
int getAddSmall() const
returns the number of small particles that are to be added on restart.
bool saveCurrentTimestep(unsigned int ntimeSteps)
void gatherContactStatistics()
virtual void outputStatistics()
no implementation but can be overidden in its derived classes.
void setTimeStep(Mdouble newDt)
Allows the time step dt to be changed.
bool compare(std::istream &is, std::string s)
void removeDuplicatePeriodicParticles()
Removes periodic duplicate Particles.
bool checkParticleForInteractionLocalPeriodic(const BaseParticle &P)
void setMin(Vec3D min)
Sets the values xMin, yMin, zMin of the problem domain, which is [xMin,xMax]x[yMin,yMax]x[zMin,zMax].
virtual void integrateBeforeForceComputation()
This is were the integration is done, at the moment it is velocity Verlet integration and is done bef...
virtual void writeRestartFile()
Stores all the particle data for current save time step. Calls the write function.
std::string xBallsAdditionalArguments_
A string of additional arguments for xballs can be specified (see XBalls/xballs.txt). e.g. "-solidf -v0".
double getXBallsVectorScale() const
Returns the scale of vectors used in xballs.
This is a class defining walls.
virtual bool continueSolve() const
each time-step will be written into/read from separate files numbered consecutively: name_...
It is publicly inherited from class Files. It defines an awesome feature that is ideal when doing a p...
static Mdouble getDistanceSquared(const Vec3D &a, const Vec3D &b)
Calculates the squared distance between two Vec3D: .
void addTorque(const Vec3D &addTorque)
Adds an amount to the torque on this BaseInteractable.
std::ostream & operator<<(std::ostream &os, DPMBase &md)
virtual void hGridUpdateMove(BaseParticle *, Mdouble)
no implementation but can be overidden in its derived classes.
virtual void computeForcesDueToWalls(BaseParticle *PI)
Computes the forces on the particles due to the walls (normals are outward normals) ...
std::string restartVersion_
Previous versions of MercuryDPM had a different restart file format, the below member variable allows...
const std::list< BaseInteraction * > & getInteractions() const
Returns a reference to the list of interactions in this BaseInteractable.
T * getLastObject()
Gets a pointer to the last Object in this BaseHandler.
void setRestarted(bool newRestartedFlag)
Allows to set the flag stating if the simulation is to be restarted or not.
Implementation of a 3D vector (by Vitaliy).
void setName(const std::string &name)
Sets the file name, e.g. "Name.data".
std::string getXBallsAdditionalArguments() const
Returns the additional arguments for xballs.
virtual void hGridActionsAfterIntegration()
no implementation but can be overidden in its derived classes.
Mdouble getTimeStep() const
Allows the time step dt to be accessed.
File statFile
An instance of class File to handle in- and output into a .stat file.
double getXBallsScale() const
Returns the scale of the view in xballs.
bool isFixed() const
Is fixed Particle function. It returns whether a Particle is fixed or not, by checking its inverse Ma...
virtual void hGridActionsBeforeTimeStep()
A virtual function that allows one to set or execute hGrid parameters or operations before every simu...
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.
Mdouble getInteractionRadius() const
Returns the particle's interaction radius, which might be different from radius_ (e.g., when dealing with wet particles)
bool getRotation() const
Returns a flag indicating if particle rotation is enabled or disabled.
virtual void finishStatistics()
no implementation but can be overidden in its derived classes.
virtual void broadPhase(BaseParticle *i)
By broad one means to screen and determine an approximate number of particles that a given particle c...
Mdouble getTime() const
Access function for the time.
const std::string & getName() const
Returns the name of the file. Does not allow to change it though.
virtual void checkInteractionWithBoundaries()
There are a range of boundaries one could implement depending on ones' problem. This methods checks f...
virtual void writeFstatHeader(std::ostream &os) const
Writes a header with a certain format for FStat file.
virtual void read(std::istream &is)
Reads all data from a restart file, e.g. domain data and particle data.
Mdouble getTimeMax() const
Allows the user to access the total simulation time during the simulation. Cannot change it though...
int getRunNumber() const
This returns the current value of the counter (runNumber_)
const std::string & getName() const
Allows to access the file name, e.g., "problem.data".
DPMBase()
Constructor that calls the "void constructor()".
void writeVTK() const
Writes all walls into a vtk format, consisting of points (edges) and cells (faces).
void setOpenMode(std::fstream::openmode openMode)
Allows the user to Sets File::openMode_.
Vec3D gravity_
Gravity vector.
void clear()
Empties the whole BaseHandler by removing all Objects and setting all other variables to 0...
virtual bool checkParticleForInteractionLocal(const BaseParticle &P)
Checks if a particle P has any interaction with walls or other particles in the local domain...
virtual void setupInitialConditions()
This function allows to set the initial conditions for our problem to be solved, by default particle ...
void setSpecies(const ParticleSpecies *species)
Define the species of this wall.
void fixParticle()
Fix Particle function. It fixes a Particle by setting its inverse mass and inertia and velocities to ...
bool append_
A flag to determine if the file has to be appended or not. See DPMBase::Solve() for example...
void setMax(Vec3D max)
Sets the values xMax, yMax, zMax of the problem domain, which is [xMin,xMax]x[yMin,yMax]x[zMin,zMax].
virtual void computeExternalForces(BaseParticle *PI)
Computes the external forces acting on particles (e.g. gravitational)
std::vector< BaseInteraction * > getInteractionWith(BaseParticle *P, Mdouble timeStamp, InteractionHandler *interactionHandler)
Checks if particle is in interaction with given particle P, and if so, returns pointer to the associa...
std::string getRestartVersion() const
This is to take into account for different Mercury versions. Returns the version of the restart file...
bool isTimeEqualTo(Mdouble time) const
Checks if the input variable "time" is the current time in the simulation.