ESyS-Particle  4.0.1
RotLocalDamping.hpp
00001 
00002 //                                                         //
00003 // Copyright (c) 2003-2011 by The University of Queensland //
00004 // Earth Systems Science Computational Centre (ESSCC)      //
00005 // http://www.uq.edu.au/esscc                              //
00006 //                                                         //
00007 // Primary Business: Brisbane, Queensland, Australia       //
00008 // Licensed under the Open Software License version 3.0    //
00009 // http://www.opensource.org/licenses/osl-3.0.php          //
00010 //                                                         //
00012 
00013 
00014 #ifndef MODEL_ROTLOCALDAMPING_HPP
00015 #define MODEL_ROTLOCALDAMPING_HPP
00016 
00017 #include "Model/RotLocalDamping.h"
00018 
00026 template <class T>
00027 CRotLocalDamping<T>::CRotLocalDamping(T* P,double visc, double dt)
00028 {
00029   m_p=P;
00030   m_visc=visc;
00031   m_dt=dt;
00032   m_force=Vec3(0.0,0.0,0.0);
00033 }
00034 
00041 template <class T>
00042 CRotLocalDamping<T>::CRotLocalDamping(T* P,const CLocalDampingIGP& param)
00043 {
00044   m_p=P;
00045   m_visc=param.getVisc();
00046   m_dt=param.getTimeStep();
00047   m_force=Vec3(0.0,0.0,0.0);
00048 }
00049 
00056 template <class T>
00057 CRotLocalDamping<T>::CRotLocalDamping(T* P,CLocalDampingIGP* param)
00058 {
00059   m_p=P;
00060   m_visc=param->getVisc();
00061   m_dt=param->getTimeStep();
00062   m_force=Vec3(0.0,0.0,0.0);
00063 }
00064 
00068 template <class T>
00069 CRotLocalDamping<T>::~CRotLocalDamping()
00070 {}
00071 
00072 template <class T>
00073 void CRotLocalDamping<T>::setTimeStepSize(double dt)
00074 {
00075   m_dt = dt;
00076 }
00077 
00081 template <class T>
00082 void CRotLocalDamping<T>::calcForces()
00083 {
00084   m_E_diss=0.0;// zero dissipated energy
00085   Vec3 v=m_p->getAngVel();
00086   Vec3 frc=m_p->getMoment();
00087 
00088   double dampFx, dampFy, dampFz;
00089 
00090   dampFx = fabs(frc.X());
00091   if (v.X() < 0) {
00092      dampFx *= -1.;
00093   }
00094   if (v.X() == 0) {
00095      dampFx = 0.0;
00096   }
00097   dampFy = fabs(frc.Y());
00098   if (v.Y() < 0) {
00099      dampFy *= -1.;
00100   }
00101   if (v.Y() == 0) {
00102      dampFy = 0.0;
00103   }
00104   dampFz = fabs(frc.Z());
00105   if (v.Z() < 0) {
00106      dampFz *= -1.;
00107   }
00108   if (v.Z() == 0) {
00109      dampFz = 0.0;
00110   }
00111 
00112   m_force=-1.0*m_visc*Vec3(dampFx, dampFy, dampFz);
00113 
00114   m_p->applyMoment(m_force);
00115 
00116   m_E_diss=m_visc*m_force.norm()*v.norm()*m_dt;
00117 }
00118 
00124 template <class T>
00125 typename CRotLocalDamping<T>::ScalarFieldFunction CRotLocalDamping<T>::getScalarFieldFunction(const string& name)
00126 {
00127   typename CRotLocalDamping<T>::ScalarFieldFunction sf;
00128 
00129   if(name=="dissipated_energy"){
00130     sf=&CRotLocalDamping<T>::getDissipatedEnergy;
00131   } else {
00132     sf=NULL;
00133     cerr << "ERROR - invalid name for interaction scalar  access function" << endl;
00134   }
00135 
00136   return sf;
00137 }
00138 
00144 template <class T>
00145 typename CRotLocalDamping<T>::CheckedScalarFieldFunction CRotLocalDamping<T>::getCheckedScalarFieldFunction(const string& name)
00146 {
00147   typename CRotLocalDamping<T>::CheckedScalarFieldFunction sf;
00148 
00149   sf=NULL;
00150   cerr << "ERROR - invalid name for interaction scalar  access function" << endl;
00151   
00152   return sf;
00153 }
00154 
00155 
00161 template <class T>
00162 typename CRotLocalDamping<T>::VectorFieldFunction CRotLocalDamping<T>::getVectorFieldFunction(const string& name)
00163 {
00164   typename CRotLocalDamping<T>::VectorFieldFunction vf;
00165 
00166   if (name=="force"){
00167     vf=&CRotLocalDamping<T>::getForce;
00168   } else {
00169       vf=NULL;
00170       cerr << "ERROR - invalid name for interaction vector access function" << endl;
00171   }
00172   
00173   return vf;
00174 }
00175 
00179 template <class T>
00180 double CRotLocalDamping<T>::getDissipatedEnergy() const
00181 {
00182   return m_E_diss;
00183 }
00184 
00185 template <class T>
00186 Vec3 CRotLocalDamping<T>::getForce() const
00187 {
00188   return m_force;
00189 }
00190 
00197 template <class T>
00198 bool CRotLocalDamping<T>::hasTag(int tag,int mask) const
00199 {
00200  int tag1=m_p->getTag();
00201 
00202   return ((tag1 & mask)==(tag & mask));
00203 }
00204 
00208 template <class T>
00209 vector<int> CRotLocalDamping<T>::getAllID() const
00210 {
00211   vector<int> res;
00212 
00213   res.push_back(m_p->getID());
00214 
00215   return res;
00216 }
00217 
00218 #endif