/[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 918 - (show annotations)
Wed Jan 3 06:30:00 2007 UTC (16 years, 2 months ago) by gross
File MIME type: text/x-python
File size: 4455 byte(s)
fixes on ESySXML to get runmodel going.

    * object ids are now local for read and write of XML
    * ParameterSets are now written with class name
    * ParameterSets linked by other ParameterSets (previously only Models) are written now 
    * list are now lists of str (rather than bools), lists with bool, int or float are mapped to numarray
    * numarray are writen with generic types Bool, Int, Float (portability!)


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