/[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 149 - (hide annotations)
Thu Sep 1 03:31:39 2005 UTC (15 years, 3 months ago) by jgs
Original Path: trunk/esys2/modellib/py_src/probe.py
File MIME type: text/x-python
File size: 4156 byte(s)
Merge of development branch dev-02 back to main trunk on 2005-09-01

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