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

app-kersten/ThinSheet/asympEdges.hh
Go to the documentation of this file.
00001 
00006 #ifndef AsympEdges_hh
00007 #define AsympEdges_hh
00008 
00009 
00010 #include "basics.hh"
00011 #include "geometry.hh"
00012 #include "toolbox/sequence.hh"
00013 
00014 namespace concepts {
00015 
00016   // ***************************************************** splitbySemicolon **
00017 
00018   /* Split a string into a sequence of substrings, where semicolons
00019      separate them.
00020    */
00021   Sequence<std::string> splitbySemicolon(const std::string s) {
00022     Sequence<std::string> seq;
00023     
00024     uint cnt = 0;
00025     while(cnt < s.size()) {
00026       uint n = s.find(";",cnt);
00027       std::string sub = s.substr(cnt, n);
00028       // delete whitespaces
00029       uint c2 = 0;
00030       while(c2 != sub.npos) {
00031   c2 = sub.find(" ");
00032   if (c2 != sub.npos)
00033     sub = sub.erase(c2, 1);
00034     }
00035       seq.push_back(sub);
00036       
00037       if (n == s.npos)
00038   cnt = s.size();
00039       else
00040   cnt = n+1;
00041     }
00042     
00043     return seq;
00044   }
00045 
00046   // ***************************************************************** match **
00047 
00051   int match(const Connector1& edg, const Connector0& vtx, int& idx) {
00052     for (idx = 0; idx < 2; ++idx)
00053       if (*edg.vertex(idx) == vtx) return 1;
00054     return 0;
00055   }
00056 
00057   // ****************************************************** ParseInputString **
00058 
00059   /* Class for parsing a string with input variables of the form
00060      <pre>"attrib = 1;"</pre>
00061 
00062      @author Kersten Schmidt, 2007
00063   */
00064   class ParseInputString {
00065   public:
00066     ParseInputString() {}
00067     virtual ~ParseInputString() {}
00069     void parse(const std::map<int, std::string> map) {
00070       std::map<int, std::string>::const_iterator i = map.begin();
00071       for(; i != map.end(); ++i)
00072   parse(i->second);
00073     }
00074     inline void parse(const std::string data) {
00075       this->evaluate_(splitbySemicolon(data));
00076     }
00077   private:
00079     virtual void evaluate_(const Sequence<std::string> substrings) = 0;
00080   };
00081 
00082   // *********************************************** ParseThinSheetThickness **
00083 
00084   /* Class for parsing a string with thicknesses of thin sheets.
00085 
00086      With
00087      <pre>"attrib = 1; thickness = 0.2;"</pre>
00088      the edges with attribute 1 get thickness 0.2.
00089 
00090      @author Kersten Schmidt, 2007
00091   */
00092   class ParseThinSheetThickness : public ParseInputString,
00093           public HashMap<double> {
00094   public:
00095     ParseThinSheetThickness(const std::map<int, std::string> map) { 
00096       parse(map);
00097     }
00098   protected:
00099     virtual std::ostream& info(std::ostream& os) const;
00100   private:
00101     virtual void evaluate_(const Sequence<std::string> substrings);
00102   };
00103 
00104   template<class F>
00105   std::ostream& operator<<(std::ostream& os, const typename std::list<F>& l) {
00106     os << "std::list(";
00107     for(typename std::list<F>::
00108     const_iterator i = l.begin(); i != l.end();) {
00109       pointerOutput(os, *i);
00110       if (++i != l.end()) os << ", ";
00111     }
00112     return os << ")";
00113   }
00114 
00115   // ********************************************************* ThinSheetRule **
00116 
00117   /* Defines a rule, where is a top and the bottom of a sheet.
00118    */
00119   class ThinSheetRule : public OutputOperator {
00120   public:
00127     virtual Z2 top(const Real2d& vtx0, const Real2d& vtx1) const = 0;
00128   protected:
00129     virtual std::ostream& info(std::ostream& os) const {
00130       return os << "ThinSheetRule()";
00131     }
00132   };
00133 
00134   // **************************************************** ThinSheetRuleCoord **
00135 
00139   class ThinSheetRuleCoord : public ThinSheetRule {
00140   public:
00141     enum directions {LEFT = 0, RIGHT = 1, TOP = 2, BOTTOM = 3};
00143     ThinSheetRuleCoord(enum directions dir) : dir_(dir) {}
00144     virtual ~ThinSheetRuleCoord() {}
00145     virtual Z2 top(const Real2d& vtx0, const Real2d& vtx1) const;
00146   protected:
00147     virtual std::ostream& info(std::ostream& os) const;
00148   private:
00149     enum directions dir_;
00150   };
00151 
00152   // ******************************************************** ThinSheetEdges **
00153 
00154   /* Holds thickness of thin sheets, which are edges in a mesh
00155    */
00156   class ThinSheetEdges : public OutputOperator {
00157   public:
00158     class List : public Sequence<const Connector1*> {
00159     public:
00164       Z2 top;
00165     protected:
00166       virtual std::ostream& info(std::ostream& os) const;
00167     };
00168 
00170     ThinSheetEdges(Mesh2& msh, const HashMap<double> thickness,
00171        const ThinSheetRule& rule);
00172 
00174     bool exists(const Connector1* edge) const;
00175 
00179     bool exists(const Connector2* cell, const uint i) const;
00180 
00182     double thickness(const uint attrib) const;
00183 
00188     Z2 top(const Connector1* edge);
00189 
00194     bool top(const Quad* cell, const uint i);
00195 
00200     Z2 edgeDirection(const Connector1* edge) const;
00201 
00203     void rebuild();
00204 
00209     bool takeChildren_(const Connector1* edge, Sequence<List>::iterator& i,
00210            Sequence<const Connector1*>::iterator& ie);
00211 
00212   protected:
00213     virtual std::ostream& info(std::ostream& os) const;
00214   private:
00216     HashMap<double> thickness_;
00218     HashMap<uint> edgeToList_;
00223     HashMap<Z2> edgeDirection_;
00224 
00233     Sequence<List> edges_;
00234 
00236     bool appended_(const Connector1* edge) const;
00237 
00243     bool fitToList_(const Connector1* edge, const Z2 top,
00244         const List& list, uint& vidx, bool& front);
00245 
00247     void append_(const Cell2& cell, const ThinSheetRule* rule);
00248 
00250     void append_(const Connector1* edge, const Z2 top);
00251   };
00252 
00253 } // namespace concepts
00254 
00255 #endif // AsympEdges_hh

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