/[escript]/branches/more_shared_ptrs_from_1812/escript/src/FunctionSpace.cpp
ViewVC logotype

Contents of /branches/more_shared_ptrs_from_1812/escript/src/FunctionSpace.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1821 - (show annotations)
Wed Oct 1 04:46:59 2008 UTC (11 years, 4 months ago) by jfenwick
File size: 6603 byte(s)
Branch commit.
Fixed some issues.
runs c++ unit tests and run_simplesolve successfully.


1
2 /*******************************************************
3 *
4 * Copyright (c) 2003-2008 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 std::pair<int,int>
59 FunctionSpace::getDataShape() const
60 {
61 return m_domain->getDataShape(m_functionSpaceType);
62 }
63
64 int
65 FunctionSpace::getTypeCode() const
66 {
67 return m_functionSpaceType;
68 }
69
70 // const
71 // AbstractDomain&
72 const_Domain_ptr
73 FunctionSpace::getDomain() const
74 {
75 return m_domain;
76 }
77
78 Domain_ptr
79 FunctionSpace::getDomainPython() const
80 {
81 // cast away the const-ness because python ignores it anyway
82 return const_pointer_cast<AbstractDomain>(m_domain);
83 }
84
85
86
87 std::string
88 FunctionSpace::toString() const
89 {
90 std::stringstream temp;
91 temp << m_domain->functionSpaceTypeAsString(m_functionSpaceType)
92 << " on " << m_domain->getDescription();
93
94 return temp.str();
95 }
96
97
98 #ifdef DEBUG_PY_STRINGS
99 PyObject *
100 FunctionSpace::toPyString() const
101 {
102 boost::python::to_python_value<const std::string &> cvtr;
103 std::stringstream temp;
104
105 temp << m_domain->functionSpaceTypeAsString(m_functionSpaceType)
106 << " on " << m_domain->getDescription();
107
108 return cvtr(temp.str());
109 }
110 #endif
111
112
113 int
114 FunctionSpace::getTagFromSampleNo(int sampleNo) const
115 {
116 return m_domain->getTagFromSampleNo(m_functionSpaceType,sampleNo);
117 }
118
119 int
120 FunctionSpace::getTagFromDataPointNo(int dataPointNo) const
121 {
122 //
123 // Get the number of samples and data-points per sample
124 int numSamples = getNumSamples();
125 int numDataPointsPerSample = getNumDPPSample();
126 int numDataPoints = numSamples * numDataPointsPerSample;
127
128 if (numDataPointsPerSample==0) {
129 throw DataException("FunctionSpace::getTagFromDataPointNo error: no data-points associated with this object.");
130 }
131
132 if (dataPointNo<0 || dataPointNo>numDataPoints) {
133 throw DataException("FunctionSpace::getTagFromDataPointNo error: invalid data-point number supplied.");
134 }
135
136 //
137 // Determine the sample number which corresponds to this data-point number
138 int sampleNo = dataPointNo / numDataPointsPerSample;
139
140 //
141 // Determine the tag number which corresponds to this sample number
142 int tagNo = getTagFromSampleNo(sampleNo);
143
144 //
145 // return the tag number
146 return(tagNo);
147 }
148
149 int FunctionSpace::getReferenceIDFromDataPointNo(int dataPointNo) const
150 {
151 //
152 // Get the number of samples and data-points per sample
153 int numSamples = getNumSamples();
154 int numDataPointsPerSample = getNumDPPSample();
155 int*referenceIDs= borrowSampleReferenceIDs();
156 int numDataPoints = numSamples * numDataPointsPerSample;
157
158 if (numDataPointsPerSample==0) {
159 throw DataException("FunctionSpace::getReferenceIDFromDataPointNo error: no data-points associated with this object.");
160 }
161 if (dataPointNo<0 || dataPointNo>numDataPoints) {
162 throw DataException("FunctionSpace::getReferenceIDFromDataPointNo error: invalid data-point number supplied.");
163 }
164 int sampleNo = dataPointNo / numDataPointsPerSample;
165 return referenceIDs[sampleNo];
166 }
167
168 int*
169 FunctionSpace::borrowSampleReferenceIDs() const
170 {
171 return m_domain->borrowSampleReferenceIDs(m_functionSpaceType);
172 }
173
174 FunctionSpace&
175 FunctionSpace::operator=(const FunctionSpace& other)
176 {
177 // explicitly defined assignment operator to emphasise pointer copy
178 m_functionSpaceType=other.m_functionSpaceType;
179 m_domain=other.m_domain;
180 return *this;
181 }
182
183 bool
184 FunctionSpace::operator==(const FunctionSpace& other) const
185 {
186 return ((*(other.m_domain)==*(m_domain)) && (other.m_functionSpaceType==m_functionSpaceType));
187 }
188
189 bool
190 FunctionSpace::operator!=(const FunctionSpace& other) const
191 {
192 return !(operator==(other));
193 }
194
195 escript::Data
196 FunctionSpace::getX() const
197 {
198 Data out=escript::Vector(0,*this,true);
199 getDomain()->setToX(out);
200 out.setProtection();
201 return out;
202 }
203
204 escript::Data
205 FunctionSpace::getNormal() const
206 {
207 Data out=escript::Vector(0,*this,true);
208 getDomain()->setToNormal(out);
209 out.setProtection();
210 return out;
211 }
212
213 escript::Data
214 FunctionSpace::getSize() const
215 {
216 Data out=escript::Scalar(0,*this,true);
217 getDomain()->setToSize(out);
218 out.setProtection();
219 return out;
220 }
221
222 void
223 FunctionSpace::setTags(const int newTag, const escript::Data& mask) const
224 {
225 if (mask.getFunctionSpace()== *this) {
226 m_domain->setTags(m_functionSpaceType,newTag,mask);
227 } else {
228 throw FunctionSpaceException("illegal function space of mask.");
229 }
230 }
231
232 int
233 FunctionSpace::getNumberOfTagsInUse() const
234 {
235 return m_domain->getNumberOfTagsInUse(m_functionSpaceType);
236 }
237
238 int*
239 FunctionSpace::borrowListOfTagsInUse() const
240 {
241 return m_domain->borrowListOfTagsInUse(m_functionSpaceType);
242 }
243
244 std::list<int>
245 FunctionSpace::getListOfTagsSTL() const
246 {
247 std::list<int> taglist;
248 int i;
249 int* tags=borrowListOfTagsInUse();
250 for (i=0;i<getNumberOfTagsInUse();++i) taglist.push_back(tags[i]);
251 return taglist;
252 }
253
254
255 boost::python::list
256 FunctionSpace::getListOfTags() const
257 {
258 boost::python::list taglist;
259 int i;
260 int* tags=borrowListOfTagsInUse();
261 for (i=0;i<getNumberOfTagsInUse();++i) taglist.append(tags[i]);
262 return taglist;
263 }
264
265 bool
266 FunctionSpace::canTag() const
267 {
268 return m_domain->canTag(m_functionSpaceType);
269 }
270
271 } // end of namespace

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26