ESyS-Particle
4.0.1
|
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 #ifndef __ROTPARTICLE_H 00014 #define __ROTPARTICLE_H 00015 00016 //--- MPIincludes --- 00017 #include <mpi.h> 00018 00019 // -- project includes -- 00020 #include "Foundation/vec3.h" 00021 #include "Foundation/Matrix3.h" 00022 #include "Model/Particle.h" 00023 #include "Foundation/Quaternion.h" 00024 00025 template <class T> class ParallelParticleArray; 00026 class AMPISGBufferRoot; 00027 class AMPIBuffer; 00028 00029 00030 //--- STL includes --- 00031 #include <map> 00032 #include <vector> 00033 #include <utility> 00034 #include <string> 00035 00036 using std::map; 00037 using std::vector; 00038 using std::pair; 00039 using std::string; 00040 00041 namespace esys 00042 { 00043 namespace lsm 00044 { 00045 class SimpleParticleData; 00046 } 00047 } 00048 00053 class CRotParticle : public CParticle 00054 { 00055 public: // types 00056 00057 class exchangeType 00058 { 00059 public: 00060 exchangeType() 00061 : m_pos(), 00062 m_initPos(), 00063 m_vel(), 00064 m_angVel(), 00065 m_quat() 00066 { 00067 m_is_dynamic=true; 00068 m_is_rot=true; 00069 } 00070 00071 exchangeType( 00072 const Vec3 &pos, 00073 const Vec3 &initPos, 00074 const Vec3 &vel, 00075 const Vec3 &currAngVel, 00076 const Quaternion &quat, 00077 const bool is_dyn, 00078 const bool is_rot 00079 ) 00080 : m_pos(pos), 00081 m_initPos(initPos), 00082 m_vel(vel), 00083 m_angVel(currAngVel), 00084 m_quat(quat) 00085 { 00086 m_is_dynamic=is_dyn; 00087 m_is_rot=is_rot; 00088 } 00089 public: 00090 Vec3 m_pos; 00091 Vec3 m_initPos; 00092 Vec3 m_vel; 00093 Vec3 m_angVel; 00094 Quaternion m_quat; 00095 bool m_is_dynamic; 00096 bool m_is_rot; 00097 00098 friend class TML_PackedMessageInterface; 00099 }; 00100 typedef double (CRotParticle::* ScalarFieldFunction)() const; 00101 typedef Vec3 (CRotParticle::* VectorFieldFunction)() const; 00102 00103 protected: 00104 00105 Quaternion m_quat; 00106 Quaternion m_initquat; 00107 Vec3 m_angVel; 00108 Vec3 m_moment; 00109 double m_inertRot; 00110 double m_div_inertRot; 00111 bool m_is_rot; 00112 00113 void setMoment(const Vec3 &moment) {m_moment = moment;} 00114 00115 public: 00116 CRotParticle(); 00117 CRotParticle(const esys::lsm::SimpleParticleData &particleData); 00118 CRotParticle(const CParticle &particle); 00119 CRotParticle( 00120 double rad, 00121 double mass, 00122 const Vec3& pos, 00123 const Vec3& vel, 00124 const Vec3& force, 00125 int id, 00126 bool is_dyn, 00127 bool is_rot 00128 ); 00129 CRotParticle( 00130 double rad, 00131 double mass, 00132 const Vec3& pos, 00133 const Vec3& vel, 00134 const Vec3& force, 00135 int id, 00136 Quaternion& quat, 00137 double inertRot, 00138 const Vec3& moment, 00139 const Vec3& angvel, 00140 bool is_dyn, 00141 bool is_rot 00142 ); 00143 CRotParticle( 00144 double rad, 00145 double mass, 00146 const Vec3& pos, 00147 const Vec3& oldpos, 00148 const Vec3& initpos, 00149 const Vec3& vel, 00150 const Vec3& force, 00151 int id, 00152 const Quaternion& quat, 00153 const Quaternion& initquat, 00154 double inertRot, 00155 const Vec3& moment, 00156 const Vec3& angvel, 00157 bool is_dyn, 00158 bool is_rot 00159 ); 00160 00161 virtual ~CRotParticle(){}; 00162 00163 static int getPackSize(); 00164 static ScalarFieldFunction getScalarFieldFunction(const string&); 00165 static VectorFieldFunction getVectorFieldFunction(const string&); 00166 00167 // Need to define this for template class using forAllParticles call in Parallel/SubLattice.hpp. 00168 Vec3 getDisplacement() const {return CParticle::getDisplacement();}; 00169 void resetDisplacement() {CParticle::resetDisplacement();} 00170 00171 inline const Vec3 &getAngVel () const { return m_angVel;} 00172 inline Vec3 getAngVelNR () const { return m_angVel;} // for field functions 00173 inline void setAngVel(const Vec3 &V) { m_angVel = V;} 00174 inline Quaternion getInitQuat() const { return m_initquat;} 00175 inline Quaternion getQuat() const { return m_quat;} 00176 inline void setQuat(const Quaternion &quat) { m_quat = quat;} 00177 inline double getInertRot () const { return m_inertRot; } 00178 inline void setInertRot (double inertRot) 00179 { 00180 m_inertRot = inertRot; 00181 m_div_inertRot = 1.0/m_inertRot; 00182 } 00183 inline double getInvInertRot () const { return m_div_inertRot; } 00184 inline Vec3 getMoment() const {return m_moment;} 00185 void applyMoment( const Vec3&); 00186 void integrate(double); 00187 void integrateTherm(double dt){} 00188 virtual void thermExpansion() {} 00189 void zeroForce(); 00190 virtual void zeroHeat(){} 00191 void rescale(); 00192 void setCircular(const Vec3& cv); 00193 double getAngularKineticEnergy() const {return (0.2*m_mass*m_rad*m_rad)*(m_angVel*m_angVel);} 00194 double getLinearKineticEnergy() const {return (0.5*m_mass)*(m_vel*m_vel);} 00195 double getKineticEnergy() const {return getLinearKineticEnergy() + getAngularKineticEnergy();} 00196 void writeAsDXLine(ostream&,int slid=0); 00197 00198 // switching on/off dynamic behaviour 00199 virtual void setNonDynamic() {m_is_dynamic=false;m_is_rot=false;}; 00200 virtual void setNonDynamicLinear() {m_is_dynamic=false;}; 00201 virtual void setNonDynamicRot() {m_is_rot=false;}; 00202 00203 inline Quaternion getQuatFromRotVec(const Vec3 &vec) const 00204 { 00205 const double angle = vec.norm(); 00206 const double halfAngle = angle/2.0; 00207 if (halfAngle > 0.0) { 00208 return Quaternion(cos(halfAngle), (vec)*(sin(halfAngle)/angle)); 00209 } 00210 return Quaternion(); 00211 } 00212 void rotateBy(const Vec3 &vec) {m_quat = getQuatFromRotVec(vec)*m_quat;} 00213 void rotateTo(const Vec3 &vec) {m_quat = getQuatFromRotVec(vec);} 00214 00215 friend ostream& operator<<(ostream&, const CRotParticle&); 00216 void print(){cout << *this << endl << flush;}; 00217 00218 // -- checkpointing -- 00219 virtual void saveSnapShotData(std::ostream& oStream); 00220 virtual void saveCheckPointData(std::ostream& oStream); 00221 virtual void loadCheckPointData(std::istream& iStream); 00222 00223 CRotParticle::exchangeType getExchangeValues(); 00224 void setExchangeValues(const CRotParticle::exchangeType &e); 00225 00226 template <typename TmplVisitor> 00227 void visit(TmplVisitor &visitor) 00228 { 00229 visitor.visitRotParticle(*this); 00230 } 00231 00232 // stress 00233 inline double sigma_xx_2D() const {return m_sigma(0,0)/(M_PI*m_rad*m_rad);}; 00234 inline double sigma_xy_2D() const {return m_sigma(0,1)/(M_PI*m_rad*m_rad);}; 00235 inline double sigma_yy_2D() const {return m_sigma(1,1)/(M_PI*m_rad*m_rad);}; 00236 // inline double sigma_d() const; 00237 static void get_type() {cout <<" CRotParticle" ;}; 00238 friend class TML_PackedMessageInterface; 00239 }; 00240 00241 #endif //__ROTPARTICLE_H