00001
00002
00003
00004 #ifndef vectorialThings_hh
00005 #define vectorialThings_hh
00006
00007 #include <memory>
00008 #include "basics/cloneable.hh"
00009 #include "toolbox/array.hh"
00010 #include "space/tmatrix.hh"
00011 #include "space/element.hh"
00012 #include "space/space.hh"
00013 #include "operator/bilinearForm.hh"
00014 #include "toolbox/scannerConnectors.hh"
00015 #include "vectorial/graphics.hh"
00016
00017
00018 #include "basics/debug.hh"
00019
00020 #define VectorialConstr_D 0
00021 #define VectorialPut_D 0
00022
00023 #define TMatrixOffsetConstr_D 0
00024
00025 #define TMatrixConstr_D 0
00026
00027 #define ElementConstr_D 0
00028
00029 #define BilinearFormConstr_D 0
00030
00031 #define LinearFormConstr_D 0
00032
00033 #define SpaceConstr_D 0
00034
00035 namespace concepts {
00036
00037 template<typename F>
00038 class ElementGraphics;
00039 }
00040
00041 namespace vectorial {
00042
00043 using concepts::Real;
00044
00045
00046
00051 template<class F>
00052 class Vectorial {
00053 public:
00058 Vectorial(uint vdim, uint arrayWidth) :
00059 vdim_(vdim), idx_(0), vdata_(arrayWidth, 0) {
00060 DEBUGL(VectorialConstr_D,
00061 "vdim = " << vdim_ << ", arraywidth = " << arrayWidth);
00062 }
00063 virtual ~Vectorial();
00065 virtual void put(F& vdata, const int a = 0, const int b = 0);
00067 virtual const F* get(const int a, const int b = 0) const
00068 { return vdata_[a]; }
00070 uint vdim() const { return vdim_; }
00071 protected:
00073 uint vdim_;
00075 uint idx_;
00077 concepts::Array<F*> vdata_;
00078 private:
00080 Vectorial(const Vectorial<F>& c);
00081 };
00082
00083 template<class F>
00084 Vectorial<F>::~Vectorial() {}
00085
00086 template<class F>
00087 void Vectorial<F>::put(F& vdata, int, int) {
00088 vdata_[idx_++] = &vdata;
00089 DEBUGL(VectorialConstr_D,"idx = " << idx_);
00090 }
00091
00092
00093
00094 template<class F>
00095 class TMatrix;
00096
00100 template<class F>
00101 class TMatrixOffset : public concepts::TMatrixBase<F> {
00102 friend class TMatrix<F>;
00103 public:
00104 TMatrixOffset(const concepts::TMatrixBase<F> &T, int offsetRow,
00105 int offsetColumn) :
00106 concepts::TMatrixBase<F>(0),
00107 offsetRow_(offsetRow), offsetColumn_(offsetColumn), T_(T) {
00108 DEBUGL(TMatrixOffsetConstr_D,
00109 "offsetRow = " << offsetRow_ << ", " <<
00110 "offsetColumn = " << offsetColumn_ << ", T = " << T_);
00111 }
00112 virtual ~TMatrixOffset();
00113 virtual void operator ()(const concepts::ElementMatrix<F>& A,
00114 concepts::ElementMatrix<F>& B) const
00115 { return T_(A,B); }
00116 virtual void operator ()
00117 (const concepts::ElementMatrix<std::complex<F> >& A,
00118 concepts::ElementMatrix<std::complex<F> >& B) const
00119 { return T_(A,B); }
00120
00122 virtual uint index(unsigned int i) const { return T_.index(i); }
00123
00124 inline uint m() const { return T_.m(); }
00125
00126 inline uint n() const { return T_.n(); }
00127
00128 virtual void usedIdx(concepts::TColumn<bool>& c) const {}
00129 virtual void extract(const concepts::Vector<F>& solution,
00130 concepts::Array<F>& coeff) const;
00131 virtual void extract(const concepts::Vector<std::complex<F> >& solution,
00132 concepts::Array<std::complex<F> >& coeff) const;
00133 protected:
00134 virtual std::ostream& info(std::ostream& os) const;
00135
00136 uint offsetRow_, offsetColumn_;
00137 const concepts::TMatrixBase<F> &T_;
00138 };
00139
00140
00141
00145 template<class F>
00146 class TMatrix : public concepts::TMatrixBase<F>,
00147 public Vectorial<vectorial::TMatrixOffset<F> > {
00148 public:
00149 TMatrix(uint vdim, uint arrayWidth = 0) :
00150 concepts::TMatrixBase<F>(0),
00151 Vectorial<vectorial::TMatrixOffset<F> >(vdim,vdim),
00152 offsetRow_(0), offsetColumn_(0) {
00153 DEBUGL(TMatrixConstr_D, "done.");
00154 }
00155 virtual ~TMatrix();
00156
00157 virtual void operator()(const concepts::ElementMatrix<F>& A,
00158 concepts::ElementMatrix<F>& B) const;
00159 virtual void operator()
00160 (const concepts::ElementMatrix<std::complex<F> >& A,
00161 concepts::ElementMatrix<std::complex<F> >& B) const;
00167 void put(const concepts::TMatrixBase<F> &T, const int dim);
00168
00170 virtual uint index(unsigned int i) const;
00171
00172
00173 virtual void usedIdx(concepts::TColumn<bool>& c) const {}
00181 virtual void extract(const concepts::Vector<F>& solution,
00182 concepts::Array<F>& coeff) const;
00183 virtual void extract(const concepts::Vector<std::complex<F> >& solution,
00184 concepts::Array<std::complex<F> >& coeff) const;
00185 protected:
00186 virtual std::ostream& info(std::ostream& os) const;
00187 private:
00188 uint offsetRow_, offsetColumn_;
00189 };
00190
00191
00192
00193
00194 template<class F>
00195 class Graphics;
00196
00200 template<class F>
00201 class Element : public concepts::Element<F>,
00202 public Vectorial<concepts::Element<F> > {
00203 public:
00204 Element(uint vdim, uint arrayWidth=0) :
00205 concepts::Element<F>(), Vectorial<concepts::Element<F> >(vdim, vdim),
00206 T_(new TMatrix<F>(vdim)) {
00207 DEBUGL(ElementConstr_D, "done.");
00208 }
00209 virtual ~Element();
00210
00215 virtual void put(concepts::Element<F>& em, const int dim, const int b = 0);
00216
00217 virtual vectorial::TMatrix<F>& T() const { return *T_; }
00218 virtual const Graphics<F>* graphics() const;
00219 static Graphics<F>* vecGraphics();
00220 protected:
00221 virtual std::ostream& info(std::ostream& os) const;
00222 private:
00224 std::auto_ptr<vectorial::TMatrix<F> > T_;
00225 static std::auto_ptr<Graphics<F> > graphics_;
00226 };
00227
00228
00229
00233 template<class F, class G = typename concepts::Realtype<F>::type>
00234 class BilinearForm : public concepts::BilinearForm<F,G>,
00235 public Vectorial<concepts::BilinearForm<F,G> > {
00236 public:
00241 BilinearForm(const uint vdim1, const uint vdim2 = 0) :
00242 Vectorial<concepts::BilinearForm<F,G> >(vdim1,
00243 vdim1*(vdim2 ? vdim2 : vdim1)),
00244 vdim2(vdim2 ? vdim2 : vdim1), deepCopies_(0)
00245 {
00246 DEBUGL(BilinearFormConstr_D, "done.");
00247 }
00249 BilinearForm(const BilinearForm& b);
00250 virtual ~BilinearForm();
00251 virtual BilinearForm* clone() const;
00252
00259 virtual void put(concepts::BilinearForm<F,G> &bf,const int i,const int j);
00264 void putStore(concepts::BilinearForm<F,G>* bf, const int i, const int j);
00265
00269 void putData(concepts::Cloneable* data) { sharedData_.reset(data); }
00270
00271 virtual void operator ()(const concepts::Element<G>& elmX,
00272 const concepts::Element<G>& elmY,
00273 concepts::ElementMatrix<F>& em);
00274 virtual void operator ()(const concepts::Element<G>& elmV,
00275 const concepts::Element<G>& elmU,
00276 concepts::ElementMatrix<F>& em,
00277 const concepts::ElementPair<G>& elmp);
00278
00280 uint vdim2;
00281 protected:
00282 virtual std::ostream& info(std::ostream& os) const;
00283 private:
00286 concepts::Array<std::auto_ptr<concepts::BilinearForm<F,G> > > deepCopies_;
00289 std::auto_ptr<concepts::Cloneable> sharedData_;
00290 };
00291
00292 }
00293
00294 namespace concepts {
00295
00296
00297
00298 template<class F>
00299 class Scan<vectorial::Element<F> > :
00300 public concepts::Scan<concepts::Element<F> > {
00301 public:
00302 virtual vectorial::Element<F>& operator++(int) = 0;
00303 };
00304
00305 }
00306
00307 namespace vectorial {
00308
00309
00310
00314 template<class F>
00315 class Space : public Vectorial<concepts::Space<F> >,
00316 public concepts::Space<F> {
00317 public:
00318 Space(const uint vdim, const uint arrayWidth=0)
00319 : Vectorial<concepts::Space<F> >(vdim,vdim)
00320 , dim_(0), nelm_(0), elm_(0)
00321 {
00322 DEBUGL(SpaceConstr_D, "done.");
00323 }
00324 virtual ~Space();
00325
00326 virtual uint dim() const { return dim_;}
00327 virtual uint nelm() const { return nelm_;}
00328 typedef concepts::Scan<vectorial::Element<F> > Scanner;
00329 virtual Scanner* scan() const;
00330
00334 virtual void put(concepts::Space<F> &spc,const int i=0,const int j=0);
00335
00337 void rebuild();
00338 protected:
00339 virtual std::ostream& info(std::ostream& os) const;
00340 private:
00341 uint dim_, nelm_;
00342 concepts::Joiner<Element<F>*, 1>* elm_;
00343 void buildElm_(const concepts::Space<F>& spc, uint idx);
00344 };
00345
00346
00347
00351 template<class F>
00352 class ElementPair
00353 : public concepts::ElementPair<F>,
00354 public Vectorial<concepts::ElementPair<F> > {
00355 public:
00356 ElementPair(const Element<F>& elm1, const Element<F>& elm2)
00357 : Vectorial<concepts::ElementPair<F> >(elm2.vdim(),
00358 elm1.vdim()*elm2.vdim()),
00359 elm1_(elm1), elm2_(elm2) { }
00360 virtual ~ElementPair() { }
00361 virtual void put(concepts::ElementPair<F>& ep,
00362 const int iV, const int iU);
00364 virtual const concepts::Element<F>& elm1() const;
00366 virtual const concepts::Element<F>& elm2() const;
00367 private:
00368 const Element<F>& elm1_;
00369 const Element<F>& elm2_;
00370 };
00371
00372 }
00373
00374 #endif // vectorialThings_hh