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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1387 - (hide annotations)
Fri Jan 11 07:45:26 2008 UTC (11 years, 6 months ago) by trankine
Original Path: temp/escript/src/FunctionSpace.cpp
File size: 4378 byte(s)
Restore the trunk that existed before the windows changes were committed to the (now moved to branches) old trunk.
1 ksteube 1312
2 jgs 115 /* $Id$ */
3 jgs 82
4 ksteube 1312 /*******************************************************
5     *
6     * Copyright 2003-2007 by ACceSS MNRF
7     * Copyright 2007 by University of Queensland
8     *
9     * http://esscc.uq.edu.au
10     * Primary Business: Queensland, Australia
11     * Licensed under the Open Software License version 3.0
12     * http://www.opensource.org/licenses/osl-3.0.php
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 woo409 757 ESCRIPT_DLL_API NullDomain FunctionSpace::m_nullDomainValue;
31 jgs 82
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 ksteube 1312 temp << m_domain->functionSpaceTypeAsString(m_functionSpaceType)
75     << " on " << m_domain->getDescription();
76 jgs 82 return temp.str();
77     }
78    
79 jgs 117 int
80     FunctionSpace::getTagFromSampleNo(int sampleNo) const
81 jgs 82 {
82     return m_domain->getTagFromSampleNo(m_functionSpaceType,sampleNo);
83     }
84    
85 jgs 117 int
86 jgs 149 FunctionSpace::getTagFromDataPointNo(int dataPointNo) const
87     {
88     //
89     // Get the number of samples and data-points per sample
90     int numSamples = getNumSamples();
91     int numDataPointsPerSample = getNumDPPSample();
92     int numDataPoints = numSamples * numDataPointsPerSample;
93    
94     if (numDataPointsPerSample==0) {
95     throw DataException("FunctionSpace::getTagFromDataPointNo error: no data-points associated with this object.");
96     }
97    
98     if (dataPointNo<0 || dataPointNo>numDataPoints) {
99     throw DataException("FunctionSpace::getTagFromDataPointNo error: invalid data-point number supplied.");
100     }
101    
102     //
103     // Determine the sample number which corresponds to this data-point number
104     int sampleNo = dataPointNo / numDataPointsPerSample;
105    
106     //
107     // Determine the tag number which corresponds to this sample number
108     int tagNo = getTagFromSampleNo(sampleNo);
109    
110     //
111     // return the tag number
112     return(tagNo);
113     }
114    
115 gross 964 int*
116     FunctionSpace::borrowSampleReferenceIDs() const
117 jgs 110 {
118 gross 964 return m_domain->borrowSampleReferenceIDs(m_functionSpaceType);
119 jgs 110 }
120    
121 jgs 117 FunctionSpace&
122     FunctionSpace::operator=(const FunctionSpace& other)
123 jgs 82 {
124     // explicitly defined assignment operator to emphasise pointer copy
125     m_nullDomainValue=other.m_nullDomainValue;
126     m_functionSpaceType=other.m_functionSpaceType;
127     m_domain=other.m_domain;
128     return *this;
129     }
130    
131 jgs 117 bool
132     FunctionSpace::operator==(const FunctionSpace& other) const
133 jgs 82 {
134 jgs 121 return ((*(other.m_domain)==*(m_domain)) && (other.m_functionSpaceType==m_functionSpaceType));
135 jgs 82 }
136    
137 jgs 117 bool
138     FunctionSpace::operator!=(const FunctionSpace& other) const
139 jgs 82 {
140 jgs 121 return !(operator==(other));
141 jgs 82 }
142    
143 jgs 117 escript::Data
144     FunctionSpace::getX() const
145 jgs 82 {
146     Data out=escript::Vector(0,*this,true);
147     getDomain().setToX(out);
148 gross 783 out.setProtection();
149 jgs 82 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 gross 783 out.setProtection();
158 jgs 82 return out;
159     }
160    
161 jgs 117 escript::Data
162     FunctionSpace::getSize() const
163 jgs 82 {
164     Data out=escript::Scalar(0,*this,true);
165     getDomain().setToSize(out);
166 gross 783 out.setProtection();
167 jgs 82 return out;
168     }
169    
170 gross 767 void
171     FunctionSpace::setTags(const int newTag, const escript::Data& mask) const
172     {
173     if (mask.getFunctionSpace()== *this) {
174     m_domain->setTags(m_functionSpaceType,newTag,mask);
175     } else {
176     throw FunctionSpaceException("illegal function space of mask.");
177     }
178     }
179    
180 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