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

Legend:
Removed from v.104  
changed lines
  Added in v.122

  ViewVC Help
Powered by ViewVC 1.1.26