MercuryDPM  Beta
 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 
31 class BaseParticle;
32 class BaseInteractable;
33 
35 {
36  stiffness_ = 0;
37  dissipation_ = 0;
38 #ifdef DEBUG_CONSTRUCTOR
39  std::cout<<"LinearViscoelasticNormalSpecies::LinearViscoelasticNormalSpecies() finished"<<std::endl;
40 #endif
41 }
42 
47 {
50 #ifdef DEBUG_CONSTRUCTOR
51  std::cout<<"LinearViscoelasticNormalSpecies::LinearViscoelasticNormalSpecies(const LinearViscoelasticNormalSpecies &p) finished"<<std::endl;
52 #endif
53 }
54 
56 {
57 #ifdef DEBUG_DESTRUCTOR
58  std::cout<<"LinearViscoelasticNormalSpecies::~LinearViscoelasticNormalSpecies() finished"<<std::endl;
59 #endif
60 }
61 
65 void LinearViscoelasticNormalSpecies::write(std::ostream& os) const
66 {
67  os << " stiffness " << stiffness_
68  << " dissipation " << dissipation_;
69 }
70 
75 {
76  std::string dummy;
77  is >> dummy >> stiffness_
78  >> dummy >> dissipation_;
79 }
80 
85 {
86  return "LinearViscoelastic";
87 }
88 
91 {
92  if (new_k >= 0)
93  stiffness_ = new_k;
94  else
95  {
96  std::cerr << "Error in set_k" << std::endl;
97  exit(-1);
98  }
99 }
100 
103 {
104  return stiffness_;
105 }
106 
109 {
110  setStiffness(new_.k);
111  setDissipation(new_.disp);
112 }
113 
116 {
117  if (dissipation >= 0)
118  {
119  dissipation_ = dissipation;
120  }
121  else
122  {
123  std::cerr << "Error in setDissipation(" << dissipation << ")" << std::endl;
124  exit(-1);
125  }
126 }
127 
130 {
131  return dissipation_;
132 }
133 
136 {
137  if (mass <= 0)
138  {
139  std::cerr << "Error in getCollisionTime(" << mass << ") mass is not set or has an unexpected value, (getCollisionTime(" << mass << "))" << std::endl;
140  exit(-1);
141  }
142  if (stiffness_ <= 0)
143  {
144  std::cerr << "Error in getCollisionTime(" << mass << ") stiffness=" << stiffness_ << " is not set or has an unexpected value, (getCollisionTime(" << mass << "), with stiffness=" << stiffness_ << ")" << std::endl;
145  exit(-1);
146  }
147  if (dissipation_ < 0)
148  {
149  std::cerr << "Error in getCollisionTime(" << mass << ") dissipation=" << dissipation_ << " is not set or has an unexpected value, (getCollisionTime(" << mass << "), with dissipation=" << dissipation_ << ")" << std::endl;
150  exit(-1);
151  }
152  Mdouble tosqrt = stiffness_ / (.5 * mass) - mathsFunc::square(dissipation_ / mass);
153  if (tosqrt <= 0)
154  {
155  std::cerr << "Error 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;
156  exit(-1);
157  }
158  return constants::pi / std::sqrt(tosqrt);
159 }
160 
163 {
164  return std::exp(-dissipation_ / mass * getCollisionTime(mass));
165 }
166 
169 {
170  return radius * std::sqrt(stiffness_ / (.5 * mass));
171 }
172 
180 {
181  stiffness_ = stiffness;
182  dissipation_ = -std::sqrt(2.0 * mass * stiffness_ / (constants::sqr_pi + mathsFunc::square(log(eps)))) * log(eps);
183 }
184 
192 {
193  dissipation_ = -mass / tc * std::log(eps);
195 }
196 
204 {
205  Mdouble reduced_mass = mass1 * mass2 / (mass1 + mass2);
206  setCollisionTimeAndRestitutionCoefficient(collisionTime, restitutionCoefficient, 2.0 * reduced_mass);
207 }
208 
215 {
218 }
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
Mdouble getStiffness() const
Allows the spring constant to be accessed.
return type specifically for fuctions returning k and disp at once
Definition: Helpers.h:39
void setDissipation(Mdouble dissipation)
Allows the normal dissipation to be changed.
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
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.
T square(T val)
squares a number
Definition: ExtendedMath.h:91
Mdouble getRestitutionCoefficient(Mdouble mass)
Calculates restitution coefficient for two copies of given disp, k, mass.
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:43
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
void read(std::istream &is)
Reads the species properties from an input stream.
Mdouble getMaximumVelocity(Mdouble radius, Mdouble mass)
Calculates the maximum velocity allowed for a collision of two copies of P (for higher velocities par...
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
Mdouble getCollisionTime(Mdouble mass)
Calculates collision time for two copies of a particle of given disp, k, mass.