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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 783 - (show annotations)
Tue Jul 18 01:32:50 2006 UTC (13 years, 2 months ago) by gross
File size: 4573 byte(s)
coordinates, element size and normals returned by corresponding
FunctionSpace mesthods are now protected against updates. So 
+=, -=, *=, /=, setTaggedValue, fillFromNumArray will through an
excpetion.

The FunctionSpace class does nut buffer the oordinates, element size and
normals yet.


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 << "Function space type: "
73 << m_domain->functionSpaceTypeAsString(m_functionSpaceType)
74 << " on " << m_domain->getDescription();
75 return temp.str();
76 }
77
78 int
79 FunctionSpace::getTagFromSampleNo(int sampleNo) const
80 {
81 return m_domain->getTagFromSampleNo(m_functionSpaceType,sampleNo);
82 }
83
84 int
85 FunctionSpace::getTagFromDataPointNo(int dataPointNo) const
86 {
87 //
88 // Get the number of samples and data-points per sample
89 int numSamples = getNumSamples();
90 int numDataPointsPerSample = getNumDPPSample();
91 int numDataPoints = numSamples * numDataPointsPerSample;
92
93 if (numDataPointsPerSample==0) {
94 throw DataException("FunctionSpace::getTagFromDataPointNo error: no data-points associated with this object.");
95 }
96
97 if (dataPointNo<0 || dataPointNo>numDataPoints) {
98 throw DataException("FunctionSpace::getTagFromDataPointNo error: invalid data-point number supplied.");
99 }
100
101 //
102 // Determine the sample number which corresponds to this data-point number
103 int sampleNo = dataPointNo / numDataPointsPerSample;
104
105 //
106 // Determine the tag number which corresponds to this sample number
107 int tagNo = getTagFromSampleNo(sampleNo);
108
109 //
110 // return the tag number
111 return(tagNo);
112 }
113
114 int
115 FunctionSpace::getReferenceNoFromSampleNo(int sampleNo) const
116 {
117 return m_domain->getReferenceNoFromSampleNo(m_functionSpaceType,sampleNo);
118 }
119
120 FunctionSpace&
121 FunctionSpace::operator=(const FunctionSpace& other)
122 {
123 // explicitly defined assignment operator to emphasise pointer copy
124 m_nullDomainValue=other.m_nullDomainValue;
125 m_functionSpaceType=other.m_functionSpaceType;
126 m_domain=other.m_domain;
127 return *this;
128 }
129
130 bool
131 FunctionSpace::operator==(const FunctionSpace& other) const
132 {
133 return ((*(other.m_domain)==*(m_domain)) && (other.m_functionSpaceType==m_functionSpaceType));
134 }
135
136 bool
137 FunctionSpace::operator!=(const FunctionSpace& other) const
138 {
139 return !(operator==(other));
140 }
141
142 escript::Data
143 FunctionSpace::getX() const
144 {
145 Data out=escript::Vector(0,*this,true);
146 getDomain().setToX(out);
147 out.setProtection();
148 return out;
149 }
150
151 escript::Data
152 FunctionSpace::getNormal() const
153 {
154 Data out=escript::Vector(0,*this,true);
155 getDomain().setToNormal(out);
156 out.setProtection();
157 return out;
158 }
159
160 escript::Data
161 FunctionSpace::getSize() const
162 {
163 Data out=escript::Scalar(0,*this,true);
164 getDomain().setToSize(out);
165 out.setProtection();
166 return out;
167 }
168
169 void
170 FunctionSpace::setTags(const int newTag, const escript::Data& mask) const
171 {
172 if (mask.getFunctionSpace()== *this) {
173 m_domain->setTags(m_functionSpaceType,newTag,mask);
174 } else {
175 throw FunctionSpaceException("illegal function space of mask.");
176 }
177 }
178
179 } // end of namespace

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26