/[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

trunk/esys2/escript/src/Data/Data.h revision 147 by jgs, Fri Aug 12 01:45:47 2005 UTC trunk/escript/src/Data.h revision 751 by bcumming, Mon Jun 26 01:46:34 2006 UTC
# Line 1  Line 1 
1  // $Id$  // $Id$
2  /*  /*
3   ******************************************************************************   ************************************************************
4   *                                                                            *   *          Copyright 2006 by ACcESS MNRF                   *
5   *       COPYRIGHT ACcESS 2004 -  All Rights Reserved                         *   *                                                          *
6   *                                                                            *   *              http://www.access.edu.au                    *
7   * This software is the property of ACcESS.  No part of this code             *   *       Primary Business: Queensland, Australia            *
8   * may be copied in any form or by any means without the expressed written    *   *  Licensed under the Open Software License version 3.0    *
9   * consent of ACcESS.  Copying, use or modification of this software          *   *     http://www.opensource.org/licenses/osl-3.0.php       *
10   * by any unauthorised person is illegal unless that                          *   *                                                          *
11   * person has a software license agreement with ACcESS.                       *   ************************************************************
  *                                                                            *  
  ******************************************************************************  
12  */  */
13    
14  /** \file Data.h */  /** \file Data.h */
# Line 18  Line 16 
16  #ifndef DATA_H  #ifndef DATA_H
17  #define DATA_H  #define DATA_H
18    
19  #include "escript/Data/DataAbstract.h"  #include "DataAbstract.h"
20  #include "escript/Data/DataTagged.h"  #include "DataAlgorithm.h"
21  #include "escript/Data/DataAlgorithm.h"  #include "FunctionSpace.h"
22  #include "escript/Data/FunctionSpace.h"  #include "BinaryOp.h"
23  #include "escript/Data/BinaryOp.h"  #include "UnaryOp.h"
24  #include "escript/Data/UnaryOp.h"  #include "DataException.h"
 #include "escript/Data/DataException.h"  
25    
26  extern "C" {  extern "C" {
27  #include "escript/Data/DataC.h"  #include "DataC.h"
28    #include "./paso/Paso.h"
29  }  }
30    
 #include <iostream>  
31  #include <string>  #include <string>
 #include <memory>  
32  #include <algorithm>  #include <algorithm>
33    
34  #include <boost/shared_ptr.hpp>  #include <boost/shared_ptr.hpp>
35  #include <boost/python/object.hpp>  #include <boost/python/object.hpp>
 #include <boost/python/list.hpp>  
36  #include <boost/python/tuple.hpp>  #include <boost/python/tuple.hpp>
37  #include <boost/python/numeric.hpp>  #include <boost/python/numeric.hpp>
38    
39  namespace escript {  namespace escript {
40    
41  //  //
42  // Forward declaration for various implimentations of Data.  // Forward declaration for various implementations of Data.
 class DataEmpty;  
43  class DataConstant;  class DataConstant;
44  class DataTagged;  class DataTagged;
45  class DataExpanded;  class DataExpanded;
# Line 150  class Data { Line 144  class Data {
144       \param what - Input - A description of what this data represents.       \param what - Input - A description of what this data represents.
145       \param expanded - Input - Flag, if true fill the entire container with       \param expanded - Input - Flag, if true fill the entire container with
146                         the appropriate values.                         the appropriate values.
147        ==>*
148    */    */
149    Data(const DataTagged::TagListType& tagKeys,    Data(const DataTagged::TagListType& tagKeys,
150         const DataTagged::ValueListType& values,         const DataTagged::ValueListType& values,
# Line 206  class Data { Line 201  class Data {
201         const boost::python::tuple& shape=boost::python::make_tuple(),         const boost::python::tuple& shape=boost::python::make_tuple(),
202         const FunctionSpace& what=FunctionSpace(),         const FunctionSpace& what=FunctionSpace(),
203         bool expanded=false);         bool expanded=false);
204      /**
205         \brief
206         Destructor
207      */
208      ~Data();
209    
210    /**    /**
211       \brief       \brief
# Line 226  class Data { Line 226  class Data {
226    convertToNumArray();    convertToNumArray();
227    
228    /**    /**
      \brief fills the expanded Data object from values of a  python numarray object.  
   
   */  
   void  
   fillFromNumArray(const boost::python::numeric::array);  
   /**  
229       \brief       \brief
230       Return the values of all data-points for the given sample as a single python numarray object.       Return the values of all data-points for the given sample as a single python numarray object.
231    */    */
# Line 248  class Data { Line 242  class Data {
242    
243    /**    /**
244       \brief       \brief
245         Fills the expanded Data object from values of a python numarray object.
246      */
247      void
248      fillFromNumArray(const boost::python::numeric::array);
249    
250      /**
251         \brief
252         Return the tag number associated with the given data-point.
253    
254         The data-point number here corresponds to the data-point number in the
255         numarray returned by convertToNumArray.
256      */
257      int
258      getTagNumber(int dpno);
259    
260      /**
261         \brief
262       Return the C wrapper for the Data object.       Return the C wrapper for the Data object.
263    */    */
264    escriptDataC    escriptDataC
# Line 296  class Data { Line 307  class Data {
307       If possible convert this Data to DataTagged. This will only allow       If possible convert this Data to DataTagged. This will only allow
308       Constant data to be converted to tagged. An attempt to convert       Constant data to be converted to tagged. An attempt to convert
309       Expanded data to tagged will throw an exception.       Expanded data to tagged will throw an exception.
310        ==>*
311    */    */
312    void    void
313    tag();    tag();
# Line 514  class Data { Line 526  class Data {
526       cannot be converted to a DataTagged object.       cannot be converted to a DataTagged object.
527       \param tagKey - Input - Integer key.       \param tagKey - Input - Integer key.
528       \param value - Input - Value to associate with given key.       \param value - Input - Value to associate with given key.
529        ==>*
530    */    */
531    void    void
532    setTaggedValue(int tagKey,    setTaggedValue(int tagKey,
# Line 526  class Data { Line 539  class Data {
539       cannot be converted to a DataTagged object.       cannot be converted to a DataTagged object.
540       \param tagKey - Input - Integer key.       \param tagKey - Input - Integer key.
541       \param value - Input - Value to associate with given key.       \param value - Input - Value to associate with given key.
542        ==>*
543    */    */
544    void    void
545    setTaggedValueFromCPP(int tagKey,    setTaggedValueFromCPP(int tagKey,
# Line 610  class Data { Line 624  class Data {
624       *       *
625    */    */
626    Data    Data
627    whereZero() const;    whereZero(double tol=0.0) const;
628    
629    /**    /**
630       \brief       \brief
# Line 618  class Data { Line 632  class Data {
632       *       *
633    */    */
634    Data    Data
635    whereNonZero() const;    whereNonZero(double tol=0.0) const;
636    
637    /**    /**
638       \brief       \brief
# Line 684  class Data { Line 698  class Data {
698    const boost::python::tuple    const boost::python::tuple
699    mindp() const;    mindp() const;
700    
701      void
702      calc_mindp(int& SampleNo,
703                 int& DataPointNo) const;
704    
705    /**    /**
706       \brief       \brief
707       Return the length of each data point of this Data object.       Return the sign of each data point of this Data object.
708       sqrt(sum(A[i,j,k,l]^2))       -1 for negative values, zero for zero values, 1 for positive values.
709       *       *
710    */    */
711    Data    Data
712    length() const;    sign() const;
713    
714    /**    /**
715       \brief       \brief
716       Return the sign of each data point of this Data object.       Return the eigenvalues of the symmetric part at each data point of this Data object in increasing values.
717       -1 for negative values, zero for zero values, 1 for positive values.       Currently this function is restricted to rank 2, square shape, and dimension 3.
718       *       *
719    */    */
720    Data    Data
721    sign() const;    eigenvalues() const;
722    
723      /**
724         \brief
725         Return the eigenvalues and corresponding eigenvcetors of the symmetric part at each data point of this Data object.
726         the eigenvalues are ordered in increasing size where eigenvalues with relative difference less than
727         tol are treated as equal. The eigenvectors are orthogonal, normalized and the sclaed such that the
728         first non-zero entry is positive.
729         Currently this function is restricted to rank 2, square shape, and dimension 3
730         *
731      */
732      const boost::python::tuple
733      eigenvalues_and_eigenvectors(const double tol=1.e-12) const;
734    
735    /**    /**
736       \brief       \brief
# Line 714  class Data { Line 744  class Data {
744    /**    /**
745       \brief       \brief
746       Calculate the trace of each data point of this Data object.       Calculate the trace of each data point of this Data object.
      sum(A[i,i,i,i])  
747       *       *
748    */    */
749    Data    Data
# Line 746  class Data { Line 775  class Data {
775    
776    /**    /**
777       \brief       \brief
778         Return the asin of each data point of this Data object.
779         *
780      */
781      Data
782      asin() const;
783    
784      /**
785         \brief
786         Return the acos of each data point of this Data object.
787         *
788      */
789      Data
790      acos() const;
791    
792      /**
793         \brief
794         Return the atan of each data point of this Data object.
795         *
796      */
797      Data
798      atan() const;
799    
800      /**
801         \brief
802         Return the sinh of each data point of this Data object.
803         *
804      */
805      Data
806      sinh() const;
807    
808      /**
809         \brief
810         Return the cosh of each data point of this Data object.
811         *
812      */
813      Data
814      cosh() const;
815    
816      /**
817         \brief
818         Return the tanh of each data point of this Data object.
819         *
820      */
821      Data
822      tanh() const;
823    
824      /**
825         \brief
826         Return the asinh of each data point of this Data object.
827         *
828      */
829      Data
830      asinh() const;
831    
832      /**
833         \brief
834         Return the acosh of each data point of this Data object.
835         *
836      */
837      Data
838      acosh() const;
839    
840      /**
841         \brief
842         Return the atanh of each data point of this Data object.
843         *
844      */
845      Data
846      atanh() const;
847    
848      /**
849         \brief
850       Return the log to base 10 of each data point of this Data object.       Return the log to base 10 of each data point of this Data object.
851       *       *
852    */    */
853    Data    Data
854    log() const;    log10() const;
855    
856    /**    /**
857       \brief       \brief
# Line 758  class Data { Line 859  class Data {
859       *       *
860    */    */
861    Data    Data
862    ln() const;    log() const;
863    
864    /**    /**
865       \brief       \brief
# Line 815  class Data { Line 916  class Data {
916    
917    /**    /**
918       \brief       \brief
919         Return the given power of each data point of this boost python object.
920        
921         \param left Input - the bases
922         *
923       */
924    
925      Data
926      rpowO(const boost::python::object& left) const;
927    
928      /**
929         \brief
930       writes the object to a file in the DX file format       writes the object to a file in the DX file format
931    */    */
932    void    void
# Line 961  class Data { Line 1073  class Data {
1073    extractData(const std::string fileName,    extractData(const std::string fileName,
1074                const FunctionSpace& fspace);                const FunctionSpace& fspace);
1075    
1076    
1077      /**
1078         \brief
1079         print the data values to stdout. Used for debugging
1080      */
1081      void print();
1082    
1083   protected:   protected:
1084    
1085   private:   private:
# Line 1400  inline Line 1519  inline
1519  Data  Data
1520  Data::dp_algorithm(BinaryFunction operation, double initial_value) const  Data::dp_algorithm(BinaryFunction operation, double initial_value) const
1521  {  {
   Data result(0,DataArrayView::ShapeType(),getFunctionSpace(),isExpanded());  
1522    if (isExpanded()) {    if (isExpanded()) {
1523        Data result(0,DataArrayView::ShapeType(),getFunctionSpace(),isExpanded());
1524      DataExpanded* dataE=dynamic_cast<DataExpanded*>(m_data.get());      DataExpanded* dataE=dynamic_cast<DataExpanded*>(m_data.get());
1525      DataExpanded* resultE=dynamic_cast<DataExpanded*>(result.m_data.get());      DataExpanded* resultE=dynamic_cast<DataExpanded*>(result.m_data.get());
1526      EsysAssert((dataE!=0), "Programming error - casting data to DataExpanded.");      EsysAssert((dataE!=0), "Programming error - casting data to DataExpanded.");
1527      EsysAssert((resultE!=0), "Programming error - casting result to DataExpanded.");      EsysAssert((resultE!=0), "Programming error - casting result to DataExpanded.");
1528      escript::dp_algorithm(*dataE,*resultE,operation,initial_value);      escript::dp_algorithm(*dataE,*resultE,operation,initial_value);
1529        return result;
1530    } else if (isTagged()) {    } else if (isTagged()) {
1531      DataTagged* dataT=dynamic_cast<DataTagged*>(m_data.get());      DataTagged* dataT=dynamic_cast<DataTagged*>(m_data.get());
1532        DataArrayView::ShapeType viewShape;
1533        DataArrayView::ValueType viewData(1);
1534        viewData[0]=0;
1535        DataArrayView defaultValue(viewData,viewShape);
1536        DataTagged::TagListType keys;
1537        DataTagged::ValueListType values;
1538        DataTagged::DataMapType::const_iterator i;
1539        for (i=dataT->getTagLookup().begin();i!=dataT->getTagLookup().end();i++) {
1540          keys.push_back(i->first);
1541          values.push_back(defaultValue);
1542        }
1543        Data result(keys,values,defaultValue,getFunctionSpace());
1544      DataTagged* resultT=dynamic_cast<DataTagged*>(result.m_data.get());      DataTagged* resultT=dynamic_cast<DataTagged*>(result.m_data.get());
1545      EsysAssert((dataT!=0), "Programming error - casting data to DataTagged.");      EsysAssert((dataT!=0), "Programming error - casting data to DataTagged.");
1546      EsysAssert((resultT!=0), "Programming error - casting result to DataTagged.");      EsysAssert((resultT!=0), "Programming error - casting result to DataTagged.");
1547      escript::dp_algorithm(*dataT,*resultT,operation,initial_value);      escript::dp_algorithm(*dataT,*resultT,operation,initial_value);
1548        return result;
1549    } else if (isConstant()) {    } else if (isConstant()) {
1550        Data result(0,DataArrayView::ShapeType(),getFunctionSpace(),isExpanded());
1551      DataConstant* dataC=dynamic_cast<DataConstant*>(m_data.get());      DataConstant* dataC=dynamic_cast<DataConstant*>(m_data.get());
1552      DataConstant* resultC=dynamic_cast<DataConstant*>(result.m_data.get());      DataConstant* resultC=dynamic_cast<DataConstant*>(result.m_data.get());
1553      EsysAssert((dataC!=0), "Programming error - casting data to DataConstant.");      EsysAssert((dataC!=0), "Programming error - casting data to DataConstant.");
1554      EsysAssert((resultC!=0), "Programming error - casting result to DataConstant.");      EsysAssert((resultC!=0), "Programming error - casting result to DataConstant.");
1555      escript::dp_algorithm(*dataC,*resultC,operation,initial_value);      escript::dp_algorithm(*dataC,*resultC,operation,initial_value);
1556        return result;
1557    }    }
1558    return result;    Data falseRetVal; // to keep compiler quiet
1559      return falseRetVal;
1560  }  }
1561    
1562  }  }

Legend:
Removed from v.147  
changed lines
  Added in v.751

  ViewVC Help
Powered by ViewVC 1.1.26