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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2856 - (show annotations)
Mon Jan 18 04:14:37 2010 UTC (9 years, 7 months ago) by gross
File size: 8037 byte(s)
FunctionSpaces provide now some information about their approximation order.
1
2 /*******************************************************
3 *
4 * Copyright (c) 2003-2009 by University of Queensland
5 * Earth Systems Science Computational Center (ESSCC)
6 * http://www.uq.edu.au/esscc
7 *
8 * Primary Business: Queensland, Australia
9 * Licensed under the Open Software License version 3.0
10 * http://www.opensource.org/licenses/osl-3.0.php
11 *
12 *******************************************************/
13
14
15 #include "FunctionSpace.h"
16 #include "FunctionSpaceException.h"
17 #include "Data.h"
18 #include "DataFactory.h"
19
20 #include <iostream>
21 #include <sstream>
22 #include <boost/smart_ptr.hpp>
23
24 using namespace std;
25 using namespace boost;
26
27 namespace escript {
28
29 namespace
30 {
31 //
32 // Create a null domain for use with any default-constructed function space
33 // NullDomain const FunctionSpace::nullDomainValue;
34 const_Domain_ptr nullDomainValue(new NullDomain());
35 }
36
37 FunctionSpace::FunctionSpace():
38 // m_domain(static_cast<const AbstractDomain*>(&nullDomainValue)),
39 m_domain(nullDomainValue),
40 m_functionSpaceType(dynamic_cast<const NullDomain*>(nullDomainValue.get())->getFunctionCode())
41 {
42 }
43
44 // FunctionSpace::FunctionSpace(const AbstractDomain& domain,
45 // int functionSpaceType):
46 // /* m_domain(dynamic_cast<const AbstractDomain*>(&domain)),*/
47 // m_domain(domain.getPtr()),
48 // m_functionSpaceType(functionSpaceType)
49 // {
50 // if (!m_domain->isValidFunctionSpaceType(functionSpaceType)) {
51 // std::stringstream temp;
52 // temp << "Invalid function space type: " << functionSpaceType
53 // << " for domain: " << m_domain->getDescription();
54 // throw FunctionSpaceException(temp.str());
55 // }
56 // }
57
58 FunctionSpace::FunctionSpace(const_Domain_ptr domain,
59 int functionSpaceType):
60 /* m_domain(dynamic_cast<const AbstractDomain*>(&domain)),*/
61 m_domain(domain),
62 m_functionSpaceType(functionSpaceType)
63 {
64 if (!m_domain->isValidFunctionSpaceType(functionSpaceType)) {
65 std::stringstream temp;
66 temp << "Invalid function space type: " << functionSpaceType
67 << " for domain: " << m_domain->getDescription();
68 throw FunctionSpaceException(temp.str());
69 }
70 }
71
72 FunctionSpace::FunctionSpace(const FunctionSpace& other)
73 :m_domain(other.m_domain),
74 m_functionSpaceType(other.m_functionSpaceType)
75 {
76 }
77
78 std::pair<int,int>
79 FunctionSpace::getDataShape() const
80 {
81 return m_domain->getDataShape(m_functionSpaceType);
82 }
83
84 int
85 FunctionSpace::getTypeCode() const
86 {
87 return m_functionSpaceType;
88 }
89
90 // const
91 // AbstractDomain&
92 const_Domain_ptr
93 FunctionSpace::getDomain() const
94 {
95 return m_domain;
96 }
97
98 Domain_ptr
99 FunctionSpace::getDomainPython() const
100 {
101 // cast away the const-ness because python ignores it anyway
102 return const_pointer_cast<AbstractDomain>(m_domain);
103 }
104
105
106
107 std::string
108 FunctionSpace::toString() const
109 {
110 std::stringstream temp;
111 temp << m_domain->functionSpaceTypeAsString(m_functionSpaceType)
112 << " on " << m_domain->getDescription();
113
114 return temp.str();
115 }
116
117
118 #ifdef DEBUG_PY_STRINGS
119 PyObject *
120 FunctionSpace::toPyString() const
121 {
122 boost::python::to_python_value<const std::string &> cvtr;
123 std::stringstream temp;
124
125 temp << m_domain->functionSpaceTypeAsString(m_functionSpaceType)
126 << " on " << m_domain->getDescription();
127
128 return cvtr(temp.str());
129 }
130 #endif
131
132
133 int
134 FunctionSpace::getTagFromSampleNo(int sampleNo) const
135 {
136 return m_domain->getTagFromSampleNo(m_functionSpaceType,sampleNo);
137 }
138
139 int
140 FunctionSpace::getTagFromDataPointNo(int dataPointNo) const
141 {
142 //
143 // Get the number of samples and data-points per sample
144 int numSamples = getNumSamples();
145 int numDataPointsPerSample = getNumDPPSample();
146 int numDataPoints = numSamples * numDataPointsPerSample;
147
148 if (numDataPointsPerSample==0) {
149 throw DataException("FunctionSpace::getTagFromDataPointNo error: no data-points associated with this object.");
150 }
151
152 if (dataPointNo<0 || dataPointNo>numDataPoints) {
153 throw DataException("FunctionSpace::getTagFromDataPointNo error: invalid data-point number supplied.");
154 }
155
156 //
157 // Determine the sample number which corresponds to this data-point number
158 int sampleNo = dataPointNo / numDataPointsPerSample;
159
160 //
161 // Determine the tag number which corresponds to this sample number
162 int tagNo = getTagFromSampleNo(sampleNo);
163
164 //
165 // return the tag number
166 return(tagNo);
167 }
168
169 int FunctionSpace::getReferenceIDFromDataPointNo(int dataPointNo) const
170 {
171 //
172 // Get the number of samples and data-points per sample
173 int numSamples = getNumSamples();
174 int numDataPointsPerSample = getNumDPPSample();
175 const int* referenceIDs= borrowSampleReferenceIDs();
176 int numDataPoints = numSamples * numDataPointsPerSample;
177
178 if (numDataPointsPerSample==0) {
179 throw DataException("FunctionSpace::getReferenceIDFromDataPointNo error: no data-points associated with this object.");
180 }
181 if (dataPointNo<0 || dataPointNo>numDataPoints) {
182 throw DataException("FunctionSpace::getReferenceIDFromDataPointNo error: invalid data-point number supplied.");
183 }
184 int sampleNo = dataPointNo / numDataPointsPerSample;
185 return referenceIDs[sampleNo];
186 }
187
188 const int*
189 FunctionSpace::borrowSampleReferenceIDs() const
190 {
191 return m_domain->borrowSampleReferenceIDs(m_functionSpaceType);
192 }
193
194 // FunctionSpace instances should not be overwritten to point to different domains/types
195 // The only time this was actually used was in constructors and the copy constructor can deal with that
196 FunctionSpace&
197 FunctionSpace::operator=(const FunctionSpace& other)
198 {
199 throw DataException("FunctionSpace::= should not be called. Programming Error.");
200 // explicitly defined assignment operator to emphasise pointer copy
201 /* m_functionSpaceType=other.m_functionSpaceType;
202 m_domain=other.m_domain;
203 return *this;*/
204 }
205
206 bool
207 FunctionSpace::operator==(const FunctionSpace& other) const
208 {
209 return ((*(other.m_domain)==*(m_domain)) && (other.m_functionSpaceType==m_functionSpaceType));
210 }
211
212 bool
213 FunctionSpace::operator!=(const FunctionSpace& other) const
214 {
215 return !(operator==(other));
216 }
217
218 escript::Data
219 FunctionSpace::getX() const
220 {
221 Data out=escript::Vector(0,*this,true);
222 getDomain()->setToX(out);
223 out.setProtection();
224 return out;
225 }
226
227 escript::Data
228 FunctionSpace::getNormal() const
229 {
230 Data out=escript::Vector(0,*this,true);
231 getDomain()->setToNormal(out);
232 out.setProtection();
233 return out;
234 }
235
236 escript::Data
237 FunctionSpace::getSize() const
238 {
239 Data out=escript::Scalar(0,*this,true);
240 getDomain()->setToSize(out);
241 out.setProtection();
242 return out;
243 }
244
245 void
246 FunctionSpace::setTags(const int newTag, const escript::Data& mask) const
247 {
248 if (mask.getFunctionSpace()== *this) {
249 m_domain->setTags(m_functionSpaceType,newTag,mask);
250 } else {
251 throw FunctionSpaceException("illegal function space of mask.");
252 }
253 }
254
255 void
256 FunctionSpace::setTagsByString(const std::string& name, const escript::Data& mask) const
257 {
258 int newTag=m_domain->getTag(name);
259 if (mask.getFunctionSpace()== *this) {
260 m_domain->setTags(m_functionSpaceType,newTag,mask);
261 } else {
262 throw FunctionSpaceException("illegal function space of mask.");
263 }
264 }
265
266 int
267 FunctionSpace::getNumberOfTagsInUse() const
268 {
269 return m_domain->getNumberOfTagsInUse(m_functionSpaceType);
270 }
271
272 const int*
273 FunctionSpace::borrowListOfTagsInUse() const
274 {
275 return m_domain->borrowListOfTagsInUse(m_functionSpaceType);
276 }
277
278 std::list<int>
279 FunctionSpace::getListOfTagsSTL() const
280 {
281 std::list<int> taglist;
282 int i;
283 const int* tags=borrowListOfTagsInUse();
284 for (i=0;i<getNumberOfTagsInUse();++i) taglist.push_back(tags[i]);
285 return taglist;
286 }
287
288
289 boost::python::list
290 FunctionSpace::getListOfTags() const
291 {
292 boost::python::list taglist;
293 int i;
294 const int* tags=borrowListOfTagsInUse();
295 for (i=0;i<getNumberOfTagsInUse();++i) taglist.append(tags[i]);
296 return taglist;
297 }
298
299 bool
300 FunctionSpace::canTag() const
301 {
302 return m_domain->canTag(m_functionSpaceType);
303 }
304
305 int
306 FunctionSpace::getApproximationOrder() const
307 {
308 return m_domain->getApproximationOrder(m_functionSpaceType);
309 }
310
311 } // end of namespace

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26