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