/[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 1421 - (hide annotations)
Tue Feb 26 10:17:33 2008 UTC (15 years, 1 month ago) by trankine
File size: 4709 byte(s)
In this version

1. with DEBUG_PY_STRINGS not defined, it succeeds to run repeated str(a_fn_space) 50000 times. However it fails run_tests and py_tests in the same way it did previously.
2. with DEBUG_PY_STRINGS it uses toPyString, and almost passes run_tests, and gets far further into py_tests, to a point that looks quite different.
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 1419 if( type_str.empty() )
74     {
75     std::stringstream temp;
76     temp << m_domain->functionSpaceTypeAsString(m_functionSpaceType)
77     << " on " << m_domain->getDescription();
78    
79     type_str = temp.str();
80     }
81     return type_str;
82     }
83    
84    
85 trankine 1421 #ifdef DEBUG_PY_STRINGS
86 trankine 1419 PyObject *
87     FunctionSpace::toPyString() const
88     {
89 jgs 82 std::stringstream temp;
90 trankine 1419
91 ksteube 1312 temp << m_domain->functionSpaceTypeAsString(m_functionSpaceType)
92     << " on " << m_domain->getDescription();
93 trankine 1419
94     boost::python::to_python_value<const std::string &> cvtr;
95    
96     return cvtr(temp.str());
97 jgs 82 }
98 trankine 1419 #endif
99 jgs 82
100 jgs 117 int
101     FunctionSpace::getTagFromSampleNo(int sampleNo) const
102 jgs 82 {
103     return m_domain->getTagFromSampleNo(m_functionSpaceType,sampleNo);
104     }
105    
106 jgs 117 int
107 jgs 149 FunctionSpace::getTagFromDataPointNo(int dataPointNo) const
108     {
109     //
110     // Get the number of samples and data-points per sample
111     int numSamples = getNumSamples();
112     int numDataPointsPerSample = getNumDPPSample();
113     int numDataPoints = numSamples * numDataPointsPerSample;
114    
115     if (numDataPointsPerSample==0) {
116     throw DataException("FunctionSpace::getTagFromDataPointNo error: no data-points associated with this object.");
117     }
118    
119     if (dataPointNo<0 || dataPointNo>numDataPoints) {
120     throw DataException("FunctionSpace::getTagFromDataPointNo error: invalid data-point number supplied.");
121     }
122    
123     //
124     // Determine the sample number which corresponds to this data-point number
125     int sampleNo = dataPointNo / numDataPointsPerSample;
126    
127     //
128     // Determine the tag number which corresponds to this sample number
129     int tagNo = getTagFromSampleNo(sampleNo);
130    
131     //
132     // return the tag number
133     return(tagNo);
134     }
135    
136 gross 964 int*
137     FunctionSpace::borrowSampleReferenceIDs() const
138 jgs 110 {
139 gross 964 return m_domain->borrowSampleReferenceIDs(m_functionSpaceType);
140 jgs 110 }
141    
142 jgs 117 FunctionSpace&
143     FunctionSpace::operator=(const FunctionSpace& other)
144 jgs 82 {
145     // explicitly defined assignment operator to emphasise pointer copy
146     m_functionSpaceType=other.m_functionSpaceType;
147     m_domain=other.m_domain;
148     return *this;
149     }
150    
151 jgs 117 bool
152     FunctionSpace::operator==(const FunctionSpace& other) const
153 jgs 82 {
154 jgs 121 return ((*(other.m_domain)==*(m_domain)) && (other.m_functionSpaceType==m_functionSpaceType));
155 jgs 82 }
156    
157 jgs 117 bool
158     FunctionSpace::operator!=(const FunctionSpace& other) const
159 jgs 82 {
160 jgs 121 return !(operator==(other));
161 jgs 82 }
162    
163 jgs 117 escript::Data
164     FunctionSpace::getX() const
165 jgs 82 {
166     Data out=escript::Vector(0,*this,true);
167     getDomain().setToX(out);
168 gross 783 out.setProtection();
169 jgs 82 return out;
170     }
171    
172 jgs 117 escript::Data
173     FunctionSpace::getNormal() const
174 jgs 82 {
175     Data out=escript::Vector(0,*this,true);
176     getDomain().setToNormal(out);
177 gross 783 out.setProtection();
178 jgs 82 return out;
179     }
180    
181 jgs 117 escript::Data
182     FunctionSpace::getSize() const
183 jgs 82 {
184     Data out=escript::Scalar(0,*this,true);
185     getDomain().setToSize(out);
186 gross 783 out.setProtection();
187 jgs 82 return out;
188     }
189    
190 gross 767 void
191     FunctionSpace::setTags(const int newTag, const escript::Data& mask) const
192     {
193     if (mask.getFunctionSpace()== *this) {
194     m_domain->setTags(m_functionSpaceType,newTag,mask);
195     } else {
196     throw FunctionSpaceException("illegal function space of mask.");
197     }
198     }
199    
200 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