SyFi 0.3
Polygon.h
Go to the documentation of this file.
00001 // Copyright (C) 2006-2009 Kent-Andre Mardal and Simula Research Laboratory.
00002 // Licensed under the GNU GPL Version 2, or (at your option) any later version.
00003 
00004 #ifndef POLYGON_IS_INCLUDED
00005 #define POLYGON_IS_INCLUDED
00006 
00007 #include <string>
00008 #include <ginac/ginac.h>
00009 
00010 namespace SyFi
00011 {
00012 
00013         enum  Repr_format
00014         {
00015                 SUBS_PERFORMED = 1,
00016                 SUBS_NOT_PERFORMED = 2
00017         };
00018 
00019         // TODO: Can be const too:
00020         //      integrate
00021 
00022         class Line;
00023         class Triangle;
00024         class Rectangle;
00025 
00026         class Polygon
00027         {
00028                 protected:
00029                         Polygon(const std::string & subscript_="", unsigned int no_vert=0);
00030                         Polygon(const Polygon& polygon);
00031 
00032                         std::string subscript;
00033                         GiNaC::exvector p;
00034 
00035                 public:
00036                         virtual ~Polygon() {}
00037 
00038                         /* Return the topological dimension of the object. */
00039                         virtual unsigned int no_space_dim() const = 0;
00040 
00041                         virtual unsigned int no_vertices() const;
00042                         virtual GiNaC::ex vertex(unsigned int i) const;
00043 
00044                         virtual GiNaC::ex repr(Repr_format format = SUBS_PERFORMED) const = 0;
00045                         virtual const std::string str() const = 0;
00046 
00047                         virtual GiNaC::ex integrate(GiNaC::ex f, Repr_format format = SUBS_PERFORMED) = 0;
00048                         virtual Polygon* copy() const = 0;
00049 
00050                         // This design isn't very good, but doing it differently will require solving some memory issues:
00051                         virtual Line line(unsigned int i) const;
00052                         virtual Triangle triangle(unsigned int i) const;
00053                         virtual Rectangle rectangle(unsigned int i) const;
00054         };
00055 
00056         class Line : public Polygon
00057         {
00058                 protected:
00059                         GiNaC::ex a_;
00060                         GiNaC::ex b_;
00061                 public:
00062                         /* Constructing an empty object. */
00063                         Line() {}
00064                         /* x0_ and x1_ are points, of the type GiNaC::lst if dim>1 */
00065                         Line(GiNaC::ex x0, GiNaC::ex x1, const std::string & subscript = "");
00066                         Line(const Line& line);
00067                         virtual ~Line(){}
00068 
00069                         virtual unsigned int no_space_dim() const;
00070 
00071                         GiNaC::ex a() const;
00072                         GiNaC::ex b() const;
00073 
00074                         virtual GiNaC::ex repr(Repr_format format = SUBS_PERFORMED) const;
00075                         virtual GiNaC::ex repr(GiNaC::ex t, Repr_format format = SUBS_PERFORMED) const;
00076                         virtual const std::string str() const;
00077 
00078                         virtual GiNaC::ex integrate(GiNaC::ex f, Repr_format format = SUBS_PERFORMED);
00079                         virtual Line* copy() const;
00080         };
00081 
00082         class ReferenceLine : public Line
00083         {
00084                 public:
00085                         ReferenceLine(const std::string & subscript = "");
00086                         ReferenceLine(const ReferenceLine& line);
00087                         virtual ~ReferenceLine(){}
00088 
00089                         virtual GiNaC::ex repr(GiNaC::ex t, Repr_format format = SUBS_PERFORMED) const;
00090                         virtual const std::string str() const;
00091 
00092                         virtual GiNaC::ex integrate(GiNaC::ex f, Repr_format format = SUBS_PERFORMED);
00093                         virtual ReferenceLine* copy() const;
00094         };
00095 
00096         class Triangle : public Polygon
00097         {
00098                 protected:
00099                         Triangle(const std::string & subscript = "");
00100                 public:
00101                         Triangle(GiNaC::ex x0, GiNaC::ex x1, GiNaC::ex x2, const std::string & subscript = "");
00102                         Triangle(const Triangle& triangle);
00103                         virtual ~Triangle(){}
00104 
00105                         virtual unsigned int no_space_dim() const;
00106 
00107                         virtual Line line(unsigned int i) const;
00108 
00109                         virtual GiNaC::ex repr(Repr_format = SUBS_PERFORMED) const;
00110                         virtual const std::string str() const;
00111 
00112                         virtual GiNaC::ex integrate(GiNaC::ex f, Repr_format format = SUBS_PERFORMED);
00113                         virtual Triangle* copy() const;
00114 
00115         };
00116 
00117         class ReferenceTriangle : public Triangle
00118         {
00119                 public:
00120                         ReferenceTriangle(const std::string & subscript = "");
00121                         ReferenceTriangle(const ReferenceTriangle& triangle);
00122                         virtual ~ReferenceTriangle(){}
00123 
00124                         virtual const std::string str() const;
00125 
00126                         virtual GiNaC::ex integrate(GiNaC::ex f, Repr_format format = SUBS_PERFORMED);
00127                         virtual ReferenceTriangle* copy() const;
00128         };
00129 
00130         class Rectangle : public Polygon
00131         {
00132                 protected:
00133                         Rectangle(const std::string & subscript = "");
00134                 public:
00135                         Rectangle(GiNaC::ex p0, GiNaC::ex p1, const std::string & subscript = "");
00136                         Rectangle(GiNaC::ex p0, GiNaC::ex p1, GiNaC::ex p2, GiNaC::ex p3, const std::string & subscript = "");
00137                         Rectangle(const Rectangle& rectangle);
00138                         virtual ~Rectangle(){}
00139 
00140                         virtual unsigned int no_space_dim() const;
00141 
00142                         virtual Line line(unsigned int i) const;
00143 
00144                         virtual GiNaC::ex repr(Repr_format format = SUBS_PERFORMED) const;
00145                         virtual const std::string str() const;
00146 
00147                         virtual GiNaC::ex integrate(GiNaC::ex f, Repr_format format = SUBS_PERFORMED);
00148                         virtual Rectangle* copy() const;
00149         };
00150 
00151         class ReferenceRectangle : public Rectangle
00152         {
00153                 public:
00154                         ReferenceRectangle(const std::string & subscript = "");
00155                         ReferenceRectangle(const ReferenceRectangle& rectangle);
00156                         virtual ~ReferenceRectangle(){}
00157 
00158                         virtual const std::string str() const;
00159                         virtual ReferenceRectangle* copy() const;
00160         };
00161 
00162         class Tetrahedron : public Polygon
00163         {
00164                 public:
00165                         Tetrahedron(GiNaC::ex x0, GiNaC::ex x1, GiNaC::ex x2, GiNaC::ex x3, const std::string & subscript = "");
00166                         Tetrahedron(const Tetrahedron& tetrahedron);
00167                         virtual ~Tetrahedron(){}
00168 
00169                         virtual unsigned int no_space_dim() const;
00170 
00171                         virtual Line line(unsigned int i) const;
00172                         virtual Triangle triangle(unsigned int i) const;
00173 
00174                         virtual GiNaC::ex repr(Repr_format format = SUBS_PERFORMED) const;
00175                         virtual const std::string str() const;
00176 
00177                         virtual GiNaC::ex integrate(GiNaC::ex f, Repr_format format = SUBS_PERFORMED);
00178                         virtual Tetrahedron* copy() const;
00179 
00180         };
00181 
00182         class ReferenceTetrahedron : public Tetrahedron
00183         {
00184                 public:
00185                         ReferenceTetrahedron(const std::string & subscript = "");
00186                         ReferenceTetrahedron(const ReferenceTetrahedron& tetrahedron);
00187                         virtual ~ReferenceTetrahedron(){}
00188 
00189                         virtual const std::string str() const;
00190 
00191                         virtual GiNaC::ex integrate(GiNaC::ex f, Repr_format format = SUBS_PERFORMED);
00192                         virtual ReferenceTetrahedron* copy() const;
00193         };
00194 
00195         class Box: public Polygon
00196         {
00197                 public:
00198                         Box(GiNaC::ex p0, GiNaC::ex p1, const std::string & subscript="");
00199                         Box(GiNaC::ex p0, GiNaC::ex p1, GiNaC::ex p2, GiNaC::ex p3, GiNaC::ex p4, GiNaC::ex p5, GiNaC::ex p6, GiNaC::ex p7, const std::string & subscript="");
00200                         Box(const Box& box);
00201                         Box(){}
00202                         virtual ~Box(){}
00203 
00204                         virtual unsigned int no_space_dim() const;
00205 
00206                         virtual Line line(unsigned int i) const;
00207                         virtual Rectangle rectangle(unsigned int i) const;
00208 
00209                         virtual GiNaC::ex repr(Repr_format format = SUBS_PERFORMED) const;
00210                         virtual const std::string str() const;
00211 
00212                         virtual GiNaC::ex integrate(GiNaC::ex f, Repr_format format = SUBS_PERFORMED);
00213                         virtual Box* copy() const;
00214         };
00215 
00216         class ReferenceBox: public Box
00217         {
00218                 public:
00219                         ReferenceBox(const std::string & subscript = "");
00220                         ReferenceBox(const ReferenceBox& box);
00221                         virtual ~ReferenceBox(){}
00222 
00223                         virtual const std::string str() const;
00224                         virtual ReferenceBox* copy() const;
00225         };
00226 
00227         class Simplex : public Polygon
00228         {
00229                 public:
00230                         Simplex(GiNaC::lst vertices, const std::string & subscript = "");
00231                         Simplex(const Simplex& simplex);
00232                         virtual ~Simplex(){}
00233 
00234                         virtual unsigned int no_space_dim() const;
00235 
00236                         virtual GiNaC::ex repr(Repr_format format = SUBS_PERFORMED) const;
00237                         virtual const std::string str() const;
00238 
00239                         virtual GiNaC::ex integrate(GiNaC::ex f, Repr_format format = SUBS_PERFORMED);
00240                         Simplex sub_simplex(unsigned int i);
00241                         virtual Simplex* copy() const;
00242         };
00243 
00244         /*
00245         class ReferenceSimplex : public Simplex {
00246           public:
00247                 ReferenceSimplex(const std::string & subscript = "");
00248                 virtual ~ReferenceSimplex(){}
00249 
00250         virtual std::string str();
00251 
00252         virtual GiNaC::ex integrate(GiNaC::ex f, Repr_format format = SUBS_PERFORMED);
00253         };
00254         */
00255 
00256         // ---- Some tools for Polygons
00257 
00258         // FIXME: change to barycenter(Triangle&)
00259         // FIXME:       and barycenter(Tetrahedron&)
00260         GiNaC::ex barycenter_line(GiNaC::ex p0, GiNaC::ex p1);
00261         GiNaC::ex barycenter_triangle(GiNaC::ex p0, GiNaC::ex p1, GiNaC::ex p2);
00262         GiNaC::ex barycenter_tetrahedron(GiNaC::ex p0, GiNaC::ex p1, GiNaC::ex p2, GiNaC::ex p3);
00263         GiNaC::ex barycenter(Simplex& simplex);
00264         GiNaC::lst bezier_ordinates(Line& line, unsigned int d);
00265         GiNaC::lst bezier_ordinates(Triangle& triangle, unsigned int d);
00266         GiNaC::lst bezier_ordinates(Tetrahedron& tetrahedra, unsigned int d);
00267         GiNaC::lst interior_coordinates(Line& line, unsigned int d);
00268         GiNaC::lst interior_coordinates(Triangle& triangle, unsigned int d);
00269         GiNaC::lst interior_coordinates(Tetrahedron& tetrahedra, unsigned int d);
00270 
00271         // polynom of arbitrary order on a line, a triangle,
00272         // or a tetrahedron using the Bernstein basis
00273         GiNaC::ex bernstein(unsigned int order, Polygon& p, const std::string & a);
00274 
00275         // vector polynom of arbitrary order on a line, a triangle,
00276         // or a tetrahedron using the Bernstein basis
00277         GiNaC::lst bernsteinv(unsigned int no_fields, unsigned int order, Polygon& p, const std::string & a);
00278 
00279         GiNaC::lst normal(Triangle&, unsigned int i);
00280         GiNaC::lst normal(Tetrahedron&, unsigned int i);
00281 
00282         GiNaC::lst tangent(Triangle&, unsigned int i);
00283 
00284 }
00285 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines