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

Contents of /trunk/escript/src/TestDomain.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4286 - (show annotations)
Thu Mar 7 04:28:11 2013 UTC (6 years, 7 months ago) by caltinay
File size: 6043 byte(s)
Assorted spelling fixes.

1
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2013 by University of Queensland
5 * http://www.uq.edu.au
6 *
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 * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 * Development since 2012 by School of Earth Sciences
13 *
14 *****************************************************************************/
15
16
17 #include "DomainException.h"
18 #include "TestDomain.h"
19 #include "Data.h"
20 #include "Utils.h" // for MPI functions
21
22 namespace escript {
23
24 namespace {
25 const int defaultList[1]={0}; // an array to return in borrowListOfTagsInUse();
26 const int TestDomainFS=1; // Null domains only support 1 functionspace type.
27 // The choice of =1 as the value is arbitrary
28 }
29
30
31 TestDomain::TestDomain(int pointspersample, int numsamples, int dpsize)
32 : m_samples(numsamples), m_dpps(pointspersample), m_dpsize(dpsize)
33 {
34 #ifdef ESYS_MPI
35 int world=getMPISizeWorld();
36 int rank=getMPIRankWorld();
37 m_samples/=world;
38 if (rank<(numsamples%world))
39 {
40 m_samples++;
41 }
42 #endif
43 m_samplerefids=new int[numsamples];
44 for (int i=0;i<numsamples;++i)
45 {
46 m_samplerefids[i]=i+10; // the +10 is arbitrary.
47 } // so these ids look different from others
48 }
49
50
51 TestDomain::~TestDomain()
52 {
53 delete[] m_samplerefids;
54 }
55
56 bool TestDomain::isValidFunctionSpaceType(int functionSpaceType) const
57 {
58 return (functionSpaceType==TestDomainFS);
59 }
60
61 std::string TestDomain::getDescription() const
62 {
63 return "TestDomain";
64 }
65
66 std::string TestDomain::functionSpaceTypeAsString(int functionSpaceType) const
67 {
68 return "Default_FunctionSpace";
69 }
70
71 void TestDomain::interpolateOnDomain(Data& target,const Data& source) const
72 {
73 if (source.getFunctionSpace().getDomain().get()!=this)
74 throw DomainException("Error - Illegal domain of interpolant.");
75 if (target.getFunctionSpace().getDomain().get()!=this)
76 throw DomainException("Error - Illegal domain of interpolation target.");
77 target=source;
78 }
79
80 bool TestDomain::probeInterpolationOnDomain(int functionSpaceType_source,int functionSpaceType_target) const
81 {
82 if ((functionSpaceType_source!=functionSpaceType_target) || (functionSpaceType_target!=TestDomainFS))
83 {
84 throw DomainException("Error - Illegal function type for TestDomain.");
85 }
86 return true;
87 }
88
89 void TestDomain::interpolateACross(Data& target, const Data& source) const
90 {
91 throw DomainException("Error - interpolation to the TestDomain not supported.");
92 }
93
94 bool TestDomain::probeInterpolationACross(int functionSpaceType_source,const AbstractDomain& targetDomain, int functionSpaceType_target) const
95 {
96 return false;
97 }
98
99 ESCRIPT_DLL_API
100 bool TestDomain::commonFunctionSpace(const std::vector<int>& fs, int& resultcode) const
101 {
102 for (int i=0;i<fs.size();++i)
103 {
104 if (fs[i]!=TestDomainFS)
105 {
106 return false;
107 }
108 }
109 resultcode=TestDomainFS;
110 return true;
111 }
112
113
114 int TestDomain::getDefaultCode() const
115 {
116 return TestDomainFS;
117 }
118
119 int TestDomain::getContinuousFunctionCode() const
120 {
121 return TestDomainFS;
122 }
123
124 int TestDomain::getFunctionCode() const
125 {
126 return TestDomainFS;
127 }
128
129 int TestDomain::getFunctionOnBoundaryCode() const
130 {
131 return TestDomainFS;
132 }
133
134 int TestDomain::getFunctionOnContactZeroCode() const
135 {
136 return TestDomainFS;
137 }
138
139 int TestDomain::getFunctionOnContactOneCode() const
140 {
141 return TestDomainFS;
142 }
143
144 int TestDomain::getSolutionCode() const
145 {
146 return TestDomainFS;
147 }
148
149 int TestDomain::getReducedSolutionCode() const
150 {
151 return TestDomainFS;
152 }
153
154 int TestDomain::getDiracDeltaFunctionsCode() const
155 {
156 return TestDomainFS;
157 }
158
159 std::pair<int,int> TestDomain::getDataShape(int functionSpaceCode) const
160 {
161 return std::pair<int,int>(m_dpps,m_samples);
162 }
163
164 int TestDomain::getTagFromSampleNo(int functionSpaceType, int sampleNo) const
165 {
166 //
167 // return an arbitrary value
168 // - In this case I have chosen to return the default tag
169 return 0;
170 }
171
172 const int* TestDomain::borrowSampleReferenceIDs(int functionSpaceType) const
173 {
174 //
175 // return an arbitrary value
176 return m_samplerefids;
177 }
178
179 int TestDomain::getDim() const
180 {
181 //
182 // return an arbitrary value
183 // Since this domain doesn't really have structure I guess 1 seems sensible
184 return 1;
185 }
186
187 bool TestDomain::operator==(const AbstractDomain& other) const
188 {
189 const TestDomain* temp=dynamic_cast<const TestDomain*>(&other);
190 if (temp!=0) {
191 return true;
192 } else {
193 return false;
194 }
195 }
196
197 bool TestDomain::operator!=(const AbstractDomain& other) const
198 {
199 return(!(*this==other));
200 }
201
202
203
204 bool TestDomain::canTag(int functionSpaceCode) const
205 {
206 return true;
207 }
208
209 int TestDomain::getNumberOfTagsInUse(int functionSpaceCode) const
210 {
211 return 1; // this is not arbitrary. It allows us to report that the default tag is in use
212 }
213
214 const int* TestDomain::borrowListOfTagsInUse(int functionSpaceCode) const
215 {
216 return defaultList;
217 }
218
219 escript::Data TestDomain::getX() const
220 {
221 if (m_dpsize<2)
222 {
223 Data res(0,DataTypes::scalarShape,FunctionSpace( getPtr(), getDefaultCode()),true);
224 DataTypes::ValueType& vec=res.getReady()->getVectorRW();
225 for (int i=0;i<m_samples;++i)
226 {
227 for (int j=0;j<m_dpps;++j)
228 {
229 vec[i*m_dpps+j]=i+(1.0*j)/m_dpps;
230 }
231 }
232 return res;
233 }
234 DataTypes::ShapeType p;
235 p.push_back(m_dpsize);
236 Data res(0,p,FunctionSpace( getPtr(), getDefaultCode()),true);
237 DataTypes::ValueType& vec=res.getReady()->getVectorRW();
238 double majorstep=double(1)/m_dpps;
239 double minorstep=majorstep*0.9/m_dpsize;
240 for (int i=0;i<m_samples;++i)
241 {
242 for (int j=0;j<m_dpps;++j)
243 {
244 for (int k=0;k<m_dpsize;++k)
245 {
246 vec[i*m_dpsize*m_dpps+j*m_dpsize+k]=i+j*majorstep+k*minorstep;
247 }
248 }
249 }
250 return res;
251
252
253 }
254
255 FunctionSpace
256 getTestDomainFunctionSpace(int dpps, int samples, int dpsize)
257 {
258 TestDomain* td=new TestDomain(dpps, samples, dpsize);
259 Domain_ptr p=Domain_ptr(td);
260 return FunctionSpace(p, td->getDefaultCode());
261 }
262
263 } // end of namespace

  ViewVC Help
Powered by ViewVC 1.1.26