MechSys  1.0
Computing library for simulations in continuum and discrete mechanics
/home/dorival/mechsys/lib/sph/particle.h
Go to the documentation of this file.
00001 /************************************************************************
00002  * MechSys - Open Library for Mechanical Systems                        *
00003  * Copyright (C) 2005 Dorival M. Pedroso, Raul Durand                   *
00004  * Copyright (C) 2009 Sergio Galindo                                    *
00005  *                                                                      *
00006  * This program is free software: you can redistribute it and/or modify *
00007  * it under the terms of the GNU General Public License as published by *
00008  * the Free Software Foundation, either version 3 of the License, or    *
00009  * any later version.                                                   *
00010  *                                                                      *
00011  * This program is distributed in the hope that it will be useful,      *
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the         *
00014  * GNU General Public License for more details.                         *
00015  *                                                                      *
00016  * You should have received a copy of the GNU General Public License    *
00017  * along with this program. If not, see <http://www.gnu.org/licenses/>  *
00018  ************************************************************************/
00019 
00020 #ifndef MECHSYS_SPH_PARTICLE_H
00021 #define MECHSYS_SPH_PARTICLE_H
00022 
00023 // Std lib
00024 #include <iostream>
00025 
00026 // MechSys
00027 #include <mechsys/linalg/matvec.h>
00028 #include <mechsys/dem/special_functions.h>
00029 
00030 namespace SPH {
00031 
00032 class Particle
00033 {
00034 public:
00035 
00036     // Constructor
00037     Particle(Vec3_t const & x0, Vec3_t const & v0, double density0, double h0, bool Fixed=false);
00038 
00039 
00040     // Data
00041     bool   IsFree;                  
00042     Vec3_t xo;                      
00043     Vec3_t x;                       
00044     Vec3_t xb;                      
00045     Vec3_t v;                       
00046     Vec3_t a;                       
00047     double Pressure;                
00048     double Density;                 
00049     double Densityb;                
00050     double Density0;                
00051     double dDensity;                
00052     double h;                       
00053 
00054 
00055     // Methods
00056     void Move (double dt);                                                  
00057     void StartAccel (Vec3_t acc = Vec3_t(0.0,0.0,0.0)) {a = acc;};          
00058     void Translate  (Vec3_t const & V) {x+=V; xb+=V;};                      
00059     void ResetDisplacements ();                                             
00060     double MaxDisplacement ();                                              
00061 
00062 };
00063 
00064 inline Particle::Particle(Vec3_t const & x0, Vec3_t const & v0, double density0, double h0,bool Fixed)
00065 {
00066     x = x0;
00067     xb = x;
00068     v = v0;
00069     Density = density0;
00070     Densityb = Density;
00071     Density0 = Density;
00072     IsFree = !Fixed;
00073     h = h0;
00074 }
00075 
00076 inline void Particle::Move (double dt)
00077 {
00078     if (IsFree)
00079     {
00080         // Evolve position and velocity
00081         Vec3_t xa;
00082         xa = 2*x - xb + a*dt*dt;
00083         v = 0.5*(xa - xb)/dt;
00084         xb = x;
00085         x = xa;
00086 
00087         // Evolve density
00088         double dens = Density;
00089         Density = Densityb + 2*dt*dDensity;
00090         //std::cout << Density << std::endl;
00091         Densityb = dens;
00092     }
00093 }
00094 
00095 inline void Particle::ResetDisplacements ()
00096 {
00097     xo = x;
00098 }
00099 
00100 inline double Particle::MaxDisplacement ()
00101 {
00102     return Distance(x,xo);
00103 }
00104 
00105 }; // namespace SPH
00106 
00107 #endif // MECHSYS_SPH_PARTICLE_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines