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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 906 - (show annotations)
Tue Nov 21 05:34:15 2006 UTC (12 years, 8 months ago) by gross
File size: 4538 byte(s)
some minor fixes
1 /* $Id$ */
2 /*
3 ************************************************************
4 * Copyright 2006 by ACcESS MNRF *
5 * *
6 * http://www.access.edu.au *
7 * Primary Business: Queensland, Australia *
8 * Licensed under the Open Software License version 3.0 *
9 * http://www.opensource.org/licenses/osl-3.0.php *
10 * *
11 ************************************************************
12 */
13
14 #include "FunctionSpace.h"
15 #include "FunctionSpaceException.h"
16 #include "Data.h"
17 #include "DataFactory.h"
18
19 #include <iostream>
20 #include <sstream>
21
22 using namespace std;
23
24 namespace escript {
25
26 //
27 // Create a null domain for use with any default-constructed function space
28 ESCRIPT_DLL_API NullDomain FunctionSpace::m_nullDomainValue;
29
30 FunctionSpace::FunctionSpace():
31 m_domain(static_cast<AbstractDomain*>(&m_nullDomainValue)),
32 m_functionSpaceType(m_nullDomainValue.getFunctionCode())
33 {
34 }
35
36 FunctionSpace::FunctionSpace(const AbstractDomain& domain,
37 int functionSpaceType):
38 m_domain(dynamic_cast<const AbstractDomain*>(&domain)),
39 m_functionSpaceType(functionSpaceType)
40 {
41 if (!m_domain->isValidFunctionSpaceType(functionSpaceType)) {
42 std::stringstream temp;
43 temp << "Invalid function space type: " << functionSpaceType
44 << " for domain: " << m_domain->getDescription();
45 throw FunctionSpaceException(temp.str());
46 }
47 }
48
49 std::pair<int,int>
50 FunctionSpace::getDataShape() const
51 {
52 return m_domain->getDataShape(m_functionSpaceType);
53 }
54
55 int
56 FunctionSpace::getTypeCode() const
57 {
58 return m_functionSpaceType;
59 }
60
61 const
62 AbstractDomain&
63 FunctionSpace::getDomain() const
64 {
65 return *m_domain;
66 }
67
68 std::string
69 FunctionSpace::toString() const
70 {
71 std::stringstream temp;
72 temp << m_domain->functionSpaceTypeAsString(m_functionSpaceType)
73 << " on " << m_domain->getDescription();
74 return temp.str();
75 }
76
77 int
78 FunctionSpace::getTagFromSampleNo(int sampleNo) const
79 {
80 return m_domain->getTagFromSampleNo(m_functionSpaceType,sampleNo);
81 }
82
83 int
84 FunctionSpace::getTagFromDataPointNo(int dataPointNo) const
85 {
86 //
87 // Get the number of samples and data-points per sample
88 int numSamples = getNumSamples();
89 int numDataPointsPerSample = getNumDPPSample();
90 int numDataPoints = numSamples * numDataPointsPerSample;
91
92 if (numDataPointsPerSample==0) {
93 throw DataException("FunctionSpace::getTagFromDataPointNo error: no data-points associated with this object.");
94 }
95
96 if (dataPointNo<0 || dataPointNo>numDataPoints) {
97 throw DataException("FunctionSpace::getTagFromDataPointNo error: invalid data-point number supplied.");
98 }
99
100 //
101 // Determine the sample number which corresponds to this data-point number
102 int sampleNo = dataPointNo / numDataPointsPerSample;
103
104 //
105 // Determine the tag number which corresponds to this sample number
106 int tagNo = getTagFromSampleNo(sampleNo);
107
108 //
109 // return the tag number
110 return(tagNo);
111 }
112
113 int
114 FunctionSpace::getReferenceNoFromSampleNo(int sampleNo) const
115 {
116 return m_domain->getReferenceNoFromSampleNo(m_functionSpaceType,sampleNo);
117 }
118
119 FunctionSpace&
120 FunctionSpace::operator=(const FunctionSpace& other)
121 {
122 // explicitly defined assignment operator to emphasise pointer copy
123 m_nullDomainValue=other.m_nullDomainValue;
124 m_functionSpaceType=other.m_functionSpaceType;
125 m_domain=other.m_domain;
126 return *this;
127 }
128
129 bool
130 FunctionSpace::operator==(const FunctionSpace& other) const
131 {
132 return ((*(other.m_domain)==*(m_domain)) && (other.m_functionSpaceType==m_functionSpaceType));
133 }
134
135 bool
136 FunctionSpace::operator!=(const FunctionSpace& other) const
137 {
138 return !(operator==(other));
139 }
140
141 escript::Data
142 FunctionSpace::getX() const
143 {
144 Data out=escript::Vector(0,*this,true);
145 getDomain().setToX(out);
146 out.setProtection();
147 return out;
148 }
149
150 escript::Data
151 FunctionSpace::getNormal() const
152 {
153 Data out=escript::Vector(0,*this,true);
154 getDomain().setToNormal(out);
155 out.setProtection();
156 return out;
157 }
158
159 escript::Data
160 FunctionSpace::getSize() const
161 {
162 Data out=escript::Scalar(0,*this,true);
163 getDomain().setToSize(out);
164 out.setProtection();
165 return out;
166 }
167
168 void
169 FunctionSpace::setTags(const int newTag, const escript::Data& mask) const
170 {
171 if (mask.getFunctionSpace()== *this) {
172 m_domain->setTags(m_functionSpaceType,newTag,mask);
173 } else {
174 throw FunctionSpaceException("illegal function space of mask.");
175 }
176 }
177
178 } // end of namespace

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26