/[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 6651 - (hide annotations)
Wed Feb 7 02:12:08 2018 UTC (23 months, 1 week ago) by jfenwick
File MIME type: text/x-python
File size: 5147 byte(s)
Make everyone sad by touching all the files

Copyright dates update

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