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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 148 - (show annotations)
Tue Aug 23 01:24:31 2005 UTC (13 years, 9 months ago) by jgs
File MIME type: text/x-python
File size: 4030 byte(s)
Merge of development branch dev-02 back to main trunk on 2005-08-23

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26