space.hh

Go to the documentation of this file.
1 
6 #ifndef spcSpace_hh
7 #define spcSpace_hh
8 
9 #include <cstring>
10 #include <climits>
11 #include <set>
12 #include <map>
13 #include "basics/outputOperator.hh"
14 #include "basics/typedefs.hh"
15 #include "basics/exceptions.hh"
16 #include "basics/level.hh"
18 #include "geometry/connector.hh"
19 #include "space/element.hh"
20 
21 namespace concepts {
22 
23  // ********************************************************* SpaceNotBuilt **
24 
36  class SpaceNotBuilt : public ExceptionBase {};
37 
38  // ***************************************************************** Space **
39 
43  template<class F>
44  class Space : public virtual OutputOperator {
45  public:
46  typedef Element<F> type;
48 
50  virtual uint getOutputDimension() const{
51  return 1u;
52  };
53 
55  virtual uint dim() const = 0;
56 
58  virtual uint nelm() const = 0;
59 
61  virtual Scanner* scan() const = 0;
62  protected:
63  virtual std::ostream& info(std::ostream& os) const;
64 
65  };
66 
67  // ********************************************** Scan<ElementWithCell<F> > **
68 
69  template<class F>
70  class Scan<ElementWithCell<F> > : public Scan<Element<F> > {
71  public:
72  virtual ElementWithCell<F>& operator++(int) = 0;
73  };
74 
75  // ***************************************************************** Space **
76 
80  template<class F>
81  class SpaceOnCells : public Space<F> {
82  public:
85 
87  virtual Scanner* scan() const = 0;
88 
90  virtual uint dim() const = 0;
91 
93  virtual uint nelm() const = 0;
94 
95  protected:
96  virtual std::ostream& info(std::ostream& os) const;
97  };
98 
99 
100 
101 
102  template<uint dimC> class CellType;
103 
104  template<> class CellType<1>{
105  public:
107  };
108 
109  template<> class CellType<2>{
110  public:
112  };
113 
114  template<> class CellType<3>{
115  public:
117  };
118 
119 
126  template<uint dimC, class F>
127  class SpaceOnCoarseCells : public SpaceOnCells<F>{
128 
129  public:
130  virtual const std::set<typename CellType<dimC>::cell * > allCells() const = 0;
131 
132  protected:
133  virtual std::ostream& info(std::ostream& os) const;
134 
135  };
136 
137  // **************************************************** AdaptiveControlTag **
138 
156  enum tagInfo { NO_TAG = 0, MEMBER = 1, PASSIVE = 2, VLD_IDX = 4, VLD_P = 8 };
168 
171 
173  uchar operator=(const uchar& t) { return data_ = t; }
174 
178  bool isMember() const { return (data_ & MEMBER); }
180  void takeIn() { data_ |= MEMBER; }
182  void takeOut() { data_ &= ~MEMBER; }
183 
187  bool isActive() const { return !(data_ & PASSIVE); }
193  bool isPassive() const { return (data_ & PASSIVE); }
194  void activate() { data_ &= ~PASSIVE; }
195  void deactivate() { data_ |= PASSIVE; }
196 
200  bool idxValid() const { return (data_ & VLD_IDX); }
201  void validateIdx() { data_ |= VLD_IDX; }
202  void invalidateIdx() { data_ &= ~VLD_IDX; }
203 
207  bool pValid() const { return (data_ & VLD_P); }
208  void validateP() { data_ |= VLD_P; }
209  void invalidateP() { data_ &= ~VLD_P; }
210  };
211 
212  std::ostream& operator<<(std::ostream& os, const AdaptiveControlTag& c);
213 
214  // ************************************************************ IndexRange **
215 
226  struct IndexRange {
232  uint idx_[2];
233 
235  IndexRange() { idx_[0] = idx_[1] = 0; }
237  IndexRange(uint idx);
239  IndexRange(uint idxBegin, uint idxEnd);
241  std::set<uint> operator()();
248  bool operator==(uint i) const;
250  bool operator==(const IndexRange& i) const;
252  bool operator<(const IndexRange& i) const;
254  uint dim() const { return idx_[1] - idx_[0] + 1; }
255  };
256 
257  std::ostream& operator<<(std::ostream& os, const IndexRange& i);
258 
259  std::ostream& operator<<(std::ostream& os,
260  const std::map<uint, IndexRange>& map);
261 
262  // ******************************************************* AdaptiveControl **
263 
270  template<class F = uint>
278  F idx_;
279 
282  };
283 
284  template<class F>
285  std::ostream& operator<<(std::ostream& os, const AdaptiveControl<F>& c);
286 
287  // ******************************************************** AdaptiveAdjust **
288 
298  template<uint levelDim = 1>
300  public:
306  short& l_;
307 
313  AdaptiveAdjust(short l) : level_(l), l_(level_.l_[0]) {}
314  };
315 
316  template<uint levelDim>
317  std::ostream& operator<<(std::ostream& os,
318  const AdaptiveAdjust<levelDim>& a);
319 
320  // ************************************************************ Adaptivity **
321 
331  template<class F = Connector, class Tadj = class AdaptiveAdjust<1> >
332  class Adaptivity {
333  public:
334  virtual ~Adaptivity() { }
336  virtual void adjust(const F& cell, const Tadj& a) = 0;
337  };
338 
339  // ********************************************************* AdaptiveSpace **
340 
349  template<class F, class Tadj = class AdaptiveAdjust<1> >
350  class AdaptiveSpace {
351  public:
355  virtual void adjust(const Element<F>& elm, const Tadj& a) = 0;
356 
357  virtual ~AdaptiveSpace() { }
358  };
359 
360  // ************************************************************ DummySpace **
361 
366  template<typename F>
367  class DummySpace : public Space<F> {
368  public:
370  DummySpace(uint dim) : dim_(dim) {}
371  virtual uint dim() const { return dim_; }
372  virtual uint nelm() const { return 0; }
373  virtual Scan* scan() const { return 0; }
374  protected:
375  virtual std::ostream& info(std::ostream& os) const {
376  return os << "DummySpace<" << number<F>::name()
377  << ">(dim = " << dim_ << ')'; }
378  private:
379  uint dim_;
380  };
381 
382  // ************************************************************** Subspace **
383 
386  class Subspace {
387  public:
389  virtual uint& lastIdx() = 0;
391  virtual uint offset() const = 0;
392  virtual ~Subspace() {}
393  };
394 
395  // ************************************************************ SpaceDebug **
401  template<typename F = Real>
402  class SpaceDebug : public virtual OutputOperator {
403  public:
404  SpaceDebug(const Space<F>& spc) : spc_(spc) {}
405  protected:
406  virtual std::ostream& info(std::ostream& os) const;
407  private:
408  const Space<F>& spc_;
409  };
410 
411  template<typename F>
412  std::ostream& SpaceDebug<F>::info(std::ostream& os) const {
413  os << spc_ << std::endl;
414  std::unique_ptr<typename Space<F>::Scanner> sc(spc_.scan());
415  uint i = 1;
416  while (*sc) {
417  const Element<F>& elm = (*sc)++;
418  os << i++ << ". element = " << elm << std::endl;
419  }
420  return os;
421  }
422 
423 } // namespace concepts
424 
425 #endif // spcSpace_hh
concepts::Cell1 cell
Definition: space.hh:106
virtual void adjust(const Element< F > &elm, const Tadj &a)=0
Adjusts the space in the next rebuild step for this element.
virtual ~Adaptivity()
Definition: space.hh:334
An abstract class for an element of a space.
Definition: exceptions.hh:15
bool pValid() const
Checks for a valid polynomial degree.
Definition: space.hh:207
virtual uint nelm() const =0
Returns the number of elements in the space.
Scan< Element< F > > Scanner
Definition: space.hh:47
virtual ~Subspace()
Definition: space.hh:392
bool operator<(const IndexRange &i) const
Comparison of beginning indices.
AdaptiveAdjust()
Default constructor.
Definition: space.hh:309
DummySpace(uint dim)
Definition: space.hh:370
IndexRange(uint idxBegin, uint idxEnd)
Constructor for several successive indices.
virtual ~AdaptiveSpace()
Definition: space.hh:357
Base class for exceptions.
Definition: exceptions.hh:86
Abstract class for a space.
AdaptiveAdjust(short l)
Constructor.
Definition: space.hh:313
Element< F > type
Definition: space.hh:46
virtual uint dim() const
Returns the dimension of the space.
Definition: space.hh:371
virtual uint offset() const =0
Returns the offset.
Three dimensional cell.
Definition: cell.hh:112
Class for a range of global indices.
Definition: space.hh:226
virtual uint dim() const =0
Returns the dimension of the space.
uint idx_[2]
Begin and end of a unique range of indices of element.
Definition: space.hh:232
bool isPassive() const
Checks activity.
Definition: space.hh:193
unsigned char uchar
Abbreviation for unsigned char.
Definition: typedefs.hh:45
bool isActive() const
Checks activity.
Definition: space.hh:187
virtual uint dim() const =0
Returns the dimension of the space.
virtual void adjust(const F &cell, const Tadj &a)=0
Adjusts in the next rebuild step for this cell.
Element with cell.
SpaceDebug(const Space< F > &spc)
Definition: space.hh:404
ElementWithCell< F > type
Definition: space.hh:83
F idx_
Unique index of element.
Definition: space.hh:278
virtual Scan * scan() const
Returns a scanner to iterate over the elements of the space.
Definition: space.hh:373
One dimensional cell.
Definition: cell.hh:75
short & l_
Level.
Definition: space.hh:306
AdaptiveControlTag tag_
Control information.
Definition: space.hh:273
virtual const std::set< typename CellType< dimC >::cell * > allCells() const =0
Class for holding an offset of global indices of space.
Definition: space.hh:386
Class to describe control structures of an adaptive space.
Definition: space.hh:271
Abstract base class for an adaptive classes, a.o.t.
Definition: space.hh:332
virtual std::ostream & info(std::ostream &os) const
IndexRange & operator=(IndexRange &i)
Level< levelDim > level_
Level in several dimensions.
Definition: space.hh:302
tagInfo
Enumeration of the bit values in data_.
Definition: space.hh:156
AdaptiveControl()
Default constructor.
std::ostream & operator<<(std::ostream &os, const Level< dim > &c)
Name traits for number types.
Definition: typedefs.hh:68
virtual Scanner * scan() const =0
Returns a scanner to iterate over the elements of the space.
concepts::Scan< concepts::Element< F > > Scan
Definition: space.hh:369
Interface class for SpacesOnCells that also allow for allCells(), that i.e.
Definition: space.hh:127
An abstract class for scanning a mesh (a set of cells) or a space (a set of elements).
void takeOut()
Takes out of the space.
Definition: space.hh:182
bool idxValid() const
Checks for a valid index.
Definition: space.hh:200
Two dimensional cell.
Definition: cell.hh:89
virtual ElementWithCell< F > & operator++(int)=0
Returns the next element in the scanned set.
bool operator==(uint i) const
Comparison with beginning index.
IndexRange()
Default constructor.
Definition: space.hh:235
Indicates that the space on which a function was called was not yet correctly built.
Definition: space.hh:36
concepts::Cell3 cell
Definition: space.hh:116
virtual std::ostream & info(std::ostream &os) const
void takeIn()
Takes into the space.
Definition: space.hh:180
bool isMember() const
Checks member of the space.
Definition: space.hh:178
virtual std::ostream & info(std::ostream &os) const
Returns information in an output stream.
Definition: space.hh:412
virtual uint getOutputDimension() const
Returns the default output dimension, when we consider plotting a real-valued operator on this space.
Definition: space.hh:50
Abstract class for a space.
Definition: space.hh:81
virtual std::ostream & info(std::ostream &os) const
virtual uint & lastIdx()=0
Returns last global index of the space.
const Space< F > & spc_
Definition: space.hh:408
AdaptiveControlTag(uchar t=0)
Constructor.
Definition: space.hh:170
bool operator==(const IndexRange &i) const
Comparison.
virtual std::ostream & info(std::ostream &os) const
Definition: space.hh:375
virtual uint nelm() const =0
Returns the number of elements in the space.
uint dim() const
Number of indices.
Definition: space.hh:254
concepts::Cell2 cell
Definition: space.hh:111
Class to describe adjustments to elements in an adaptive space.
Definition: space.hh:299
Tag information which is used in AdaptiveControl.
Definition: space.hh:142
IndexRange & operator=(const IndexRange &i)
Assigment operator.
virtual Scanner * scan() const =0
Returns a scanner to iterate over the elements of the space.
IndexRange & operator=(uint i)
Assigment operator.
Scan< ElementWithCell< F > > Scanner
Definition: space.hh:84
Abstract base class for an adaptive space.
Definition: space.hh:350
uchar operator=(const uchar &t)
Assignement operator.
Definition: space.hh:173
uchar data_
Control information.
Definition: space.hh:167
Class providing an output operator.
Space for a given dimension but without more functionality.
Definition: space.hh:367
IndexRange(uint idx)
Constructor, where is only on index assigned.
Class for output of all elements of a class, good for debugging.
Definition: space.hh:402
Basic namespace for Concepts-2.
Definition: pml_formula.h:16
virtual uint nelm() const
Returns the number of elements in the space.
Definition: space.hh:372
std::set< uint > operator()()
Returns a set of the indices.
Page URL: http://wiki.math.ethz.ch/bin/view/Concepts/WebHome
21 August 2020
© 2020 Eidgenössische Technische Hochschule Zürich