1 |
gross |
381 |
# $Id:$ |
2 |
|
|
|
3 |
|
|
# |
4 |
|
|
# COPYRIGHT ACcESS 2004 - All Rights Reserved |
5 |
|
|
# |
6 |
|
|
# This software is the property of ACcESS. No part of this code |
7 |
|
|
# may be copied in any form or by any means without the expressed written |
8 |
|
|
# consent of ACcESS. Copying, use or modification of this software |
9 |
|
|
# by any unauthorised person is illegal unless that |
10 |
|
|
# person has a software license agreement with ACcESS. |
11 |
|
|
# |
12 |
|
|
|
13 |
|
|
""" |
14 |
|
|
some benchmarks for tetsing the finley solver. The idea is to develop a set of standart benchmarks |
15 |
|
|
|
16 |
|
|
* Laplace2Dorder1_?k |
17 |
gross |
389 |
* Laplace2Dorder2_?k |
18 |
|
|
* Laplace3Dorder1_?k |
19 |
gross |
381 |
* Laplace3Dorder2_?k |
20 |
|
|
|
21 |
|
|
where ? is approximatively the number of unknowns in 1000. |
22 |
|
|
|
23 |
|
|
@var __author__: name of author |
24 |
|
|
@var __licence__: licence agreement |
25 |
|
|
var __url__: url entry point on documentation |
26 |
|
|
@var __version__: version |
27 |
|
|
@var __date__: date of the version |
28 |
|
|
""" |
29 |
|
|
|
30 |
|
|
__author__="Lutz Gross, l.gross@uq.edu.au" |
31 |
|
|
__licence__="contact: esys@access.uq.edu.au" |
32 |
|
|
__url__="http://www.iservo.edu.au/esys/escript" |
33 |
|
|
__version__="$Revision:$" |
34 |
|
|
__date__="$Date:$" |
35 |
|
|
|
36 |
gross |
383 |
from esys.escript import Lsup,whereZero,kronecker |
37 |
gross |
381 |
from esys.escript.benchmark import BenchmarkProblem, Options, BenchmarkFilter |
38 |
|
|
import esys.finley |
39 |
gross |
383 |
from esys.escript.linearPDEs import LinearPDE |
40 |
gross |
381 |
import os |
41 |
|
|
|
42 |
|
|
class FinleyFilter(BenchmarkFilter): |
43 |
|
|
""" |
44 |
|
|
defines a filter for L{FinleyProblem} characteristics |
45 |
|
|
""" |
46 |
|
|
TIME="t [sec]" |
47 |
|
|
ERROR="rel. error" |
48 |
|
|
|
49 |
|
|
|
50 |
|
|
def __init__(self,args=None): |
51 |
|
|
""" |
52 |
|
|
sets up the filter |
53 |
|
|
|
54 |
|
|
@param args: list of value names to be filtered |
55 |
|
|
@type args: C{list} of L{TIME}, L{ERROR} |
56 |
|
|
""" |
57 |
|
|
if args==None: args=[FinleyFilter.TIME,FinleyFilter.ERROR] |
58 |
|
|
super(FinleyFilter,self).__init__() |
59 |
|
|
self.__args=args |
60 |
|
|
|
61 |
|
|
def getResultNames(self): |
62 |
|
|
""" |
63 |
|
|
return the names of the results produced when run() is called. |
64 |
|
|
|
65 |
|
|
@return: names the list of the names to be used when the results of the run() call are printed |
66 |
|
|
@rtype: C{list} of C{str} |
67 |
|
|
""" |
68 |
|
|
return self.__args |
69 |
|
|
|
70 |
|
|
def __call__(self,result): |
71 |
|
|
""" |
72 |
|
|
filters out the characteristic values |
73 |
|
|
|
74 |
|
|
@param result: characteristics rturned by a L{FinleyProblem} run |
75 |
|
|
@type result: C{dict} |
76 |
|
|
@return: filtered values |
77 |
|
|
@rtype: C{list} of C{str} |
78 |
|
|
""" |
79 |
|
|
out=[] |
80 |
|
|
for a in self.__args: |
81 |
|
|
out.append(result[a]) |
82 |
|
|
return out |
83 |
|
|
|
84 |
gross |
383 |
class FinleyOptions(Options): |
85 |
|
|
""" |
86 |
|
|
finley solver options to be handed over to paso |
87 |
gross |
381 |
|
88 |
gross |
383 |
""" |
89 |
|
|
def __init__(self,solver_method=None, |
90 |
|
|
preconditioner=None, |
91 |
|
|
package=None, |
92 |
|
|
tolerance=None, |
93 |
|
|
verbose=False): |
94 |
|
|
self.strmap={ |
95 |
|
|
LinearPDE.DIRECT : "DIRECT", |
96 |
|
|
LinearPDE.PCG: "PCG", |
97 |
|
|
LinearPDE.CR: "CR", |
98 |
|
|
LinearPDE.CGS: "CGS", |
99 |
|
|
LinearPDE.BICGSTAB: "BICGSTAB", |
100 |
|
|
LinearPDE.SSOR: "SSOR", |
101 |
|
|
LinearPDE.ILU0: "ILU0", |
102 |
|
|
LinearPDE.ILUT: "ILUT", |
103 |
|
|
LinearPDE.JACOBI: "JACOBI", |
104 |
|
|
LinearPDE.GMRES: "GMRES", |
105 |
|
|
LinearPDE.PRES20: "PRES20", |
106 |
|
|
LinearPDE.LUMPING: "LUMPIMG", |
107 |
|
|
LinearPDE.NO_REORDERING: "NO_REORDERING", |
108 |
|
|
LinearPDE.MINIMUM_FILL_IN: "MINIMUM_FILL_IN", |
109 |
|
|
LinearPDE.NESTED_DISSECTION: "NESTED_DISSECTION", |
110 |
|
|
LinearPDE.SCSL: "SCSL", |
111 |
|
|
LinearPDE.MKL: "MKL", |
112 |
|
|
LinearPDE.UMFPACK: "UMFPACK", |
113 |
|
|
LinearPDE.PASO: "PASO" |
114 |
|
|
} |
115 |
|
|
name="" |
116 |
|
|
if solver_method==None: |
117 |
|
|
solver_method==LinearPDE.PRES20 |
118 |
|
|
else: |
119 |
|
|
name+=self.strmap[solver_method] |
120 |
|
|
if preconditioner==None: |
121 |
|
|
preconditioner==LinearPDE.JACOBI |
122 |
|
|
else: |
123 |
|
|
if not name=="": name+="+" |
124 |
|
|
name+=self.strmap[preconditioner] |
125 |
|
|
if package==None: |
126 |
|
|
package==LinearPDE.PASO |
127 |
|
|
else: |
128 |
|
|
if not name=="": name+=" with " |
129 |
|
|
name+=self.strmap[package] |
130 |
|
|
if tolerance==None: |
131 |
|
|
tolerance=1.e-8 |
132 |
|
|
else: |
133 |
|
|
if not name=="": name+=", " |
134 |
|
|
name+="tol = %s"%tolerance |
135 |
|
|
self.solver_method=solver_method |
136 |
|
|
self.preconditioner=preconditioner |
137 |
|
|
self.tolerance=tolerance |
138 |
|
|
self.package=package |
139 |
|
|
self.verbose=verbose |
140 |
|
|
super(FinleyOptions,self).__init__(name=name) |
141 |
|
|
|
142 |
|
|
|
143 |
|
|
|
144 |
gross |
381 |
class FinleyProblem(BenchmarkProblem): |
145 |
|
|
""" |
146 |
|
|
The general benchmark problem for Finley |
147 |
|
|
""" |
148 |
|
|
def run(self,options): |
149 |
|
|
""" |
150 |
|
|
creates a domain and a PDE on this domain, solves it (with the given options) and returns the |
151 |
|
|
elapsed time and the error. |
152 |
|
|
|
153 |
|
|
@param options: paso solver options |
154 |
|
|
@type options: L{PasoOptions} |
155 |
|
|
@return: elapsed time and the error of calculated solution |
156 |
|
|
@rtype: pair of C{float} |
157 |
|
|
""" |
158 |
|
|
domain=self.getDomain() |
159 |
|
|
pde,u=self.getTestProblem(domain) |
160 |
gross |
383 |
pde.setTolerance(options.tolerance) |
161 |
|
|
pde.setSolverMethod(options.solver_method,options.preconditioner) |
162 |
|
|
pde.setSolverPackage(options.package) |
163 |
gross |
381 |
a=os.times()[4] |
164 |
gross |
383 |
uh=pde.getSolution(verbose=options.verbose) |
165 |
gross |
381 |
a=os.times()[4]-a |
166 |
|
|
if u==None: |
167 |
gross |
383 |
return {FinleyFilter.TIME : a , FinleyFilter.ERROR : None } |
168 |
gross |
381 |
else: |
169 |
|
|
error=Lsup(u-uh)/Lsup(u) |
170 |
gross |
383 |
return {FinleyFilter.TIME : a , FinleyFilter.ERROR : error } |
171 |
gross |
381 |
|
172 |
|
|
def getTestProblem(self,domain): |
173 |
|
|
""" |
174 |
|
|
returns a PDEto be solved and an exact solution |
175 |
|
|
|
176 |
|
|
@param domain: the PDE domain |
177 |
|
|
@type domain: L{escript.Domain} |
178 |
|
|
@return: a linear PDE to be solved an a reference solution |
179 |
|
|
@rtype: L{LinearPDE},L{escript.Data} |
180 |
|
|
@remark: must be overwritten by a particular problem |
181 |
|
|
""" |
182 |
|
|
raise NotImplementedError |
183 |
|
|
|
184 |
|
|
def getDomain(self): |
185 |
|
|
""" |
186 |
|
|
returns the domain of the problem |
187 |
|
|
|
188 |
|
|
@return: a domain |
189 |
|
|
@rtype: L{escript.Domain} |
190 |
|
|
@remark: must be overwritten by a particular problem |
191 |
|
|
""" |
192 |
|
|
raise NotImplementedError |
193 |
|
|
|
194 |
|
|
class RegularFinleyProblem(FinleyProblem): |
195 |
|
|
""" |
196 |
|
|
base class for finley problem on a rectangular mesh |
197 |
|
|
""" |
198 |
|
|
def __init__(self,n=1,order=1,dim=2): |
199 |
|
|
""" |
200 |
|
|
sets up a recangular mesh in finley on a unit cube/square |
201 |
|
|
|
202 |
|
|
@param n: number of elements in each spactial direction |
203 |
|
|
@type n: C{int} |
204 |
|
|
@param order: element order |
205 |
|
|
@type order: 1 or 2 |
206 |
|
|
@param dim: spatial dimension |
207 |
|
|
@type n: 2 or 3 |
208 |
|
|
""" |
209 |
|
|
super(RegularFinleyProblem,self).__init__(name=str((order*n+1)**dim)) |
210 |
|
|
self.__n=n |
211 |
|
|
self.__order=order |
212 |
|
|
self.__dim=dim |
213 |
|
|
|
214 |
|
|
def getDomain(self): |
215 |
|
|
""" |
216 |
|
|
returns the unit square/cube with a rectangular mesh |
217 |
|
|
|
218 |
|
|
@return: a domain |
219 |
|
|
@rtype: L{escript.Domain} |
220 |
|
|
""" |
221 |
gross |
383 |
if self.__dim==2: |
222 |
|
|
domain=esys.finley.Rectangle(n0=self.__n,n1=self.__n,order=self.__order) |
223 |
gross |
381 |
else: |
224 |
gross |
383 |
domain=esys.finley.Brick(n0=self.__n,n1=self.__n,n2=self.__n,order=self.__order) |
225 |
gross |
381 |
return domain |
226 |
|
|
|
227 |
|
|
class LaplaceProblem(RegularFinleyProblem): |
228 |
|
|
""" |
229 |
|
|
base class for the Lapalce eqaution on a rectangular mesh |
230 |
|
|
""" |
231 |
|
|
def getTestProblem(self,domain): |
232 |
|
|
""" |
233 |
|
|
returns a PDE and a test solution on the given domain |
234 |
|
|
|
235 |
|
|
@param doamin: a domain |
236 |
|
|
@type domain: L{escript.Domain} |
237 |
|
|
@return: the Laplace equation and a test solution |
238 |
|
|
@rtype: C{tuple} of C{LinearPDE} and C{escript.Data} |
239 |
|
|
""" |
240 |
|
|
x=domain.getX() |
241 |
|
|
msk=whereZero(x[0])+whereZero(x[0]-1.) |
242 |
|
|
u=x[0] |
243 |
|
|
for i in range(1,domain.getDim()): |
244 |
|
|
msk+=whereZero(x[i])+whereZero(x[i]-1.) |
245 |
|
|
u*=(x[i]-i) |
246 |
gross |
383 |
pde=LinearPDE(domain) |
247 |
gross |
381 |
pde.setSymmetryOn() |
248 |
gross |
383 |
pde.setValue(A=kronecker(domain),q=msk,r=u) |
249 |
gross |
381 |
return pde,u |
250 |
|
|
|
251 |
gross |
389 |
class Laplace2DOrder1_30k(LaplaceProblem): |
252 |
|
|
def __init__(self): |
253 |
|
|
super(Laplace2DOrder1_30k,self).__init__(n=172,order=1,dim=2) |
254 |
|
|
class Laplace2DOrder1_60k(LaplaceProblem): |
255 |
|
|
def __init__(self): |
256 |
|
|
super(Laplace2DOrder1_60k,self).__init__(n=244,order=1,dim=2) |
257 |
|
|
class Laplace2DOrder1_120k(LaplaceProblem): |
258 |
|
|
def __init__(self): |
259 |
|
|
super(Laplace2DOrder1_120k,self).__init__(n=345,order=1,dim=2) |
260 |
|
|
class Laplace2DOrder1_240k(LaplaceProblem): |
261 |
|
|
def __init__(self): |
262 |
|
|
super(Laplace2DOrder1_240k,self).__init__(n=489,order=1,dim=2) |
263 |
|
|
class Laplace2DOrder1_480k(LaplaceProblem): |
264 |
|
|
def __init__(self): |
265 |
|
|
super(Laplace2DOrder1_480k,self).__init__(n=692,order=1,dim=2) |
266 |
|
|
class Laplace2DOrder1_960k(LaplaceProblem): |
267 |
|
|
def __init__(self): |
268 |
|
|
super(Laplace2DOrder1_960k,self).__init__(n=979,order=1,dim=2) |
269 |
|
|
class Laplace2DOrder1_1920k(LaplaceProblem): |
270 |
|
|
def __init__(self): |
271 |
|
|
super(Laplace2DOrder1_1920k,self).__init__(n=1385,order=1,dim=2) |
272 |
|
|
class Laplace2DOrder1_3840k(LaplaceProblem): |
273 |
|
|
def __init__(self): |
274 |
|
|
super(Laplace2DOrder1_3840k,self).__init__(n=1959,order=1,dim=2) |
275 |
|
|
class Laplace2DOrder1_7680k(LaplaceProblem): |
276 |
|
|
def __init__(self): |
277 |
|
|
super(Laplace2DOrder1_7680k,self).__init__(n=2770,order=1,dim=2) |
278 |
|
|
class Laplace2DOrder1_15360k(LaplaceProblem): |
279 |
|
|
def __init__(self): |
280 |
|
|
super(Laplace2DOrder1_15360k,self).__init__(n=3918,order=1,dim=2) |
281 |
gross |
381 |
class Laplace2DOrder2_30k(LaplaceProblem): |
282 |
gross |
389 |
def __init__(self): |
283 |
|
|
super(Laplace2DOrder2_30k,self).__init__(n=86,order=2,dim=2) |
284 |
gross |
381 |
class Laplace2DOrder2_60k(LaplaceProblem): |
285 |
gross |
389 |
def __init__(self): |
286 |
|
|
super(Laplace2DOrder2_60k,self).__init__(n=122,order=2,dim=2) |
287 |
gross |
381 |
class Laplace2DOrder2_120k(LaplaceProblem): |
288 |
gross |
389 |
def __init__(self): |
289 |
|
|
super(Laplace2DOrder2_120k,self).__init__(n=173,order=2,dim=2) |
290 |
gross |
381 |
class Laplace2DOrder2_240k(LaplaceProblem): |
291 |
gross |
389 |
def __init__(self): |
292 |
|
|
super(Laplace2DOrder2_240k,self).__init__(n=244,order=2,dim=2) |
293 |
gross |
381 |
class Laplace2DOrder2_480k(LaplaceProblem): |
294 |
gross |
389 |
def __init__(self): |
295 |
|
|
super(Laplace2DOrder2_480k,self).__init__(n=346,order=2,dim=2) |
296 |
gross |
381 |
class Laplace2DOrder2_960k(LaplaceProblem): |
297 |
gross |
389 |
def __init__(self): |
298 |
|
|
super(Laplace2DOrder2_960k,self).__init__(n=489,order=2,dim=2) |
299 |
|
|
class Laplace2DOrder2_1920k(LaplaceProblem): |
300 |
|
|
def __init__(self): |
301 |
|
|
super(Laplace2DOrder2_1920k,self).__init__(n=692,order=2,dim=2) |
302 |
|
|
class Laplace2DOrder2_3840k(LaplaceProblem): |
303 |
|
|
def __init__(self): |
304 |
|
|
super(Laplace2DOrder2_3840k,self).__init__(n=979,order=2,dim=2) |
305 |
|
|
class Laplace2DOrder2_7680k(LaplaceProblem): |
306 |
|
|
def __init__(self): |
307 |
|
|
super(Laplace2DOrder2_7680k,self).__init__(n=1385,order=2,dim=2) |
308 |
|
|
class Laplace2DOrder2_15360k(LaplaceProblem): |
309 |
|
|
def __init__(self): |
310 |
|
|
super(Laplace2DOrder2_15360k,self).__init__(n=1959,order=2,dim=2) |
311 |
|
|
class Laplace3DOrder1_30k(LaplaceProblem): |
312 |
|
|
def __init__(self): |
313 |
|
|
super(Laplace3DOrder1_30k,self).__init__(n=30,order=1,dim=3) |
314 |
|
|
class Laplace3DOrder1_60k(LaplaceProblem): |
315 |
|
|
def __init__(self): |
316 |
|
|
super(Laplace3DOrder1_60k,self).__init__(n=38,order=1,dim=3) |
317 |
|
|
class Laplace3DOrder1_120k(LaplaceProblem): |
318 |
|
|
def __init__(self): |
319 |
|
|
super(Laplace3DOrder1_120k,self).__init__(n=48,order=1,dim=3) |
320 |
|
|
class Laplace3DOrder1_240k(LaplaceProblem): |
321 |
|
|
def __init__(self): |
322 |
|
|
super(Laplace3DOrder1_240k,self).__init__(n=61,order=1,dim=3) |
323 |
|
|
class Laplace3DOrder1_480k(LaplaceProblem): |
324 |
|
|
def __init__(self): |
325 |
|
|
super(Laplace3DOrder1_480k,self).__init__(n=77,order=1,dim=3) |
326 |
|
|
class Laplace3DOrder1_960k(LaplaceProblem): |
327 |
|
|
def __init__(self): |
328 |
|
|
super(Laplace3DOrder1_960k,self).__init__(n=98,order=1,dim=3) |
329 |
|
|
class Laplace3DOrder1_1920k(LaplaceProblem): |
330 |
|
|
def __init__(self): |
331 |
|
|
super(Laplace3DOrder1_1920k,self).__init__(n=123,order=1,dim=3) |
332 |
|
|
class Laplace3DOrder1_3840k(LaplaceProblem): |
333 |
|
|
def __init__(self): |
334 |
|
|
super(Laplace3DOrder1_3840k,self).__init__(n=156,order=1,dim=3) |
335 |
|
|
class Laplace3DOrder1_7680k(LaplaceProblem): |
336 |
|
|
def __init__(self): |
337 |
|
|
super(Laplace3DOrder1_7680k,self).__init__(n=196,order=1,dim=3) |
338 |
|
|
class Laplace3DOrder1_15360k(LaplaceProblem): |
339 |
|
|
def __init__(self): |
340 |
|
|
super(Laplace3DOrder1_15360k,self).__init__(n=248,order=1,dim=3) |
341 |
|
|
class Laplace3DOrder2_30k(LaplaceProblem): |
342 |
|
|
def __init__(self): |
343 |
|
|
super(Laplace3DOrder2_30k,self).__init__(n=15,order=2,dim=3) |
344 |
|
|
class Laplace3DOrder2_60k(LaplaceProblem): |
345 |
|
|
def __init__(self): |
346 |
|
|
super(Laplace3DOrder2_60k,self).__init__(n=19,order=2,dim=3) |
347 |
|
|
class Laplace3DOrder2_120k(LaplaceProblem): |
348 |
|
|
def __init__(self): |
349 |
|
|
super(Laplace3DOrder2_120k,self).__init__(n=24,order=2,dim=3) |
350 |
|
|
class Laplace3DOrder2_240k(LaplaceProblem): |
351 |
|
|
def __init__(self): |
352 |
|
|
super(Laplace3DOrder2_240k,self).__init__(n=31,order=2,dim=3) |
353 |
|
|
class Laplace3DOrder2_480k(LaplaceProblem): |
354 |
|
|
def __init__(self): |
355 |
|
|
super(Laplace3DOrder2_480k,self).__init__(n=39,order=2,dim=3) |
356 |
|
|
class Laplace3DOrder2_960k(LaplaceProblem): |
357 |
|
|
def __init__(self): |
358 |
|
|
super(Laplace3DOrder2_960k,self).__init__(n=49,order=2,dim=3) |
359 |
|
|
class Laplace3DOrder2_1920k(LaplaceProblem): |
360 |
|
|
def __init__(self): |
361 |
|
|
super(Laplace3DOrder2_1920k,self).__init__(n=62,order=2,dim=3) |
362 |
|
|
class Laplace3DOrder2_3840k(LaplaceProblem): |
363 |
|
|
def __init__(self): |
364 |
|
|
super(Laplace3DOrder2_3840k,self).__init__(n=78,order=2,dim=3) |
365 |
|
|
class Laplace3DOrder2_7680k(LaplaceProblem): |
366 |
|
|
def __init__(self): |
367 |
|
|
super(Laplace3DOrder2_7680k,self).__init__(n=98,order=2,dim=3) |
368 |
|
|
class Laplace3DOrder2_15360k(LaplaceProblem): |
369 |
|
|
def __init__(self): |
370 |
|
|
super(Laplace3DOrder2_15360k,self).__init__(n=124,order=2,dim=3) |
371 |
|
|
|
372 |
|
|
if __name__=="__main__": |
373 |
|
|
test="" |
374 |
|
|
n0=30000 |
375 |
|
|
for d in [2,3]: |
376 |
|
|
for o in [1,2]: |
377 |
|
|
for i in range(10): |
378 |
|
|
dofs=n0*2**i |
379 |
|
|
n=int((float(dofs)**(1./float(d))-1)/o+0.5) |
380 |
|
|
name="Laplace%sDOrder%s_%sk"%(d,o,dofs/1000) |
381 |
|
|
print "class %s(LaplaceProblem):"%name |
382 |
|
|
print " def __init__(self):" |
383 |
|
|
print " super(%s,self).__init__(n=%s,order=%s,dim=%s)"%(name,n,o,d) |
384 |
|
|
test+="addProblem(%s())\n"%name |
385 |
|
|
print test |
386 |
|
|
|