/[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 615 by elspeth, Wed Mar 22 02:12:00 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    
17  #include "escript/Data/DataException.h"  #include "DataArrayView.h"
18  #include "escript/Data/DataArrayView.h"  #include "DataConstant.h"
19  #include "escript/Data/DataConstant.h"  #include "DataTagged.h"
20  #include "escript/Data/DataExpanded.h"  #include "DataExpanded.h"
 #include "escript/Data/DataTagged.h"  
   
 #include <iostream>  
 #include <boost/scoped_ptr.hpp>  
 #include <functional>  
 #include <string>  
21    
22  namespace escript {  namespace escript {
23    
24  /**  /**
25     \brief     \brief
26     Perform the given unary operation.     Perform the given unary operation on each data point of the given Data object.
27       Called by Data::unaryOp.
28       Calls DataArrayView::unaryOp.
29       For DataExpanded objects, operation is done in parallel.
30     \param data Input/Output - The data.     \param data Input/Output - The data.
31       \param operation Input - The operation to perform.
32  */  */
33    
34  template <class UnaryFunction>  template <class UnaryFunction>
35  inline void unaryOp(DataExpanded& data, UnaryFunction operation)  inline
36    void
37    unaryOp(DataExpanded& data,
38            UnaryFunction operation)
39  {  {
40    int i,j;    int i,j;
41    DataArrayView::ValueType::size_type numDPPSample=data.getNumDPPSample();    DataArrayView::ValueType::size_type numDPPSample=data.getNumDPPSample();
42    DataArrayView::ValueType::size_type numSamples=data.getNumSamples();    DataArrayView::ValueType::size_type numSamples=data.getNumSamples();
43  #pragma omp parallel for private(i,j) schedule(static)    #pragma omp parallel for private(i,j) schedule(static)
44     for (i=0;i<numSamples;++i) {    for (i=0;i<numSamples;i++) {
45       for (j=0;j<numDPPSample;++j) {      for (j=0;j<numDPPSample;j++) {
46        data.getPointDataView().unaryOp(data.getPointOffset(i,j),        data.getPointDataView().unaryOp(data.getPointOffset(i,j),operation);
                   operation);  
47      }      }
48    }    }
49  }  }
50    
51  template <class UnaryFunction>  template <class UnaryFunction>
52  inline void unaryOp(DataTagged& data, UnaryFunction operation)  inline
53    void
54    unaryOp(DataTagged& data,
55            UnaryFunction operation)
56  {  {
57    //    // perform the operation on each tagged value
   // perform the operation on each tagged value including the default  
58    const DataTagged::DataMapType& lookup=data.getTagLookup();    const DataTagged::DataMapType& lookup=data.getTagLookup();
59    DataTagged::DataMapType::const_iterator i;    DataTagged::DataMapType::const_iterator i;
60    DataTagged::DataMapType::const_iterator lookupEnd=lookup.end();    DataTagged::DataMapType::const_iterator lookupEnd=lookup.end();
61    DataArrayView& dataView=data.getPointDataView();    DataArrayView& dataView=data.getPointDataView();
62    for (i=lookup.begin();i!=lookupEnd;++i) {    for (i=lookup.begin();i!=lookupEnd;i++) {
63      dataView.unaryOp(i->second,operation);      dataView.unaryOp(i->second,operation);
64    }    }
65    //    // perform the operation on the default value
   // finally perform the operation on the default value  
66    data.getDefaultValue().unaryOp(operation);    data.getDefaultValue().unaryOp(operation);
67  }  }
68    
69  template <class UnaryFunction>  template <class UnaryFunction>
70  inline void unaryOp(DataConstant& data, UnaryFunction operation)  inline
71    void
72    unaryOp(DataConstant& data,
73            UnaryFunction operation)
74  {  {
75    data.getPointDataView().unaryOp(operation);    data.getPointDataView().unaryOp(operation);
76  }  }

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

  ViewVC Help
Powered by ViewVC 1.1.26