52 std::cerr <<
"Error in helpers::computeCollisionTimeFromKandDispAndEffectiveMass(Mdouble k, Mdouble disp, Mdouble mass) stiffness is not set or has an unexpected value, (stiffness=" << k <<
")" << std::endl;
57 std::cerr <<
"Error in helpers::computeCollisionTimeFromKandDispAndEffectiveMass(Mdouble k, Mdouble disp, Mdouble mass) dissipation is not set or has an unexpected value, (dissipation=" << disp <<
")" << std::endl;
62 std::cerr <<
"Error in helpers::computeCollisionTimeFromKandDispAndEffectiveMass(Mdouble k, Mdouble disp, Mdouble mass) mass is not set or has an unexpected value (mass=" << mass <<
")" << std::endl;
67 std::cerr <<
"Error in helpers::computeCollisionTimeFromKandDispAndEffectiveMass(Mdouble k, Mdouble disp, Mdouble mass) values for stiffness, dissipation and mass lead to an overdamped system (stiffness=" << k <<
" dissipation=" << disp <<
" mass=" << mass <<
")" << std::endl;
77 std::cerr <<
"Error in helpers::computeRestitutionCoefficientFromKandDispAndEffectiveMass(Mdouble k, Mdouble disp, Mdouble mass) stiffness is not set or has an unexpected value, (stiffness=" << k <<
")" << std::endl;
82 std::cerr <<
"Error in helpers::computeRestitutionCoefficientFromKandDispAndEffectiveMass(Mdouble k, Mdouble disp, Mdouble mass) dissipation is not set or has an unexpected value, (dissipation=" << disp <<
")" << std::endl;
87 std::cerr <<
"Error in helpers::computeRestitutionCoefficientFromKandDispAndEffectiveMass(Mdouble k, Mdouble disp, Mdouble mass) mass is not set or has an unexpected value (mass=" << mass <<
")" << std::endl;
92 std::cerr <<
"Error in helpers::computeRestitutionCoefficientFromKandDispAndEffectiveMass(Mdouble k, Mdouble disp, Mdouble mass) values for stiffness, dissipation and mass lead to an overdamped system (stiffness=" << k <<
" dissipation=" << disp <<
" mass=" << mass <<
")" << std::endl;
102 std::cerr <<
"Error in helpers::computeDispFromKAndRestitutionCoefficientAndEffectiveMass(Mdouble k, Mdouble r, Mdouble mass) stiffness is not set or has an unexpected value, (stiffness=" << k <<
")" << std::endl;
107 std::cerr <<
"Error in helpers::computeDispFromKAndRestitutionCoefficientAndEffectiveMass(Mdouble k, Mdouble r, Mdouble mass) restitution coefficient is not set or has an unexpected value, (restitution coefficient=" << r <<
")" << std::endl;
112 std::cerr <<
"Error in helpers::computeDispFromKAndRestitutionCoefficientAndEffectiveMass(Mdouble k, Mdouble r, Mdouble mass) mass is not set or has an unexpected value (mass=" << mass <<
")" << std::endl;
122 std::cerr <<
"Error in helpers::computeCollisionTimeFromKAndRestitutionCoefficientAndEffectiveMass(Mdouble k, Mdouble r, Mdouble mass) stiffness is not set or has an unexpected value, (stiffness=" << k <<
")" << std::endl;
127 std::cerr <<
"Error in helpers::computeCollisionTimeFromKAndRestitutionCoefficientAndEffectiveMass(Mdouble k, Mdouble r, Mdouble mass) restitution coefficient is not set or has an unexpected value, (restitution coefficient=" << r <<
")" << std::endl;
132 std::cerr <<
"Error in helpers::computeCollisionTimeFromKAndRestitutionCoefficientAndEffectiveMass(Mdouble k, Mdouble r, Mdouble mass) mass is not set or has an unexpected value (mass=" << mass <<
")" << std::endl;
142 std::cerr <<
"Error in helpers::computeDispFromKAndCollisionTimeAndEffectiveMass(Mdouble k, Mdouble tc, Mdouble mass) stiffness is not set or has an unexpected value, (stiffness=" << k <<
")" << std::endl;
147 std::cerr <<
"Error in helpers::computeDispFromKAndCollisionTimeAndEffectiveMass(Mdouble k, Mdouble tc, Mdouble mass) collision time is not set or has an unexpected value, (collision time=" << tc <<
")" << std::endl;
152 std::cerr <<
"Error in helpers::computeDispFromKAndCollisionTimeAndEffectiveMass(Mdouble k, Mdouble tc, Mdouble mass) mass is not set or has an unexpected value (mass=" << mass <<
")" << std::endl;
157 std::cerr <<
"Error in helpers::computeDispFromKAndCollisionTimeAndEffectiveMass(Mdouble k, Mdouble disp, Mdouble mass) values for stiffness, collision time and mass lead to an overdamped system (stiffness=" << k <<
" collision time=" << tc <<
" mass=" << mass <<
")" << std::endl;
167 std::cerr <<
"Error in helpers::computeRestitutionCoefficientFromKAndCollisionTimeAndEffectiveMass(Mdouble k, Mdouble tc, Mdouble mass) stiffness is not set or has an unexpected value, (stiffness=" << k <<
")" << std::endl;
172 std::cerr <<
"Error in helpers::computeRestitutionCoefficientFromKAndCollisionTimeAndEffectiveMass(Mdouble k, Mdouble tc, Mdouble mass) collision time is not set or has an unexpected value, (collision time=" << tc <<
")" << std::endl;
177 std::cerr <<
"Error in helpers::computeRestitutionCoefficientFromKAndCollisionTimeAndEffectiveMass(Mdouble k, Mdouble tc, Mdouble mass) mass is not set or has an unexpected value (mass=" << mass <<
")" << std::endl;
182 std::cerr <<
"Error in helpers::computeRestitutionCoefficientFromKAndCollisionTimeAndEffectiveMass(Mdouble k, Mdouble disp, Mdouble mass) values for stiffness, collision time and mass lead to an overdamped system (stiffness=" << k <<
" collision time=" << tc <<
" mass=" << mass <<
")" << std::endl;
192 std::cerr <<
"Error in helpers::computeDispFromCollisionTimeAndRestitutionCoefficientAndEffectiveMass(Mdouble tc, Mdouble r, Mdouble mass) collision time is not set or has an unexpected value, (collision time=" << tc <<
")" << std::endl;
197 std::cerr <<
"Error in helpers::computeDispFromCollisionTimeAndRestitutionCoefficientAndEffectiveMass(Mdouble tc, Mdouble r, Mdouble mass) restitution coefficient not set or has an unexpected value, (restitution coefficient=" << r <<
")" << std::endl;
202 std::cerr <<
"Error in helpers::computeDispFromCollisionTimeAndRestitutionCoefficientAndEffectiveMass(Mdouble tc, Mdouble r, Mdouble mass) mass is not set or has an unexpected value (mass=" << mass <<
")" << std::endl;
205 return -2.0 * mass *
std::log(r) / tc;
212 std::cerr <<
"Error in helpers::computeKFromCollisionTimeAndRestitutionCoefficientAndEffectiveMass(Mdouble tc, Mdouble r, Mdouble mass) collision time is not set or has an unexpected value, (collision time=" << tc <<
")" << std::endl;
217 std::cerr <<
"Error in helpers::computeKFromCollisionTimeAndRestitutionCoefficientAndEffectiveMass(Mdouble tc, Mdouble r, Mdouble mass) restitution coefficient not set or has an unexpected value, (restitution coefficient=" << r <<
")" << std::endl;
222 std::cerr <<
"Error in helpers::computeKFromCollisionTimeAndRestitutionCoefficientAndEffectiveMass(Mdouble tc, Mdouble r, Mdouble mass) mass is not set or has an unexpected value (mass=" << mass <<
")" << std::endl;
232 std::cerr <<
"Error in helpers::computeKFromCollisionTimeAndDispAndEffectiveMass(Mdouble tc, Mdouble disp, Mdouble mass) collision time is not set or has an unexpected value, (collision time=" << tc <<
")" << std::endl;
237 std::cerr <<
"Error in helpers::computeKFromCollisionTimeAndDispAndEffectiveMass(Mdouble tc, Mdouble disp, Mdouble mass) dissipation not set or has an unexpected value, (dissipation=" << disp <<
")" << std::endl;
242 std::cerr <<
"Error in helpers::computeKFromCollisionTimeAndDispAndEffectiveMass(Mdouble tc, Mdouble disp, Mdouble mass) mass is not set or has an unexpected value (mass=" << mass <<
")" << std::endl;
252 std::cerr <<
"Error in helpers::computeRestitutionCoefficientFromCollisionTimeAndDispAndEffectiveMass(Mdouble tc, Mdouble disp, Mdouble mass) collision time is not set or has an unexpected value, (collision time=" << tc <<
")" << std::endl;
257 std::cerr <<
"Error in helpers::computeRestitutionCoefficientFromCollisionTimeAndDispAndEffectiveMass(Mdouble tc, Mdouble disp, Mdouble mass) dissipation not set or has an unexpected value, (dissipation=" << disp <<
")" << std::endl;
262 std::cerr <<
"Error in helpers::computeRestitutionCoefficientFromCollisionTimeAndDispAndEffectiveMass(Mdouble tc, Mdouble disp, Mdouble mass) mass is not set or has an unexpected value (mass=" << mass <<
")" << std::endl;
265 return std::exp(-0.5 * disp * tc / mass);
272 std::cerr <<
"Error in helpers::computeKFromDispAndRestitutionCoefficientAndEffectiveMass(Mdouble disp, Mdouble r, Mdouble mass) dissipation is not set or has an unexpected value, (dissipation time=" << disp <<
")" << std::endl;
277 std::cerr <<
"Error in helpers::computeKFromDispAndRestitutionCoefficientAndEffectiveMass(Mdouble disp, Mdouble r, Mdouble mass) restitution coefficient not set or has an unexpected value, (restitution coefficient=" << r <<
")" << std::endl;
282 std::cerr <<
"Error in helpers::computeKFromDispAndRestitutionCoefficientAndEffectiveMass(Mdouble disp, Mdouble r, Mdouble mass) mass is not set or has an unexpected value (mass=" << mass <<
")" << std::endl;
292 std::cerr <<
"Error in helpers::computeCollisionTimeFromDispAndRestitutionCoefficientAndEffectiveMass(Mdouble disp, Mdouble r, Mdouble mass) dissipation is not set or has an unexpected value, (dissipation time=" << disp <<
")" << std::endl;
297 std::cerr <<
"Error in helpers::computeCollisionTimeFromDispAndRestitutionCoefficientAndEffectiveMass(Mdouble disp, Mdouble r, Mdouble mass) restitution coefficient not set or has an unexpected value, (restitution coefficient=" << r <<
")" << std::endl;
302 std::cerr <<
"Error in helpers::computeCollisionTimeFromDispAndRestitutionCoefficientAndEffectiveMass(Mdouble disp, Mdouble r, Mdouble mass) mass is not set or has an unexpected value (mass=" << mass <<
")" << std::endl;
305 return -2.0 * mass *
std::log(r) / disp;
312 ans.
disp = -2.0 * mass *
log(r) / tc;
318 ans.
dispt = 2. * sqrt(1.0 / 7.0 * mass * ans.
kt);
331 Mdouble DispCorrection =
exp(-disp / mass / w) * asin(w / w0);
333 return radius * sqrt(8.0 * k / mass) / DispCorrection;
352 if (numberOfSaves > 0 && timeMax > 0 && timestep > 0)
354 return static_cast<unsigned int>(ceil((timeMax + timestep) / timestep / static_cast<double>(numberOfSaves - 1)));
358 logger(
ERROR,
"[Helpers::getSaveCountFromNumberOfSavesAndTimeMaxAndTimestep()] numberOfSaves: %, timeMax: %, timestep: %", numberOfSaves, timeMax, timestep);
398 std::string line_string;
399 getline(in, line_string);
400 out.str(line_string);
421 file.open(filename.c_str(), std::ios::out);
424 std::cerr <<
"Error in writeToFile: file could not be opened" << std::endl;
435 file.open(filename.c_str(), std::ios::app);
438 std::cerr <<
"Error in writeToFile: file could not be opened" << std::endl;
452 struct stat stFileInfo;
458 intStat = stat(strFilename.c_str(), &stFileInfo);
489 file.open(filename.c_str(), mode);
505 return mass0 * mass1 / (mass0 + mass1);
511 file.open(filename.c_str(), std::ios::in);
514 std::cerr <<
"Error in readArrayFromFile: file could not be opened" << std::endl;
518 std::vector<double> v;
520 for (
int i=0; i<n*m; i++)
537 class LoadingTest :
public DPMBase {
545 : species(species), displacement(displacement), velocity(velocity), radius(radius) {}
556 setMax({radius,radius,radius+radius});
557 setMin({-radius,-radius,0});
561 speciesHandler.copyAndAddObject(*species);
567 particleHandler.copyAndAddObject(p);
572 wallHandler.copyAndAddObject(w);
581 if (
getTime() <= displacement/velocity) {
589 } test(species, displacement, velocity, radius);
592 writeToFile(test.getName()+
".gnu",
"plot '"+test.getName()+
".fstat' u 7:9 w lp");
593 logger(
INFO,
"finished loading test: run 'gnuplot %.gnu' to view output",test.getName());
606 class LoadingTest :
public DPMBase {
609 Mdouble tangentialDisplacement;
615 : species(species), displacement(displacement), tangentialDisplacement(tangentialDisplacement), velocity(velocity), radius(radius) {}
620 setTimeMax(4.0*tangentialDisplacement/velocity);
626 setMax({radius,radius,radius+radius});
627 setMin({-radius,-radius,0});
631 speciesHandler.copyAndAddObject(*species);
637 particleHandler.copyAndAddObject(p);
642 wallHandler.copyAndAddObject(w);
655 }
else if (time <= 3.0) {
657 p->
setPosition({2.0*tangentialDisplacement-velocity*
getTime(),0,radius-displacement});
660 p->
setPosition({-4.0*tangentialDisplacement+velocity*
getTime(),0,radius-displacement});
664 } test(species, displacement, tangentialDisplacement, velocity, radius);
667 writeToFile(test.getName()+
".gnu",
"plot '"+test.getName()+
".fstat' u 8:($10*$14) w lp");
668 logger(
INFO,
"finished tangential loading test: run 'gnuplot %.gnu' to view output",test.getName());
679 class ObjectivenessTest :
public DPMBase {
682 Mdouble tangentialDisplacement;
688 : species(species), displacement(displacement), tangentialDisplacement(tangentialDisplacement), velocity(velocity), radius(radius) {}
705 speciesHandler.copyAndAddObject(*species);
711 particleHandler.copyAndAddObject(p);
713 particleHandler.copyAndAddObject(p);
723 if (
getTime() <= tangentialDisplacement/velocity) {
731 Mdouble angle = velocity/(radius-displacement) * (
getTime()-tangentialDisplacement/velocity);
747 } test (species, displacement, tangentialDisplacement, velocity, radius);
750 writeToFile(test.getName()+
".gnu",
"set size ratio -1; plot '"+test.getName()+
".fstat' u 14:15 every 2 w lp");
751 logger(
INFO,
"finished objectiveness test: run 'gnuplot %.gnu' to view output",test.getName());
758 int len = is.tellg();
761 if (dummy.compare(s) != 0)
763 is.seekg(len, std::ios_base::beg);
765 logger(
INFO,
"helpers::compare: Next stream value (%) is not %", dummy,s);
770 void helpers::check(
double real,
double ideal,
double error, std::string errorMessage) {
772 errorMessage +
": % (should be %) ",real, ideal);
MERCURY_DEPRECATED KAndDispAndKtAndDispt computeDisptFromCollisionTimeAndRestitutionCoefficientAndTangentialRestitutionCoefficientAndEffectiveMass(Mdouble tc, Mdouble r, Mdouble beta, Mdouble mass)
Set disp, k, dispt and kt such that is matches a given collision time tc and a normal andtangential r...
bool writeToFile(std::string filename, std::string filecontent)
Writes a string to a file.
The DPMBase header includes quite a few header files, defining all the handlers, which are essential...
void setVelocity(const Vec3D &velocity)
set the velocity of the BaseInteractable.
void setTimeMax(Mdouble newTMax)
Allows the upper time limit to be changed.
Mdouble getEffectiveMass(Mdouble mass0, Mdouble mass1)
Calculates the effective mass of a particle pair, i.e. half the harmonic mean of two particle masses...
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
return type specifically for fuctions returning k and disp at once
void setOrientation(const Vec3D &orientation)
Sets the orientation of this BaseInteractable.
MERCURY_DEPRECATED Mdouble computeRestitutionCoefficientFromKAndDispAndEffectiveMass(Mdouble k, Mdouble disp, Mdouble mass)
Calculates the restitution coefficient time for a given stiffness, dissipation, and effective mass...
LL< Log::INFO > INFO
Info log level.
Mdouble exp(Mdouble Exponent)
MERCURY_DEPRECATED Mdouble computeRestitutionCoefficientFromKAndCollisionTimeAndEffectiveMass(Mdouble k, Mdouble tc, Mdouble mass)
Calculates the restitution coefficient for a given stiffness, collision time, and effective mass...
void check(double real, double ideal, double error, std::string errorMessage)
void setParticleDimensions(unsigned int particleDimensions)
Allows the dimension of the particle (f.e. for mass) to be changed. e.g. discs or spheres...
virtual const Vec3D & getAngularVelocity() const
Returns the angular velocity of this interactable.
void setSpecies(const ParticleSpecies *species)
return type specifically for fuctions returning k, disp, kt, dispt at once
void normalAndTangentialLoadingTest(const ParticleSpecies *species, Mdouble displacement, Mdouble tangentialDisplacement, Mdouble velocity, Mdouble radius, std::string name)
Used to test the tangential loading/unloading/reloading properties of a frictional contact law...
void setSystemDimensions(unsigned int newDim)
Allows for the dimension of the simulation to be changed.
void setFileType(FileType fileType)
Sets File::fileType_ for all files (ene, data, fstat, restart, stat)
Mdouble log(Mdouble Power)
LL< Log::ERROR > ERROR
Error log level.
bool isEqual(Mdouble v1, Mdouble v2, Mdouble absError)
Compares the difference of two Mdouble with an absolute error, useful in UnitTests.
T square(T val)
squares a number
void setRadius(const Mdouble radius)
Sets the particle's radius_ (and adjusts the mass_ accordingly, based on the particle's species) ...
const Vec3D & getPosition() const
Returns the position of this BaseInteractable.
const Vec3D & getOrientation() const
Returns the orientation of this BaseInteractable.
MERCURY_DEPRECATED Mdouble computeKFromCollisionTimeAndDispAndEffectiveMass(Mdouble tc, Mdouble disp, Mdouble mass)
Calculates the stiffness for a given collision time, dissipation, and effective mass.
MERCURY_DEPRECATED KAndDisp computeKAndDispFromCollisionTimeAndRestitutionCoefficientAndEffectiveMass(Mdouble tc, Mdouble r, Mdouble mass)
Set disp and k such that is matches a given collision time tc and restitution coefficient r for a col...
MERCURY_DEPRECATED Mdouble computeCollisionTimeFromKAndRestitutionCoefficientAndEffectiveMass(Mdouble k, Mdouble r, Mdouble mass)
Calculates the collision time for a given stiffness, restitution coefficient, and effective mass...
MERCURY_DEPRECATED Mdouble computeDispFromKAndRestitutionCoefficientAndEffectiveMass(Mdouble k, Mdouble r, Mdouble mass)
Calculates the dissipation for a given stiffness, restitution coefficient, and effective mass...
file will not be created/read
void getLineFromStringStream(std::istream &in, std::stringstream &out)
Reads a line from one stringstream into another, and prepares the latter for reading in...
all data will be written into/ read from a single file called name_
void setSaveCount(unsigned int saveCount)
Sets File::saveCount_ for all files (ene, data, fstat, restart, stat)
MERCURY_DEPRECATED Mdouble computeCollisionTimeFromDispAndRestitutionCoefficientAndEffectiveMass(Mdouble disp, Mdouble r, Mdouble mass)
Calculates the collision time for a given dissipation, restitution coefficient, and effective mass...
void loadingTest(const ParticleSpecies *species, Mdouble displacement, Mdouble velocity, Mdouble radius, std::string name)
Used to test the loading/unloading properties of a contact law.
virtual void actionsBeforeTimeStep()
A virtual function which allows to define operations to be executed before the new time step...
MERCURY_DEPRECATED Mdouble computeRestitutionCoefficientFromCollisionTimeAndDispAndEffectiveMass(Mdouble tc, Mdouble disp, Mdouble mass)
Calculates the resitution coefficient for a given collision time, dissipation, and effective mass...
void setPosition(const Vec3D &position)
Sets the position of this BaseInteractable.
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...
MERCURY_DEPRECATED Mdouble computeKFromCollisionTimeAndRestitutionCoefficientAndEffectiveMass(Mdouble tc, Mdouble r, Mdouble mass)
Calculates the stiffness for a given collision time, restitution coefficient, and effective mass...
MERCURY_DEPRECATED Mdouble computeDispFromCollisionTimeAndRestitutionCoefficientAndEffectiveMass(Mdouble tc, Mdouble r, Mdouble mass)
Calculates the dissipation for a given collision time, restitution coefficient, and effective mass...
void setTimeStep(Mdouble newDt)
Allows the time step dt to be changed.
bool compare(std::istream &is, std::string s)
void setMin(Vec3D min)
Sets the values xMin, yMin, zMin of the problem domain, which is [xMin,xMax]x[yMin,yMax]x[zMin,zMax].
This is a class defining walls.
bool fileExists(std::string strFilename)
Function to check if a file exists, is used to check if a run has already need done.
MERCURY_DEPRECATED Mdouble getMaximumVelocity(Mdouble k, Mdouble disp, Mdouble radius, Mdouble mass)
Calculates the maximum relative velocity allowed for a normal collision of two particles of radius r ...
virtual const Vec3D & getVelocity() const
Returns the velocity of this interactable.
Implementation of a 3D vector (by Vitaliy).
MERCURY_DEPRECATED Mdouble computeCollisionTimeFromKAndDispAndEffectiveMass(Mdouble k, Mdouble disp, Mdouble mass)
Calculates the collision time for a given stiffness, dissipation, and effective mass.
bool openFile(std::fstream &file, std::string filename, std::fstream::openmode mode)
Provides a simple interface for opening a file.
void objectivenessTest(const ParticleSpecies *species, Mdouble displacement, Mdouble tangentialDisplacement, Mdouble velocity, Mdouble radius, std::string name)
Used to test the tangential loading/unloading/reloading properties of a frictional contact law...
bool addToFile(std::string filename, std::string filecontent)
Adds a string to an existing file.
void setAngularVelocity(const Vec3D &angularVelocity)
set the angular velocity of the BaseInteractble.
MERCURY_DEPRECATED Mdouble computeKFromDispAndRestitutionCoefficientAndEffectiveMass(Mdouble disp, Mdouble r, Mdouble mass)
Calculates the stiffness for a given dissipation, restitution coefficient, and effective mass...
MERCURY_DEPRECATED Mdouble computeDispFromKAndCollisionTimeAndEffectiveMass(Mdouble k, Mdouble tc, Mdouble mass)
Calculates the dissipation for a given stiffness, collision time, and effective mass.
unsigned int getSaveCountFromNumberOfSavesAndTimeMaxAndTimestep(unsigned int numberOfSaves, Mdouble timeMax, Mdouble timestep)
Returns the correct saveCount if the total number of saves, the final time and the time step is known...
Mdouble getTime() const
Access function for the time.
Mdouble getTimeMax() const
Allows the user to access the total simulation time during the simulation. Cannot change it though...
std::vector< double > readArrayFromFile(std::string filename, int &n, int &m)
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 setMax(Vec3D max)
Sets the values xMax, yMax, zMax of the problem domain, which is [xMin,xMax]x[yMin,yMax]x[zMin,zMax].