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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 480 - (hide 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 jgs 115 /* $Id$ */
2 jgs 82 /*
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 jgs 480 #include "FunctionSpace.h"
17 jgs 474 #include "FunctionSpaceException.h"
18     #include "Data.h"
19     #include "DataFactory.h"
20 jgs 82
21     #include <iostream>
22     #include <sstream>
23    
24 jgs 121 using namespace std;
25 jgs 149
26 jgs 82 namespace escript {
27    
28     //
29 jgs 149 // Create a null domain for use with any default-constructed function space
30 jgs 82 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 jgs 117 FunctionSpace::FunctionSpace(const AbstractDomain& domain,
39     int functionSpaceType):
40 jgs 82 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 jgs 149 << " for domain: " << m_domain->getDescription();
47 jgs 82 throw FunctionSpaceException(temp.str());
48     }
49     }
50    
51 jgs 117 std::pair<int,int>
52     FunctionSpace::getDataShape() const
53 jgs 82 {
54     return m_domain->getDataShape(m_functionSpaceType);
55     }
56    
57 jgs 117 int
58     FunctionSpace::getTypeCode() const
59 jgs 82 {
60     return m_functionSpaceType;
61     }
62    
63 jgs 117 const
64     AbstractDomain&
65     FunctionSpace::getDomain() const
66 jgs 82 {
67     return *m_domain;
68     }
69    
70 jgs 117 std::string
71     FunctionSpace::toString() const
72 jgs 82 {
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 jgs 117 int
81     FunctionSpace::getTagFromSampleNo(int sampleNo) const
82 jgs 82 {
83     return m_domain->getTagFromSampleNo(m_functionSpaceType,sampleNo);
84     }
85    
86 jgs 117 int
87 jgs 149 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 jgs 117 FunctionSpace::getReferenceNoFromSampleNo(int sampleNo) const
118 jgs 110 {
119     return m_domain->getReferenceNoFromSampleNo(m_functionSpaceType,sampleNo);
120     }
121    
122 jgs 117 FunctionSpace&
123     FunctionSpace::operator=(const FunctionSpace& other)
124 jgs 82 {
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 jgs 117 bool
133     FunctionSpace::operator==(const FunctionSpace& other) const
134 jgs 82 {
135 jgs 121 return ((*(other.m_domain)==*(m_domain)) && (other.m_functionSpaceType==m_functionSpaceType));
136 jgs 82 }
137    
138 jgs 117 bool
139     FunctionSpace::operator!=(const FunctionSpace& other) const
140 jgs 82 {
141 jgs 121 return !(operator==(other));
142 jgs 82 }
143    
144 jgs 117 escript::Data
145     FunctionSpace::getX() const
146 jgs 82 {
147     Data out=escript::Vector(0,*this,true);
148     getDomain().setToX(out);
149     return out;
150     }
151    
152 jgs 117 escript::Data
153     FunctionSpace::getNormal() const
154 jgs 82 {
155     Data out=escript::Vector(0,*this,true);
156     getDomain().setToNormal(out);
157     return out;
158     }
159    
160 jgs 117 escript::Data
161     FunctionSpace::getSize() const
162 jgs 82 {
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