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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3981 - (show annotations)
Fri Sep 21 02:47:54 2012 UTC (6 years, 11 months ago) by jfenwick
File size: 8053 byte(s)
First pass of updating copyright notices
1
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2012 by University of Queensland
5 * http://www.uq.edu.au
6 *
7 * Primary Business: Queensland, Australia
8 * Licensed under the Open Software License version 3.0
9 * http://www.opensource.org/licenses/osl-3.0.php
10 *
11 * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 * Development since 2012 by School of Earth Sciences
13 *
14 *****************************************************************************/
15
16
17 #include "DataAbstract.h"
18 #include "DataException.h"
19 #include "DataLazy.h"
20
21 #include "Data.h" // So we can update the shared status when things change
22
23 using namespace std;
24
25 namespace escript {
26
27 // The boost methods enable_shared_from_this return a shared_ptr managing the object
28 // when all you have is the object. It explicitly fails in the case where
29 // you haven't made a shared_ptr for this object yet.
30 // _Currently_ we need this behaviour, hence the exception squashing.
31 // An execption would be thrown in two circumstances:
32 // 1. The object doesn't have a shared_ptr attached yet.
33 // 2. All shared_ptrs have let go and the object is in the process of being destroyed.
34 // An attempt to getPtr() in the second case is doomed anyway.
35 //
36 // Use of something equivalent to boost_1_39's make_shared used elsewhere might remove
37 // the need for the hack.
38 DataAbstract_ptr DataAbstract::getPtr()
39 {
40 try
41 {
42 return shared_from_this();
43 }
44 catch (boost::bad_weak_ptr p)
45 {
46 return DataAbstract_ptr(this);
47 }
48 }
49
50 const_DataAbstract_ptr DataAbstract::getPtr() const
51 {
52 try
53 {
54 return shared_from_this();
55 }
56 catch (boost::bad_weak_ptr p)
57 {
58 return const_DataAbstract_ptr(this);
59 }
60 }
61
62
63 // Warning - this method uses .use_count() which the boost doco labels inefficient.
64 // If this method needs to be called in debug contexts, we may need to do some
65 // timing experiments to determine how inefficient and possibly switch over to
66 // invasive pointers which can answer these questions faster
67 bool DataAbstract::checkNoSharing() const
68 {
69
70 return !m_lazyshared && (m_owners.size()<2);
71
72 /* if (_internal_weak_this.expired()) // there is no shared_ptr for this object yet
73 {
74 return true;
75 }
76 if (shared_from_this().use_count()==2) // shared_from_this will increase the ref count
77 { // which is the reason .unique is no use.
78 return true;
79 }
80 std::cerr << "-<"<<shared_from_this().use_count() << ">-" << endl;
81 return false;*/
82 }
83
84 bool
85 DataAbstract::isLazy() const
86 {
87 return (dynamic_cast<const DataLazy*>(this)!=0);
88 }
89
90
91
92 DataAbstract::DataAbstract(const FunctionSpace& what, const ShapeType& shape, bool isDataEmpty):
93 m_noSamples(what.getNumSamples()),
94 m_noDataPointsPerSample(what.getNumDPPSample()),
95 m_functionSpace(what),
96 m_shape(shape),
97 m_novalues(DataTypes::noValues(shape)),
98 m_rank(DataTypes::getRank(shape)),
99 m_lazyshared(false)
100
101 {
102 m_isempty=isDataEmpty;
103 if (m_rank>ESCRIPT_MAX_DATA_RANK)
104 {
105 ostringstream os;
106 os << "Error - Attempt to create a rank " << m_rank
107 << " object. The maximum rank is " << ESCRIPT_MAX_DATA_RANK << ".";
108 throw DataException(os.str());
109 }
110 }
111
112 DataAbstract::~DataAbstract()
113 {
114 }
115
116
117 void
118 DataAbstract::operandCheck(const DataAbstract& right) const
119 {
120 if ((right.getNumDPPSample()!=getNumDPPSample()) ||
121 (right.getNumSamples()!=getNumSamples()) ||
122 (right.getFunctionSpace()!=getFunctionSpace())) {
123 stringstream temp;
124 temp << "Error - Right hand argument sample shape or function space "
125 << "incompatible with left." << endl
126 << "LHS: (" << getNumSamples() << ","
127 << getNumDPPSample() << ") " << getFunctionSpace().toString()
128 << endl
129 << "RHS: (" << right.getNumSamples() << ","
130 << right.getNumDPPSample() << ") "
131 << right.getFunctionSpace().toString();
132 throw DataException(temp.str());
133 }
134
135 //
136 // Check the shape of the point data, a rank of 0(scalar) is okay
137 if (!((right.getRank()==0) || (getRank()==0) ||
138 (right.getShape()==getShape())))
139 {
140 stringstream temp;
141 temp << "Error - Right hand argument point data shape: "
142 << DataTypes::shapeToString(right.getShape())
143 << " doesn't match left: "
144 << DataTypes::shapeToString(getShape());
145 throw DataException(temp.str());
146 }
147 }
148
149 void
150 DataAbstract::dump(const std::string fileName) const
151 {
152 throw DataException("Error - DataAbstract::dump: not implemented.");
153 }
154
155
156
157 DataAbstract::ValueType::value_type*
158 DataAbstract::getSampleDataByTag(int tag)
159 {
160 throw DataException("Error - DataAbstract::getSampleDataByTag: Data type does not have tag values.");
161 }
162
163
164 void
165 DataAbstract::setTaggedValue(int tagKey,
166 const DataTypes::ShapeType& pointshape,
167 const DataTypes::ValueType& value,
168 int dataOffset)
169 {
170 throw DataException("Error - DataAbstract::setTaggedValue: Data type does not have tag values.");
171 }
172
173
174 int
175 DataAbstract::getTagNumber(int dpno)
176 {
177 throw DataException("Error - DataAbstract::getTagNumber: Data type cannot be accessed by tag values.");
178 return (0);
179 }
180
181 void
182 DataAbstract::copyToDataPoint(const int sampleNo, const int dataPointNo, const double value)
183 {
184 throw DataException("Error - DataAbstract::copying data from double value to a single data point is not supported.");
185 }
186
187
188 void
189 DataAbstract::copyToDataPoint(const int sampleNo, const int dataPointNo, const WrappedArray& value)
190 {
191 throw DataException("Error - DataAbstract::copying data from WrappedArray objects to a single data point is not supported.");
192 }
193
194
195 void
196 DataAbstract::symmetric(DataAbstract* ev)
197 {
198 throw DataException("Error - DataAbstract::symmetric is not supported.");
199 }
200
201 void
202 DataAbstract::nonsymmetric(DataAbstract* ev)
203 {
204 throw DataException("Error - DataAbstract::nonsymmetric is not supported.");
205 }
206
207 void
208 DataAbstract::trace(DataAbstract* ev, int axis_offset)
209 {
210 throw DataException("Error - DataAbstract::trace is not supported.");
211 }
212
213 void
214 DataAbstract::swapaxes(DataAbstract* ev, int axis0, int axis1)
215 {
216 throw DataException("Error - DataAbstract::component swapaxes is not supported.");
217 }
218 void
219 DataAbstract::transpose(DataAbstract* ev, int axis_offset)
220 {
221 throw DataException("Error - DataAbstract::transpose is not supported.");
222 }
223
224 void
225 DataAbstract::eigenvalues(DataAbstract* ev)
226 {
227 throw DataException("Error - DataAbstract::eigenvalues is not supported.");
228 }
229 void
230 DataAbstract::eigenvalues_and_eigenvectors(DataAbstract* ev,DataAbstract* V,const double tol)
231 {
232 throw DataException("Error - DataAbstract::eigenvalues_and_eigenvectors is not supported.");
233
234 }
235
236 int
237 DataAbstract::matrixInverse(DataAbstract* out) const
238 {
239 throw DataException("Error - DataAbstract::matrixInverse is not supported.");
240 }
241
242 void
243 DataAbstract::setToZero()
244 {
245 throw DataException("Error - DataAbstract:: cannot set values to zero.");
246 }
247
248 void
249 DataAbstract::reorderByReferenceIDs(int *reference_ids)
250 {
251 throw DataException("Error - DataAbstract:: cannot reorder by reference ids.");
252 }
253
254
255 void DataAbstract::addOwner(Data* d)
256 {
257 for (size_t i=0;i<m_owners.size();++i)
258 {
259 if (m_owners[i]==d)
260 {
261 return;
262 }
263 }
264 m_owners.push_back(d);
265 // cerr << "Adding " << d << " as an owner of " << this << " now O=" << m_owners.size() << endl;
266 if (m_owners.size()==2) // Means it used to be 1 so we need to tell people
267 {
268 for (size_t i=0;i<m_owners.size();++i)
269 {
270 m_owners[i]->updateShareStatus(true);
271 }
272 }
273 }
274
275 void DataAbstract::removeOwner(Data* d)
276 {
277 for (size_t i=0;i<m_owners.size();++i)
278 {
279 if (m_owners[i]==d)
280 {
281 m_owners.erase(m_owners.begin()+i,m_owners.begin()+(i+1)); // remove the element
282 break;
283 }
284 }
285 if (m_owners.size()==1) // Means it used to be 2 so we need to tell people
286 {
287 m_owners[0]->updateShareStatus(isShared()); // could still be lazy shared
288 }
289 }
290
291
292 void DataAbstract::makeLazyShared()
293 {
294 m_lazyshared=true; // now we need to inform all the owners
295 for (size_t i=0;i<m_owners.size();++i)
296 {
297 m_owners[i]->updateShareStatus(true);
298 }
299 }
300
301
302 } // end of namespace

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.26