/[escript]/trunk/escript/src/Data.h
ViewVC logotype

Diff of /trunk/escript/src/Data.h

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

revision 97 by jgs, Tue Dec 14 05:39:33 2004 UTC revision 121 by jgs, Fri May 6 04:26:16 2005 UTC
# Line 1  Line 1 
1  // $Id$  // $Id$
2  /*=============================================================================  /*
   
3   ******************************************************************************   ******************************************************************************
4   *                                                                            *   *                                                                            *
5   *       COPYRIGHT ACcESS 2004 -  All Rights Reserved                         *   *       COPYRIGHT ACcESS 2004 -  All Rights Reserved                         *
# Line 12  Line 11 
11   * person has a software license agreement with ACcESS.                       *   * person has a software license agreement with ACcESS.                       *
12   *                                                                            *   *                                                                            *
13   ******************************************************************************   ******************************************************************************
14    */
15    
16  ******************************************************************************/  /** \file Data.h */
17    
18  #ifndef DATA_H  #ifndef DATA_H
19  #define DATA_H  #define DATA_H
# Line 23  Line 23 
23  #include "escript/Data/FunctionSpace.h"  #include "escript/Data/FunctionSpace.h"
24  #include "escript/Data/BinaryOp.h"  #include "escript/Data/BinaryOp.h"
25  #include "escript/Data/UnaryOp.h"  #include "escript/Data/UnaryOp.h"
26    #include "escript/Data/DataException.h"
27    
28  extern "C" {  extern "C" {
29  #include "escript/Data/DataC.h"  #include "escript/Data/DataC.h"
# Line 39  extern "C" { Line 40  extern "C" {
40  #include <boost/python/tuple.hpp>  #include <boost/python/tuple.hpp>
41  #include <boost/python/numeric.hpp>  #include <boost/python/numeric.hpp>
42    
43    namespace escript {
44    
45    //
46    // Forward declaration for various implimentations of Data.
47    class DataEmpty;
48    class DataConstant;
49    class DataTagged;
50    class DataExpanded;
51    
52  /**  /**
53     \brief     \brief
54     Data is essentially a factory class which creates the appropriate Data     Data creates the appropriate Data object for the given construction
55     object for the given construction arguments. It retains control over     arguments.
    the object created for the lifetime of the object.  
    The type of Data object referred to may change during the lifetime of  
    the Data object.  
56    
57     Description:     Description:
58     Data is essentially a factory class which creates the appropriate Data     Data is essentially a factory class which creates the appropriate Data
# Line 54  extern "C" { Line 61  extern "C" {
61     The type of Data object referred to may change during the lifetime of     The type of Data object referred to may change during the lifetime of
62     the Data object.     the Data object.
63  */  */
   
 namespace escript {  
   
 //  
 // Forward declaration for various implimentations of Data.  
 class DataEmpty;  
 class DataConstant;  
 class DataTagged;  
 class DataExpanded;  
   
64  class Data {  class Data {
65    
66    public:    public:
67    
68      // These typedefs allow function names to be cast to pointers
69      // to functions of the appropriate type when calling unaryOp etc.
70    typedef double (*UnaryDFunPtr)(double);    typedef double (*UnaryDFunPtr)(double);
71    typedef double (*BinaryDFunPtr)(double,double);    typedef double (*BinaryDFunPtr)(double,double);
72    
# Line 220  class Data { Line 219  class Data {
219    
220    /**    /**
221       \brief       \brief
222         Return the values of all data-points as a single python numarray object.
223      */
224      const boost::python::numeric::array
225      convertToNumArray();
226    
227      /**
228         \brief
229         Return the values of all data-points for the given sample as a single python numarray object.
230      */
231      const boost::python::numeric::array
232      convertToNumArrayFromSampleNo(int sampleNo);
233    
234      /**
235         \brief
236         Return the value of the specified data-point as a single python numarray object.
237      */
238      const boost::python::numeric::array
239      convertToNumArrayFromDPNo(int sampleNo,
240                                int dataPointNo);
241    
242      /**
243         \brief
244       Return the C wrapper for the Data object.       Return the C wrapper for the Data object.
245    */    */
246    escriptDataC    escriptDataC
# Line 397  class Data { Line 418  class Data {
418    
419    /**    /**
420       \brief       \brief
421         Assign the given value to the data-points referenced by the given
422         reference number.
423    
424         The value supplied is a python numarray object.  The data from this numarray
425         is unpacked into a DataArray, and this is used to set the corresponding
426         data-points in the underlying Data object.
427    
428         If the underlying Data object cannot be accessed via reference numbers, an
429         exception will be thrown.
430    
431         \param ref - Input - reference number.
432         \param value - Input - value to assign to data-points associated with
433                                the given reference number.
434      */
435      void
436      setRefValue(int ref,
437                  const boost::python::numeric::array& value);
438    
439      /**
440         \brief
441         Return the values associated with the data-points referenced by the given
442         reference number.
443    
444         The value supplied is a python numarray object. The data from the corresponding
445         data-points in this Data object are packed into the given numarray object.
446    
447         If the underlying Data object cannot be accessed via reference numbers, an
448         exception will be thrown.
449    
450         \param ref - Input - reference number.
451         \param value - Output - object to receive values from data-points
452                                 associated with the given reference number.
453      */
454      void
455      getRefValue(int ref,
456                  boost::python::numeric::array& value);
457    
458      /**
459         \brief
460       Return a view into the data for the data point specified.       Return a view into the data for the data point specified.
461       NOTE: Construction of the DataArrayView is a relatively expensive       NOTE: Construction of the DataArrayView is a relatively expensive
462       operation.       operation.
# Line 422  class Data { Line 482  class Data {
482       \brief       \brief
483       Return the data point shape as a tuple of integers.       Return the data point shape as a tuple of integers.
484    */    */
485    boost::python::tuple    const boost::python::tuple
486    getShapeTuple() const;    getShapeTuple() const;
487    
488    /**    /**
# Line 459  class Data { Line 519  class Data {
519       cannot be converted to a DataTagged object.       cannot be converted to a DataTagged object.
520       \param tagKey - Input - Integer key.       \param tagKey - Input - Integer key.
521       \param value - Input - Value to associate with given key.       \param value - Input - Value to associate with given key.
      Note: removed for now - this version not needed, and breaks escript.cpp  
522    */    */
   /*  
523    void    void
524    setTaggedValue(int tagKey,    setTaggedValueFromCPP(int tagKey,
525                   const DataArrayView& value);                          const DataArrayView& value);
   */  
526    
527    /**    /**
528      \brief      \brief
# Line 591  class Data { Line 648  class Data {
648    
649    /**    /**
650       \brief       \brief
651         Return the minimum absolute value of this Data object.
652      */
653      double
654      Linf() const;
655    
656      /**
657         \brief
658       Return the maximum value of this Data object.       Return the maximum value of this Data object.
659    */    */
660    double    double
# Line 626  class Data { Line 690  class Data {
690    
691    /**    /**
692       \brief       \brief
693         Return the (sample number, data-point number) of the data point with
694         the minimum value in this Data object.
695      */
696      const boost::python::tuple
697      mindp() const;
698    
699      /**
700         \brief
701       Return the length of each data point of this Data object.       Return the length of each data point of this Data object.
702       sqrt(sum(A[i,j,k,l]^2))       sqrt(sum(A[i,j,k,l]^2))
703    */    */
# Line 641  class Data { Line 713  class Data {
713    sign() const;    sign() const;
714    
715    /**    /**
716      \transpose      \brief
717      Transpose each data point of this Data object around the given axis.      Transpose each data point of this Data object around the given axis.
718        --* not implemented yet *--
719    */    */
720    Data    Data
721    transpose(int axis) const;    transpose(int axis) const;
722    
723    /**    /**
724      \trace      \brief
725      Calculate the trace of each data point of this Data object.      Calculate the trace of each data point of this Data object.
726      sum(A[i,i,i,i])      sum(A[i,i,i,i])
727    */    */
# Line 656  class Data { Line 729  class Data {
729    trace() const;    trace() const;
730    
731    /**    /**
732      \exp      \brief
733      Return the exponential function of each data point of this Data object.      Return the exponential function of each data point of this Data object.
734    */    */
735    Data    Data
736    exp() const;    exp() const;
737    
738    /**    /**
739      \sqrt      \brief
740      Return the square root of each data point of this Data object.      Return the square root of each data point of this Data object.
741    */    */
742    Data    Data
743    sqrt() const;    sqrt() const;
744    
745    /**    /**
746        \brief
747        Return the negation of each data point of this Data object.
748      */
749      Data
750      neg() const;
751    
752      /**
753        \brief
754        Return the identity of each data point of this Data object.
755        Simply returns this object unmodified.
756      */
757      Data
758      pos() const;
759    
760      /**
761       \brief       \brief
762       Return the given power of each data point of this Data object.       Return the given power of each data point of this Data object.
763    
764         \param right Input - the power to raise the object to.
765    */    */
766    Data    Data
767    powD(const Data& right) const;    powD(const Data& right) const;
768    
769      /**
770       * \brief
771       * Return the given power of each data point of this boost python object.
772       *
773       * \param right Input - the power to raise the object to.
774       */
775    Data    Data
776    powO(const boost::python::object& right) const;    powO(const boost::python::object& right) const;
777    
778    /**    /**
779      \brief      \brief
780      Return the negation of each data point of this Data object.      writes the object to a file in the DX file format
781    */    */
782    Data    void
783    neg() const;    saveDX(std::string fileName) const;
784    
785    /**    /**
786      \brief      \brief
787      Return the identity of each data point of this Data object.      writes the object to a file in the VTK file format
     Simply returns this object unmodified.  
788    */    */
789    Data    void
790    pos() const;    saveVTK(std::string fileName) const;
791    
792    /**    /**
793       \brief       \brief
# Line 755  class Data { Line 850  class Data {
850       \brief       \brief
851       Copies slice from value into this Data object.       Copies slice from value into this Data object.
852    
      \description  
853       Implements the [] set operator in python.       Implements the [] set operator in python.
854       Calls setSlice.       Calls setSlice.
855    
# Line 803  class Data { Line 897  class Data {
897    setSlice(const Data& value,    setSlice(const Data& value,
898             const DataArrayView::RegionType& region);             const DataArrayView::RegionType& region);
899    
900      /**
901         \brief
902         Archive the current Data object to the given file.
903         \param fileName - Input - file to archive to.
904      */
905      void
906      archiveData(const std::string fileName);
907    
908      /**
909         \brief
910         Extract the Data object archived in the given file, overwriting
911         the current Data object.
912         Note - the current object must be of type DataEmpty.
913         \param fileName - Input - file to extract from.
914         \param fspace - Input - a suitable FunctionSpace descibing the data.
915      */
916      void
917      extractData(const std::string fileName,
918                  const FunctionSpace& fspace);
919    
920   protected:   protected:
921    
922   private:   private:
# Line 823  class Data { Line 937  class Data {
937    /**    /**
938       \brief       \brief
939       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
940       this Data object and return the single double value result.       this Data object according to the given function and return the single value result.
941    */    */
942    template <class UnaryFunction>    template <class UnaryFunction>
943    inline    inline
# Line 832  class Data { Line 946  class Data {
946    
947    /**    /**
948       \brief       \brief
949         Reduce each data-point in this Data object using the given operation. Return a Data
950         object with the same number of data-points, but with each data-point containing only
951         one value - the result of the reduction operation on the corresponding data-point in
952         this Data object
953      */
954      template <class UnaryFunction>
955      inline
956      Data
957      dp_algorithm(UnaryFunction operation) const;
958    
959      /**
960         \brief
961       Perform the given binary operation on all of the data's elements.       Perform the given binary operation on all of the data's elements.
962       The underlying type of the right hand side (right) determines the final       The underlying type of the right hand side (right) determines the final
963       type of *this after the operation. For example if the right hand side       type of *this after the operation. For example if the right hand side
# Line 1222  Data::algorithm(UnaryFunction operation) Line 1348  Data::algorithm(UnaryFunction operation)
1348  template <class UnaryFunction>  template <class UnaryFunction>
1349  inline  inline
1350  Data  Data
1351  dp_algorithm(const Data& data,  Data::dp_algorithm(UnaryFunction operation) const
              UnaryFunction operation)  
1352  {  {
1353    Data result(0,DataArrayView::ShapeType(),data.getFunctionSpace(),data.isExpanded());    Data result(0,DataArrayView::ShapeType(),getFunctionSpace(),isExpanded());
1354    if (data.isExpanded()) {    if (isExpanded()) {
1355      DataExpanded* dataE=dynamic_cast<DataExpanded*>(data.m_data.get());      DataExpanded* dataE=dynamic_cast<DataExpanded*>(m_data.get());
1356      DataExpanded* resultE=dynamic_cast<DataExpanded*>(result.m_data.get());      DataExpanded* resultE=dynamic_cast<DataExpanded*>(result.m_data.get());
1357      EsysAssert((dataE!=0), "Programming error - casting data to DataExpanded.");      EsysAssert((dataE!=0), "Programming error - casting data to DataExpanded.");
1358      EsysAssert((resultE!=0), "Programming error - casting result to DataExpanded.");      EsysAssert((resultE!=0), "Programming error - casting result to DataExpanded.");
1359      escript::dp_algorithm(*dataE,*resultE,operation);      escript::dp_algorithm(*dataE,*resultE,operation);
1360    } else if (data.isTagged()) {    } else if (isTagged()) {
1361      DataTagged* dataT=dynamic_cast<DataTagged*>(data.m_data.get());      DataTagged* dataT=dynamic_cast<DataTagged*>(m_data.get());
1362      DataTagged* resultT=dynamic_cast<DataTagged*>(result.m_data.get());      DataTagged* resultT=dynamic_cast<DataTagged*>(result.m_data.get());
1363      EsysAssert((dataT!=0), "Programming error - casting data to DataTagged.");      EsysAssert((dataT!=0), "Programming error - casting data to DataTagged.");
1364      EsysAssert((resultT!=0), "Programming error - casting result to DataTagged.");      EsysAssert((resultT!=0), "Programming error - casting result to DataTagged.");
1365      escript::dp_algorithm(*dataT,*resultT,operation);      escript::dp_algorithm(*dataT,*resultT,operation);
1366    } else if (data.isConstant()) {    } else if (isConstant()) {
1367      DataConstant* dataC=dynamic_cast<DataConstant*>(data.m_data.get());      DataConstant* dataC=dynamic_cast<DataConstant*>(m_data.get());
1368      DataConstant* resultC=dynamic_cast<DataConstant*>(result.m_data.get());      DataConstant* resultC=dynamic_cast<DataConstant*>(result.m_data.get());
1369      EsysAssert((dataC!=0), "Programming error - casting data to DataConstant.");      EsysAssert((dataC!=0), "Programming error - casting data to DataConstant.");
1370      EsysAssert((resultC!=0), "Programming error - casting result to DataConstant.");      EsysAssert((resultC!=0), "Programming error - casting result to DataConstant.");

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

  ViewVC Help
Powered by ViewVC 1.1.26