/[escript]/branches/more_shared_ptrs_from_1812/escript/src/Data.h
ViewVC logotype

Diff of /branches/more_shared_ptrs_from_1812/escript/src/Data.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

trunk/esys2/escript/src/Data/Data.h revision 121 by jgs, Fri May 6 04:26:16 2005 UTC trunk/escript/src/Data/Data.h revision 286 by gross, Thu Dec 1 06:40:20 2005 UTC
# Line 20  Line 20 
20    
21  #include "escript/Data/DataAbstract.h"  #include "escript/Data/DataAbstract.h"
22  #include "escript/Data/DataTagged.h"  #include "escript/Data/DataTagged.h"
23    #include "escript/Data/DataAlgorithm.h"
24  #include "escript/Data/FunctionSpace.h"  #include "escript/Data/FunctionSpace.h"
25  #include "escript/Data/BinaryOp.h"  #include "escript/Data/BinaryOp.h"
26  #include "escript/Data/UnaryOp.h"  #include "escript/Data/UnaryOp.h"
# Line 43  extern "C" { Line 44  extern "C" {
44  namespace escript {  namespace escript {
45    
46  //  //
47  // Forward declaration for various implimentations of Data.  // Forward declaration for various implementations of Data.
48  class DataEmpty;  class DataEmpty;
49  class DataConstant;  class DataConstant;
50  class DataTagged;  class DataTagged;
# Line 205  class Data { Line 206  class Data {
206         const boost::python::tuple& shape=boost::python::make_tuple(),         const boost::python::tuple& shape=boost::python::make_tuple(),
207         const FunctionSpace& what=FunctionSpace(),         const FunctionSpace& what=FunctionSpace(),
208         bool expanded=false);         bool expanded=false);
209      /**
210         \brief
211         Destructor
212      */
213      ~Data();
214    
215    /**    /**
216       \brief       \brief
# Line 241  class Data { Line 247  class Data {
247    
248    /**    /**
249       \brief       \brief
250         Fills the expanded Data object from values of a python numarray object.
251      */
252      void
253      fillFromNumArray(const boost::python::numeric::array);
254    
255      /**
256         \brief
257         Return the tag number associated with the given data-point.
258    
259         The data-point number here corresponds to the data-point number in the
260         numarray returned by convertToNumArray.
261      */
262      int
263      getTagNumber(int dpno);
264    
265      /**
266         \brief
267       Return the C wrapper for the Data object.       Return the C wrapper for the Data object.
268    */    */
269    escriptDataC    escriptDataC
# Line 540  class Data { Line 563  class Data {
563       \brief       \brief
564       Interpolates this onto the given functionspace and returns       Interpolates this onto the given functionspace and returns
565       the result as a Data object.       the result as a Data object.
566         *
567    */    */
568    Data    Data
569    interpolate(const FunctionSpace& functionspace) const;    interpolate(const FunctionSpace& functionspace) const;
# Line 548  class Data { Line 572  class Data {
572       \brief       \brief
573       Calculates the gradient of the data at the data points of functionspace.       Calculates the gradient of the data at the data points of functionspace.
574       If functionspace is not present the function space of Function(getDomain()) is used.       If functionspace is not present the function space of Function(getDomain()) is used.
575         *
576    */    */
577    Data    Data
578    gradOn(const FunctionSpace& functionspace) const;    gradOn(const FunctionSpace& functionspace) const;
# Line 558  class Data { Line 583  class Data {
583    /**    /**
584       \brief       \brief
585       Calculate the integral over the function space domain.       Calculate the integral over the function space domain.
586         *
587    */    */
588    boost::python::numeric::array    boost::python::numeric::array
589    integrate() const;    integrate() const;
# Line 565  class Data { Line 591  class Data {
591    /**    /**
592       \brief       \brief
593       Return a Data with a 1 for +ive values and a 0 for 0 or -ive values.       Return a Data with a 1 for +ive values and a 0 for 0 or -ive values.
594         *
595    */    */
596    Data    Data
597    wherePositive() const;    wherePositive() const;
# Line 572  class Data { Line 599  class Data {
599    /**    /**
600       \brief       \brief
601       Return a Data with a 1 for -ive values and a 0 for +ive or 0 values.       Return a Data with a 1 for -ive values and a 0 for +ive or 0 values.
602         *
603    */    */
604    Data    Data
605    whereNegative() const;    whereNegative() const;
# Line 579  class Data { Line 607  class Data {
607    /**    /**
608       \brief       \brief
609       Return a Data with a 1 for +ive or 0 values and a 0 for -ive values.       Return a Data with a 1 for +ive or 0 values and a 0 for -ive values.
610         *
611    */    */
612    Data    Data
613    whereNonNegative() const;    whereNonNegative() const;
# Line 586  class Data { Line 615  class Data {
615    /**    /**
616       \brief       \brief
617       Return a Data with a 1 for -ive or 0 values and a 0 for +ive values.       Return a Data with a 1 for -ive or 0 values and a 0 for +ive values.
618         *
619    */    */
620    Data    Data
621    whereNonPositive() const;    whereNonPositive() const;
# Line 593  class Data { Line 623  class Data {
623    /**    /**
624       \brief       \brief
625       Return a Data with a 1 for 0 values and a 0 for +ive or -ive values.       Return a Data with a 1 for 0 values and a 0 for +ive or -ive values.
626         *
627    */    */
628    Data    Data
629    whereZero() const;    whereZero() const;
# Line 600  class Data { Line 631  class Data {
631    /**    /**
632       \brief       \brief
633       Return a Data with a 0 for 0 values and a 1 for +ive or -ive values.       Return a Data with a 0 for 0 values and a 1 for +ive or -ive values.
634         *
635    */    */
636    Data    Data
637    whereNonZero() const;    whereNonZero() const;
638    
639    /**    /**
640       \brief       \brief
641       Return the sin of each data point of this Data object.       Return the maximum absolute value of this Data object.
642         *
643      */
644      double
645      Lsup() const;
646    
647      /**
648         \brief
649         Return the minimum absolute value of this Data object.
650         *
651      */
652      double
653      Linf() const;
654    
655      /**
656         \brief
657         Return the maximum value of this Data object.
658         *
659      */
660      double
661      sup() const;
662    
663      /**
664         \brief
665         Return the minimum value of this Data object.
666         *
667      */
668      double
669      inf() const;
670    
671      /**
672         \brief
673         Return the absolute value of each data point of this Data object.
674         *
675    */    */
676    Data    Data
677    sin() const;    abs() const;
678    
679    /**    /**
680       \brief       \brief
681       Return the cos of each data point of this Data object.       Return the maximum value of each data point of this Data object.
682         *
683    */    */
684    Data    Data
685    cos() const;    maxval() const;
686    
687    /**    /**
688       \brief       \brief
689       Return the tan of each data point of this Data object.       Return the minimum value of each data point of this Data object.
690         *
691    */    */
692    Data    Data
693    tan() const;    minval() const;
694    
695    /**    /**
696       \brief       \brief
697       Return the log to base 10 of each data point of this Data object.       Return the (sample number, data-point number) of the data point with
698         the minimum value in this Data object.
699      */
700      const boost::python::tuple
701      mindp() const;
702    
703      void
704      calc_mindp(int& SampleNo,
705                 int& DataPointNo) const;
706    
707      /**
708         \brief
709         Return the sign of each data point of this Data object.
710         -1 for negative values, zero for zero values, 1 for positive values.
711         *
712    */    */
713    Data    Data
714    log() const;    sign() const;
715    
716    /**    /**
717       \brief       \brief
718       Return the natural log of each data point of this Data object.       Transpose each data point of this Data object around the given axis.
719         --* not implemented yet *--
720         *
721    */    */
722    Data    Data
723    ln() const;    transpose(int axis) const;
724    
725    /**    /**
726       \brief       \brief
727       Return the maximum absolute value of this Data object.       Calculate the trace of each data point of this Data object.
728         sum(A[i,i,i,i])
729         *
730    */    */
731    double    Data
732    Lsup() const;    trace() const;
733    
734    /**    /**
735       \brief       \brief
736       Return the minimum absolute value of this Data object.       Return the sin of each data point of this Data object.
737         *
738    */    */
739    double    Data
740    Linf() const;    sin() const;
741    
742    /**    /**
743       \brief       \brief
744       Return the maximum value of this Data object.       Return the cos of each data point of this Data object.
745         *
746    */    */
747    double    Data
748    sup() const;    cos() const;
749    
750    /**    /**
751       \brief       \brief
752       Return the minimum value of this Data object.       Return the tan of each data point of this Data object.
753         *
754    */    */
755    double    Data
756    inf() const;    tan() const;
757    
758    /**    /**
759       \brief       \brief
760       Return the absolute value of each data point of this Data object.       Return the asin of each data point of this Data object.
761         *
762    */    */
763    Data    Data
764    abs() const;    asin() const;
765    
766    /**    /**
767       \brief       \brief
768       Return the maximum value of each data point of this Data object.       Return the acos of each data point of this Data object.
769         *
770    */    */
771    Data    Data
772    maxval() const;    acos() const;
773    
774    /**    /**
775       \brief       \brief
776       Return the minimum value of each data point of this Data object.       Return the atan of each data point of this Data object.
777         *
778    */    */
779    Data    Data
780    minval() const;    atan() const;
781    
782    /**    /**
783       \brief       \brief
784       Return the (sample number, data-point number) of the data point with       Return the sinh of each data point of this Data object.
785       the minimum value in this Data object.       *
786    */    */
787    const boost::python::tuple    Data
788    mindp() const;    sinh() const;
789    
790    /**    /**
791       \brief       \brief
792       Return the length of each data point of this Data object.       Return the cosh of each data point of this Data object.
793       sqrt(sum(A[i,j,k,l]^2))       *
794    */    */
795    Data    Data
796    length() const;    cosh() const;
797    
798    /**    /**
799       \brief       \brief
800       Return the sign of each data point of this Data object.       Return the tanh of each data point of this Data object.
801       -1 for negative values, zero for zero values, 1 for positive values.       *
802    */    */
803    Data    Data
804    sign() const;    tanh() const;
805    
806    /**    /**
807      \brief       \brief
808      Transpose each data point of this Data object around the given axis.       Return the asinh of each data point of this Data object.
809      --* not implemented yet *--       *
810    */    */
811    Data    Data
812    transpose(int axis) const;    asinh() const;
813    
814    /**    /**
815      \brief       \brief
816      Calculate the trace of each data point of this Data object.       Return the acosh of each data point of this Data object.
817      sum(A[i,i,i,i])       *
818    */    */
819    Data    Data
820    trace() const;    acosh() const;
821    
822    /**    /**
823      \brief       \brief
824      Return the exponential function of each data point of this Data object.       Return the atanh of each data point of this Data object.
825         *
826      */
827      Data
828      atanh() const;
829    
830      /**
831         \brief
832         Return the log to base 10 of each data point of this Data object.
833         *
834      */
835      Data
836      log10() const;
837    
838      /**
839         \brief
840         Return the natural log of each data point of this Data object.
841         *
842      */
843      Data
844      log() const;
845    
846      /**
847         \brief
848         Return the exponential function of each data point of this Data object.
849         *
850    */    */
851    Data    Data
852    exp() const;    exp() const;
853    
854    /**    /**
855      \brief       \brief
856      Return the square root of each data point of this Data object.       Return the square root of each data point of this Data object.
857         *
858    */    */
859    Data    Data
860    sqrt() const;    sqrt() const;
861    
862    /**    /**
863      \brief       \brief
864      Return the negation of each data point of this Data object.       Return the negation of each data point of this Data object.
865         *
866    */    */
867    Data    Data
868    neg() const;    neg() const;
869    
870    /**    /**
871      \brief       \brief
872      Return the identity of each data point of this Data object.       Return the identity of each data point of this Data object.
873      Simply returns this object unmodified.       Simply returns this object unmodified.
874         *
875    */    */
876    Data    Data
877    pos() const;    pos() const;
# Line 762  class Data { Line 881  class Data {
881       Return the given power of each data point of this Data object.       Return the given power of each data point of this Data object.
882    
883       \param right Input - the power to raise the object to.       \param right Input - the power to raise the object to.
884         *
885    */    */
886    Data    Data
887    powD(const Data& right) const;    powD(const Data& right) const;
888    
889    /**    /**
890     * \brief       \brief
891     * Return the given power of each data point of this boost python object.       Return the given power of each data point of this boost python object.
892     *      
893     * \param right Input - the power to raise the object to.       \param right Input - the power to raise the object to.
894         *
895     */     */
896    Data    Data
897    powO(const boost::python::object& right) const;    powO(const boost::python::object& right) const;
898    
899    /**    /**
900      \brief       \brief
901      writes the object to a file in the DX file format       writes the object to a file in the DX file format
902    */    */
903    void    void
904    saveDX(std::string fileName) const;    saveDX(std::string fileName) const;
905    
906    /**    /**
907      \brief       \brief
908      writes the object to a file in the VTK file format       writes the object to a file in the VTK file format
909    */    */
910    void    void
911    saveVTK(std::string fileName) const;    saveVTK(std::string fileName) const;
# Line 793  class Data { Line 914  class Data {
914       \brief       \brief
915       Overloaded operator +=       Overloaded operator +=
916       \param right - Input - The right hand side.       \param right - Input - The right hand side.
917         *
918    */    */
919    Data& operator+=(const Data& right);    Data& operator+=(const Data& right);
920    Data& operator+=(const boost::python::object& right);    Data& operator+=(const boost::python::object& right);
# Line 801  class Data { Line 923  class Data {
923       \brief       \brief
924       Overloaded operator -=       Overloaded operator -=
925       \param right - Input - The right hand side.       \param right - Input - The right hand side.
926         *
927    */    */
928    Data& operator-=(const Data& right);    Data& operator-=(const Data& right);
929    Data& operator-=(const boost::python::object& right);    Data& operator-=(const boost::python::object& right);
# Line 809  class Data { Line 932  class Data {
932       \brief       \brief
933       Overloaded operator *=       Overloaded operator *=
934       \param right - Input - The right hand side.       \param right - Input - The right hand side.
935         *
936    */    */
937    Data& operator*=(const Data& right);    Data& operator*=(const Data& right);
938    Data& operator*=(const boost::python::object& right);    Data& operator*=(const boost::python::object& right);
# Line 817  class Data { Line 941  class Data {
941       \brief       \brief
942       Overloaded operator /=       Overloaded operator /=
943       \param right - Input - The right hand side.       \param right - Input - The right hand side.
944         *
945    */    */
946    Data& operator/=(const Data& right);    Data& operator/=(const Data& right);
947    Data& operator/=(const boost::python::object& right);    Data& operator/=(const boost::python::object& right);
# Line 882  class Data { Line 1007  class Data {
1007       Return a Data object containing the specified slice of       Return a Data object containing the specified slice of
1008       this Data object.       this Data object.
1009       \param region - Input - Region to copy.       \param region - Input - Region to copy.
1010         *
1011    */    */
1012    Data    Data
1013    getSlice(const DataArrayView::RegionType& region) const;    getSlice(const DataArrayView::RegionType& region) const;
# Line 892  class Data { Line 1018  class Data {
1018       Data object.       Data object.
1019       \param value - Input - Data to copy from.       \param value - Input - Data to copy from.
1020       \param region - Input - Region to copy.       \param region - Input - Region to copy.
1021         *
1022    */    */
1023    void    void
1024    setSlice(const Data& value,    setSlice(const Data& value,
# Line 939  class Data { Line 1066  class Data {
1066       Perform the specified reduction algorithm on every element of every data point in       Perform the specified reduction algorithm on every element of every data point in
1067       this Data object according to the given function and return the single value result.       this Data object according to the given function and return the single value result.
1068    */    */
1069    template <class UnaryFunction>    template <class BinaryFunction>
1070    inline    inline
1071    double    double
1072    algorithm(UnaryFunction operation) const;    algorithm(BinaryFunction operation,
1073                double initial_value) const;
1074    
1075    /**    /**
1076       \brief       \brief
# Line 951  class Data { Line 1079  class Data {
1079       one value - the result of the reduction operation on the corresponding data-point in       one value - the result of the reduction operation on the corresponding data-point in
1080       this Data object       this Data object
1081    */    */
1082    template <class UnaryFunction>    template <class BinaryFunction>
1083    inline    inline
1084    Data    Data
1085    dp_algorithm(UnaryFunction operation) const;    dp_algorithm(BinaryFunction operation,
1086                   double initial_value) const;
1087    
1088    /**    /**
1089       \brief       \brief
# Line 1021  class Data { Line 1150  class Data {
1150    // pointer to the actual data object    // pointer to the actual data object
1151    boost::shared_ptr<DataAbstract> m_data;    boost::shared_ptr<DataAbstract> m_data;
1152    
1153      //
1154      // pointer to the internal profiling data
1155      struct profDataEntry *profData;
1156    
1157  };  };
1158    
1159  template <class IValueType>  template <class IValueType>
# Line 1316  Data::unaryOp(UnaryFunction operation) Line 1449  Data::unaryOp(UnaryFunction operation)
1449    object (*this) is a rank n Data object, and returned object is a scalar.    object (*this) is a rank n Data object, and returned object is a scalar.
1450    Calls escript::algorithm.    Calls escript::algorithm.
1451  */  */
1452  template <class UnaryFunction>  template <class BinaryFunction>
1453  inline  inline
1454  double  double
1455  Data::algorithm(UnaryFunction operation) const  Data::algorithm(BinaryFunction operation, double initial_value) const
1456  {  {
1457    if (isExpanded()) {    if (isExpanded()) {
1458      DataExpanded* leftC=dynamic_cast<DataExpanded*>(m_data.get());      DataExpanded* leftC=dynamic_cast<DataExpanded*>(m_data.get());
1459      EsysAssert((leftC!=0), "Programming error - casting to DataExpanded.");      EsysAssert((leftC!=0), "Programming error - casting to DataExpanded.");
1460      return escript::algorithm(*leftC,operation);      return escript::algorithm(*leftC,operation,initial_value);
1461    } else if (isTagged()) {    } else if (isTagged()) {
1462      DataTagged* leftC=dynamic_cast<DataTagged*>(m_data.get());      DataTagged* leftC=dynamic_cast<DataTagged*>(m_data.get());
1463      EsysAssert((leftC!=0), "Programming error - casting to DataTagged.");      EsysAssert((leftC!=0), "Programming error - casting to DataTagged.");
1464      return escript::algorithm(*leftC,operation);      return escript::algorithm(*leftC,operation,initial_value);
1465    } else if (isConstant()) {    } else if (isConstant()) {
1466      DataConstant* leftC=dynamic_cast<DataConstant*>(m_data.get());      DataConstant* leftC=dynamic_cast<DataConstant*>(m_data.get());
1467      EsysAssert((leftC!=0), "Programming error - casting to DataConstant.");      EsysAssert((leftC!=0), "Programming error - casting to DataConstant.");
1468      return escript::algorithm(*leftC,operation);      return escript::algorithm(*leftC,operation,initial_value);
1469    }    }
1470    return 0;    return 0;
1471  }  }
# Line 1345  Data::algorithm(UnaryFunction operation) Line 1478  Data::algorithm(UnaryFunction operation)
1478    rank 0 Data object.    rank 0 Data object.
1479    Calls escript::dp_algorithm.    Calls escript::dp_algorithm.
1480  */  */
1481  template <class UnaryFunction>  template <class BinaryFunction>
1482  inline  inline
1483  Data  Data
1484  Data::dp_algorithm(UnaryFunction operation) const  Data::dp_algorithm(BinaryFunction operation, double initial_value) const
1485  {  {
1486    Data result(0,DataArrayView::ShapeType(),getFunctionSpace(),isExpanded());    Data result(0,DataArrayView::ShapeType(),getFunctionSpace(),isExpanded());
1487    if (isExpanded()) {    if (isExpanded()) {
# Line 1356  Data::dp_algorithm(UnaryFunction operati Line 1489  Data::dp_algorithm(UnaryFunction operati
1489      DataExpanded* resultE=dynamic_cast<DataExpanded*>(result.m_data.get());      DataExpanded* resultE=dynamic_cast<DataExpanded*>(result.m_data.get());
1490      EsysAssert((dataE!=0), "Programming error - casting data to DataExpanded.");      EsysAssert((dataE!=0), "Programming error - casting data to DataExpanded.");
1491      EsysAssert((resultE!=0), "Programming error - casting result to DataExpanded.");      EsysAssert((resultE!=0), "Programming error - casting result to DataExpanded.");
1492      escript::dp_algorithm(*dataE,*resultE,operation);      escript::dp_algorithm(*dataE,*resultE,operation,initial_value);
1493    } else if (isTagged()) {    } else if (isTagged()) {
1494      DataTagged* dataT=dynamic_cast<DataTagged*>(m_data.get());      DataTagged* dataT=dynamic_cast<DataTagged*>(m_data.get());
1495      DataTagged* resultT=dynamic_cast<DataTagged*>(result.m_data.get());      DataTagged* resultT=dynamic_cast<DataTagged*>(result.m_data.get());
1496      EsysAssert((dataT!=0), "Programming error - casting data to DataTagged.");      EsysAssert((dataT!=0), "Programming error - casting data to DataTagged.");
1497      EsysAssert((resultT!=0), "Programming error - casting result to DataTagged.");      EsysAssert((resultT!=0), "Programming error - casting result to DataTagged.");
1498      escript::dp_algorithm(*dataT,*resultT,operation);      escript::dp_algorithm(*dataT,*resultT,operation,initial_value);
1499    } else if (isConstant()) {    } else if (isConstant()) {
1500      DataConstant* dataC=dynamic_cast<DataConstant*>(m_data.get());      DataConstant* dataC=dynamic_cast<DataConstant*>(m_data.get());
1501      DataConstant* resultC=dynamic_cast<DataConstant*>(result.m_data.get());      DataConstant* resultC=dynamic_cast<DataConstant*>(result.m_data.get());
1502      EsysAssert((dataC!=0), "Programming error - casting data to DataConstant.");      EsysAssert((dataC!=0), "Programming error - casting data to DataConstant.");
1503      EsysAssert((resultC!=0), "Programming error - casting result to DataConstant.");      EsysAssert((resultC!=0), "Programming error - casting result to DataConstant.");
1504      escript::dp_algorithm(*dataC,*resultC,operation);      escript::dp_algorithm(*dataC,*resultC,operation,initial_value);
1505    }    }
1506    return result;    return result;
1507  }  }

Legend:
Removed from v.121  
changed lines
  Added in v.286

  ViewVC Help
Powered by ViewVC 1.1.26