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

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

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

trunk/esys2/escript/src/Data/UnaryOp.h revision 82 by jgs, Tue Oct 26 06:53:54 2004 UTC trunk/escript/src/UnaryOp.h revision 757 by woo409, Mon Jun 26 13:12:56 2006 UTC
# Line 1  Line 1 
1    // $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 person has a software    *   *                                                          *
11   * license agreement with ACcESS.                                             *   ************************************************************
  *                                                                            *  
  ******************************************************************************  
12  */  */
13                                                                              
14  #if !defined  escript_UnaryOp_20040315_H  #if !defined escript_UnaryOp_20040315_H
15  #define escript_UnaryOp_20040315_H  #define escript_UnaryOp_20040315_H
16    #include "system_dep.h"
17    
18  #include "escript/Data/DataException.h"  #include "DataArrayView.h"
19  #include "escript/Data/DataArrayView.h"  #include "DataConstant.h"
20  #include "escript/Data/DataConstant.h"  #include "DataTagged.h"
21  #include "escript/Data/DataExpanded.h"  #include "DataExpanded.h"
 #include "escript/Data/DataTagged.h"  
   
 #include <iostream>  
 #include <boost/scoped_ptr.hpp>  
 #include <functional>  
 #include <string>  
22    
23  namespace escript {  namespace escript {
24    
25  /**  /**
26     \brief     \brief
27     Perform the given unary operation.     Perform the given unary operation on each data point of the given Data object.
28       Called by Data::unaryOp.
29       Calls DataArrayView::unaryOp.
30       For DataExpanded objects, operation is done in parallel.
31     \param data Input/Output - The data.     \param data Input/Output - The data.
32       \param operation Input - The operation to perform.
33  */  */
34    
35  template <class UnaryFunction>  template <class UnaryFunction>
36  inline void unaryOp(DataExpanded& data, UnaryFunction operation)  inline
37    void
38    unaryOp(DataExpanded& data,
39            UnaryFunction operation)
40  {  {
41    int i,j;    int i,j;
42    DataArrayView::ValueType::size_type numDPPSample=data.getNumDPPSample();    DataArrayView::ValueType::size_type numDPPSample=data.getNumDPPSample();
43    DataArrayView::ValueType::size_type numSamples=data.getNumSamples();    DataArrayView::ValueType::size_type numSamples=data.getNumSamples();
44  #pragma omp parallel for private(i,j) schedule(static)    #pragma omp parallel for private(i,j) schedule(static)
45     for (i=0;i<numSamples;++i) {    for (i=0;i<numSamples;i++) {
46       for (j=0;j<numDPPSample;++j) {      for (j=0;j<numDPPSample;j++) {
47        data.getPointDataView().unaryOp(data.getPointOffset(i,j),        data.getPointDataView().unaryOp(data.getPointOffset(i,j),operation);
                   operation);  
48      }      }
49    }    }
50  }  }
51    
52  template <class UnaryFunction>  template <class UnaryFunction>
53  inline void unaryOp(DataTagged& data, UnaryFunction operation)  inline
54    void
55    unaryOp(DataTagged& data,
56            UnaryFunction operation)
57  {  {
58    //    // perform the operation on each tagged value
   // perform the operation on each tagged value including the default  
59    const DataTagged::DataMapType& lookup=data.getTagLookup();    const DataTagged::DataMapType& lookup=data.getTagLookup();
60    DataTagged::DataMapType::const_iterator i;    DataTagged::DataMapType::const_iterator i;
61    DataTagged::DataMapType::const_iterator lookupEnd=lookup.end();    DataTagged::DataMapType::const_iterator lookupEnd=lookup.end();
62    DataArrayView& dataView=data.getPointDataView();    DataArrayView& dataView=data.getPointDataView();
63    for (i=lookup.begin();i!=lookupEnd;++i) {    for (i=lookup.begin();i!=lookupEnd;i++) {
64      dataView.unaryOp(i->second,operation);      dataView.unaryOp(i->second,operation);
65    }    }
66    //    // perform the operation on the default value
   // finally perform the operation on the default value  
67    data.getDefaultValue().unaryOp(operation);    data.getDefaultValue().unaryOp(operation);
68  }  }
69    
70  template <class UnaryFunction>  template <class UnaryFunction>
71  inline void unaryOp(DataConstant& data, UnaryFunction operation)  inline
72    void
73    unaryOp(DataConstant& data,
74            UnaryFunction operation)
75  {  {
76    data.getPointDataView().unaryOp(operation);    data.getPointDataView().unaryOp(operation);
77  }  }

Legend:
Removed from v.82  
changed lines
  Added in v.757

  ViewVC Help
Powered by ViewVC 1.1.26