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

Diff of /trunk/esys2/escript/src/Data/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 100 by jgs, Wed Dec 15 03:48:48 2004 UTC
# Line 72  class Data { Line 72  class Data {
72    typedef double (*BinaryDFunPtr)(double,double);    typedef double (*BinaryDFunPtr)(double,double);
73    
74    /**    /**
      Constructors.  
   */  
   
   /**  
75       \brief       \brief
76       Default constructor.       Default constructor.
77       Creates a DataEmpty object.       Creates a DataEmpty object.
# Line 92  class Data { Line 88  class Data {
88    /**    /**
89       \brief       \brief
90       Constructor from another Data object. If "what" is different from the       Constructor from another Data object. If "what" is different from the
91       function space of inData the inData are tried to be interpolated to what,       function space of inData the inData are tried to be interpolated to what
92       otherwise a shallow copy of inData is returned.       otherwise a shallow copy of inData is returned.
93    */    */
94    Data(const Data& inData,    Data(const Data& inData,
# Line 209  class Data { Line 205  class Data {
205    
206    /**    /**
207       \brief       \brief
208       Perform a deep copy.       Perform the specified algorithm on the Data and return result.
209      */
210      template <class UnaryFunction>
211      inline double
212      algorithm(UnaryFunction operation) const;
213    
214      /**
215         \brief
216         Perform the given unary operation on all of the data's elements.
217    */    */
218      template <class UnaryFunction>
219    void    void
220    copy(const Data& other);    unaryOp(UnaryFunction operation);
221    
222    /**    /**
223       Member access methods.       \brief
224         Perform the given binary operation on all of the data's elements.
225         The underlying type of the right hand side (right) determines the final
226         type of *this after the operation. For example if the right hand side
227         is expanded *this will be expanded if necessary.
228    */    */
229      template <class BinaryFunction>
230      void
231      binaryOp(const Data& right,
232               BinaryFunction operation);
233    
234      /**
235         \brief
236         Perform the given binary operation on all of the data's elements.
237      */
238      template <class BinaryFunction>
239      void
240      binaryOp(const boost::python::object& right,
241               BinaryFunction operation);
242    
243      /**
244         \brief
245         Overloaded operator +=
246         \param right - Input - The right hand side.
247      */
248      Data& operator+=(const Data& right);
249      Data& operator+=(const boost::python::object& right);
250    
251      /**
252         \brief
253         Overloaded operator -=
254         \param right - Input - The right hand side.
255      */
256      Data& operator-=(const Data& right);
257      Data& operator-=(const boost::python::object& right);
258    
259     /**
260         \brief
261         Overloaded operator *=
262         \param right - Input - The right hand side.
263      */
264      Data& operator*=(const Data& right);
265      Data& operator*=(const boost::python::object& right);
266    
267     /**
268         \brief
269         Overloaded operator /=
270         \param right - Input - The right hand side.
271      */
272      Data& operator/=(const Data& right);
273      Data& operator/=(const boost::python::object& right);
274    
275      /**
276         \brief
277         Return the power of Data.
278      */
279      Data powD(const Data& right) const;
280      Data powO(const boost::python::object& right) const;
281    
282    /**    /**
283       \brief       \brief
284       Return the C wrapper for the Data object.       Return the C wrapper for the Data object.
285    */    */
286    escriptDataC    escriptDataC getDataC();
   getDataC();  
287    
288    /**    /**
289       \brief       \brief
290       Return the C wrapper for the Data object - const version.       Return the C wrapper for the Data object - const version.
291    */    */
292    escriptDataC    escriptDataC getDataC() const;
   getDataC() const;  
293    
294    /**    /**
295       \brief       \brief
296       Write the data as a string.       Write the data as a string.
297    */    */
298    inline    std::string toString() const;
   std::string  
   toString() const  
   {  
     return m_data->toString();  
   }  
299    
300    /**    /**
301       \brief       \brief
# Line 258  class Data { Line 312  class Data {
312    
313    /**    /**
314       \brief       \brief
315       Whatever the current Data type make this into a DataExpanded.       Perform a deep copy.
316      */
317      void
318      copy(const Data& other);
319    
320      /**
321        \brief
322        Copy other Data object into this Data object where mask is positive.
323      */
324      void
325      copyWithMask(const Data& other,
326                   const Data& mask);
327    
328      /**
329         \brief
330         Whatever the current Data type make it expanded.
331    */    */
332    void    void
333    expand();    expand();
334    
335    /**    /**
336       \brief       \brief
337       If possible convert this Data to DataTagged. This will only allow       If possible convert the Data type to tagged. This will only allow
338       Constant data to be converted to tagged. An attempt to convert       Constant data to be converted to tagged. An attempt to convert
339       Expanded data to tagged will throw an exception.       Expanded data to tagged will throw an exception.
340    */    */
# Line 288  class Data { Line 357  class Data {
357    
358    /**    /**
359       \brief       \brief
360       Return true if this Data is constant.       Return true if this Data is empty.
361    */    */
362    bool    bool
363    isConstant() const;    isEmpty() const;
364    
365    /**    /**
366       \brief       \brief
367       Return true if this Data is empty.       Return true if this Data is constant.
368    */    */
369    bool    bool
370    isEmpty() const;    isConstant() const;
371    
372    /**    /**
373       \brief       \brief
# Line 349  class Data { Line 418  class Data {
418    
419    /**    /**
420       \brief       \brief
421       Return the number of samples.       Return the number of data points per sample.
422    */    */
423    inline    inline
424    int    int
425    getNumSamples() const    getNumDataPointsPerSample() const
426    {    {
427      return m_data->getNumSamples();      return m_data->getNumDPPSample();
428    }    }
429    
430    /**    /**
431       \brief       \brief
432       Return the number of data points per sample.       Return the number of samples.
433    */    */
   inline  
434    int    int
435    getNumDataPointsPerSample() const    getNumSamples() const;
436    {  
437      return m_data->getNumDPPSample();    /**
438    }       \brief
439         Check *this and the right operand are compatible. Throws
440         an exception if they aren't.
441         \param right - Input - The right hand side.
442      */
443      void
444      operandCheck(const Data& right) const;
445    
446    /**    /**
447       \brief       \brief
# Line 375  class Data { Line 449  class Data {
449       preferred interface but is provided for use by C code.       preferred interface but is provided for use by C code.
450       \param sampleNo - Input - the given sample no.       \param sampleNo - Input - the given sample no.
451    */    */
   inline  
452    DataAbstract::ValueType::value_type*    DataAbstract::ValueType::value_type*
453    getSampleData(DataAbstract::ValueType::size_type sampleNo)    getSampleData(DataAbstract::ShapeType::size_type sampleNo);
   {  
     return m_data->getSampleData(sampleNo);  
   }  
454    
455    /**    /**
456       \brief       \brief
# Line 388  class Data { Line 458  class Data {
458       access data that isn't tagged an exception will be thrown.       access data that isn't tagged an exception will be thrown.
459       \param tag - Input - the tag key.       \param tag - Input - the tag key.
460    */    */
   inline  
461    DataAbstract::ValueType::value_type*    DataAbstract::ValueType::value_type*
462    getSampleDataByTag(int tag)    getSampleDataByTag(int tag);
   {  
     return m_data->getSampleDataByTag(tag);  
   }  
463    
464    /**    /**
465       \brief       \brief
# Line 420  class Data { Line 486  class Data {
486    
487    /**    /**
488       \brief       \brief
489       Return the data point shape as a tuple of integers.       Return data point shape as a tuple of integers:
490    */    */
491    boost::python::tuple    boost::python::tuple
492    getShapeTuple() const;    getShapeTuple() const;
# Line 435  class Data { Line 501  class Data {
501    
502    /**    /**
503       \brief       \brief
504       Return the number of doubles stored for this Data.       Return the number of doubles stored for Data.
505    */    */
506    DataArrayView::ValueType::size_type    DataArrayView::ValueType::size_type
507    getLength() const;    getLength() const;
508    
509    /**    /**
510       \brief       \brief
511       Assign the given value to the tag. Implicitly converts this       Interpolates this onto the given functionspace and returns the result as a Data object.
      object to type DataTagged. Throws an exception if this object  
      cannot be converted to a DataTagged object.  
      \param tagKey - Input - Integer key.  
      \param value - Input - Value to associate with given key.  
   */  
   void  
   setTaggedValue(int tagKey,  
                  const boost::python::object& value);  
   
   /**  
      \brief  
      Assign the given value to the tag. Implicitly converts this  
      object to type DataTagged. Throws an exception if this object  
      cannot be converted to a DataTagged object.  
      \param tagKey - Input - Integer key.  
      \param value - Input - Value to associate with given key.  
      Note: removed for now - this version not needed, and breaks escript.cpp  
   */  
   /*  
   void  
   setTaggedValue(int tagKey,  
                  const DataArrayView& value);  
   */  
   
   /**  
     \brief  
     Copy other Data object into this Data object where mask is positive.  
   */  
   void  
   copyWithMask(const Data& other,  
                const Data& mask);  
   
   /**  
      Data object operation methods and operators.  
   */  
   
   /**  
      \brief  
      Interpolates this onto the given functionspace and returns  
      the result as a Data object.  
512    */    */
513    Data    Data
514    interpolate(const FunctionSpace& functionspace) const;    interpolate(const FunctionSpace& functionspace) const;
# Line 514  class Data { Line 540  class Data {
540    
541    /**    /**
542       \brief       \brief
543       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 values.
   */  
   Data  
   whereNegative() const;  
   
   /**  
      \brief  
      Return a Data with a 1 for +ive or 0 values and a 0 for -ive values.  
544    */    */
545    Data    Data
546    whereNonNegative() const;    whereNonNegative() const;
547    
548    /**    /**
549       \brief       \brief
550       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 values and a 0 for +ive or 0 values.
551    */    */
552    Data    Data
553    whereNonPositive() const;    whereNegative() const;
554    
555    /**    /**
556       \brief       \brief
557       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 a 0 for +ive or -ive.
558    */    */
559    Data    Data
560    whereZero() const;    whereZero() const;
561    
562    /**    /**
563       \brief       \brief
564       Return a Data with a 0 for 0 values and a 1 for +ive or -ive values.       Return the sin of Data.
   */  
   Data  
   whereNonZero() const;  
   
   /**  
      \brief  
      Return the sin of each data point of this Data object.  
565    */    */
566    Data    Data
567    sin() const;    sin() const;
568    
569    /**    /**
570       \brief       \brief
571       Return the cos of each data point of this Data object.       Return the cos of Data.
572    */    */
573    Data    Data
574    cos() const;    cos() const;
575    
576    /**    /**
577       \brief       \brief
578       Return the tan of each data point of this Data object.       Return the tan of Data.
579    */    */
580    Data    Data
581    tan() const;    tan() const;
582    
583    /**    /**
584       \brief       \brief
585       Return the log to base 10 of each data point of this Data object.       Return the log to base 10 of Data.
586    */    */
587    Data    Data
588    log() const;    log() const;
589    
590    /**    /**
591       \brief       \brief
592       Return the natural log of each data point of this Data object.       Return the natural log of Data.
593    */    */
594    Data    Data
595    ln() const;    ln() const;
596    
597    /**    /**
598       \brief       \brief
599       Return the maximum absolute value of this Data object.       Return a Data containing a slice of this Data.
   */  
   double  
   Lsup() const;  
   
   /**  
      \brief  
      Return the maximum value of this Data object.  
   */  
   double  
   sup() const;  
   
   /**  
      \brief  
      Return the minimum value of this Data object.  
   */  
   double  
   inf() const;  
   
   /**  
      \brief  
      Return the absolute value of each data point of this Data object.  
600    */    */
601    Data    Data
602    abs() const;    getSlice(const DataArrayView::RegionType& region) const;
603    
604    /**    /**
605       \brief       \brief
606       Return the maximum value of each data point of this Data object.       Copy the specified region from the given value.
607         \param value - Input - Data to copy from.
608         \param region - Input - Region to copy.
609    */    */
610    Data    void
611    maxval() const;    setSlice(const Data& value,
612               const DataArrayView::RegionType& region);
613    
614    /**    /**
615       \brief       \brief
616       Return the minimum value of each data point of this Data object.       Return the maximum absolute value.
617    */    */
618    Data    double
619    minval() const;    Lsup() const;
620    
621    /**    /**
622       \brief       \brief
623       Return the length of each data point of this Data object.       Return the maximum value.
      sqrt(sum(A[i,j,k,l]^2))  
624    */    */
625    Data    double
626    length() const;    sup() const;
627    
628    /**    /**
629       \brief       \brief
630       Return the sign of each data point of this Data object.       Return the minimum value.
      -1 for negative values, zero for zero values, 1 for positive values.  
   */  
   Data  
   sign() const;  
   
   /**  
     \transpose  
     Transpose each data point of this Data object around the given axis.  
   */  
   Data  
   transpose(int axis) const;  
   
   /**  
     \trace  
     Calculate the trace of each data point of this Data object.  
     sum(A[i,i,i,i])  
   */  
   Data  
   trace() const;  
   
   /**  
     \exp  
     Return the exponential function of each data point of this Data object.  
   */  
   Data  
   exp() const;  
   
   /**  
     \sqrt  
     Return the square root of each data point of this Data object.  
631    */    */
632    Data    double
633    sqrt() const;    inf() const;
634    
635    /**    /**
636       \brief       \brief
637       Return the given power of each data point of this Data object.       Returns a slice from this.
   */  
   Data  
   powD(const Data& right) const;  
   
   Data  
   powO(const boost::python::object& right) const;  
   
   /**  
     \brief  
     Return the negation of each data point of this Data object.  
638    */    */
639    Data    Data
640    neg() const;    getItem(const boost::python::object& key) const;
   
   /**  
     \brief  
     Return the identity of each data point of this Data object.  
     Simply returns this object unmodified.  
   */  
   Data  
   pos() const;  
641    
642    /**    /**
643       \brief       \brief
644       Overloaded operator +=       Copies slice from value into this.
      \param right - Input - The right hand side.  
645    */    */
646    Data& operator+=(const Data& right);    void
647    Data& operator+=(const boost::python::object& right);    setItem(const boost::python::object& key,
648              const Data& value);
649    
650    /**    /**
651       \brief       \brief
652       Overloaded operator -=       Convert the underlying data type to match the RHS.
653       \param right - Input - The right hand side.       \param right - Input - data type to match.
   */  
   Data& operator-=(const Data& right);  
   Data& operator-=(const boost::python::object& right);  
   
  /**  
      \brief  
      Overloaded operator *=  
      \param right - Input - The right hand side.  
   */  
   Data& operator*=(const Data& right);  
   Data& operator*=(const boost::python::object& right);  
   
  /**  
      \brief  
      Overloaded operator /=  
      \param right - Input - The right hand side.  
654    */    */
655    Data& operator/=(const Data& right);    void
656    Data& operator/=(const boost::python::object& right);    typeMatch(const Data& right);
657    
658    /**    /**
659       \brief       \brief
# Line 734  class Data { Line 663  class Data {
663    probeInterpolation(const FunctionSpace& functionspace) const;    probeInterpolation(const FunctionSpace& functionspace) const;
664    
665    /**    /**
      Data object slicing methods.  
   */  
   
   /**  
      \brief  
      Returns a slice from this Data object.  
   
      /description  
      Implements the [] get operator in python.  
      Calls getSlice.  
   
      \param key - Input - python slice tuple specifying  
      slice to return.  
   */  
   Data  
   getItem(const boost::python::object& key) const;  
   
   /**  
666       \brief       \brief
667       Copies slice from value into this Data object.       Assign the given value to the tag. Implicitly converts this
668         object to type DataTagged. Throws an exception if this object
669       \description       cannot be converted to a DataTagged object.
670       Implements the [] set operator in python.       \param tagKey - Input - Integer key.
671       Calls setSlice.       \param value - Input - Value to associate with given key.
   
      \param key - Input - python slice tuple specifying  
      slice to copy from value.  
      \param value - Input - Data object to copy from.  
672    */    */
673    void    void
674    setItemD(const boost::python::object& key,    setTaggedValue(int tagKey,
675             const Data& value);                   const boost::python::object& value);
   
   void  
   setItemO(const boost::python::object& key,  
            const boost::python::object& value);  
   
   // These following public methods should be treated as private.  
676    
677    /**    /**
678       \brief       \brief
679       Perform the given unary operation on every element of every data point in       Assign the given value to the tag. Implicitly converts this
680       this Data object.       object to type DataTagged. Throws an exception if this object
681         cannot be converted to a DataTagged object.
682         \param tagKey - Input - Integer key.
683         \param value - Input - Value to associate with given key.
684         Note: removed for now - this version not needed, and breaks escript.cpp
685    */    */
686    template <class UnaryFunction>    /*
   inline  
687    void    void
688    unaryOp(UnaryFunction operation);    setTaggedValue(int tagKey,
689                     const DataArrayView& value);
   /**  
      \brief  
      Return a Data object containing the specified slice of  
      this Data object.  
      \param region - Input - Region to copy.  
   */  
   Data  
   getSlice(const DataArrayView::RegionType& region) const;  
   
   /**  
      \brief  
      Copy the specified slice from the given value into this  
      Data object.  
      \param value - Input - Data to copy from.  
      \param region - Input - Region to copy.  
690    */    */
   void  
   setSlice(const Data& value,  
            const DataArrayView::RegionType& region);  
   
  protected:  
691    
692   private:   private:
693    
694    /**    /**
695       \brief       \brief
      Check *this and the right operand are compatible. Throws  
      an exception if they aren't.  
      \param right - Input - The right hand side.  
   */  
   inline  
   void  
   operandCheck(const Data& right) const  
   {  
     return m_data->operandCheck(*(right.m_data.get()));  
   }  
   
   /**  
      \brief  
      Perform the specified reduction algorithm on every element of every data point in  
      this Data object and return the single double value result.  
   */  
   template <class UnaryFunction>  
   inline  
   double  
   algorithm(UnaryFunction operation) const;  
   
   /**  
      \brief  
      Perform the given binary operation on all of the data's elements.  
      The underlying type of the right hand side (right) determines the final  
      type of *this after the operation. For example if the right hand side  
      is expanded *this will be expanded if necessary.  
      RHS is a Data object.  
   */  
   template <class BinaryFunction>  
   inline  
   void  
   binaryOp(const Data& right,  
            BinaryFunction operation);  
   
   /**  
      \brief  
      Perform the given binary operation on all of the data's elements.  
      RHS is a boost::python object.  
   */  
   template <class BinaryFunction>  
   inline  
   void  
   binaryOp(const boost::python::object& right,  
            BinaryFunction operation);  
   
   /**  
      \brief  
      Convert the data type of the RHS to match this.  
      \param right - Input - data type to match.  
   */  
   void  
   typeMatchLeft(Data& right) const;  
   
   /**  
      \brief  
      Convert the data type of this to match the RHS.  
      \param right - Input - data type to match.  
   */  
   void  
   typeMatchRight(const Data& right);  
   
   /**  
      \brief  
696       Construct a Data object of the appropriate type.       Construct a Data object of the appropriate type.
697    */    */
698    template <class IValueType>    template <class IValueType>
# Line 892  class Data { Line 712  class Data {
712    reshapeDataPoint(const DataArrayView::ShapeType& shape);    reshapeDataPoint(const DataArrayView::ShapeType& shape);
713    
714    //    //
715    // pointer to the actual data object    // pointer to the actual data
716    boost::shared_ptr<DataAbstract> m_data;    boost::shared_ptr<DataAbstract> m_data;
717    
718  };  };
# Line 910  Data::initialise(const IValueType& value Line 730  Data::initialise(const IValueType& value
730    // within the shared_ptr constructor.    // within the shared_ptr constructor.
731    if (expanded) {    if (expanded) {
732      DataAbstract* temp=new DataExpanded(value,what);      DataAbstract* temp=new DataExpanded(value,what);
733      boost::shared_ptr<DataAbstract> temp_data(temp);      m_data=boost::shared_ptr<DataAbstract>(temp);
     m_data=temp_data;  
734    } else {    } else {
735      DataAbstract* temp=new DataConstant(value,what);      DataAbstract* temp=new DataConstant(value,what);
736      boost::shared_ptr<DataAbstract> temp_data(temp);      m_data=boost::shared_ptr<DataAbstract>(temp);
     m_data=temp_data;  
737    }    }
738  }  }
739    
740  /**  inline
741     Binary Data object operators.  DataAbstract::ValueType::value_type*
742  */  Data::getSampleData(DataAbstract::ValueType::size_type sampleNo)
743    {
744      return m_data->getSampleData(sampleNo);
745    }
746    
747    inline
748    DataAbstract::ValueType::value_type*
749    Data::getSampleDataByTag(int tag)
750    {
751      return m_data->getSampleDataByTag(tag);
752    }
753    
754    inline
755    void
756    Data::operandCheck(const Data& right) const
757    {
758      return m_data->operandCheck(*(right.m_data.get()));
759    }
760    
761    inline
762    int
763    Data::getNumSamples() const
764    {
765      return m_data->getNumSamples();
766    }
767    
768    inline
769    std::string
770    Data::toString() const
771    {
772      return m_data->toString();
773    }
774    
775  /**  /**
776    \brief    \brief
# Line 1027  std::ostream& operator<<(std::ostream& o Line 876  std::ostream& operator<<(std::ostream& o
876    NB: this operator does very little at this point, and isn't to    NB: this operator does very little at this point, and isn't to
877    be relied on. Requires further implementation.    be relied on. Requires further implementation.
878  */  */
879  //bool operator==(const Data& left, const Data& right);  bool operator==(const Data& left, const Data& right);
880    
 /**  
   \brief  
   Perform the given binary operation with this and right as operands.  
   Right is a Data object.  
 */  
881  template <class BinaryFunction>  template <class BinaryFunction>
882  inline  inline
883  void  void
# Line 1063  Data::binaryOp(const Data& right, Line 907  Data::binaryOp(const Data& right,
907     operandCheck(tempRight);     operandCheck(tempRight);
908     //     //
909     // ensure this has the right type for the RHS     // ensure this has the right type for the RHS
910     typeMatchRight(tempRight);     typeMatch(tempRight);
911     //     //
912     // Need to cast to the concrete types so that the correct binaryOp     // Need to cast to the concrete types so that the correct binaryOp
913     // is called.     // is called.
# Line 1089  Data::binaryOp(const Data& right, Line 933  Data::binaryOp(const Data& right,
933         EsysAssert((rightC!=0), "Programming error - casting to DataConstant.");         EsysAssert((rightC!=0), "Programming error - casting to DataConstant.");
934         escript::binaryOp(*leftC,*rightC,operation);         escript::binaryOp(*leftC,*rightC,operation);
935       }       }
936     } else if (isConstant()) {     } else {
937         //
938         // can only be DataConstant
939       DataConstant* leftC=dynamic_cast<DataConstant*>(m_data.get());       DataConstant* leftC=dynamic_cast<DataConstant*>(m_data.get());
940       DataConstant* rightC=dynamic_cast<DataConstant*>(tempRight.m_data.get());       DataConstant* rightC=dynamic_cast<DataConstant*>(tempRight.m_data.get());
941       EsysAssert((leftC!=0 && rightC!=0), "Programming error - casting to DataConstant.");       EsysAssert((leftC!=0 && rightC!=0), "Programming error - casting to DataConstant.");
# Line 1097  Data::binaryOp(const Data& right, Line 943  Data::binaryOp(const Data& right,
943     }     }
944  }  }
945    
 /**  
   \brief  
   Perform the given binary operation with this and right as operands.  
   Right is a boost::python object.  
 */  
946  template <class BinaryFunction>  template <class BinaryFunction>
947  inline  inline
948  void  void
# Line 1122  Data::binaryOp(const boost::python::obje Line 963  Data::binaryOp(const boost::python::obje
963                    "Error - RHS shape doesn't match LHS shape.",temp.getView().getShape()));                    "Error - RHS shape doesn't match LHS shape.",temp.getView().getShape()));
964       }       }
965     }     }
966    
967     if (isExpanded()) {     if (isExpanded()) {
968         //
969         // Expanded data will be done in parallel
970       DataExpanded* leftC=dynamic_cast<DataExpanded*>(m_data.get());       DataExpanded* leftC=dynamic_cast<DataExpanded*>(m_data.get());
971       EsysAssert((leftC!=0),"Programming error - casting to DataExpanded.");       EsysAssert((leftC!=0),"Programming error - casting to DataExpanded.");
972       escript::binaryOp(*leftC,temp.getView(),operation);       escript::binaryOp(*leftC,temp.getView(),operation);
# Line 1130  Data::binaryOp(const boost::python::obje Line 974  Data::binaryOp(const boost::python::obje
974       DataTagged* leftC=dynamic_cast<DataTagged*>(m_data.get());       DataTagged* leftC=dynamic_cast<DataTagged*>(m_data.get());
975       EsysAssert((leftC!=0), "Programming error - casting to DataTagged.");       EsysAssert((leftC!=0), "Programming error - casting to DataTagged.");
976       escript::binaryOp(*leftC,temp.getView(),operation);       escript::binaryOp(*leftC,temp.getView(),operation);
977     } else if (isConstant()) {     } else {
978         //
979         // can only be DataConstant
980       DataConstant* leftC=dynamic_cast<DataConstant*>(m_data.get());       DataConstant* leftC=dynamic_cast<DataConstant*>(m_data.get());
981       EsysAssert((leftC!=0),"Programming error - casting to DataConstant.");       EsysAssert((leftC!=0),"Programming error - casting to DataConstant.");
982       escript::binaryOp(*leftC,temp.getView(),operation);       escript::binaryOp(*leftC,temp.getView(),operation);
983     }     }
984  }  }
985    
 /**  
   \brief  
   Perform the given unary operation on other and return the result.  
   Given operation is performed on each element of each data point, thus  
   argument object is a rank n Data object, and returned object is a rank n  
   Data object.  
   Calls Data::unaryOp.  
 */  
 template <class UnaryFunction>  
 inline  
 Data  
 unaryOp(const Data& other,  
         UnaryFunction operation)  
 {  
   Data result;  
   result.copy(other);  
   result.unaryOp(operation);  
   return result;  
 }  
   
 /**  
   \brief  
   Perform the given unary operation on this.  
   Given operation is performed on each element of each data point.  
   Calls escript::unaryOp.  
 */  
986  template <class UnaryFunction>  template <class UnaryFunction>
987  inline  inline
988  void  void
989  Data::unaryOp(UnaryFunction operation)  Data::unaryOp(UnaryFunction operation)
990  {  {
991    if (isExpanded()) {    if (isExpanded()) {
992        //
993        // Expanded data will be done in parallel
994      DataExpanded* leftC=dynamic_cast<DataExpanded*>(m_data.get());      DataExpanded* leftC=dynamic_cast<DataExpanded*>(m_data.get());
995      EsysAssert((leftC!=0), "Programming error - casting to DataExpanded.");      EsysAssert((leftC!=0), "Programming error - casting to DataExpanded.");
996      escript::unaryOp(*leftC,operation);      escript::unaryOp(*leftC,operation);
# Line 1176  Data::unaryOp(UnaryFunction operation) Line 998  Data::unaryOp(UnaryFunction operation)
998      DataTagged* leftC=dynamic_cast<DataTagged*>(m_data.get());      DataTagged* leftC=dynamic_cast<DataTagged*>(m_data.get());
999      EsysAssert((leftC!=0), "Programming error - casting to DataTagged.");      EsysAssert((leftC!=0), "Programming error - casting to DataTagged.");
1000      escript::unaryOp(*leftC,operation);      escript::unaryOp(*leftC,operation);
1001    } else if (isConstant()) {    } else {
1002      DataConstant* leftC=dynamic_cast<DataConstant*>(m_data.get());      DataConstant* leftC=dynamic_cast<DataConstant*>(m_data.get());
1003      EsysAssert((leftC!=0), "Programming error - casting to DataConstant.");      EsysAssert((leftC!=0), "Programming error - casting to DataConstant.");
1004      escript::unaryOp(*leftC,operation);      escript::unaryOp(*leftC,operation);
1005    }    }
1006  }  }
1007    
 /**  
   \brief  
   Perform the given Data object reduction algorithm on this and return the result.  
   Given operation combines each element of each data point, thus argument  
   object (*this) is a rank n Data object, and returned object is a scalar.  
   Calls escript::algorithm.  
 */  
1008  template <class UnaryFunction>  template <class UnaryFunction>
1009  inline  inline
1010  double  double
1011  Data::algorithm(UnaryFunction operation) const  Data::algorithm(UnaryFunction operation) const
1012  {  {
1013    if (isExpanded()) {    if (isExpanded()) {
1014        //
1015        // Expanded data will be done in parallel
1016      DataExpanded* leftC=dynamic_cast<DataExpanded*>(m_data.get());      DataExpanded* leftC=dynamic_cast<DataExpanded*>(m_data.get());
1017      EsysAssert((leftC!=0), "Programming error - casting to DataExpanded.");      EsysAssert((leftC!=0), "Programming error - casting to DataExpanded.");
1018      return escript::algorithm(*leftC,operation);      return escript::algorithm(*leftC,operation);
1019    } else if (isTagged()) {    }
1020      else if (isTagged()) {
1021      DataTagged* leftC=dynamic_cast<DataTagged*>(m_data.get());      DataTagged* leftC=dynamic_cast<DataTagged*>(m_data.get());
1022      EsysAssert((leftC!=0), "Programming error - casting to DataTagged.");      EsysAssert((leftC!=0), "Programming error - casting to DataTagged.");
1023      return escript::algorithm(*leftC,operation);      return escript::algorithm(*leftC,operation);
1024    } else if (isConstant()) {    } else {
1025      DataConstant* leftC=dynamic_cast<DataConstant*>(m_data.get());      DataConstant* leftC=dynamic_cast<DataConstant*>(m_data.get());
1026      EsysAssert((leftC!=0), "Programming error - casting to DataConstant.");      EsysAssert((leftC!=0), "Programming error - casting to DataConstant.");
1027      return escript::algorithm(*leftC,operation);      return escript::algorithm(*leftC,operation);
1028    }    }
   return 0;  
1029  }  }
1030    
 /**  
   \brief  
   Perform the given data point reduction algorithm on data and return the result.  
   Given operation combines each element within each data point into a scalar,  
   thus argument object is a rank n Data object, and returned object is a  
   rank 0 Data object.  
   Calls escript::dp_algorithm.  
 */  
1031  template <class UnaryFunction>  template <class UnaryFunction>
1032  inline  inline
1033  Data  Data
1034  dp_algorithm(const Data& data,  unaryOp(const Data& other,
1035               UnaryFunction operation)          UnaryFunction operation)
1036  {  {
1037    Data result(0,DataArrayView::ShapeType(),data.getFunctionSpace(),data.isExpanded());    //
1038    if (data.isExpanded()) {    // Perform the given operation on a copy of the input data and return the result
1039      DataExpanded* dataE=dynamic_cast<DataExpanded*>(data.m_data.get());    Data result;
1040      DataExpanded* resultE=dynamic_cast<DataExpanded*>(result.m_data.get());    //
1041      EsysAssert((dataE!=0), "Programming error - casting data to DataExpanded.");    // perform a deep copy
1042      EsysAssert((resultE!=0), "Programming error - casting result to DataExpanded.");    result.copy(other);
1043      escript::dp_algorithm(*dataE,*resultE,operation);    result.unaryOp(operation);
   } else if (data.isTagged()) {  
     DataTagged* dataT=dynamic_cast<DataTagged*>(data.m_data.get());  
     DataTagged* resultT=dynamic_cast<DataTagged*>(result.m_data.get());  
     EsysAssert((dataT!=0), "Programming error - casting data to DataTagged.");  
     EsysAssert((resultT!=0), "Programming error - casting result to DataTagged.");  
     escript::dp_algorithm(*dataT,*resultT,operation);  
   } else if (data.isConstant()) {  
     DataConstant* dataC=dynamic_cast<DataConstant*>(data.m_data.get());  
     DataConstant* resultC=dynamic_cast<DataConstant*>(result.m_data.get());  
     EsysAssert((dataC!=0), "Programming error - casting data to DataConstant.");  
     EsysAssert((resultC!=0), "Programming error - casting result to DataConstant.");  
     escript::dp_algorithm(*dataC,*resultC,operation);  
   }  
1044    return result;    return result;
1045  }  }
1046    
1047  }  }
1048    
1049  #endif  #endif

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

  ViewVC Help
Powered by ViewVC 1.1.26