/[escript]/branches/trilinos_from_5897/escriptcore/src/DataAbstract.cpp
ViewVC logotype

Contents of /branches/trilinos_from_5897/escriptcore/src/DataAbstract.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5963 - (show annotations)
Mon Feb 22 06:59:27 2016 UTC (3 years, 3 months ago) by caltinay
File size: 9395 byte(s)
sync and fix.

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26