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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 906 - (hide annotations)
Tue Nov 21 05:34:15 2006 UTC (12 years, 7 months ago) by gross
File size: 4538 byte(s)
some minor fixes
1 jgs 115 /* $Id$ */
2 jgs 82 /*
3 elspeth 615 ************************************************************
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 jgs 82 */
13    
14 jgs 480 #include "FunctionSpace.h"
15 jgs 474 #include "FunctionSpaceException.h"
16     #include "Data.h"
17     #include "DataFactory.h"
18 jgs 82
19     #include <iostream>
20     #include <sstream>
21    
22 jgs 121 using namespace std;
23 jgs 149
24 jgs 82 namespace escript {
25    
26     //
27 jgs 149 // Create a null domain for use with any default-constructed function space
28 woo409 757 ESCRIPT_DLL_API NullDomain FunctionSpace::m_nullDomainValue;
29 jgs 82
30     FunctionSpace::FunctionSpace():
31     m_domain(static_cast<AbstractDomain*>(&m_nullDomainValue)),
32     m_functionSpaceType(m_nullDomainValue.getFunctionCode())
33     {
34     }
35    
36 jgs 117 FunctionSpace::FunctionSpace(const AbstractDomain& domain,
37     int functionSpaceType):
38 jgs 82 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 jgs 149 << " for domain: " << m_domain->getDescription();
45 jgs 82 throw FunctionSpaceException(temp.str());
46     }
47     }
48    
49 jgs 117 std::pair<int,int>
50     FunctionSpace::getDataShape() const
51 jgs 82 {
52     return m_domain->getDataShape(m_functionSpaceType);
53     }
54    
55 jgs 117 int
56     FunctionSpace::getTypeCode() const
57 jgs 82 {
58     return m_functionSpaceType;
59     }
60    
61 jgs 117 const
62     AbstractDomain&
63     FunctionSpace::getDomain() const
64 jgs 82 {
65     return *m_domain;
66     }
67    
68 jgs 117 std::string
69     FunctionSpace::toString() const
70 jgs 82 {
71     std::stringstream temp;
72 gross 906 temp << m_domain->functionSpaceTypeAsString(m_functionSpaceType)
73 jgs 82 << " on " << m_domain->getDescription();
74     return temp.str();
75     }
76    
77 jgs 117 int
78     FunctionSpace::getTagFromSampleNo(int sampleNo) const
79 jgs 82 {
80     return m_domain->getTagFromSampleNo(m_functionSpaceType,sampleNo);
81     }
82    
83 jgs 117 int
84 jgs 149 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 jgs 117 FunctionSpace::getReferenceNoFromSampleNo(int sampleNo) const
115 jgs 110 {
116     return m_domain->getReferenceNoFromSampleNo(m_functionSpaceType,sampleNo);
117     }
118    
119 jgs 117 FunctionSpace&
120     FunctionSpace::operator=(const FunctionSpace& other)
121 jgs 82 {
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 jgs 117 bool
130     FunctionSpace::operator==(const FunctionSpace& other) const
131 jgs 82 {
132 jgs 121 return ((*(other.m_domain)==*(m_domain)) && (other.m_functionSpaceType==m_functionSpaceType));
133 jgs 82 }
134    
135 jgs 117 bool
136     FunctionSpace::operator!=(const FunctionSpace& other) const
137 jgs 82 {
138 jgs 121 return !(operator==(other));
139 jgs 82 }
140    
141 jgs 117 escript::Data
142     FunctionSpace::getX() const
143 jgs 82 {
144     Data out=escript::Vector(0,*this,true);
145     getDomain().setToX(out);
146 gross 783 out.setProtection();
147 jgs 82 return out;
148     }
149    
150 jgs 117 escript::Data
151     FunctionSpace::getNormal() const
152 jgs 82 {
153     Data out=escript::Vector(0,*this,true);
154     getDomain().setToNormal(out);
155 gross 783 out.setProtection();
156 jgs 82 return out;
157     }
158    
159 jgs 117 escript::Data
160     FunctionSpace::getSize() const
161 jgs 82 {
162     Data out=escript::Scalar(0,*this,true);
163     getDomain().setToSize(out);
164 gross 783 out.setProtection();
165 jgs 82 return out;
166     }
167    
168 gross 767 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 jgs 82 } // end of namespace

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26