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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 144 - (hide annotations)
Mon Jul 25 05:42:21 2005 UTC (14 years, 3 months ago) by jgs
Original Path: trunk/esys2/modellib/py_src/probe.py
File MIME type: text/x-python
File size: 2696 byte(s)
moved form old modellib directory

1 jgs 144 # $Id$
2    
3    
4     from esys.modelframe import Model
5     from esys.escript import inf,sup,Lsup
6    
7    
8     class Probe(Model):
9     """@brief tests values against a reference which may depend on time and spatial coordinates
10     it prints out the relative error in each time step and the maximum relative error over
11     all time steps at the end
12    
13     WARNING: this class use python's eval function!!!!!
14    
15     @param value (in) - values to be tested
16     @param reference (in) - expressions defining reference values to test against. If None only value is reported.
17     @param line_tag (in) - tag to be used when printing error
18     @param max_error (out) - maximum error
19     @param t_max (out) - time of maximum error
20    
21     """
22    
23     def __init__(self,debug=False):
24     """set up parameters"""
25     Model.__init__(self,debug=debug)
26     self.declareParameter(reference=None, \
27     value=0., \
28     line_tag="PROBE")
29    
30     def doInitialization(self,t):
31     """initializes values"""
32     self.__tn=t
33     self.t_max=None
34     self.max_err=0.
35    
36     def doStep(self,dt):
37     t=self.__tn+dt
38     print "%s : time %d"%t
39     v=self.value
40     x=v.getFunctionSpace().getX()
41     if v.getRank()==0:
42     if self.reference==None:
43     print "%s : (min,max)= (%e,%e)"%(self.line_tag,inf(v),max(v))
44     else:
45     ref=eval(self.reference)
46     err=Lsup(v-ref)/Lsup(ref)
47     print "%s : (min,max,rel error)= (%e,%e,%e)"%(self.line_tag,inf(v),max(v),err)
48     else:
49     err=0
50     for i in range(v.getRank()):
51     vi=v[i]
52     if self.reference==None:
53     print "%s : component %d (min,max)= (%e,%e)"%(self.line_tag,i,inf(vi),max(vi))
54     else:
55     refi=eval(self.reference[i])
56     erri=Lsup(vi-refi)/Lsup(refi)
57     print "%s : component %d (min,max,rel error)= (%e,%e,%e)"%(self.line_tag,i,inf(vi),max(vi),erri)
58     err=max(err,erri)
59     if not self.reference==None: print "%s : maximum error %e",err
60     self.__tn=t
61    
62     if not self.reference==None:
63     if err>self.max_err:
64     self.t_max=self.__tn
65     self.max_error=err/max_ref
66    
67     def finalize(self):
68     """print out the maximum error"""
69     if not self.t_max==None: print "%s : component %d (min,max)= (%e,%e)"%(self.line_tag,self.t_max,self.max_err)

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26