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

space/spacePreBuilder.hh
Go to the documentation of this file.
00001 /* @file spacePreBuilder.hh Base class for space pre builder and
00002    helper classes based on space pre builders.
00003    @author Kersten Schmidt, 2005
00004  */
00005 
00006 #ifndef hpSpacePreBuilder_hh
00007 #define hpSpacePreBuilder_hh
00008 
00009 #include "basics/debug.hh"
00010 #include "basics/exceptions.hh"
00011 #include "basics/outputOperator.hh"
00012 #include "geometry/boundaryConditions.hh"
00013 #include "geometry/cellConditions.hh"
00014 #include "geometry/mesh.hh"
00015 #include "spaceSet.hh"
00016 
00017 #define SubSpaceHelper_D 0
00018 
00019 namespace concepts {
00020 
00021   // forward declarations
00022   template<class F, class G>
00023   class BuildTColumnsBase;
00024 
00025   // *********************************************************** NotValidDof **
00026 
00031   class NotValidDof : public ExceptionBase {};
00032 
00033   // ******************************************************* SpacePreBuilder **
00034 
00035   class SpacePreBuilder : public OutputOperator {
00036   public:
00038     SpacePreBuilder() {}
00040     virtual ~SpacePreBuilder() {}
00041 
00043     virtual concepts::Mesh& mesh() const = 0;
00046     virtual void rebuildMesh() = 0;
00049     virtual void rebuildDof() = 0;
00060     virtual concepts::IndexRange&
00061       setIndex(uint& firstIdx, uint noIdx, uint dim,
00062          const concepts::Connector& cntr, uint i = 0,
00063          uint spcNo = 0) throw(NotValidDof) = 0;
00072     virtual concepts::Set<concepts::IndexRange> indices
00073       (uint dim, const concepts::Connector& cntr, uint spcNo = 0) const 
00074       throw(concepts::MissingFeature) = 0;
00075   protected:
00076     virtual std::ostream& info(std::ostream& os) const;
00077   };
00078 
00079   // *********************************************************** SpaceHelper **
00080 
00087   template<class F, class G>
00088   class SpaceHelper : public OutputOperator {
00089 //     friend class BuildTColumnsBase<F,G>;
00090   public:
00096     SpaceHelper(G& prebuild, const BoundaryConditions* bc = 0,
00097     const CellConditions* cc = 0) : 
00098       prebuild_(&prebuild), 
00099       bc_(bc ? new const BoundaryConditions(*bc) : 0), 
00100       cc_(cc ? new const CellConditions    (*cc) : 0) {}
00101     virtual ~SpaceHelper() {}
00103     const BoundaryConditions* bc() const { return bc_.get(); }
00105     const CellConditions* cc() const { return cc_.get(); }
00107     G& prebuild() { return *prebuild_; }
00109     virtual void reset() = 0;
00111     virtual uint& idx() = 0;
00112     virtual const uint& idx() const = 0;
00117     virtual uint spcNo() const { return 0; }
00119     bool passive(const concepts::Connector& cntr) const {
00120       return passive_.exist(&cntr);
00121     }
00123     void setPassive(const concepts::Connector& cntr) {
00124       passive_.insert(&cntr);
00125     }
00126     const concepts::Set<const concepts::Connector*> passive() const {
00127       return passive_;
00128     }
00129   protected:
00130     virtual std::ostream& info(std::ostream& os) const;
00131   private:
00133     G* prebuild_;
00135     std::auto_ptr<const BoundaryConditions> bc_;
00137     std::auto_ptr<const CellConditions> cc_;
00139     concepts::Set<const concepts::Connector*> passive_;
00140   };
00141 
00142   template<class F, class G>
00143   std::ostream& SpaceHelper<F,G>::info(std::ostream& os) const {
00144     os << "SpaceHelper(";
00145     if (bc_.get()) {
00146       os << *bc_; if (cc_.get()) os << ", ";
00147     }
00148     if (cc_.get()) os << *cc_;
00149     
00150     return os << ')';
00151   }
00152 
00153   // ******************************************************** SubspaceHelper **
00154 
00155   template<class F, class G>
00156   class SubspaceHelper : public SpaceHelper<F,G> {
00157   public:
00167     SubspaceHelper(G& prebuild, uint spcNo, const BoundaryConditions* bc = 0,
00168                    const CellConditions* cc = 0, uint* const offset = 0,
00169                    uint* const idx = 0)
00170       : SpaceHelper<F,G>(prebuild, bc, cc), spcNo_(spcNo), offset_(offset),
00171   ownIndex_(idx == 0), idx_(ownIndex_ ? new uint(this->offset()) : idx) {
00172       DEBUGL(SubSpaceHelper_D, *this);
00173     }
00174     virtual ~SubspaceHelper() {
00175       if (ownIndex_) delete idx_;
00176       DEBUGL(SubSpaceHelper_D, "done");
00177     }
00178     virtual void reset() { *idx_ = offset(); }
00184     virtual uint& idx() { 
00185       DEBUGL(SubSpaceHelper_D, "idx = " << *idx_); 
00186       return *idx_; }
00187     virtual const uint& idx() const { 
00188       DEBUGL(SubSpaceHelper_D, "idx = " << *idx_); 
00189       return *idx_;
00190     }
00191     bool ownIndex() const { return ownIndex_; }
00192     virtual uint spcNo() const { return spcNo_; }
00194     uint offset() const { return offset_ ? *offset_ : 0; }
00195   protected:
00196     virtual std::ostream& info(std::ostream& os) const;
00197   private:
00198     uint spcNo_;
00200     uint* const offset_;
00202     bool ownIndex_;
00204     uint* const idx_;
00205 
00206   };
00207 
00208   template<class F, class G>
00209   std::ostream& SubspaceHelper<F,G>::info(std::ostream& os) const {
00210     os << "SubspaceHelper(";
00211     if (this->bc()) os << *this->bc() << ", ";
00212     if (this->cc()) os << *this->cc() << ", ";
00213     if (offset_ == 0) os << "(own)"; else os << "(given)";
00214     os << " offset = " << offset() << ", ";
00215     if (ownIndex_) os << "(own)"; else os << "(given)";
00216     return os << " idx = " << idx() << ")";
00217   }
00218 
00219   // ***************************************************** BuildTColumnsBase **
00220 
00237   template<class F, class G>
00238   class BuildTColumnsBase : public OutputOperator {
00239   public:
00241     BuildTColumnsBase() : spc_(0) {}
00245     BuildTColumnsBase(SpaceHelper<F,G>& spc) : spc_(&spc) {}
00246     virtual ~BuildTColumnsBase() {}
00247 
00249     inline SpaceHelper<F,G>& spc() const;
00251     inline G& prebuild() const;
00252 
00263     virtual BuildTColumnsBase<F,G>* clone(SpaceHelper<F,G>* spc = 0) const = 0;
00264   protected:
00266     SpaceHelper<F,G>* spc_;
00267     virtual std::ostream& info(std::ostream& os) const;
00268   };
00269 
00270   template<class F, class G>
00271   SpaceHelper<F,G>& BuildTColumnsBase<F,G>::spc() const { 
00272     conceptsAssert(spc_, Assertion());
00273     return *spc_;
00274   }
00275 
00276   template<class F, class G>
00277   G& BuildTColumnsBase<F,G>::prebuild() const { 
00278     conceptsAssert(spc_, Assertion());
00279     return spc_->prebuild();
00280   }
00281 
00282   template<class F, class G>
00283   std::ostream& BuildTColumnsBase<F,G>::info(std::ostream& os) const {
00284     return os << "BuildTColumnsBase(" << *spc_ << ")";
00285   }
00286 
00287 }
00288 
00289 #endif // hpSpacePreBuilder_hh

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