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 |
|
|
* Laplace3Dorder2_?k |
18 |
|
|
|
19 |
|
|
where ? is approximatively the number of unknowns in 1000. |
20 |
|
|
|
21 |
|
|
@var __author__: name of author |
22 |
|
|
@var __licence__: licence agreement |
23 |
|
|
var __url__: url entry point on documentation |
24 |
|
|
@var __version__: version |
25 |
|
|
@var __date__: date of the version |
26 |
|
|
""" |
27 |
|
|
|
28 |
|
|
__author__="Lutz Gross, l.gross@uq.edu.au" |
29 |
|
|
__licence__="contact: esys@access.uq.edu.au" |
30 |
|
|
__url__="http://www.iservo.edu.au/esys/escript" |
31 |
|
|
__version__="$Revision:$" |
32 |
|
|
__date__="$Date:$" |
33 |
|
|
|
34 |
|
|
from esys.escript.benchmark import BenchmarkProblem, Options, BenchmarkFilter |
35 |
|
|
from esys.escript import Lsup |
36 |
|
|
import esys.finley |
37 |
|
|
import os |
38 |
|
|
|
39 |
|
|
class FinleyFilter(BenchmarkFilter): |
40 |
|
|
""" |
41 |
|
|
defines a filter for L{FinleyProblem} characteristics |
42 |
|
|
""" |
43 |
|
|
TIME="t [sec]" |
44 |
|
|
ERROR="rel. error" |
45 |
|
|
|
46 |
|
|
|
47 |
|
|
def __init__(self,args=None): |
48 |
|
|
""" |
49 |
|
|
sets up the filter |
50 |
|
|
|
51 |
|
|
@param args: list of value names to be filtered |
52 |
|
|
@type args: C{list} of L{TIME}, L{ERROR} |
53 |
|
|
""" |
54 |
|
|
if args==None: args=[FinleyFilter.TIME,FinleyFilter.ERROR] |
55 |
|
|
super(FinleyFilter,self).__init__() |
56 |
|
|
self.__args=args |
57 |
|
|
|
58 |
|
|
def getResultNames(self): |
59 |
|
|
""" |
60 |
|
|
return the names of the results produced when run() is called. |
61 |
|
|
|
62 |
|
|
@return: names the list of the names to be used when the results of the run() call are printed |
63 |
|
|
@rtype: C{list} of C{str} |
64 |
|
|
""" |
65 |
|
|
return self.__args |
66 |
|
|
|
67 |
|
|
def __call__(self,result): |
68 |
|
|
""" |
69 |
|
|
filters out the characteristic values |
70 |
|
|
|
71 |
|
|
@param result: characteristics rturned by a L{FinleyProblem} run |
72 |
|
|
@type result: C{dict} |
73 |
|
|
@return: filtered values |
74 |
|
|
@rtype: C{list} of C{str} |
75 |
|
|
""" |
76 |
|
|
out=[] |
77 |
|
|
for a in self.__args: |
78 |
|
|
out.append(result[a]) |
79 |
|
|
return out |
80 |
|
|
|
81 |
|
|
|
82 |
|
|
|
83 |
|
|
class FinleyProblem(BenchmarkProblem): |
84 |
|
|
""" |
85 |
|
|
The general benchmark problem for Finley |
86 |
|
|
""" |
87 |
|
|
def run(self,options): |
88 |
|
|
""" |
89 |
|
|
creates a domain and a PDE on this domain, solves it (with the given options) and returns the |
90 |
|
|
elapsed time and the error. |
91 |
|
|
|
92 |
|
|
@param options: paso solver options |
93 |
|
|
@type options: L{PasoOptions} |
94 |
|
|
@return: elapsed time and the error of calculated solution |
95 |
|
|
@rtype: pair of C{float} |
96 |
|
|
""" |
97 |
|
|
domain=self.getDomain() |
98 |
|
|
pde,u=self.getTestProblem(domain) |
99 |
|
|
pde.setTolerance(options.getTolerance()) |
100 |
|
|
pde.setSolverMethod(options.getSolverMethod()) |
101 |
|
|
pde.setSolverPackage(options.getSolverPackage()) |
102 |
|
|
a=os.times()[4] |
103 |
|
|
u_h=pde.getSolution(options.getPasoOptions()) |
104 |
|
|
a=os.times()[4]-a |
105 |
|
|
if u==None: |
106 |
|
|
return {FinleyFilter.TIME : a ,FinleyFilter.TIME : None } |
107 |
|
|
else: |
108 |
|
|
error=Lsup(u-uh)/Lsup(u) |
109 |
|
|
return {FinleyFilter.TIME : a ,FinleyFilter.TIME : error } |
110 |
|
|
|
111 |
|
|
def getTestProblem(self,domain): |
112 |
|
|
""" |
113 |
|
|
returns a PDEto be solved and an exact solution |
114 |
|
|
|
115 |
|
|
@param domain: the PDE domain |
116 |
|
|
@type domain: L{escript.Domain} |
117 |
|
|
@return: a linear PDE to be solved an a reference solution |
118 |
|
|
@rtype: L{LinearPDE},L{escript.Data} |
119 |
|
|
@remark: must be overwritten by a particular problem |
120 |
|
|
""" |
121 |
|
|
raise NotImplementedError |
122 |
|
|
|
123 |
|
|
def getDomain(self): |
124 |
|
|
""" |
125 |
|
|
returns the domain of the problem |
126 |
|
|
|
127 |
|
|
@return: a domain |
128 |
|
|
@rtype: L{escript.Domain} |
129 |
|
|
@remark: must be overwritten by a particular problem |
130 |
|
|
""" |
131 |
|
|
raise NotImplementedError |
132 |
|
|
|
133 |
|
|
class RegularFinleyProblem(FinleyProblem): |
134 |
|
|
""" |
135 |
|
|
base class for finley problem on a rectangular mesh |
136 |
|
|
""" |
137 |
|
|
def __init__(self,n=1,order=1,dim=2): |
138 |
|
|
""" |
139 |
|
|
sets up a recangular mesh in finley on a unit cube/square |
140 |
|
|
|
141 |
|
|
@param n: number of elements in each spactial direction |
142 |
|
|
@type n: C{int} |
143 |
|
|
@param order: element order |
144 |
|
|
@type order: 1 or 2 |
145 |
|
|
@param dim: spatial dimension |
146 |
|
|
@type n: 2 or 3 |
147 |
|
|
""" |
148 |
|
|
super(RegularFinleyProblem,self).__init__(name=str((order*n+1)**dim)) |
149 |
|
|
self.__n=n |
150 |
|
|
self.__order=order |
151 |
|
|
self.__dim=dim |
152 |
|
|
|
153 |
|
|
def getDomain(self): |
154 |
|
|
""" |
155 |
|
|
returns the unit square/cube with a rectangular mesh |
156 |
|
|
|
157 |
|
|
@return: a domain |
158 |
|
|
@rtype: L{escript.Domain} |
159 |
|
|
""" |
160 |
|
|
if dim==2: |
161 |
|
|
domain=esys.finley.Rectangle(n0=self.__n,n1=self.__n,order=order) |
162 |
|
|
else: |
163 |
|
|
domain=esys.finley.Brick(n0=self.__n,n1=self.__n,n2=self.__n,order=order) |
164 |
|
|
return domain |
165 |
|
|
|
166 |
|
|
class LaplaceProblem(RegularFinleyProblem): |
167 |
|
|
""" |
168 |
|
|
base class for the Lapalce eqaution on a rectangular mesh |
169 |
|
|
""" |
170 |
|
|
def getTestProblem(self,domain): |
171 |
|
|
""" |
172 |
|
|
returns a PDE and a test solution on the given domain |
173 |
|
|
|
174 |
|
|
@param doamin: a domain |
175 |
|
|
@type domain: L{escript.Domain} |
176 |
|
|
@return: the Laplace equation and a test solution |
177 |
|
|
@rtype: C{tuple} of C{LinearPDE} and C{escript.Data} |
178 |
|
|
""" |
179 |
|
|
x=domain.getX() |
180 |
|
|
msk=whereZero(x[0])+whereZero(x[0]-1.) |
181 |
|
|
u=x[0] |
182 |
|
|
for i in range(1,domain.getDim()): |
183 |
|
|
msk+=whereZero(x[i])+whereZero(x[i]-1.) |
184 |
|
|
u*=(x[i]-i) |
185 |
|
|
pde=LinearPDE(mydomain) |
186 |
|
|
pde.setSymmetryOn() |
187 |
|
|
pde.setValue(A=kronnecker,q=msk,r=u) |
188 |
|
|
return pde,u |
189 |
|
|
|
190 |
|
|
class Laplace2DOrder1_30k(LaplaceProblem): |
191 |
|
|
def __init__(self): |
192 |
|
|
super(Laplace2DOrder1_30k,self).__init__(n=176,order=1,dim=2) |
193 |
|
|
class Laplace2DOrder2_30k(LaplaceProblem): |
194 |
|
|
def __init__(self): |
195 |
|
|
super(Laplace2DOrder2_30k,self).__init__(n=88,order=2,dim=2) |
196 |
|
|
class Laplace2DOrder1_60k(LaplaceProblem): |
197 |
|
|
def __init__(self): |
198 |
|
|
super(Laplace2DOrder1_60k,self).__init__(n=248,order=1,dim=2) |
199 |
|
|
class Laplace2DOrder2_60k(LaplaceProblem): |
200 |
|
|
def __init__(self): |
201 |
|
|
super(Laplace2DOrder2_60k,self).__init__(n=124,order=2,dim=2) |
202 |
|
|
class Laplace2DOrder1_120k(LaplaceProblem): |
203 |
|
|
def __init__(self): |
204 |
|
|
super(Laplace2DOrder1_120k,self).__init__(n=349,order=1,dim=2) |
205 |
|
|
class Laplace2DOrder2_120k(LaplaceProblem): |
206 |
|
|
def __init__(self): |
207 |
|
|
super(Laplace2DOrder2_120k,self).__init__(n=175,order=2,dim=2) |
208 |
|
|
class Laplace2DOrder1_240k(LaplaceProblem): |
209 |
|
|
def __init__(self): |
210 |
|
|
super(Laplace2DOrder1_240k,self).__init__(n=492,order=1,dim=2) |
211 |
|
|
class Laplace2DOrder2_240k(LaplaceProblem): |
212 |
|
|
def __init__(self): |
213 |
|
|
super(Laplace2DOrder2_240k,self).__init__(n=246,order=2,dim=2) |
214 |
|
|
class Laplace2DOrder1_480k(LaplaceProblem): |
215 |
|
|
def __init__(self): |
216 |
|
|
super(Laplace2DOrder1_480k,self).__init__(n=694,order=1,dim=2) |
217 |
|
|
class Laplace2DOrder2_480k(LaplaceProblem): |
218 |
|
|
def __init__(self): |
219 |
|
|
super(Laplace2DOrder2_480k,self).__init__(n=347,order=2,dim=2) |
220 |
|
|
class Laplace2DOrder1_960k(LaplaceProblem): |
221 |
|
|
def __init__(self): |
222 |
|
|
super(Laplace2DOrder1_960k,self).__init__(n=978,order=1,dim=2) |
223 |
|
|
class Laplace2DOrder2_960k(LaplaceProblem): |
224 |
|
|
def __init__(self): |
225 |
|
|
super(Laplace2DOrder2_960k,self).__init__(n=489,order=2,dim=2) |