forwardeuler.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_FEM_FORWARDEULER_H
00023 #define MECHSYS_FEM_FORWARDEULER_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 // MechSys
00034 #include "fem/solver/solver.h"
00035 
00036 namespace FEM
00037 {
00038 
00039 class ForwardEuler: public Solver
00040 {
00041 public:
00042     ForwardEuler(Array<String> const & SolverCtes, FEM::InputData const & ID, FEM::Data & data, FEM::Output & output)
00043         : Solver (ID, data, output),
00044           _nSS   (1)
00045     {
00046         for (size_t i=0; i<SolverCtes.size(); ++i)
00047         {
00048             LineParser LP(SolverCtes[i]);
00049             LP.ReplaceAllChars('=',' ');
00050             String key;     LP>>key;
00051             if (key=="nSS") LP>>_nSS;
00052             else throw new Fatal(_("ForwardEuler::ForwardEuler: < %s > is invalid "), key.c_str());
00053         }
00054         if (_nSS<1) throw new Fatal(_("ForwardEuler::ForwardEuler: The number of substeps (nSS=%d) must be greater than or equal to 1"), _nSS);
00055     }
00056     void _do_solve_for_an_increment(int                  const   increment,  // In
00057                                     LinAlg::Vector<REAL> const & DF_ext   ,  // In
00058                                     LinAlg::Vector<REAL> const & DU_ext   ,  // In
00059                                     LinAlg::Matrix<REAL>       & K        ,  // (no needed outside)
00060                                     LinAlg::Vector<REAL>       & dF_int   ,  // (no needed outside)
00061                                     LinAlg::Vector<REAL>       & Rinternal,  // (no needed outside)
00062                                     IntSolverData              & ISD      ); // Out
00063 private:
00064     int _nSS; // number of substeps
00065 }; // class ForwardEuler
00066 
00067 
00069 
00070 
00071 inline void ForwardEuler::_do_solve_for_an_increment(int                  const   increment, // In // {{{
00072                                                      LinAlg::Vector<REAL> const & DF_ext   , // In
00073                                                      LinAlg::Vector<REAL> const & DU_ext   , // In
00074                                                      LinAlg::Matrix<REAL>       & K        , // (no needed outside)
00075                                                      LinAlg::Vector<REAL>       & dF_int   , // (no needed outside)
00076                                                      LinAlg::Vector<REAL>       & Rinternal, // (no needed outside)
00077                                                      IntSolverData              & ISD      ) // Out
00078 {
00079     // Allocate and fill dF_ext and dU_ext
00080     int n_tot_dof = DF_ext.Size();
00081     LinAlg::Vector<REAL> dF_ext; dF_ext.Resize(n_tot_dof);
00082     LinAlg::Vector<REAL> dU_ext; dU_ext.Resize(n_tot_dof);
00083     LinAlg::CopyScal(1.0/_nSS,DF_ext, dF_ext); // dF_ext <- DF_ext/_nss
00084     LinAlg::CopyScal(1.0/_nSS,DU_ext, dU_ext); // dU_ext <- DU_ext/_nss
00085 
00086     // Start
00087     for (int i=0; i<_nSS; ++i)
00088     {
00089         // Assemble K matrix and calculate dU_ext
00090         _assemb_K      (K);
00091         _inv_K_times_X (K, false, dF_ext, dU_ext); // In=R,U; Out=dU  =>  dU=inv[K(U)]*R
00092 
00093         // Update nodes and elements state
00094         _update_nodes_and_elements_state(dU_ext, dF_int);
00095 
00096         // Calculate residual (internal)
00097         LinAlg::AddScaled (1.0,dF_ext, -1.0,dF_int, Rinternal); // Rinternal <- dF_ext - dF_int
00098         REAL denom = 0.0;                                       // Normalizer
00099         for (int i=0; i<Rinternal.Size(); i++) denom += pow((dF_ext(i)+dF_int(i))/2.0, 2.0);
00100         ISD.FE_resid(LinAlg::Norm(Rinternal)/sqrt(denom));
00101     }
00102 
00103 } // }}}
00104 
00105 
00107 
00108 
00109 // Allocate a new ForwardEuler solver
00110 Solver * ForwardEulerMaker(Array<String> const & SolverCtes, FEM::InputData const & ID, FEM::Data & data, FEM::Output & output) // {{{
00111 {
00112     return new ForwardEuler(SolverCtes, ID, data, output);
00113 } // }}}
00114 
00115 // Register an ForwardEuler solver into SolverFactory array map
00116 int ForwardEulerRegister() // {{{
00117 {
00118     SolverFactory["ForwardEuler"] = ForwardEulerMaker;
00119     return 0;
00120 } // }}}
00121 
00122 // Execute the autoregistration
00123 int __ForwardEuler_dummy_int = ForwardEulerRegister();
00124 
00125 }; // namespace FEM
00126 
00127 #endif // MECHSYS_FEM_FORWARDEULER_H
00128 
00129 // vim:fdm=marker

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