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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 757 - (show annotations)
Mon Jun 26 13:12:56 2006 UTC (13 years, 2 months ago) by woo409
File size: 4224 byte(s)
+ Merge of intelc_win32 branch (revision 741:755) with trunk. Tested on iVEC altix (run_tests and py_tests all pass)

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 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 return out;
156 }
157
158 escript::Data
159 FunctionSpace::getSize() const
160 {
161 Data out=escript::Scalar(0,*this,true);
162 getDomain().setToSize(out);
163 return out;
164 }
165
166 } // end of namespace

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26