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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 149 - (show annotations)
Thu Sep 1 03:31:39 2005 UTC (14 years, 1 month ago) by jgs
Original Path: trunk/esys2/escript/src/Data/FunctionSpace.cpp
File size: 4634 byte(s)
Merge of development branch dev-02 back to main trunk on 2005-09-01

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 "escript/Data/AbstractContinuousDomain.h"
17 #include "escript/Data/FunctionSpaceException.h"
18 #include "escript/Data/Data.h"
19 #include "escript/Data/DataFactory.h"
20
21 #include "escript/Data/FunctionSpace.h"
22
23 #include <iostream>
24 #include <sstream>
25
26 using namespace std;
27
28 namespace escript {
29
30 //
31 // Create a null domain for use with any default-constructed function space
32 NullDomain FunctionSpace::m_nullDomainValue;
33
34 FunctionSpace::FunctionSpace():
35 m_domain(static_cast<AbstractDomain*>(&m_nullDomainValue)),
36 m_functionSpaceType(m_nullDomainValue.getFunctionCode())
37 {
38 }
39
40 FunctionSpace::FunctionSpace(const AbstractDomain& domain,
41 int functionSpaceType):
42 m_domain(dynamic_cast<const AbstractDomain*>(&domain)),
43 m_functionSpaceType(functionSpaceType)
44 {
45 if (!m_domain->isValidFunctionSpaceType(functionSpaceType)) {
46 std::stringstream temp;
47 temp << "Invalid function space type: " << functionSpaceType
48 << " for domain: " << m_domain->getDescription();
49 throw FunctionSpaceException(temp.str());
50 }
51 }
52
53 std::pair<int,int>
54 FunctionSpace::getDataShape() const
55 {
56 return m_domain->getDataShape(m_functionSpaceType);
57 }
58
59 int
60 FunctionSpace::getTypeCode() const
61 {
62 return m_functionSpaceType;
63 }
64
65 const
66 AbstractDomain&
67 FunctionSpace::getDomain() const
68 {
69 return *m_domain;
70 }
71
72 std::string
73 FunctionSpace::toString() const
74 {
75 std::stringstream temp;
76 temp << "Function space type: "
77 << m_domain->functionSpaceTypeAsString(m_functionSpaceType)
78 << " on " << m_domain->getDescription();
79 return temp.str();
80 }
81
82 int
83 FunctionSpace::getTagFromSampleNo(int sampleNo) const
84 {
85 return m_domain->getTagFromSampleNo(m_functionSpaceType,sampleNo);
86 }
87
88 int
89 FunctionSpace::getTagFromDataPointNo(int dataPointNo) const
90 {
91 //
92 // Get the number of samples and data-points per sample
93 int numSamples = getNumSamples();
94 int numDataPointsPerSample = getNumDPPSample();
95 int numDataPoints = numSamples * numDataPointsPerSample;
96
97 if (numDataPointsPerSample==0) {
98 throw DataException("FunctionSpace::getTagFromDataPointNo error: no data-points associated with this object.");
99 }
100
101 if (dataPointNo<0 || dataPointNo>numDataPoints) {
102 throw DataException("FunctionSpace::getTagFromDataPointNo error: invalid data-point number supplied.");
103 }
104
105 //
106 // Determine the sample number which corresponds to this data-point number
107 int sampleNo = dataPointNo / numDataPointsPerSample;
108
109 //
110 // Determine the tag number which corresponds to this sample number
111 int tagNo = getTagFromSampleNo(sampleNo);
112
113 //
114 // return the tag number
115 return(tagNo);
116 }
117
118 int
119 FunctionSpace::getReferenceNoFromSampleNo(int sampleNo) const
120 {
121 return m_domain->getReferenceNoFromSampleNo(m_functionSpaceType,sampleNo);
122 }
123
124 FunctionSpace&
125 FunctionSpace::operator=(const FunctionSpace& other)
126 {
127 // explicitly defined assignment operator to emphasise pointer copy
128 m_nullDomainValue=other.m_nullDomainValue;
129 m_functionSpaceType=other.m_functionSpaceType;
130 m_domain=other.m_domain;
131 return *this;
132 }
133
134 bool
135 FunctionSpace::operator==(const FunctionSpace& other) const
136 {
137 return ((*(other.m_domain)==*(m_domain)) && (other.m_functionSpaceType==m_functionSpaceType));
138 }
139
140 bool
141 FunctionSpace::operator!=(const FunctionSpace& other) const
142 {
143 return !(operator==(other));
144 }
145
146 escript::Data
147 FunctionSpace::getX() const
148 {
149 Data out=escript::Vector(0,*this,true);
150 getDomain().setToX(out);
151 return out;
152 }
153
154 escript::Data
155 FunctionSpace::getNormal() const
156 {
157 Data out=escript::Vector(0,*this,true);
158 getDomain().setToNormal(out);
159 return out;
160 }
161
162 escript::Data
163 FunctionSpace::getSize() const
164 {
165 Data out=escript::Scalar(0,*this,true);
166 getDomain().setToSize(out);
167 return out;
168 }
169
170 } // end of namespace

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26