linearelastic.h

00001 /*************************************************************************************
00002  * MechSys - A C++ library to simulate (Continuum) Mechanical Systems                *
00003  * Copyright (C) 2005 Dorival de Moraes Pedroso <dorival.pedroso at gmail.com>       *
00004  * Copyright (C) 2005 Raul Dario Durand Farfan  <raul.durand at gmail.com>           *
00005  *                                                                                   *
00006  * This file is part of MechSys.                                                     *
00007  *                                                                                   *
00008  * MechSys is free software; you can redistribute it and/or modify it under the      *
00009  * terms of the GNU General Public License as published by the Free Software         *
00010  * Foundation; either version 2 of the License, or (at your option) any later        *
00011  * version.                                                                          *
00012  *                                                                                   *
00013  * MechSys is distributed in the hope that it will be useful, but WITHOUT ANY        *
00014  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A   *
00015  * PARTICULAR PURPOSE. See the GNU General Public License for more details.          *
00016  *                                                                                   *
00017  * You should have received a copy of the GNU General Public License along with      *
00018  * MechSys; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, *
00019  * Fifth Floor, Boston, MA 02110-1301, USA                                           *
00020  *************************************************************************************/
00021 
00022 #ifndef MECHSYS_LINEARELASTIC_H
00023 #define MECHSYS_LINEARELASTIC_H
00024 
00025 #ifdef HAVE_CONFIG_H
00026   #include "config.h"
00027 #else
00028   #ifndef REAL
00029     #define REAL double
00030   #endif
00031 #endif
00032 
00033 #include "models/equilibmodel.h"
00034 #include "util/string.h"
00035 #include "tensors/tensors.h"
00036 #include "tensors/operators.h"
00037 #include "tensors/functions.h"
00038 
00039 class LinearElastic : public EquilibModel
00040 {
00041 public:
00042     // Constants
00043     static const size_t NPRMS = 2;
00044     static const size_t NIDAT = 5;
00045 
00046     // Constructor
00047     LinearElastic(Array<REAL> const & Prms, Array<REAL> const & IniData);
00048 
00049     // Derived Methods
00050     String Name         () const { return "LinearElastic"; }
00051     void   TgStiffness  (Tensors::Tensor4 & D) const;
00052     void   StressUpdate (Tensors::Tensor2 const & DEps, Tensors::Tensor2 & DSig);
00053     void   Actualize    (Tensors::Tensor2 const & DSig, Tensors::Tensor2 & DEps);
00054     void   BackupState  ();
00055     void   RestoreState ();
00056 
00057     // Access Methods
00058     int  nInternalStateValues ()                              const { return 1;                                        }
00059     void InternalStateValues  (Array<REAL>   & IntStateVals ) const { IntStateVals .resize(1); IntStateVals [0] = _v;  }
00060     void InternalStateNames   (Array<String> & IntStateNames) const { IntStateNames.resize(1); IntStateNames[0] = "v"; }
00061 
00062 private:
00063     // Parameters
00064     REAL _E;  // Young
00065     REAL _nu; // Poisson
00066     REAL _v;  // Specific volume
00067     REAL _v_bkp;
00068 
00069 }; // class LinearElastic
00070 
00071 
00073 
00074 
00075 inline LinearElastic::LinearElastic(Array<REAL> const & Prms, Array<REAL> const & IniData) // {{{
00076 {
00077 
00078     // ##################################################################### Setup Parameters
00079 
00080     /* example.mat 
00081      * #----------------------------
00082      * #              Young  Poisson 
00083      * LinearElastic  20000     0.25 
00084      */
00085     
00086     // Check number of parameters 
00087     if (Prms.size()!=NPRMS) 
00088         throw new Fatal(_("LinearElastic::Constructor: The number of parameters (%d) is incorrect. It must be equal to %d \n"));
00089 
00090     // Fill the parameters
00091     _E  = Prms[0];
00092     _nu = Prms[1];
00093 
00094     // Check number of initial data
00095     if (IniData.size()!=NIDAT) 
00096         throw new Fatal(_("LinearElastic::Constructor: The number of initial data is not sufficient (it must be equal to %d). { Sx' Sy' Sz' vini(not-used) OCR(not-used) }"), NIDAT);
00097 
00098     // Fill stress and strain tensors
00099     _sig = IniData[0], IniData[1], IniData[2], 0.0, 0.0, 0.0; // Mandel representation
00100     _eps = 0.0,0.0,0.0,0.0,0.0,0.0;
00101 
00102     // Specific volume
00103     _v = IniData[3];
00104 
00105 } // }}}
00106 
00107 inline void LinearElastic::TgStiffness(Tensors::Tensor4 & De) const // {{{
00108 {
00109     // Calculate elastic tangent tensor
00110     Tensors::AddScaled(     _E/ (1.0+_nu)                , Tensors::IIsym ,
00111                         _nu*_E/((1.0+_nu)*(1.0-2.0*_nu)) , Tensors::IdyI  , De ); // Z = a*X + b*Y
00112 
00113 } // }}}
00114 
00115 inline void LinearElastic::StressUpdate(Tensors::Tensor2 const & DEps, Tensors::Tensor2 & DSig) // {{{
00116 {
00117     // Just a forward-Euler step
00118     Tensors::Tensor4 De;
00119     TgStiffness(De);
00120     Tensors::Dot(De,DEps, DSig);
00121 
00122     // Update stress and strains
00123     _sig += DSig;
00124     _eps += DEps;
00125 
00126     // Update internal state
00127     _v += -(DEps(0)+DEps(1)+DEps(2))*_v; // dv=-dEv*v
00128 
00129 } // }}}
00130 
00131 inline void LinearElastic::Actualize(Tensors::Tensor2 const & DSig, Tensors::Tensor2 & DEps) // {{{
00132 {
00133     // Calculate elastic tangent tensor
00134     Tensors::Tensor4 Ce;
00135     Tensors::AddScaled( (1.0+_nu)/_E , Tensors::IIsym ,
00136                             - _nu/_E , Tensors::IdyI  , Ce ); // Z = a*X + b*Y
00137 
00138     // Just a forward-Euler step
00139     Tensors::Dot(Ce,DSig, DEps);
00140 
00141     // Update stress and strains
00142     _sig += DSig;
00143     _eps += DEps;
00144 
00145     // Update internal state
00146     _v += -(DEps(0)+DEps(1)+DEps(2))*_v; // dv=-dEv*v
00147 
00148 } // }}}
00149 
00150 inline void LinearElastic::BackupState() // {{{
00151 {
00152     _sig_bkp = _sig;
00153     _eps_bkp = _eps;
00154     _v_bkp   = _v;
00155 } // }}}
00156 
00157 inline void LinearElastic::RestoreState() // {{{
00158 {
00159     _sig = _sig_bkp;
00160     _eps = _eps_bkp;
00161     _v   = _v_bkp;
00162 } // }}}
00163 
00164 
00166 
00167 
00168 // Allocate a new LinearElastic model
00169 EquilibModel * LinearElasticMaker(Array<REAL> const & Prms, Array<REAL> const & IniData) // {{{
00170 {
00171     return new LinearElastic(Prms, IniData);
00172 } // }}}
00173 
00174 // Register an LinearElastic model into ModelFactory array map
00175 int LinearElasticRegister() // {{{
00176 {
00177     EquilibModelFactory["LinearElastic"] = LinearElasticMaker;
00178     return 0;
00179 } // }}}
00180 
00181 // Execute the autoregistration
00182 int __LinearElastic_dummy_int = LinearElasticRegister();
00183 
00184 #endif // MECHSYS_LINEARELASTIC_H
00185 
00186 // vim:fdm=marker

Generated on Wed Jan 24 15:56:27 2007 for MechSys by  doxygen 1.4.7