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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 149 - (hide annotations)
Thu Sep 1 03:31:39 2005 UTC (14 years, 2 months 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 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     #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 jgs 121 using namespace std;
27 jgs 149
28 jgs 82 namespace escript {
29    
30     //
31 jgs 149 // Create a null domain for use with any default-constructed function space
32 jgs 82 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 jgs 117 FunctionSpace::FunctionSpace(const AbstractDomain& domain,
41     int functionSpaceType):
42 jgs 82 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 jgs 149 << " for domain: " << m_domain->getDescription();
49 jgs 82 throw FunctionSpaceException(temp.str());
50     }
51     }
52    
53 jgs 117 std::pair<int,int>
54     FunctionSpace::getDataShape() const
55 jgs 82 {
56     return m_domain->getDataShape(m_functionSpaceType);
57     }
58    
59 jgs 117 int
60     FunctionSpace::getTypeCode() const
61 jgs 82 {
62     return m_functionSpaceType;
63     }
64    
65 jgs 117 const
66     AbstractDomain&
67     FunctionSpace::getDomain() const
68 jgs 82 {
69     return *m_domain;
70     }
71    
72 jgs 117 std::string
73     FunctionSpace::toString() const
74 jgs 82 {
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 jgs 117 int
83     FunctionSpace::getTagFromSampleNo(int sampleNo) const
84 jgs 82 {
85     return m_domain->getTagFromSampleNo(m_functionSpaceType,sampleNo);
86     }
87    
88 jgs 117 int
89 jgs 149 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 jgs 117 FunctionSpace::getReferenceNoFromSampleNo(int sampleNo) const
120 jgs 110 {
121     return m_domain->getReferenceNoFromSampleNo(m_functionSpaceType,sampleNo);
122     }
123    
124 jgs 117 FunctionSpace&
125     FunctionSpace::operator=(const FunctionSpace& other)
126 jgs 82 {
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 jgs 117 bool
135     FunctionSpace::operator==(const FunctionSpace& other) const
136 jgs 82 {
137 jgs 121 return ((*(other.m_domain)==*(m_domain)) && (other.m_functionSpaceType==m_functionSpaceType));
138 jgs 82 }
139    
140 jgs 117 bool
141     FunctionSpace::operator!=(const FunctionSpace& other) const
142 jgs 82 {
143 jgs 121 return !(operator==(other));
144 jgs 82 }
145    
146 jgs 117 escript::Data
147     FunctionSpace::getX() const
148 jgs 82 {
149     Data out=escript::Vector(0,*this,true);
150     getDomain().setToX(out);
151     return out;
152     }
153    
154 jgs 117 escript::Data
155     FunctionSpace::getNormal() const
156 jgs 82 {
157     Data out=escript::Vector(0,*this,true);
158     getDomain().setToNormal(out);
159     return out;
160     }
161    
162 jgs 117 escript::Data
163     FunctionSpace::getSize() const
164 jgs 82 {
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