MercuryDPM  Alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
helpers Namespace Reference

Classes

class  KAndDisp
 return type specifically for fuctions returning k and disp at once More...
 
class  KAndDispAndKtAndDispt
 return type specifically for fuctions returning k, disp, kt, dispt at once More...
 

Functions

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 collision of effective/reduced mass m. More...
 
MERCURY_DEPRECATED Mdouble computeCollisionTimeFromKAndDispAndEffectiveMass (Mdouble k, Mdouble disp, Mdouble mass)
 Calculates the collision time for a given stiffness, dissipation, and effective mass. More...
 
MERCURY_DEPRECATED Mdouble computeRestitutionCoefficientFromKAndDispAndEffectiveMass (Mdouble k, Mdouble disp, Mdouble mass)
 Calculates the restitution coefficient time for a given stiffness, dissipation, and effective mass. More...
 
MERCURY_DEPRECATED Mdouble computeDispFromKAndRestitutionCoefficientAndEffectiveMass (Mdouble k, Mdouble r, Mdouble mass)
 Calculates the dissipation for a given stiffness, restitution coefficient, and effective mass. More...
 
MERCURY_DEPRECATED Mdouble computeCollisionTimeFromKAndRestitutionCoefficientAndEffectiveMass (Mdouble k, Mdouble r, Mdouble mass)
 Calculates the collision time for a given stiffness, restitution coefficient, and effective mass. More...
 
MERCURY_DEPRECATED Mdouble computeDispFromKAndCollisionTimeAndEffectiveMass (Mdouble k, Mdouble tc, Mdouble mass)
 Calculates the dissipation for a given stiffness, collision time, and effective mass. More...
 
MERCURY_DEPRECATED Mdouble computeRestitutionCoefficientFromKAndCollisionTimeAndEffectiveMass (Mdouble k, Mdouble tc, Mdouble mass)
 Calculates the restitution coefficient for a given stiffness, collision time, and effective mass. More...
 
MERCURY_DEPRECATED Mdouble computeDispFromCollisionTimeAndRestitutionCoefficientAndEffectiveMass (Mdouble tc, Mdouble r, Mdouble mass)
 Calculates the dissipation for a given collision time, restitution coefficient, and effective mass. More...
 
MERCURY_DEPRECATED Mdouble computeKFromCollisionTimeAndRestitutionCoefficientAndEffectiveMass (Mdouble tc, Mdouble r, Mdouble mass)
 Calculates the stiffness for a given collision time, restitution coefficient, and effective mass. More...
 
MERCURY_DEPRECATED Mdouble computeKFromCollisionTimeAndDispAndEffectiveMass (Mdouble tc, Mdouble disp, Mdouble mass)
 Calculates the stiffness for a given collision time, dissipation, and effective mass. More...
 
MERCURY_DEPRECATED Mdouble computeRestitutionCoefficientFromCollisionTimeAndDispAndEffectiveMass (Mdouble tc, Mdouble disp, Mdouble mass)
 Calculates the resitution coefficient for a given collision time, dissipation, and effective mass. More...
 
MERCURY_DEPRECATED Mdouble computeKFromDispAndRestitutionCoefficientAndEffectiveMass (Mdouble disp, Mdouble r, Mdouble mass)
 Calculates the stiffness for a given dissipation, restitution coefficient, and effective mass. More...
 
MERCURY_DEPRECATED Mdouble computeCollisionTimeFromDispAndRestitutionCoefficientAndEffectiveMass (Mdouble disp, Mdouble r, Mdouble mass)
 Calculates the collision time for a given dissipation, restitution coefficient, and effective mass. More...
 
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 restitution coefficient r, beta for a collision of effective/reduced mass m. From Deen...Kuipers2006, eq. 43 and 30. More...
 
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 and particle mass m (for higher velocities particles could pass through each other) More...
 
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. More...
 
void getLineFromStringStream (std::istream &in, std::stringstream &out)
 Reads a line from one stringstream into another, and prepares the latter for reading in. More...
 
bool writeToFile (std::string filename, std::string filecontent)
 Writes a string to a file. More...
 
bool addToFile (std::string filename, std::string filecontent)
 Adds a string to an existing file. More...
 
bool fileExists (std::string strFilename)
 Function to check if a file exists, is used to check if a run has already need done. More...
 
bool openFile (std::fstream &file, std::string filename, std::fstream::openmode mode)
 Provides a simple interface for opening a file. More...
 
Mdouble getEffectiveMass (Mdouble mass0, Mdouble mass1)
 Calculates the effective mass of a particle pair, i.e. half the harmonic mean of two particle masses. More...
 
std::vector< double > readArrayFromFile (std::string filename, int &n, int &m)
 
template<typename T >
std::string to_string (const T &n)
 
template<typename T >
void readOptionalVariable (std::istream &is, std::string name, T &variable)
 
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. More...
 
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. More...
 
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. More...
 
template<typename T >
readFromFile (std::string fileName, std::string varName, T value)
 Allows a quick read-in from a parameter file. More...
 
bool compare (std::istream &is, std::string s)
 
void check (double real, double ideal, double error, std::string errorMessage)
 

Function Documentation

bool helpers::addToFile ( std::string  filename,
std::string  filecontent 
)

Adds a string to an existing file.

Definition at line 432 of file Helpers.cc.

433 {
434  std::fstream file;
435  file.open(filename.c_str(), std::ios::app);
436  if (file.fail())
437  {
438  std::cerr << "Error in writeToFile: file could not be opened" << std::endl;
439  return false;
440  }
441  file << filecontent;
442  file.close();
443  return true;
444 }
void helpers::check ( double  real,
double  ideal,
double  error,
std::string  errorMessage 
)

Definition at line 770 of file Helpers.cc.

References mathsFunc::isEqual(), and logger.

770  {
771  logger.assert_always(mathsFunc::isEqual(real, ideal, error),
772  errorMessage + ": % (should be %) ",real, ideal);
773 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
bool isEqual(Mdouble v1, Mdouble v2, Mdouble absError)
Compares the difference of two Mdouble with an absolute error, useful in UnitTests.
bool helpers::compare ( std::istream &  is,
std::string  s 
)

Definition at line 754 of file Helpers.cc.

References INFO, and logger.

Referenced by File::open(), DPMBase::write(), and File::write().

755 {
756  // Get current position
757  //check if the next line starts with 'interactionFile'; otherwise, skip interaction
758  int len = is.tellg();
759  std::string dummy;
760  is >> dummy;
761  if (dummy.compare(s) != 0)
762  {
763  is.seekg(len, std::ios_base::beg);
764  return false;
765  logger(INFO, "helpers::compare: Next stream value (%) is not %", dummy,s);
766  }
767  return true;
768 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
LL< Log::INFO > INFO
Info log level.
Definition: Logger.cc:53
Mdouble helpers::computeCollisionTimeFromDispAndRestitutionCoefficientAndEffectiveMass ( Mdouble  disp,
Mdouble  r,
Mdouble  mass 
)

Calculates the collision time for a given dissipation, restitution coefficient, and effective mass.

Deprecated:
use species->computeCollisionTime(2.0*effectiveMass) instead

Definition at line 288 of file Helpers.cc.

References mathsFunc::log().

289 {
290  if (disp <= 0)
291  {
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;
293  exit(-1);
294  }
295  if (r < 0)
296  {
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;
298  exit(-1);
299  }
300  if (mass <= 0)
301  {
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;
303  exit(-1);
304  }
305  return -2.0 * mass * std::log(r) / disp;
306 }
Mdouble log(Mdouble Power)
Definition: ExtendedMath.cc:97
Mdouble helpers::computeCollisionTimeFromKAndDispAndEffectiveMass ( Mdouble  k,
Mdouble  disp,
Mdouble  mass 
)

Calculates the collision time for a given stiffness, dissipation, and effective mass.

Deprecated:
use species->computeCollisionTime(2.0*effectiveMass) instead
Todo:
This does not result in the same value as the given alternative.

Definition at line 48 of file Helpers.cc.

References constants::pi, and mathsFunc::square().

49 {
50  if (k <= 0)
51  {
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;
53  exit(-1);
54  }
55  if (disp < 0)
56  {
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;
58  exit(-1);
59  }
60  if (mass <= 0)
61  {
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;
63  exit(-1);
64  }
65  if (4.0 * k / mass - mathsFunc::square(disp / mass) < 0)
66  {
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;
68  exit(-1);
69  }
70  return 2.0 * constants::pi / std::sqrt(4.0 * k / mass - mathsFunc::square(disp / mass));
71 }
T square(T val)
squares a number
Definition: ExtendedMath.h:91
const Mdouble pi
Definition: ExtendedMath.h:42
Mdouble helpers::computeCollisionTimeFromKAndRestitutionCoefficientAndEffectiveMass ( Mdouble  k,
Mdouble  r,
Mdouble  mass 
)

Calculates the collision time for a given stiffness, restitution coefficient, and effective mass.

Deprecated:
use species->computeCollisionTime(2.0*effectiveMass) instead

Definition at line 118 of file Helpers.cc.

References mathsFunc::log(), constants::sqr_pi, and mathsFunc::square().

119 {
120  if (k <= 0)
121  {
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;
123  exit(-1);
124  }
125  if (r < 0)
126  {
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;
128  exit(-1);
129  }
130  if (mass <= 0)
131  {
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;
133  exit(-1);
134  }
135  return sqrt(mass / k * (constants::sqr_pi + mathsFunc::square(std::log(r))));
136 }
Mdouble log(Mdouble Power)
Definition: ExtendedMath.cc:97
T square(T val)
squares a number
Definition: ExtendedMath.h:91
const Mdouble sqr_pi
Definition: ExtendedMath.h:44
Mdouble helpers::computeDispFromCollisionTimeAndRestitutionCoefficientAndEffectiveMass ( Mdouble  tc,
Mdouble  r,
Mdouble  mass 
)

Calculates the dissipation for a given collision time, restitution coefficient, and effective mass.

Deprecated:
use species->setCollisionTimeAndRestitutionCoefficient(2.0*effectiveMass) instead

Definition at line 188 of file Helpers.cc.

References mathsFunc::log().

Referenced by computeKAndDispFromCollisionTimeAndRestitutionCoefficientAndEffectiveMass().

189 {
190  if (tc <= 0)
191  {
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;
193  exit(-1);
194  }
195  if (r < 0)
196  {
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;
198  exit(-1);
199  }
200  if (mass <= 0)
201  {
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;
203  exit(-1);
204  }
205  return -2.0 * mass * std::log(r) / tc;
206 }
Mdouble log(Mdouble Power)
Definition: ExtendedMath.cc:97
Mdouble helpers::computeDispFromKAndCollisionTimeAndEffectiveMass ( Mdouble  k,
Mdouble  tc,
Mdouble  mass 
)

Calculates the dissipation for a given stiffness, collision time, and effective mass.

Deprecated:
use species->setStiffnessAndRestitutionCoefficient(2.0*effectiveMass) instead

Definition at line 138 of file Helpers.cc.

References constants::sqr_pi, and mathsFunc::square().

139 {
140  if (k <= 0)
141  {
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;
143  exit(-1);
144  }
145  if (tc <= 0)
146  {
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;
148  exit(-1);
149  }
150  if (mass <= 0)
151  {
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;
153  exit(-1);
154  }
155  if (mass * k - constants::sqr_pi * mathsFunc::square(mass / tc) < 0)
156  {
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;
158  exit(-1);
159  }
160  return 2.0 * std::sqrt(mass * k - constants::sqr_pi * mathsFunc::square(mass / tc));
161 }
T square(T val)
squares a number
Definition: ExtendedMath.h:91
const Mdouble sqr_pi
Definition: ExtendedMath.h:44
Mdouble helpers::computeDispFromKAndRestitutionCoefficientAndEffectiveMass ( Mdouble  k,
Mdouble  r,
Mdouble  mass 
)

Calculates the dissipation for a given stiffness, restitution coefficient, and effective mass.

Definition at line 98 of file Helpers.cc.

References mathsFunc::log(), constants::sqr_pi, and mathsFunc::square().

99 {
100  if (k <= 0)
101  {
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;
103  exit(-1);
104  }
105  if (r < 0)
106  {
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;
108  exit(-1);
109  }
110  if (mass <= 0)
111  {
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;
113  exit(-1);
114  }
115  return -2.0 * sqrt(mass * k / (constants::sqr_pi + mathsFunc::square(std::log(r)))) * std::log(r);
116 }
Mdouble log(Mdouble Power)
Definition: ExtendedMath.cc:97
T square(T val)
squares a number
Definition: ExtendedMath.h:91
const Mdouble sqr_pi
Definition: ExtendedMath.h:44
helpers::KAndDispAndKtAndDispt helpers::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 restitution coefficient r, beta for a collision of effective/reduced mass m. From Deen...Kuipers2006, eq. 43 and 30.

from Deen...Kuipers2006, eq. 43 and 30

Todo:
what should be used instead of this function?

Definition at line 309 of file Helpers.cc.

References helpers::KAndDispAndKtAndDispt::disp, helpers::KAndDispAndKtAndDispt::dispt, helpers::KAndDispAndKtAndDispt::k, helpers::KAndDispAndKtAndDispt::kt, mathsFunc::log(), constants::pi, and mathsFunc::square().

310 {
312  ans.disp = -2.0 * mass * log(r) / tc;
313  ans.k = mass * (mathsFunc::square(constants::pi / tc) + mathsFunc::square(ans.disp / (2.0 * mass)));
315  if (beta != 0.0)
316  ans.dispt = -2 * log(beta) * sqrt(1.0 / 7.0 * mass * ans.kt / (mathsFunc::square(constants::pi) + mathsFunc::square(log(beta))));
317  else
318  ans.dispt = 2. * sqrt(1.0 / 7.0 * mass * ans.kt);
319  return ans;
320 }
return type specifically for fuctions returning k, disp, kt, dispt at once
Definition: Helpers.h:143
Mdouble log(Mdouble Power)
Definition: ExtendedMath.cc:97
T square(T val)
squares a number
Definition: ExtendedMath.h:91
const Mdouble pi
Definition: ExtendedMath.h:42
helpers::KAndDisp helpers::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 collision of effective/reduced mass m.

Deprecated:
use species->setCollisionTimeAndRestitutionCoefficient(collisionTime, dissipationTimeScale, 2.0*effectiveMass); instead

Definition at line 40 of file Helpers.cc.

References computeDispFromCollisionTimeAndRestitutionCoefficientAndEffectiveMass(), computeKFromCollisionTimeAndRestitutionCoefficientAndEffectiveMass(), helpers::KAndDisp::disp, and helpers::KAndDisp::k.

41 {
45  return ans;
46 }
return type specifically for fuctions returning k and disp at once
Definition: Helpers.h:42
Mdouble disp
Definition: Helpers.h:46
MERCURY_DEPRECATED Mdouble computeKFromCollisionTimeAndRestitutionCoefficientAndEffectiveMass(Mdouble tc, Mdouble r, Mdouble mass)
Calculates the stiffness for a given collision time, restitution coefficient, and effective mass...
Definition: Helpers.cc:208
MERCURY_DEPRECATED Mdouble computeDispFromCollisionTimeAndRestitutionCoefficientAndEffectiveMass(Mdouble tc, Mdouble r, Mdouble mass)
Calculates the dissipation for a given collision time, restitution coefficient, and effective mass...
Definition: Helpers.cc:188
Mdouble helpers::computeKFromCollisionTimeAndDispAndEffectiveMass ( Mdouble  tc,
Mdouble  disp,
Mdouble  mass 
)

Calculates the stiffness for a given collision time, dissipation, and effective mass.

Definition at line 228 of file Helpers.cc.

References constants::sqr_pi, and mathsFunc::square().

229 {
230  if (tc <= 0)
231  {
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;
233  exit(-1);
234  }
235  if (disp < 0)
236  {
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;
238  exit(-1);
239  }
240  if (mass <= 0)
241  {
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;
243  exit(-1);
244  }
245  return 0.25 * mathsFunc::square(disp) / mass + constants::sqr_pi * mass / mathsFunc::square(tc);
246 }
T square(T val)
squares a number
Definition: ExtendedMath.h:91
const Mdouble sqr_pi
Definition: ExtendedMath.h:44
Mdouble helpers::computeKFromCollisionTimeAndRestitutionCoefficientAndEffectiveMass ( Mdouble  tc,
Mdouble  r,
Mdouble  mass 
)

Calculates the stiffness for a given collision time, restitution coefficient, and effective mass.

Deprecated:
use species->setCollisionTimeAndRestitutionCoefficient(2.0*effectiveMass) instead

Definition at line 208 of file Helpers.cc.

References mathsFunc::log(), constants::pi, and mathsFunc::square().

Referenced by computeKAndDispFromCollisionTimeAndRestitutionCoefficientAndEffectiveMass().

209 {
210  if (tc <= 0)
211  {
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;
213  exit(-1);
214  }
215  if (r < 0)
216  {
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;
218  exit(-1);
219  }
220  if (mass <= 0)
221  {
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;
223  exit(-1);
224  }
225  return mass * (mathsFunc::square(constants::pi / tc) + mathsFunc::square(-std::log(r) / tc));
226 }
Mdouble log(Mdouble Power)
Definition: ExtendedMath.cc:97
T square(T val)
squares a number
Definition: ExtendedMath.h:91
const Mdouble pi
Definition: ExtendedMath.h:42
Mdouble helpers::computeKFromDispAndRestitutionCoefficientAndEffectiveMass ( Mdouble  disp,
Mdouble  r,
Mdouble  mass 
)

Calculates the stiffness for a given dissipation, restitution coefficient, and effective mass.

Definition at line 268 of file Helpers.cc.

References mathsFunc::log(), constants::sqr_pi, and mathsFunc::square().

269 {
270  if (disp <= 0)
271  {
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;
273  exit(-1);
274  }
275  if (r < 0)
276  {
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;
278  exit(-1);
279  }
280  if (mass <= 0)
281  {
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;
283  exit(-1);
284  }
285  return 0.25 * mathsFunc::square(disp)*(constants::sqr_pi / (mathsFunc::square(std::log(r))) + 1.0) / mass;
286 }
Mdouble log(Mdouble Power)
Definition: ExtendedMath.cc:97
T square(T val)
squares a number
Definition: ExtendedMath.h:91
const Mdouble sqr_pi
Definition: ExtendedMath.h:44
Mdouble helpers::computeRestitutionCoefficientFromCollisionTimeAndDispAndEffectiveMass ( Mdouble  tc,
Mdouble  disp,
Mdouble  mass 
)

Calculates the resitution coefficient for a given collision time, dissipation, and effective mass.

Deprecated:
use species->computeRestitutionCoefficient(2.0*effectiveMass) instead

Definition at line 248 of file Helpers.cc.

References mathsFunc::exp().

249 {
250  if (tc <= 0)
251  {
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;
253  exit(-1);
254  }
255  if (disp < 0)
256  {
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;
258  exit(-1);
259  }
260  if (mass <= 0)
261  {
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;
263  exit(-1);
264  }
265  return std::exp(-0.5 * disp * tc / mass);
266 }
Mdouble exp(Mdouble Exponent)
Definition: ExtendedMath.cc:78
Mdouble helpers::computeRestitutionCoefficientFromKAndCollisionTimeAndEffectiveMass ( Mdouble  k,
Mdouble  tc,
Mdouble  mass 
)

Calculates the restitution coefficient for a given stiffness, collision time, and effective mass.

Deprecated:
use species->computeRestitutionCoefficient(2.0*effectiveMass) instead

Definition at line 163 of file Helpers.cc.

References mathsFunc::exp(), constants::sqr_pi, and mathsFunc::square().

164 {
165  if (k <= 0)
166  {
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;
168  exit(-1);
169  }
170  if (tc <= 0)
171  {
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;
173  exit(-1);
174  }
175  if (mass <= 0)
176  {
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;
178  exit(-1);
179  }
180  if (k / mass * mathsFunc::square(tc) - constants::sqr_pi < 0)
181  {
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;
183  exit(-1);
184  }
185  return std::exp(-std::sqrt(k / mass * mathsFunc::square(tc) - constants::sqr_pi));
186 }
Mdouble exp(Mdouble Exponent)
Definition: ExtendedMath.cc:78
T square(T val)
squares a number
Definition: ExtendedMath.h:91
const Mdouble sqr_pi
Definition: ExtendedMath.h:44
Mdouble helpers::computeRestitutionCoefficientFromKAndDispAndEffectiveMass ( Mdouble  k,
Mdouble  disp,
Mdouble  mass 
)

Calculates the restitution coefficient time for a given stiffness, dissipation, and effective mass.

Deprecated:
use species->computeRestitutionCoefficient(2.0*effectiveMass) instead

Definition at line 73 of file Helpers.cc.

References mathsFunc::exp(), constants::pi, and mathsFunc::square().

74 {
75  if (k <= 0)
76  {
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;
78  exit(-1);
79  }
80  if (disp < 0)
81  {
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;
83  exit(-1);
84  }
85  if (mass <= 0)
86  {
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;
88  exit(-1);
89  }
90  if (4.0 * mass * k - mathsFunc::square(disp) < 0)
91  {
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;
93  exit(-1);
94  }
95  return std::exp(-disp * constants::pi / std::sqrt(4.0 * mass * k - mathsFunc::square(disp)));
96 }
Mdouble exp(Mdouble Exponent)
Definition: ExtendedMath.cc:78
T square(T val)
squares a number
Definition: ExtendedMath.h:91
const Mdouble pi
Definition: ExtendedMath.h:42
bool helpers::fileExists ( std::string  strFilename)

Function to check if a file exists, is used to check if a run has already need done.

This is a FileExist routine, which is used to test if a run have already need preformed, allows me to plug holes in parm studies.

Definition at line 450 of file Helpers.cc.

451 {
452  struct stat stFileInfo;
453  bool blnReturn;
454  int intStat;
455 
456  // Attempt to get the file attributes
457 
458  intStat = stat(strFilename.c_str(), &stFileInfo);
459  if (intStat == 0)
460  {
461  // We were able to get the file attributes
462  // so the file obviously exists.
463  blnReturn = true;
464  }
465  else
466  {
467  // We were not able to get the file attributes.
468  // This may mean that we don't have permission to
469  // access the folder which contains this file. If you
470  // need to do that level of checking, lookup the
471  // return values of stat which will give you
472  // more details on why stat failed.
473  blnReturn = false;
474  }
475 
476  return blnReturn;
477 }
Mdouble helpers::getEffectiveMass ( Mdouble  mass0,
Mdouble  mass1 
)

Calculates the effective mass of a particle pair, i.e. half the harmonic mean of two particle masses.

The effective mass is an important parameter in a collision. E.g. the collision time and the restitution coefficient are functions of the effective mass.

Parameters
[in]mass0The mass of the first particle.
[in]mass1The mass of the second particle.
Returns
the effective mass of the particle pair.

Definition at line 503 of file Helpers.cc.

504 {
505  return mass0 * mass1 / (mass0 + mass1);
506 }
void helpers::getLineFromStringStream ( std::istream &  in,
std::stringstream &  out 
)

Reads a line from one stringstream into another, and prepares the latter for reading in.

This function is used to avoid errors from reading in old or manually modified restart files. Instead of reading variable by variable directly from the restart stringstream, a full line is read first, from which the variables are read. Thus, if a line has the wrong number of arguments, it might affect the reading of the current line, but correctly reads the next line.

Example of usage:

std::stringstream line(std::stringstream::in | std::stringstream::out); std::stringstream is = restartFile.getFStream(); helpers::getLineFromStringStream(is, line); std::string dummy; line >> dummy;

Parameters
[in]inthe stringstream from which a line is read out should be initialized as std::stringstream(std::stringstream::out)
[out]outthe stringstream into which the line is read; should be initialized as std::stringstream(std::stringstream::in | std::stringstream::out)

Definition at line 396 of file Helpers.cc.

Referenced by BaseHandler< T >::read(), MercuryBase::read(), DPMBase::read(), DPMBase::readNextDataFile(), SpeciesHandler::readObject(), InteractionHandler::readObject(), SpeciesHandler::readOldObject(), BoundaryHandler::readOldObject(), WallHandler::readOldObject(), and ParticleHandler::readOldObject().

397 {
398  std::string line_string;
399  getline(in, line_string);
400  out.str(line_string);
401  out.clear();
402 }
Mdouble helpers::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 and particle mass m (for higher velocities particles could pass through each other)

Todo:
what should be used instead of this function?

Definition at line 322 of file Helpers.cc.

References mathsFunc::exp(), and mathsFunc::square().

323 {
324  // note: underestimate based on energy argument,
325  // Ekin = 2*1/2*m*(v/2)^2 = 1/2*k*(2*r)^2, gives
326  // return radius * sqrt(8.0*k/mass);
327 
328  // with dissipation, see S. Luding, Collisions & Contacts between two particles, eq 34
329  Mdouble w = sqrt(k / mass - mathsFunc::square(disp / (2.0 * mass)));
330  Mdouble w0 = sqrt(k / mass);
331  Mdouble DispCorrection = exp(-disp / mass / w) * asin(w / w0);
332  //std::cout << "DispCorrection" << DispCorrection << std::endl;
333  return radius * sqrt(8.0 * k / mass) / DispCorrection;
334 }
Mdouble exp(Mdouble Exponent)
Definition: ExtendedMath.cc:78
double Mdouble
T square(T val)
squares a number
Definition: ExtendedMath.h:91
unsigned int helpers::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.

MercuryDPM uses the DPMBase::setSaveCount to determine how often output is written. However, if the user wants to set the total number of saves instead of the saveCount, he can use this function to calculate the correct saveCount, assuming that the final time and the mean time step is known.

Example of use:

setSaveCount(helpers::getSaveCountFromNumberOfSavesAndTimeMaxAndTimestep(numberOfSaves, getTimeMax(), getTimeStep()));

Parameters
[in]numberOfSavesthe total number of output files the user wants at the end of the simulation.
[in]timeMaxthe final time of the simulation
[in]timestepthe mean time step used during the simulation
Returns
the saveCount value that should be used to get the desired number of saves.

Definition at line 350 of file Helpers.cc.

References ERROR, and logger.

351 {
352  if (numberOfSaves > 0 && timeMax > 0 && timestep > 0)
353  {
354  return static_cast<unsigned int>(ceil((timeMax + timestep) / timestep / static_cast<double>(numberOfSaves - 1)));
355  }
356  else
357  {
358  logger(ERROR, "[Helpers::getSaveCountFromNumberOfSavesAndTimeMaxAndTimestep()] numberOfSaves: %, timeMax: %, timestep: %", numberOfSaves, timeMax, timestep);
359  logger(ERROR, " Arguments need to be positive");
360  exit(-1);
361  }
362 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
LL< Log::ERROR > ERROR
Error log level.
Definition: Logger.cc:51
void helpers::loadingTest ( const ParticleSpecies species,
Mdouble  displacement,
Mdouble  velocity,
Mdouble  radius,
std::string  name 
)

Used to test the loading/unloading properties of a contact law.

Creates a DPMBase with a particles of unit size and a flat wall and loads/unloads the particle-wall contact.

Parameters
[in]speciesparticle species specifying the contact law
[in]displacementpeak displacement before unloading
[in]velocityloading/unloading velocity

Definition at line 535 of file Helpers.cc.

References DPMBase::actionsBeforeTimeStep(), assert, DPMBase::getTime(), DPMBase::getTimeMax(), INFO, logger, NO_FILE, ONE_FILE, InfiniteWall::set(), BaseInteractable::setAngularVelocity(), Files::setFileType(), DPMBase::setMax(), DPMBase::setMin(), DPMBase::setParticleDimensions(), BaseInteractable::setPosition(), BaseParticle::setRadius(), Files::setSaveCount(), BaseWall::setSpecies(), BaseParticle::setSpecies(), DPMBase::setSystemDimensions(), DPMBase::setTimeMax(), DPMBase::setTimeStep(), DPMBase::setupInitialConditions(), BaseInteractable::setVelocity(), and writeToFile().

536 {
537  class LoadingTest : public DPMBase {
538  const ParticleSpecies* species;
539  Mdouble displacement;
540  Mdouble velocity;
541  Mdouble radius;
542  public:
543  //public variables
544  LoadingTest (const ParticleSpecies* species, Mdouble displacement, Mdouble velocity, Mdouble radius)
545  : species(species), displacement(displacement), velocity(velocity), radius(radius) {}
546 
547  void setupInitialConditions() override
548  {
549  //setName("LoadingTest"+species->getName());
550  setTimeMax(2.0*displacement/velocity);
551  setTimeStep(2e-3*getTimeMax());
552  setSaveCount(1);
554  fStatFile.setFileType(FileType::ONE_FILE);
555 
556  setMax({radius,radius,radius+radius});
557  setMin({-radius,-radius,0});
560 
561  speciesHandler.copyAndAddObject(*species);
562 
563  BaseParticle p;
564  p.setSpecies(speciesHandler.getObject(0));
565  p.setRadius(radius);
566  p.setPosition({0,0,radius});
567  particleHandler.copyAndAddObject(p);
568 
569  InfiniteWall w;
570  w.setSpecies(speciesHandler.getObject(0));
571  w.set(Vec3D(0,0,-1),Vec3D(0.0,0.0,0.0));
572  wallHandler.copyAndAddObject(w);
573  }
574 
575  void actionsBeforeTimeStep() override {
576  BaseParticle* p = particleHandler.getLastObject();
577  assert(p);
578  p->setAngularVelocity({0,0,0});
579 
580  //Moving particle normally into surface
581  if (getTime() <= displacement/velocity) {
582  p->setVelocity({0,0,velocity});
583  p->setPosition({0,0,radius-velocity*getTime()});
584  } else {
585  p->setVelocity({0,0,-velocity});
586  p->setPosition({0,0,radius-displacement-displacement+velocity*getTime()});
587  }
588  }
589  } test(species, displacement, velocity, radius);
590  test.setName(name);
591  test.solve();
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());
594 }
bool writeToFile(std::string filename, std::string filecontent)
Writes a string to a file.
Definition: Helpers.cc:418
The DPMBase header includes quite a few header files, defining all the handlers, which are essential...
Definition: DPMBase.h:65
void setVelocity(const Vec3D &velocity)
set the velocity of the BaseInteractable.
void setTimeMax(Mdouble newTMax)
Allows the upper time limit to be changed.
Definition: DPMBase.cc:199
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
LL< Log::INFO > INFO
Info log level.
Definition: Logger.cc:53
double Mdouble
void setParticleDimensions(unsigned int particleDimensions)
Allows the dimension of the particle (f.e. for mass) to be changed. e.g. discs or spheres...
Definition: DPMBase.cc:583
void setSpecies(const ParticleSpecies *species)
void setSystemDimensions(unsigned int newDim)
Allows for the dimension of the simulation to be changed.
Definition: DPMBase.cc:562
void setFileType(FileType fileType)
Sets File::fileType_ for all files (ene, data, fstat, restart, stat)
Definition: Files.cc:170
void setRadius(const Mdouble radius)
Sets the particle's radius_ (and adjusts the mass_ accordingly, based on the particle's species) ...
file will not be created/read
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)
Definition: Files.cc:139
virtual void actionsBeforeTimeStep()
A virtual function which allows to define operations to be executed before the new time step...
Definition: DPMBase.cc:779
#define assert(e,...)
Definition: Logger.h:584
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...
Definition: InfiniteWall.cc:79
void setTimeStep(Mdouble newDt)
Allows the time step dt to be changed.
Definition: DPMBase.cc:451
void setMin(Vec3D min)
Sets the values xMin, yMin, zMin of the problem domain, which is [xMin,xMax]x[yMin,yMax]x[zMin,zMax].
Definition: DPMBase.cc:405
This is a class defining walls.
Definition: InfiniteWall.h:47
Implementation of a 3D vector (by Vitaliy).
Definition: Vector.h:45
void setAngularVelocity(const Vec3D &angularVelocity)
set the angular velocity of the BaseInteractble.
Mdouble getTime() const
Access function for the time.
Definition: DPMBase.cc:169
Mdouble getTimeMax() const
Allows the user to access the total simulation time during the simulation. Cannot change it though...
Definition: DPMBase.cc:214
virtual void setupInitialConditions()
This function allows to set the initial conditions for our problem to be solved, by default particle ...
Definition: DPMBase.cc:966
void setSpecies(const ParticleSpecies *species)
Define the species of this wall.
Definition: BaseWall.cc:113
void setMax(Vec3D max)
Sets the values xMax, yMax, zMax of the problem domain, which is [xMin,xMax]x[yMin,yMax]x[zMin,zMax].
Definition: DPMBase.cc:395
void helpers::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.

Creates a DPMBase with a particles of unit size and a flat wall and loads/unloads/reloads the particle-wall contact in tangential direction.

Parameters
[in]speciesparticle species specifying the contact law
[in]displacementpeak displacement before unloading
[in]velocityloading/unloading velocity

Definition at line 602 of file Helpers.cc.

References DPMBase::actionsBeforeTimeStep(), assert, DPMBase::getTime(), DPMBase::getTimeMax(), INFO, logger, NO_FILE, ONE_FILE, InfiniteWall::set(), BaseInteractable::setAngularVelocity(), Files::setFileType(), DPMBase::setMax(), DPMBase::setMin(), DPMBase::setParticleDimensions(), BaseInteractable::setPosition(), BaseParticle::setRadius(), Files::setSaveCount(), BaseWall::setSpecies(), BaseParticle::setSpecies(), DPMBase::setSystemDimensions(), DPMBase::setTimeMax(), DPMBase::setTimeStep(), DPMBase::setupInitialConditions(), BaseInteractable::setVelocity(), and writeToFile().

605 {
606  class LoadingTest : public DPMBase {
607  const ParticleSpecies* species;
608  Mdouble displacement;
609  Mdouble tangentialDisplacement;
610  Mdouble velocity;
611  Mdouble radius;
612  public:
613  //public variables
614  LoadingTest (const ParticleSpecies* species, Mdouble displacement, Mdouble tangentialDisplacement, Mdouble velocity, Mdouble radius)
615  : species(species), displacement(displacement), tangentialDisplacement(tangentialDisplacement), velocity(velocity), radius(radius) {}
616 
617  void setupInitialConditions() override
618  {
619  //setName("TangentialLoadingTest"+species->getName());
620  setTimeMax(4.0*tangentialDisplacement/velocity);
621  setTimeStep(2e-3*getTimeMax());
622  setSaveCount(1);
624  fStatFile.setFileType(FileType::ONE_FILE);
625 
626  setMax({radius,radius,radius+radius});
627  setMin({-radius,-radius,0});
630 
631  speciesHandler.copyAndAddObject(*species);
632 
633  BaseParticle p;
634  p.setSpecies(speciesHandler.getObject(0));
635  p.setRadius(radius);
636  p.setPosition({0,0,radius-displacement});
637  particleHandler.copyAndAddObject(p);
638 
639  InfiniteWall w;
640  w.setSpecies(speciesHandler.getObject(0));
641  w.set(Vec3D(0,0,-1),Vec3D(0.0,0.0,0.0));
642  wallHandler.copyAndAddObject(w);
643  }
644 
645  void actionsBeforeTimeStep() override {
646  BaseParticle* p = particleHandler.getLastObject();
647  assert(p);
648  p->setAngularVelocity({0,0,0});
649 
650  //Moving particle normally into surface
651  Mdouble time = getTime() / (tangentialDisplacement/velocity);
652  if (time <= 1.0) {
653  p->setVelocity({velocity,0,0});
654  p->setPosition({velocity*getTime(),0,radius-displacement});
655  } else if (time <= 3.0) {
656  p->setVelocity({-velocity,0,0});
657  p->setPosition({2.0*tangentialDisplacement-velocity*getTime(),0,radius-displacement});
658  } else {
659  p->setVelocity({velocity,0,0});
660  p->setPosition({-4.0*tangentialDisplacement+velocity*getTime(),0,radius-displacement});
661  }
662  }
663 
664  } test(species, displacement, tangentialDisplacement, velocity, radius);
665  test.setName(name);
666  test.solve();
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());
669 }
bool writeToFile(std::string filename, std::string filecontent)
Writes a string to a file.
Definition: Helpers.cc:418
The DPMBase header includes quite a few header files, defining all the handlers, which are essential...
Definition: DPMBase.h:65
void setVelocity(const Vec3D &velocity)
set the velocity of the BaseInteractable.
void setTimeMax(Mdouble newTMax)
Allows the upper time limit to be changed.
Definition: DPMBase.cc:199
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
LL< Log::INFO > INFO
Info log level.
Definition: Logger.cc:53
double Mdouble
void setParticleDimensions(unsigned int particleDimensions)
Allows the dimension of the particle (f.e. for mass) to be changed. e.g. discs or spheres...
Definition: DPMBase.cc:583
void setSpecies(const ParticleSpecies *species)
void setSystemDimensions(unsigned int newDim)
Allows for the dimension of the simulation to be changed.
Definition: DPMBase.cc:562
void setFileType(FileType fileType)
Sets File::fileType_ for all files (ene, data, fstat, restart, stat)
Definition: Files.cc:170
void setRadius(const Mdouble radius)
Sets the particle's radius_ (and adjusts the mass_ accordingly, based on the particle's species) ...
file will not be created/read
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)
Definition: Files.cc:139
virtual void actionsBeforeTimeStep()
A virtual function which allows to define operations to be executed before the new time step...
Definition: DPMBase.cc:779
#define assert(e,...)
Definition: Logger.h:584
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...
Definition: InfiniteWall.cc:79
void setTimeStep(Mdouble newDt)
Allows the time step dt to be changed.
Definition: DPMBase.cc:451
void setMin(Vec3D min)
Sets the values xMin, yMin, zMin of the problem domain, which is [xMin,xMax]x[yMin,yMax]x[zMin,zMax].
Definition: DPMBase.cc:405
This is a class defining walls.
Definition: InfiniteWall.h:47
Implementation of a 3D vector (by Vitaliy).
Definition: Vector.h:45
void setAngularVelocity(const Vec3D &angularVelocity)
set the angular velocity of the BaseInteractble.
Mdouble getTime() const
Access function for the time.
Definition: DPMBase.cc:169
Mdouble getTimeMax() const
Allows the user to access the total simulation time during the simulation. Cannot change it though...
Definition: DPMBase.cc:214
virtual void setupInitialConditions()
This function allows to set the initial conditions for our problem to be solved, by default particle ...
Definition: DPMBase.cc:966
void setSpecies(const ParticleSpecies *species)
Define the species of this wall.
Definition: BaseWall.cc:113
void setMax(Vec3D max)
Sets the values xMax, yMax, zMax of the problem domain, which is [xMin,xMax]x[yMin,yMax]x[zMin,zMax].
Definition: DPMBase.cc:395
void helpers::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.

Creates a DPMBase with a particles of unit size and a flat wall, loads the particle-wall contact in normal and tangential direction, then rotates.

Parameters
[in]speciesparticle species specifying the contact law
[in]displacementpeak displacement before unloading
[in]velocityloading/unloading velocity

Definition at line 677 of file Helpers.cc.

References DPMBase::actionsBeforeTimeStep(), assert, mathsFunc::cos(), BaseInteractable::getAngularVelocity(), BaseInteractable::getOrientation(), BaseInteractable::getPosition(), DPMBase::getTime(), DPMBase::getTimeMax(), BaseInteractable::getVelocity(), INFO, logger, NO_FILE, ONE_FILE, constants::pi, BaseInteractable::setAngularVelocity(), Files::setFileType(), DPMBase::setMax(), DPMBase::setMin(), BaseInteractable::setOrientation(), DPMBase::setParticleDimensions(), BaseInteractable::setPosition(), BaseParticle::setRadius(), Files::setSaveCount(), BaseParticle::setSpecies(), DPMBase::setSystemDimensions(), DPMBase::setTimeMax(), DPMBase::setTimeStep(), DPMBase::setupInitialConditions(), BaseInteractable::setVelocity(), mathsFunc::sin(), and writeToFile().

678 {
679  class ObjectivenessTest : public DPMBase {
680  const ParticleSpecies* species;
681  Mdouble displacement;
682  Mdouble tangentialDisplacement;
683  Mdouble velocity;
684  Mdouble radius;
685  public:
686  //public variables
687  ObjectivenessTest (const ParticleSpecies* species, Mdouble displacement, Mdouble tangentialDisplacement, Mdouble velocity, Mdouble radius)
688  : species(species), displacement(displacement), tangentialDisplacement(tangentialDisplacement), velocity(velocity), radius(radius) {}
689 
690  void setupInitialConditions() override
691  {
692  //setName("ObjectivenessTest"+species->getName());
693  setTimeMax((tangentialDisplacement+0.5*constants::pi*radius)/velocity);
694  setTimeStep(1e-4*getTimeMax());
695  setSaveCount(20);
697  dataFile.setFileType(FileType::ONE_FILE);
698  fStatFile.setFileType(FileType::ONE_FILE);
699 
700  setMax(radius*Vec3D(2,2,2));
701  setMin(radius*Vec3D(-2,-2,-2));
704 
705  speciesHandler.copyAndAddObject(*species);
706 
707  BaseParticle p;
708  p.setSpecies(speciesHandler.getObject(0));
709  p.setRadius(radius);
710  p.setPosition({0,radius-displacement,0});
711  particleHandler.copyAndAddObject(p);
712  p.setPosition({0,-radius+displacement,0});
713  particleHandler.copyAndAddObject(p);
714  }
715 
716  void actionsBeforeTimeStep() override {
717  BaseParticle* p = particleHandler.getObject(0);
718  BaseParticle* q = particleHandler.getLastObject();
719  assert(p);
720  assert(q);
721 
722  //Moving particle normally into surface
723  if (getTime() <= tangentialDisplacement/velocity) {
724  p->setAngularVelocity({0,0,0});
725  p->setVelocity({velocity,0,0});
726  p->setPosition({-tangentialDisplacement+velocity*getTime(),radius-displacement,0});
727  q->setAngularVelocity({0,0,0});
728  q->setVelocity({-velocity,0,0});
729  q->setPosition({tangentialDisplacement-velocity*getTime(),-radius+displacement,0});
730  } else {
731  Mdouble angle = velocity/(radius-displacement) * (getTime()-tangentialDisplacement/velocity);
732  Mdouble s = sin(angle);
733  Mdouble c = cos(angle);
734  p->setAngularVelocity(velocity/(radius-displacement)*Vec3D(0,0,-1));
735  //p->setAngularVelocity(Vec3D(0,0,0));
736  //p->setOrientation({1,0,0,0});
737  p->setVelocity(velocity*Vec3D(c,-s,0));
738  //p->setVelocity(Vec3D(0,0,0));
739  p->setPosition((radius-displacement)*Vec3D(s,c,0));
741  q->setOrientation(-p->getOrientation());
742  q->setVelocity(-p->getVelocity());
743  q->setPosition(-p->getPosition());
744  }
745  }
746 
747  } test (species, displacement, tangentialDisplacement, velocity, radius);
748  test.setName(name);
749  test.solve();
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());
752 }
bool writeToFile(std::string filename, std::string filecontent)
Writes a string to a file.
Definition: Helpers.cc:418
The DPMBase header includes quite a few header files, defining all the handlers, which are essential...
Definition: DPMBase.h:65
void setVelocity(const Vec3D &velocity)
set the velocity of the BaseInteractable.
void setTimeMax(Mdouble newTMax)
Allows the upper time limit to be changed.
Definition: DPMBase.cc:199
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
void setOrientation(const Vec3D &orientation)
Sets the orientation of this BaseInteractable.
LL< Log::INFO > INFO
Info log level.
Definition: Logger.cc:53
double Mdouble
void setParticleDimensions(unsigned int particleDimensions)
Allows the dimension of the particle (f.e. for mass) to be changed. e.g. discs or spheres...
Definition: DPMBase.cc:583
virtual const Vec3D & getAngularVelocity() const
Returns the angular velocity of this interactable.
void setSpecies(const ParticleSpecies *species)
void setSystemDimensions(unsigned int newDim)
Allows for the dimension of the simulation to be changed.
Definition: DPMBase.cc:562
void setFileType(FileType fileType)
Sets File::fileType_ for all files (ene, data, fstat, restart, stat)
Definition: Files.cc:170
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.
Mdouble cos(Mdouble x)
Definition: ExtendedMath.cc:60
file will not be created/read
Mdouble sin(Mdouble x)
Definition: ExtendedMath.cc:42
const Mdouble pi
Definition: ExtendedMath.h:42
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)
Definition: Files.cc:139
virtual void actionsBeforeTimeStep()
A virtual function which allows to define operations to be executed before the new time step...
Definition: DPMBase.cc:779
#define assert(e,...)
Definition: Logger.h:584
void setPosition(const Vec3D &position)
Sets the position of this BaseInteractable.
void setTimeStep(Mdouble newDt)
Allows the time step dt to be changed.
Definition: DPMBase.cc:451
void setMin(Vec3D min)
Sets the values xMin, yMin, zMin of the problem domain, which is [xMin,xMax]x[yMin,yMax]x[zMin,zMax].
Definition: DPMBase.cc:405
virtual const Vec3D & getVelocity() const
Returns the velocity of this interactable.
Implementation of a 3D vector (by Vitaliy).
Definition: Vector.h:45
void setAngularVelocity(const Vec3D &angularVelocity)
set the angular velocity of the BaseInteractble.
Mdouble getTime() const
Access function for the time.
Definition: DPMBase.cc:169
Mdouble getTimeMax() const
Allows the user to access the total simulation time during the simulation. Cannot change it though...
Definition: DPMBase.cc:214
virtual void setupInitialConditions()
This function allows to set the initial conditions for our problem to be solved, by default particle ...
Definition: DPMBase.cc:966
void setMax(Vec3D max)
Sets the values xMax, yMax, zMax of the problem domain, which is [xMin,xMax]x[yMin,yMax]x[zMin,zMax].
Definition: DPMBase.cc:395
bool helpers::openFile ( std::fstream &  file,
std::string  filename,
std::fstream::openmode  mode 
)

Provides a simple interface for opening a file.

Provides a simple interface for opening a file, in order to avoid that the user has to learn the syntax for opening a file.

Parameters
[out]fileThe std::fstream object that the user can write to.
[in]filenameThe name of the file.
[in]modeThe openmode of the file, typically std::fstream::out or std::fstream::in.
Returns
true is the file was successfully opened, false else.

Definition at line 487 of file Helpers.cc.

488 {
489  file.open(filename.c_str(), mode);
490  if (file.fail())
491  return false;
492  else
493  return true;
494 }
std::vector< double > helpers::readArrayFromFile ( std::string  filename,
int &  n,
int &  m 
)

Definition at line 508 of file Helpers.cc.

509 {
510  std::fstream file;
511  file.open(filename.c_str(), std::ios::in);
512  if (file.fail())
513  {
514  std::cerr << "Error in readArrayFromFile: file could not be opened" << std::endl;
515  exit(-1);
516  }
517  file >> n >> m;
518  std::vector<double> v;
519  Mdouble val;
520  for (int i=0; i<n*m; i++)
521  {
522  file >> val;
523  v.push_back(val);
524  }
525  file.close();
526  return v;
527 }
double Mdouble
template<typename T >
T helpers::readFromFile ( std::string  fileName,
std::string  varName,
value 
)

Allows a quick read-in from a parameter file.

For example, the following code reads in the variable time from the file in:

double time = readFromFile("in","time",24);

The in file needs to contain the string time, followed by the value, e.g.

time 20

If the file cannot be opened, or the parameter is not found, the variable is set to the default value specified by the third argument.

Parameters
fileNamename of input
varNamevariable name as it appears in the input file
valuedefault value (used if the parameter could not be read)
Returns
value of variable

Definition at line 260 of file Helpers.h.

References INFO, logger, and WARN.

260  {
261  //open filestream
262  std::ifstream is(fileName.c_str(), std::ios::in);
263  if (is.fail()) {
264  logger(INFO, "readFromFile: file % could not be opened, variable % set to default value %", fileName, varName, value);
265  return value;
266  }
267 
268  //read in variables, until the right one is fount
269  std::string s;
270  while(!is.eof()) {
271  is >> s;
272  if (!s.compare(varName)) {
273  is >> value;
274  logger(INFO,"readFromFile: variable % set to % ",varName,value);
275  return value;
276  }
277  }
278 
279  //if the right variable is never found
280  logger(WARN,"readFromFile: variable % not set in file %, set to default value % ", varName, fileName, value);
281  return value;
282  }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
LL< Log::INFO > INFO
Info log level.
Definition: Logger.cc:53
LL< Log::WARN > WARN
Warning log level.
Definition: Logger.cc:52
template<typename T >
void helpers::readOptionalVariable ( std::istream &  is,
std::string  name,
T &  variable 
)
Todo:
checkAndRead should check if the next variable in the ifstream is equal to the string nam, and only read in this case; otherwise continue, but I don't know how to put the location in the ifstream back.

Definition at line 212 of file Helpers.h.

212  {
214  if (is.peek() == name.c_str()[0])
215  {
216  std::string dummy;
217  is >> dummy >> variable;
218  }
219  }
template<typename T >
std::string helpers::to_string ( const T &  n)

Definition at line 203 of file Helpers.h.

Referenced by InteractionHandler::writeVTK(), ParticleHandler::writeVTK(), and WallHandler::writeVTKFile().

204  {
205  std::ostringstream stm ;
206  stm << n ;
207  return stm.str() ;
208  }
bool helpers::writeToFile ( std::string  filename,
std::string  filecontent 
)

Writes a string to a file.

Provides a simple interface for writing a string to a file. This function is mainly used to create ini or restart file that the code later reads back in.

Example of usage:

helpers::writeToFile("RestartUnitTest.ini", "1 0 0 0 0 1 1 1\n" "0.5 0.5 0 0 0 0.5 0 0 0 0 0 0 0 0\n");

Parameters
[in]filenamethe name of the file
[in]filecontentthe content
Returns
true on success.

Definition at line 418 of file Helpers.cc.

Referenced by loadingTest(), main(), normalAndTangentialLoadingTest(), objectivenessTest(), Screw::writeVTK(), and DPMBase::writeVTK().

419 {
420  std::fstream file;
421  file.open(filename.c_str(), std::ios::out);
422  if (file.fail())
423  {
424  std::cerr << "Error in writeToFile: file could not be opened" << std::endl;
425  return false;
426  }
427  file << filecontent;
428  file.close();
429  return true;
430 }