00001
00002
00003 #ifndef DUNE_LOCALSTIFFNESS_HH
00004 #define DUNE_LOCALSTIFFNESS_HH
00005
00006 #include<iostream>
00007 #include<vector>
00008 #include<set>
00009 #include<map>
00010 #include<stdio.h>
00011 #include<stdlib.h>
00012
00013 #include<dune/common/timer.hh>
00014 #include<dune/common/fvector.hh>
00015 #include<dune/common/fmatrix.hh>
00016 #include<dune/common/fixedarray.hh>
00017 #include<dune/common/exceptions.hh>
00018 #include<dune/common/geometrytype.hh>
00019 #include<dune/grid/common/grid.hh>
00020 #include<dune/istl/operators.hh>
00021 #include<dune/istl/bvector.hh>
00022 #include<dune/istl/matrix.hh>
00023 #include"boundaryconditions.hh"
00024
00041 namespace Dune
00042 {
00063 template<class GV, class RT, int m>
00064 class LocalStiffness
00065 {
00066
00067 typedef typename GV::Grid::ctype DT;
00068 typedef typename GV::template Codim<0>::Entity Entity;
00069 enum {n=GV::dimension};
00070
00071 public:
00072
00073 typedef FieldMatrix<RT,m,m> MBlockType;
00074 typedef FieldVector<RT,m> VBlockType;
00075 typedef array<BoundaryConditions::Flags,m> BCBlockType;
00076
00077 virtual ~LocalStiffness ()
00078 {
00079 }
00080
00082
00099 virtual void assemble (const Entity& e, int k=1) = 0;
00100
00124 virtual void assemble (const Entity& e, const BlockVector<VBlockType>& localSolution, int k=1) = 0;
00125
00126
00128
00144 virtual void assembleBoundaryCondition (const Entity& e, int k=1) = 0;
00145
00147 void print (std::ostream& s, int width, int precision)
00148 {
00149
00150 s.setf(std::ios_base::scientific, std::ios_base::floatfield);
00151 int oldprec = s.precision();
00152 s.precision(precision);
00153
00154 for (int i=0; i<currentsize(); i++)
00155 {
00156 s << "FEM";
00157 s << " ";
00158 s.width(4);
00159 s << i;
00160 for (int j=0; j<currentsize(); j++)
00161 {
00162 s << " ";
00163 s.width(width);
00164 s << mat(i,j);
00165 }
00166 s << " ";
00167 s.width(width);
00168 s << rhs(i);
00169 s << " ";
00170 s.width(width);
00171 s << bc(i)[0];
00172 s << std::endl;
00173 }
00174
00175
00176
00177 s.precision(oldprec);
00178 s.setf(std::ios_base::fixed, std::ios_base::floatfield);
00179 }
00180
00182
00185 const MBlockType& mat (int i, int j) const
00186 {
00187 return A[i][j];
00188 }
00189
00190
00192
00195 const VBlockType& rhs (int i) const
00196 {
00197 return b[i];
00198 }
00199
00201
00204 const BCBlockType& bc (int i) const
00205 {
00206 return bctype[i];
00207 }
00208
00210 void setcurrentsize (int s)
00211 {
00212 A.setSize(s,s);
00213 b.resize(s);
00214 bctype.resize(s);
00215 }
00216
00218 int currentsize ()
00219 {
00220 return A.N();
00221 }
00222
00223 protected:
00224
00225 Matrix<MBlockType> A;
00226 std::vector<VBlockType> b;
00227 std::vector<BCBlockType> bctype;
00228
00229 };
00230
00241 template<class GV, class RT, int m>
00242 class LinearLocalStiffness : public LocalStiffness<GV,RT,m>
00243 {
00244
00245 typedef typename GV::Grid::ctype DT;
00246 typedef typename GV::template Codim<0>::Entity Entity;
00247 enum {n=GV::dimension};
00248
00249 public:
00250
00251 typedef FieldMatrix<RT,m,m> MBlockType;
00252 typedef FieldVector<RT,m> VBlockType;
00253 typedef array<BoundaryConditions::Flags,m> BCBlockType;
00254
00256 LinearLocalStiffness ()
00257 {}
00258
00259 virtual ~LinearLocalStiffness ()
00260 {
00261 }
00262
00264
00281 virtual void assemble (const Entity& e, int k=1) = 0;
00282
00291 virtual void assemble (const Entity& e, const BlockVector<VBlockType>& localSolution, int k=1)
00292 {
00293 assemble(e,k);
00294 }
00295
00296 };
00297
00300 }
00301 #endif