/[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 1809 - (hide annotations)
Thu Sep 25 06:43:44 2008 UTC (10 years, 10 months ago) by ksteube
File MIME type: text/x-python
File size: 4923 byte(s)
Copyright updated in all python files

1 ksteube 1809
2     ########################################################
3 ksteube 1312 #
4 ksteube 1809 # Copyright (c) 2003-2008 by University of Queensland
5     # Earth Systems Science Computational Center (ESSCC)
6     # http://www.uq.edu.au/esscc
7 ksteube 1312 #
8 ksteube 1809 # Primary Business: Queensland, Australia
9     # Licensed under the Open Software License version 3.0
10     # http://www.opensource.org/licenses/osl-3.0.php
11 ksteube 1312 #
12 ksteube 1809 ########################################################
13 jgs 144
14 ksteube 1809 __copyright__="""Copyright (c) 2003-2008 by University of Queensland
15     Earth Systems Science Computational Center (ESSCC)
16     http://www.uq.edu.au/esscc
17     Primary Business: Queensland, Australia"""
18 elspeth 628 __license__="""Licensed under the Open Software License version 3.0
19 ksteube 1809 http://www.opensource.org/licenses/osl-3.0.php"""
20     __url__="http://www.uq.edu.au/esscc/escript-finley"
21 elspeth 628
22 jgs 149 from esys.escript.modelframe import Model,ParameterSet
23     from esys.escript.escript import Data
24     from esys.escript.util import *
25 jgs 144
26    
27 jgs 148 class EvaluateExpression(ParameterSet):
28 jgs 149 """
29     Return the evaluation of an expression at current time t and
30     locations in the domain
31 jgs 144
32 jgs 149 @warning: this class use python's eval function!!!!!
33     Please use input.InterpolateOverBox is possible!!!!
34     @ivar expression (in): expression or list of expressions defining
35     expression value
36     @ivar out (callable): current value of the expression
37     """
38 jgs 147
39 gross 918 def __init__(self,**kwargs):
40 jgs 149 """
41     Set up parameters
42     """
43 gross 918 super(EvaluateExpression, self).__init__(**kwargs)
44 jgs 147 self.declareParameter(domain=None, \
45     t=0., \
46     expression="x[0]")
47    
48     def out(self):
49     x=self.domain.getX()
50     t=self.t
51     if isinstance(self.expression,str):
52     out=eval(self.expression)
53     else:
54     out=Data(0,(len(self.expression),),x.getFunctionSpace())
55     for i in range(len(self.expression)): out[i]=eval(self.expression[i])
56     return out
57    
58 jgs 144 class Probe(Model):
59 jgs 149 """
60     Tests values against a expression which may depend on time and spatial
61     coordinates.
62    
63     It prints out the relative error in each time step and the maximum
64     relative error over all time steps at the end.
65 jgs 144
66 jgs 149 @warning: this class use python's eval function!!!!!
67     @ivar value (in): values to be tested
68     @ivar expression (in): expressions defining expression values to test against. If None only value is reported.
69     @ivar line_tag (in): tag to be used when printing error
70     @ivar t (in): current time
71     @ivar max_error (out): maximum error
72     @ivar t_max (out): time of maximum error
73 jgs 144
74 jgs 149 """
75 jgs 144
76 gross 918 def __init__(self,**kwargs):
77 jgs 149 """
78     Set up parameters
79     """
80 gross 918 super(Probe, self).__init__(**kwargs)
81 jgs 147 self.declareParameter(expression=None, \
82 jgs 144 value=0., \
83 jgs 147 t=0., \
84 jgs 144 line_tag="PROBE")
85    
86 jgs 147 def doInitialization(self):
87 jgs 149 """
88     Initializes values
89     """
90 jgs 144 self.t_max=None
91 jgs 147 self.max_error=0.
92 jgs 144
93 jgs 147 def doStepPostprocessing(self,dt):
94     t=self.t
95     print "%s : time %e"%(self.line_tag,t)
96 jgs 144 v=self.value
97     x=v.getFunctionSpace().getX()
98     if v.getRank()==0:
99 jgs 147 if self.expression==None:
100     print "%s : true (min,max)= (%e,%e)"%(self.line_tag,inf(v),sub(v))
101 jgs 144 else:
102 jgs 147 ref=eval(self.expression)
103 jgs 144 err=Lsup(v-ref)/Lsup(ref)
104 jgs 147 print "%s : true (min,max)= (%e,%e)"%(self.line_tag,inf(ref),sup(ref))
105     print "%s : (min,max,rel error)= (%e,%e,%e)"%(self.line_tag,inf(v),sup(v),err)
106 jgs 144 else:
107     err=0
108     for i in range(v.getRank()):
109     vi=v[i]
110 jgs 147 if self.expression==None:
111     print "%s : component %d: true (min,max)= (%e,%e)"%(self.line_tag,i,inf(vi))
112 jgs 144 else:
113 jgs 147 refi=eval(self.expression[i])
114 jgs 144 erri=Lsup(vi-refi)/Lsup(refi)
115 jgs 147 print "%s : component %d true (min,max)= (%e,%e)"%(self.line_tag,i,inf(refi),sup(refi))
116     print "%s : component %d (min,max,rel error)= (%e,%e,%e,%e,%e)"%(self.line_tag,i,inf(vi),sup(vi),erri)
117 jgs 144 err=max(err,erri)
118 jgs 147 if not self.expression==None: print "%s : maximum error %e",err
119 jgs 144
120 jgs 147 if not self.expression==None:
121     if err>self.max_error:
122     self.t_max=t
123     self.max_error=err
124 jgs 144
125 jgs 147 def doFinalization(self):
126 jgs 149 """
127     Print out the maximum error.
128     """
129 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)
130 jgs 149
131     # 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