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

Annotation of /branches/windows_from_1383_trunk/escript/src/FunctionSpace.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1424 - (hide annotations)
Wed Feb 27 05:27:18 2008 UTC (11 years, 6 months ago) by trankine
File size: 4709 byte(s)
removed the toPyString code by undefining DEBUG_PY_STRINGS.
passes the python string() call test 50000 times. Also passes run_rests, but the slightest thing makes it fail.
1 ksteube 1312
2 jgs 115 /* $Id$ */
3 jgs 82
4 ksteube 1312 /*******************************************************
5     *
6     * Copyright 2003-2007 by ACceSS MNRF
7     * Copyright 2007 by University of Queensland
8     *
9     * http://esscc.uq.edu.au
10     * Primary Business: Queensland, Australia
11     * Licensed under the Open Software License version 3.0
12     * http://www.opensource.org/licenses/osl-3.0.php
13     *
14     *******************************************************/
15    
16 jgs 480 #include "FunctionSpace.h"
17 jgs 474 #include "FunctionSpaceException.h"
18     #include "Data.h"
19     #include "DataFactory.h"
20 jgs 82
21     #include <iostream>
22     #include <sstream>
23    
24 jgs 121 using namespace std;
25 jgs 149
26 jgs 82 namespace escript {
27    
28     //
29 jgs 149 // Create a null domain for use with any default-constructed function space
30 trankine 1419 NullDomain const FunctionSpace::nullDomainValue;
31 jgs 82
32     FunctionSpace::FunctionSpace():
33 trankine 1419 m_domain(static_cast<const AbstractDomain*>(&nullDomainValue)),
34     m_functionSpaceType(nullDomainValue.getFunctionCode())
35 jgs 82 {
36     }
37    
38 jgs 117 FunctionSpace::FunctionSpace(const AbstractDomain& domain,
39     int functionSpaceType):
40 jgs 82 m_domain(dynamic_cast<const AbstractDomain*>(&domain)),
41     m_functionSpaceType(functionSpaceType)
42     {
43     if (!m_domain->isValidFunctionSpaceType(functionSpaceType)) {
44     std::stringstream temp;
45     temp << "Invalid function space type: " << functionSpaceType
46 jgs 149 << " for domain: " << m_domain->getDescription();
47 jgs 82 throw FunctionSpaceException(temp.str());
48     }
49     }
50    
51 jgs 117 std::pair<int,int>
52     FunctionSpace::getDataShape() const
53 jgs 82 {
54     return m_domain->getDataShape(m_functionSpaceType);
55     }
56    
57 jgs 117 int
58     FunctionSpace::getTypeCode() const
59 jgs 82 {
60     return m_functionSpaceType;
61     }
62    
63 jgs 117 const
64     AbstractDomain&
65     FunctionSpace::getDomain() const
66 jgs 82 {
67     return *m_domain;
68     }
69    
70 trankine 1419 const std::string &
71 jgs 117 FunctionSpace::toString() const
72 jgs 82 {
73 trankine 1422 std::stringstream temp;
74     temp << m_domain->functionSpaceTypeAsString(m_functionSpaceType)
75     << " on " << m_domain->getDescription();
76 trankine 1419
77 trankine 1422 type_str = temp.str();
78    
79 trankine 1419 return type_str;
80     }
81    
82    
83 trankine 1421 #ifdef DEBUG_PY_STRINGS
84 trankine 1419 PyObject *
85     FunctionSpace::toPyString() const
86     {
87 trankine 1422 boost::python::to_python_value<const std::string &> cvtr;
88 trankine 1424 std::stringstream temp;
89 trankine 1419
90 trankine 1424 temp << m_domain->functionSpaceTypeAsString(m_functionSpaceType)
91     << " on " << m_domain->getDescription();
92 trankine 1419
93 trankine 1424 //toString();
94     type_str = temp.str();
95 trankine 1419
96 trankine 1422 return cvtr(type_str);
97 jgs 82 }
98 trankine 1419 #endif
99 jgs 82
100 trankine 1422
101 jgs 117 int
102     FunctionSpace::getTagFromSampleNo(int sampleNo) const
103 jgs 82 {
104     return m_domain->getTagFromSampleNo(m_functionSpaceType,sampleNo);
105     }
106    
107 jgs 117 int
108 jgs 149 FunctionSpace::getTagFromDataPointNo(int dataPointNo) const
109     {
110     //
111     // Get the number of samples and data-points per sample
112     int numSamples = getNumSamples();
113     int numDataPointsPerSample = getNumDPPSample();
114     int numDataPoints = numSamples * numDataPointsPerSample;
115    
116     if (numDataPointsPerSample==0) {
117     throw DataException("FunctionSpace::getTagFromDataPointNo error: no data-points associated with this object.");
118     }
119    
120     if (dataPointNo<0 || dataPointNo>numDataPoints) {
121     throw DataException("FunctionSpace::getTagFromDataPointNo error: invalid data-point number supplied.");
122     }
123    
124     //
125     // Determine the sample number which corresponds to this data-point number
126     int sampleNo = dataPointNo / numDataPointsPerSample;
127    
128     //
129     // Determine the tag number which corresponds to this sample number
130     int tagNo = getTagFromSampleNo(sampleNo);
131    
132     //
133     // return the tag number
134     return(tagNo);
135     }
136    
137 gross 964 int*
138     FunctionSpace::borrowSampleReferenceIDs() const
139 jgs 110 {
140 gross 964 return m_domain->borrowSampleReferenceIDs(m_functionSpaceType);
141 jgs 110 }
142    
143 jgs 117 FunctionSpace&
144     FunctionSpace::operator=(const FunctionSpace& other)
145 jgs 82 {
146     // explicitly defined assignment operator to emphasise pointer copy
147     m_functionSpaceType=other.m_functionSpaceType;
148     m_domain=other.m_domain;
149     return *this;
150     }
151    
152 jgs 117 bool
153     FunctionSpace::operator==(const FunctionSpace& other) const
154 jgs 82 {
155 jgs 121 return ((*(other.m_domain)==*(m_domain)) && (other.m_functionSpaceType==m_functionSpaceType));
156 jgs 82 }
157    
158 jgs 117 bool
159     FunctionSpace::operator!=(const FunctionSpace& other) const
160 jgs 82 {
161 jgs 121 return !(operator==(other));
162 jgs 82 }
163    
164 jgs 117 escript::Data
165     FunctionSpace::getX() const
166 jgs 82 {
167     Data out=escript::Vector(0,*this,true);
168     getDomain().setToX(out);
169 gross 783 out.setProtection();
170 jgs 82 return out;
171     }
172    
173 jgs 117 escript::Data
174     FunctionSpace::getNormal() const
175 jgs 82 {
176     Data out=escript::Vector(0,*this,true);
177     getDomain().setToNormal(out);
178 gross 783 out.setProtection();
179 jgs 82 return out;
180     }
181    
182 jgs 117 escript::Data
183     FunctionSpace::getSize() const
184 jgs 82 {
185     Data out=escript::Scalar(0,*this,true);
186     getDomain().setToSize(out);
187 gross 783 out.setProtection();
188 jgs 82 return out;
189     }
190    
191 gross 767 void
192     FunctionSpace::setTags(const int newTag, const escript::Data& mask) const
193     {
194     if (mask.getFunctionSpace()== *this) {
195     m_domain->setTags(m_functionSpaceType,newTag,mask);
196     } else {
197     throw FunctionSpaceException("illegal function space of mask.");
198     }
199     }
200    
201 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