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 __EDGE_VECT_H
00035 #define __EDGE_VECT_H
00036
00037
00038 namespace OFELI {
00039
00045 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00046 template<class T_>
00047 struct ErrorInEdgeVect {
00048 void Message(const char *file, size_t line, int code, int p1=0, int p2=0, char *p3=NULL) {
00049 cerr << "\n*** Fatal Error in OFELI ***\n";
00050 cerr << "File : " << file << ", line : " << line << "\nIn EdgeVect<>::";
00051 switch (code) {
00052
00053 case 21:
00054 cerr << "EdgeVect(mesh,nb_dof) : Illegal value of _nb_dof : " << p1 << endl;
00055 break;
00056
00057 case 31:
00058 cerr << "EdgeVect(mesh,nb_dof,name,time) : Illegal value of _nb_dof : " << p1 << endl;
00059 break;
00060 }
00061 cerr << "Program stops" << endl;
00062 exit(1);
00063 }
00064 };
00065 #endif
00066
00067
00081 template <class T_>
00082 class EdgeVect : virtual public AbsVect<T_>
00083 {
00084
00085 public:
00086
00087 using AbsVect<T_>::Init;
00088 using AbsVect<T_>::getName;
00089
00091 EdgeVect();
00092
00097 EdgeVect(const class Mesh &mesh, size_t nb_dof=1);
00098
00105 EdgeVect(const class Mesh &mesh, size_t nb_dof, const string &name=" ", double time=0);
00106
00109 EdgeVect(const EdgeVect<T_> &v);
00110
00112 ~EdgeVect();
00113
00118 void setMesh(class Mesh &ms, size_t nb_dof=0);
00119
00121 size_t getNbEdges() const;
00122
00125 EdgeVect<T_> & operator=(T_ a);
00126
00131 EdgeVect<T_> & operator+=(const EdgeVect<T_> &x);
00132
00137 EdgeVect<T_> & operator+=(const T_ &a);
00138
00141 EdgeVect<T_> & operator-=(const EdgeVect<T_> &x);
00142
00147 EdgeVect<T_> & operator-=(const T_ &a);
00148
00151 EdgeVect<T_> &operator*=(const T_ &a);
00152
00155 EdgeVect<T_> &operator/=(const T_ &a);
00156
00157 private:
00158
00159 using AbsVect<T_>::_nbn;
00160 using AbsVect<T_>::_nb;
00161 using AbsVect<T_>::_nb_dof;
00162 using AbsVect<T_>::_first_dof;
00163 using AbsVect<T_>::_length;
00164 using AbsVect<T_>::_time;
00165 using AbsVect<T_>::_name;
00166 using AbsVect<T_>::_theMesh;
00167 using AbsVect<T_>::_v;
00168
00169 ErrorInEdgeVect<T_> _e;
00170 size_t _nb_edges;
00171
00172 };
00173
00174
00176
00178
00179
00180 template <class T_>
00181 EdgeVect<T_>::EdgeVect()
00182 {
00183 #ifdef _OFELI_DEBUG
00184 std::clog << "An instance of class EdgeVect is constructed.\n";
00185 std::clog << "File: " << __FILE__ << ", Line: " << __LINE__ << endl;
00186 #endif
00187 }
00188
00189
00190 template <class T_>
00191 EdgeVect<T_>::EdgeVect(const class Mesh &mesh, size_t nb_dof) : AbsVect<T_>(mesh,_nb_dof)
00192 {
00193 if (nb_dof <= 0 || nb_dof)
00194 _e.Message(__FILE__,__LINE__,21,_nb_dof);
00195 _nb = _nb_edges = mesh.getNbEdges();
00196 _nb_dof = nb_dof;
00197 _length = _nb_dof * _nb;
00198 Init();
00199 #ifdef _OFELI_DEBUG
00200 std::clog << "An instance of class EdgeVect is constructed.\n";
00201 std::clog << "File: " << __FILE__ << ", Line: " << __LINE__ << endl;
00202 #endif
00203 }
00204
00205
00206 template <class T_>
00207 EdgeVect<T_>::EdgeVect(const class Mesh &mesh, size_t nb_dof, const string &name, double time)
00208 : AbsVect<T_>(mesh,nb_dof,name,time)
00209 {
00210 if (nb_dof <= 0)
00211 _e.Message(__FILE__,__LINE__,31,_nb_dof);
00212 _nb_dof = nb_dof;
00213 _nb = _nb_edges = mesh.getNbEdges();
00214 _length = _nb_dof * _nb;
00215 Init();
00216 #ifdef _OFELI_DEBUG
00217 std::clog << "An instance of class EdgeVect is constructed.\n";
00218 std::clog << "File: " << __FILE__ << ", Line: " << __LINE__ << endl;
00219 #endif
00220 }
00221
00222
00223 template <class T_>
00224 EdgeVect<T_>::EdgeVect(const EdgeVect<T_> &v)
00225 {
00226 _time = v._time;
00227 _name = v._name;
00228 _length = v.getLength();
00229 _nb = _nb_edges = v.getNbEdges();
00230 _nbn = 1;
00231 _theMesh = v._theMesh;
00232 _first_dof = 1;
00233 _nb_dof = v._nb_dof;
00234 Init();
00235 _v = v._v;
00236 #ifdef _OFELI_DEBUG
00237 std::clog << "An instance of class EdgeVect is constructed.\n";
00238 std::clog << "File: " << __FILE__ << ", Line: " << __LINE__ << endl;
00239 #endif
00240 }
00241
00242
00243 template <class T_>
00244 EdgeVect<T_>::~EdgeVect()
00245 {
00246 #ifdef _OFELI_DEBUG
00247 std::clog << "An instance of class EdgeVect is destructed.\n";
00248 std::clog << "File: " << __FILE__ << ", Line: " << __LINE__ << endl;
00249 #endif
00250 }
00251
00252
00253 template <class T_>
00254 void EdgeVect<T_>::setMesh(class Mesh &ms, size_t nb_dof)
00255 {
00256 _theMesh = &ms;
00257 _first_dof = 1;
00258 _nbn = 1;
00259 _nb_dof = nb_dof;
00260 if (_nb_dof==0)
00261 _nb_dof = ms.getPtrEdge(1)->getNbDOF();
00262 _nb = _nb_edges = ms.getNbEdges();
00263 _length = _nb_dof * _nb_edges;
00264 Init();
00265 }
00266
00267
00268 template <class T_>
00269 size_t EdgeVect<T_>::getNbEdges() const
00270 {
00271 return _nb_edges;
00272 }
00273
00274
00275 template <class T_>
00276 EdgeVect<T_> & EdgeVect<T_>::operator=(T_ a)
00277 {
00278 for (size_t i=0; i<_length; ++i)
00279 _v[i] = a;
00280 return *this;
00281 }
00282
00283
00284 template <class T_>
00285 EdgeVect<T_> & EdgeVect<T_>::operator+=(const EdgeVect<T_> &x)
00286 {
00287 for (size_t i=0; i<_length; ++i)
00288 _v[i] += x[i];
00289 return *this;
00290 }
00291
00292
00293 template <class T_>
00294 EdgeVect<T_> & EdgeVect<T_>::operator+=(const T_ &a)
00295 {
00296 for (size_t i=0; i<_length; ++i)
00297 _v[i] += a;
00298 return *this;
00299 }
00300
00301
00302 template <class T_>
00303 EdgeVect<T_> & EdgeVect<T_>::operator-=(const EdgeVect<T_> &x)
00304 {
00305 for (size_t i=0; i<_length; ++i)
00306 _v[i] -= x[i];
00307 return *this;
00308 }
00309
00310
00311 template <class T_>
00312 EdgeVect<T_> & EdgeVect<T_>::operator-=(const T_ &a)
00313 {
00314 for (size_t i=0; i<_length; ++i)
00315 _v[i] -= a;
00316 return *this;
00317 }
00318
00319
00320 template <class T_>
00321 EdgeVect<T_> & EdgeVect<T_>::operator*=(const T_ &a)
00322 {
00323 for (size_t i=0; i<_length; ++i)
00324 _v[i] *= a;
00325 return *this;
00326 }
00327
00328
00329 template <class T_>
00330 EdgeVect<T_> & EdgeVect<T_>::operator/=(const T_ &a)
00331 {
00332 for (size_t i=0; i<_length; ++i)
00333 _v[i] /= a;
00334 return *this;
00335 }
00336
00337
00339
00341
00345 template <class T_>
00346 istream& operator>>(istream& s, EdgeVect<T_> &a)
00347 {
00348 size_t j, n;
00349 double time;
00350 static char name[40];
00351 s >> name;
00352 a.setName(name);
00353 s >> n >> time;
00354 a.setTime(time);
00355
00356 for (size_t i=1; i<=n; i++) {
00357 s >> j;
00358 for (size_t k=1; k<=a.NbDOF(); k++)
00359 s >> a(i,j) >> " ";
00360 }
00361 return s;
00362 }
00363
00364
00368 template <class T_>
00369 ostream& operator<<(ostream& s, const EdgeVect<T_> &a)
00370 {
00371 Edge *ed;
00372 if (a.getName())
00373 s << a.getName() << " at";
00374 s << " time = " << a.Time() << endl << endl;
00375 s.setf(ios::scientific);
00376 for (a.getMesh()->topEdge(); (ed=a.getMesh()->getEdge());) {
00377 size_t i = ed->getLabel();
00378 s << setw(6) << i << " ";
00379 for (size_t j=1; j<=a.getNbDOF(); j++)
00380 s << setprecision(8) << setw(18) << a(i,j);
00381 s << endl;
00382 }
00383 s << endl;
00384 return s;
00385 }
00386
00387 }
00388
00389 #endif