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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 480 - (show annotations)
Wed Feb 1 05:15:12 2006 UTC (13 years, 7 months ago) by jgs
File size: 4530 byte(s)
rationalise #includes and forward declarations

1 /* $Id$ */
2 /*
3 ******************************************************************************
4 * *
5 * COPYRIGHT ACcESS 2004 - All Rights Reserved *
6 * *
7 * This software is the property of ACcESS. No part of this code *
8 * may be copied in any form or by any means without the expressed written *
9 * consent of ACcESS. Copying, use or modification of this software *
10 * by any unauthorised person is illegal unless that person has a software *
11 * license agreement with ACcESS. *
12 * *
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 FunctionSpace::m_nullDomainValue;
31
32 FunctionSpace::FunctionSpace():
33 m_domain(static_cast<AbstractDomain*>(&m_nullDomainValue)),
34 m_functionSpaceType(m_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 std::string
71 FunctionSpace::toString() const
72 {
73 std::stringstream temp;
74 temp << "Function space type: "
75 << m_domain->functionSpaceTypeAsString(m_functionSpaceType)
76 << " on " << m_domain->getDescription();
77 return temp.str();
78 }
79
80 int
81 FunctionSpace::getTagFromSampleNo(int sampleNo) const
82 {
83 return m_domain->getTagFromSampleNo(m_functionSpaceType,sampleNo);
84 }
85
86 int
87 FunctionSpace::getTagFromDataPointNo(int dataPointNo) const
88 {
89 //
90 // Get the number of samples and data-points per sample
91 int numSamples = getNumSamples();
92 int numDataPointsPerSample = getNumDPPSample();
93 int numDataPoints = numSamples * numDataPointsPerSample;
94
95 if (numDataPointsPerSample==0) {
96 throw DataException("FunctionSpace::getTagFromDataPointNo error: no data-points associated with this object.");
97 }
98
99 if (dataPointNo<0 || dataPointNo>numDataPoints) {
100 throw DataException("FunctionSpace::getTagFromDataPointNo error: invalid data-point number supplied.");
101 }
102
103 //
104 // Determine the sample number which corresponds to this data-point number
105 int sampleNo = dataPointNo / numDataPointsPerSample;
106
107 //
108 // Determine the tag number which corresponds to this sample number
109 int tagNo = getTagFromSampleNo(sampleNo);
110
111 //
112 // return the tag number
113 return(tagNo);
114 }
115
116 int
117 FunctionSpace::getReferenceNoFromSampleNo(int sampleNo) const
118 {
119 return m_domain->getReferenceNoFromSampleNo(m_functionSpaceType,sampleNo);
120 }
121
122 FunctionSpace&
123 FunctionSpace::operator=(const FunctionSpace& other)
124 {
125 // explicitly defined assignment operator to emphasise pointer copy
126 m_nullDomainValue=other.m_nullDomainValue;
127 m_functionSpaceType=other.m_functionSpaceType;
128 m_domain=other.m_domain;
129 return *this;
130 }
131
132 bool
133 FunctionSpace::operator==(const FunctionSpace& other) const
134 {
135 return ((*(other.m_domain)==*(m_domain)) && (other.m_functionSpaceType==m_functionSpaceType));
136 }
137
138 bool
139 FunctionSpace::operator!=(const FunctionSpace& other) const
140 {
141 return !(operator==(other));
142 }
143
144 escript::Data
145 FunctionSpace::getX() const
146 {
147 Data out=escript::Vector(0,*this,true);
148 getDomain().setToX(out);
149 return out;
150 }
151
152 escript::Data
153 FunctionSpace::getNormal() const
154 {
155 Data out=escript::Vector(0,*this,true);
156 getDomain().setToNormal(out);
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 return out;
166 }
167
168 } // end of namespace

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26