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

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

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

revision 1487 by gross, Thu Apr 10 05:28:01 2008 UTC revision 2271 by jfenwick, Mon Feb 16 05:08:29 2009 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 "DataAbstract.h"  #include "DataAbstract.h"
16  #include "DataException.h"  #include "DataException.h"
17    #include "DataLazy.h"
18    
19    #include "Data.h"       // So we can update the shared status when things change
20    
21  using namespace std;  using namespace std;
22    
23  namespace escript {  namespace escript {
24    
25  DataAbstract::DataAbstract(const FunctionSpace& what):  DataAbstract_ptr DataAbstract::getPtr()
     m_noDataPointsPerSample(what.getNumDPPSample()),  
     m_noSamples(what.getNumSamples()),  
     m_functionSpace(what)  
26  {  {
27      if (_internal_weak_this.expired())
28      {
29        return DataAbstract_ptr(this);  
30      }
31      else
32      {
33        return shared_from_this();
34      }
35  }  }
36    
37  DataAbstract::~DataAbstract()  const_DataAbstract_ptr DataAbstract::getPtr() const
38  {  {
39      if (_internal_weak_this.expired())
40      {
41        return const_DataAbstract_ptr(this);
42      }
43      else
44      {
45        return shared_from_this();
46      }
47  }  }
48    
49  void  
50  DataAbstract::setPointDataView(const DataArrayView& input)  // Warning - this method uses .use_count() which the boost doco labels inefficient.
51    // If this method needs to be called in debug contexts, we may need to do some
52    // timing experiments to determine how inefficient and possibly switch over to
53    // invasive pointers which can answer these questions faster
54    bool DataAbstract::checkNoSharing() const
55  {  {
56      m_pointDataView.reset(new DataArrayView(input.getData(),input.getShape(),input.getOffset()));  
57      return !m_lazyshared && (m_owners.size()<2);
58    
59    /*  if (_internal_weak_this.expired())  // there is no shared_ptr for this object yet
60      {
61        return true;
62      }
63      if (shared_from_this().use_count()==2)    // shared_from_this will increase the ref count
64      {                     // which is the reason .unique is no use.
65        return true;
66      }
67    std::cerr << "-<"<<shared_from_this().use_count() << ">-" << endl;
68      return false;*/
69  }  }
70    
71  void  bool
72  DataAbstract::resetPointDataView()  DataAbstract::isLazy() const
73    {
74        return (dynamic_cast<const DataLazy*>(this)!=0);
75    }
76    
77    
78    
79    DataAbstract::DataAbstract(const FunctionSpace& what, const ShapeType& shape, bool isDataEmpty):
80        m_noSamples(what.getNumSamples()),
81        m_noDataPointsPerSample(what.getNumDPPSample()),
82        m_functionSpace(what),
83        m_shape(shape),
84        m_novalues(DataTypes::noValues(shape)),
85        m_rank(DataTypes::getRank(shape)),
86        m_lazyshared(false)
87    
88    {
89        m_isempty=isDataEmpty;
90        if (m_rank>ESCRIPT_MAX_DATA_RANK)
91        {
92        ostringstream os;
93            os << "Error - Attempt to create a rank " << m_rank
94           << " object. The maximum rank is " << ESCRIPT_MAX_DATA_RANK << ".";
95         throw DataException(os.str());
96        }
97    }
98    
99    DataAbstract::~DataAbstract()
100  {  {
     m_pointDataView.reset(new DataArrayView());  
101  }  }
102    
103    
104  void  void
105  DataAbstract::operandCheck(const DataAbstract& right) const  DataAbstract::operandCheck(const DataAbstract& right) const
106  {  {
# Line 63  DataAbstract::operandCheck(const DataAbs Line 121  DataAbstract::operandCheck(const DataAbs
121    
122      //      //
123      // Check the shape of the point data, a rank of 0(scalar) is okay      // Check the shape of the point data, a rank of 0(scalar) is okay
124      if (!((right.getPointDataView().getRank()==0) ||      if (!((right.getRank()==0) || (getRank()==0) ||
125        (right.getPointDataView().getShape()==getPointDataView().getShape())))        (right.getShape()==getShape())))
126        {        {
127          stringstream temp;          stringstream temp;
128      temp << "Error - Right hand argument point data shape: "      temp << "Error - Right hand argument point data shape: "
129           << DataArrayView::shapeToString(right.getPointDataView().getShape())           << DataTypes::shapeToString(right.getShape())
130           << " doesn't match left: "           << " doesn't match left: "
131           << DataArrayView::shapeToString(getPointDataView().getShape());           << DataTypes::shapeToString(getShape());
132      throw DataException(temp.str());      throw DataException(temp.str());
133        }        }
134  }  }
# Line 78  DataAbstract::operandCheck(const DataAbs Line 136  DataAbstract::operandCheck(const DataAbs
136  void  void
137  DataAbstract::dump(const std::string fileName) const  DataAbstract::dump(const std::string fileName) const
138  {  {
139      throw DataException("Error - DataAbstract:: dump: not implemented.");      throw DataException("Error - DataAbstract::dump: not implemented.");
140  }  }
141    
142    
# Line 89  DataAbstract::getSampleDataByTag(int tag Line 147  DataAbstract::getSampleDataByTag(int tag
147      throw DataException("Error - DataAbstract::getSampleDataByTag: Data type does not have tag values.");      throw DataException("Error - DataAbstract::getSampleDataByTag: Data type does not have tag values.");
148  }  }
149    
150  void  
151    void  
152  DataAbstract::setTaggedValue(int tagKey,  DataAbstract::setTaggedValue(int tagKey,
153                               const DataArrayView& value)             const DataTypes::ShapeType& pointshape,
154                   const DataTypes::ValueType& value,
155               int dataOffset)
156  {  {
157      throw DataException("Error - DataAbstract::setTaggedValue: Data type does not have tag values.");      throw DataException("Error - DataAbstract::setTaggedValue: Data type does not have tag values.");
158  }  }
159    
160    
161  int  int
162  DataAbstract::getTagNumber(int dpno)  DataAbstract::getTagNumber(int dpno)
163  {  {
# Line 103  DataAbstract::getTagNumber(int dpno) Line 165  DataAbstract::getTagNumber(int dpno)
165      return (0);      return (0);
166  }  }
167    
 int  
 DataAbstract::archiveData(ofstream& archiveFile,  
                           const ValueType::size_type noValues) const  
 {  
   return 0;  
 }  
   
 int  
 DataAbstract::extractData(ifstream& archiveFile,  
                           const ValueType::size_type noValues)  
 {  
   return 0;  
 }  
   
 void  
 DataAbstract::copyAll(const boost::python::numeric::array& value)  
 {  
     throw DataException("Error - DataAbstract::copying data from numarray objects is not supported.");  
 }  
168  void  void
169  DataAbstract::copyToDataPoint(const int sampleNo, const int dataPointNo, const double value)  DataAbstract::copyToDataPoint(const int sampleNo, const int dataPointNo, const double value)
170  {  {
171      throw DataException("Error - DataAbstract::copying data from double value to a single data point is not supported.");      throw DataException("Error - DataAbstract::copying data from double value to a single data point is not supported.");
172  }  }
173    
174    
175  void  void
176  DataAbstract::copyToDataPoint(const int sampleNo, const int dataPointNo, const boost::python::numeric::array& value)  DataAbstract::copyToDataPoint(const int sampleNo, const int dataPointNo, const WrappedArray& value)
177  {  {
178      throw DataException("Error - DataAbstract::copying data from numarray objects to a single data point is not supported.");      throw DataException("Error - DataAbstract::copying data from WrappedArray objects to a single data point is not supported.");
179  }  }
180    
181    
182  void  void
183  DataAbstract::symmetric(DataAbstract* ev)  DataAbstract::symmetric(DataAbstract* ev)
184  {  {
# Line 182  DataAbstract::setToZero() Line 228  DataAbstract::setToZero()
228  void  void
229  DataAbstract::reorderByReferenceIDs(int *reference_ids)  DataAbstract::reorderByReferenceIDs(int *reference_ids)
230  {  {
231        throw DataException("Error - DataAbstract:: cannot reorder by reference ids.");
232    }
233    
234    
235    void DataAbstract::addOwner(Data* d)
236    {
237      for (size_t i=0;i<m_owners.size();++i)
238      {
239        if (m_owners[i]==d)
240        {
241            return;
242        }
243      }
244      m_owners.push_back(d);
245    // cerr << "Adding " << d << " as an owner of " << this << " now O=" << m_owners.size() << endl;
246      if (m_owners.size()==2)   // Means it used to be 1 so we need to tell people
247      {
248        for (size_t i=0;i<m_owners.size();++i)
249        {
250            m_owners[i]->updateShareStatus(true);
251        }
252      }
253    }
254    
255    void DataAbstract::removeOwner(Data* d)
256    {
257      for (size_t i=0;i<m_owners.size();++i)
258      {
259        if (m_owners[i]==d)
260        {
261            m_owners.erase(m_owners.begin()+i,m_owners.begin()+(i+1));  // remove the element
262            break;
263        }
264      }
265      if (m_owners.size()==1)   // Means it used to be 2 so we need to tell people
266      {
267        m_owners[0]->updateShareStatus(isShared());     // could still be lazy shared
268      }
269  }  }
270    
271    
272    void DataAbstract::makeLazyShared()
273    {
274        m_lazyshared=true;  // now we need to inform all the owners
275        for (size_t i=0;i<m_owners.size();++i)
276        {
277            m_owners[i]->updateShareStatus(true);
278        }
279    }  
280    
281    
282  }  // end of namespace  }  // end of namespace

Legend:
Removed from v.1487  
changed lines
  Added in v.2271

  ViewVC Help
Powered by ViewVC 1.1.26