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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26