Source: k2dgrflow/k2dborderbase.h


Annotated List
Files
Globals
Hierarchy
Index
/***************************************************************************
                          k2dborderbase.h  -  description
                             -------------------
    begin                : Fri Apr 27 2001
    copyright            : (C) 2001 by benny
    email                : bm@cage.rug.ac.be
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/
#ifndef _K2DBORDERBASE_H_
#define _K2DBORDERBASE_H_

#include <kglobal.h>
#include <qarray.h>
#include <qtextstream.h>
#include <qpainter.h>

/** BorderPoint is the datatype we use to store points of the domain, we store the coordinates (2 dimensions)
    and the trianglesize (of the net in that point) if known
    */
class BorderPoint {
public:
     /** create a borderpoint with the 2 coordinates and the trianglesize in the coord
       */
     BorderPoint(double coord1, double coord2, double triaSize=1.0);
     /** create a borderpoint with another point
        */
     BorderPoint(const BorderPoint &bp) ;
     /** return the first coordinate
        */
     double coord1(){return data[0];};
     /** return the second coordinate
        */
     double coord2(){return data[1];};
     /** return the trianglesize set in a certain point
        */
     double triaSize(){return data[2];};
     /** set the trianglesize in a certain point. Changes present value
        */
     void setTriaSize(double &size){data[2] = size ;};
     /** return depending on index coord1(index=0), coord2 (index=1) or trianglesize (index=2)
        */
     double &at(uint index) const  {return data[index];} ;
     /** duplicate the given borderpoint a.
        */
     void duplicate(BorderPoint &a){data[0]=a.data[0]; data[1]=a.data[1]; data[2]=a.data[2];};
     /** are 2 points equal? only looks at the coordinates, NOT at the trianglesize
        */
     bool operator==( const BorderPoint &a ) const { return (data[0]==a.data[0] && data[1]==a.data[1]) ; }
     /** are 2 points not equal? only looks at the coordinate, NOT at the trianglesize
        */
     bool operator!=( const BorderPoint &a ) const { return !(data[0]==a.data[0] && data[1]==a.data[1]) ; }

private:
     /** data representation with an array of doubles
       */
     QArray<double> data;
};

/**Representation of the Border. We define first the astract class BorderBase
  *  wich will be the basis of all possible borders a domain can have.
  *  It defines the common interface of all borders.
  *@author benny
  */
class K2dBorderBase {
public:
    /**every border is of a certain type
      */
    enum BorderType{Line,SinCurve};
    /** BorderCondition is a state of the border. Every Border has a BorderCondition
                        */
    enum BorderCondition {NotSet, DIRICHLET, NEUMANN , ROBIN  };
    /** when we have a dirichletcondition, we distinguish 2 types for now
       */
    enum BorderCondDirType{DirZ, DirAx_B};

    /** Constructor, a border is constructed with bordercondition NotSet
      */
    K2dBorderBase();
    virtual ~K2dBorderBase(){};
    /** Draw the border on a painter, also meshed or not
      */
    virtual  void draw(QPainter*, bool meshed = false )=0;
    /** Every border has a first and a last point, pointers to these are returned
      */
    virtual BorderPoint* firstPoint() const {return points[0];} ;
    /** Every border has a first and a last point, pointers to these are returned
      */
    virtual BorderPoint* lastPoint() const {return points[points.size()-1];} ;
    /** return a pointer to a certain point of the border, defined by index
      */
    BorderPoint* atPoint(uint index) const { return points.at(index) ;};
    /** see if a certain given point is on the border (or the meshed border if meshed = true )
          Remark : since we work with double, we take the defined TOPONUMEPS as allowed difference to be equal */
    virtual bool onBorder(const double &co1, const double &co2, bool meshed) const=0;
    /** see if a given point is an endpoint of the border (a corner)
      */
    virtual bool endPoint(const double &co1, const double &co2) ;
    /**we want to be able to retrieve the min and maximum values of border
         coordIndex is the index, eg 0 for the first, 1 for the second; and value is the present min or max
         the function changes this if necessary. */
    virtual void minCo(uint coordIndex, double &valueMin) const=0;
    virtual void maxCo(uint coordIndex, double &valueMax) const=0;
    /** Return the number of points we have on our border for the starting mesh
      */
    uint nrPointsOnBorder() const {return points.count() ; };
    /** change the bordercondition to bc, if dirichlet, you must specify a and b parameter as in g(x,z) = ax + b, if not
         these are unimportant
         PS : this has to be changed later to a bordercondition object that encapsulates everything                             */
    void setBorderCond(BorderCondition bc, BorderCondDirType dirT=DirZ, double a=0,
                       double b=0) {borderCond = bc; dirType = dirT ; dirLineA=a ; dirLineB=b ;};
    /** return the present bordercondition
      */
    BorderCondition getBorderCondition(){return borderCond;};
    /**depending of the bordercondition, there are associated functions
          -> if dirichlet : a g_dir()function, value on dir border : u(x,y) = g_dir(x,y)
          -> if neuman : a neuman g_neu function :  Du(u,y) = g_neu
          -> if robin : a combination.
       For now only dirichlet and neuman are implemented.
       */
    virtual double gDirichlet(const double &co1, const double &co2) const;
    virtual double gNeumann(const double &co1, const double &co2) const;
    /** we allow for now two types of dirichlet border condition. when it is g(x,z)=z, we return true
      */
    BorderCondDirType getBorderCondDirType(){return dirType ; };
    /** return the A parameter of a dirichletcondition ax + b
         should be replaced later by a function that returns a Bordercondition object */
    double getBorderCondDirLineA(){return dirLineA ; };
    /** return the B parameter of a dirichletcondition ax + b
         should be replaced later by a function that returns a Bordercondition object */
    double getBorderCondDirLineB(){return dirLineB ; };
    /** return the type of the Border (something like the name)
      */
    virtual BorderType type()=0;

    /** write a border to the ouputstream in a nice text format, a virtual function
         it is not possible to make the << a virtual function, so a virtual function has
         to be provided. In the childclasses this should just do a call to <<                 */
    virtual void printBorder(QTextStream &){};

protected:
    /** Points, every border consists of a number of points we keep data about
      */
    QArray<BorderPoint*> points;
    /** Every Border has an assotiated bordercondition
         For now we integrate the datastructure of a bordercondition into the BorderBase object. */
    BorderCondition borderCond;
    /** We allow two dirichletconditions : g(x,z)=z and g(x,z)=ax + b. If the first, we set DirType = DirZ, otherwise DirAx_B.
         This has only meaning when we have a dirichletcondition
         if condition is a dirichletcondition of second type, so first order in x parameter, then 2 parameters, a and b must be ginven */
    BorderCondDirType dirType;
    double dirLineA;
    double dirLineB;
};

/**Representation of a line as a Border. Inherits the astract class BorderBase
  *  a line is defined by a begin and an endpoint.
  *@author benny
  */
class K2dBorderLine : public K2dBorderBase {
public:
    /** to prevent making two functions for begin and endpoint, we introduce a
         enumerator that makes the difference between the two                          */
    enum LinePoint {BeginPoint , EndPoint };
    /** construct an empty Line
      */
    K2dBorderLine();
    /** construct a line by giving the Begin and the end point.
      */
    K2dBorderLine(const BorderPoint& , const BorderPoint&);

    virtual ~K2dBorderLine();
    /** draw on a painter the line
      */
    virtual void draw(QPainter*,bool meshed = false  );
    /** Implementation of first and lastpoint of base class
      */
    virtual BorderPoint* lastPoint() const  {return points[1];} ;
    /** Change the line by giving another point for begin or end.
         Last parameter is the LinePoint. If not given BeginPoint is taken */
    void changePoint( BorderPoint& , LinePoint = BeginPoint);
    /** see if a certain given point is on the border
          Remark : since we work with double, we take the defined TOPONUMEPS as allowed difference to be equal */
    virtual bool onBorder(const double &co1, const double &co2, bool meshed) const;
    /**we want to be able to retrieve the min and maximum values of border
         coordIndex is the index, eg 0 for the first, 1 for the second; and value is the present min or max
         the function changes this if necessary. */
    virtual void minCo(uint coordIndex, double &valueMin) const;
    virtual void maxCo(uint coordIndex, double &valueMax) const;
    /**  Return trianglesize in begin or endpoint, is default initialized on construction by 1, so 1 is returned if
         never set before */
    double triaSize(LinePoint = BeginPoint);
    /** Change the trianglesize in begin or endpoint
      */
    void changeTriaSize(double size, LinePoint = BeginPoint);
    /** return the type of the Border (something like the name)
      */
    virtual BorderType type(){return Line ; };
    /** Implementation of base class printborder
      */
    virtual void printBorder(QTextStream &);
    /**write a line to the ouputstream in a nice text format
      */
    friend QTextStream &operator<<( QTextStream &,  const K2dBorderLine & );

};

/**Representation of a sinus curve as a Border. Inherits the astract class BorderBase
  *  the sine is prescribed by 4 variable, always starts at x=0.
  *@author benny
  */
class K2dBorderSinCurve : public K2dBorderBase {
public:
    /** construct an sine curve with length L, slope a, amplitude V, nr of hills n, offset b
      */
    K2dBorderSinCurve(double L, double a, double V, uint n, double b );
    virtual ~K2dBorderSinCurve();
    /** draw on a painter the sinus
      */
    virtual void draw(QPainter* ,bool meshed = false );
    /** Change the sine in one action. This automatically recalculates interval points
         One action for less overhead in recalculating interval */
    void changeSinCurve( double L, double a, double V, uint n, double b );
    /** see if a certain given point is on the border
          Remark : since we work with double, we take the defined TOPONUMEPS as allowed difference to be equal */
    virtual bool onBorder(const double &co1, const double &co2 , bool meshed) const;
    /**we want to be able to retrieve the min and maximum values of border
         coordIndex is the index, eg 0 for the first, 1 for the second; and value is the present min or max
         the function changes this if necessary. */
    virtual void minCo(uint coordIndex, double &valueMin) const;
    virtual void maxCo(uint coordIndex, double &valueMax) const;
    /**function to retrieve internal data sine
      */
    double getLength() const {return length;};
    /**function to retrieve internal data sine
      */
    double getSlope() const {return slope;};
    /**function to retrieve internal data sine
      */
    double getAmplitude() const {return amplitude;};
    /**function to retrieve internal data sine
      */
    double getOffset() const {return offset;};
    /**function to retrieve internal data sine
      */
    int getHills() const {return hills;};
    /** return the number of mesh interval points currently set on the curve, default = 0
      */
    int nrMeshIntervalPoints() const {return nrMeshPoints;};
    /** set the meshinterval to a certain value (default = 0), the points are recalculated if changed.
         beware to give value >=0 */
    void setNrMeshInterval(int);
    /** return how the curve is transversed, false is normal t from 0 to 1, true is transverse, t from 1 to 0
      */
    bool reverseValue() const {return reverse ;};
    /** set how the curve is transversed
      */
    void setReverse(bool );
    /**  Return trianglesize in meshpoints on the sine, is default initialized on construction by 1, so 1 is returned if
         never set before */
    double triaSize() const ;
    /** Change the trianglesize for the meshpoints
      */
    void changeTriaSize(double size) ;
    /** return the type of the Border (something like the name)
      */
    virtual BorderType type(){return SinCurve ; };
    /** Implementation of base class printBorder
      */
    virtual void printBorder(QTextStream &);
    /**write a line to the ouputstream in a nice text format
      */
    friend QTextStream &operator<<( QTextStream &,  const K2dBorderSinCurve & );

private:
   double length, slope, amplitude, offset ;
   int hills ;
   int nrMeshPoints;
   /** bool to notice how the sinecurve is transversed
     */
   bool reverse;
   /** internal functioni that computes first coordinate with a given t, parameter between 0 .. 1
     */
   double value1(double t) const;
   /** internal functioni that computes second coordinate with a given t, parameter between 0 .. 1
     */
   double value2(double t) const;
   /** internal function that recalculates the value of the points between begin and endpoint in the mesh
     */
   void calcMeshIntervalPoints();
};

#endif

Generated by: benny@okidoki on Thu Jun 21 10:41:51 2001, using kdoc 2.0a53.