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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1811 - (show annotations)
Thu Sep 25 23:11:13 2008 UTC (10 years, 9 months ago) by ksteube
File size: 6175 byte(s)
Copyright updated in all files

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
23 using namespace std;
24
25 namespace escript {
26
27 //
28 // Create a null domain for use with any default-constructed function space
29 NullDomain const FunctionSpace::nullDomainValue;
30
31 FunctionSpace::FunctionSpace():
32 m_domain(static_cast<const AbstractDomain*>(&nullDomainValue)),
33 m_functionSpaceType(nullDomainValue.getFunctionCode())
34 {
35 }
36
37 FunctionSpace::FunctionSpace(const AbstractDomain& domain,
38 int functionSpaceType):
39 m_domain(dynamic_cast<const AbstractDomain*>(&domain)),
40 m_functionSpaceType(functionSpaceType)
41 {
42 if (!m_domain->isValidFunctionSpaceType(functionSpaceType)) {
43 std::stringstream temp;
44 temp << "Invalid function space type: " << functionSpaceType
45 << " for domain: " << m_domain->getDescription();
46 throw FunctionSpaceException(temp.str());
47 }
48 }
49
50 std::pair<int,int>
51 FunctionSpace::getDataShape() const
52 {
53 return m_domain->getDataShape(m_functionSpaceType);
54 }
55
56 int
57 FunctionSpace::getTypeCode() const
58 {
59 return m_functionSpaceType;
60 }
61
62 const
63 AbstractDomain&
64 FunctionSpace::getDomain() const
65 {
66 return *m_domain;
67 }
68
69 std::string
70 FunctionSpace::toString() const
71 {
72 std::stringstream temp;
73 temp << m_domain->functionSpaceTypeAsString(m_functionSpaceType)
74 << " on " << m_domain->getDescription();
75
76 return temp.str();
77 }
78
79
80 #ifdef DEBUG_PY_STRINGS
81 PyObject *
82 FunctionSpace::toPyString() const
83 {
84 boost::python::to_python_value<const std::string &> cvtr;
85 std::stringstream temp;
86
87 temp << m_domain->functionSpaceTypeAsString(m_functionSpaceType)
88 << " on " << m_domain->getDescription();
89
90 return cvtr(temp.str());
91 }
92 #endif
93
94
95 int
96 FunctionSpace::getTagFromSampleNo(int sampleNo) const
97 {
98 return m_domain->getTagFromSampleNo(m_functionSpaceType,sampleNo);
99 }
100
101 int
102 FunctionSpace::getTagFromDataPointNo(int dataPointNo) const
103 {
104 //
105 // Get the number of samples and data-points per sample
106 int numSamples = getNumSamples();
107 int numDataPointsPerSample = getNumDPPSample();
108 int numDataPoints = numSamples * numDataPointsPerSample;
109
110 if (numDataPointsPerSample==0) {
111 throw DataException("FunctionSpace::getTagFromDataPointNo error: no data-points associated with this object.");
112 }
113
114 if (dataPointNo<0 || dataPointNo>numDataPoints) {
115 throw DataException("FunctionSpace::getTagFromDataPointNo error: invalid data-point number supplied.");
116 }
117
118 //
119 // Determine the sample number which corresponds to this data-point number
120 int sampleNo = dataPointNo / numDataPointsPerSample;
121
122 //
123 // Determine the tag number which corresponds to this sample number
124 int tagNo = getTagFromSampleNo(sampleNo);
125
126 //
127 // return the tag number
128 return(tagNo);
129 }
130
131 int FunctionSpace::getReferenceIDFromDataPointNo(int dataPointNo) const
132 {
133 //
134 // Get the number of samples and data-points per sample
135 int numSamples = getNumSamples();
136 int numDataPointsPerSample = getNumDPPSample();
137 int*referenceIDs= borrowSampleReferenceIDs();
138 int numDataPoints = numSamples * numDataPointsPerSample;
139
140 if (numDataPointsPerSample==0) {
141 throw DataException("FunctionSpace::getReferenceIDFromDataPointNo error: no data-points associated with this object.");
142 }
143 if (dataPointNo<0 || dataPointNo>numDataPoints) {
144 throw DataException("FunctionSpace::getReferenceIDFromDataPointNo error: invalid data-point number supplied.");
145 }
146 int sampleNo = dataPointNo / numDataPointsPerSample;
147 return referenceIDs[sampleNo];
148 }
149
150 int*
151 FunctionSpace::borrowSampleReferenceIDs() const
152 {
153 return m_domain->borrowSampleReferenceIDs(m_functionSpaceType);
154 }
155
156 FunctionSpace&
157 FunctionSpace::operator=(const FunctionSpace& other)
158 {
159 // explicitly defined assignment operator to emphasise pointer copy
160 m_functionSpaceType=other.m_functionSpaceType;
161 m_domain=other.m_domain;
162 return *this;
163 }
164
165 bool
166 FunctionSpace::operator==(const FunctionSpace& other) const
167 {
168 return ((*(other.m_domain)==*(m_domain)) && (other.m_functionSpaceType==m_functionSpaceType));
169 }
170
171 bool
172 FunctionSpace::operator!=(const FunctionSpace& other) const
173 {
174 return !(operator==(other));
175 }
176
177 escript::Data
178 FunctionSpace::getX() const
179 {
180 Data out=escript::Vector(0,*this,true);
181 getDomain().setToX(out);
182 out.setProtection();
183 return out;
184 }
185
186 escript::Data
187 FunctionSpace::getNormal() const
188 {
189 Data out=escript::Vector(0,*this,true);
190 getDomain().setToNormal(out);
191 out.setProtection();
192 return out;
193 }
194
195 escript::Data
196 FunctionSpace::getSize() const
197 {
198 Data out=escript::Scalar(0,*this,true);
199 getDomain().setToSize(out);
200 out.setProtection();
201 return out;
202 }
203
204 void
205 FunctionSpace::setTags(const int newTag, const escript::Data& mask) const
206 {
207 if (mask.getFunctionSpace()== *this) {
208 m_domain->setTags(m_functionSpaceType,newTag,mask);
209 } else {
210 throw FunctionSpaceException("illegal function space of mask.");
211 }
212 }
213
214 int
215 FunctionSpace::getNumberOfTagsInUse() const
216 {
217 return m_domain->getNumberOfTagsInUse(m_functionSpaceType);
218 }
219
220 int*
221 FunctionSpace::borrowListOfTagsInUse() const
222 {
223 return m_domain->borrowListOfTagsInUse(m_functionSpaceType);
224 }
225
226 std::list<int>
227 FunctionSpace::getListOfTagsSTL() const
228 {
229 std::list<int> taglist;
230 int i;
231 int* tags=borrowListOfTagsInUse();
232 for (i=0;i<getNumberOfTagsInUse();++i) taglist.push_back(tags[i]);
233 return taglist;
234 }
235
236
237 boost::python::list
238 FunctionSpace::getListOfTags() const
239 {
240 boost::python::list taglist;
241 int i;
242 int* tags=borrowListOfTagsInUse();
243 for (i=0;i<getNumberOfTagsInUse();++i) taglist.append(tags[i]);
244 return taglist;
245 }
246
247 bool
248 FunctionSpace::canTag() const
249 {
250 return m_domain->canTag(m_functionSpaceType);
251 }
252
253 } // end of namespace

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26