/[escript]/trunk/escript/src/Data.cpp
ViewVC logotype

Diff of /trunk/escript/src/Data.cpp

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

temp/escript/src/Data.cpp revision 1387 by trankine, Fri Jan 11 07:45:26 2008 UTC trunk/escript/src/Data.cpp revision 1841 by gross, Fri Oct 3 03:57:52 2008 UTC
# Line 1  Line 1 
1    
 /* $Id$ */  
   
2  /*******************************************************  /*******************************************************
3   *  *
4   *           Copyright 2003-2007 by ACceSS MNRF  * Copyright (c) 2003-2008 by University of Queensland
5   *       Copyright 2007 by University of Queensland  * Earth Systems Science Computational Center (ESSCC)
6   *  * http://www.uq.edu.au/esscc
7   *                http://esscc.uq.edu.au  *
8   *        Primary Business: Queensland, Australia  * Primary Business: Queensland, Australia
9   *  Licensed under the Open Software License version 3.0  * Licensed under the Open Software License version 3.0
10   *     http://www.opensource.org/licenses/osl-3.0.php  * http://www.opensource.org/licenses/osl-3.0.php
11   *  *
12   *******************************************************/  *******************************************************/
13    
14    
15  #include "Data.h"  #include "Data.h"
16    
# Line 19  Line 18 
18  #include "DataConstant.h"  #include "DataConstant.h"
19  #include "DataTagged.h"  #include "DataTagged.h"
20  #include "DataEmpty.h"  #include "DataEmpty.h"
 #include "DataArrayView.h"  
21  #include "FunctionSpaceFactory.h"  #include "FunctionSpaceFactory.h"
22  #include "AbstractContinuousDomain.h"  #include "AbstractContinuousDomain.h"
23  #include "UnaryFuncs.h"  #include "UnaryFuncs.h"
24    #include "FunctionSpaceException.h"
25    
26  extern "C" {  extern "C" {
27  #include "escript/blocktimer.h"  #include "escript/blocktimer.h"
28  }  }
# Line 56  Data::Data(double value, Line 56  Data::Data(double value,
56             const FunctionSpace& what,             const FunctionSpace& what,
57             bool expanded)             bool expanded)
58  {  {
59    DataArrayView::ShapeType dataPointShape;    DataTypes::ShapeType dataPointShape;
60    for (int i = 0; i < shape.attr("__len__")(); ++i) {    for (int i = 0; i < shape.attr("__len__")(); ++i) {
61      dataPointShape.push_back(extract<const int>(shape[i]));      dataPointShape.push_back(extract<const int>(shape[i]));
62    }    }
63    
64    int len = DataArrayView::noValues(dataPointShape);    int len = DataTypes::noValues(dataPointShape);
65    DataVector temp_data(len,value,len);    DataVector temp_data(len,value,len);
66    DataArrayView temp_dataView(temp_data, dataPointShape);  //   DataArrayView temp_dataView(temp_data, dataPointShape);
67    
68    initialise(temp_dataView, what, expanded);  //   initialise(temp_dataView, what, expanded);
69      initialise(temp_data, dataPointShape, what, expanded);
70    
71    m_protected=false;    m_protected=false;
72  }  }
73    
74  Data::Data(double value,  Data::Data(double value,
75         const DataArrayView::ShapeType& dataPointShape,         const DataTypes::ShapeType& dataPointShape,
76         const FunctionSpace& what,         const FunctionSpace& what,
77             bool expanded)             bool expanded)
78  {  {
79    int len = DataArrayView::noValues(dataPointShape);    int len = DataTypes::noValues(dataPointShape);
80    
81    DataVector temp_data(len,value,len);    DataVector temp_data(len,value,len);
82    DataArrayView temp_dataView(temp_data, dataPointShape);  //   DataArrayView temp_dataView(temp_data, dataPointShape);
83    
84    initialise(temp_dataView, what, expanded);  //   initialise(temp_dataView, what, expanded);
85      initialise(temp_data, dataPointShape, what, expanded);
86    
87    m_protected=false;    m_protected=false;
88  }  }
# Line 91  Data::Data(const Data& inData) Line 93  Data::Data(const Data& inData)
93    m_protected=inData.isProtected();    m_protected=inData.isProtected();
94  }  }
95    
96    
97  Data::Data(const Data& inData,  Data::Data(const Data& inData,
98             const DataArrayView::RegionType& region)             const DataTypes::RegionType& region)
99  {  {
100    //    //
101    // Create Data which is a slice of another Data    // Create Data which is a slice of another Data
# Line 105  Data::Data(const Data& inData, Line 108  Data::Data(const Data& inData,
108  Data::Data(const Data& inData,  Data::Data(const Data& inData,
109             const FunctionSpace& functionspace)             const FunctionSpace& functionspace)
110  {  {
111      if (inData.isEmpty())
112      {
113        throw DataException("Error - will not interpolate for instances of DataEmpty.");
114      }
115    if (inData.getFunctionSpace()==functionspace) {    if (inData.getFunctionSpace()==functionspace) {
116      m_data=inData.m_data;      m_data=inData.m_data;
117      } else if (inData.isConstant()) { // for a constant function, we just need to use the new function space
118        if (!inData.probeInterpolation(functionspace))
119        {           // Even though this is constant, we still need to check whether interpolation is allowed
120        throw FunctionSpaceException("Call to probeInterpolation returned false for DataConstant.");
121        }
122        DataConstant* dc=new DataConstant(functionspace,inData.m_data->getShape(),inData.m_data->getVector());  
123        m_data=shared_ptr<DataAbstract>(dc);
124    } else {    } else {
125      Data tmp(0,inData.getPointDataView().getShape(),functionspace,true);      Data tmp(0,inData.getDataPointShape(),functionspace,true);
126      // Note: Must use a reference or pointer to a derived object      // Note: Must use a reference or pointer to a derived object
127      // in order to get polymorphic behaviour. Shouldn't really      // in order to get polymorphic behaviour. Shouldn't really
128      // be able to create an instance of AbstractDomain but that was done      // be able to create an instance of AbstractDomain but that was done
# Line 124  Data::Data(const Data& inData, Line 138  Data::Data(const Data& inData,
138    m_protected=false;    m_protected=false;
139  }  }
140    
141  Data::Data(const DataTagged::TagListType& tagKeys,  // Data::Data(const DataTagged::TagListType& tagKeys,
142             const DataTagged::ValueListType & values,  //            const DataTagged::ValueListType & values,
143             const DataArrayView& defaultValue,  //            const DataArrayView& defaultValue,
144             const FunctionSpace& what,  //            const FunctionSpace& what,
145             bool expanded)  //            bool expanded)
146    // {
147    //   DataAbstract* temp=new DataTagged(tagKeys,values,defaultValue,what);
148    //   shared_ptr<DataAbstract> temp_data(temp);
149    //   m_data=temp_data;
150    //   m_protected=false;
151    //   if (expanded) {
152    //     expand();
153    //   }
154    // }
155    
156    
157    
158    Data::Data(DataAbstract* underlyingdata)
159  {  {
160    DataAbstract* temp=new DataTagged(tagKeys,values,defaultValue,what);      m_data=shared_ptr<DataAbstract>(underlyingdata);
161    shared_ptr<DataAbstract> temp_data(temp);      m_protected=false;
   m_data=temp_data;  
   m_protected=false;  
   if (expanded) {  
     expand();  
   }  
162  }  }
163    
164  Data::Data(const numeric::array& value,  Data::Data(const numeric::array& value,
# Line 146  Data::Data(const numeric::array& value, Line 168  Data::Data(const numeric::array& value,
168    initialise(value,what,expanded);    initialise(value,what,expanded);
169    m_protected=false;    m_protected=false;
170  }  }
171    /*
172  Data::Data(const DataArrayView& value,  Data::Data(const DataArrayView& value,
173         const FunctionSpace& what,         const FunctionSpace& what,
174             bool expanded)             bool expanded)
175  {  {
176    initialise(value,what,expanded);    initialise(value,what,expanded);
177    m_protected=false;    m_protected=false;
178    }*/
179    
180    Data::Data(const DataTypes::ValueType& value,
181             const DataTypes::ShapeType& shape,
182                     const FunctionSpace& what,
183                     bool expanded)
184    {
185       initialise(value,shape,what,expanded);
186       m_protected=false;
187  }  }
188    
189    
190  Data::Data(const object& value,  Data::Data(const object& value,
191         const FunctionSpace& what,         const FunctionSpace& what,
192             bool expanded)             bool expanded)
# Line 168  Data::Data(const object& value, Line 200  Data::Data(const object& value,
200  Data::Data(const object& value,  Data::Data(const object& value,
201             const Data& other)             const Data& other)
202  {  {
   
203    numeric::array asNumArray(value);    numeric::array asNumArray(value);
204    
   
205    // extract the shape of the numarray    // extract the shape of the numarray
206    DataArrayView::ShapeType tempShape;    DataTypes::ShapeType tempShape=DataTypes::shapeFromNumArray(asNumArray);
207    for (int i=0; i < asNumArray.getrank(); i++) {  // /*  for (int i=0; i < asNumArray.getrank(); i++) {
208      tempShape.push_back(extract<int>(asNumArray.getshape()[i]));  //     tempShape.push_back(extract<int>(asNumArray.getshape()[i]));
209    }  //   }*/
210    // get the space for the data vector  //   // get the space for the data vector
211    int len = DataArrayView::noValues(tempShape);  //   int len = DataTypes::noValues(tempShape);
212    DataVector temp_data(len, 0.0, len);  //   DataVector temp_data(len, 0.0, len);
213    DataArrayView temp_dataView(temp_data, tempShape);  // /*  DataArrayView temp_dataView(temp_data, tempShape);
214    temp_dataView.copy(asNumArray);  //   temp_dataView.copy(asNumArray);*/
215    //   temp_data.copyFromNumArray(asNumArray);
216    
217    //    //
218    // Create DataConstant using the given value and all other parameters    // Create DataConstant using the given value and all other parameters
219    // copied from other. If value is a rank 0 object this Data    // copied from other. If value is a rank 0 object this Data
220    // will assume the point data shape of other.    // will assume the point data shape of other.
221    
222    if (temp_dataView.getRank()==0) {    if (DataTypes::getRank(tempShape)/*temp_dataView.getRank()*/==0) {
223      int len = DataArrayView::noValues(other.getPointDataView().getShape());  
224    
225        // get the space for the data vector
226        int len1 = DataTypes::noValues(tempShape);
227        DataVector temp_data(len1, 0.0, len1);
228        temp_data.copyFromNumArray(asNumArray);
229    
230        int len = DataTypes::noValues(other.getDataPointShape());
231    
232        DataVector temp2_data(len, temp_data[0]/*temp_dataView()*/, len);
233        //DataArrayView temp2_dataView(temp2_data, other.getPointDataView().getShape());
234    //     initialise(temp2_dataView, other.getFunctionSpace(), false);
235    
236        DataConstant* t=new DataConstant(other.getFunctionSpace(),other.getDataPointShape(),temp2_data);
237        boost::shared_ptr<DataAbstract> sp(t);
238        m_data=sp;
239    
     DataVector temp2_data(len, temp_dataView(), len);  
     DataArrayView temp2_dataView(temp2_data, other.getPointDataView().getShape());  
     initialise(temp2_dataView, other.getFunctionSpace(), false);  
240    
241    } else {    } else {
242      //      //
243      // Create a DataConstant with the same sample shape as other      // Create a DataConstant with the same sample shape as other
244      initialise(temp_dataView, other.getFunctionSpace(), false);  //     initialise(temp_dataView, other.getFunctionSpace(), false);
245        DataConstant* t=new DataConstant(asNumArray,other.getFunctionSpace());
246        boost::shared_ptr<DataAbstract> sp(t);
247        m_data=sp;
248    }    }
249    m_protected=false;    m_protected=false;
250  }  }
# Line 208  Data::~Data() Line 254  Data::~Data()
254    
255  }  }
256    
257    
258    
259    void
260    Data::initialise(const boost::python::numeric::array& value,
261                     const FunctionSpace& what,
262                     bool expanded)
263    {
264      //
265      // Construct a Data object of the appropriate type.
266      // Construct the object first as there seems to be a bug which causes
267      // undefined behaviour if an exception is thrown during construction
268      // within the shared_ptr constructor.
269      if (expanded) {
270        DataAbstract* temp=new DataExpanded(value, what);
271        boost::shared_ptr<DataAbstract> temp_data(temp);
272        m_data=temp_data;
273      } else {
274        DataAbstract* temp=new DataConstant(value, what);
275        boost::shared_ptr<DataAbstract> temp_data(temp);
276        m_data=temp_data;
277      }
278    }
279    
280    
281    void
282    Data::initialise(const DataTypes::ValueType& value,
283             const DataTypes::ShapeType& shape,
284                     const FunctionSpace& what,
285                     bool expanded)
286    {
287      //
288      // Construct a Data object of the appropriate type.
289      // Construct the object first as there seems to be a bug which causes
290      // undefined behaviour if an exception is thrown during construction
291      // within the shared_ptr constructor.
292      if (expanded) {
293        DataAbstract* temp=new DataExpanded(what, shape, value);
294        boost::shared_ptr<DataAbstract> temp_data(temp);
295        m_data=temp_data;
296      } else {
297        DataAbstract* temp=new DataConstant(what, shape, value);
298        boost::shared_ptr<DataAbstract> temp_data(temp);
299        m_data=temp_data;
300      }
301    }
302    
303    
304    // void
305    // Data::CompareDebug(const Data& rd)
306    // {
307    //  using namespace std;
308    //  bool mismatch=false;
309    //  std::cout << "Comparing left and right" << endl;
310    //  const DataTagged* left=dynamic_cast<DataTagged*>(m_data.get());
311    //  const DataTagged* right=dynamic_cast<DataTagged*>(rd.m_data.get());
312    //  
313    //  if (left==0)
314    //  {
315    //      cout << "left arg is not a DataTagged\n";
316    //      return;
317    //  }
318    //  
319    //  if (right==0)
320    //  {
321    //      cout << "right arg is not a DataTagged\n";
322    //      return;
323    //  }
324    //  cout << "Num elements=" << left->getVector().size() << ":" << right->getVector().size() << std::endl;
325    //  cout << "Shapes ";
326    //  if (left->getShape()==right->getShape())
327    //  {
328    //      cout << "ok\n";
329    //  }
330    //  else
331    //  {
332    //      cout << "Problem: shapes do not match\n";
333    //      mismatch=true;
334    //  }
335    //  int lim=left->getVector().size();
336    //  if (right->getVector().size()) lim=right->getVector().size();
337    //  for (int i=0;i<lim;++i)
338    //  {
339    //      if (left->getVector()[i]!=right->getVector()[i])
340    //      {
341    //          cout << "[" << i << "] value mismatch " << left->getVector()[i] << ":" << right->getVector()[i] << endl;
342    //          mismatch=true;
343    //      }
344    //  }
345    //
346    //  // still need to check the tag map
347    //  // also need to watch what is happening to function spaces, are they copied or what?
348    //
349    //  const DataTagged::DataMapType& mapleft=left->getTagLookup();
350    //  const DataTagged::DataMapType& mapright=right->getTagLookup();
351    //
352    //  if (mapleft.size()!=mapright.size())
353    //  {
354    //      cout << "Maps are different sizes " << mapleft.size() << ":" << mapright.size() << endl;
355    //      mismatch=true;
356    //      cout << "Left map\n";
357    //      DataTagged::DataMapType::const_iterator i,j;
358    //      for (i=mapleft.begin();i!=mapleft.end();++i) {
359    //          cout << "(" << i->first << "=>" << i->second << ")\n";
360    //      }
361    //      cout << "Right map\n";
362    //      for (i=mapright.begin();i!=mapright.end();++i) {
363    //          cout << "(" << i->first << "=>" << i->second << ")\n";
364    //      }
365    //      cout << "End map\n";
366    //
367    //  }
368    //
369    //  DataTagged::DataMapType::const_iterator i,j;
370    //  for (i=mapleft.begin(),j=mapright.begin();i!=mapleft.end() && j!=mapright.end();++i,++j) {
371    //     if ((i->first!=j->first) || (i->second!=j->second))
372    //     {
373    //      cout << "(" << i->first << "=>" << i->second << ")";
374    //      cout << ":(" << j->first << "=>" << j->second << ") ";
375    //      mismatch=true;
376    //            }
377    //  }
378    //  if (mismatch)
379    //  {
380    //      cout << "#Mismatch\n";
381    //  }
382    // }
383    
384  escriptDataC  escriptDataC
385  Data::getDataC()  Data::getDataC()
386  {  {
# Line 227  Data::getDataC() const Line 400  Data::getDataC() const
400  const boost::python::tuple  const boost::python::tuple
401  Data::getShapeTuple() const  Data::getShapeTuple() const
402  {  {
403    const DataArrayView::ShapeType& shape=getDataPointShape();    const DataTypes::ShapeType& shape=getDataPointShape();
404    switch(getDataPointRank()) {    switch(getDataPointRank()) {
405       case 0:       case 0:
406          return make_tuple();          return make_tuple();
# Line 243  Data::getShapeTuple() const Line 416  Data::getShapeTuple() const
416          throw DataException("Error - illegal Data rank.");          throw DataException("Error - illegal Data rank.");
417    }    }
418  }  }
419    
420    
421    // The different name is needed because boost has trouble with overloaded functions.
422    // It can't work out what type the function is based soley on its name.
423    // There are ways to fix this involving creating function pointer variables for each form
424    // but there doesn't seem to be a need given that the methods have the same name from the python point of view
425    Data*
426    Data::copySelf()
427    {
428       DataAbstract* temp=m_data->deepCopy();
429       return new Data(temp);
430    }
431    
432  void  void
433  Data::copy(const Data& other)  Data::copy(const Data& other)
434  {  {
435    //    DataAbstract* temp=other.m_data->deepCopy();
436    // Perform a deep copy    shared_ptr<DataAbstract> temp_data(temp);
437    {    m_data=temp_data;
     DataExpanded* temp=dynamic_cast<DataExpanded*>(other.m_data.get());  
     if (temp!=0) {  
       //  
       // Construct a DataExpanded copy  
       DataAbstract* newData=new DataExpanded(*temp);  
       shared_ptr<DataAbstract> temp_data(newData);  
       m_data=temp_data;  
       return;  
     }  
   }  
   {  
     DataTagged* temp=dynamic_cast<DataTagged*>(other.m_data.get());  
     if (temp!=0) {  
       //  
       // Construct a DataTagged copy  
       DataAbstract* newData=new DataTagged(*temp);  
       shared_ptr<DataAbstract> temp_data(newData);  
       m_data=temp_data;  
       return;  
     }  
   }  
   {  
     DataConstant* temp=dynamic_cast<DataConstant*>(other.m_data.get());  
     if (temp!=0) {  
       //  
       // Construct a DataConstant copy  
       DataAbstract* newData=new DataConstant(*temp);  
       shared_ptr<DataAbstract> temp_data(newData);  
       m_data=temp_data;  
       return;  
     }  
   }  
   {  
     DataEmpty* temp=dynamic_cast<DataEmpty*>(other.m_data.get());  
     if (temp!=0) {  
       //  
       // Construct a DataEmpty copy  
       DataAbstract* newData=new DataEmpty();  
       shared_ptr<DataAbstract> temp_data(newData);  
       m_data=temp_data;  
       return;  
     }  
   }  
   throw DataException("Error - Copy not implemented for this Data type.");  
438  }  }
439    
440    
441  void  void
442  Data::setToZero()  Data::setToZero()
443  {  {
444      if (isEmpty())
445      {
446         throw DataException("Error - Operations not permitted on instances of DataEmpty.");
447      }
448    {    {
449      DataExpanded* temp=dynamic_cast<DataExpanded*>(m_data.get());      DataExpanded* temp=dynamic_cast<DataExpanded*>(m_data.get());
450      if (temp!=0) {      if (temp!=0) {
# Line 327  void Line 473  void
473  Data::copyWithMask(const Data& other,  Data::copyWithMask(const Data& other,
474                     const Data& mask)                     const Data& mask)
475  {  {
476      if (other.isEmpty() || mask.isEmpty())
477      {
478        throw DataException("Error - copyWithMask not permitted using instances of DataEmpty.");
479      }
480    Data mask1;    Data mask1;
481    Data mask2;    Data mask2;
   
482    mask1 = mask.wherePositive();    mask1 = mask.wherePositive();
   mask2.copy(mask1);  
483    
484      mask2.copy(mask1);
485    mask1 *= other;    mask1 *= other;
486    
487    mask2 *= *this;    mask2 *= *this;
488    mask2 = *this - mask2;    mask2 = *this - mask2;
   
489    *this = mask1 + mask2;    *this = mask1 + mask2;
490  }  }
491    
# Line 492  Data::probeInterpolation(const FunctionS Line 641  Data::probeInterpolation(const FunctionS
641  Data  Data
642  Data::gradOn(const FunctionSpace& functionspace) const  Data::gradOn(const FunctionSpace& functionspace) const
643  {  {
644      if (isEmpty())
645      {
646        throw DataException("Error - operation not permitted on instances of DataEmpty.");
647      }
648    double blocktimer_start = blocktimer_time();    double blocktimer_start = blocktimer_time();
649    if (functionspace.getDomain()!=getDomain())    if (functionspace.getDomain()!=getDomain())
650      throw DataException("Error - gradient cannot be calculated on different domains.");      throw DataException("Error - gradient cannot be calculated on different domains.");
651    DataArrayView::ShapeType grad_shape=getPointDataView().getShape();    DataTypes::ShapeType grad_shape=getDataPointShape();
652    grad_shape.push_back(functionspace.getDim());    grad_shape.push_back(functionspace.getDim());
653    Data out(0.0,grad_shape,functionspace,true);    Data out(0.0,grad_shape,functionspace,true);
654    getDomain().setToGradient(out,*this);    getDomain().setToGradient(out,*this);
# Line 506  Data::gradOn(const FunctionSpace& functi Line 659  Data::gradOn(const FunctionSpace& functi
659  Data  Data
660  Data::grad() const  Data::grad() const
661  {  {
662      if (isEmpty())
663      {
664        throw DataException("Error - operation not permitted on instances of DataEmpty.");
665      }
666    return gradOn(escript::function(getDomain()));    return gradOn(escript::function(getDomain()));
667  }  }
668    
669  int  int
670  Data::getDataPointSize() const  Data::getDataPointSize() const
671  {  {
672    return getPointDataView().noValues();    return m_data->getNoValues();
673  }  }
674    
675  DataArrayView::ValueType::size_type  DataTypes::ValueType::size_type
676  Data::getLength() const  Data::getLength() const
677  {  {
678    return m_data->getLength();    return m_data->getLength();
679  }  }
680    
 const DataArrayView::ShapeType&  
 Data::getDataPointShape() const  
 {  
   return getPointDataView().getShape();  
 }  
   
   
   
681  const  const
682  boost::python::numeric::array  boost::python::numeric::array
683  Data:: getValueOfDataPoint(int dataPointNo)  Data:: getValueOfDataPoint(int dataPointNo)
# Line 538  Data:: getValueOfDataPoint(int dataPoint Line 687  Data:: getValueOfDataPoint(int dataPoint
687    //    //
688    // determine the rank and shape of each data point    // determine the rank and shape of each data point
689    int dataPointRank = getDataPointRank();    int dataPointRank = getDataPointRank();
690    DataArrayView::ShapeType dataPointShape = getDataPointShape();    const DataTypes::ShapeType& dataPointShape = getDataPointShape();
691    
692    //    //
693    // create the numeric array to be returned    // create the numeric array to be returned
# Line 548  Data:: getValueOfDataPoint(int dataPoint Line 697  Data:: getValueOfDataPoint(int dataPoint
697    // the shape of the returned numeric array will be the same    // the shape of the returned numeric array will be the same
698    // as that of the data point    // as that of the data point
699    int arrayRank = dataPointRank;    int arrayRank = dataPointRank;
700    DataArrayView::ShapeType arrayShape = dataPointShape;    const DataTypes::ShapeType& arrayShape = dataPointShape;
701    
702    //    //
703    // resize the numeric array to the shape just calculated    // resize the numeric array to the shape just calculated
# Line 584  Data:: getValueOfDataPoint(int dataPoint Line 733  Data:: getValueOfDataPoint(int dataPoint
733         }         }
734         // TODO: global error handling         // TODO: global error handling
735         // create a view of the data if it is stored locally         // create a view of the data if it is stored locally
736         DataArrayView dataPointView = getDataPoint(sampleNo, dataPointNoInSample);  //       DataArrayView dataPointView = getDataPoint(sampleNo, dataPointNoInSample);
737           DataTypes::ValueType::size_type offset=getDataOffset(sampleNo, dataPointNoInSample);
738    
739    
740         switch( dataPointRank ){         switch( dataPointRank ){
741              case 0 :              case 0 :
742                  numArray[0] = dataPointView();                  numArray[0] = getDataAtOffset(offset);
743                  break;                  break;
744              case 1 :              case 1 :
745                  for( i=0; i<dataPointShape[0]; i++ )                  for( i=0; i<dataPointShape[0]; i++ )
746                      numArray[i]=dataPointView(i);                      numArray[i]=getDataAtOffset(offset+DataTypes::getRelIndex(dataPointShape, i));
747                  break;                  break;
748              case 2 :              case 2 :
749                  for( i=0; i<dataPointShape[0]; i++ )                  for( i=0; i<dataPointShape[0]; i++ )
750                      for( j=0; j<dataPointShape[1]; j++)                      for( j=0; j<dataPointShape[1]; j++)
751                          numArray[make_tuple(i,j)]=dataPointView(i,j);                          numArray[make_tuple(i,j)]=getDataAtOffset(offset+DataTypes::getRelIndex(dataPointShape, i,j));
752                  break;                  break;
753              case 3 :              case 3 :
754                  for( i=0; i<dataPointShape[0]; i++ )                  for( i=0; i<dataPointShape[0]; i++ )
755                      for( j=0; j<dataPointShape[1]; j++ )                      for( j=0; j<dataPointShape[1]; j++ )
756                          for( k=0; k<dataPointShape[2]; k++)                          for( k=0; k<dataPointShape[2]; k++)
757                              numArray[make_tuple(i,j,k)]=dataPointView(i,j,k);                              numArray[make_tuple(i,j,k)]=getDataAtOffset(offset+DataTypes::getRelIndex(dataPointShape, i,j,k));
758                  break;                  break;
759              case 4 :              case 4 :
760                  for( i=0; i<dataPointShape[0]; i++ )                  for( i=0; i<dataPointShape[0]; i++ )
761                      for( j=0; j<dataPointShape[1]; j++ )                      for( j=0; j<dataPointShape[1]; j++ )
762                          for( k=0; k<dataPointShape[2]; k++ )                          for( k=0; k<dataPointShape[2]; k++ )
763                              for( l=0; l<dataPointShape[3]; l++)                              for( l=0; l<dataPointShape[3]; l++)
764                                  numArray[make_tuple(i,j,k,l)]=dataPointView(i,j,k,l);                                  numArray[make_tuple(i,j,k,l)]=getDataAtOffset(offset+DataTypes::getRelIndex(dataPointShape, i,j,k,l));
765                  break;                  break;
766      }      }
767    }    }
# Line 619  Data:: getValueOfDataPoint(int dataPoint Line 770  Data:: getValueOfDataPoint(int dataPoint
770    return numArray;    return numArray;
771    
772  }  }
773    
774  void  void
775  Data::setValueOfDataPointToPyObject(int dataPointNo, const boost::python::object& py_object)  Data::setValueOfDataPointToPyObject(int dataPointNo, const boost::python::object& py_object)
776  {  {
# Line 689  Data::getValueOfGlobalDataPoint(int proc Line 841  Data::getValueOfGlobalDataPoint(int proc
841    //    //
842    // determine the rank and shape of each data point    // determine the rank and shape of each data point
843    int dataPointRank = getDataPointRank();    int dataPointRank = getDataPointRank();
844    DataArrayView::ShapeType dataPointShape = getDataPointShape();    const DataTypes::ShapeType& dataPointShape = getDataPointShape();
845    
846    //    //
847    // create the numeric array to be returned    // create the numeric array to be returned
# Line 699  Data::getValueOfGlobalDataPoint(int proc Line 851  Data::getValueOfGlobalDataPoint(int proc
851    // the shape of the returned numeric array will be the same    // the shape of the returned numeric array will be the same
852    // as that of the data point    // as that of the data point
853    int arrayRank = dataPointRank;    int arrayRank = dataPointRank;
854    DataArrayView::ShapeType arrayShape = dataPointShape;    const DataTypes::ShapeType& arrayShape = dataPointShape;
855    
856    //    //
857    // resize the numeric array to the shape just calculated    // resize the numeric array to the shape just calculated
# Line 745  Data::getValueOfGlobalDataPoint(int proc Line 897  Data::getValueOfGlobalDataPoint(int proc
897                  }                  }
898                  // TODO: global error handling                  // TODO: global error handling
899          // create a view of the data if it is stored locally          // create a view of the data if it is stored locally
900          DataArrayView dataPointView = getDataPoint(sampleNo, dataPointNoInSample);          //DataArrayView dataPointView = getDataPoint(sampleNo, dataPointNoInSample);
901            DataTypes::ValueType::size_type offset=getDataOffset(sampleNo, dataPointNoInSample);
902    
903          // pack the data from the view into tmpData for MPI communication          // pack the data from the view into tmpData for MPI communication
904          pos=0;          pos=0;
905          switch( dataPointRank ){          switch( dataPointRank ){
906              case 0 :              case 0 :
907                  tmpData[0] = dataPointView();                  tmpData[0] = getDataAtOffset(offset);
908                  break;                  break;
909              case 1 :              case 1 :
910                  for( i=0; i<dataPointShape[0]; i++ )                  for( i=0; i<dataPointShape[0]; i++ )
911                      tmpData[i]=dataPointView(i);                      tmpData[i]=getDataAtOffset(offset+DataTypes::getRelIndex(dataPointShape, i));
912                  break;                  break;
913              case 2 :              case 2 :
914                  for( i=0; i<dataPointShape[0]; i++ )                  for( i=0; i<dataPointShape[0]; i++ )
915                      for( j=0; j<dataPointShape[1]; j++, pos++ )                      for( j=0; j<dataPointShape[1]; j++, pos++ )
916                          tmpData[pos]=dataPointView(i,j);                          tmpData[pos]=getDataAtOffset(offset+DataTypes::getRelIndex(dataPointShape, i,j));
917                  break;                  break;
918              case 3 :              case 3 :
919                  for( i=0; i<dataPointShape[0]; i++ )                  for( i=0; i<dataPointShape[0]; i++ )
920                      for( j=0; j<dataPointShape[1]; j++ )                      for( j=0; j<dataPointShape[1]; j++ )
921                          for( k=0; k<dataPointShape[2]; k++, pos++ )                          for( k=0; k<dataPointShape[2]; k++, pos++ )
922                              tmpData[pos]=dataPointView(i,j,k);                              tmpData[pos]=getDataAtOffset(offset+DataTypes::getRelIndex(dataPointShape, i,j,k));
923                  break;                  break;
924              case 4 :              case 4 :
925                  for( i=0; i<dataPointShape[0]; i++ )                  for( i=0; i<dataPointShape[0]; i++ )
926                      for( j=0; j<dataPointShape[1]; j++ )                      for( j=0; j<dataPointShape[1]; j++ )
927                          for( k=0; k<dataPointShape[2]; k++ )                          for( k=0; k<dataPointShape[2]; k++ )
928                              for( l=0; l<dataPointShape[3]; l++, pos++ )                              for( l=0; l<dataPointShape[3]; l++, pos++ )
929                                  tmpData[pos]=dataPointView(i,j,k,l);                                  tmpData[pos]=getDataAtOffset(offset+DataTypes::getRelIndex(dataPointShape, i,j,k,l));
930                  break;                  break;
931          }          }
932              }              }
# Line 825  Data::integrate() const Line 978  Data::integrate() const
978  {  {
979    int index;    int index;
980    int rank = getDataPointRank();    int rank = getDataPointRank();
981    DataArrayView::ShapeType shape = getDataPointShape();    DataTypes::ShapeType shape = getDataPointShape();
982    int dataPointSize = getDataPointSize();    int dataPointSize = getDataPointSize();
983    
984    //    //
# Line 1052  Data::sqrt() const Line 1205  Data::sqrt() const
1205  double  double
1206  Data::Lsup() const  Data::Lsup() const
1207  {  {
1208    double localValue, globalValue;    double localValue;
1209    //    //
1210    // set the initial absolute maximum value to zero    // set the initial absolute maximum value to zero
1211    
1212    AbsMax abs_max_func;    AbsMax abs_max_func;
1213    localValue = algorithm(abs_max_func,0);    localValue = algorithm(abs_max_func,0);
1214  #ifdef PASO_MPI  #ifdef PASO_MPI
1215      double globalValue;
1216    MPI_Allreduce( &localValue, &globalValue, 1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD );    MPI_Allreduce( &localValue, &globalValue, 1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD );
1217    return globalValue;    return globalValue;
1218  #else  #else
# Line 1069  Data::Lsup() const Line 1223  Data::Lsup() const
1223  double  double
1224  Data::sup() const  Data::sup() const
1225  {  {
1226    double localValue, globalValue;    double localValue;
1227    //    //
1228    // set the initial maximum value to min possible double    // set the initial maximum value to min possible double
1229    FMax fmax_func;    FMax fmax_func;
1230    localValue = algorithm(fmax_func,numeric_limits<double>::max()*-1);    localValue = algorithm(fmax_func,numeric_limits<double>::max()*-1);
1231  #ifdef PASO_MPI  #ifdef PASO_MPI
1232      double globalValue;
1233    MPI_Allreduce( &localValue, &globalValue, 1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD );    MPI_Allreduce( &localValue, &globalValue, 1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD );
1234    return globalValue;    return globalValue;
1235  #else  #else
# Line 1085  Data::sup() const Line 1240  Data::sup() const
1240  double  double
1241  Data::inf() const  Data::inf() const
1242  {  {
1243    double localValue, globalValue;    double localValue;
1244    //    //
1245    // set the initial minimum value to max possible double    // set the initial minimum value to max possible double
1246    FMin fmin_func;    FMin fmin_func;
1247    localValue = algorithm(fmin_func,numeric_limits<double>::max());    localValue = algorithm(fmin_func,numeric_limits<double>::max());
1248  #ifdef PASO_MPI  #ifdef PASO_MPI
1249      double globalValue;
1250    MPI_Allreduce( &localValue, &globalValue, 1, MPI_DOUBLE, MPI_MIN, MPI_COMM_WORLD );    MPI_Allreduce( &localValue, &globalValue, 1, MPI_DOUBLE, MPI_MIN, MPI_COMM_WORLD );
1251    return globalValue;    return globalValue;
1252  #else  #else
# Line 1122  Data Line 1278  Data
1278  Data::swapaxes(const int axis0, const int axis1) const  Data::swapaxes(const int axis0, const int axis1) const
1279  {  {
1280       int axis0_tmp,axis1_tmp;       int axis0_tmp,axis1_tmp;
1281       DataArrayView::ShapeType s=getDataPointShape();       DataTypes::ShapeType s=getDataPointShape();
1282       DataArrayView::ShapeType ev_shape;       DataTypes::ShapeType ev_shape;
1283       // Here's the equivalent of python s_out=s[axis_offset:]+s[:axis_offset]       // Here's the equivalent of python s_out=s[axis_offset:]+s[:axis_offset]
1284       // which goes thru all shape vector elements starting with axis_offset (at index=rank wrap around to 0)       // which goes thru all shape vector elements starting with axis_offset (at index=rank wrap around to 0)
1285       int rank=getDataPointRank();       int rank=getDataPointRank();
# Line 1166  Data Line 1322  Data
1322  Data::symmetric() const  Data::symmetric() const
1323  {  {
1324       // check input       // check input
1325       DataArrayView::ShapeType s=getDataPointShape();       DataTypes::ShapeType s=getDataPointShape();
1326       if (getDataPointRank()==2) {       if (getDataPointRank()==2) {
1327          if(s[0] != s[1])          if(s[0] != s[1])
1328             throw DataException("Error - Data::symmetric can only be calculated for rank 2 object with equal first and second dimension.");             throw DataException("Error - Data::symmetric can only be calculated for rank 2 object with equal first and second dimension.");
# Line 1188  Data Line 1344  Data
1344  Data::nonsymmetric() const  Data::nonsymmetric() const
1345  {  {
1346       // check input       // check input
1347       DataArrayView::ShapeType s=getDataPointShape();       DataTypes::ShapeType s=getDataPointShape();
1348       if (getDataPointRank()==2) {       if (getDataPointRank()==2) {
1349          if(s[0] != s[1])          if(s[0] != s[1])
1350             throw DataException("Error - Data::nonsymmetric can only be calculated for rank 2 object with equal first and second dimension.");             throw DataException("Error - Data::nonsymmetric can only be calculated for rank 2 object with equal first and second dimension.");
1351          DataArrayView::ShapeType ev_shape;          DataTypes::ShapeType ev_shape;
1352          ev_shape.push_back(s[0]);          ev_shape.push_back(s[0]);
1353          ev_shape.push_back(s[1]);          ev_shape.push_back(s[1]);
1354          Data ev(0.,ev_shape,getFunctionSpace());          Data ev(0.,ev_shape,getFunctionSpace());
# Line 1203  Data::nonsymmetric() const Line 1359  Data::nonsymmetric() const
1359       else if (getDataPointRank()==4) {       else if (getDataPointRank()==4) {
1360          if(!(s[0] == s[2] && s[1] == s[3]))          if(!(s[0] == s[2] && s[1] == s[3]))
1361             throw DataException("Error - Data::nonsymmetric can only be calculated for rank 4 object with dim0==dim2 and dim1==dim3.");             throw DataException("Error - Data::nonsymmetric can only be calculated for rank 4 object with dim0==dim2 and dim1==dim3.");
1362          DataArrayView::ShapeType ev_shape;          DataTypes::ShapeType ev_shape;
1363          ev_shape.push_back(s[0]);          ev_shape.push_back(s[0]);
1364          ev_shape.push_back(s[1]);          ev_shape.push_back(s[1]);
1365          ev_shape.push_back(s[2]);          ev_shape.push_back(s[2]);
# Line 1221  Data::nonsymmetric() const Line 1377  Data::nonsymmetric() const
1377  Data  Data
1378  Data::trace(int axis_offset) const  Data::trace(int axis_offset) const
1379  {  {
1380       DataArrayView::ShapeType s=getDataPointShape();       DataTypes::ShapeType s=getDataPointShape();
1381       if (getDataPointRank()==2) {       if (getDataPointRank()==2) {
1382          DataArrayView::ShapeType ev_shape;          DataTypes::ShapeType ev_shape;
1383          Data ev(0.,ev_shape,getFunctionSpace());          Data ev(0.,ev_shape,getFunctionSpace());
1384          ev.typeMatchRight(*this);          ev.typeMatchRight(*this);
1385          m_data->trace(ev.m_data.get(), axis_offset);          m_data->trace(ev.m_data.get(), axis_offset);
1386          return ev;          return ev;
1387       }       }
1388       if (getDataPointRank()==3) {       if (getDataPointRank()==3) {
1389          DataArrayView::ShapeType ev_shape;          DataTypes::ShapeType ev_shape;
1390          if (axis_offset==0) {          if (axis_offset==0) {
1391            int s2=s[2];            int s2=s[2];
1392            ev_shape.push_back(s2);            ev_shape.push_back(s2);
# Line 1245  Data::trace(int axis_offset) const Line 1401  Data::trace(int axis_offset) const
1401          return ev;          return ev;
1402       }       }
1403       if (getDataPointRank()==4) {       if (getDataPointRank()==4) {
1404          DataArrayView::ShapeType ev_shape;          DataTypes::ShapeType ev_shape;
1405          if (axis_offset==0) {          if (axis_offset==0) {
1406            ev_shape.push_back(s[2]);            ev_shape.push_back(s[2]);
1407            ev_shape.push_back(s[3]);            ev_shape.push_back(s[3]);
# Line 1271  Data::trace(int axis_offset) const Line 1427  Data::trace(int axis_offset) const
1427  Data  Data
1428  Data::transpose(int axis_offset) const  Data::transpose(int axis_offset) const
1429  {  {
1430       DataArrayView::ShapeType s=getDataPointShape();       DataTypes::ShapeType s=getDataPointShape();
1431       DataArrayView::ShapeType ev_shape;       DataTypes::ShapeType ev_shape;
1432       // Here's the equivalent of python s_out=s[axis_offset:]+s[:axis_offset]       // Here's the equivalent of python s_out=s[axis_offset:]+s[:axis_offset]
1433       // which goes thru all shape vector elements starting with axis_offset (at index=rank wrap around to 0)       // which goes thru all shape vector elements starting with axis_offset (at index=rank wrap around to 0)
1434       int rank=getDataPointRank();       int rank=getDataPointRank();
# Line 1293  Data Line 1449  Data
1449  Data::eigenvalues() const  Data::eigenvalues() const
1450  {  {
1451       // check input       // check input
1452       DataArrayView::ShapeType s=getDataPointShape();       DataTypes::ShapeType s=getDataPointShape();
1453       if (getDataPointRank()!=2)       if (getDataPointRank()!=2)
1454          throw DataException("Error - Data::eigenvalues can only be calculated for rank 2 object.");          throw DataException("Error - Data::eigenvalues can only be calculated for rank 2 object.");
1455       if(s[0] != s[1])       if(s[0] != s[1])
1456          throw DataException("Error - Data::eigenvalues can only be calculated for object with equal first and second dimension.");          throw DataException("Error - Data::eigenvalues can only be calculated for object with equal first and second dimension.");
1457       // create return       // create return
1458       DataArrayView::ShapeType ev_shape(1,s[0]);       DataTypes::ShapeType ev_shape(1,s[0]);
1459       Data ev(0.,ev_shape,getFunctionSpace());       Data ev(0.,ev_shape,getFunctionSpace());
1460       ev.typeMatchRight(*this);       ev.typeMatchRight(*this);
1461       m_data->eigenvalues(ev.m_data.get());       m_data->eigenvalues(ev.m_data.get());
# Line 1309  Data::eigenvalues() const Line 1465  Data::eigenvalues() const
1465  const boost::python::tuple  const boost::python::tuple
1466  Data::eigenvalues_and_eigenvectors(const double tol) const  Data::eigenvalues_and_eigenvectors(const double tol) const
1467  {  {
1468       DataArrayView::ShapeType s=getDataPointShape();       DataTypes::ShapeType s=getDataPointShape();
1469       if (getDataPointRank()!=2)       if (getDataPointRank()!=2)
1470          throw DataException("Error - Data::eigenvalues and eigenvectors can only be calculated for rank 2 object.");          throw DataException("Error - Data::eigenvalues and eigenvectors can only be calculated for rank 2 object.");
1471       if(s[0] != s[1])       if(s[0] != s[1])
1472          throw DataException("Error - Data::eigenvalues and eigenvectors can only be calculated for object with equal first and second dimension.");          throw DataException("Error - Data::eigenvalues and eigenvectors can only be calculated for object with equal first and second dimension.");
1473       // create return       // create return
1474       DataArrayView::ShapeType ev_shape(1,s[0]);       DataTypes::ShapeType ev_shape(1,s[0]);
1475       Data ev(0.,ev_shape,getFunctionSpace());       Data ev(0.,ev_shape,getFunctionSpace());
1476       ev.typeMatchRight(*this);       ev.typeMatchRight(*this);
1477       DataArrayView::ShapeType V_shape(2,s[0]);       DataTypes::ShapeType V_shape(2,s[0]);
1478       Data V(0.,V_shape,getFunctionSpace());       Data V(0.,V_shape,getFunctionSpace());
1479       V.typeMatchRight(*this);       V.typeMatchRight(*this);
1480       m_data->eigenvalues_and_eigenvectors(ev.m_data.get(),V.m_data.get(),tol);       m_data->eigenvalues_and_eigenvectors(ev.m_data.get(),V.m_data.get(),tol);
# Line 1360  Data::calc_minGlobalDataPoint(int& ProcN Line 1516  Data::calc_minGlobalDataPoint(int& ProcN
1516      #pragma omp for private(i,j) schedule(static)      #pragma omp for private(i,j) schedule(static)
1517      for (i=0; i<numSamples; i++) {      for (i=0; i<numSamples; i++) {
1518        for (j=0; j<numDPPSample; j++) {        for (j=0; j<numDPPSample; j++) {
1519          next=temp.getDataPoint(i,j)();          next=temp.getDataAtOffset(temp.getDataOffset(i,j));
1520          if (next<local_min) {          if (next<local_min) {
1521            local_min=next;            local_min=next;
1522            local_lowi=i;            local_lowi=i;
# Line 1378  Data::calc_minGlobalDataPoint(int& ProcN Line 1534  Data::calc_minGlobalDataPoint(int& ProcN
1534    
1535  #ifdef PASO_MPI  #ifdef PASO_MPI
1536      // determine the processor on which the minimum occurs      // determine the processor on which the minimum occurs
1537      next = temp.getDataPoint(lowi,lowj)();      next = temp.getDataPoint(lowi,lowj);
1538      int lowProc = 0;      int lowProc = 0;
1539      double *globalMins = new double[get_MPISize()+1];      double *globalMins = new double[get_MPISize()+1];
1540      int error = MPI_Gather ( &next, 1, MPI_DOUBLE, globalMins, 1, MPI_DOUBLE, 0, get_MPIComm() );      int error = MPI_Gather ( &next, 1, MPI_DOUBLE, globalMins, 1, MPI_DOUBLE, 0, get_MPIComm() );
# Line 1404  Data::calc_minGlobalDataPoint(int& ProcN Line 1560  Data::calc_minGlobalDataPoint(int& ProcN
1560  void  void
1561  Data::saveDX(std::string fileName) const  Data::saveDX(std::string fileName) const
1562  {  {
1563      if (isEmpty())
1564      {
1565        throw DataException("Error - Operations not permitted on instances of DataEmpty.");
1566      }
1567    boost::python::dict args;    boost::python::dict args;
1568    args["data"]=boost::python::object(this);    args["data"]=boost::python::object(this);
1569    getDomain().saveDX(fileName,args);    getDomain().saveDX(fileName,args);
# Line 1413  Data::saveDX(std::string fileName) const Line 1573  Data::saveDX(std::string fileName) const
1573  void  void
1574  Data::saveVTK(std::string fileName) const  Data::saveVTK(std::string fileName) const
1575  {  {
1576      if (isEmpty())
1577      {
1578        throw DataException("Error - Operations not permitted on instances of DataEmpty.");
1579      }
1580    boost::python::dict args;    boost::python::dict args;
1581    args["data"]=boost::python::object(this);    args["data"]=boost::python::object(this);
1582    getDomain().saveVTK(fileName,args);    getDomain().saveVTK(fileName,args);
# Line 1663  escript::operator/(const boost::python:: Line 1827  escript::operator/(const boost::python::
1827  Data  Data
1828  Data::getItem(const boost::python::object& key) const  Data::getItem(const boost::python::object& key) const
1829  {  {
1830    const DataArrayView& view=getPointDataView();  //  const DataArrayView& view=getPointDataView();
1831    
1832    DataArrayView::RegionType slice_region=view.getSliceRegion(key);    DataTypes::RegionType slice_region=DataTypes::getSliceRegion(getDataPointShape(),key);
1833    
1834    if (slice_region.size()!=view.getRank()) {    if (slice_region.size()!=getDataPointRank()) {
1835      throw DataException("Error - slice size does not match Data rank.");      throw DataException("Error - slice size does not match Data rank.");
1836    }    }
1837    
# Line 1677  Data::getItem(const boost::python::objec Line 1841  Data::getItem(const boost::python::objec
1841  /* TODO */  /* TODO */
1842  /* global reduction */  /* global reduction */
1843  Data  Data
1844  Data::getSlice(const DataArrayView::RegionType& region) const  Data::getSlice(const DataTypes::RegionType& region) const
1845  {  {
1846    return Data(*this,region);    return Data(*this,region);
1847  }  }
# Line 1696  void Line 1860  void
1860  Data::setItemD(const boost::python::object& key,  Data::setItemD(const boost::python::object& key,
1861                 const Data& value)                 const Data& value)
1862  {  {
1863    const DataArrayView& view=getPointDataView();  //  const DataArrayView& view=getPointDataView();
1864    
1865    DataArrayView::RegionType slice_region=view.getSliceRegion(key);    DataTypes::RegionType slice_region=DataTypes::getSliceRegion(getDataPointShape(),key);
1866    if (slice_region.size()!=view.getRank()) {    if (slice_region.size()!=getDataPointRank()) {
1867      throw DataException("Error - slice size does not match Data rank.");      throw DataException("Error - slice size does not match Data rank.");
1868    }    }
1869    if (getFunctionSpace()!=value.getFunctionSpace()) {    if (getFunctionSpace()!=value.getFunctionSpace()) {
# Line 1711  Data::setItemD(const boost::python::obje Line 1875  Data::setItemD(const boost::python::obje
1875    
1876  void  void
1877  Data::setSlice(const Data& value,  Data::setSlice(const Data& value,
1878                 const DataArrayView::RegionType& region)                 const DataTypes::RegionType& region)
1879  {  {
1880    if (isProtected()) {    if (isProtected()) {
1881          throw DataException("Error - attempt to update protected Data object.");          throw DataException("Error - attempt to update protected Data object.");
# Line 1774  Data::setTaggedValue(int tagKey, Line 1938  Data::setTaggedValue(int tagKey,
1938    
1939    
1940    // extract the shape of the numarray    // extract the shape of the numarray
1941    DataArrayView::ShapeType tempShape;    DataTypes::ShapeType tempShape;
1942    for (int i=0; i < asNumArray.getrank(); i++) {    for (int i=0; i < asNumArray.getrank(); i++) {
1943      tempShape.push_back(extract<int>(asNumArray.getshape()[i]));      tempShape.push_back(extract<int>(asNumArray.getshape()[i]));
1944    }    }
1945    
1946    // get the space for the data vector    // get the space for the data vector
1947    int len = DataArrayView::noValues(tempShape);  //   int len = DataTypes::noValues(tempShape);
1948    DataVector temp_data(len, 0.0, len);  //   DataVector temp_data(len, 0.0, len);
1949    DataArrayView temp_dataView(temp_data, tempShape);  //   DataArrayView temp_dataView(temp_data, tempShape);
1950    temp_dataView.copy(asNumArray);  //   temp_dataView.copy(asNumArray);
1951    
1952      DataVector temp_data2;
1953      temp_data2.copyFromNumArray(asNumArray);
1954    
1955    //    //
1956    // Call DataAbstract::setTaggedValue    // Call DataAbstract::setTaggedValue
1957    m_data->setTaggedValue(tagKey,temp_dataView);    //m_data->setTaggedValue(tagKey,temp_dataView);
1958    
1959        m_data->setTaggedValue(tagKey,tempShape, temp_data2);
1960  }  }
1961    
1962    // void
1963    // Data::setTaggedValueFromCPP(int tagKey,
1964    //                             const DataArrayView& value)
1965    // {
1966    //   if (isProtected()) {
1967    //         throw DataException("Error - attempt to update protected Data object.");
1968    //   }
1969    //   //
1970    //   // Ensure underlying data object is of type DataTagged
1971    //   if (isConstant()) tag();
1972    //
1973    //   //
1974    //   // Call DataAbstract::setTaggedValue
1975    //   m_data->setTaggedValue(tagKey,value);
1976    // }
1977    
1978  void  void
1979  Data::setTaggedValueFromCPP(int tagKey,  Data::setTaggedValueFromCPP(int tagKey,
1980                              const DataArrayView& value)                  const DataTypes::ShapeType& pointshape,
1981                                const DataTypes::ValueType& value,
1982                    int dataOffset)
1983  {  {
1984    if (isProtected()) {    if (isProtected()) {
1985          throw DataException("Error - attempt to update protected Data object.");          throw DataException("Error - attempt to update protected Data object.");
# Line 1803  Data::setTaggedValueFromCPP(int tagKey, Line 1990  Data::setTaggedValueFromCPP(int tagKey,
1990    
1991    //    //
1992    // Call DataAbstract::setTaggedValue    // Call DataAbstract::setTaggedValue
1993    m_data->setTaggedValue(tagKey,value);    m_data->setTaggedValue(tagKey,pointshape, value, dataOffset);
1994  }  }
1995    
1996  int  int
1997  Data::getTagNumber(int dpno)  Data::getTagNumber(int dpno)
1998  {  {
1999    return getFunctionSpace().getTagFromSampleNo(dpno);    if (isEmpty())
2000  }    {
2001        throw DataException("Error - operation not permitted on instances of DataEmpty.");
 void  
 Data::archiveData(const std::string fileName)  
 {  
   cout << "Archiving Data object to: " << fileName << endl;  
   
   //  
   // Determine type of this Data object  
   int dataType = -1;  
   
   if (isEmpty()) {  
     dataType = 0;  
     cout << "\tdataType: DataEmpty" << endl;  
   }  
   if (isConstant()) {  
     dataType = 1;  
     cout << "\tdataType: DataConstant" << endl;  
   }  
   if (isTagged()) {  
     dataType = 2;  
     cout << "\tdataType: DataTagged" << endl;  
   }  
   if (isExpanded()) {  
     dataType = 3;  
     cout << "\tdataType: DataExpanded" << endl;  
   }  
   
   if (dataType == -1) {  
     throw DataException("archiveData Error: undefined dataType");  
   }  
   
   //  
   // Collect data items common to all Data types  
   int noSamples = getNumSamples();  
   int noDPPSample = getNumDataPointsPerSample();  
   int functionSpaceType = getFunctionSpace().getTypeCode();  
   int dataPointRank = getDataPointRank();  
   int dataPointSize = getDataPointSize();  
   int dataLength = getLength();  
   DataArrayView::ShapeType dataPointShape = getDataPointShape();  
   vector<int> referenceNumbers(noSamples);  
   for (int sampleNo=0; sampleNo<noSamples; sampleNo++) {  
     referenceNumbers[sampleNo] = getFunctionSpace().getReferenceIDOfSample(sampleNo);  
   }  
   vector<int> tagNumbers(noSamples);  
   if (isTagged()) {  
     for (int sampleNo=0; sampleNo<noSamples; sampleNo++) {  
       tagNumbers[sampleNo] = getFunctionSpace().getTagFromSampleNo(sampleNo);  
     }  
   }  
   
   cout << "\tnoSamples: " << noSamples << " noDPPSample: " << noDPPSample << endl;  
   cout << "\tfunctionSpaceType: " << functionSpaceType << endl;  
   cout << "\trank: " << dataPointRank << " size: " << dataPointSize << " length: " << dataLength << endl;  
   
   //  
   // Flatten Shape to an array of integers suitable for writing to file  
   int flatShape[4] = {0,0,0,0};  
   cout << "\tshape: < ";  
   for (int dim=0; dim<dataPointRank; dim++) {  
     flatShape[dim] = dataPointShape[dim];  
     cout << dataPointShape[dim] << " ";  
   }  
   cout << ">" << endl;  
   
   //  
   // Open archive file  
   ofstream archiveFile;  
   archiveFile.open(fileName.data(), ios::out);  
   
   if (!archiveFile.good()) {  
     throw DataException("archiveData Error: problem opening archive file");  
   }  
   
   //  
   // Write common data items to archive file  
   archiveFile.write(reinterpret_cast<char *>(&dataType),sizeof(int));  
   archiveFile.write(reinterpret_cast<char *>(&noSamples),sizeof(int));  
   archiveFile.write(reinterpret_cast<char *>(&noDPPSample),sizeof(int));  
   archiveFile.write(reinterpret_cast<char *>(&functionSpaceType),sizeof(int));  
   archiveFile.write(reinterpret_cast<char *>(&dataPointRank),sizeof(int));  
   archiveFile.write(reinterpret_cast<char *>(&dataPointSize),sizeof(int));  
   archiveFile.write(reinterpret_cast<char *>(&dataLength),sizeof(int));  
   for (int dim = 0; dim < 4; dim++) {  
     archiveFile.write(reinterpret_cast<char *>(&flatShape[dim]),sizeof(int));  
   }  
   for (int sampleNo=0; sampleNo<noSamples; sampleNo++) {  
     archiveFile.write(reinterpret_cast<char *>(&referenceNumbers[sampleNo]),sizeof(int));  
   }  
   if (isTagged()) {  
     for (int sampleNo=0; sampleNo<noSamples; sampleNo++) {  
       archiveFile.write(reinterpret_cast<char *>(&tagNumbers[sampleNo]),sizeof(int));  
     }  
   }  
   
   if (!archiveFile.good()) {  
     throw DataException("archiveData Error: problem writing to archive file");  
   }  
   
   //  
   // Archive underlying data values for each Data type  
   int noValues;  
   switch (dataType) {  
     case 0:  
       // DataEmpty  
       noValues = 0;  
       archiveFile.write(reinterpret_cast<char *>(&noValues),sizeof(int));  
       cout << "\tnoValues: " << noValues << endl;  
       break;  
     case 1:  
       // DataConstant  
       noValues = m_data->getLength();  
       archiveFile.write(reinterpret_cast<char *>(&noValues),sizeof(int));  
       cout << "\tnoValues: " << noValues << endl;  
       if (m_data->archiveData(archiveFile,noValues)) {  
         throw DataException("archiveData Error: problem writing data to archive file");  
       }  
       break;  
     case 2:  
       // DataTagged  
       noValues = m_data->getLength();  
       archiveFile.write(reinterpret_cast<char *>(&noValues),sizeof(int));  
       cout << "\tnoValues: " << noValues << endl;  
       if (m_data->archiveData(archiveFile,noValues)) {  
         throw DataException("archiveData Error: problem writing data to archive file");  
       }  
       break;  
     case 3:  
       // DataExpanded  
       noValues = m_data->getLength();  
       archiveFile.write(reinterpret_cast<char *>(&noValues),sizeof(int));  
       cout << "\tnoValues: " << noValues << endl;  
       if (m_data->archiveData(archiveFile,noValues)) {  
         throw DataException("archiveData Error: problem writing data to archive file");  
       }  
       break;  
   }  
   
   if (!archiveFile.good()) {  
     throw DataException("archiveData Error: problem writing data to archive file");  
   }  
   
   //  
   // Close archive file  
   archiveFile.close();  
   
   if (!archiveFile.good()) {  
     throw DataException("archiveData Error: problem closing archive file");  
2002    }    }
2003      return getFunctionSpace().getTagFromDataPointNo(dpno);
2004  }  }
2005    
 void  
 Data::extractData(const std::string fileName,  
                   const FunctionSpace& fspace)  
 {  
   //  
   // Can only extract Data to an object which is initially DataEmpty  
   if (!isEmpty()) {  
     throw DataException("extractData Error: can only extract to DataEmpty object");  
   }  
   
   cout << "Extracting Data object from: " << fileName << endl;  
   
   int dataType;  
   int noSamples;  
   int noDPPSample;  
   int functionSpaceType;  
   int dataPointRank;  
   int dataPointSize;  
   int dataLength;  
   DataArrayView::ShapeType dataPointShape;  
   int flatShape[4];  
   
   //  
   // Open the archive file  
   ifstream archiveFile;  
   archiveFile.open(fileName.data(), ios::in);  
   
   if (!archiveFile.good()) {  
     throw DataException("extractData Error: problem opening archive file");  
   }  
   
   //  
   // Read common data items from archive file  
   archiveFile.read(reinterpret_cast<char *>(&dataType),sizeof(int));  
   archiveFile.read(reinterpret_cast<char *>(&noSamples),sizeof(int));  
   archiveFile.read(reinterpret_cast<char *>(&noDPPSample),sizeof(int));  
   archiveFile.read(reinterpret_cast<char *>(&functionSpaceType),sizeof(int));  
   archiveFile.read(reinterpret_cast<char *>(&dataPointRank),sizeof(int));  
   archiveFile.read(reinterpret_cast<char *>(&dataPointSize),sizeof(int));  
   archiveFile.read(reinterpret_cast<char *>(&dataLength),sizeof(int));  
   for (int dim = 0; dim < 4; dim++) {  
     archiveFile.read(reinterpret_cast<char *>(&flatShape[dim]),sizeof(int));  
     if (flatShape[dim]>0) {  
       dataPointShape.push_back(flatShape[dim]);  
     }  
   }  
   vector<int> referenceNumbers(noSamples);  
   for (int sampleNo=0; sampleNo<noSamples; sampleNo++) {  
     archiveFile.read(reinterpret_cast<char *>(&referenceNumbers[sampleNo]),sizeof(int));  
   }  
   vector<int> tagNumbers(noSamples);  
   if (dataType==2) {  
     for (int sampleNo=0; sampleNo<noSamples; sampleNo++) {  
       archiveFile.read(reinterpret_cast<char *>(&tagNumbers[sampleNo]),sizeof(int));  
     }  
   }  
   
   if (!archiveFile.good()) {  
     throw DataException("extractData Error: problem reading from archive file");  
   }  
   
   //  
   // Verify the values just read from the archive file  
   switch (dataType) {  
     case 0:  
       cout << "\tdataType: DataEmpty" << endl;  
       break;  
     case 1:  
       cout << "\tdataType: DataConstant" << endl;  
       break;  
     case 2:  
       cout << "\tdataType: DataTagged" << endl;  
       break;  
     case 3:  
       cout << "\tdataType: DataExpanded" << endl;  
       break;  
     default:  
       throw DataException("extractData Error: undefined dataType read from archive file");  
       break;  
   }  
   
   cout << "\tnoSamples: " << noSamples << " noDPPSample: " << noDPPSample << endl;  
   cout << "\tfunctionSpaceType: " << functionSpaceType << endl;  
   cout << "\trank: " << dataPointRank << " size: " << dataPointSize << " length: " << dataLength << endl;  
   cout << "\tshape: < ";  
   for (int dim = 0; dim < dataPointRank; dim++) {  
     cout << dataPointShape[dim] << " ";  
   }  
   cout << ">" << endl;  
   
   //  
   // Verify that supplied FunctionSpace object is compatible with this Data object.  
   if ( (fspace.getTypeCode()!=functionSpaceType) ||  
        (fspace.getNumSamples()!=noSamples) ||  
        (fspace.getNumDPPSample()!=noDPPSample)  
      ) {  
     throw DataException("extractData Error: incompatible FunctionSpace");  
   }  
   for (int sampleNo=0; sampleNo<noSamples; sampleNo++) {  
     if (referenceNumbers[sampleNo] != fspace.getReferenceIDOfSample(sampleNo)) {  
       throw DataException("extractData Error: incompatible FunctionSpace");  
     }  
   }  
   if (dataType==2) {  
     for (int sampleNo=0; sampleNo<noSamples; sampleNo++) {  
       if (tagNumbers[sampleNo] != fspace.getTagFromSampleNo(sampleNo)) {  
         throw DataException("extractData Error: incompatible FunctionSpace");  
       }  
     }  
   }  
   
   //  
   // Construct a DataVector to hold underlying data values  
   DataVector dataVec(dataLength);  
   
   //  
   // Load this DataVector with the appropriate values  
   int noValues;  
   archiveFile.read(reinterpret_cast<char *>(&noValues),sizeof(int));  
   cout << "\tnoValues: " << noValues << endl;  
   switch (dataType) {  
     case 0:  
       // DataEmpty  
       if (noValues != 0) {  
         throw DataException("extractData Error: problem reading data from archive file");  
       }  
       break;  
     case 1:  
       // DataConstant  
       if (dataVec.extractData(archiveFile,noValues)) {  
         throw DataException("extractData Error: problem reading data from archive file");  
       }  
       break;  
     case 2:  
       // DataTagged  
       if (dataVec.extractData(archiveFile,noValues)) {  
         throw DataException("extractData Error: problem reading data from archive file");  
       }  
       break;  
     case 3:  
       // DataExpanded  
       if (dataVec.extractData(archiveFile,noValues)) {  
         throw DataException("extractData Error: problem reading data from archive file");  
       }  
       break;  
   }  
   
   if (!archiveFile.good()) {  
     throw DataException("extractData Error: problem reading from archive file");  
   }  
   
   //  
   // Close archive file  
   archiveFile.close();  
   
   if (!archiveFile.good()) {  
     throw DataException("extractData Error: problem closing archive file");  
   }  
   
   //  
   // Construct an appropriate Data object  
   DataAbstract* tempData;  
   switch (dataType) {  
     case 0:  
       // DataEmpty  
       tempData=new DataEmpty();  
       break;  
     case 1:  
       // DataConstant  
       tempData=new DataConstant(fspace,dataPointShape,dataVec);  
       break;  
     case 2:  
       // DataTagged  
       tempData=new DataTagged(fspace,dataPointShape,tagNumbers,dataVec);  
       break;  
     case 3:  
       // DataExpanded  
       tempData=new DataExpanded(fspace,dataPointShape,dataVec);  
       break;  
   }  
   shared_ptr<DataAbstract> temp_data(tempData);  
   m_data=temp_data;  
 }  
2006    
2007  ostream& escript::operator<<(ostream& o, const Data& data)  ostream& escript::operator<<(ostream& o, const Data& data)
2008  {  {
# Line 2183  escript::C_GeneralTensorProduct(Data& ar Line 2040  escript::C_GeneralTensorProduct(Data& ar
2040    // Get rank and shape of inputs    // Get rank and shape of inputs
2041    int rank0 = arg_0_Z.getDataPointRank();    int rank0 = arg_0_Z.getDataPointRank();
2042    int rank1 = arg_1_Z.getDataPointRank();    int rank1 = arg_1_Z.getDataPointRank();
2043    DataArrayView::ShapeType shape0 = arg_0_Z.getDataPointShape();    const DataTypes::ShapeType& shape0 = arg_0_Z.getDataPointShape();
2044    DataArrayView::ShapeType shape1 = arg_1_Z.getDataPointShape();    const DataTypes::ShapeType& shape1 = arg_1_Z.getDataPointShape();
2045    
2046    // Prepare for the loops of the product and verify compatibility of shapes    // Prepare for the loops of the product and verify compatibility of shapes
2047    int start0=0, start1=0;    int start0=0, start1=0;
# Line 2193  escript::C_GeneralTensorProduct(Data& ar Line 2050  escript::C_GeneralTensorProduct(Data& ar
2050    else if (transpose == 2)  { start1 = rank1-axis_offset; }    else if (transpose == 2)  { start1 = rank1-axis_offset; }
2051    else              { throw DataException("C_GeneralTensorProduct: Error - transpose should be 0, 1 or 2"); }    else              { throw DataException("C_GeneralTensorProduct: Error - transpose should be 0, 1 or 2"); }
2052    
2053    
2054    // Adjust the shapes for transpose    // Adjust the shapes for transpose
2055    DataArrayView::ShapeType tmpShape0;    DataTypes::ShapeType tmpShape0(rank0);    // pre-sizing the vectors rather
2056    DataArrayView::ShapeType tmpShape1;    DataTypes::ShapeType tmpShape1(rank1);    // than using push_back
2057    for (int i=0; i<rank0; i++)   { tmpShape0.push_back( shape0[(i+start0)%rank0] ); }    for (int i=0; i<rank0; i++)   { tmpShape0[i]=shape0[(i+start0)%rank0]; }
2058    for (int i=0; i<rank1; i++)   { tmpShape1.push_back( shape1[(i+start1)%rank1] ); }    for (int i=0; i<rank1; i++)   { tmpShape1[i]=shape1[(i+start1)%rank1]; }
2059    
2060  #if 0  #if 0
2061    // For debugging: show shape after transpose    // For debugging: show shape after transpose
# Line 2228  escript::C_GeneralTensorProduct(Data& ar Line 2086  escript::C_GeneralTensorProduct(Data& ar
2086      SR *= tmpShape1[i];      SR *= tmpShape1[i];
2087    }    }
2088    
2089    // Define the shape of the output    // Define the shape of the output (rank of shape is the sum of the loop ranges below)
2090    DataArrayView::ShapeType shape2;    DataTypes::ShapeType shape2(rank0+rank1-2*axis_offset);  
2091    for (int i=0; i<rank0-axis_offset; i++) { shape2.push_back(tmpShape0[i]); } // First part of arg_0_Z    {         // block to limit the scope of out_index
2092    for (int i=axis_offset; i<rank1; i++)   { shape2.push_back(tmpShape1[i]); } // Last part of arg_1_Z       int out_index=0;
2093         for (int i=0; i<rank0-axis_offset; i++, ++out_index) { shape2[out_index]=tmpShape0[i]; } // First part of arg_0_Z
2094         for (int i=axis_offset; i<rank1; i++, ++out_index)   { shape2[out_index]=tmpShape1[i]; } // Last part of arg_1_Z
2095      }
2096    
2097    // Declare output Data object    // Declare output Data object
2098    Data res;    Data res;
2099    
2100    if      (arg_0_Z.isConstant()   && arg_1_Z.isConstant()) {    if      (arg_0_Z.isConstant()   && arg_1_Z.isConstant()) {
2101      res = Data(0.0, shape2, arg_1_Z.getFunctionSpace());    // DataConstant output      res = Data(0.0, shape2, arg_1_Z.getFunctionSpace());    // DataConstant output
2102      double *ptr_0 = &((arg_0_Z.getPointDataView().getData())[0]);      double *ptr_0 = &(arg_0_Z.getDataAtOffset(0));
2103      double *ptr_1 = &((arg_1_Z.getPointDataView().getData())[0]);      double *ptr_1 = &(arg_1_Z.getDataAtOffset(0));
2104      double *ptr_2 = &((res.getPointDataView().getData())[0]);      double *ptr_2 = &(res.getDataAtOffset(0));
2105      matrix_matrix_product(SL, SM, SR, ptr_0, ptr_1, ptr_2, transpose);      matrix_matrix_product(SL, SM, SR, ptr_0, ptr_1, ptr_2, transpose);
2106    }    }
2107    else if (arg_0_Z.isConstant()   && arg_1_Z.isTagged()) {    else if (arg_0_Z.isConstant()   && arg_1_Z.isTagged()) {
# Line 2261  escript::C_GeneralTensorProduct(Data& ar Line 2122  escript::C_GeneralTensorProduct(Data& ar
2122    
2123      // Prepare offset into DataConstant      // Prepare offset into DataConstant
2124      int offset_0 = tmp_0->getPointOffset(0,0);      int offset_0 = tmp_0->getPointOffset(0,0);
2125      double *ptr_0 = &((arg_0_Z.getPointDataView().getData())[offset_0]);      double *ptr_0 = &(arg_0_Z.getDataAtOffset(offset_0));
2126      // Get the views      // Get the views
2127      DataArrayView view_1 = tmp_1->getDefaultValue();  //     DataArrayView view_1 = tmp_1->getDefaultValue();
2128      DataArrayView view_2 = tmp_2->getDefaultValue();  //     DataArrayView view_2 = tmp_2->getDefaultValue();
2129      // Get the pointers to the actual data  //     // Get the pointers to the actual data
2130      double *ptr_1 = &((view_1.getData())[0]);  //     double *ptr_1 = &((view_1.getData())[0]);
2131      double *ptr_2 = &((view_2.getData())[0]);  //     double *ptr_2 = &((view_2.getData())[0]);
2132    
2133        double *ptr_1 = &(tmp_1->getDefaultValue(0));
2134        double *ptr_2 = &(tmp_2->getDefaultValue(0));
2135    
2136    
2137      // Compute an MVP for the default      // Compute an MVP for the default
2138      matrix_matrix_product(SL, SM, SR, ptr_0, ptr_1, ptr_2, transpose);      matrix_matrix_product(SL, SM, SR, ptr_0, ptr_1, ptr_2, transpose);
2139      // Compute an MVP for each tag      // Compute an MVP for each tag
2140      const DataTagged::DataMapType& lookup_1=tmp_1->getTagLookup();      const DataTagged::DataMapType& lookup_1=tmp_1->getTagLookup();
2141      DataTagged::DataMapType::const_iterator i; // i->first is a tag, i->second is an offset into memory      DataTagged::DataMapType::const_iterator i; // i->first is a tag, i->second is an offset into memory
2142      for (i=lookup_1.begin();i!=lookup_1.end();i++) {      for (i=lookup_1.begin();i!=lookup_1.end();i++) {
2143        tmp_2->addTaggedValue(i->first,tmp_2->getDefaultValue());        tmp_2->addTag(i->first);
2144        DataArrayView view_1 = tmp_1->getDataPointByTag(i->first);  //       DataArrayView view_1 = tmp_1->getDataPointByTag(i->first);
2145        DataArrayView view_2 = tmp_2->getDataPointByTag(i->first);  //       DataArrayView view_2 = tmp_2->getDataPointByTag(i->first);
2146        double *ptr_1 = &view_1.getData(0);  //       double *ptr_1 = &view_1.getData(0);
2147        double *ptr_2 = &view_2.getData(0);  //       double *ptr_2 = &view_2.getData(0);
2148    
2149          double *ptr_1 = &(tmp_1->getDataByTag(i->first,0));
2150          double *ptr_2 = &(tmp_2->getDataByTag(i->first,0));
2151        
2152        matrix_matrix_product(SL, SM, SR, ptr_0, ptr_1, ptr_2, transpose);        matrix_matrix_product(SL, SM, SR, ptr_0, ptr_1, ptr_2, transpose);
2153      }      }
2154    
# Line 2301  escript::C_GeneralTensorProduct(Data& ar Line 2171  escript::C_GeneralTensorProduct(Data& ar
2171        for (dataPointNo_1 = 0; dataPointNo_1 < numDataPointsPerSample_1; dataPointNo_1++) {        for (dataPointNo_1 = 0; dataPointNo_1 < numDataPointsPerSample_1; dataPointNo_1++) {
2172          int offset_1 = tmp_1->getPointOffset(sampleNo_1,dataPointNo_1);          int offset_1 = tmp_1->getPointOffset(sampleNo_1,dataPointNo_1);
2173          int offset_2 = tmp_2->getPointOffset(sampleNo_1,dataPointNo_1);          int offset_2 = tmp_2->getPointOffset(sampleNo_1,dataPointNo_1);
2174          double *ptr_0 = &((arg_0_Z.getPointDataView().getData())[offset_0]);          double *ptr_0 = &(arg_0_Z.getDataAtOffset(offset_0));
2175          double *ptr_1 = &((arg_1_Z.getPointDataView().getData())[offset_1]);          double *ptr_1 = &(arg_1_Z.getDataAtOffset(offset_1));
2176          double *ptr_2 = &((res.getPointDataView().getData())[offset_2]);          double *ptr_2 = &(res.getDataAtOffset(offset_2));
2177          matrix_matrix_product(SL, SM, SR, ptr_0, ptr_1, ptr_2, transpose);          matrix_matrix_product(SL, SM, SR, ptr_0, ptr_1, ptr_2, transpose);
2178        }        }
2179      }      }
# Line 2327  escript::C_GeneralTensorProduct(Data& ar Line 2197  escript::C_GeneralTensorProduct(Data& ar
2197    
2198      // Prepare offset into DataConstant      // Prepare offset into DataConstant
2199      int offset_1 = tmp_1->getPointOffset(0,0);      int offset_1 = tmp_1->getPointOffset(0,0);
2200      double *ptr_1 = &((arg_1_Z.getPointDataView().getData())[offset_1]);      double *ptr_1 = &(arg_1_Z.getDataAtOffset(offset_1));
2201      // Get the views      // Get the views
2202      DataArrayView view_0 = tmp_0->getDefaultValue();  //     DataArrayView view_0 = tmp_0->getDefaultValue();
2203      DataArrayView view_2 = tmp_2->getDefaultValue();  //     DataArrayView view_2 = tmp_2->getDefaultValue();
2204      // Get the pointers to the actual data  //     // Get the pointers to the actual data
2205      double *ptr_0 = &((view_0.getData())[0]);  //     double *ptr_0 = &((view_0.getData())[0]);
2206      double *ptr_2 = &((view_2.getData())[0]);  //     double *ptr_2 = &((view_2.getData())[0]);
2207    
2208        double *ptr_0 = &(tmp_0->getDefaultValue(0));
2209        double *ptr_2 = &(tmp_2->getDefaultValue(0));
2210    
2211      // Compute an MVP for the default      // Compute an MVP for the default
2212      matrix_matrix_product(SL, SM, SR, ptr_0, ptr_1, ptr_2, transpose);      matrix_matrix_product(SL, SM, SR, ptr_0, ptr_1, ptr_2, transpose);
2213      // Compute an MVP for each tag      // Compute an MVP for each tag
2214      const DataTagged::DataMapType& lookup_0=tmp_0->getTagLookup();      const DataTagged::DataMapType& lookup_0=tmp_0->getTagLookup();
2215      DataTagged::DataMapType::const_iterator i; // i->first is a tag, i->second is an offset into memory      DataTagged::DataMapType::const_iterator i; // i->first is a tag, i->second is an offset into memory
2216      for (i=lookup_0.begin();i!=lookup_0.end();i++) {      for (i=lookup_0.begin();i!=lookup_0.end();i++) {
2217        tmp_2->addTaggedValue(i->first,tmp_2->getDefaultValue());  //      tmp_2->addTaggedValue(i->first,tmp_2->getDefaultValue());
2218        DataArrayView view_0 = tmp_0->getDataPointByTag(i->first);  //       DataArrayView view_0 = tmp_0->getDataPointByTag(i->first);
2219        DataArrayView view_2 = tmp_2->getDataPointByTag(i->first);  //       DataArrayView view_2 = tmp_2->getDataPointByTag(i->first);
2220        double *ptr_0 = &view_0.getData(0);  //       double *ptr_0 = &view_0.getData(0);
2221        double *ptr_2 = &view_2.getData(0);  //       double *ptr_2 = &view_2.getData(0);
2222    
2223          tmp_2->addTag(i->first);
2224          double *ptr_0 = &(tmp_0->getDataByTag(i->first,0));
2225          double *ptr_2 = &(tmp_2->getDataByTag(i->first,0));
2226        matrix_matrix_product(SL, SM, SR, ptr_0, ptr_1, ptr_2, transpose);        matrix_matrix_product(SL, SM, SR, ptr_0, ptr_1, ptr_2, transpose);
2227      }      }
2228    
# Line 2365  escript::C_GeneralTensorProduct(Data& ar Line 2243  escript::C_GeneralTensorProduct(Data& ar
2243      DataTagged* tmp_2=dynamic_cast<DataTagged*>(res.borrowData());      DataTagged* tmp_2=dynamic_cast<DataTagged*>(res.borrowData());
2244      if (tmp_2==0) { throw DataException("GTP Programming error - casting to DataTagged."); }      if (tmp_2==0) { throw DataException("GTP Programming error - casting to DataTagged."); }
2245    
2246      // Get the views  //     // Get the views
2247      DataArrayView view_0 = tmp_0->getDefaultValue();  //     DataArrayView view_0 = tmp_0->getDefaultValue();
2248      DataArrayView view_1 = tmp_1->getDefaultValue();  //     DataArrayView view_1 = tmp_1->getDefaultValue();
2249      DataArrayView view_2 = tmp_2->getDefaultValue();  //     DataArrayView view_2 = tmp_2->getDefaultValue();
2250      // Get the pointers to the actual data  //     // Get the pointers to the actual data
2251      double *ptr_0 = &((view_0.getData())[0]);  //     double *ptr_0 = &((view_0.getData())[0]);
2252      double *ptr_1 = &((view_1.getData())[0]);  //     double *ptr_1 = &((view_1.getData())[0]);
2253      double *ptr_2 = &((view_2.getData())[0]);  //     double *ptr_2 = &((view_2.getData())[0]);
2254    
2255        double *ptr_0 = &(tmp_0->getDefaultValue(0));
2256        double *ptr_1 = &(tmp_1->getDefaultValue(0));
2257        double *ptr_2 = &(tmp_2->getDefaultValue(0));
2258    
2259    
2260      // Compute an MVP for the default      // Compute an MVP for the default
2261      matrix_matrix_product(SL, SM, SR, ptr_0, ptr_1, ptr_2, transpose);      matrix_matrix_product(SL, SM, SR, ptr_0, ptr_1, ptr_2, transpose);
2262      // Merge the tags      // Merge the tags
# Line 2380  escript::C_GeneralTensorProduct(Data& ar Line 2264  escript::C_GeneralTensorProduct(Data& ar
2264      const DataTagged::DataMapType& lookup_0=tmp_0->getTagLookup();      const DataTagged::DataMapType& lookup_0=tmp_0->getTagLookup();
2265      const DataTagged::DataMapType& lookup_1=tmp_1->getTagLookup();      const DataTagged::DataMapType& lookup_1=tmp_1->getTagLookup();
2266      for (i=lookup_0.begin();i!=lookup_0.end();i++) {      for (i=lookup_0.begin();i!=lookup_0.end();i++) {
2267        tmp_2->addTaggedValue(i->first,tmp_2->getDefaultValue()); // use tmp_2 to get correct shape        tmp_2->addTag(i->first); // use tmp_2 to get correct shape
2268      }      }
2269      for (i=lookup_1.begin();i!=lookup_1.end();i++) {      for (i=lookup_1.begin();i!=lookup_1.end();i++) {
2270        tmp_2->addTaggedValue(i->first,tmp_2->getDefaultValue());        tmp_2->addTag(i->first);
2271      }      }
2272      // Compute an MVP for each tag      // Compute an MVP for each tag
2273      const DataTagged::DataMapType& lookup_2=tmp_2->getTagLookup();      const DataTagged::DataMapType& lookup_2=tmp_2->getTagLookup();
2274      for (i=lookup_2.begin();i!=lookup_2.end();i++) {      for (i=lookup_2.begin();i!=lookup_2.end();i++) {
2275        DataArrayView view_0 = tmp_0->getDataPointByTag(i->first);  //       DataArrayView view_0 = tmp_0->getDataPointByTag(i->first);
2276        DataArrayView view_1 = tmp_1->getDataPointByTag(i->first);  //       DataArrayView view_1 = tmp_1->getDataPointByTag(i->first);
2277        DataArrayView view_2 = tmp_2->getDataPointByTag(i->first);  //       DataArrayView view_2 = tmp_2->getDataPointByTag(i->first);
2278        double *ptr_0 = &view_0.getData(0);  //       double *ptr_0 = &view_0.getData(0);
2279        double *ptr_1 = &view_1.getData(0);  //       double *ptr_1 = &view_1.getData(0);
2280        double *ptr_2 = &view_2.getData(0);  //       double *ptr_2 = &view_2.getData(0);
2281    
2282          double *ptr_0 = &(tmp_0->getDataByTag(i->first,0));
2283          double *ptr_1 = &(tmp_1->getDataByTag(i->first,0));
2284          double *ptr_2 = &(tmp_2->getDataByTag(i->first,0));
2285    
2286        matrix_matrix_product(SL, SM, SR, ptr_0, ptr_1, ptr_2, transpose);        matrix_matrix_product(SL, SM, SR, ptr_0, ptr_1, ptr_2, transpose);
2287      }      }
2288    
# Line 2414  escript::C_GeneralTensorProduct(Data& ar Line 2303  escript::C_GeneralTensorProduct(Data& ar
2303      #pragma omp parallel for private(sampleNo_0,dataPointNo_0) schedule(static)      #pragma omp parallel for private(sampleNo_0,dataPointNo_0) schedule(static)
2304      for (sampleNo_0 = 0; sampleNo_0 < numSamples_0; sampleNo_0++) {      for (sampleNo_0 = 0; sampleNo_0 < numSamples_0; sampleNo_0++) {
2305        int offset_0 = tmp_0->getPointOffset(sampleNo_0,0); // They're all the same, so just use #0        int offset_0 = tmp_0->getPointOffset(sampleNo_0,0); // They're all the same, so just use #0
2306        double *ptr_0 = &((arg_0_Z.getPointDataView().getData())[offset_0]);        double *ptr_0 = &(arg_0_Z.getDataAtOffset(offset_0));
2307        for (dataPointNo_0 = 0; dataPointNo_0 < numDataPointsPerSample_0; dataPointNo_0++) {        for (dataPointNo_0 = 0; dataPointNo_0 < numDataPointsPerSample_0; dataPointNo_0++) {
2308          int offset_1 = tmp_1->getPointOffset(sampleNo_0,dataPointNo_0);          int offset_1 = tmp_1->getPointOffset(sampleNo_0,dataPointNo_0);
2309          int offset_2 = tmp_2->getPointOffset(sampleNo_0,dataPointNo_0);          int offset_2 = tmp_2->getPointOffset(sampleNo_0,dataPointNo_0);
2310          double *ptr_1 = &((arg_1_Z.getPointDataView().getData())[offset_1]);          double *ptr_1 = &(arg_1_Z.getDataAtOffset(offset_1));
2311          double *ptr_2 = &((res.getPointDataView().getData())[offset_2]);          double *ptr_2 = &(res.getDataAtOffset(offset_2));
2312          matrix_matrix_product(SL, SM, SR, ptr_0, ptr_1, ptr_2, transpose);          matrix_matrix_product(SL, SM, SR, ptr_0, ptr_1, ptr_2, transpose);
2313        }        }
2314      }      }
# Line 2443  escript::C_GeneralTensorProduct(Data& ar Line 2332  escript::C_GeneralTensorProduct(Data& ar
2332        for (dataPointNo_0 = 0; dataPointNo_0 < numDataPointsPerSample_0; dataPointNo_0++) {        for (dataPointNo_0 = 0; dataPointNo_0 < numDataPointsPerSample_0; dataPointNo_0++) {
2333          int offset_0 = tmp_0->getPointOffset(sampleNo_0,dataPointNo_0);          int offset_0 = tmp_0->getPointOffset(sampleNo_0,dataPointNo_0);
2334          int offset_2 = tmp_2->getPointOffset(sampleNo_0,dataPointNo_0);          int offset_2 = tmp_2->getPointOffset(sampleNo_0,dataPointNo_0);
2335          double *ptr_0 = &((arg_0_Z.getPointDataView().getData())[offset_0]);          double *ptr_0 = &(arg_0_Z.getDataAtOffset(offset_0));
2336          double *ptr_1 = &((arg_1_Z.getPointDataView().getData())[offset_1]);          double *ptr_1 = &(arg_1_Z.getDataAtOffset(offset_1));
2337          double *ptr_2 = &((res.getPointDataView().getData())[offset_2]);          double *ptr_2 = &(res.getDataAtOffset(offset_2));
2338          matrix_matrix_product(SL, SM, SR, ptr_0, ptr_1, ptr_2, transpose);          matrix_matrix_product(SL, SM, SR, ptr_0, ptr_1, ptr_2, transpose);
2339        }        }
2340      }      }
# Line 2468  escript::C_GeneralTensorProduct(Data& ar Line 2357  escript::C_GeneralTensorProduct(Data& ar
2357      #pragma omp parallel for private(sampleNo_0,dataPointNo_0) schedule(static)      #pragma omp parallel for private(sampleNo_0,dataPointNo_0) schedule(static)
2358      for (sampleNo_0 = 0; sampleNo_0 < numSamples_0; sampleNo_0++) {      for (sampleNo_0 = 0; sampleNo_0 < numSamples_0; sampleNo_0++) {
2359        int offset_1 = tmp_1->getPointOffset(sampleNo_0,0);        int offset_1 = tmp_1->getPointOffset(sampleNo_0,0);
2360        double *ptr_1 = &((arg_1_Z.getPointDataView().getData())[offset_1]);        double *ptr_1 = &(arg_1_Z.getDataAtOffset(offset_1));
2361        for (dataPointNo_0 = 0; dataPointNo_0 < numDataPointsPerSample_0; dataPointNo_0++) {        for (dataPointNo_0 = 0; dataPointNo_0 < numDataPointsPerSample_0; dataPointNo_0++) {
2362          int offset_0 = tmp_0->getPointOffset(sampleNo_0,dataPointNo_0);          int offset_0 = tmp_0->getPointOffset(sampleNo_0,dataPointNo_0);
2363          int offset_2 = tmp_2->getPointOffset(sampleNo_0,dataPointNo_0);          int offset_2 = tmp_2->getPointOffset(sampleNo_0,dataPointNo_0);
2364          double *ptr_0 = &((arg_0_Z.getPointDataView().getData())[offset_0]);          double *ptr_0 = &(arg_0_Z.getDataAtOffset(offset_0));
2365          double *ptr_2 = &((res.getPointDataView().getData())[offset_2]);          double *ptr_2 = &(res.getDataAtOffset(offset_2));
2366          matrix_matrix_product(SL, SM, SR, ptr_0, ptr_1, ptr_2, transpose);          matrix_matrix_product(SL, SM, SR, ptr_0, ptr_1, ptr_2, transpose);
2367        }        }
2368      }      }
# Line 2498  escript::C_GeneralTensorProduct(Data& ar Line 2387  escript::C_GeneralTensorProduct(Data& ar
2387          int offset_0 = tmp_0->getPointOffset(sampleNo_0,dataPointNo_0);          int offset_0 = tmp_0->getPointOffset(sampleNo_0,dataPointNo_0);
2388          int offset_1 = tmp_1->getPointOffset(sampleNo_0,dataPointNo_0);          int offset_1 = tmp_1->getPointOffset(sampleNo_0,dataPointNo_0);
2389          int offset_2 = tmp_2->getPointOffset(sampleNo_0,dataPointNo_0);          int offset_2 = tmp_2->getPointOffset(sampleNo_0,dataPointNo_0);
2390          double *ptr_0 = &((arg_0_Z.getPointDataView().getData())[offset_0]);          double *ptr_0 = &(arg_0_Z.getDataAtOffset(offset_0));
2391          double *ptr_1 = &((arg_1_Z.getPointDataView().getData())[offset_1]);          double *ptr_1 = &(arg_1_Z.getDataAtOffset(offset_1));
2392          double *ptr_2 = &((res.getPointDataView().getData())[offset_2]);          double *ptr_2 = &(res.getDataAtOffset(offset_2));
2393          matrix_matrix_product(SL, SM, SR, ptr_0, ptr_1, ptr_2, transpose);          matrix_matrix_product(SL, SM, SR, ptr_0, ptr_1, ptr_2, transpose);
2394        }        }
2395      }      }
# Line 2519  Data::borrowData() const Line 2408  Data::borrowData() const
2408    return m_data.get();    return m_data.get();
2409  }  }
2410    
2411    
2412    std::string
2413    Data::toString() const
2414    {
2415        static const DataTypes::ValueType::size_type TOO_MANY_POINTS=80;
2416        if (getNumDataPoints()*getDataPointSize()>TOO_MANY_POINTS)
2417        {
2418        stringstream temp;
2419        temp << "Summary: inf="<< inf() << " sup=" << sup() << " data points=" << getNumDataPoints();
2420        return  temp.str();
2421        }
2422        return m_data->toString();
2423    }
2424    
2425    
2426    
2427    DataTypes::ValueType::const_reference
2428    Data::getDataAtOffset(DataTypes::ValueType::size_type i) const
2429    {
2430        return m_data->getDataAtOffset(i);
2431    }
2432    
2433    
2434    DataTypes::ValueType::reference
2435    Data::getDataAtOffset(DataTypes::ValueType::size_type i)
2436    {
2437        return m_data->getDataAtOffset(i);
2438    }
2439    
2440    DataTypes::ValueType::const_reference
2441    Data::getDataPoint(int sampleNo, int dataPointNo) const
2442    {
2443        return m_data->getDataAtOffset(m_data->getPointOffset(sampleNo, dataPointNo));
2444    }
2445    
2446    
2447    DataTypes::ValueType::reference
2448    Data::getDataPoint(int sampleNo, int dataPointNo)
2449    {
2450        return m_data->getDataAtOffset(m_data->getPointOffset(sampleNo, dataPointNo));
2451    }
2452    
2453    
2454  /* Member functions specific to the MPI implementation */  /* Member functions specific to the MPI implementation */
2455    
2456  void  void
# Line 2551  Data::dump(const std::string fileName) c Line 2483  Data::dump(const std::string fileName) c
2483  int  int
2484  Data::get_MPISize() const  Data::get_MPISize() const
2485  {  {
2486      int error, size;      int size;
2487  #ifdef PASO_MPI  #ifdef PASO_MPI
2488        int error;
2489      error = MPI_Comm_size( get_MPIComm(), &size );      error = MPI_Comm_size( get_MPIComm(), &size );
2490  #else  #else
2491      size = 1;      size = 1;
# Line 2563  Data::get_MPISize() const Line 2496  Data::get_MPISize() const
2496  int  int
2497  Data::get_MPIRank() const  Data::get_MPIRank() const
2498  {  {
2499      int error, rank;      int rank;
2500  #ifdef PASO_MPI  #ifdef PASO_MPI
2501        int error;
2502      error = MPI_Comm_rank( get_MPIComm(), &rank );      error = MPI_Comm_rank( get_MPIComm(), &rank );
2503  #else  #else
2504      rank = 0;      rank = 0;
# Line 2582  Data::get_MPIComm() const Line 2516  Data::get_MPIComm() const
2516  #endif  #endif
2517  }  }
2518    
2519    

Legend:
Removed from v.1387  
changed lines
  Added in v.1841

  ViewVC Help
Powered by ViewVC 1.1.26