/[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 628 - (hide annotations)
Thu Mar 23 02:27:57 2006 UTC (14 years, 7 months ago) by elspeth
File MIME type: text/x-python
File size: 4445 byte(s)
Copyright information added.

1 jgs 144 # $Id$
2    
3 elspeth 628 __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 jgs 149 from esys.escript.modelframe import Model,ParameterSet
10     from esys.escript.escript import Data
11     from esys.escript.util import *
12 jgs 144
13    
14 jgs 148 class EvaluateExpression(ParameterSet):
15 jgs 149 """
16     Return the evaluation of an expression at current time t and
17     locations in the domain
18 jgs 144
19 jgs 149 @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 jgs 147
26     def __init__(self,debug=False):
27 jgs 149 """
28     Set up parameters
29     """
30 jgs 148 ParameterSet.__init__(self,debug=debug)
31 jgs 147 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 jgs 144 class Probe(Model):
46 jgs 149 """
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 jgs 144
53 jgs 149 @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 jgs 144
61 jgs 149 """
62 jgs 144
63     def __init__(self,debug=False):
64 jgs 149 """
65     Set up parameters
66     """
67 jgs 144 Model.__init__(self,debug=debug)
68 jgs 147 self.declareParameter(expression=None, \
69 jgs 144 value=0., \
70 jgs 147 t=0., \
71 jgs 144 line_tag="PROBE")
72    
73 jgs 147 def doInitialization(self):
74 jgs 149 """
75     Initializes values
76     """
77 jgs 144 self.t_max=None
78 jgs 147 self.max_error=0.
79 jgs 144
80 jgs 147 def doStepPostprocessing(self,dt):
81     t=self.t
82     print "%s : time %e"%(self.line_tag,t)
83 jgs 144 v=self.value
84     x=v.getFunctionSpace().getX()
85     if v.getRank()==0:
86 jgs 147 if self.expression==None:
87     print "%s : true (min,max)= (%e,%e)"%(self.line_tag,inf(v),sub(v))
88 jgs 144 else:
89 jgs 147 ref=eval(self.expression)
90 jgs 144 err=Lsup(v-ref)/Lsup(ref)
91 jgs 147 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 jgs 144 else:
94     err=0
95     for i in range(v.getRank()):
96     vi=v[i]
97 jgs 147 if self.expression==None:
98     print "%s : component %d: true (min,max)= (%e,%e)"%(self.line_tag,i,inf(vi))
99 jgs 144 else:
100 jgs 147 refi=eval(self.expression[i])
101 jgs 144 erri=Lsup(vi-refi)/Lsup(refi)
102 jgs 147 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 jgs 144 err=max(err,erri)
105 jgs 147 if not self.expression==None: print "%s : maximum error %e",err
106 jgs 144
107 jgs 147 if not self.expression==None:
108     if err>self.max_error:
109     self.t_max=t
110     self.max_error=err
111 jgs 144
112 jgs 147 def doFinalization(self):
113 jgs 149 """
114     Print out the maximum error.
115     """
116 jgs 147 if not self.t_max==None: print "%s : == maximum error %e at time %e == "%(self.line_tag,self.max_error,self.t_max)
117 jgs 149
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