00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #ifndef __SIDE_VECT_H
00035 #define __SIDE_VECT_H
00036
00037
00038 #include "AbsVect.h"
00039
00040
00041 namespace OFELI {
00042
00047 template <class T_> class Vect;
00048 template <class T_> class AbsVect;
00049
00050
00051
00052
00053
00054 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00055 template<class T_>
00056 struct ErrorInSideVect {
00057 void Message(const char *file, size_t line, int code, int p1=0) {
00058 cerr << "\n*** Fatal Error in OFELI ***\n";
00059 cerr << "File : " << file << ", line : " << line << "\nIn SideVect<>::";
00060 switch (code) {
00061
00062 case 21:
00063 cerr << "SideVect(mesh,nb_dof) : Illegal value of nb_dof : " << p1 << endl;
00064 break;
00065
00066 case 31:
00067 cerr << "SideVect(mesh,nb_dof,name,time) : Illegal value of nb_dof : " << p1 << endl;
00068 break;
00069 }
00070 cerr << "Program stops" << endl;
00071 exit(1);
00072 }
00073 };
00074 #endif
00075
00076
00077
00091 template <class T_>
00092 class SideVect : virtual public AbsVect<T_>
00093 {
00094
00095 public:
00096
00097 using AbsVect<T_>::Init;
00098 using AbsVect<T_>::setName;
00099
00102 SideVect();
00103
00108 SideVect(const class Mesh &mesh, size_t nb_dof=1);
00109
00116 SideVect(const class Mesh &mesh, size_t nb_dof, const char *name, double time=0);
00117
00119 SideVect(const SideVect<T_> &v);
00120
00122 ~SideVect();
00123
00128 void setMesh(const class Mesh &ms, size_t nb_dof=0);
00129
00131 size_t getNbSides() const;
00132
00135 SideVect<T_> & operator=(T_ a);
00136
00141 SideVect<T_> & operator+=(const SideVect<T_> &x);
00142
00147 SideVect<T_> & operator+=(const T_ &a);
00148
00151 SideVect<T_> & operator-=(const SideVect<T_> &x);
00152
00157 SideVect<T_> & operator-=(const T_ &a);
00158
00161 SideVect<T_> &operator*=(const T_ &a);
00162
00165 SideVect<T_> &operator/=(const T_ &a);
00166
00167 private:
00168
00169 ErrorInSideVect<T_> _e;
00170 size_t _nb_sides;
00171 using AbsVect<T_>::_nbn;
00172 using AbsVect<T_>::_nb;
00173 using AbsVect<T_>::_nb_dof;
00174 using AbsVect<T_>::_first_dof;
00175 using AbsVect<T_>::_length;
00176 using AbsVect<T_>::_time;
00177 using AbsVect<T_>::_name;
00178 using AbsVect<T_>::_theMesh;
00179 using AbsVect<T_>::_v;
00180 };
00181
00182
00183
00185
00187
00188
00189 template<class T_>
00190 SideVect<T_>::SideVect()
00191 {
00192 #ifdef _OFELI_DEBUG
00193 std::clog << "An instance of class SideVect is constructed.\n";
00194 std::clog << "File : " << __FILE__ << ", Line: " << __LINE__ << endl;
00195 #endif
00196 }
00197
00198
00199 template<class T_>
00200 SideVect<T_>::SideVect(const class Mesh &mesh, size_t nb_dof) : AbsVect<T_>(mesh,nb_dof)
00201 {
00202 _nb = _nb_sides = mesh.getNbSides();
00203 _nbn = 1;
00204 _nb_dof = nb_dof;
00205 _length = _nb_dof * _nb;
00206 Init();
00207 #ifdef _OFELI_DEBUG
00208 std::clog << "An instance of class SideVect is constructed.\n";
00209 std::clog << "File : " << __FILE__ << ", Line : " << __LINE__ << endl;
00210 #endif
00211 }
00212
00213
00214 template<class T_>
00215 SideVect<T_>::SideVect(const class Mesh &mesh, size_t nb_dof, const char *name, double time)
00216 : AbsVect<T_>(mesh,nb_dof,name,time)
00217 {
00218 if (nb_dof <= 0)
00219 _e.Message(__FILE__,__LINE__,31,nb_dof);
00220 _nb_dof = nb_dof;
00221 _nb = _nb_sides = mesh.getNbSides();
00222 _length = _nb_dof * _nb_sides;
00223 Init();
00224 #ifdef _OFELI_DEBUG
00225 std::clog << "An instance of class SideVect is constructed.\n";
00226 std::clog << "File : " << __FILE__ << ", Line : " << __LINE__ << endl;
00227 #endif
00228 }
00229
00230
00231 template<class T_>
00232 SideVect<T_>::SideVect(const SideVect<T_> &v)
00233 {
00234 _time = v._time;
00235 _name = v._name;
00236 _length = v.getLength();
00237 _nb = _nb_sides = v.getNbSides();
00238 _nbn = 1;
00239 _theMesh = v._theMesh;
00240 _first_dof = 1;
00241 _nb_dof = v._nb_dof;
00242 Init();
00243 _v = v._v;
00244 #ifdef _OFELI_DEBUG
00245 std::clog << "An instance of class SideVect is constructed.\n";
00246 std::clog << "File : " << __FILE__ << ", Line : " << __LINE__ << endl;
00247 #endif
00248 }
00249
00250
00251 template<class T_>
00252 SideVect<T_>::~SideVect()
00253 {
00254 #ifdef _OFELI_DEBUG
00255 std::clog << "An instance of class SideVect is destructed.\n";
00256 std::clog << "File : " << __FILE__ << ", Line : " << __LINE__ << endl;
00257 #endif
00258 }
00259
00260
00261 template<class T_>
00262 void SideVect<T_>::setMesh(const class Mesh &ms, size_t nb_dof)
00263 {
00264 _theMesh = &ms;
00265 _first_dof = 1;
00266 _nbn = 1;
00267 _nb_dof = nb_dof;
00268 if (_nb_dof==0)
00269 _nb_dof = ms.getPtrSide(1)->getNbDOF();
00270 _nb = _nb_sides = ms.getNbSides();
00271 _length = _nb_dof * _nb_sides;
00272 Init();
00273 }
00274
00275
00276 template<class T_>
00277 size_t SideVect<T_>::getNbSides() const
00278 {
00279 return _nb_sides;
00280 }
00281
00282
00283 template<class T_>
00284 SideVect<T_> & SideVect<T_>::operator=(T_ a)
00285 {
00286 for (size_t i=0; i<_length; ++i)
00287 _v[i] = a;
00288 return *this;
00289 }
00290
00291
00292 template <class T_>
00293 SideVect<T_> & SideVect<T_>::operator+=(const SideVect<T_> &x)
00294 {
00295 for (size_t i=0; i<_length; ++i)
00296 _v[i] += x[i];
00297 return *this;
00298 }
00299
00300
00301 template <class T_>
00302 SideVect<T_> & SideVect<T_>::operator+=(const T_ &a)
00303 {
00304 for (size_t i=0; i<_length; ++i)
00305 _v[i] += a;
00306 return *this;
00307 }
00308
00309
00310 template <class T_>
00311 SideVect<T_> & SideVect<T_>::operator-=(const SideVect<T_> &x)
00312 {
00313 for (size_t i=0; i<_length; ++i)
00314 _v[i] -= x[i];
00315 return *this;
00316 }
00317
00318
00319 template <class T_>
00320 SideVect<T_> & SideVect<T_>::operator-=(const T_ &a)
00321 {
00322 for (size_t i=0; i<_length; ++i)
00323 _v[i] -= a;
00324 return *this;
00325 }
00326
00327
00328 template <class T_>
00329 SideVect<T_> & SideVect<T_>::operator*=(const T_ &a)
00330 {
00331 for (size_t i=0; i<_length; ++i)
00332 _v[i] *= a;
00333 return *this;
00334 }
00335
00336
00337 template <class T_>
00338 SideVect<T_> & SideVect<T_>::operator/=(const T_ &a)
00339 {
00340 for (size_t i=0; i<_length; ++i)
00341 _v[i] /= a;
00342 return *this;
00343 }
00344
00345
00347
00349
00350
00354 template <class T_>
00355 istream& operator>>(istream& s, SideVect<T_> &v)
00356 {
00357 size_t j, n;
00358 double time;
00359 static char name[40];
00360 s >> name;
00361 v.setName(name);
00362 s >> n >> time;
00363 v.setTime(time);
00364
00365 for (size_t i=1; i<=n; i++) {
00366 s >> j;
00367 for (size_t k=1; k<=v.NbDOF(); k++)
00368 s >> v(i,j) >> " ";
00369 }
00370 return s;
00371 }
00372
00373
00377 template <class T_>
00378 ostream& operator<<(ostream &s, const SideVect<T_> &v)
00379 {
00380 const Side *sd;
00381 s << v.getName() << " at";
00382 s << " time = " << v.getTime() << endl << endl;
00383 s.setf(ios::scientific);
00384 for (v.getMesh().topSide(); (sd=v.getMesh().getSide());) {
00385 size_t i = sd->getLabel();
00386 s << setw(6) << i << " ";
00387 for (size_t j=1; j<=v.getNbDOF(); j++)
00388 s << setprecision(8) << setw(18) << v(i,j);
00389 s << endl;
00390 }
00391 s << endl;
00392 return s;
00393 }
00394
00395 }
00396
00397 #endif