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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1872 - (hide annotations)
Mon Oct 13 00:18:55 2008 UTC (11 years, 4 months ago) by jfenwick
File size: 7554 byte(s)
Closing the moreshared branch

1 ksteube 1312
2     /*******************************************************
3 ksteube 1811 *
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 ksteube 1312
14 ksteube 1811
15 jgs 480 #include "FunctionSpace.h"
16 jgs 474 #include "FunctionSpaceException.h"
17     #include "Data.h"
18     #include "DataFactory.h"
19 jgs 82
20     #include <iostream>
21     #include <sstream>
22 jfenwick 1872 #include <boost/smart_ptr.hpp>
23 jgs 82
24 jgs 121 using namespace std;
25 jfenwick 1872 using namespace boost;
26 jgs 149
27 jgs 82 namespace escript {
28    
29 jfenwick 1872 namespace
30     {
31 jgs 82 //
32 jgs 149 // Create a null domain for use with any default-constructed function space
33 jfenwick 1872 // NullDomain const FunctionSpace::nullDomainValue;
34     const_Domain_ptr nullDomainValue(new NullDomain());
35     }
36 jgs 82
37     FunctionSpace::FunctionSpace():
38 jfenwick 1872 // m_domain(static_cast<const AbstractDomain*>(&nullDomainValue)),
39     m_domain(nullDomainValue),
40     m_functionSpaceType(dynamic_cast<const NullDomain*>(nullDomainValue.get())->getFunctionCode())
41 jgs 82 {
42     }
43    
44 jfenwick 1872 // 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 jgs 117 int functionSpaceType):
60 jfenwick 1872 /* m_domain(dynamic_cast<const AbstractDomain*>(&domain)),*/
61     m_domain(domain),
62 jgs 82 m_functionSpaceType(functionSpaceType)
63     {
64     if (!m_domain->isValidFunctionSpaceType(functionSpaceType)) {
65     std::stringstream temp;
66     temp << "Invalid function space type: " << functionSpaceType
67 jgs 149 << " for domain: " << m_domain->getDescription();
68 jgs 82 throw FunctionSpaceException(temp.str());
69     }
70     }
71    
72 jfenwick 1872 FunctionSpace::FunctionSpace(const FunctionSpace& other)
73     :m_domain(other.m_domain),
74     m_functionSpaceType(other.m_functionSpaceType)
75     {
76     }
77    
78 jgs 117 std::pair<int,int>
79     FunctionSpace::getDataShape() const
80 jgs 82 {
81     return m_domain->getDataShape(m_functionSpaceType);
82     }
83    
84 jgs 117 int
85     FunctionSpace::getTypeCode() const
86 jgs 82 {
87     return m_functionSpaceType;
88     }
89    
90 jfenwick 1872 // const
91     // AbstractDomain&
92     const_Domain_ptr
93 jgs 117 FunctionSpace::getDomain() const
94 jgs 82 {
95 jfenwick 1872 return m_domain;
96 jgs 82 }
97    
98 jfenwick 1872 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 phornby 1628 std::string
108 jgs 117 FunctionSpace::toString() const
109 jgs 82 {
110     std::stringstream temp;
111 ksteube 1312 temp << m_domain->functionSpaceTypeAsString(m_functionSpaceType)
112     << " on " << m_domain->getDescription();
113 trankine 1426
114 phornby 1628 return temp.str();
115 jgs 82 }
116    
117 trankine 1426
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 phornby 1628 return cvtr(temp.str());
129 trankine 1426 }
130     #endif
131    
132    
133 jgs 117 int
134     FunctionSpace::getTagFromSampleNo(int sampleNo) const
135 jgs 82 {
136     return m_domain->getTagFromSampleNo(m_functionSpaceType,sampleNo);
137     }
138    
139 jgs 117 int
140 jgs 149 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 gross 1718 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     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 gross 964 int*
189     FunctionSpace::borrowSampleReferenceIDs() const
190 jgs 110 {
191 gross 964 return m_domain->borrowSampleReferenceIDs(m_functionSpaceType);
192 jgs 110 }
193    
194 jfenwick 1872 // 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 jgs 117 FunctionSpace&
197     FunctionSpace::operator=(const FunctionSpace& other)
198 jgs 82 {
199 jfenwick 1872 throw DataException("FunctionSpace::= should not be called. Programming Error.");
200 jgs 82 // explicitly defined assignment operator to emphasise pointer copy
201 jfenwick 1872 /* m_functionSpaceType=other.m_functionSpaceType;
202 jgs 82 m_domain=other.m_domain;
203 jfenwick 1872 return *this;*/
204 jgs 82 }
205    
206 jgs 117 bool
207     FunctionSpace::operator==(const FunctionSpace& other) const
208 jgs 82 {
209 jgs 121 return ((*(other.m_domain)==*(m_domain)) && (other.m_functionSpaceType==m_functionSpaceType));
210 jgs 82 }
211    
212 jgs 117 bool
213     FunctionSpace::operator!=(const FunctionSpace& other) const
214 jgs 82 {
215 jgs 121 return !(operator==(other));
216 jgs 82 }
217    
218 jgs 117 escript::Data
219     FunctionSpace::getX() const
220 jgs 82 {
221     Data out=escript::Vector(0,*this,true);
222 jfenwick 1872 getDomain()->setToX(out);
223 gross 783 out.setProtection();
224 jgs 82 return out;
225     }
226    
227 jgs 117 escript::Data
228     FunctionSpace::getNormal() const
229 jgs 82 {
230     Data out=escript::Vector(0,*this,true);
231 jfenwick 1872 getDomain()->setToNormal(out);
232 gross 783 out.setProtection();
233 jgs 82 return out;
234     }
235    
236 jgs 117 escript::Data
237     FunctionSpace::getSize() const
238 jgs 82 {
239     Data out=escript::Scalar(0,*this,true);
240 jfenwick 1872 getDomain()->setToSize(out);
241 gross 783 out.setProtection();
242 jgs 82 return out;
243     }
244    
245 gross 767 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 gross 1716 int
256     FunctionSpace::getNumberOfTagsInUse() const
257     {
258     return m_domain->getNumberOfTagsInUse(m_functionSpaceType);
259     }
260    
261     int*
262     FunctionSpace::borrowListOfTagsInUse() const
263     {
264     return m_domain->borrowListOfTagsInUse(m_functionSpaceType);
265     }
266    
267 jfenwick 1802 std::list<int>
268     FunctionSpace::getListOfTagsSTL() const
269     {
270     std::list<int> taglist;
271     int i;
272     int* tags=borrowListOfTagsInUse();
273     for (i=0;i<getNumberOfTagsInUse();++i) taglist.push_back(tags[i]);
274     return taglist;
275     }
276 gross 1716
277    
278     boost::python::list
279     FunctionSpace::getListOfTags() const
280     {
281     boost::python::list taglist;
282     int i;
283     int* tags=borrowListOfTagsInUse();
284     for (i=0;i<getNumberOfTagsInUse();++i) taglist.append(tags[i]);
285     return taglist;
286     }
287    
288 jfenwick 1802 bool
289     FunctionSpace::canTag() const
290     {
291     return m_domain->canTag(m_functionSpaceType);
292     }
293    
294 jgs 82 } // end of namespace

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26