Main Page | Class Hierarchy | Class List | File List | Class Members

particle.h

00001 /***************************************************************************
00002                           particle.h  -  description
00003                              -------------------
00004     begin                : Fri Jan 3 2003
00005     copyright            : (C) 2003 by Moritz Franosch
00006     email                : mail@Franosch.org
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #ifndef PARTICLE_H
00019 #define PARTICLE_H
00020 
00021 #include "blitz/tinyvec.h"
00022 
00023 #include "askosmath/askosmath.h"
00024 
00025 #include "errorcheck.h"
00026 
00027 
00032 class Particle {
00033 
00034 public:
00035 
00036   typedef blitz::TinyVector<double,3> vector_t;
00037 
00038 private:
00039 
00040   double m; // mass
00041   //  double V; // volume
00042   double rho; // density
00043   double drho; // derivative drho/dt
00044 
00045   vector_t position;
00046   vector_t velocity;
00047   vector_t acceleration;
00048 
00049   double last_rho; // rho_(m-1) for leap-frog integration
00050   vector_t last_position; // position_(m-1) for leap-frog integration
00051   vector_t last_velocity; // velocity_(m-1) for leap-frog integration
00052 
00053 public:
00054 
00057   static std::string string_vector(const Particle::vector_t& v);
00058 
00061   static std::string list_vector(const Particle::vector_t& v);
00062 
00065   Particle(const vector_t& p);
00066 
00069   Particle();
00070 
00071   const vector_t& get_position() const {
00072     return position;
00073   }
00074 
00075   const vector_t& get_velocity() const {
00076     return velocity;
00077   }
00078 
00079   const vector_t& get_acceleration() const {
00080     return acceleration;
00081   }
00082 
00083   double get_mass() const {
00084     return m;
00085   }
00086 
00087   double get_density() const {
00088     return rho;
00089   }
00090 
00091   void set_position(const vector_t& p);
00092 
00093   void set_velocity(const vector_t& v);
00094 
00095   void set_acceleration(const vector_t& a);
00096 
00097   void set_mass(const double m);
00098 
00099   void set_density(const double rho);
00100 
00101   void set_drho(const double drho);
00102 
00106   void update_Euler(const double dt);
00107 
00113   double update_modified_midpoint(const int m, const double dt);
00114 
00115 };
00116 
00117 
00120 template<typename number, int N>
00121 double sqr_euclidian_distance(const blitz::TinyVector<number,N>& r1, 
00122                               const blitz::TinyVector<number,N>& r2) {
00123   REQUIRE( r1.length()==N );
00124   REQUIRE( r2.length()==N );
00125   double s=0;
00126   for (int i=0; i<N; ++i) {
00127     s += sqr(r1[i]-r2[i]);
00128   }
00129   return s;
00130 }
00131 
00132 
00133 template<>
00134 inline double sqr_euclidian_distance<double,3>(const blitz::TinyVector<double,3>& r1, 
00135                                                const blitz::TinyVector<double,3>& r2) {
00136   REQUIRE( r1.length()==3 );
00137   REQUIRE( r2.length()==3 );
00138   return sqr(r1[0]-r2[0])+sqr(r1[1]-r2[1])+sqr(r1[2]-r2[2]);
00139 }
00140 
00141 
00142 template<>
00143 inline double sqr_euclidian_distance<float,3>(const blitz::TinyVector<float,3>& r1, 
00144                                               const blitz::TinyVector<float,3>& r2) {
00145   REQUIRE( r1.length()==3 );
00146   REQUIRE( r2.length()==3 );
00147   return sqr(r1[0]-r2[0])+sqr(r1[1]-r2[1])+sqr(r1[2]-r2[2]);
00148 }
00149 
00150 
00153 double euclidian_distance(const Particle::vector_t& r1, const Particle::vector_t& r2);
00154 
00155 
00158 double euclidian_norm(const Particle::vector_t& r);
00159 
00160 
00161 #endif // PARTICLE_H

Generated on Fri Apr 22 11:06:42 2005 for partsim.kdevelop by doxygen 1.3.6