MechSys  1.0
Computing library for simulations in continuum and discrete mechanics
/home/dorival/mechsys/lib/fem/solver.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_FEM_SOLVER_H
00021 #define MECHSYS_FEM_SOLVER_H
00022 
00023 // Std Lib
00024 #include <cstring>  // for strcmp
00025 #include <iostream> // for cout
00026 
00027 // Blitz++
00028 #include <blitz/tinyvec-et.h>
00029 
00030 // MPI
00031 #ifdef HAS_MPI
00032   #include <mpi.h>
00033 #endif
00034 
00035 // MechSys
00036 #include <mechsys/fem/node.h>
00037 #include <mechsys/fem/element.h>
00038 #include <mechsys/fem/domain.h>
00039 #include <mechsys/linalg/sparse_triplet.h>
00040 #include <mechsys/linalg/sparse_matrix.h>
00041 #include <mechsys/linalg/umfpack.h>
00042 #include <mechsys/linalg/mumps.h>
00043 #include <mechsys/util/stopwatch.h>
00044 #include <mechsys/numerical/odesolver.h>
00045 
00046 namespace FEM
00047 {
00048 
00049 class Solver
00050 {
00051 public:
00052     // typedefs
00053     typedef void (*pOutFun) (Solver * Sol, void * OutDat); 
00054 
00055     // Constructor
00056     Solver (Domain & Dom, SDPair const & Flags, pOutFun OutFun=NULL, void * OutDat=NULL,
00057                                                 pOutFun DbgFun=NULL, void * DbgDat=NULL); 
00058 
00059     // Destructor
00060     virtual ~Solver () {}
00061 
00062     // Methods
00063     virtual void   Solve    (size_t NInc=1, char const * FileKey=NULL)                      { throw new Fatal("FEM::Solver.Solve: method not available for '%s' solver",   Name().CStr()); } 
00064     virtual void   DynSolve (double tf, double dt, double dtOut, char const * FileKey=NULL) { throw new Fatal("FEM::Solver.DynSolve: method not available for '%s' solver",Name().CStr()); } 
00065     virtual String Name     () const =0;
00066 
00067     // Auxiliary methods
00068     double Timestep (int i, int a=7, double L=100.0, int sch=0, double m=2.0) const; 
00069 
00070     // Data
00071     Domain  & Dom;      
00072     pOutFun   OutFun;   
00073     void    * OutDat;   
00074     pOutFun   DbgFun;   
00075     void    * DbgDat;   
00076 };
00077 
00078 
00080 
00081 
00082 inline Solver::Solver (Domain & TheDom, SDPair const & Flags, pOutFun TheOutFun, void * TheOutDat, pOutFun TheDbgFun, void * TheDbgDat)
00083     : Dom      (TheDom),
00084       OutFun   (TheOutFun),
00085       OutDat   (TheOutDat),
00086       DbgFun   (TheDbgFun),
00087       DbgDat   (TheDbgDat)
00088 {
00089 }
00090 
00091 inline double Solver::Timestep (int i, int a, double L, int sch, double m) const
00092 {
00093     return (i<a ? pow(2.0,i)/L : (sch==0 ? pow(2.0,i-a) : pow(2.0,a)/L+m*(i-a)));
00094 }
00095 
00096 
00098 
00099 
00100 typedef Solver * (*SolverMakerPtr)(Domain & Dom, SDPair const & Flags, Solver::pOutFun OutFun, void * OutDat, Solver::pOutFun DbgFun, void * DbgDat);
00101 
00102 typedef std::map<String, SolverMakerPtr> SolverFactory_t;
00103 
00104 SolverFactory_t SolverFactory;
00105 
00106 Solver * AllocSolver(String const & Name, Domain & Dom, SDPair const & Flags, Solver::pOutFun OutFun=NULL, void * OutDat=NULL, Solver::pOutFun DbgFun=NULL, void * DbgDat=NULL)
00107 {
00108     SolverFactory_t::iterator it = SolverFactory.find(Name);
00109     if (it==SolverFactory.end()) throw new Fatal("AllocSolver: '%s' is not available", Name.CStr());
00110     Solver * ptr = (*it->second)(Dom,Flags,OutFun,OutDat,DbgFun,DbgDat);
00111     return ptr;
00112 }
00113 
00114 
00115 }; // namespace FEM
00116 
00117 #endif // MECHSYS_FEM_SOLVER_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines