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

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

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

trunk/esys2/escript/src/Data/Data.h revision 149 by jgs, Thu Sep 1 03:31:39 2005 UTC trunk/escript/src/Data.h revision 698 by gross, Fri Mar 31 04:52:55 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  }  }
29    
 #include <iostream>  
30  #include <string>  #include <string>
 #include <memory>  
31  #include <algorithm>  #include <algorithm>
32    
33  #include <boost/shared_ptr.hpp>  #include <boost/shared_ptr.hpp>
34  #include <boost/python/object.hpp>  #include <boost/python/object.hpp>
 #include <boost/python/list.hpp>  
35  #include <boost/python/tuple.hpp>  #include <boost/python/tuple.hpp>
36  #include <boost/python/numeric.hpp>  #include <boost/python/numeric.hpp>
37    
# Line 45  namespace escript { Line 39  namespace escript {
39    
40  //  //
41  // Forward declaration for various implementations of Data.  // Forward declaration for various implementations of Data.
 class DataEmpty;  
42  class DataConstant;  class DataConstant;
43  class DataTagged;  class DataTagged;
44  class DataExpanded;  class DataExpanded;
# Line 150  class Data { Line 143  class Data {
143       \param what - Input - A description of what this data represents.       \param what - Input - A description of what this data represents.
144       \param expanded - Input - Flag, if true fill the entire container with       \param expanded - Input - Flag, if true fill the entire container with
145                         the appropriate values.                         the appropriate values.
146        ==>*
147    */    */
148    Data(const DataTagged::TagListType& tagKeys,    Data(const DataTagged::TagListType& tagKeys,
149         const DataTagged::ValueListType& values,         const DataTagged::ValueListType& values,
# Line 206  class Data { Line 200  class Data {
200         const boost::python::tuple& shape=boost::python::make_tuple(),         const boost::python::tuple& shape=boost::python::make_tuple(),
201         const FunctionSpace& what=FunctionSpace(),         const FunctionSpace& what=FunctionSpace(),
202         bool expanded=false);         bool expanded=false);
203      /**
204         \brief
205         Destructor
206      */
207      ~Data();
208    
209    /**    /**
210       \brief       \brief
# Line 307  class Data { Line 306  class Data {
306       If possible convert this Data to DataTagged. This will only allow       If possible convert this Data to DataTagged. This will only allow
307       Constant data to be converted to tagged. An attempt to convert       Constant data to be converted to tagged. An attempt to convert
308       Expanded data to tagged will throw an exception.       Expanded data to tagged will throw an exception.
309        ==>*
310    */    */
311    void    void
312    tag();    tag();
# Line 525  class Data { Line 525  class Data {
525       cannot be converted to a DataTagged object.       cannot be converted to a DataTagged object.
526       \param tagKey - Input - Integer key.       \param tagKey - Input - Integer key.
527       \param value - Input - Value to associate with given key.       \param value - Input - Value to associate with given key.
528        ==>*
529    */    */
530    void    void
531    setTaggedValue(int tagKey,    setTaggedValue(int tagKey,
# Line 537  class Data { Line 538  class Data {
538       cannot be converted to a DataTagged object.       cannot be converted to a DataTagged object.
539       \param tagKey - Input - Integer key.       \param tagKey - Input - Integer key.
540       \param value - Input - Value to associate with given key.       \param value - Input - Value to associate with given key.
541        ==>*
542    */    */
543    void    void
544    setTaggedValueFromCPP(int tagKey,    setTaggedValueFromCPP(int tagKey,
# Line 621  class Data { Line 623  class Data {
623       *       *
624    */    */
625    Data    Data
626    whereZero() const;    whereZero(double tol=0.0) const;
627    
628    /**    /**
629       \brief       \brief
# Line 629  class Data { Line 631  class Data {
631       *       *
632    */    */
633    Data    Data
634    whereNonZero() const;    whereNonZero(double tol=0.0) const;
635    
636    /**    /**
637       \brief       \brief
# Line 701  class Data { Line 703  class Data {
703    
704    /**    /**
705       \brief       \brief
706       Return the length of each data point of this Data object.       Return the sign of each data point of this Data object.
707       sqrt(sum(A[i,j,k,l]^2))       -1 for negative values, zero for zero values, 1 for positive values.
708       *       *
709    */    */
710    Data    Data
711    length() const;    sign() const;
712    
713    /**    /**
714       \brief       \brief
715       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.
716       -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.
717       *       *
718    */    */
719    Data    Data
720    sign() const;    eigenvalues() const;
721    
722      /**
723         \brief
724         Return the eigenvalues and corresponding eigenvcetors of the symmetric part at each data point of this Data object.
725         the eigenvalues are ordered in increasing size where eigenvalues with relative difference less than
726         tol are treated as equal. The eigenvectors are orthogonal, normalized and the sclaed such that the
727         first non-zero entry is positive.
728         Currently this function is restricted to rank 2, square shape, and dimension 3
729         *
730      */
731      const boost::python::tuple
732      eigenvalues_and_eigenvectors(const double tol=1.e-12) const;
733    
734    /**    /**
735       \brief       \brief
# Line 729  class Data { Line 743  class Data {
743    /**    /**
744       \brief       \brief
745       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])  
746       *       *
747    */    */
748    Data    Data
# Line 761  class Data { Line 774  class Data {
774    
775    /**    /**
776       \brief       \brief
777         Return the asin of each data point of this Data object.
778         *
779      */
780      Data
781      asin() const;
782    
783      /**
784         \brief
785         Return the acos of each data point of this Data object.
786         *
787      */
788      Data
789      acos() const;
790    
791      /**
792         \brief
793         Return the atan of each data point of this Data object.
794         *
795      */
796      Data
797      atan() const;
798    
799      /**
800         \brief
801         Return the sinh of each data point of this Data object.
802         *
803      */
804      Data
805      sinh() const;
806    
807      /**
808         \brief
809         Return the cosh of each data point of this Data object.
810         *
811      */
812      Data
813      cosh() const;
814    
815      /**
816         \brief
817         Return the tanh of each data point of this Data object.
818         *
819      */
820      Data
821      tanh() const;
822    
823      /**
824         \brief
825         Return the asinh of each data point of this Data object.
826         *
827      */
828      Data
829      asinh() const;
830    
831      /**
832         \brief
833         Return the acosh of each data point of this Data object.
834         *
835      */
836      Data
837      acosh() const;
838    
839      /**
840         \brief
841         Return the atanh of each data point of this Data object.
842         *
843      */
844      Data
845      atanh() const;
846    
847      /**
848         \brief
849       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.
850       *       *
851    */    */
852    Data    Data
853    log() const;    log10() const;
854    
855    /**    /**
856       \brief       \brief
# Line 773  class Data { Line 858  class Data {
858       *       *
859    */    */
860    Data    Data
861    ln() const;    log() const;
862    
863    /**    /**
864       \brief       \brief
# Line 1415  inline Line 1500  inline
1500  Data  Data
1501  Data::dp_algorithm(BinaryFunction operation, double initial_value) const  Data::dp_algorithm(BinaryFunction operation, double initial_value) const
1502  {  {
   Data result(0,DataArrayView::ShapeType(),getFunctionSpace(),isExpanded());  
1503    if (isExpanded()) {    if (isExpanded()) {
1504        Data result(0,DataArrayView::ShapeType(),getFunctionSpace(),isExpanded());
1505      DataExpanded* dataE=dynamic_cast<DataExpanded*>(m_data.get());      DataExpanded* dataE=dynamic_cast<DataExpanded*>(m_data.get());
1506      DataExpanded* resultE=dynamic_cast<DataExpanded*>(result.m_data.get());      DataExpanded* resultE=dynamic_cast<DataExpanded*>(result.m_data.get());
1507      EsysAssert((dataE!=0), "Programming error - casting data to DataExpanded.");      EsysAssert((dataE!=0), "Programming error - casting data to DataExpanded.");
1508      EsysAssert((resultE!=0), "Programming error - casting result to DataExpanded.");      EsysAssert((resultE!=0), "Programming error - casting result to DataExpanded.");
1509      escript::dp_algorithm(*dataE,*resultE,operation,initial_value);      escript::dp_algorithm(*dataE,*resultE,operation,initial_value);
1510        return result;
1511    } else if (isTagged()) {    } else if (isTagged()) {
1512      DataTagged* dataT=dynamic_cast<DataTagged*>(m_data.get());      DataTagged* dataT=dynamic_cast<DataTagged*>(m_data.get());
1513        DataArrayView::ShapeType viewShape;
1514        DataArrayView::ValueType viewData(1);
1515        viewData[0]=0;
1516        DataArrayView defaultValue(viewData,viewShape);
1517        DataTagged::TagListType keys;
1518        DataTagged::ValueListType values;
1519        DataTagged::DataMapType::const_iterator i;
1520        for (i=dataT->getTagLookup().begin();i!=dataT->getTagLookup().end();i++) {
1521          keys.push_back(i->first);
1522          values.push_back(defaultValue);
1523        }
1524        Data result(keys,values,defaultValue,getFunctionSpace());
1525      DataTagged* resultT=dynamic_cast<DataTagged*>(result.m_data.get());      DataTagged* resultT=dynamic_cast<DataTagged*>(result.m_data.get());
1526      EsysAssert((dataT!=0), "Programming error - casting data to DataTagged.");      EsysAssert((dataT!=0), "Programming error - casting data to DataTagged.");
1527      EsysAssert((resultT!=0), "Programming error - casting result to DataTagged.");      EsysAssert((resultT!=0), "Programming error - casting result to DataTagged.");
1528      escript::dp_algorithm(*dataT,*resultT,operation,initial_value);      escript::dp_algorithm(*dataT,*resultT,operation,initial_value);
1529        return result;
1530    } else if (isConstant()) {    } else if (isConstant()) {
1531        Data result(0,DataArrayView::ShapeType(),getFunctionSpace(),isExpanded());
1532      DataConstant* dataC=dynamic_cast<DataConstant*>(m_data.get());      DataConstant* dataC=dynamic_cast<DataConstant*>(m_data.get());
1533      DataConstant* resultC=dynamic_cast<DataConstant*>(result.m_data.get());      DataConstant* resultC=dynamic_cast<DataConstant*>(result.m_data.get());
1534      EsysAssert((dataC!=0), "Programming error - casting data to DataConstant.");      EsysAssert((dataC!=0), "Programming error - casting data to DataConstant.");
1535      EsysAssert((resultC!=0), "Programming error - casting result to DataConstant.");      EsysAssert((resultC!=0), "Programming error - casting result to DataConstant.");
1536      escript::dp_algorithm(*dataC,*resultC,operation,initial_value);      escript::dp_algorithm(*dataC,*resultC,operation,initial_value);
1537        return result;
1538    }    }
1539    return result;    Data falseRetVal; // to keep compiler quiet
1540      return falseRetVal;
1541  }  }
1542    
1543  }  }

Legend:
Removed from v.149  
changed lines
  Added in v.698

  ViewVC Help
Powered by ViewVC 1.1.26