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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 147 - (hide annotations)
Fri Aug 12 01:45:47 2005 UTC (17 years, 7 months ago) by jgs
File MIME type: text/x-python
File size: 4003 byte(s)
erge of development branch dev-02 back to main trunk on 2005-08-12

1 jgs 144 # $Id$
2    
3 jgs 147 from escript.modelframe import Model
4     from escript.escript import Data
5     from escript.util import *
6 jgs 144
7    
8 jgs 147 class EvaluateExpression(Model):
9     """@brief return the evaluation of an expression at current time t and locations in the domain
10 jgs 144
11 jgs 147 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     Model.__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 jgs 144 class Probe(Model):
36 jgs 147 """@brief tests values against a expression which may depend on time and spatial coordinates
37 jgs 144 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 jgs 147 @param expression (in) - expressions defining expression values to test against. If None only value is reported.
44 jgs 144 @param line_tag (in) - tag to be used when printing error
45 jgs 147 @param t (in) - current time
46 jgs 144 @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 jgs 147 self.declareParameter(expression=None, \
55 jgs 144 value=0., \
56 jgs 147 t=0., \
57 jgs 144 line_tag="PROBE")
58    
59 jgs 147 def doInitialization(self):
60 jgs 144 """initializes values"""
61     self.t_max=None
62 jgs 147 self.max_error=0.
63 jgs 144
64 jgs 147 def doStepPostprocessing(self,dt):
65     t=self.t
66     print "%s : time %e"%(self.line_tag,t)
67 jgs 144 v=self.value
68     x=v.getFunctionSpace().getX()
69     if v.getRank()==0:
70 jgs 147 if self.expression==None:
71     print "%s : true (min,max)= (%e,%e)"%(self.line_tag,inf(v),sub(v))
72 jgs 144 else:
73 jgs 147 ref=eval(self.expression)
74 jgs 144 err=Lsup(v-ref)/Lsup(ref)
75 jgs 147 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 jgs 144 else:
78     err=0
79     for i in range(v.getRank()):
80     vi=v[i]
81 jgs 147 if self.expression==None:
82     print "%s : component %d: true (min,max)= (%e,%e)"%(self.line_tag,i,inf(vi))
83 jgs 144 else:
84 jgs 147 refi=eval(self.expression[i])
85 jgs 144 erri=Lsup(vi-refi)/Lsup(refi)
86 jgs 147 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 jgs 144 err=max(err,erri)
89 jgs 147 if not self.expression==None: print "%s : maximum error %e",err
90 jgs 144
91 jgs 147 if not self.expression==None:
92     if err>self.max_error:
93     self.t_max=t
94     self.max_error=err
95 jgs 144
96 jgs 147 def doFinalization(self):
97 jgs 144 """print out the maximum error"""
98 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)

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26