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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 767 - (hide annotations)
Fri Jun 30 07:29:08 2006 UTC (13 years, 4 months ago) by gross
File size: 4504 byte(s)
new FunctionSpace method setTags added
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     temp << "Function space type: "
73     << m_domain->functionSpaceTypeAsString(m_functionSpaceType)
74     << " on " << m_domain->getDescription();
75     return temp.str();
76     }
77    
78 jgs 117 int
79     FunctionSpace::getTagFromSampleNo(int sampleNo) const
80 jgs 82 {
81     return m_domain->getTagFromSampleNo(m_functionSpaceType,sampleNo);
82     }
83    
84 jgs 117 int
85 jgs 149 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 jgs 117 FunctionSpace::getReferenceNoFromSampleNo(int sampleNo) const
116 jgs 110 {
117     return m_domain->getReferenceNoFromSampleNo(m_functionSpaceType,sampleNo);
118     }
119    
120 jgs 117 FunctionSpace&
121     FunctionSpace::operator=(const FunctionSpace& other)
122 jgs 82 {
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 jgs 117 bool
131     FunctionSpace::operator==(const FunctionSpace& other) const
132 jgs 82 {
133 jgs 121 return ((*(other.m_domain)==*(m_domain)) && (other.m_functionSpaceType==m_functionSpaceType));
134 jgs 82 }
135    
136 jgs 117 bool
137     FunctionSpace::operator!=(const FunctionSpace& other) const
138 jgs 82 {
139 jgs 121 return !(operator==(other));
140 jgs 82 }
141    
142 jgs 117 escript::Data
143     FunctionSpace::getX() const
144 jgs 82 {
145     Data out=escript::Vector(0,*this,true);
146     getDomain().setToX(out);
147     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     return out;
156     }
157    
158 jgs 117 escript::Data
159     FunctionSpace::getSize() const
160 jgs 82 {
161     Data out=escript::Scalar(0,*this,true);
162     getDomain().setToSize(out);
163     return out;
164     }
165    
166 gross 767 void
167     FunctionSpace::setTags(const int newTag, const escript::Data& mask) const
168     {
169     if (mask.getFunctionSpace()== *this) {
170     m_domain->setTags(m_functionSpaceType,newTag,mask);
171     } else {
172     throw FunctionSpaceException("illegal function space of mask.");
173     }
174     }
175    
176 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