MechSys  1.0
Computing library for simulations in continuum and discrete mechanics
/home/dorival/mechsys/lib/lbm/Dem.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 
00021 #ifndef MECHSYS_LBM_DEM_H
00022 #define MECHSYS_LBM_DEM_H
00023 
00024 // STD
00025 #include <algorithm>
00026 
00027 // Mechsys
00028 #include <mechsys/lbm/Lattice.h>
00029 
00030 namespace LBM
00031 {
00032 class Particle
00033 {
00034 public:
00035     Particle () {} 
00036 
00037     //Methods
00038     void Translate   (double dt);
00039     void FixVelocity () {vf=true,true,true; wf=true,true,true;};
00040     bool IsFree () {return !vf(0)&&!vf(1)&&!vf(2)&&!wf(0)&&!wf(1)&&!wf(2);}; 
00041     void ImprintDisk (Lattice & Lat);
00042 
00043     // Data
00044     int  Tag;              
00045     Vec3_t X0;             
00046     Vec3_t X;              
00047     Vec3_t Xb;             
00048     Vec3_t V;              
00049     Vec3_t W;              
00050     Vec3_t Wb;             
00051     Vec3_t F;              
00052     Vec3_t Ff;             
00053     Vec3_t T;              
00054     Vec3_t Tf;             
00055     double R;              
00056     double M;              
00057     double I;              
00058     double GT;             
00059     double Gn;             
00060     double Kn;             
00061     bVec3_t vf;            
00062     bVec3_t wf;            
00063     
00064 };
00065 
00066 class Disk: public Particle
00067 {
00068 public:
00069     //Constructor
00070     Disk(int Tag, Vec3_t const & X, Vec3_t const & V, Vec3_t const & W, double rho, double R, double dt);
00071 
00072     //Imprint method
00073     void ImprintDisk(Lattice & Lat);
00074 };
00075 
00076 class Sphere: public Particle
00077 {
00078 public:
00079     //Constructor
00080     Sphere(int Tag, Vec3_t const & X, Vec3_t const & V, Vec3_t const & W, double rho, double R, double dt);
00081 };
00082 
00083 inline void Particle::Translate(double dt)
00084 {
00085     //std::cout << F(0) << " " << M << " " << V(0) << std::endl;
00086     if (vf(0)) F(0) = 0.0;
00087     if (vf(1)) F(1) = 0.0;
00088     if (vf(2)) F(2) = 0.0;
00089     Vec3_t Xa = 2*X - Xb + F*(dt*dt/M);
00090     Vec3_t tp = Xa - X;
00091     V         = 0.5*(Xa - Xb)/dt;
00092     Xb        = X;
00093     X         = Xa;
00094 
00095     //if (wf(0)) T(0) = 0.0;
00096     //if (wf(1)) T(1) = 0.0;
00097     //if (wf(2)) T(2) = 0.0;
00098     //Vec3_t Wa = Wb + 2*dt*(T-GT*W)/I;
00099     //Wb        = W;
00100     //W         = Wa;
00101 
00102     //std::cout << T(2) << " " << W(2) << " " << Wb(2) << std::endl;
00103 }
00104 
00105 
00106 
00107 inline Disk::Disk(int TheTag, Vec3_t const & TheX, Vec3_t const & TheV, Vec3_t const & TheW, double Therho, double TheR, double dt)
00108 {
00109     Tag = TheTag;
00110     X   = TheX;
00111     V   = TheV;
00112     W   = TheW;
00113     R   = TheR;
00114     M   = M_PI*R*R*Therho;
00115     I   = 0.5*M*R*R;
00116     Xb  = X - dt*V;
00117     Wb  = W;
00118     Ff  = 0.0,0.0,0.0;
00119     Tf  = 0.0,0.0,0.0;
00120     vf  = false,false,false;
00121     wf  = false,false,false;
00122     GT  = 1.0e5;
00123     Kn  = 1.0e3;
00124 }
00125 
00126 inline void Particle::ImprintDisk(Lattice & Lat)
00127 {
00128     for (size_t n=std::max(0.0,double(X(0)-R-Lat.dx)/Lat.dx);n<=std::min(double(Lat.Ndim(0)-1),double(X(0)+R+Lat.dx)/Lat.dx);n++)
00129     for (size_t m=std::max(0.0,double(X(1)-R-Lat.dx)/Lat.dx);m<=std::min(double(Lat.Ndim(1)-1),double(X(1)+R+Lat.dx)/Lat.dx);m++)
00130     //for (size_t i=0;i<Lat.Cells.Size();i++)
00131     {
00132         Cell  * cell = Lat.GetCell(iVec3_t(n,m,0));
00133         //Cell  * cell = Lat.Cells[i];
00134         double x     = Lat.dx*cell->Index(0);
00135         double y     = Lat.dx*cell->Index(1);
00136         double z     = Lat.dx*cell->Index(2);
00137         Vec3_t  C(x,y,z);
00138 
00139         Array<Vec3_t> P(4);
00140 
00141         P[0] = C - 0.5*Lat.dx*OrthoSys::e0 - 0.5*Lat.dx*OrthoSys::e1;
00142         P[1] = C + 0.5*Lat.dx*OrthoSys::e0 - 0.5*Lat.dx*OrthoSys::e1;
00143         P[2] = C + 0.5*Lat.dx*OrthoSys::e0 + 0.5*Lat.dx*OrthoSys::e1;
00144         P[3] = C - 0.5*Lat.dx*OrthoSys::e0 + 0.5*Lat.dx*OrthoSys::e1;
00145 
00146         double len = 0.0;
00147         for (size_t j=0;j<4;j++)
00148         {
00149             Vec3_t D = P[(j+1)%4] - P[j];
00150             double a = dot(D,D);
00151             double b = 2*dot(P[j]-X,D);
00152             double c = dot(P[j]-X,P[j]-X) - R*R;
00153             if (b*b-4*a*c>0.0)
00154             {
00155                 double ta = (-b - sqrt(b*b-4*a*c))/(2*a);
00156                 double tb = (-b + sqrt(b*b-4*a*c))/(2*a);
00157                 if (ta>1.0&&tb>1.0) continue;
00158                 if (ta<0.0&&tb<0.0) continue;
00159                 if (ta<0.0) ta = 0.0;
00160                 if (tb>1.0) tb = 1.0;
00161                 len += norm((tb-ta)*D);
00162             }
00163         }
00164 
00165         if (len>0.0)
00166         {
00167             cell->Gamma   = std::max(len/(4*Lat.dx),cell->Gamma);
00168             if (fabs(cell->Gamma-1.0)<1.0e-12&&fabs(Lat.G)>1.0e-12) continue;
00169             Vec3_t B      = C - X;
00170             Vec3_t VelP   = V + cross(W,B);
00171             Vec3_t V   = cell->Vel;
00172             double rho = cell->Rho;
00173             double Bn  = (cell->Gamma*(cell->Tau-0.5))/((1.0-cell->Gamma)+(cell->Tau-0.5));
00174             for (size_t j=0;j<cell->Nneigh;j++)
00175             {
00176                 //double Feqn    = cell->Feq(j,                   V,rho);
00177                 double Fvpp    = cell->Feq(cell->Op[j],VelP,rho);
00178                 double Fvp     = cell->Feq(j          ,VelP,rho);
00179                 //cell->Omeis[j] = Fvp - cell->F[j] + (1.0 - 1.0/cell->Tau)*(cell->F[j] - Feqn);
00180                 cell->Omeis[j] = cell->F[cell->Op[j]] - Fvpp - (cell->F[j] - Fvp);
00181                 Vec3_t Flbm    = -Bn*cell->Omeis[j]*cell->C[j];
00182                 F             += Flbm;
00183                 T             += cross(B,Flbm);
00184             }
00185         }
00186     }
00187 }
00188 
00189 inline Sphere::Sphere(int TheTag, Vec3_t const & TheX, Vec3_t const & TheV, Vec3_t const & TheW, double Therho, double TheR, double dt)
00190 {
00191     Tag = TheTag;
00192     X   = TheX;
00193     V   = TheV;
00194     W   = TheW;
00195     R   = TheR;
00196     M   = 4.0/3.0*M_PI*R*R*R*Therho;
00197     I   = 2.0/5.0*M*R*R;
00198     Xb  = X - dt*V;
00199     Wb  = W;
00200     Ff  = 0.0,0.0,0.0;
00201     Tf  = 0.0,0.0,0.0;
00202     vf  = false,false,false;
00203     wf  = false,false,false;
00204     GT  = 1.0e5;
00205     Gn  = 8.0;
00206     Kn  = 1.0e3;
00207 }
00208 
00209 }
00210 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines