mesh_p.hh

Go to the documentation of this file.
1 
7 #ifndef mesh_p_hh
8 #define mesh_p_hh
9 
10 #include <memory>
11 
12 #include "basics/exceptions.hh"
13 #include "basics/outputOperator.hh"
14 #include "geometry/elementMaps.hh"
16 #include "geometry/mesh.hh"
17 #include "toolbox_p/using_p.hh"
19 
20 namespace concepts {
21 
22  // ******************************************* Scanners **
23 
25  template <>
26  class Scan<Connector0> :
27  public Scan<Connector> {
28  public:
31  };
32 
34  template <>
35  class Scan<Connector1> :
36  public Scan<Connector> {
37  public:
40  };
41 
43  template <>
44  class Scan<Connector2> :
45  public Scan<Connector> {
46  public:
49  };
50 
54 
55 } // namespace concepts
56 
57 
58 
59 namespace parallel {
60 
61  // ********************************************** Lists **
62 
65  template<class T>
66  class ListElm {
67  private:
68  ListElm<T>* lnk_;
69  T* elm_;
70 
71  public:
72  inline ListElm(T* elm, ListElm<T>* lnk = 0) : lnk_(lnk), elm_(elm) {};
73 
74  inline ListElm<T>** linkp() {return &lnk_;};
75  inline ListElm<T>* link() const {return lnk_;};
76  inline T* elm() const {return elm_;}
77  };
78 
81  template<class ListNode>
82  class ListHead : public concepts::OutputOperator {
83  private:
84  ListNode* root_;
85 
86  public:
87  inline ListHead(ListNode* root = 0) : root_(root) {};
88  inline ~ListHead() {
89  while (root_)
90  {ListNode* foo = root_; root_ = root_->link(); delete foo;}
91  };
92 
93  inline ListNode** rootp() {return &root_;};
94  inline ListNode* root() const {return root_;};
95  };
96 
97  typedef ListElm<Connector0> Cntr0LstEl;
98  typedef ListElm<Connector1> Cntr1LstEl;
99  typedef ListElm<Connector2> Cntr2LstEl;
100  typedef ListElm<Cell1> Cell1LstEl;
101  typedef ListElm<Cell2> Cell2LstEl;
102  typedef ListElm<Cell3> Cell3LstEl;
103 
104  typedef ListHead<Cntr0LstEl> Cntr0Lst;
105  typedef ListHead<Cntr1LstEl> Cntr1Lst;
106  typedef ListHead<Cntr2LstEl> Cntr2Lst;
107  typedef ListHead<Cell1LstEl> Cell1Lst;
108  typedef ListHead<Cell2LstEl> Cell2Lst;
109  typedef ListHead<Cell3LstEl> Cell3Lst;
110 
111 
112 
113  // *********************************************** Mesh **
114 
122  class Mesh : public concepts::OutputOperator {
123  private:
124  const Communicator& com_;
125  public:
126  Mesh(const Communicator& com) : com_(com) {};
127  virtual ~Mesh() {};
128 
129  inline const Communicator& comm() const {return com_;};
130 
132  virtual uint nglobcell() const = 0;
133 
135  virtual uint nloccell() const = 0;
136 
141  virtual Scan<Cell>* globscan() = 0;
142 
147  virtual Scan<Cell>* locscan() = 0;
148 
149  protected:
150  virtual std::ostream& info(std::ostream& os) const;
151  };
152 
153 
154  // ********************************************** Mesh1 **
155 
158  class Mesh1 : public Mesh {
159  private:
161  class LocalS : public Scan<Cell1> {
162  uint n_;
163  uint idx_;
164  Array<unique_ptr<Cell1> > *cell_;
165  public:
166  inline LocalS(uint n, Array<unique_ptr<Cell1> > *cell)
167  : n_(n), idx_(0), cell_(cell) {};
168  inline LocalS(const LocalS& scan) : n_(scan.n_), idx_(scan.idx_),
169  cell_(scan.cell_) {};
170  inline bool eos() const {return idx_ == n_;};
171  inline Cell1& operator++(int) {return *((*cell_)[idx_++]);};
172  inline concepts::Scan1* clone() const {return new LocalS(*this);};
173  };
174 
176  class GlobalS : public Scan<Cell1> {
177  uint n_;
178  uint idx_;
179  Array<unique_ptr<Cell1> > *cell_;
180  public:
181  inline GlobalS(uint n, Array<unique_ptr<Cell1> > *cell)
182  : n_(n), idx_(0), cell_(cell) {
183  throw conceptsException(MissingFeature("GlobalS not yet implemented"));
184  };
185  inline GlobalS(const GlobalS& scan) {
186  throw conceptsException(MissingFeature("GlobalS not yet implemented"));
187  };
188  inline bool eos() const {return 1;};
189  inline Cell1& operator++(int) {return *((*cell_)[idx_++]);};
190  inline concepts::Scan1* clone() const {return new GlobalS(*this);};
191  };
192 
194  template<class T>
195  class CapS : public Scan<T> {
196  private:
197  ListElm<T>* cntr_;
198  public:
199  inline CapS(ListElm<T>* cntr) : cntr_(cntr) {};
200  inline CapS(const CapS<T>& scan) : cntr_(scan.cntr_) {};
201  inline bool eos() const {return (!cntr_);};
202  inline T& operator++(int) {
203  ListElm<T>* foo = cntr_; cntr_ = cntr_->link();
204  return *(foo->elm());};
205  inline Scan<T>* clone() const {return new CapS(*this);};
206  };
207 
209  uint ngcell_;
211  uint nlcell_;
212 
214  Array<unique_ptr<Connector0> >* cntr0_;
215  uint ncntr0_;
216 
218  Array<unique_ptr<Connector1> >* cntr1_;
220  Array<unique_ptr<Cell1> >* cell_;
221 
223  Array<unique_ptr<concepts::Map1d> >* map_;
224  uint nmap_;
225 
227  Array<Cntr0Lst>* cap0_;
229  Array<Cell1Lst>* cap1_;
230 
231  public:
250  inline Mesh1(Array<unique_ptr<Connector0> >* cntr0,
251  Array<unique_ptr<Connector1> >* cntr1,
252  Array<unique_ptr<Cell1> >* cell, uint ngcell,
253  Array<unique_ptr<concepts::Map1d> >* map,
254  Array<Cntr0Lst>* cap0, Array<Cell1Lst>* cap1,
255  const Communicator& com);
256  inline ~Mesh1();
257 
259  inline uint nglobcell() const {return ngcell_;};
261  inline uint nloccell() const {return nlcell_;};
262 
264  inline concepts::Scan1* globscan() {return new GlobalS(nlcell_, cell_);};
265 
267  inline concepts::Scan1* locscan() {return new LocalS(nlcell_, cell_);};
268 
272  inline concepts::ScanCntr0* cap0scan(uint i) {
273  return new CapS<Connector0>((*cap0_)[i].root());
274  };
278  inline concepts::Scan1* cap1scan(uint i) {
279  return new CapS<Cell1>((*cap1_)[i].root());
280  };
281 
282  protected:
283  std::ostream& info(std::ostream& os) const;
284  };
285 
286 
287  Mesh1::Mesh1(Array<unique_ptr<Connector0> >* cntr0,
288  Array<unique_ptr<Connector1> >* cntr1,
289  Array<unique_ptr<Cell1> >* cell, uint ngcell,
290  Array<unique_ptr<concepts::Map1d> >* map,
291  Array<Cntr0Lst>* cap0, Array<Cell1Lst>* cap1,
292  const Communicator& com)
293  : Mesh(com), ngcell_(ngcell), nlcell_(cell->cursize()), cntr0_(cntr0),
294  ncntr0_(cntr0->cursize()), cntr1_(cntr1), cell_(cell), map_(map),
295  nmap_(map ? map->cursize() : 0), cap0_(cap0), cap1_(cap1) {
296  }
297 
298  Mesh1::~Mesh1() {
299  delete cap0_;
300  delete cap1_;
301  delete cell_; delete map_;
302  delete cntr1_; delete cntr0_;
303  }
304 
305 
306  // ********************************************** Mesh2 **
307 
310  class Mesh2 : public Mesh {
311  private:
313  class LocalS : public Scan<Cell2> {
314  uint n_;
315  uint idx_;
316  Array<unique_ptr<Cell2> > *cell_;
317  public:
318  inline LocalS(uint n, Array<unique_ptr<Cell2> > *cell)
319  : n_(n), idx_(0), cell_(cell) {};
320  inline LocalS(const LocalS& scan) : n_(scan.n_), idx_(scan.idx_),
321  cell_(scan.cell_) {};
322  inline bool eos() const {return idx_ == n_;};
323  inline Cell2& operator++(int) {return *((*cell_)[idx_++]);};
324  inline concepts::Scan2* clone() const {return new LocalS(*this);};
325  };
326 
328  class GlobalS : public Scan<Cell2> {
329  uint n_;
330  uint idx_;
331  Array<unique_ptr<Cell2> > *cell_;
332  public:
333  inline GlobalS(uint n, Array<unique_ptr<Cell2> > *cell)
334  : n_(n), idx_(0), cell_(cell) {
335  throw conceptsException(MissingFeature("GlobalS not yet implemented"));
336  };
337  inline GlobalS(const GlobalS& scan) {
338  throw conceptsException(MissingFeature("GlobalS not yet implemented"));
339  };
340  inline bool eos() const {return 1;};
341  inline Cell2& operator++(int) {return *((*cell_)[idx_++]);};
342  inline concepts::Scan2* clone() const {return new GlobalS(*this);};
343  };
344 
346  template<class T>
347  class CapS : public Scan<T> {
348  private:
349  ListElm<T>* cntr_;
350  public:
351  inline CapS(ListElm<T>* cntr) : cntr_(cntr) {};
352  inline CapS(const CapS<T>& scan) : cntr_(scan.cntr_) {};
353  inline bool eos() const {return (!cntr_);};
354  inline T& operator++(int) {
355  ListElm<T>* foo = cntr_; cntr_ = cntr_->link();
356  return *(foo->elm());};
357  inline Scan<T>* clone() const {return new CapS(*this);};
358  };
359 
360 
362  uint ngcell_;
364  uint nlcell_;
365 
367  Array<unique_ptr<Connector0> >* cntr0_;
368  uint ncntr0_;
370  Array<unique_ptr<Connector1> >* cntr1_;
371  uint ncntr1_;
372 
374  Array<unique_ptr<Connector2> >* cntr2_;
376  Array<unique_ptr<Cell2> >* cell_;
377 
379  Array<unique_ptr<concepts::Map2d> >* map_;
380  uint nmap_;
381 
383  Array<Cntr0Lst>* cap0_;
385  Array<Cntr1Lst>* cap1_;
387  Array<Cell2Lst>* cap2_;
388 
389  public:
414  inline Mesh2(Array<unique_ptr<Connector0> >* cntr0,
415  Array<unique_ptr<Connector1> >* cntr1,
416  Array<unique_ptr<Connector2> >* cntr2,
417  Array<unique_ptr<Cell2> >* cell, uint ngcell,
418  Array<unique_ptr<concepts::Map2d> >* map,
419  Array<Cntr0Lst>* cap0, Array<Cntr1Lst>* cap1,
420  Array<Cell2Lst>* cap2, const Communicator& com);
421  inline ~Mesh2();
422 
424  inline uint nglobcell() const {return ngcell_;};
426  inline uint nloccell() const {return nlcell_;};
427 
429  inline concepts::Scan2* globscan() {return new GlobalS(nlcell_, cell_);};
430 
432  inline concepts::Scan2* locscan() {return new LocalS(nlcell_, cell_);};
433 
437  inline concepts::ScanCntr0* cap0scan(uint i) {
438  return new CapS<Connector0>((*cap0_)[i].root());
439  };
443  inline concepts::ScanCntr1* cap1scan(uint i) {
444  return new CapS<Connector1>((*cap1_)[i].root());
445  };
449  inline concepts::Scan2* cap2scan(uint i) {
450  return new CapS<Cell2>((*cap2_)[i].root());
451  };
452 
453  protected:
454  std::ostream& info(std::ostream& os) const;
455  };
456 
457 
458  Mesh2::Mesh2(Array<unique_ptr<Connector0> >* cntr0,
459  Array<unique_ptr<Connector1> >* cntr1,
460  Array<unique_ptr<Connector2> >* cntr2,
461  Array<unique_ptr<Cell2> >* cell, uint ngcell,
462  Array<unique_ptr<concepts::Map2d> >* map,
463  Array<Cntr0Lst>* cap0, Array<Cntr1Lst>* cap1,
464  Array<Cell2Lst>* cap2, const Communicator& com)
465  : Mesh(com), ngcell_(ngcell), nlcell_(cell->cursize()), cntr0_(cntr0),
466  ncntr0_(cntr0->cursize()), cntr1_(cntr1), ncntr1_(cntr1->cursize()),
467  cntr2_(cntr2), cell_(cell), map_(map), nmap_(map ? map->cursize() : 0),
468  cap0_(cap0), cap1_(cap1), cap2_(cap2) {
469  }
470 
471  Mesh2::~Mesh2() {
472  delete cap2_; delete cap1_; delete cap0_;
473  delete cell_; delete map_;
474  delete cntr2_; delete cntr1_; delete cntr0_;
475  }
476 
477 
478  // ********************************************** Mesh3 **
479 
482  class Mesh3 : public Mesh {
483  private:
485  class LocalS : public concepts::Scan<Cell3> {
486  uint n_;
487  uint idx_;
488  Array<unique_ptr<Cell3> > *cell_;
489  public:
490  inline LocalS(uint n, Array<unique_ptr<Cell3> > *cell)
491  : n_(n), idx_(0), cell_(cell) {};
492  inline LocalS(const LocalS& scan) : n_(scan.n_), idx_(scan.idx_),
493  cell_(scan.cell_) {};
494  inline bool eos() const {return idx_ == n_;};
495  inline Cell3& operator++(int) {return *((*cell_)[idx_++]);};
496  inline concepts::Scan3* clone() const {return new LocalS(*this);};
497  };
498 
500  class GlobalS : public concepts::Scan<Cell3> {
501  uint n_;
502  uint idx_;
503  Array<unique_ptr<Cell3> > *cell_;
504  public:
505  inline GlobalS(uint n, Array<unique_ptr<Cell3> > *cell)
506  : n_(n), idx_(0), cell_(cell) {
507  throw conceptsException(MissingFeature("GlobalS not yet implemented"));
508  };
509  inline GlobalS(const GlobalS& scan) {
510  throw conceptsException(MissingFeature("GlobalS not yet implemented"));
511  };
512  inline bool eos() const {return 1;};
513  inline Cell3& operator++(int) {return *((*cell_)[idx_++]);};
514  inline concepts::Scan3* clone() const {return new GlobalS(*this);};
515  };
516 
518  template<class T>
519  class CapS : public Scan<T> {
520  private:
521  ListElm<T>* cntr_;
522  public:
523  inline CapS(ListElm<T>* cntr) : cntr_(cntr) {};
524  inline CapS(const CapS<T>& scan) : cntr_(scan.cntr_) {};
525  inline bool eos() const {return (!cntr_);};
526  inline T& operator++(int) {
527  ListElm<T>* foo = cntr_; cntr_ = cntr_->link();
528  return *(foo->elm());};
529  inline concepts::Scan<T>* clone() const {return new CapS(*this);};
530  };
531 
533  uint ngcell_;
535  uint nlcell_;
536 
538  Array<unique_ptr<Connector0> >* cntr0_;
539  uint ncntr0_;
541  Array<unique_ptr<Connector1> >* cntr1_;
542  uint ncntr1_;
544  Array<unique_ptr<Connector2> >* cntr2_;
545  uint ncntr2_;
546 
548  Array<unique_ptr<Connector3> >* cntr3_;
550  Array<unique_ptr<Cell3> >* cell_;
551 
553  Array<unique_ptr<concepts::Map3d> >* map_;
554  uint nmap_;
555 
557  Array<Cntr0Lst>* cap0_;
559  Array<Cntr1Lst>* cap1_;
561  Array<Cntr2Lst>* cap2_;
563  Array<Cell3Lst>* cap3_;
564 
565  public:
596  inline Mesh3(Array<unique_ptr<Connector0> >* cntr0,
597  Array<unique_ptr<Connector1> >* cntr1,
598  Array<unique_ptr<Connector2> >* cntr2,
599  Array<unique_ptr<Connector3> >* cntr3,
600  Array<unique_ptr<Cell3> >* cell, uint ngcell,
601  Array<unique_ptr<concepts::Map3d> >* map,
602  Array<Cntr0Lst>* cap0, Array<Cntr1Lst>* cap1,
603  Array<Cntr2Lst>* cap2, Array<Cell3Lst>* cap3_,
604  const Communicator& com);
605  inline ~Mesh3();
606 
608  inline uint nglobcell() const {return ngcell_;};
610  inline uint nloccell() const {return nlcell_;};
611 
613  inline concepts::Scan3* globscan() {return new GlobalS(nlcell_, cell_);};
614 
616  inline concepts::Scan3* locscan() {return new LocalS(nlcell_, cell_);};
617 
621  inline concepts::ScanCntr0* cap0scan(uint i) {
622  return new CapS<Connector0>((*cap0_)[i].root());
623  };
627  inline concepts::ScanCntr1* cap1scan(uint i) {
628  return new CapS<Connector1>((*cap1_)[i].root());
629  };
633  inline concepts::ScanCntr2* cap2scan(uint i) {
634  return new CapS<Connector2>((*cap2_)[i].root());
635  };
639  inline concepts::Scan3* cap3scan(uint i) {
640  return new CapS<Cell3>((*cap3_)[i].root());
641  };
642 
643  protected:
644  std::ostream& info(std::ostream& os) const;
645  };
646 
647 
648  Mesh3::Mesh3(Array<unique_ptr<Connector0> >* cntr0,
649  Array<unique_ptr<Connector1> >* cntr1,
650  Array<unique_ptr<Connector2> >* cntr2,
651  Array<unique_ptr<Connector3> >* cntr3,
652  Array<unique_ptr<Cell3> >* cell, uint ngcell,
653  Array<unique_ptr<concepts::Map3d> >* map,
654  Array<Cntr0Lst>* cap0, Array<Cntr1Lst>* cap1,
655  Array<Cntr2Lst>* cap2, Array<Cell3Lst>* cap3,
656  const Communicator& com)
657  : Mesh(com), ngcell_(ngcell), nlcell_(cell->cursize()), cntr0_(cntr0),
658  ncntr0_(cntr0->cursize()), cntr1_(cntr1), ncntr1_(cntr1->cursize()),
659  cntr2_(cntr2), ncntr2_(cntr2->cursize()), cntr3_(cntr3), cell_(cell),
660  map_(map), nmap_(map ? map->cursize() : 0), cap0_(cap0), cap1_(cap1),
661  cap2_(cap2), cap3_(cap3) {
662  }
663 
664  Mesh3::~Mesh3() {
665  delete cap3_; delete cap2_; delete cap1_; delete cap0_;
666  delete cell_; delete map_;
667  delete cntr3_; delete cntr2_; delete cntr1_; delete cntr0_;
668  }
669 
670 
671 } // namespace parallel
672 
673 #endif // mesh_p_hh
Scan< Connector2 > ScanCntr2
Definition: mesh_p.hh:53
virtual bool eos() const =0
Returns true if the end of the scanned set is reached.
#define conceptsException(exc)
Prepares an exception for throwing.
Definition: exceptions.hh:344
A scanner for a 3D mesh.
Definition: mesh.hh:52
A scanner for a 2D mesh.
Definition: mesh.hh:44
virtual T & operator++(int)=0
Returns the next element in the scanned set.
A scanner for 1D connectors on the processor intersection (cap)
Definition: mesh_p.hh:36
A 2D element of the topology.
Definition: connector.hh:226
virtual Scan * clone() const =0
Returns a clone of the scanner.
An abstract class for scanning a mesh (a set of cells) or a space (a set of elements).
Scan< Connector0 > ScanCntr0
Definition: mesh_p.hh:51
A scanner for 2D connectors on the processor intersection (cap)
Definition: mesh_p.hh:45
Scan< Connector1 > ScanCntr1
Definition: mesh_p.hh:52
Connector1 & operator++(int)=0
Returns the next connector of the cap.
A 1D element of the topology.
Definition: connector.hh:182
Connector2 & operator++(int)=0
Returns the next connector of the cap.
virtual std::ostream & info(std::ostream &os) const
Returns information in an output stream.
A scanner for a 1D mesh.
Definition: mesh.hh:36
Class providing an output operator.
A scanner for 0D connectors on the processor intersection (cap)
Definition: mesh_p.hh:27
Connector0 & operator++(int)=0
Returns the next connnector of the cap.
A 0D element of the topology.
Definition: connector.hh:147
Basic namespace for Concepts-2.
Definition: pml_formula.h:16
Page URL: http://wiki.math.ethz.ch/bin/view/Concepts/WebHome
21 August 2020
© 2020 Eidgenössische Technische Hochschule Zürich