/[escript]/trunk/modellib/py_src/probe.py
ViewVC logotype

Contents of /trunk/modellib/py_src/probe.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1388 - (show annotations)
Fri Jan 11 07:45:58 2008 UTC (11 years, 7 months ago) by trankine
File MIME type: text/x-python
File size: 4876 byte(s)
And get the *(&(*&(* name right
1 #
2 # $Id$
3 #
4 #######################################################
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
17
18 __copyright__=""" Copyright (c) 2006 by ACcESS MNRF
19 http://www.access.edu.au
20 Primary Business: Queensland, Australia"""
21 __license__="""Licensed under the Open Software License version 3.0
22 http://www.opensource.org/licenses/osl-3.0.php"""
23
24 from esys.escript.modelframe import Model,ParameterSet
25 from esys.escript.escript import Data
26 from esys.escript.util import *
27
28
29 class EvaluateExpression(ParameterSet):
30 """
31 Return the evaluation of an expression at current time t and
32 locations in the domain
33
34 @warning: this class use python's eval function!!!!!
35 Please use input.InterpolateOverBox is possible!!!!
36 @ivar expression (in): expression or list of expressions defining
37 expression value
38 @ivar out (callable): current value of the expression
39 """
40
41 def __init__(self,**kwargs):
42 """
43 Set up parameters
44 """
45 super(EvaluateExpression, self).__init__(**kwargs)
46 self.declareParameter(domain=None, \
47 t=0., \
48 expression="x[0]")
49
50 def out(self):
51 x=self.domain.getX()
52 t=self.t
53 if isinstance(self.expression,str):
54 out=eval(self.expression)
55 else:
56 out=Data(0,(len(self.expression),),x.getFunctionSpace())
57 for i in range(len(self.expression)): out[i]=eval(self.expression[i])
58 return out
59
60 class Probe(Model):
61 """
62 Tests values against a expression which may depend on time and spatial
63 coordinates.
64
65 It prints out the relative error in each time step and the maximum
66 relative error over all time steps at the end.
67
68 @warning: this class use python's eval function!!!!!
69 @ivar value (in): values to be tested
70 @ivar expression (in): expressions defining expression values to test against. If None only value is reported.
71 @ivar line_tag (in): tag to be used when printing error
72 @ivar t (in): current time
73 @ivar max_error (out): maximum error
74 @ivar t_max (out): time of maximum error
75
76 """
77
78 def __init__(self,**kwargs):
79 """
80 Set up parameters
81 """
82 super(Probe, self).__init__(**kwargs)
83 self.declareParameter(expression=None, \
84 value=0., \
85 t=0., \
86 line_tag="PROBE")
87
88 def doInitialization(self):
89 """
90 Initializes values
91 """
92 self.t_max=None
93 self.max_error=0.
94
95 def doStepPostprocessing(self,dt):
96 t=self.t
97 print "%s : time %e"%(self.line_tag,t)
98 v=self.value
99 x=v.getFunctionSpace().getX()
100 if v.getRank()==0:
101 if self.expression==None:
102 print "%s : true (min,max)= (%e,%e)"%(self.line_tag,inf(v),sub(v))
103 else:
104 ref=eval(self.expression)
105 err=Lsup(v-ref)/Lsup(ref)
106 print "%s : true (min,max)= (%e,%e)"%(self.line_tag,inf(ref),sup(ref))
107 print "%s : (min,max,rel error)= (%e,%e,%e)"%(self.line_tag,inf(v),sup(v),err)
108 else:
109 err=0
110 for i in range(v.getRank()):
111 vi=v[i]
112 if self.expression==None:
113 print "%s : component %d: true (min,max)= (%e,%e)"%(self.line_tag,i,inf(vi))
114 else:
115 refi=eval(self.expression[i])
116 erri=Lsup(vi-refi)/Lsup(refi)
117 print "%s : component %d true (min,max)= (%e,%e)"%(self.line_tag,i,inf(refi),sup(refi))
118 print "%s : component %d (min,max,rel error)= (%e,%e,%e,%e,%e)"%(self.line_tag,i,inf(vi),sup(vi),erri)
119 err=max(err,erri)
120 if not self.expression==None: print "%s : maximum error %e",err
121
122 if not self.expression==None:
123 if err>self.max_error:
124 self.t_max=t
125 self.max_error=err
126
127 def doFinalization(self):
128 """
129 Print out the maximum error.
130 """
131 if not self.t_max==None: print "%s : == maximum error %e at time %e == "%(self.line_tag,self.max_error,self.t_max)
132
133 # vim: expandtab shiftwidth=4:

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.26