MercuryDPM  Beta
 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 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...
 

Function Documentation

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 281 of file Helpers.cc.

282 {
283  if (disp <= 0)
284  {
285  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;
286  exit(-1);
287  }
288  if (r < 0)
289  {
290  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;
291  exit(-1);
292  }
293  if (mass <= 0)
294  {
295  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;
296  exit(-1);
297  }
298  return -2.0 * mass * std::log(r) / disp;
299 }
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 41 of file Helpers.cc.

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

Referenced by ChuteBottom::makeRoughBottom().

42 {
43  if (k <= 0)
44  {
45  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;
46  exit(-1);
47  }
48  if (disp < 0)
49  {
50  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;
51  exit(-1);
52  }
53  if (mass <= 0)
54  {
55  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;
56  exit(-1);
57  }
58  if (4.0 * k / mass - mathsFunc::square(disp / mass) < 0)
59  {
60  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;
61  exit(-1);
62  }
63  return 2.0 * constants::pi / std::sqrt(4.0 * k / mass - mathsFunc::square(disp / mass));
64 }
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 111 of file Helpers.cc.

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

112 {
113  if (k <= 0)
114  {
115  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;
116  exit(-1);
117  }
118  if (r < 0)
119  {
120  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;
121  exit(-1);
122  }
123  if (mass <= 0)
124  {
125  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;
126  exit(-1);
127  }
128  return sqrt(mass / k * (constants::sqr_pi + mathsFunc::square(std::log(r))));
129 }
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 181 of file Helpers.cc.

Referenced by computeKAndDispFromCollisionTimeAndRestitutionCoefficientAndEffectiveMass().

182 {
183  if (tc <= 0)
184  {
185  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;
186  exit(-1);
187  }
188  if (r < 0)
189  {
190  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;
191  exit(-1);
192  }
193  if (mass <= 0)
194  {
195  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;
196  exit(-1);
197  }
198  return -2.0 * mass * std::log(r) / tc;
199 }
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 131 of file Helpers.cc.

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

132 {
133  if (k <= 0)
134  {
135  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;
136  exit(-1);
137  }
138  if (tc <= 0)
139  {
140  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;
141  exit(-1);
142  }
143  if (mass <= 0)
144  {
145  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;
146  exit(-1);
147  }
148  if (mass * k - constants::sqr_pi * mathsFunc::square(mass / tc) < 0)
149  {
150  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;
151  exit(-1);
152  }
153  return 2.0 * std::sqrt(mass * k - constants::sqr_pi * mathsFunc::square(mass / tc));
154 }
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 91 of file Helpers.cc.

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

92 {
93  if (k <= 0)
94  {
95  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;
96  exit(-1);
97  }
98  if (r < 0)
99  {
100  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;
101  exit(-1);
102  }
103  if (mass <= 0)
104  {
105  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;
106  exit(-1);
107  }
108  return -2.0 * sqrt(mass * k / (constants::sqr_pi + mathsFunc::square(std::log(r)))) * std::log(r);
109 }
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

Definition at line 302 of file Helpers.cc.

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

303 {
305  ans.disp = -2.0 * mass * log(r) / tc;
306  ans.k = mass * (mathsFunc::square(constants::pi / tc) + mathsFunc::square(ans.disp / (2.0 * mass)));
307  ans.kt = 2.0 / 7.0 * ans.k * (mathsFunc::square(constants::pi) + mathsFunc::square(log(beta))) / (mathsFunc::square(constants::pi) + mathsFunc::square(log(r)));
308  if (beta != 0.0)
309  ans.dispt = -2 * log(beta) * sqrt(1.0 / 7.0 * mass * ans.kt / (mathsFunc::square(constants::pi) + mathsFunc::square(log(beta))));
310  else
311  ans.dispt = 2. * sqrt(1.0 / 7.0 * mass * ans.kt);
312  return ans;
313 }
return type specifically for fuctions returning k, disp, kt, dispt at once
Definition: Helpers.h:140
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, restitutionCoefficient, 2.0*effectiveMass); instead

Definition at line 33 of file Helpers.cc.

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

34 {
38  return ans;
39 }
return type specifically for fuctions returning k and disp at once
Definition: Helpers.h:39
Mdouble disp
Definition: Helpers.h:43
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:201
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:181
Mdouble helpers::computeKFromCollisionTimeAndDispAndEffectiveMass ( Mdouble  tc,
Mdouble  disp,
Mdouble  mass 
)

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

Definition at line 221 of file Helpers.cc.

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

222 {
223  if (tc <= 0)
224  {
225  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;
226  exit(-1);
227  }
228  if (disp < 0)
229  {
230  std::cerr << "Error in helpers::computeKFromCollisionTimeAndDispAndEffectiveMass(Mdouble tc, Mdouble disp, Mdouble mass) dissipation not set or has an unexpected value, (dissipation=" << disp << ")" << std::endl;
231  exit(-1);
232  }
233  if (mass <= 0)
234  {
235  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;
236  exit(-1);
237  }
238  return 0.25 * mathsFunc::square(disp) / mass + constants::sqr_pi * mass / mathsFunc::square(tc);
239 }
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 201 of file Helpers.cc.

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

Referenced by computeKAndDispFromCollisionTimeAndRestitutionCoefficientAndEffectiveMass().

202 {
203  if (tc <= 0)
204  {
205  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;
206  exit(-1);
207  }
208  if (r < 0)
209  {
210  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;
211  exit(-1);
212  }
213  if (mass <= 0)
214  {
215  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;
216  exit(-1);
217  }
218  return mass * (mathsFunc::square(constants::pi / tc) + mathsFunc::square(-std::log(r) / tc));
219 }
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 261 of file Helpers.cc.

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

262 {
263  if (disp <= 0)
264  {
265  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;
266  exit(-1);
267  }
268  if (r < 0)
269  {
270  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;
271  exit(-1);
272  }
273  if (mass <= 0)
274  {
275  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;
276  exit(-1);
277  }
278  return 0.25 * mathsFunc::square(disp)*(constants::sqr_pi / (mathsFunc::square(std::log(r))) + 1.0) / mass;
279 }
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 241 of file Helpers.cc.

242 {
243  if (tc <= 0)
244  {
245  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;
246  exit(-1);
247  }
248  if (disp < 0)
249  {
250  std::cerr << "Error in helpers::computeRestitutionCoefficientFromCollisionTimeAndDispAndEffectiveMass(Mdouble tc, Mdouble disp, Mdouble mass) dissipation not set or has an unexpected value, (dissipation=" << disp << ")" << std::endl;
251  exit(-1);
252  }
253  if (mass <= 0)
254  {
255  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;
256  exit(-1);
257  }
258  return std::exp(-0.5 * disp * tc / mass);
259 }
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 156 of file Helpers.cc.

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

157 {
158  if (k <= 0)
159  {
160  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;
161  exit(-1);
162  }
163  if (tc <= 0)
164  {
165  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;
166  exit(-1);
167  }
168  if (mass <= 0)
169  {
170  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;
171  exit(-1);
172  }
173  if (k / mass * mathsFunc::square(tc) - constants::sqr_pi < 0)
174  {
175  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;
176  exit(-1);
177  }
178  return std::exp(-std::sqrt(k / mass * mathsFunc::square(tc) - constants::sqr_pi));
179 }
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 66 of file Helpers.cc.

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

67 {
68  if (k <= 0)
69  {
70  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;
71  exit(-1);
72  }
73  if (disp < 0)
74  {
75  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;
76  exit(-1);
77  }
78  if (mass <= 0)
79  {
80  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;
81  exit(-1);
82  }
83  if (4.0 * mass * k - mathsFunc::square(disp) < 0)
84  {
85  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;
86  exit(-1);
87  }
88  return std::exp(-disp * constants::pi / std::sqrt(4.0 * mass * k - mathsFunc::square(disp)));
89 }
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 429 of file Helpers.cc.

430 {
431  struct stat stFileInfo;
432  bool blnReturn;
433  int intStat;
434 
435  // Attempt to get the file attributes
436 
437  intStat = stat(strFilename.c_str(), &stFileInfo);
438  if (intStat == 0)
439  {
440  // We were able to get the file attributes
441  // so the file obviously exists.
442  blnReturn = true;
443  }
444  else
445  {
446  // We were not able to get the file attributes.
447  // This may mean that we don't have permission to
448  // access the folder which contains this file. If you
449  // need to do that level of checking, lookup the
450  // return values of stat which will give you
451  // more details on why stat failed.
452  blnReturn = false;
453  }
454 
455  return blnReturn;
456 }
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 482 of file Helpers.cc.

483 {
484  return mass0 * mass1 / (mass0 + mass1);
485 }
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 389 of file Helpers.cc.

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

390 {
391  std::string line_string;
392  getline(in, line_string);
393  out.str(line_string);
394  out.clear();
395 }
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)

Definition at line 315 of file Helpers.cc.

References mathsFunc::square().

316 {
317  // note: underestimate based on energy argument,
318  // Ekin = 2*1/2*m*(v/2)^2 = 1/2*k*(2*r)^2, gives
319  // return radius * sqrt(8.0*k/mass);
320 
321  // with dissipation, see S. Luding, Collisions & Contacts between two particles, eq 34
322  Mdouble w = sqrt(k / mass - mathsFunc::square(disp / (2.0 * mass)));
323  Mdouble w0 = sqrt(k / mass);
324  Mdouble DispCorrection = exp(-disp / mass / w) * asin(w / w0);
325  //std::cout << "DispCorrection" << DispCorrection << std::endl;
326  return radius * sqrt(8.0 * k / mass) / DispCorrection;
327 }
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 343 of file Helpers.cc.

References ERROR, and logger.

344 {
345  if (numberOfSaves > 0 && timeMax > 0 && timestep > 0)
346  {
347  return static_cast<unsigned int>(ceil((timeMax + timestep) / timestep / static_cast<double>(numberOfSaves - 1)));
348  }
349  else
350  {
351  logger(ERROR, "[Helpers::getSaveCountFromNumberOfSavesAndTimeMaxAndTimestep()] numberOfSaves: %, timeMax: %, timestep: %", numberOfSaves, timeMax, timestep);
352  logger(ERROR, " Arguments need to be positive");
353  exit(-1);
354  }
355 }
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
LL< Log::ERROR > ERROR
Error log level.
Definition: Logger.cc:26
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 466 of file Helpers.cc.

467 {
468  file.open(filename.c_str(), mode);
469  if (file.fail())
470  return false;
471  else
472  return true;
473 }
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 411 of file Helpers.cc.

412 {
413  std::fstream file;
414  file.open(filename.c_str(), std::ios::out);
415  if (file.fail())
416  {
417  std::cerr << "Error in writeToFile: file could not be opened" << std::endl;
418  return false;
419  }
420  file << filecontent;
421  file.close();
422  return true;
423 }