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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

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    
23 jgs 121 using namespace std;
24 jgs 149
25 jgs 82 namespace escript {
26    
27     //
28 jgs 149 // Create a null domain for use with any default-constructed function space
29 trankine 1426 NullDomain const FunctionSpace::nullDomainValue;
30 jgs 82
31     FunctionSpace::FunctionSpace():
32 trankine 1426 m_domain(static_cast<const AbstractDomain*>(&nullDomainValue)),
33     m_functionSpaceType(nullDomainValue.getFunctionCode())
34 jgs 82 {
35     }
36    
37 jgs 117 FunctionSpace::FunctionSpace(const AbstractDomain& domain,
38     int functionSpaceType):
39 jgs 82 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 jgs 149 << " for domain: " << m_domain->getDescription();
46 jgs 82 throw FunctionSpaceException(temp.str());
47     }
48     }
49    
50 jgs 117 std::pair<int,int>
51     FunctionSpace::getDataShape() const
52 jgs 82 {
53     return m_domain->getDataShape(m_functionSpaceType);
54     }
55    
56 jgs 117 int
57     FunctionSpace::getTypeCode() const
58 jgs 82 {
59     return m_functionSpaceType;
60     }
61    
62 jgs 117 const
63     AbstractDomain&
64     FunctionSpace::getDomain() const
65 jgs 82 {
66     return *m_domain;
67     }
68    
69 phornby 1628 std::string
70 jgs 117 FunctionSpace::toString() const
71 jgs 82 {
72     std::stringstream temp;
73 ksteube 1312 temp << m_domain->functionSpaceTypeAsString(m_functionSpaceType)
74     << " on " << m_domain->getDescription();
75 trankine 1426
76 phornby 1628 return temp.str();
77 jgs 82 }
78    
79 trankine 1426
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 phornby 1628 return cvtr(temp.str());
91 trankine 1426 }
92     #endif
93    
94    
95 jgs 117 int
96     FunctionSpace::getTagFromSampleNo(int sampleNo) const
97 jgs 82 {
98     return m_domain->getTagFromSampleNo(m_functionSpaceType,sampleNo);
99     }
100    
101 jgs 117 int
102 jgs 149 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 gross 1718 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 gross 964 int*
151     FunctionSpace::borrowSampleReferenceIDs() const
152 jgs 110 {
153 gross 964 return m_domain->borrowSampleReferenceIDs(m_functionSpaceType);
154 jgs 110 }
155    
156 jgs 117 FunctionSpace&
157     FunctionSpace::operator=(const FunctionSpace& other)
158 jgs 82 {
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 jgs 117 bool
166     FunctionSpace::operator==(const FunctionSpace& other) const
167 jgs 82 {
168 jgs 121 return ((*(other.m_domain)==*(m_domain)) && (other.m_functionSpaceType==m_functionSpaceType));
169 jgs 82 }
170    
171 jgs 117 bool
172     FunctionSpace::operator!=(const FunctionSpace& other) const
173 jgs 82 {
174 jgs 121 return !(operator==(other));
175 jgs 82 }
176    
177 jgs 117 escript::Data
178     FunctionSpace::getX() const
179 jgs 82 {
180     Data out=escript::Vector(0,*this,true);
181     getDomain().setToX(out);
182 gross 783 out.setProtection();
183 jgs 82 return out;
184     }
185    
186 jgs 117 escript::Data
187     FunctionSpace::getNormal() const
188 jgs 82 {
189     Data out=escript::Vector(0,*this,true);
190     getDomain().setToNormal(out);
191 gross 783 out.setProtection();
192 jgs 82 return out;
193     }
194    
195 jgs 117 escript::Data
196     FunctionSpace::getSize() const
197 jgs 82 {
198     Data out=escript::Scalar(0,*this,true);
199     getDomain().setToSize(out);
200 gross 783 out.setProtection();
201 jgs 82 return out;
202     }
203    
204 gross 767 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 gross 1716 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 jfenwick 1802 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 gross 1716
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 jfenwick 1802 bool
248     FunctionSpace::canTag() const
249     {
250     return m_domain->canTag(m_functionSpaceType);
251     }
252    
253 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