/[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 1878 by gross, Tue Oct 14 03:39:13 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 46  Data::Data() Line 46  Data::Data()
46    //    //
47    // Default data is type DataEmpty    // Default data is type DataEmpty
48    DataAbstract* temp=new DataEmpty();    DataAbstract* temp=new DataEmpty();
49    shared_ptr<DataAbstract> temp_data(temp);    m_data=temp->getPtr();
   m_data=temp_data;  
50    m_protected=false;    m_protected=false;
51  }  }
52    
# Line 56  Data::Data(double value, Line 55  Data::Data(double value,
55             const FunctionSpace& what,             const FunctionSpace& what,
56             bool expanded)             bool expanded)
57  {  {
58    DataArrayView::ShapeType dataPointShape;    DataTypes::ShapeType dataPointShape;
59    for (int i = 0; i < shape.attr("__len__")(); ++i) {    for (int i = 0; i < shape.attr("__len__")(); ++i) {
60      dataPointShape.push_back(extract<const int>(shape[i]));      dataPointShape.push_back(extract<const int>(shape[i]));
61    }    }
62    
63    int len = DataArrayView::noValues(dataPointShape);    int len = DataTypes::noValues(dataPointShape);
64    DataVector temp_data(len,value,len);    DataVector temp_data(len,value,len);
65    DataArrayView temp_dataView(temp_data, dataPointShape);    initialise(temp_data, dataPointShape, what, expanded);
   
   initialise(temp_dataView, what, expanded);  
   
66    m_protected=false;    m_protected=false;
67  }  }
68    
69  Data::Data(double value,  Data::Data(double value,
70         const DataArrayView::ShapeType& dataPointShape,         const DataTypes::ShapeType& dataPointShape,
71         const FunctionSpace& what,         const FunctionSpace& what,
72             bool expanded)             bool expanded)
73  {  {
74    int len = DataArrayView::noValues(dataPointShape);    int len = DataTypes::noValues(dataPointShape);
75    
76    DataVector temp_data(len,value,len);    DataVector temp_data(len,value,len);
77    DataArrayView temp_dataView(temp_data, dataPointShape);  //   DataArrayView temp_dataView(temp_data, dataPointShape);
78    
79    initialise(temp_dataView, what, expanded);  //   initialise(temp_dataView, what, expanded);
80      initialise(temp_data, dataPointShape, what, expanded);
81    
82    m_protected=false;    m_protected=false;
83  }  }
# Line 91  Data::Data(const Data& inData) Line 88  Data::Data(const Data& inData)
88    m_protected=inData.isProtected();    m_protected=inData.isProtected();
89  }  }
90    
91    
92  Data::Data(const Data& inData,  Data::Data(const Data& inData,
93             const DataArrayView::RegionType& region)             const DataTypes::RegionType& region)
94  {  {
95    //    //
96    // Create Data which is a slice of another Data    // Create Data which is a slice of another Data
97    DataAbstract* tmp = inData.m_data->getSlice(region);    DataAbstract* tmp = inData.m_data->getSlice(region);
98    shared_ptr<DataAbstract> temp_data(tmp);    m_data=DataAbstract_ptr(tmp);
   m_data=temp_data;  
99    m_protected=false;    m_protected=false;
100  }  }
101    
102  Data::Data(const Data& inData,  Data::Data(const Data& inData,
103             const FunctionSpace& functionspace)             const FunctionSpace& functionspace)
104  {  {
105      if (inData.isEmpty())
106      {
107        throw DataException("Error - will not interpolate for instances of DataEmpty.");
108      }
109    if (inData.getFunctionSpace()==functionspace) {    if (inData.getFunctionSpace()==functionspace) {
110      m_data=inData.m_data;      m_data=inData.m_data;
111      } else if (inData.isConstant()) { // for a constant function, we just need to use the new function space
112        if (!inData.probeInterpolation(functionspace))
113        {           // Even though this is constant, we still need to check whether interpolation is allowed
114        throw FunctionSpaceException("Call to probeInterpolation returned false for DataConstant.");
115        }
116        DataConstant* dc=new DataConstant(functionspace,inData.m_data->getShape(),inData.m_data->getVector());  
117        m_data=DataAbstract_ptr(dc);
118    } else {    } else {
119      Data tmp(0,inData.getPointDataView().getShape(),functionspace,true);      Data tmp(0,inData.getDataPointShape(),functionspace,true);
120      // Note: Must use a reference or pointer to a derived object      // Note: Must use a reference or pointer to a derived object
121      // in order to get polymorphic behaviour. Shouldn't really      // in order to get polymorphic behaviour. Shouldn't really
122      // be able to create an instance of AbstractDomain but that was done      // be able to create an instance of AbstractDomain but that was done
123      // as a boost:python work around which may no longer be required.      // as a boost:python work around which may no longer be required.
124      const AbstractDomain& inDataDomain=inData.getDomain();      /*const AbstractDomain& inDataDomain=inData.getDomain();*/
125        const_Domain_ptr inDataDomain=inData.getDomain();
126      if  (inDataDomain==functionspace.getDomain()) {      if  (inDataDomain==functionspace.getDomain()) {
127        inDataDomain.interpolateOnDomain(tmp,inData);        inDataDomain->interpolateOnDomain(tmp,inData);
128      } else {      } else {
129        inDataDomain.interpolateACross(tmp,inData);        inDataDomain->interpolateACross(tmp,inData);
130      }      }
131      m_data=tmp.m_data;      m_data=tmp.m_data;
132    }    }
133    m_protected=false;    m_protected=false;
134  }  }
135    
136  Data::Data(const DataTagged::TagListType& tagKeys,  Data::Data(DataAbstract* underlyingdata)
            const DataTagged::ValueListType & values,  
            const DataArrayView& defaultValue,  
            const FunctionSpace& what,  
            bool expanded)  
137  {  {
138    DataAbstract* temp=new DataTagged(tagKeys,values,defaultValue,what);  //  m_data=shared_ptr<DataAbstract>(underlyingdata);
139    shared_ptr<DataAbstract> temp_data(temp);      m_data=underlyingdata->getPtr();
140    m_data=temp_data;      m_protected=false;
   m_protected=false;  
   if (expanded) {  
     expand();  
   }  
141  }  }
142    
143  Data::Data(const numeric::array& value,  Data::Data(const numeric::array& value,
# Line 146  Data::Data(const numeric::array& value, Line 147  Data::Data(const numeric::array& value,
147    initialise(value,what,expanded);    initialise(value,what,expanded);
148    m_protected=false;    m_protected=false;
149  }  }
150    /*
151  Data::Data(const DataArrayView& value,  Data::Data(const DataArrayView& value,
152         const FunctionSpace& what,         const FunctionSpace& what,
153             bool expanded)             bool expanded)
154  {  {
155    initialise(value,what,expanded);    initialise(value,what,expanded);
156    m_protected=false;    m_protected=false;
157    }*/
158    
159    Data::Data(const DataTypes::ValueType& value,
160             const DataTypes::ShapeType& shape,
161                     const FunctionSpace& what,
162                     bool expanded)
163    {
164       initialise(value,shape,what,expanded);
165       m_protected=false;
166  }  }
167    
168    
169  Data::Data(const object& value,  Data::Data(const object& value,
170         const FunctionSpace& what,         const FunctionSpace& what,
171             bool expanded)             bool expanded)
# Line 168  Data::Data(const object& value, Line 179  Data::Data(const object& value,
179  Data::Data(const object& value,  Data::Data(const object& value,
180             const Data& other)             const Data& other)
181  {  {
   
182    numeric::array asNumArray(value);    numeric::array asNumArray(value);
183    
   
184    // extract the shape of the numarray    // extract the shape of the numarray
185    DataArrayView::ShapeType tempShape;    DataTypes::ShapeType tempShape=DataTypes::shapeFromNumArray(asNumArray);
186    for (int i=0; i < asNumArray.getrank(); i++) {  // /*  for (int i=0; i < asNumArray.getrank(); i++) {
187      tempShape.push_back(extract<int>(asNumArray.getshape()[i]));  //     tempShape.push_back(extract<int>(asNumArray.getshape()[i]));
188    }  //   }*/
189    // get the space for the data vector  //   // get the space for the data vector
190    int len = DataArrayView::noValues(tempShape);  //   int len = DataTypes::noValues(tempShape);
191    DataVector temp_data(len, 0.0, len);  //   DataVector temp_data(len, 0.0, len);
192    DataArrayView temp_dataView(temp_data, tempShape);  // /*  DataArrayView temp_dataView(temp_data, tempShape);
193    temp_dataView.copy(asNumArray);  //   temp_dataView.copy(asNumArray);*/
194    //   temp_data.copyFromNumArray(asNumArray);
195    
196    //    //
197    // Create DataConstant using the given value and all other parameters    // Create DataConstant using the given value and all other parameters
198    // copied from other. If value is a rank 0 object this Data    // copied from other. If value is a rank 0 object this Data
199    // will assume the point data shape of other.    // will assume the point data shape of other.
200    
201    if (temp_dataView.getRank()==0) {    if (DataTypes::getRank(tempShape)/*temp_dataView.getRank()*/==0) {
202      int len = DataArrayView::noValues(other.getPointDataView().getShape());  
203    
204      DataVector temp2_data(len, temp_dataView(), len);      // get the space for the data vector
205      DataArrayView temp2_dataView(temp2_data, other.getPointDataView().getShape());      int len1 = DataTypes::noValues(tempShape);
206      initialise(temp2_dataView, other.getFunctionSpace(), false);      DataVector temp_data(len1, 0.0, len1);
207        temp_data.copyFromNumArray(asNumArray);
208    
209        int len = DataTypes::noValues(other.getDataPointShape());
210    
211        DataVector temp2_data(len, temp_data[0]/*temp_dataView()*/, len);
212        //DataArrayView temp2_dataView(temp2_data, other.getPointDataView().getShape());
213    //     initialise(temp2_dataView, other.getFunctionSpace(), false);
214    
215        DataConstant* t=new DataConstant(other.getFunctionSpace(),other.getDataPointShape(),temp2_data);
216    //     boost::shared_ptr<DataAbstract> sp(t);
217    //     m_data=sp;
218        m_data=DataAbstract_ptr(t);
219    
220    } else {    } else {
221      //      //
222      // Create a DataConstant with the same sample shape as other      // Create a DataConstant with the same sample shape as other
223      initialise(temp_dataView, other.getFunctionSpace(), false);  //     initialise(temp_dataView, other.getFunctionSpace(), false);
224        DataConstant* t=new DataConstant(asNumArray,other.getFunctionSpace());
225    //     boost::shared_ptr<DataAbstract> sp(t);
226    //     m_data=sp;
227        m_data=DataAbstract_ptr(t);
228    }    }
229    m_protected=false;    m_protected=false;
230  }  }
# Line 208  Data::~Data() Line 234  Data::~Data()
234    
235  }  }
236    
237    
238    
239    void
240    Data::initialise(const boost::python::numeric::array& value,
241                     const FunctionSpace& what,
242                     bool expanded)
243    {
244      //
245      // Construct a Data object of the appropriate type.
246      // Construct the object first as there seems to be a bug which causes
247      // undefined behaviour if an exception is thrown during construction
248      // within the shared_ptr constructor.
249      if (expanded) {
250        DataAbstract* temp=new DataExpanded(value, what);
251    //     boost::shared_ptr<DataAbstract> temp_data(temp);
252    //     m_data=temp_data;
253        m_data=temp->getPtr();
254      } else {
255        DataAbstract* temp=new DataConstant(value, what);
256    //     boost::shared_ptr<DataAbstract> temp_data(temp);
257    //     m_data=temp_data;
258        m_data=temp->getPtr();
259      }
260    }
261    
262    
263    void
264    Data::initialise(const DataTypes::ValueType& value,
265             const DataTypes::ShapeType& shape,
266                     const FunctionSpace& what,
267                     bool expanded)
268    {
269      //
270      // Construct a Data object of the appropriate type.
271      // Construct the object first as there seems to be a bug which causes
272      // undefined behaviour if an exception is thrown during construction
273      // within the shared_ptr constructor.
274      if (expanded) {
275        DataAbstract* temp=new DataExpanded(what, shape, value);
276    //     boost::shared_ptr<DataAbstract> temp_data(temp);
277    //     m_data=temp_data;
278        m_data=temp->getPtr();
279      } else {
280        DataAbstract* temp=new DataConstant(what, shape, value);
281    //     boost::shared_ptr<DataAbstract> temp_data(temp);
282    //     m_data=temp_data;
283        m_data=temp->getPtr();
284      }
285    }
286    
287    
288    // void
289    // Data::CompareDebug(const Data& rd)
290    // {
291    //  using namespace std;
292    //  bool mismatch=false;
293    //  std::cout << "Comparing left and right" << endl;
294    //  const DataTagged* left=dynamic_cast<DataTagged*>(m_data.get());
295    //  const DataTagged* right=dynamic_cast<DataTagged*>(rd.m_data.get());
296    //  
297    //  if (left==0)
298    //  {
299    //      cout << "left arg is not a DataTagged\n";
300    //      return;
301    //  }
302    //  
303    //  if (right==0)
304    //  {
305    //      cout << "right arg is not a DataTagged\n";
306    //      return;
307    //  }
308    //  cout << "Num elements=" << left->getVector().size() << ":" << right->getVector().size() << std::endl;
309    //  cout << "Shapes ";
310    //  if (left->getShape()==right->getShape())
311    //  {
312    //      cout << "ok\n";
313    //  }
314    //  else
315    //  {
316    //      cout << "Problem: shapes do not match\n";
317    //      mismatch=true;
318    //  }
319    //  int lim=left->getVector().size();
320    //  if (right->getVector().size()) lim=right->getVector().size();
321    //  for (int i=0;i<lim;++i)
322    //  {
323    //      if (left->getVector()[i]!=right->getVector()[i])
324    //      {
325    //          cout << "[" << i << "] value mismatch " << left->getVector()[i] << ":" << right->getVector()[i] << endl;
326    //          mismatch=true;
327    //      }
328    //  }
329    //
330    //  // still need to check the tag map
331    //  // also need to watch what is happening to function spaces, are they copied or what?
332    //
333    //  const DataTagged::DataMapType& mapleft=left->getTagLookup();
334    //  const DataTagged::DataMapType& mapright=right->getTagLookup();
335    //
336    //  if (mapleft.size()!=mapright.size())
337    //  {
338    //      cout << "Maps are different sizes " << mapleft.size() << ":" << mapright.size() << endl;
339    //      mismatch=true;
340    //      cout << "Left map\n";
341    //      DataTagged::DataMapType::const_iterator i,j;
342    //      for (i=mapleft.begin();i!=mapleft.end();++i) {
343    //          cout << "(" << i->first << "=>" << i->second << ")\n";
344    //      }
345    //      cout << "Right map\n";
346    //      for (i=mapright.begin();i!=mapright.end();++i) {
347    //          cout << "(" << i->first << "=>" << i->second << ")\n";
348    //      }
349    //      cout << "End map\n";
350    //
351    //  }
352    //
353    //  DataTagged::DataMapType::const_iterator i,j;
354    //  for (i=mapleft.begin(),j=mapright.begin();i!=mapleft.end() && j!=mapright.end();++i,++j) {
355    //     if ((i->first!=j->first) || (i->second!=j->second))
356    //     {
357    //      cout << "(" << i->first << "=>" << i->second << ")";
358    //      cout << ":(" << j->first << "=>" << j->second << ") ";
359    //      mismatch=true;
360    //            }
361    //  }
362    //  if (mismatch)
363    //  {
364    //      cout << "#Mismatch\n";
365    //  }
366    // }
367    
368  escriptDataC  escriptDataC
369  Data::getDataC()  Data::getDataC()
370  {  {
# Line 227  Data::getDataC() const Line 384  Data::getDataC() const
384  const boost::python::tuple  const boost::python::tuple
385  Data::getShapeTuple() const  Data::getShapeTuple() const
386  {  {
387    const DataArrayView::ShapeType& shape=getDataPointShape();    const DataTypes::ShapeType& shape=getDataPointShape();
388    switch(getDataPointRank()) {    switch(getDataPointRank()) {
389       case 0:       case 0:
390          return make_tuple();          return make_tuple();
# Line 243  Data::getShapeTuple() const Line 400  Data::getShapeTuple() const
400          throw DataException("Error - illegal Data rank.");          throw DataException("Error - illegal Data rank.");
401    }    }
402  }  }
403    
404    
405    // The different name is needed because boost has trouble with overloaded functions.
406    // It can't work out what type the function is based soley on its name.
407    // There are ways to fix this involving creating function pointer variables for each form
408    // but there doesn't seem to be a need given that the methods have the same name from the python point of view
409    Data*
410    Data::copySelf()
411    {
412       DataAbstract* temp=m_data->deepCopy();
413       return new Data(temp);
414    }
415    
416  void  void
417  Data::copy(const Data& other)  Data::copy(const Data& other)
418  {  {
419    //    DataAbstract* temp=other.m_data->deepCopy();
420    // Perform a deep copy    DataAbstract_ptr p=temp->getPtr();
421    {    m_data=p;
     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.");  
422  }  }
423    
424    
425  void  void
426  Data::setToZero()  Data::setToZero()
427  {  {
428      if (isEmpty())
429      {
430         throw DataException("Error - Operations not permitted on instances of DataEmpty.");
431      }
432    {    {
433      DataExpanded* temp=dynamic_cast<DataExpanded*>(m_data.get());      DataExpanded* temp=dynamic_cast<DataExpanded*>(m_data.get());
434      if (temp!=0) {      if (temp!=0) {
# Line 323  Data::setToZero() Line 453  Data::setToZero()
453    throw DataException("Error - Data can not be set to zero.");    throw DataException("Error - Data can not be set to zero.");
454  }  }
455    
456    // void
457    // Data::copyWithMask(const Data& other,
458    //                    const Data& mask)
459    // {
460    //   if (other.isEmpty() || mask.isEmpty())
461    //   {
462    //  throw DataException("Error - copyWithMask not permitted using instances of DataEmpty.");
463    //   }
464    //   Data mask1;
465    //   Data mask2;
466    //   mask1 = mask.wherePositive();
467    //
468    //   mask2.copy(mask1);
469    //   mask1 *= other;
470    //
471    //   mask2 *= *this;
472    //   mask2 = *this - mask2;
473    //   *this = mask1 + mask2;
474    // }
475    
476  void  void
477  Data::copyWithMask(const Data& other,  Data::copyWithMask(const Data& other,
478                     const Data& mask)                     const Data& mask)
479  {  {
480    Data mask1;    // 1. Interpolate if required so all Datas use the same FS as this
481    Data mask2;    // 2. Tag or Expand so that all Data's are the same type
482      // 3. Iterate over the data vectors copying values where mask is >0
483    mask1 = mask.wherePositive();    if (other.isEmpty() || mask.isEmpty())
484    mask2.copy(mask1);    {
485        throw DataException("Error - copyWithMask not permitted using instances of DataEmpty.");
486      }
487      Data other2(other);
488      Data mask2(mask);
489      FunctionSpace myFS=getFunctionSpace();
490      FunctionSpace oFS=other2.getFunctionSpace();
491      FunctionSpace mFS=mask2.getFunctionSpace();
492      if (oFS!=myFS)
493      {
494         if (other2.probeInterpolation(myFS))
495         {
496        other2=other2.interpolate(myFS);
497         }
498         else
499         {
500        throw DataException("Error - copyWithMask: other FunctionSpace is not compatible with this one.");
501         }
502      }
503      if (mFS!=myFS)
504      {
505         if (mask2.probeInterpolation(myFS))
506         {
507        mask2=mask2.interpolate(myFS);
508         }
509         else
510         {
511        throw DataException("Error - copyWithMask: mask FunctionSpace is not compatible with this one.");
512         }
513      }
514                // Ensure that all args have the same type
515      if (this->isExpanded() || mask2.isExpanded() || other2.isExpanded())
516      {
517        this->expand();
518        other2.expand();
519        mask2.expand();
520      }
521      else if (this->isTagged() || mask2.isTagged() || other2.isTagged())
522      {
523        this->tag();
524        other2.tag();
525        mask2.tag();
526      }
527      else if (this->isConstant() && mask2.isConstant() && other2.isConstant())
528      {
529      }
530      else
531      {
532        throw DataException("Error - Unknown DataAbstract passed to copyWithMask.");
533      }
534      // Now we iterate over the elements
535      DataVector& self=m_data->getVector();
536      const DataVector& ovec=other2.m_data->getVector();
537      const DataVector& mvec=mask2.m_data->getVector();
538      if ((self.size()!=ovec.size()) || (self.size()!=mvec.size()))
539      {
540        throw DataException("Error - size mismatch in arguments to copyWithMask.");
541      }
542      size_t num_points=self.size();
543      long i;
544      #pragma omp parallel for private(i) schedule(static)
545      for (i=0;i<num_points;++i)
546      {
547        if (mvec[i]>0)
548        {
549           self[i]=ovec[i];
550        }
551      }
552    }
553    
   mask1 *= other;  
   mask2 *= *this;  
   mask2 = *this - mask2;  
554    
   *this = mask1 + mask2;  
 }  
555    
556  bool  bool
557  Data::isExpanded() const  Data::isExpanded() const
# Line 388  Data::expand() Line 601  Data::expand()
601    if (isConstant()) {    if (isConstant()) {
602      DataConstant* tempDataConst=dynamic_cast<DataConstant*>(m_data.get());      DataConstant* tempDataConst=dynamic_cast<DataConstant*>(m_data.get());
603      DataAbstract* temp=new DataExpanded(*tempDataConst);      DataAbstract* temp=new DataExpanded(*tempDataConst);
604      shared_ptr<DataAbstract> temp_data(temp);  //     shared_ptr<DataAbstract> temp_data(temp);
605      m_data=temp_data;  //     m_data=temp_data;
606        m_data=temp->getPtr();
607    } else if (isTagged()) {    } else if (isTagged()) {
608      DataTagged* tempDataTag=dynamic_cast<DataTagged*>(m_data.get());      DataTagged* tempDataTag=dynamic_cast<DataTagged*>(m_data.get());
609      DataAbstract* temp=new DataExpanded(*tempDataTag);      DataAbstract* temp=new DataExpanded(*tempDataTag);
610      shared_ptr<DataAbstract> temp_data(temp);  //     shared_ptr<DataAbstract> temp_data(temp);
611      m_data=temp_data;  //     m_data=temp_data;
612        m_data=temp->getPtr();
613    } else if (isExpanded()) {    } else if (isExpanded()) {
614      //      //
615      // do nothing      // do nothing
# Line 411  Data::tag() Line 626  Data::tag()
626    if (isConstant()) {    if (isConstant()) {
627      DataConstant* tempDataConst=dynamic_cast<DataConstant*>(m_data.get());      DataConstant* tempDataConst=dynamic_cast<DataConstant*>(m_data.get());
628      DataAbstract* temp=new DataTagged(*tempDataConst);      DataAbstract* temp=new DataTagged(*tempDataConst);
629      shared_ptr<DataAbstract> temp_data(temp);  //     shared_ptr<DataAbstract> temp_data(temp);
630      m_data=temp_data;  //     m_data=temp_data;
631        m_data=temp->getPtr();
632    } else if (isTagged()) {    } else if (isTagged()) {
633      // do nothing      // do nothing
634    } else if (isExpanded()) {    } else if (isExpanded()) {
# Line 480  Data::probeInterpolation(const FunctionS Line 696  Data::probeInterpolation(const FunctionS
696    if (getFunctionSpace()==functionspace) {    if (getFunctionSpace()==functionspace) {
697      return true;      return true;
698    } else {    } else {
699      const AbstractDomain& domain=getDomain();      const_Domain_ptr domain=getDomain();
700      if  (domain==functionspace.getDomain()) {      if  (*domain==*functionspace.getDomain()) {
701        return domain.probeInterpolationOnDomain(getFunctionSpace().getTypeCode(),functionspace.getTypeCode());        return domain->probeInterpolationOnDomain(getFunctionSpace().getTypeCode(),functionspace.getTypeCode());
702      } else {      } else {
703        return domain.probeInterpolationACross(getFunctionSpace().getTypeCode(),functionspace.getDomain(),functionspace.getTypeCode());        return domain->probeInterpolationACross(getFunctionSpace().getTypeCode(),*(functionspace.getDomain()),functionspace.getTypeCode());
704      }      }
705    }    }
706  }  }
# Line 492  Data::probeInterpolation(const FunctionS Line 708  Data::probeInterpolation(const FunctionS
708  Data  Data
709  Data::gradOn(const FunctionSpace& functionspace) const  Data::gradOn(const FunctionSpace& functionspace) const
710  {  {
711      if (isEmpty())
712      {
713        throw DataException("Error - operation not permitted on instances of DataEmpty.");
714      }
715    double blocktimer_start = blocktimer_time();    double blocktimer_start = blocktimer_time();
716    if (functionspace.getDomain()!=getDomain())    if (functionspace.getDomain()!=getDomain())
717      throw DataException("Error - gradient cannot be calculated on different domains.");      throw DataException("Error - gradient cannot be calculated on different domains.");
718    DataArrayView::ShapeType grad_shape=getPointDataView().getShape();    DataTypes::ShapeType grad_shape=getDataPointShape();
719    grad_shape.push_back(functionspace.getDim());    grad_shape.push_back(functionspace.getDim());
720    Data out(0.0,grad_shape,functionspace,true);    Data out(0.0,grad_shape,functionspace,true);
721    getDomain().setToGradient(out,*this);    getDomain()->setToGradient(out,*this);
722    blocktimer_increment("grad()", blocktimer_start);    blocktimer_increment("grad()", blocktimer_start);
723    return out;    return out;
724  }  }
# Line 506  Data::gradOn(const FunctionSpace& functi Line 726  Data::gradOn(const FunctionSpace& functi
726  Data  Data
727  Data::grad() const  Data::grad() const
728  {  {
729    return gradOn(escript::function(getDomain()));    if (isEmpty())
730      {
731        throw DataException("Error - operation not permitted on instances of DataEmpty.");
732      }
733      return gradOn(escript::function(*getDomain()));
734  }  }
735    
736  int  int
737  Data::getDataPointSize() const  Data::getDataPointSize() const
738  {  {
739    return getPointDataView().noValues();    return m_data->getNoValues();
740  }  }
741    
742  DataArrayView::ValueType::size_type  DataTypes::ValueType::size_type
743  Data::getLength() const  Data::getLength() const
744  {  {
745    return m_data->getLength();    return m_data->getLength();
746  }  }
747    
 const DataArrayView::ShapeType&  
 Data::getDataPointShape() const  
 {  
   return getPointDataView().getShape();  
 }  
   
   
   
748  const  const
749  boost::python::numeric::array  boost::python::numeric::array
750  Data:: getValueOfDataPoint(int dataPointNo)  Data:: getValueOfDataPoint(int dataPointNo)
# Line 538  Data:: getValueOfDataPoint(int dataPoint Line 754  Data:: getValueOfDataPoint(int dataPoint
754    //    //
755    // determine the rank and shape of each data point    // determine the rank and shape of each data point
756    int dataPointRank = getDataPointRank();    int dataPointRank = getDataPointRank();
757    DataArrayView::ShapeType dataPointShape = getDataPointShape();    const DataTypes::ShapeType& dataPointShape = getDataPointShape();
758    
759    //    //
760    // create the numeric array to be returned    // create the numeric array to be returned
# Line 548  Data:: getValueOfDataPoint(int dataPoint Line 764  Data:: getValueOfDataPoint(int dataPoint
764    // the shape of the returned numeric array will be the same    // the shape of the returned numeric array will be the same
765    // as that of the data point    // as that of the data point
766    int arrayRank = dataPointRank;    int arrayRank = dataPointRank;
767    DataArrayView::ShapeType arrayShape = dataPointShape;    const DataTypes::ShapeType& arrayShape = dataPointShape;
768    
769    //    //
770    // 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 800  Data:: getValueOfDataPoint(int dataPoint
800         }         }
801         // TODO: global error handling         // TODO: global error handling
802         // create a view of the data if it is stored locally         // create a view of the data if it is stored locally
803         DataArrayView dataPointView = getDataPoint(sampleNo, dataPointNoInSample);  //       DataArrayView dataPointView = getDataPoint(sampleNo, dataPointNoInSample);
804           DataTypes::ValueType::size_type offset=getDataOffset(sampleNo, dataPointNoInSample);
805    
806    
807         switch( dataPointRank ){         switch( dataPointRank ){
808              case 0 :              case 0 :
809                  numArray[0] = dataPointView();                  numArray[0] = getDataAtOffset(offset);
810                  break;                  break;
811              case 1 :              case 1 :
812                  for( i=0; i<dataPointShape[0]; i++ )                  for( i=0; i<dataPointShape[0]; i++ )
813                      numArray[i]=dataPointView(i);                      numArray[i]=getDataAtOffset(offset+DataTypes::getRelIndex(dataPointShape, i));
814                  break;                  break;
815              case 2 :              case 2 :
816                  for( i=0; i<dataPointShape[0]; i++ )                  for( i=0; i<dataPointShape[0]; i++ )
817                      for( j=0; j<dataPointShape[1]; j++)                      for( j=0; j<dataPointShape[1]; j++)
818                          numArray[make_tuple(i,j)]=dataPointView(i,j);                          numArray[make_tuple(i,j)]=getDataAtOffset(offset+DataTypes::getRelIndex(dataPointShape, i,j));
819                  break;                  break;
820              case 3 :              case 3 :
821                  for( i=0; i<dataPointShape[0]; i++ )                  for( i=0; i<dataPointShape[0]; i++ )
822                      for( j=0; j<dataPointShape[1]; j++ )                      for( j=0; j<dataPointShape[1]; j++ )
823                          for( k=0; k<dataPointShape[2]; k++)                          for( k=0; k<dataPointShape[2]; k++)
824                              numArray[make_tuple(i,j,k)]=dataPointView(i,j,k);                              numArray[make_tuple(i,j,k)]=getDataAtOffset(offset+DataTypes::getRelIndex(dataPointShape, i,j,k));
825                  break;                  break;
826              case 4 :              case 4 :
827                  for( i=0; i<dataPointShape[0]; i++ )                  for( i=0; i<dataPointShape[0]; i++ )
828                      for( j=0; j<dataPointShape[1]; j++ )                      for( j=0; j<dataPointShape[1]; j++ )
829                          for( k=0; k<dataPointShape[2]; k++ )                          for( k=0; k<dataPointShape[2]; k++ )
830                              for( l=0; l<dataPointShape[3]; l++)                              for( l=0; l<dataPointShape[3]; l++)
831                                  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));
832                  break;                  break;
833      }      }
834    }    }
# Line 619  Data:: getValueOfDataPoint(int dataPoint Line 837  Data:: getValueOfDataPoint(int dataPoint
837    return numArray;    return numArray;
838    
839  }  }
840    
841  void  void
842  Data::setValueOfDataPointToPyObject(int dataPointNo, const boost::python::object& py_object)  Data::setValueOfDataPointToPyObject(int dataPointNo, const boost::python::object& py_object)
843  {  {
844      // this will throw if the value cannot be represented      // this will throw if the value cannot be represented
845      boost::python::numeric::array num_array(py_object);      boost::python::numeric::array num_array(py_object);
846      setValueOfDataPointToArray(dataPointNo,num_array);      setValueOfDataPointToArray(dataPointNo,num_array);
   
   
847  }  }
848    
849  void  void
# Line 648  Data::setValueOfDataPointToArray(int dat Line 865  Data::setValueOfDataPointToArray(int dat
865    }    }
866    //    //
867    // make sure data is expanded:    // make sure data is expanded:
868      //
869    if (!isExpanded()) {    if (!isExpanded()) {
870      expand();      expand();
871    }    }
# Line 689  Data::getValueOfGlobalDataPoint(int proc Line 907  Data::getValueOfGlobalDataPoint(int proc
907    //    //
908    // determine the rank and shape of each data point    // determine the rank and shape of each data point
909    int dataPointRank = getDataPointRank();    int dataPointRank = getDataPointRank();
910    DataArrayView::ShapeType dataPointShape = getDataPointShape();    const DataTypes::ShapeType& dataPointShape = getDataPointShape();
911    
912    //    //
913    // create the numeric array to be returned    // create the numeric array to be returned
# Line 699  Data::getValueOfGlobalDataPoint(int proc Line 917  Data::getValueOfGlobalDataPoint(int proc
917    // the shape of the returned numeric array will be the same    // the shape of the returned numeric array will be the same
918    // as that of the data point    // as that of the data point
919    int arrayRank = dataPointRank;    int arrayRank = dataPointRank;
920    DataArrayView::ShapeType arrayShape = dataPointShape;    const DataTypes::ShapeType& arrayShape = dataPointShape;
921    
922    //    //
923    // 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 963  Data::getValueOfGlobalDataPoint(int proc
963                  }                  }
964                  // TODO: global error handling                  // TODO: global error handling
965          // create a view of the data if it is stored locally          // create a view of the data if it is stored locally
966          DataArrayView dataPointView = getDataPoint(sampleNo, dataPointNoInSample);          //DataArrayView dataPointView = getDataPoint(sampleNo, dataPointNoInSample);
967            DataTypes::ValueType::size_type offset=getDataOffset(sampleNo, dataPointNoInSample);
968    
969          // pack the data from the view into tmpData for MPI communication          // pack the data from the view into tmpData for MPI communication
970          pos=0;          pos=0;
971          switch( dataPointRank ){          switch( dataPointRank ){
972              case 0 :              case 0 :
973                  tmpData[0] = dataPointView();                  tmpData[0] = getDataAtOffset(offset);
974                  break;                  break;
975              case 1 :              case 1 :
976                  for( i=0; i<dataPointShape[0]; i++ )                  for( i=0; i<dataPointShape[0]; i++ )
977                      tmpData[i]=dataPointView(i);                      tmpData[i]=getDataAtOffset(offset+DataTypes::getRelIndex(dataPointShape, i));
978                  break;                  break;
979              case 2 :              case 2 :
980                  for( i=0; i<dataPointShape[0]; i++ )                  for( i=0; i<dataPointShape[0]; i++ )
981                      for( j=0; j<dataPointShape[1]; j++, pos++ )                      for( j=0; j<dataPointShape[1]; j++, pos++ )
982                          tmpData[pos]=dataPointView(i,j);                          tmpData[pos]=getDataAtOffset(offset+DataTypes::getRelIndex(dataPointShape, i,j));
983                  break;                  break;
984              case 3 :              case 3 :
985                  for( i=0; i<dataPointShape[0]; i++ )                  for( i=0; i<dataPointShape[0]; i++ )
986                      for( j=0; j<dataPointShape[1]; j++ )                      for( j=0; j<dataPointShape[1]; j++ )
987                          for( k=0; k<dataPointShape[2]; k++, pos++ )                          for( k=0; k<dataPointShape[2]; k++, pos++ )
988                              tmpData[pos]=dataPointView(i,j,k);                              tmpData[pos]=getDataAtOffset(offset+DataTypes::getRelIndex(dataPointShape, i,j,k));
989                  break;                  break;
990              case 4 :              case 4 :
991                  for( i=0; i<dataPointShape[0]; i++ )                  for( i=0; i<dataPointShape[0]; i++ )
992                      for( j=0; j<dataPointShape[1]; j++ )                      for( j=0; j<dataPointShape[1]; j++ )
993                          for( k=0; k<dataPointShape[2]; k++ )                          for( k=0; k<dataPointShape[2]; k++ )
994                              for( l=0; l<dataPointShape[3]; l++, pos++ )                              for( l=0; l<dataPointShape[3]; l++, pos++ )
995                                  tmpData[pos]=dataPointView(i,j,k,l);                                  tmpData[pos]=getDataAtOffset(offset+DataTypes::getRelIndex(dataPointShape, i,j,k,l));
996                  break;                  break;
997          }          }
998              }              }
# Line 825  Data::integrate() const Line 1044  Data::integrate() const
1044  {  {
1045    int index;    int index;
1046    int rank = getDataPointRank();    int rank = getDataPointRank();
1047    DataArrayView::ShapeType shape = getDataPointShape();    DataTypes::ShapeType shape = getDataPointShape();
1048    int dataPointSize = getDataPointSize();    int dataPointSize = getDataPointSize();
1049    
1050    //    //
# Line 833  Data::integrate() const Line 1052  Data::integrate() const
1052    vector<double> integrals(dataPointSize);    vector<double> integrals(dataPointSize);
1053    vector<double> integrals_local(dataPointSize);    vector<double> integrals_local(dataPointSize);
1054  #ifdef PASO_MPI  #ifdef PASO_MPI
1055    AbstractContinuousDomain::asAbstractContinuousDomain(getDomain()).setToIntegrals(integrals_local,*this);    AbstractContinuousDomain::asAbstractContinuousDomain(*getDomain()).setToIntegrals(integrals_local,*this);
1056    // Global sum: use an array instead of a vector because elements of array are guaranteed to be contiguous in memory    // Global sum: use an array instead of a vector because elements of array are guaranteed to be contiguous in memory
1057    double *tmp = new double[dataPointSize];    double *tmp = new double[dataPointSize];
1058    double *tmp_local = new double[dataPointSize];    double *tmp_local = new double[dataPointSize];
# Line 843  Data::integrate() const Line 1062  Data::integrate() const
1062    delete[] tmp;    delete[] tmp;
1063    delete[] tmp_local;    delete[] tmp_local;
1064  #else  #else
1065    AbstractContinuousDomain::asAbstractContinuousDomain(getDomain()).setToIntegrals(integrals,*this);    AbstractContinuousDomain::asAbstractContinuousDomain(*getDomain()).setToIntegrals(integrals,*this);
1066  #endif  #endif
1067    
1068    //    //
# Line 1052  Data::sqrt() const Line 1271  Data::sqrt() const
1271  double  double
1272  Data::Lsup() const  Data::Lsup() const
1273  {  {
1274    double localValue, globalValue;    double localValue;
1275    //    //
1276    // set the initial absolute maximum value to zero    // set the initial absolute maximum value to zero
1277    
1278    AbsMax abs_max_func;    AbsMax abs_max_func;
1279    localValue = algorithm(abs_max_func,0);    localValue = algorithm(abs_max_func,0);
1280  #ifdef PASO_MPI  #ifdef PASO_MPI
1281      double globalValue;
1282    MPI_Allreduce( &localValue, &globalValue, 1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD );    MPI_Allreduce( &localValue, &globalValue, 1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD );
1283    return globalValue;    return globalValue;
1284  #else  #else
# Line 1069  Data::Lsup() const Line 1289  Data::Lsup() const
1289  double  double
1290  Data::sup() const  Data::sup() const
1291  {  {
1292    double localValue, globalValue;    double localValue;
1293    //    //
1294    // set the initial maximum value to min possible double    // set the initial maximum value to min possible double
1295    FMax fmax_func;    FMax fmax_func;
1296    localValue = algorithm(fmax_func,numeric_limits<double>::max()*-1);    localValue = algorithm(fmax_func,numeric_limits<double>::max()*-1);
1297  #ifdef PASO_MPI  #ifdef PASO_MPI
1298      double globalValue;
1299    MPI_Allreduce( &localValue, &globalValue, 1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD );    MPI_Allreduce( &localValue, &globalValue, 1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD );
1300    return globalValue;    return globalValue;
1301  #else  #else
# Line 1085  Data::sup() const Line 1306  Data::sup() const
1306  double  double
1307  Data::inf() const  Data::inf() const
1308  {  {
1309    double localValue, globalValue;    double localValue;
1310    //    //
1311    // set the initial minimum value to max possible double    // set the initial minimum value to max possible double
1312    FMin fmin_func;    FMin fmin_func;
1313    localValue = algorithm(fmin_func,numeric_limits<double>::max());    localValue = algorithm(fmin_func,numeric_limits<double>::max());
1314  #ifdef PASO_MPI  #ifdef PASO_MPI
1315      double globalValue;
1316    MPI_Allreduce( &localValue, &globalValue, 1, MPI_DOUBLE, MPI_MIN, MPI_COMM_WORLD );    MPI_Allreduce( &localValue, &globalValue, 1, MPI_DOUBLE, MPI_MIN, MPI_COMM_WORLD );
1317    return globalValue;    return globalValue;
1318  #else  #else
# Line 1122  Data Line 1344  Data
1344  Data::swapaxes(const int axis0, const int axis1) const  Data::swapaxes(const int axis0, const int axis1) const
1345  {  {
1346       int axis0_tmp,axis1_tmp;       int axis0_tmp,axis1_tmp;
1347       DataArrayView::ShapeType s=getDataPointShape();       DataTypes::ShapeType s=getDataPointShape();
1348       DataArrayView::ShapeType ev_shape;       DataTypes::ShapeType ev_shape;
1349       // 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]
1350       // 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)
1351       int rank=getDataPointRank();       int rank=getDataPointRank();
# Line 1166  Data Line 1388  Data
1388  Data::symmetric() const  Data::symmetric() const
1389  {  {
1390       // check input       // check input
1391       DataArrayView::ShapeType s=getDataPointShape();       DataTypes::ShapeType s=getDataPointShape();
1392       if (getDataPointRank()==2) {       if (getDataPointRank()==2) {
1393          if(s[0] != s[1])          if(s[0] != s[1])
1394             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 1410  Data
1410  Data::nonsymmetric() const  Data::nonsymmetric() const
1411  {  {
1412       // check input       // check input
1413       DataArrayView::ShapeType s=getDataPointShape();       DataTypes::ShapeType s=getDataPointShape();
1414       if (getDataPointRank()==2) {       if (getDataPointRank()==2) {
1415          if(s[0] != s[1])          if(s[0] != s[1])
1416             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.");
1417          DataArrayView::ShapeType ev_shape;          DataTypes::ShapeType ev_shape;
1418          ev_shape.push_back(s[0]);          ev_shape.push_back(s[0]);
1419          ev_shape.push_back(s[1]);          ev_shape.push_back(s[1]);
1420          Data ev(0.,ev_shape,getFunctionSpace());          Data ev(0.,ev_shape,getFunctionSpace());
# Line 1203  Data::nonsymmetric() const Line 1425  Data::nonsymmetric() const
1425       else if (getDataPointRank()==4) {       else if (getDataPointRank()==4) {
1426          if(!(s[0] == s[2] && s[1] == s[3]))          if(!(s[0] == s[2] && s[1] == s[3]))
1427             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.");
1428          DataArrayView::ShapeType ev_shape;          DataTypes::ShapeType ev_shape;
1429          ev_shape.push_back(s[0]);          ev_shape.push_back(s[0]);
1430          ev_shape.push_back(s[1]);          ev_shape.push_back(s[1]);
1431          ev_shape.push_back(s[2]);          ev_shape.push_back(s[2]);
# Line 1221  Data::nonsymmetric() const Line 1443  Data::nonsymmetric() const
1443  Data  Data
1444  Data::trace(int axis_offset) const  Data::trace(int axis_offset) const
1445  {  {
1446       DataArrayView::ShapeType s=getDataPointShape();       DataTypes::ShapeType s=getDataPointShape();
1447       if (getDataPointRank()==2) {       if (getDataPointRank()==2) {
1448          DataArrayView::ShapeType ev_shape;          DataTypes::ShapeType ev_shape;
1449          Data ev(0.,ev_shape,getFunctionSpace());          Data ev(0.,ev_shape,getFunctionSpace());
1450          ev.typeMatchRight(*this);          ev.typeMatchRight(*this);
1451          m_data->trace(ev.m_data.get(), axis_offset);          m_data->trace(ev.m_data.get(), axis_offset);
1452          return ev;          return ev;
1453       }       }
1454       if (getDataPointRank()==3) {       if (getDataPointRank()==3) {
1455          DataArrayView::ShapeType ev_shape;          DataTypes::ShapeType ev_shape;
1456          if (axis_offset==0) {          if (axis_offset==0) {
1457            int s2=s[2];            int s2=s[2];
1458            ev_shape.push_back(s2);            ev_shape.push_back(s2);
# Line 1245  Data::trace(int axis_offset) const Line 1467  Data::trace(int axis_offset) const
1467          return ev;          return ev;
1468       }       }
1469       if (getDataPointRank()==4) {       if (getDataPointRank()==4) {
1470          DataArrayView::ShapeType ev_shape;          DataTypes::ShapeType ev_shape;
1471          if (axis_offset==0) {          if (axis_offset==0) {
1472            ev_shape.push_back(s[2]);            ev_shape.push_back(s[2]);
1473            ev_shape.push_back(s[3]);            ev_shape.push_back(s[3]);
# Line 1271  Data::trace(int axis_offset) const Line 1493  Data::trace(int axis_offset) const
1493  Data  Data
1494  Data::transpose(int axis_offset) const  Data::transpose(int axis_offset) const
1495  {  {
1496       DataArrayView::ShapeType s=getDataPointShape();       DataTypes::ShapeType s=getDataPointShape();
1497       DataArrayView::ShapeType ev_shape;       DataTypes::ShapeType ev_shape;
1498       // 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]
1499       // 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)
1500       int rank=getDataPointRank();       int rank=getDataPointRank();
# Line 1293  Data Line 1515  Data
1515  Data::eigenvalues() const  Data::eigenvalues() const
1516  {  {
1517       // check input       // check input
1518       DataArrayView::ShapeType s=getDataPointShape();       DataTypes::ShapeType s=getDataPointShape();
1519       if (getDataPointRank()!=2)       if (getDataPointRank()!=2)
1520          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.");
1521       if(s[0] != s[1])       if(s[0] != s[1])
1522          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.");
1523       // create return       // create return
1524       DataArrayView::ShapeType ev_shape(1,s[0]);       DataTypes::ShapeType ev_shape(1,s[0]);
1525       Data ev(0.,ev_shape,getFunctionSpace());       Data ev(0.,ev_shape,getFunctionSpace());
1526       ev.typeMatchRight(*this);       ev.typeMatchRight(*this);
1527       m_data->eigenvalues(ev.m_data.get());       m_data->eigenvalues(ev.m_data.get());
# Line 1309  Data::eigenvalues() const Line 1531  Data::eigenvalues() const
1531  const boost::python::tuple  const boost::python::tuple
1532  Data::eigenvalues_and_eigenvectors(const double tol) const  Data::eigenvalues_and_eigenvectors(const double tol) const
1533  {  {
1534       DataArrayView::ShapeType s=getDataPointShape();       DataTypes::ShapeType s=getDataPointShape();
1535       if (getDataPointRank()!=2)       if (getDataPointRank()!=2)
1536          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.");
1537       if(s[0] != s[1])       if(s[0] != s[1])
1538          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.");
1539       // create return       // create return
1540       DataArrayView::ShapeType ev_shape(1,s[0]);       DataTypes::ShapeType ev_shape(1,s[0]);
1541       Data ev(0.,ev_shape,getFunctionSpace());       Data ev(0.,ev_shape,getFunctionSpace());
1542       ev.typeMatchRight(*this);       ev.typeMatchRight(*this);
1543       DataArrayView::ShapeType V_shape(2,s[0]);       DataTypes::ShapeType V_shape(2,s[0]);
1544       Data V(0.,V_shape,getFunctionSpace());       Data V(0.,V_shape,getFunctionSpace());
1545       V.typeMatchRight(*this);       V.typeMatchRight(*this);
1546       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 1582  Data::calc_minGlobalDataPoint(int& ProcN
1582      #pragma omp for private(i,j) schedule(static)      #pragma omp for private(i,j) schedule(static)
1583      for (i=0; i<numSamples; i++) {      for (i=0; i<numSamples; i++) {
1584        for (j=0; j<numDPPSample; j++) {        for (j=0; j<numDPPSample; j++) {
1585          next=temp.getDataPoint(i,j)();          next=temp.getDataAtOffset(temp.getDataOffset(i,j));
1586          if (next<local_min) {          if (next<local_min) {
1587            local_min=next;            local_min=next;
1588            local_lowi=i;            local_lowi=i;
# Line 1378  Data::calc_minGlobalDataPoint(int& ProcN Line 1600  Data::calc_minGlobalDataPoint(int& ProcN
1600    
1601  #ifdef PASO_MPI  #ifdef PASO_MPI
1602      // determine the processor on which the minimum occurs      // determine the processor on which the minimum occurs
1603      next = temp.getDataPoint(lowi,lowj)();      next = temp.getDataPoint(lowi,lowj);
1604      int lowProc = 0;      int lowProc = 0;
1605      double *globalMins = new double[get_MPISize()+1];      double *globalMins = new double[get_MPISize()+1];
1606      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 1626  Data::calc_minGlobalDataPoint(int& ProcN
1626  void  void
1627  Data::saveDX(std::string fileName) const  Data::saveDX(std::string fileName) const
1628  {  {
1629      if (isEmpty())
1630      {
1631        throw DataException("Error - Operations not permitted on instances of DataEmpty.");
1632      }
1633    boost::python::dict args;    boost::python::dict args;
1634    args["data"]=boost::python::object(this);    args["data"]=boost::python::object(this);
1635    getDomain().saveDX(fileName,args);    getDomain()->saveDX(fileName,args);
1636    return;    return;
1637  }  }
1638    
1639  void  void
1640  Data::saveVTK(std::string fileName) const  Data::saveVTK(std::string fileName) const
1641  {  {
1642      if (isEmpty())
1643      {
1644        throw DataException("Error - Operations not permitted on instances of DataEmpty.");
1645      }
1646    boost::python::dict args;    boost::python::dict args;
1647    args["data"]=boost::python::object(this);    args["data"]=boost::python::object(this);
1648    getDomain().saveVTK(fileName,args);    getDomain()->saveVTK(fileName,args);
1649    return;    return;
1650  }  }
1651    
# Line 1663  escript::operator/(const boost::python:: Line 1893  escript::operator/(const boost::python::
1893  Data  Data
1894  Data::getItem(const boost::python::object& key) const  Data::getItem(const boost::python::object& key) const
1895  {  {
1896    const DataArrayView& view=getPointDataView();  //  const DataArrayView& view=getPointDataView();
1897    
1898    DataArrayView::RegionType slice_region=view.getSliceRegion(key);    DataTypes::RegionType slice_region=DataTypes::getSliceRegion(getDataPointShape(),key);
1899    
1900    if (slice_region.size()!=view.getRank()) {    if (slice_region.size()!=getDataPointRank()) {
1901      throw DataException("Error - slice size does not match Data rank.");      throw DataException("Error - slice size does not match Data rank.");
1902    }    }
1903    
# Line 1677  Data::getItem(const boost::python::objec Line 1907  Data::getItem(const boost::python::objec
1907  /* TODO */  /* TODO */
1908  /* global reduction */  /* global reduction */
1909  Data  Data
1910  Data::getSlice(const DataArrayView::RegionType& region) const  Data::getSlice(const DataTypes::RegionType& region) const
1911  {  {
1912    return Data(*this,region);    return Data(*this,region);
1913  }  }
# Line 1696  void Line 1926  void
1926  Data::setItemD(const boost::python::object& key,  Data::setItemD(const boost::python::object& key,
1927                 const Data& value)                 const Data& value)
1928  {  {
1929    const DataArrayView& view=getPointDataView();  //  const DataArrayView& view=getPointDataView();
1930    
1931    DataArrayView::RegionType slice_region=view.getSliceRegion(key);    DataTypes::RegionType slice_region=DataTypes::getSliceRegion(getDataPointShape(),key);
1932    if (slice_region.size()!=view.getRank()) {    if (slice_region.size()!=getDataPointRank()) {
1933      throw DataException("Error - slice size does not match Data rank.");      throw DataException("Error - slice size does not match Data rank.");
1934    }    }
1935    if (getFunctionSpace()!=value.getFunctionSpace()) {    if (getFunctionSpace()!=value.getFunctionSpace()) {
# Line 1711  Data::setItemD(const boost::python::obje Line 1941  Data::setItemD(const boost::python::obje
1941    
1942  void  void
1943  Data::setSlice(const Data& value,  Data::setSlice(const Data& value,
1944                 const DataArrayView::RegionType& region)                 const DataTypes::RegionType& region)
1945  {  {
1946    if (isProtected()) {    if (isProtected()) {
1947          throw DataException("Error - attempt to update protected Data object.");          throw DataException("Error - attempt to update protected Data object.");
# Line 1754  void Line 1984  void
1984  Data::setTaggedValueByName(std::string name,  Data::setTaggedValueByName(std::string name,
1985                             const boost::python::object& value)                             const boost::python::object& value)
1986  {  {
1987       if (getFunctionSpace().getDomain().isValidTagName(name)) {       if (getFunctionSpace().getDomain()->isValidTagName(name)) {
1988          int tagKey=getFunctionSpace().getDomain().getTag(name);          int tagKey=getFunctionSpace().getDomain()->getTag(name);
1989          setTaggedValue(tagKey,value);          setTaggedValue(tagKey,value);
1990       }       }
1991  }  }
# Line 1774  Data::setTaggedValue(int tagKey, Line 2004  Data::setTaggedValue(int tagKey,
2004    
2005    
2006    // extract the shape of the numarray    // extract the shape of the numarray
2007    DataArrayView::ShapeType tempShape;    DataTypes::ShapeType tempShape;
2008    for (int i=0; i < asNumArray.getrank(); i++) {    for (int i=0; i < asNumArray.getrank(); i++) {
2009      tempShape.push_back(extract<int>(asNumArray.getshape()[i]));      tempShape.push_back(extract<int>(asNumArray.getshape()[i]));
2010    }    }
2011    
2012    // get the space for the data vector    // get the space for the data vector
2013    int len = DataArrayView::noValues(tempShape);  //   int len = DataTypes::noValues(tempShape);
2014    DataVector temp_data(len, 0.0, len);  //   DataVector temp_data(len, 0.0, len);
2015    DataArrayView temp_dataView(temp_data, tempShape);  //   DataArrayView temp_dataView(temp_data, tempShape);
2016    temp_dataView.copy(asNumArray);  //   temp_dataView.copy(asNumArray);
2017    
2018      DataVector temp_data2;
2019      temp_data2.copyFromNumArray(asNumArray);
2020    
2021    //    //
2022    // Call DataAbstract::setTaggedValue    // Call DataAbstract::setTaggedValue
2023    m_data->setTaggedValue(tagKey,temp_dataView);    //m_data->setTaggedValue(tagKey,temp_dataView);
2024    
2025        m_data->setTaggedValue(tagKey,tempShape, temp_data2);
2026  }  }
2027    
2028    
2029  void  void
2030  Data::setTaggedValueFromCPP(int tagKey,  Data::setTaggedValueFromCPP(int tagKey,
2031                              const DataArrayView& value)                  const DataTypes::ShapeType& pointshape,
2032                                const DataTypes::ValueType& value,
2033                    int dataOffset)
2034  {  {
2035    if (isProtected()) {    if (isProtected()) {
2036          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 2041  Data::setTaggedValueFromCPP(int tagKey,
2041    
2042    //    //
2043    // Call DataAbstract::setTaggedValue    // Call DataAbstract::setTaggedValue
2044    m_data->setTaggedValue(tagKey,value);    m_data->setTaggedValue(tagKey,pointshape, value, dataOffset);
2045  }  }
2046    
2047  int  int
2048  Data::getTagNumber(int dpno)  Data::getTagNumber(int dpno)
2049  {  {
2050    return getFunctionSpace().getTagFromSampleNo(dpno);    if (isEmpty())
2051  }    {
2052        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");  
2053    }    }
2054      return getFunctionSpace().getTagFromDataPointNo(dpno);
2055  }  }
2056    
 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;  
 }  
2057    
2058  ostream& escript::operator<<(ostream& o, const Data& data)  ostream& escript::operator<<(ostream& o, const Data& data)
2059  {  {
# Line 2183  escript::C_GeneralTensorProduct(Data& ar Line 2091  escript::C_GeneralTensorProduct(Data& ar
2091    // Get rank and shape of inputs    // Get rank and shape of inputs
2092    int rank0 = arg_0_Z.getDataPointRank();    int rank0 = arg_0_Z.getDataPointRank();
2093    int rank1 = arg_1_Z.getDataPointRank();    int rank1 = arg_1_Z.getDataPointRank();
2094    DataArrayView::ShapeType shape0 = arg_0_Z.getDataPointShape();    const DataTypes::ShapeType& shape0 = arg_0_Z.getDataPointShape();
2095    DataArrayView::ShapeType shape1 = arg_1_Z.getDataPointShape();    const DataTypes::ShapeType& shape1 = arg_1_Z.getDataPointShape();
2096    
2097    // Prepare for the loops of the product and verify compatibility of shapes    // Prepare for the loops of the product and verify compatibility of shapes
2098    int start0=0, start1=0;    int start0=0, start1=0;
# Line 2193  escript::C_GeneralTensorProduct(Data& ar Line 2101  escript::C_GeneralTensorProduct(Data& ar
2101    else if (transpose == 2)  { start1 = rank1-axis_offset; }    else if (transpose == 2)  { start1 = rank1-axis_offset; }
2102    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"); }
2103    
2104    
2105    // Adjust the shapes for transpose    // Adjust the shapes for transpose
2106    DataArrayView::ShapeType tmpShape0;    DataTypes::ShapeType tmpShape0(rank0);    // pre-sizing the vectors rather
2107    DataArrayView::ShapeType tmpShape1;    DataTypes::ShapeType tmpShape1(rank1);    // than using push_back
2108    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]; }
2109    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]; }
2110    
2111  #if 0  #if 0
2112    // For debugging: show shape after transpose    // For debugging: show shape after transpose
# Line 2228  escript::C_GeneralTensorProduct(Data& ar Line 2137  escript::C_GeneralTensorProduct(Data& ar
2137      SR *= tmpShape1[i];      SR *= tmpShape1[i];
2138    }    }
2139    
2140    // Define the shape of the output    // Define the shape of the output (rank of shape is the sum of the loop ranges below)
2141    DataArrayView::ShapeType shape2;    DataTypes::ShapeType shape2(rank0+rank1-2*axis_offset);  
2142    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
2143    for (int i=axis_offset; i<rank1; i++)   { shape2.push_back(tmpShape1[i]); } // Last part of arg_1_Z       int out_index=0;
2144         for (int i=0; i<rank0-axis_offset; i++, ++out_index) { shape2[out_index]=tmpShape0[i]; } // First part of arg_0_Z
2145         for (int i=axis_offset; i<rank1; i++, ++out_index)   { shape2[out_index]=tmpShape1[i]; } // Last part of arg_1_Z
2146      }
2147    
2148    // Declare output Data object    // Declare output Data object
2149    Data res;    Data res;
2150    
2151    if      (arg_0_Z.isConstant()   && arg_1_Z.isConstant()) {    if      (arg_0_Z.isConstant()   && arg_1_Z.isConstant()) {
2152      res = Data(0.0, shape2, arg_1_Z.getFunctionSpace());    // DataConstant output      res = Data(0.0, shape2, arg_1_Z.getFunctionSpace());    // DataConstant output
2153      double *ptr_0 = &((arg_0_Z.getPointDataView().getData())[0]);      double *ptr_0 = &(arg_0_Z.getDataAtOffset(0));
2154      double *ptr_1 = &((arg_1_Z.getPointDataView().getData())[0]);      double *ptr_1 = &(arg_1_Z.getDataAtOffset(0));
2155      double *ptr_2 = &((res.getPointDataView().getData())[0]);      double *ptr_2 = &(res.getDataAtOffset(0));
2156      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);
2157    }    }
2158    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 2173  escript::C_GeneralTensorProduct(Data& ar
2173    
2174      // Prepare offset into DataConstant      // Prepare offset into DataConstant
2175      int offset_0 = tmp_0->getPointOffset(0,0);      int offset_0 = tmp_0->getPointOffset(0,0);
2176      double *ptr_0 = &((arg_0_Z.getPointDataView().getData())[offset_0]);      double *ptr_0 = &(arg_0_Z.getDataAtOffset(offset_0));
2177      // Get the views      // Get the views
2178      DataArrayView view_1 = tmp_1->getDefaultValue();  //     DataArrayView view_1 = tmp_1->getDefaultValue();
2179      DataArrayView view_2 = tmp_2->getDefaultValue();  //     DataArrayView view_2 = tmp_2->getDefaultValue();
2180      // Get the pointers to the actual data  //     // Get the pointers to the actual data
2181      double *ptr_1 = &((view_1.getData())[0]);  //     double *ptr_1 = &((view_1.getData())[0]);
2182      double *ptr_2 = &((view_2.getData())[0]);  //     double *ptr_2 = &((view_2.getData())[0]);
2183    
2184        double *ptr_1 = &(tmp_1->getDefaultValue(0));
2185        double *ptr_2 = &(tmp_2->getDefaultValue(0));
2186    
2187    
2188      // Compute an MVP for the default      // Compute an MVP for the default
2189      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);
2190      // Compute an MVP for each tag      // Compute an MVP for each tag
2191      const DataTagged::DataMapType& lookup_1=tmp_1->getTagLookup();      const DataTagged::DataMapType& lookup_1=tmp_1->getTagLookup();
2192      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
2193      for (i=lookup_1.begin();i!=lookup_1.end();i++) {      for (i=lookup_1.begin();i!=lookup_1.end();i++) {
2194        tmp_2->addTaggedValue(i->first,tmp_2->getDefaultValue());        tmp_2->addTag(i->first);
2195        DataArrayView view_1 = tmp_1->getDataPointByTag(i->first);  //       DataArrayView view_1 = tmp_1->getDataPointByTag(i->first);
2196        DataArrayView view_2 = tmp_2->getDataPointByTag(i->first);  //       DataArrayView view_2 = tmp_2->getDataPointByTag(i->first);
2197        double *ptr_1 = &view_1.getData(0);  //       double *ptr_1 = &view_1.getData(0);
2198        double *ptr_2 = &view_2.getData(0);  //       double *ptr_2 = &view_2.getData(0);
2199    
2200          double *ptr_1 = &(tmp_1->getDataByTag(i->first,0));
2201          double *ptr_2 = &(tmp_2->getDataByTag(i->first,0));
2202        
2203        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);
2204      }      }
2205    
# Line 2301  escript::C_GeneralTensorProduct(Data& ar Line 2222  escript::C_GeneralTensorProduct(Data& ar
2222        for (dataPointNo_1 = 0; dataPointNo_1 < numDataPointsPerSample_1; dataPointNo_1++) {        for (dataPointNo_1 = 0; dataPointNo_1 < numDataPointsPerSample_1; dataPointNo_1++) {
2223          int offset_1 = tmp_1->getPointOffset(sampleNo_1,dataPointNo_1);          int offset_1 = tmp_1->getPointOffset(sampleNo_1,dataPointNo_1);
2224          int offset_2 = tmp_2->getPointOffset(sampleNo_1,dataPointNo_1);          int offset_2 = tmp_2->getPointOffset(sampleNo_1,dataPointNo_1);
2225          double *ptr_0 = &((arg_0_Z.getPointDataView().getData())[offset_0]);          double *ptr_0 = &(arg_0_Z.getDataAtOffset(offset_0));
2226          double *ptr_1 = &((arg_1_Z.getPointDataView().getData())[offset_1]);          double *ptr_1 = &(arg_1_Z.getDataAtOffset(offset_1));
2227          double *ptr_2 = &((res.getPointDataView().getData())[offset_2]);          double *ptr_2 = &(res.getDataAtOffset(offset_2));
2228          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);
2229        }        }
2230      }      }
# Line 2327  escript::C_GeneralTensorProduct(Data& ar Line 2248  escript::C_GeneralTensorProduct(Data& ar
2248    
2249      // Prepare offset into DataConstant      // Prepare offset into DataConstant
2250      int offset_1 = tmp_1->getPointOffset(0,0);      int offset_1 = tmp_1->getPointOffset(0,0);
2251      double *ptr_1 = &((arg_1_Z.getPointDataView().getData())[offset_1]);      double *ptr_1 = &(arg_1_Z.getDataAtOffset(offset_1));
2252      // Get the views      // Get the views
2253      DataArrayView view_0 = tmp_0->getDefaultValue();  //     DataArrayView view_0 = tmp_0->getDefaultValue();
2254      DataArrayView view_2 = tmp_2->getDefaultValue();  //     DataArrayView view_2 = tmp_2->getDefaultValue();
2255      // Get the pointers to the actual data  //     // Get the pointers to the actual data
2256      double *ptr_0 = &((view_0.getData())[0]);  //     double *ptr_0 = &((view_0.getData())[0]);
2257      double *ptr_2 = &((view_2.getData())[0]);  //     double *ptr_2 = &((view_2.getData())[0]);
2258    
2259        double *ptr_0 = &(tmp_0->getDefaultValue(0));
2260        double *ptr_2 = &(tmp_2->getDefaultValue(0));
2261    
2262      // Compute an MVP for the default      // Compute an MVP for the default
2263      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);
2264      // Compute an MVP for each tag      // Compute an MVP for each tag
2265      const DataTagged::DataMapType& lookup_0=tmp_0->getTagLookup();      const DataTagged::DataMapType& lookup_0=tmp_0->getTagLookup();
2266      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
2267      for (i=lookup_0.begin();i!=lookup_0.end();i++) {      for (i=lookup_0.begin();i!=lookup_0.end();i++) {
2268        tmp_2->addTaggedValue(i->first,tmp_2->getDefaultValue());  //      tmp_2->addTaggedValue(i->first,tmp_2->getDefaultValue());
2269        DataArrayView view_0 = tmp_0->getDataPointByTag(i->first);  //       DataArrayView view_0 = tmp_0->getDataPointByTag(i->first);
2270        DataArrayView view_2 = tmp_2->getDataPointByTag(i->first);  //       DataArrayView view_2 = tmp_2->getDataPointByTag(i->first);
2271        double *ptr_0 = &view_0.getData(0);  //       double *ptr_0 = &view_0.getData(0);
2272        double *ptr_2 = &view_2.getData(0);  //       double *ptr_2 = &view_2.getData(0);
2273    
2274          tmp_2->addTag(i->first);
2275          double *ptr_0 = &(tmp_0->getDataByTag(i->first,0));
2276          double *ptr_2 = &(tmp_2->getDataByTag(i->first,0));
2277        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);
2278      }      }
2279    
# Line 2365  escript::C_GeneralTensorProduct(Data& ar Line 2294  escript::C_GeneralTensorProduct(Data& ar
2294      DataTagged* tmp_2=dynamic_cast<DataTagged*>(res.borrowData());      DataTagged* tmp_2=dynamic_cast<DataTagged*>(res.borrowData());
2295      if (tmp_2==0) { throw DataException("GTP Programming error - casting to DataTagged."); }      if (tmp_2==0) { throw DataException("GTP Programming error - casting to DataTagged."); }
2296    
2297      // Get the views  //     // Get the views
2298      DataArrayView view_0 = tmp_0->getDefaultValue();  //     DataArrayView view_0 = tmp_0->getDefaultValue();
2299      DataArrayView view_1 = tmp_1->getDefaultValue();  //     DataArrayView view_1 = tmp_1->getDefaultValue();
2300      DataArrayView view_2 = tmp_2->getDefaultValue();  //     DataArrayView view_2 = tmp_2->getDefaultValue();
2301      // Get the pointers to the actual data  //     // Get the pointers to the actual data
2302      double *ptr_0 = &((view_0.getData())[0]);  //     double *ptr_0 = &((view_0.getData())[0]);
2303      double *ptr_1 = &((view_1.getData())[0]);  //     double *ptr_1 = &((view_1.getData())[0]);
2304      double *ptr_2 = &((view_2.getData())[0]);  //     double *ptr_2 = &((view_2.getData())[0]);
2305    
2306        double *ptr_0 = &(tmp_0->getDefaultValue(0));
2307        double *ptr_1 = &(tmp_1->getDefaultValue(0));
2308        double *ptr_2 = &(tmp_2->getDefaultValue(0));
2309    
2310    
2311      // Compute an MVP for the default      // Compute an MVP for the default
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      // Merge the tags      // Merge the tags
# Line 2380  escript::C_GeneralTensorProduct(Data& ar Line 2315  escript::C_GeneralTensorProduct(Data& ar
2315      const DataTagged::DataMapType& lookup_0=tmp_0->getTagLookup();      const DataTagged::DataMapType& lookup_0=tmp_0->getTagLookup();
2316      const DataTagged::DataMapType& lookup_1=tmp_1->getTagLookup();      const DataTagged::DataMapType& lookup_1=tmp_1->getTagLookup();
2317      for (i=lookup_0.begin();i!=lookup_0.end();i++) {      for (i=lookup_0.begin();i!=lookup_0.end();i++) {
2318        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
2319      }      }
2320      for (i=lookup_1.begin();i!=lookup_1.end();i++) {      for (i=lookup_1.begin();i!=lookup_1.end();i++) {
2321        tmp_2->addTaggedValue(i->first,tmp_2->getDefaultValue());        tmp_2->addTag(i->first);
2322      }      }
2323      // Compute an MVP for each tag      // Compute an MVP for each tag
2324      const DataTagged::DataMapType& lookup_2=tmp_2->getTagLookup();      const DataTagged::DataMapType& lookup_2=tmp_2->getTagLookup();
2325      for (i=lookup_2.begin();i!=lookup_2.end();i++) {      for (i=lookup_2.begin();i!=lookup_2.end();i++) {
2326        DataArrayView view_0 = tmp_0->getDataPointByTag(i->first);  //       DataArrayView view_0 = tmp_0->getDataPointByTag(i->first);
2327        DataArrayView view_1 = tmp_1->getDataPointByTag(i->first);  //       DataArrayView view_1 = tmp_1->getDataPointByTag(i->first);
2328        DataArrayView view_2 = tmp_2->getDataPointByTag(i->first);  //       DataArrayView view_2 = tmp_2->getDataPointByTag(i->first);
2329        double *ptr_0 = &view_0.getData(0);  //       double *ptr_0 = &view_0.getData(0);
2330        double *ptr_1 = &view_1.getData(0);  //       double *ptr_1 = &view_1.getData(0);
2331        double *ptr_2 = &view_2.getData(0);  //       double *ptr_2 = &view_2.getData(0);
2332    
2333          double *ptr_0 = &(tmp_0->getDataByTag(i->first,0));
2334          double *ptr_1 = &(tmp_1->getDataByTag(i->first,0));
2335          double *ptr_2 = &(tmp_2->getDataByTag(i->first,0));
2336    
2337        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);
2338      }      }
2339    
# Line 2414  escript::C_GeneralTensorProduct(Data& ar Line 2354  escript::C_GeneralTensorProduct(Data& ar
2354      #pragma omp parallel for private(sampleNo_0,dataPointNo_0) schedule(static)      #pragma omp parallel for private(sampleNo_0,dataPointNo_0) schedule(static)
2355      for (sampleNo_0 = 0; sampleNo_0 < numSamples_0; sampleNo_0++) {      for (sampleNo_0 = 0; sampleNo_0 < numSamples_0; sampleNo_0++) {
2356        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
2357        double *ptr_0 = &((arg_0_Z.getPointDataView().getData())[offset_0]);        double *ptr_0 = &(arg_0_Z.getDataAtOffset(offset_0));
2358        for (dataPointNo_0 = 0; dataPointNo_0 < numDataPointsPerSample_0; dataPointNo_0++) {        for (dataPointNo_0 = 0; dataPointNo_0 < numDataPointsPerSample_0; dataPointNo_0++) {
2359          int offset_1 = tmp_1->getPointOffset(sampleNo_0,dataPointNo_0);          int offset_1 = tmp_1->getPointOffset(sampleNo_0,dataPointNo_0);
2360          int offset_2 = tmp_2->getPointOffset(sampleNo_0,dataPointNo_0);          int offset_2 = tmp_2->getPointOffset(sampleNo_0,dataPointNo_0);
2361          double *ptr_1 = &((arg_1_Z.getPointDataView().getData())[offset_1]);          double *ptr_1 = &(arg_1_Z.getDataAtOffset(offset_1));
2362          double *ptr_2 = &((res.getPointDataView().getData())[offset_2]);          double *ptr_2 = &(res.getDataAtOffset(offset_2));
2363          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);
2364        }        }
2365      }      }
# Line 2443  escript::C_GeneralTensorProduct(Data& ar Line 2383  escript::C_GeneralTensorProduct(Data& ar
2383        for (dataPointNo_0 = 0; dataPointNo_0 < numDataPointsPerSample_0; dataPointNo_0++) {        for (dataPointNo_0 = 0; dataPointNo_0 < numDataPointsPerSample_0; dataPointNo_0++) {
2384          int offset_0 = tmp_0->getPointOffset(sampleNo_0,dataPointNo_0);          int offset_0 = tmp_0->getPointOffset(sampleNo_0,dataPointNo_0);
2385          int offset_2 = tmp_2->getPointOffset(sampleNo_0,dataPointNo_0);          int offset_2 = tmp_2->getPointOffset(sampleNo_0,dataPointNo_0);
2386          double *ptr_0 = &((arg_0_Z.getPointDataView().getData())[offset_0]);          double *ptr_0 = &(arg_0_Z.getDataAtOffset(offset_0));
2387          double *ptr_1 = &((arg_1_Z.getPointDataView().getData())[offset_1]);          double *ptr_1 = &(arg_1_Z.getDataAtOffset(offset_1));
2388          double *ptr_2 = &((res.getPointDataView().getData())[offset_2]);          double *ptr_2 = &(res.getDataAtOffset(offset_2));
2389          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);
2390        }        }
2391      }      }
# Line 2468  escript::C_GeneralTensorProduct(Data& ar Line 2408  escript::C_GeneralTensorProduct(Data& ar
2408      #pragma omp parallel for private(sampleNo_0,dataPointNo_0) schedule(static)      #pragma omp parallel for private(sampleNo_0,dataPointNo_0) schedule(static)
2409      for (sampleNo_0 = 0; sampleNo_0 < numSamples_0; sampleNo_0++) {      for (sampleNo_0 = 0; sampleNo_0 < numSamples_0; sampleNo_0++) {
2410        int offset_1 = tmp_1->getPointOffset(sampleNo_0,0);        int offset_1 = tmp_1->getPointOffset(sampleNo_0,0);
2411        double *ptr_1 = &((arg_1_Z.getPointDataView().getData())[offset_1]);        double *ptr_1 = &(arg_1_Z.getDataAtOffset(offset_1));
2412        for (dataPointNo_0 = 0; dataPointNo_0 < numDataPointsPerSample_0; dataPointNo_0++) {        for (dataPointNo_0 = 0; dataPointNo_0 < numDataPointsPerSample_0; dataPointNo_0++) {
2413          int offset_0 = tmp_0->getPointOffset(sampleNo_0,dataPointNo_0);          int offset_0 = tmp_0->getPointOffset(sampleNo_0,dataPointNo_0);
2414          int offset_2 = tmp_2->getPointOffset(sampleNo_0,dataPointNo_0);          int offset_2 = tmp_2->getPointOffset(sampleNo_0,dataPointNo_0);
2415          double *ptr_0 = &((arg_0_Z.getPointDataView().getData())[offset_0]);          double *ptr_0 = &(arg_0_Z.getDataAtOffset(offset_0));
2416          double *ptr_2 = &((res.getPointDataView().getData())[offset_2]);          double *ptr_2 = &(res.getDataAtOffset(offset_2));
2417          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);
2418        }        }
2419      }      }
# Line 2498  escript::C_GeneralTensorProduct(Data& ar Line 2438  escript::C_GeneralTensorProduct(Data& ar
2438          int offset_0 = tmp_0->getPointOffset(sampleNo_0,dataPointNo_0);          int offset_0 = tmp_0->getPointOffset(sampleNo_0,dataPointNo_0);
2439          int offset_1 = tmp_1->getPointOffset(sampleNo_0,dataPointNo_0);          int offset_1 = tmp_1->getPointOffset(sampleNo_0,dataPointNo_0);
2440          int offset_2 = tmp_2->getPointOffset(sampleNo_0,dataPointNo_0);          int offset_2 = tmp_2->getPointOffset(sampleNo_0,dataPointNo_0);
2441          double *ptr_0 = &((arg_0_Z.getPointDataView().getData())[offset_0]);          double *ptr_0 = &(arg_0_Z.getDataAtOffset(offset_0));
2442          double *ptr_1 = &((arg_1_Z.getPointDataView().getData())[offset_1]);          double *ptr_1 = &(arg_1_Z.getDataAtOffset(offset_1));
2443          double *ptr_2 = &((res.getPointDataView().getData())[offset_2]);          double *ptr_2 = &(res.getDataAtOffset(offset_2));
2444          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);
2445        }        }
2446      }      }
# Line 2519  Data::borrowData() const Line 2459  Data::borrowData() const
2459    return m_data.get();    return m_data.get();
2460  }  }
2461    
2462    
2463    std::string
2464    Data::toString() const
2465    {
2466        static const DataTypes::ValueType::size_type TOO_MANY_POINTS=8000;
2467        if (getNumDataPoints()*getDataPointSize()>TOO_MANY_POINTS)
2468        {
2469        stringstream temp;
2470        temp << "Summary: inf="<< inf() << " sup=" << sup() << " data points=" << getNumDataPoints();
2471        return  temp.str();
2472        }
2473        return m_data->toString();
2474    }
2475    
2476    
2477    
2478    DataTypes::ValueType::const_reference
2479    Data::getDataAtOffset(DataTypes::ValueType::size_type i) const
2480    {
2481        return m_data->getDataAtOffset(i);
2482    }
2483    
2484    
2485    DataTypes::ValueType::reference
2486    Data::getDataAtOffset(DataTypes::ValueType::size_type i)
2487    {
2488        return m_data->getDataAtOffset(i);
2489    }
2490    
2491    DataTypes::ValueType::const_reference
2492    Data::getDataPoint(int sampleNo, int dataPointNo) const
2493    {
2494        return m_data->getDataAtOffset(m_data->getPointOffset(sampleNo, dataPointNo));
2495    }
2496    
2497    
2498    DataTypes::ValueType::reference
2499    Data::getDataPoint(int sampleNo, int dataPointNo)
2500    {
2501        return m_data->getDataAtOffset(m_data->getPointOffset(sampleNo, dataPointNo));
2502    }
2503    
2504    
2505  /* Member functions specific to the MPI implementation */  /* Member functions specific to the MPI implementation */
2506    
2507  void  void
# Line 2551  Data::dump(const std::string fileName) c Line 2534  Data::dump(const std::string fileName) c
2534  int  int
2535  Data::get_MPISize() const  Data::get_MPISize() const
2536  {  {
2537      int error, size;      int size;
2538  #ifdef PASO_MPI  #ifdef PASO_MPI
2539        int error;
2540      error = MPI_Comm_size( get_MPIComm(), &size );      error = MPI_Comm_size( get_MPIComm(), &size );
2541  #else  #else
2542      size = 1;      size = 1;
# Line 2563  Data::get_MPISize() const Line 2547  Data::get_MPISize() const
2547  int  int
2548  Data::get_MPIRank() const  Data::get_MPIRank() const
2549  {  {
2550      int error, rank;      int rank;
2551  #ifdef PASO_MPI  #ifdef PASO_MPI
2552        int error;
2553      error = MPI_Comm_rank( get_MPIComm(), &rank );      error = MPI_Comm_rank( get_MPIComm(), &rank );
2554  #else  #else
2555      rank = 0;      rank = 0;
# Line 2582  Data::get_MPIComm() const Line 2567  Data::get_MPIComm() const
2567  #endif  #endif
2568  }  }
2569    
2570    

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

  ViewVC Help
Powered by ViewVC 1.1.26