MechSys  1.0
Computing library for simulations in continuum and discrete mechanics
/home/dorival/mechsys/lib/dem/basic_functions.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_DEM_BASIC_H
00021 #define MECHSYS_DEM_BASIC_H
00022 
00023 // Stl
00024 #include <algorithm>
00025 
00026 // Some functions for the mass properties integration
00027 inline double f1(size_t i, Vec3_t const & V0, Vec3_t const & V1, Vec3_t const & V2)
00028 {
00029     return V0(i)+V1(i)+V2(i);
00030 }
00031 
00032 inline double f2(size_t i, Vec3_t const & V0, Vec3_t const & V1, Vec3_t const & V2)
00033 {
00034     return V0(i)*V0(i)+V0(i)*V1(i)+V1(i)*V1(i)+V2(i)*f1(i,V0,V1,V2);
00035 }
00036 
00037 inline double f3(size_t i, Vec3_t const & V0, Vec3_t const & V1, Vec3_t const & V2)
00038 {
00039     return V0(i)*V0(i)*V0(i)+V0(i)*V0(i)*V1(i)+V0(i)*V1(i)*V1(i)+V1(i)*V1(i)*V1(i)+V2(i)*f2(i,V0,V1,V2);
00040 }
00041 
00042 inline double g0(size_t i, Vec3_t const & V0, Vec3_t const & V1, Vec3_t const & V2)
00043 {
00044     return f2(i,V0,V1,V2)+V0(i)*(f1(i,V0,V1,V2)+V0(i));
00045 }
00046 
00047 inline double g1(size_t i, Vec3_t const & V0, Vec3_t const & V1, Vec3_t const & V2)
00048 {
00049     return f2(i,V0,V1,V2)+V1(i)*(f1(i,V0,V1,V2)+V1(i));
00050 }
00051 
00052 inline double g2(size_t i, Vec3_t const & V0, Vec3_t const & V1, Vec3_t const & V2)
00053 {
00054     return f2(i,V0,V1,V2)+V2(i)*(f1(i,V0,V1,V2)+V2(i));
00055 }
00056 
00057 inline void CheckDestroGiro(Vec3_t & xp, Vec3_t & yp, Vec3_t & zp) // Check if the coordinate system is destrogiro and modify the system accordingly for the quaternion calculation
00058 {
00059     bool destrogiro = dot(cross(xp,yp),zp)>0;
00060     if (!destrogiro)
00061     {
00062         xp = -xp;
00063         if (1+xp(0)+yp(1)+zp(2)>0) return;
00064         else 
00065         {
00066             xp = -xp;
00067             yp = -yp;
00068             if (1+xp(0)+yp(1)+zp(2)>0) return;
00069             else
00070             {
00071                 yp = -yp;
00072                 zp = -zp;
00073                 if (1+xp(0)+yp(1)+zp(2)>0) return;
00074                 else throw new Fatal("specialfunctions.h::CheckDestroGiro: The system cannot be transformed by a quaternion operation");
00075             }
00076         }
00077     }
00078 }
00079 
00080 inline double ReducedValue(double A, double B) //Reduced Value for two quantities
00081 {
00082     double result = A*B;
00083     if (result>0.0) result/=(A+B);
00084     return result;
00085 }
00086 
00087 #endif //MECHSYS_DEM_BASIC_H
00088 
00089 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines