Home | Doxygen Documentation | Tutorials | Developer Tools (restricted)

space/space.hh
Go to the documentation of this file.
00001 /* Abstract classes for a space and an adaptive space
00002  */
00003 
00004 #ifndef spcSpace_hh
00005 #define spcSpace_hh
00006 
00007 #include <cstring>
00008 #include <climits>
00009 #include <set>
00010 #include <map>
00011 #include "basics/outputOperator.hh"
00012 #include "basics/typedefs.hh"
00013 #include "basics/exceptions.hh"
00014 #include "basics/level.hh"
00015 #include "toolbox/scannerConnectors.hh"
00016 #include "geometry/connector.hh"
00017 #include "space/element.hh"
00018 
00019 namespace concepts {
00020 
00021   // ********************************************************* SpaceNotBuilt **
00022 
00034   class SpaceNotBuilt : public ExceptionBase {};
00035 
00036   // ***************************************************************** Space **
00037 
00041   template<class F>
00042   class Space : public OutputOperator {
00043   public:
00044     typedef Scan<Element<F> > Scanner;
00045 
00047     virtual uint dim() const = 0;
00048 
00050     virtual uint nelm() const = 0;
00051 
00053     virtual Scanner* scan() const = 0;
00054   protected:
00055     virtual std::ostream& info(std::ostream& os) const;
00056   };
00057 
00058   // ********************************************** Scan<ElementWithCell<F> > **
00059 
00060   template<class F>
00061   class Scan<ElementWithCell<F> > : public Scan<Element<F> > {
00062   public:  
00063     virtual ElementWithCell<F>& operator++(int) = 0;
00064   };
00065 
00066   // ***************************************************************** Space **
00067 
00071   template<class F>
00072   class SpaceOnCells : public Space<F> {
00073   public:
00074     typedef Scan<ElementWithCell<F> > Scanner;
00075 
00077     virtual Scanner* scan() const = 0;
00078   protected:
00079     virtual std::ostream& info(std::ostream& os) const;
00080   };
00081 
00082   // **************************************************** AdaptiveControlTag **
00083 
00087   struct AdaptiveControlTag {
00101     enum tagInfo { NO_TAG = 0, MEMBER = 1, PASSIVE = 2, VLD_IDX = 4, VLD_P = 8 };
00112     uchar data_;
00113 
00115     AdaptiveControlTag(uchar t = 0) : data_(t) {}
00116 
00118     uchar operator=(const uchar& t) { return data_ = t; }
00119 
00123     bool isMember() const { return (data_ & MEMBER); }
00125     void takeIn() { data_ |= MEMBER; }
00127     void takeOut() { data_ &= ~MEMBER; }
00128 
00132     bool isActive() const { return !(data_ & PASSIVE); }
00138     bool isPassive() const { return (data_ & PASSIVE); }
00139     void activate() { data_ &= ~PASSIVE; }
00140     void deactivate() { data_ |= PASSIVE; }
00141 
00145     bool idxValid() const { return (data_ & VLD_IDX); }
00146     void validateIdx() { data_ |= VLD_IDX; }
00147     void invalidateIdx() { data_ &= ~VLD_IDX; }
00148 
00152     bool pValid() const { return (data_ & VLD_P); }
00153     void validateP() { data_ |= VLD_P; }
00154     void invalidateP() { data_ &= ~VLD_P; }
00155   };
00156 
00157   std::ostream& operator<<(std::ostream& os, const AdaptiveControlTag& c);
00158 
00159   // ************************************************************ IndexRange **
00160 
00171   struct IndexRange {
00177     uint idx_[2];
00178 
00180     IndexRange() { idx_[0] = idx_[1] = 0; }
00182     IndexRange(uint idx);
00184     IndexRange(uint idxBegin, uint idxEnd);
00186     std::set<uint> operator()();
00188     IndexRange& operator=(uint i);
00190     IndexRange& operator=(const IndexRange& i);
00191     IndexRange& operator=(IndexRange& i);
00193     bool operator==(uint i) const;
00195     bool operator==(const IndexRange& i) const;
00197     bool operator<(const IndexRange& i) const;
00199     uint dim() const { return idx_[1] - idx_[0] + 1; }
00200   };
00201 
00202   std::ostream& operator<<(std::ostream& os, const IndexRange& i);
00203 
00204   std::ostream& operator<<(std::ostream& os,
00205       const std::map<uint, IndexRange>& map);
00206 
00207   // ******************************************************* AdaptiveControl **
00208 
00215   template<class F = uint>
00216     struct AdaptiveControl {
00218       AdaptiveControlTag tag_;
00223       F idx_;
00224 
00226       AdaptiveControl();
00227     };
00228 
00229   template<class F>
00230     std::ostream& operator<<(std::ostream& os, const AdaptiveControl<F>& c);
00231 
00232   // ******************************************************** AdaptiveAdjust **
00233 
00243   template<uint levelDim = 1>
00244   class AdaptiveAdjust {
00245   public:
00247     Level<levelDim> level_;
00251     short& l_;
00252     
00254     AdaptiveAdjust() : level_(), l_(level_.l_[0]) {}
00258     AdaptiveAdjust(short l) : level_(l), l_(level_.l_[0]) {}
00259   };
00260   
00261   template<uint levelDim>
00262     std::ostream& operator<<(std::ostream& os,
00263         const AdaptiveAdjust<levelDim>& a);
00264 
00265   // ************************************************************ Adaptivity **
00266 
00276   template<class F = Connector, class Tadj = struct AdaptiveAdjust<1> >
00277   class Adaptivity {
00278   public:
00279     virtual ~Adaptivity() { }
00281     virtual void adjust(const F& cell, const Tadj& a) = 0;
00282   };
00283 
00284   // ********************************************************* AdaptiveSpace **
00285 
00294   template<class F, class Tadj = struct AdaptiveAdjust<1> >
00295   class AdaptiveSpace { 
00296   public:
00300     virtual void adjust(const Element<F>& elm, const Tadj& a) = 0;
00301 
00302     virtual ~AdaptiveSpace() { }
00303   };
00304 
00305   // ************************************************************ DummySpace **
00306 
00311   template<typename F>
00312     class DummySpace : public Space<F> {
00313       public:
00314         typedef concepts::Scan<concepts::Element<F> > Scan;
00315         DummySpace(uint dim) : dim_(dim) {}
00316         virtual uint dim() const { return dim_; }
00317         virtual uint nelm() const { return 0; }
00318         virtual Scan* scan() const { return 0; }
00319       protected:
00320         virtual std::ostream& info(std::ostream& os) const {
00321           return os << "DummySpace<" << number<F>::name()
00322             << ">(dim = " << dim_ << ')'; }
00323       private:
00324         uint dim_;
00325     };
00326 
00327   // ************************************************************** Subspace **
00328 
00331   class Subspace {
00332     public:
00334       virtual uint& lastIdx() = 0;
00336       virtual uint offset() const = 0;
00337       virtual ~Subspace() {}
00338   };
00339 
00340   // ************************************************************ SpaceDebug **
00346   template<typename F = Real>
00347     class SpaceDebug : public OutputOperator {
00348       public:
00349         SpaceDebug(const Space<F>& spc) : spc_(spc) {}
00350       protected:
00351         virtual std::ostream& info(std::ostream& os) const;
00352       private:
00353         const Space<F>& spc_;
00354     };
00355 
00356   template<typename F>
00357     std::ostream& SpaceDebug<F>::info(std::ostream& os) const {
00358       os << spc_ << std::endl;
00359       std::auto_ptr<typename Space<F>::Scanner> sc(spc_.scan());
00360       uint i = 1;
00361       while (*sc) {
00362         const Element<F>& elm = (*sc)++;
00363         os << i++ << ". element = " << elm << std::endl;
00364       }
00365       return os;
00366     }
00367 
00368 } // namespace concepts
00369 
00370 #endif // spcSpace_hh

Home | Doxygen Documentation | Tutorials | Developer Tools (restricted)