MercuryDPM  Alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
LinearViscoelasticNormalSpecies.cc
Go to the documentation of this file.
1 //Copyright (c) 2013-2014, The MercuryDPM Developers Team. All rights reserved.
2 //For the list of developers, see <http://www.MercuryDPM.org/Team>.
3 //
4 //Redistribution and use in source and binary forms, with or without
5 //modification, are permitted provided that the following conditions are met:
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above copyright
9 // notice, this list of conditions and the following disclaimer in the
10 // documentation and/or other materials provided with the distribution.
11 // * Neither the name MercuryDPM nor the
12 // names of its contributors may be used to endorse or promote products
13 // derived from this software without specific prior written permission.
14 //
15 //THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16 //ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 //WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 //DISCLAIMED. IN NO EVENT SHALL THE MERCURYDPM DEVELOPERS TEAM BE LIABLE FOR ANY
19 //DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 //(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 //LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22 //ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 //(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 //SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 
28 #include<cmath>
30 #include "Logger.h"
31 
32 class BaseParticle;
33 class BaseInteractable;
34 
36 {
37  stiffness_ = 0;
38  dissipation_ = 0;
39 #ifdef DEBUG_CONSTRUCTOR
40  std::cout<<"LinearViscoelasticNormalSpecies::LinearViscoelasticNormalSpecies() finished"<<std::endl;
41 #endif
42 }
43 
48 {
51 #ifdef DEBUG_CONSTRUCTOR
52  std::cout<<"LinearViscoelasticNormalSpecies::LinearViscoelasticNormalSpecies(const LinearViscoelasticNormalSpecies &p) finished"<<std::endl;
53 #endif
54 }
55 
57 {
58 #ifdef DEBUG_DESTRUCTOR
59  std::cout<<"LinearViscoelasticNormalSpecies::~LinearViscoelasticNormalSpecies() finished"<<std::endl;
60 #endif
61 }
62 
66 void LinearViscoelasticNormalSpecies::write(std::ostream& os) const
67 {
68  os << " stiffness " << stiffness_
69  << " dissipation " << dissipation_;
70 }
71 
76 {
77  std::string dummy;
78  is >> dummy >> stiffness_
79  >> dummy >> dissipation_;
80 }
81 
86 {
87  return "LinearViscoelastic";
88 }
89 
92 {
93  if (new_k >= 0)
94  stiffness_ = new_k;
95  else
96  {
97  std::cerr << "Error in set_k" << std::endl;
98  exit(-1);
99  }
100 }
101 
104 {
105  return stiffness_;
106 }
107 
110 {
111  setStiffness(new_.k);
112  setDissipation(new_.disp);
113 }
114 
117 {
118  if (dissipation >= 0)
119  {
120  dissipation_ = dissipation;
121  }
122  else
123  {
124  std::cerr << "Error in setDissipation(" << dissipation << ")" << std::endl;
125  exit(-1);
126  }
127 }
128 
131 {
132  return dissipation_;
133 }
134 
137 {
138  if (mass <= 0)
139  {
140  std::cerr << "Warning in getCollisionTime(" << mass << ") mass is not set or has an unexpected value, (getCollisionTime(" << mass << "))" << std::endl;
141  }
142  if (stiffness_ <= 0)
143  {
144  std::cerr << "Warning in getCollisionTime(" << mass << ") stiffness=" << stiffness_ << " is not set or has an unexpected value, (getCollisionTime(" << mass << "), with stiffness=" << stiffness_ << ")" << std::endl;
145  }
146  if (dissipation_ < 0)
147  {
148  std::cerr << "Warning in getCollisionTime(" << mass << ") dissipation=" << dissipation_ << " is not set or has an unexpected value, (getCollisionTime(" << mass << "), with dissipation=" << dissipation_ << ")" << std::endl;
149  }
150  Mdouble tosqrt = stiffness_ / (.5 * mass) - mathsFunc::square(dissipation_ / mass);
151  if (tosqrt <= 0)
152  {
153  std::cerr << "Warning in getCollisionTime(" << mass << ") values for mass, stiffness and dissipation would lead to an overdamped system, (getCollisionTime(" << mass << "), with stiffness=" << stiffness_ << " and dissipation=" << dissipation_ << ")" << std::endl;
154  }
155  return constants::pi / std::sqrt(tosqrt);
156 }
157 
160 {
161  return std::exp(-dissipation_ / mass * getCollisionTime(mass));
162 }
163 
166 {
167  return radius * std::sqrt(stiffness_ / (.5 * mass));
168 }
169 
177 {
178  stiffness_ = stiffness;
179  if (eps==0.0) {
180  dissipation_ = std::sqrt(2.0 * mass * stiffness);
181  } else {
182  dissipation_ = -std::sqrt(2.0 * mass * stiffness / (constants::sqr_pi + mathsFunc::square(log(eps)))) * log(eps);
183  }
184 }
185 
193 {
194  if (eps==0.0) {
195  stiffness_ = .5 * mass * mathsFunc::square(constants::pi / tc);
196  dissipation_ = std::sqrt(2.0 * mass * stiffness_);
197  } else {
198  dissipation_ = -mass / tc * mathsFunc::log(eps);
199  stiffness_ = .5 * mass * (mathsFunc::square(constants::pi / tc)
200  + mathsFunc::square(dissipation_ / mass));
201  }
202  logger(INFO,"setCollisionTimeAndRestitutionCoefficient: set stiffness to % and dissipation to % to obtain a collision time of % and a restitution coefficient of % for two particles of mass %",
203  getStiffness(),getDissipation(),tc,eps,mass);
204 }
205 
213 {
214  Mdouble reduced_mass = mass1 * mass2 / (mass1 + mass2);
215  setCollisionTimeAndRestitutionCoefficient(collisionTime, restitutionCoefficient, 2.0 * reduced_mass);
216 }
217 
224 {
227 }
void setCollisionTimeAndRestitutionCoefficient(Mdouble tc, Mdouble eps, Mdouble mass)
Sets k, disp such that it matches a given tc and eps for a collision of two copies of equal mass m...
void mix(LinearViscoelasticNormalSpecies *const SBase, LinearViscoelasticNormalSpecies *const TBase)
creates default values for mixed species
Mdouble stiffness_
(normal) spring constant
Logger< MERCURY_LOGLEVEL > logger("MercuryKernel")
Mdouble getStiffness() const
Allows the spring constant to be accessed.
return type specifically for fuctions returning k and disp at once
Definition: Helpers.h:42
void setDissipation(Mdouble dissipation)
Allows the normal dissipation to be changed.
Mdouble exp(Mdouble Exponent)
Definition: ExtendedMath.cc:78
std::string getBaseName() const
Used in Species::getName to obtain a unique name for each Species.
Mdouble getDissipation() const
Allows the normal dissipation to be accessed.
double Mdouble
Mdouble getRestitutionCoefficient(Mdouble mass) const
Calculates restitution coefficient for two copies of given disp, k, mass.
void setStiffnessAndRestitutionCoefficient(Mdouble k_, Mdouble eps, Mdouble mass)
Sets k, disp such that it matches a given tc and eps for a collision of two copies of P...
virtual ~LinearViscoelasticNormalSpecies()
The default destructor.
Mdouble log(Mdouble Power)
Definition: ExtendedMath.cc:97
T square(T val)
squares a number
Definition: ExtendedMath.h:91
LinearViscoelasticNormalSpecies contains the parameters used to describe a linear elastic-dissipative...
void setStiffness(Mdouble new_k)
Allows the spring constant to be changed.
Mdouble disp
Definition: Helpers.h:46
const Mdouble pi
Definition: ExtendedMath.h:42
Mdouble average(Mdouble a, Mdouble b)
defines the average of two variables by the harmonic mean.
Definition: BaseSpecies.cc:85
Mdouble getCollisionTime(Mdouble mass) const
Calculates collision time for two copies of a particle of given disp, k, mass.
Mdouble getMaximumVelocity(Mdouble radius, Mdouble mass) const
Calculates the maximum velocity allowed for a collision of two copies of P (for higher velocities par...
void read(std::istream &is)
Reads the species properties from an input stream.
LinearViscoelasticNormalSpecies()
The default constructor.
Defines the basic properties that a interactable object can have.
MERCURY_DEPRECATED void setStiffnessAndDissipation(helpers::KAndDisp new_)
Allows the spring and dissipation constants to be changed simultaneously.
void write(std::ostream &os) const
Writes the species properties to an output stream.
const Mdouble sqr_pi
Definition: ExtendedMath.h:44