vectorial.hh

Go to the documentation of this file.
1 
6 #ifndef vectorialThings_hh
7 #define vectorialThings_hh
8 
9 #include <memory>
10 #include "basics/cloneable.hh"
11 #include "toolbox/array.hh"
13 #include "toolbox/sharedPointer.hh"
14 #include "space/tmatrix.hh"
15 #include "space/element.hh"
16 #include "space/space.hh"
17 #include "operator/bilinearForm.hh"
18 #include "vectorial/graphics.hh"
19 #include "geometry/integral.hh"
20 
21 // debugging
22 #include "basics/debug.hh"
23 
24 #define VectorialConstr_D 0
25 #define VectorialPut_D 0
26 
27 #define TMatrixOffsetConstr_D 0
28 
29 #define TMatrixConstr_D 0
30 
31 #define ElementConstr_D 0
32 
33 #define BilinearFormConstr_D 0
34 
35 #define LinearFormConstr_D 0
36 
37 #define SpaceConstr_D 0
38 
39 namespace concepts {
40  // forward declaration
41  template<typename F>
42  class ElementGraphics;
43 
44  template<typename F, typename G>
45  class ElementFunction;
46 }
47 
48 namespace vectorial {
49 
50  using concepts::Real;
51 
52  // ************************************************************* Vectorial **
53 
58  template<class F>
59  class Vectorial {
60  public:
65  Vectorial(uint vdim, uint arrayWidth) :
66  vdim_(vdim), idx_(0), vdata_(arrayWidth, 0) {
68  "vdim = " << vdim_ << ", arraywidth = " << arrayWidth);
69  }
70  virtual ~Vectorial();
72  virtual void insert(F& vdata, const int a = 0, const int b = 0);
74  virtual const F* get(const int a, const int b = 0) const
75  { return vdata_[a]; }
77  uint vdim() const { return vdim_; }
78  protected:
80  uint vdim_;
82  uint idx_;
85  private:
88  };
89 
90  template<class F>
92 
93  template<class F>
94  void Vectorial<F>::insert(F& vdata, int, int) {
95  vdata_[idx_++] = &vdata;
96  DEBUGL(VectorialConstr_D, "idx = " << idx_);
97  }
98 
99  // ********************************************************* TMatrixOffset **
100 
101  template<class F>
102  class TMatrix;
103 
107  template<class F>
109  friend class TMatrix<F>;
110  public:
111  TMatrixOffset(const concepts::TMatrixBase<F> &T, int offsetRow,
112  int offsetColumn) :
113  concepts::TMatrixBase<F>(0),
114  offsetRow_(offsetRow), offsetColumn_(offsetColumn), T_(T) {
116  "offsetRow = " << offsetRow_ << ", " <<
117  "offsetColumn = " << offsetColumn_ << ", T = " << T_);
118  }
119  virtual ~TMatrixOffset();
122  { return T_(A,B); }
123  virtual void operator ()
126  { return T_(A,B); }
127 
129  virtual uint index(unsigned int i) const { return T_.index(i); }
130 
131  inline uint m() const { return T_.m(); }
132 
133  inline uint n() const { return T_.n(); }
134 
135  virtual void usedIdx(concepts::TColumn<bool>& c) const {}
136  virtual void extract(const concepts::Vector<F>& solution,
137  concepts::Array<F>& coeff) const;
138  virtual void extract(const concepts::Vector<std::complex<F> >& solution,
139  concepts::Array<std::complex<F> >& coeff) const;
140  protected:
141  virtual std::ostream& info(std::ostream& os) const;
142  //private:
145  };
146 
147  // *************************************************************** TMatrix **
148 
152  template<class F>
153  class TMatrix : public concepts::TMatrixBase<F>,
154  public Vectorial<TMatrixOffset<F> > {
155  public:
156  TMatrix(uint vdim, uint arrayWidth = 0) :
157  concepts::TMatrixBase<F>(0),
158  Vectorial<TMatrixOffset<F> >(vdim,vdim),
159  offsetRow_(0), offsetColumn_(0) {
160  DEBUGL(TMatrixConstr_D, "done.");
161  }
162  virtual ~TMatrix();
163 
164  virtual void operator()(const concepts::ElementMatrix<F>& A,
165  concepts::ElementMatrix<F>& B) const;
166  virtual void operator()
174  void put(const concepts::TMatrixBase<F> &T, const int dim);
175 
177  virtual uint index(unsigned int i) const;
178 
179  // not needed in Vectorial problems
180  virtual void usedIdx(concepts::TColumn<bool>& c) const {}
188  virtual void extract(const concepts::Vector<F>& solution,
189  concepts::Array<F>& coeff) const;
190  virtual void extract(const concepts::Vector<std::complex<F> >& solution,
191  concepts::Array<std::complex<F> >& coeff) const;
192  protected:
193  virtual std::ostream& info(std::ostream& os) const;
194  private:
196  };
197 
198 
199  // ******************************************************* ElementNotBuilt **
200 
210 
211 
212  // *********************************************************** ElementBase **
213 
214  // forward declaration
215  template<class F>
216  class Graphics;
217 
223  template<class ElementType>
224  class ElementBase : public Vectorial<ElementType>,
225  public ElementType {
226  public:
227  typedef typename ElementType::type F;
228 
229  ElementBase(uint vdim, uint arrayWidth, std::string name = "ElementBase") :
230  Vectorial<ElementType>(vdim, vdim), ElementType(),
231  T_(new TMatrix<F>(vdim)), name_(name) {
232  DEBUGL(ElementConstr_D, "done.");
233  }
234  virtual ~ElementBase();
235 
240  virtual void put(ElementType& em, const int dim, const int b = 0);
241 
242  virtual vectorial::TMatrix<F>& T() const { return *T_; }
243  virtual const Graphics<F>* graphics() const {
244  if (! graphics_.get())
245  graphics_.reset(new Graphics<F>());
246  return graphics_.get();
247  }
249  if (! graphics_.get())
250  graphics_.reset(new Graphics<F>());
251  return graphics_.get();
252  }
253  protected:
254  virtual std::ostream& info(std::ostream& os) const;
256  std::unique_ptr<vectorial::TMatrix<F> > T_;
257  private:
258  static std::unique_ptr<Graphics<F> > graphics_;
260  std::string name_;
261  };
262 
263  // *************************************************************** Element **
264 
269  template<class F>
270  class Element : public ElementBase<concepts::Element<F> > {
271  public:
272  Element(uint vdim, uint arrayWidth=0) :
273  ElementBase<concepts::Element<F> >(vdim, arrayWidth,
274  "vectorial::Element") {}
275  virtual ~Element();
276  };
277 
278  // ******************************************************* ElementWithCell **
279 
284  template<class F>
285  class ElementWithCell : public ElementBase<concepts::ElementWithCell<F> >,
287  public:
288  ElementWithCell(uint vdim, uint arrayWidth=0) :
289  ElementBase<concepts::ElementWithCell<F> >(vdim, arrayWidth,
290  "vectorial::ElementWithCell"),
291  cell_(0), intCell_(0) {}
292  virtual ~ElementWithCell();
293 
299  const int dim, const int b = 0);
300 
301  virtual bool quadraturePoint(uint i, intPoint &p, intFormType form,
302  bool localCoord) const;
303 
305  virtual const concepts::Cell& cell() const;
306  private:
309  };
310 
311  // ********************************************************** BilinearForm **
312 
316  template<class F, class G = typename concepts::Realtype<F>::type>
317  class BilinearForm : public concepts::BilinearForm<F,G>,
318  public Vectorial<concepts::BilinearForm<F,G> > {
319  public:
324  BilinearForm(const uint vdim1, const uint vdim2 = 0) :
325  Vectorial<concepts::BilinearForm<F,G> >(vdim1,
326  vdim1*(vdim2 ? vdim2 : vdim1)),
327  vdim2(vdim2 ? vdim2 : vdim1), deepCopies_(0)
328  {
329  DEBUGL(BilinearFormConstr_D, "done.");
330  }
333  virtual ~BilinearForm();
334  virtual BilinearForm* clone() const;
335 
342  virtual void put(concepts::BilinearForm<F,G> &bf, const int i, const int j);
347  void putStore(concepts::BilinearForm<F,G>* bf, const int i, const int j);
349  const int i, const int j);
350 
354  void putData(concepts::Cloneable* data) { sharedData_.reset(data); }
355 
358 
359  virtual void operator ()(const concepts::Element<G>& elmX,
360  const concepts::Element<G>& elmY,
361  concepts::ElementMatrix<F>& em) const;
362  virtual void operator ()(const concepts::Element<G>& elmV,
363  const concepts::Element<G>& elmU,
365  const concepts::ElementPair<G>& elmp) const;
366 
368  uint vdim2;
369  protected:
370  virtual std::ostream& info(std::ostream& os) const;
371  private:
377  std::unique_ptr<concepts::Cloneable> sharedData_;
378  };
379 
380 } // namespace vectorial
381 
382 namespace concepts {
383 
384  // ****************************************************************** Scan **
385 
386  template<class F>
387  class Scan<vectorial::Element<F> > :
388  public concepts::Scan<concepts::Element<F> > {
389  public:
391  };
392 
393  template<class F>
395  public concepts::Scan<concepts::ElementWithCell<F> > {
396  public:
398  };
399 
400 } // namespace concepts
401 
402 namespace vectorial {
403 
404  template<class F>
406 
407  template<class F>
409  public:
410  typedef Element<F> type;
411  };
412 
413  template<class F>
415  public:
417  };
418 
419  // ***************************************************************** SpaceBase **
420 
425  template<class SpaceType>
426  class SpaceBase : public SpaceType,
427  public Vectorial<SpaceType> {
428  public:
429  typedef
431 
432  SpaceBase(const uint vdim, const uint arrayWidth = 0,
433  std::string name = "SpaceBase")
434  : SpaceType()
435  , Vectorial<SpaceType>(vdim, vdim)
436  , dim_(0), nelm_(0), elm_(0), name_(name)
437  {
438  DEBUGL(SpaceConstr_D, "done.");
439  }
440  SpaceBase(const SpaceBase & spcb)
441  : Vectorial<SpaceType>(spcb.vdim(), spcb.vdim())
442  , dim_(spcb.dim_) , nelm_(spcb.nelm_)
443  , elm_(spcb.elm_) , name_(spcb.name_)
444  {
445  }
446 
447  virtual ~SpaceBase();
448 
449  virtual uint dim() const { return dim_; }
450  virtual uint nelm() const { return nelm_; }
452  virtual Scanner* scan() const;
453 
457  virtual void put(SpaceType &spc, const int i = 0, const int j = 0);
458 
460  void rebuild();
461  protected:
462  virtual std::ostream& info(std::ostream& os) const;
463  private:
464  uint dim_, nelm_;
467  std::string name_;
468  void buildElm_(const SpaceType& spc, uint idx);
469  };
470 
471  // ***************************************************************** Space **
472 
477  template<class F>
478  class Space : public SpaceBase<concepts::Space<F> > {
479  public:
480  Space(const uint vdim, const uint arrayWidth=0)
481  : SpaceBase<concepts::Space<F> >(vdim, arrayWidth, "Space") {}
482  virtual ~Space();
483  };
484 
485  // ********************************************************** SpaceOnCells **
486 
491  template<class F>
492  class SpaceOnCells : public SpaceBase<concepts::SpaceOnCells<F> > {
493  public:
494  SpaceOnCells(const uint vdim, const uint arrayWidth=0)
495  : SpaceBase<concepts::SpaceOnCells<F> >(vdim, arrayWidth, "SpaceOnCells") {}
496  virtual ~SpaceOnCells();
497  };
498 
499  // *********************************************************** ElementPair **
500 
504  template<class F>
505  class ElementPair
506  : public concepts::ElementPair<F>,
507  public Vectorial<concepts::ElementPair<F> > {
508  public:
511  elm1.vdim()*elm2.vdim()),
512  elm1_(elm1), elm2_(elm2) { }
513  virtual ~ElementPair() { }
514  virtual void put(concepts::ElementPair<F>& ep,
515  const int iV, const int iU);
517  virtual const concepts::Element<F>& elm1() const;
519  virtual const concepts::Element<F>& elm2() const;
520  private:
523  };
524 
525 } // namespace vectorial
526 
527 #endif // vectorialThings_hh
BilinearForm(const BilinearForm &b)
Copy constructor. This copy constructor performs a deep copy of b.
virtual uint dim() const
Definition: vectorial.hh:449
TMatrix(uint vdim, uint arrayWidth=0)
Definition: vectorial.hh:156
virtual void put(concepts::ElementWithCell< F > &em, const int dim, const int b=0)
Insert element em into the vector valued element.
Vectorial(uint vdim, uint arrayWidth)
Constructor.
Definition: vectorial.hh:65
#define TMatrixConstr_D
Definition: vectorial.hh:29
Gives access to a pair of elements.
Definition: elementPairs.hh:25
virtual ~Space()
concepts::Scan< ElementType > Scanner
Definition: vectorial.hh:451
Integration point consisting of coordinates and intermediate data.
Definition: integral.hh:34
#define TMatrixOffsetConstr_D
Definition: vectorial.hh:27
virtual std::ostream & info(std::ostream &os) const
virtual void extract(const concepts::Vector< F > &solution, concepts::Array< F > &coeff) const
Extracts the part of solution belonging to this T matrix into coeff.
Vector valued space.
Definition: spaceTraits.hh:26
Vector valued problems.
Definition: spaceTraits.hh:24
Vector valued space with elements on cells.
Definition: vectorial.hh:492
Base class for exceptions.
Definition: exceptions.hh:86
Vector valued bilinear form.
Definition: bf_advection.hh:38
concepts::Joiner< ElementType *, 1 > * elm_
Definition: vectorial.hh:465
virtual void usedIdx(concepts::TColumn< bool > &c) const
Marks the used local indices in c with true, the local indices which are not set to false.
Definition: vectorial.hh:135
A cell in a mesh consist of topological information (neighbours, connectivity, orientation) and geome...
Definition: cell.hh:39
intFormType
Integration form, which determines terms coming from integration over reference element.
Definition: integral.hh:29
virtual vectorial::Element< F > & operator++(int)=0
Returns the next element in the scanned set.
virtual uint nelm() const
Definition: vectorial.hh:450
virtual const Graphics< F > * graphics() const
Definition: vectorial.hh:243
Space(const uint vdim, const uint arrayWidth=0)
Definition: vectorial.hh:480
virtual void put(SpaceType &spc, const int i=0, const int j=0)
Insert a Space spc of one vectorial dimension to the next v-dimensional space (arguments i and j are ...
virtual void extract(const concepts::Vector< F > &solution, concepts::Array< F > &coeff) const
Extracts a part of solution according to this T matrix into coeff.
uint vdim() const
Returns number of components.
Definition: vectorial.hh:77
SpaceBase(const uint vdim, const uint arrayWidth=0, std::string name="SpaceBase")
Definition: vectorial.hh:432
virtual const concepts::Cell & cell() const
Returns the cell on which the element is built.
virtual ~Vectorial()
Definition: vectorial.hh:91
ElementWithCell(uint vdim, uint arrayWidth=0)
Definition: vectorial.hh:288
virtual uint index(unsigned int i) const
Maps the local index i to the global index.
virtual const concepts::Element< F > & elm2() const
Returns reference to the second element.
void putStore(concepts::RCP< concepts::BilinearForm< F, G > > bf, const int i, const int j)
virtual std::ostream & info(std::ostream &os) const
virtual std::ostream & info(std::ostream &os) const
ElementType::type F
Definition: vectorial.hh:227
BilinearForm(const uint vdim1, const uint vdim2=0)
Constructor.
Definition: vectorial.hh:324
uint vdim2
vectorial dimension of second argument of bilinear form
Definition: vectorial.hh:368
SpaceOnCells(const uint vdim, const uint arrayWidth=0)
Definition: vectorial.hh:494
ElementBase(uint vdim, uint arrayWidth, std::string name="ElementBase")
Definition: vectorial.hh:229
Element with cell.
#define DEBUGL(doit, msg)
Vectorial(const Vectorial< F > &c)
Private copy constructor, forbids copying.
Abstract function class to evaluate a bilinear form.
Definition: bilinearForm.hh:33
T matrix with an offset.
Definition: vectorial.hh:108
Base class for vector valued element.
Definition: vectorial.hh:225
virtual const concepts::Element< F > & elm1() const
Returns reference to the first element.
concepts::Array< F * > vdata_
Storage.
Definition: vectorial.hh:84
Vector valued element pair.
Definition: vectorial.hh:507
virtual vectorial::ElementWithCell< F > & operator++(int)=0
Returns the next element in the scanned set.
BilinearForm< F, G > & reset()
Clear the stores bilinear forms and the shared data.
Base class for most classes which do vector valued problems.
Definition: vectorial.hh:59
std::string name_
Name of the class for output.
Definition: vectorial.hh:467
TMatrixOffset(const concepts::TMatrixBase< F > &T, int offsetRow, int offsetColumn)
Definition: vectorial.hh:111
Cloneable interface.
Definition: cloneable.hh:16
virtual void put(concepts::BilinearForm< F, G > &bf, const int i, const int j)
insert a Bilinearform bf of one vectorial dimension to the all v-dimensionial Bilinearform
uint vdim_
Number of components.
Definition: vectorial.hh:80
An abstract class for scanning a mesh (a set of cells) or a space (a set of elements).
#define BilinearFormConstr_D
Definition: vectorial.hh:33
virtual BilinearForm * clone() const
std::unique_ptr< concepts::Cloneable > sharedData_
Stores the data which is shared between the components of the bilinear forms.
Definition: vectorial.hh:377
void put(const concepts::TMatrixBase< F > &T, const int dim)
Insert a T-Matrix T (of type TMatrixOffset) of one vectorial dimension to the v-dimensionial T-Matrix...
virtual void extract(const concepts::Vector< std::complex< F > > &solution, concepts::Array< std::complex< F > > &coeff) const
const Element< F > & elm1_
Definition: vectorial.hh:521
virtual void operator()(const concepts::Element< G > &elmX, const concepts::Element< G > &elmY, concepts::ElementMatrix< F > &em) const
virtual void extract(const concepts::Vector< std::complex< F > > &solution, concepts::Array< std::complex< F > > &coeff) const
Element(uint vdim, uint arrayWidth=0)
Definition: vectorial.hh:272
Vector valued element with a cell.
Definition: vectorial.hh:286
#define VectorialConstr_D
Definition: vectorial.hh:24
Reference-counting pointer.
Definition: bf_iddiv.hh:15
virtual void insert(F &vdata, const int a=0, const int b=0)
Add a component.
Definition: vectorial.hh:94
Cell over which can be integrated.
Definition: integral.hh:24
virtual Scanner * scan() const
An abstract class for a T matrix.
Definition: element.hh:37
const concepts::TMatrixBase< F > & T_
Definition: vectorial.hh:144
SpaceBase(const SpaceBase &spcb)
Definition: vectorial.hh:440
void buildElm_(const SpaceType &spc, uint idx)
concepts::Array< concepts::RCP< concepts::BilinearForm< F, G > > > deepCopies_
Stores the deep copies of the component bilinear forms, if there are any.
Definition: vectorial.hh:374
virtual vectorial::TMatrix< F > & T() const
Definition: vectorial.hh:242
virtual bool quadraturePoint(uint i, intPoint &p, intFormType form, bool localCoord) const
Delivers a quadrature point.
static std::unique_ptr< Graphics< F > > graphics_
Definition: vectorial.hh:258
std::unique_ptr< vectorial::TMatrix< F > > T_
T matrix for the vector valued element.
Definition: vectorial.hh:256
Element matrix.
Definition: linearForm.hh:18
ElementPair(const Element< F > &elm1, const Element< F > &elm2)
Definition: vectorial.hh:509
Handles graphics for vector valued elements.
Definition: graphics.hh:19
VectorialElementType< typename SpaceType::type >::type ElementType
Definition: vectorial.hh:430
Indicates that the vectorial element is not yet built, there is no (scalar) element inside yet.
Definition: vectorial.hh:209
virtual std::ostream & info(std::ostream &os) const
const Element< F > & elm2_
Definition: vectorial.hh:522
Base class for vector valued space.
Definition: vectorial.hh:427
virtual uint index(unsigned int i) const
Maps the local index i to the global index.
Definition: vectorial.hh:129
const concepts::Cell * cell_
Definition: vectorial.hh:307
void putData(concepts::Cloneable *data)
Stores data in sharedData_ (this includes destruction of sharedData_ at cleanup).
Definition: vectorial.hh:354
#define SpaceConstr_D
Definition: vectorial.hh:37
virtual void operator()(const concepts::ElementMatrix< F > &A, concepts::ElementMatrix< F > &B) const
Application operator.
Definition: vectorial.hh:120
std::string name_
Name of the class for output.
Definition: vectorial.hh:260
const concepts::IntegrationCell * intCell_
Definition: vectorial.hh:308
void putStore(concepts::BilinearForm< F, G > *bf, const int i, const int j)
Acts similarly to the normal put() command, but stores bf in deepCopies_ (without cloning bf first).
virtual void operator()(const concepts::ElementMatrix< F > &A, concepts::ElementMatrix< F > &B) const
void rebuild()
Rebuilds the vectorial space from the scalar spaces.
virtual void put(ElementType &em, const int dim, const int b=0)
Insert element em into the vector valued element.
virtual void put(concepts::ElementPair< F > &ep, const int iV, const int iU)
virtual std::ostream & info(std::ostream &os) const
virtual const F * get(const int a, const int b=0) const
Get a component.
Definition: vectorial.hh:74
TMatrixBase(const uint n)
Constructor.
uint idx_
Index of the last added component.
Definition: vectorial.hh:82
#define ElementConstr_D
Definition: vectorial.hh:31
double Real
Type normally used for a floating point number.
Definition: typedefs.hh:36
virtual void usedIdx(concepts::TColumn< bool > &c) const
Definition: vectorial.hh:180
Vector valued T matrix.
Definition: vectorial.hh:102
Basic namespace for Concepts-2.
Definition: pml_formula.h:16
Vector valued element.
Definition: vectorial.hh:270
static Graphics< F > * vecGraphics()
Definition: vectorial.hh:248
Page URL: http://wiki.math.ethz.ch/bin/view/Concepts/WebHome
21 August 2020
© 2020 Eidgenössische Technische Hochschule Zürich