/[escript]/trunk/escript/test/python/DataVariableTests.py
ViewVC logotype

Contents of /trunk/escript/test/python/DataVariableTests.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 342 - (show annotations)
Tue Dec 13 01:50:42 2005 UTC (13 years, 10 months ago) by jgs
File MIME type: text/x-python
File size: 2166 byte(s)
minor formatting fix

1 import sys
2 import unittest
3 import os
4
5 from esys.escript import *
6 from esys import bruce
7
8 import numarray
9
10 """
11
12 Tests for DataVariable
13
14 Version $Id$
15
16 """
17
18 from numarray import array,Float64,ones,greater
19
20 # list of arguments: a list item has the form [a0,a1,a2]
21 # what a0 is the default value and a1 is used for tag Tag1
22 # and a2 for tag2. a0,a1,a2 are converted into numarrays.
23
24 arglist = [ \
25 [3,4], \
26 [[1,2],[3,4]], \
27 [[15,8],[12,8]], \
28 [[[15,8],[12,8]],[[-9,9],[13,8]]], \
29 3.0 \
30 ]
31
32 def turnToArray(val):
33 out=array(val,Float64)
34 return out
35
36 def prepareArg(val,ex,wh):
37 if ex=="Expanded":
38 exx=True
39 else:
40 exx=False
41 out=Data(val,what=wh,expand=exx)
42 return out
43
44 def checkResult(text,res,val0,val1,val2,wh):
45 ref=Data(val0,what=wh,expand=False)
46 ref.setTaggedValue(Tag1,val1)
47 ref.setTaggedValue(Tag2,val2)
48 norm=Lsup(ref)+tol
49 error=Lsup(ref-res)/norm
50 print "@@ %s, shape %s: error = %e"%(text,ref.getShape(),error)
51 if error>tol:
52 #raise SystemError,"@@ %s at %s: error is too large"%(text,wh)
53 print "**** %s : error is too large"%(text)
54
55 def getRank(arg):
56 if isinstance(arg,Data):
57 return arg.getRank()
58 else:
59 g=array(arg)
60 if g.rank==0:
61 return 1
62 else:
63 return g.rank
64
65 def isScalar(arg):
66 if isinstance(arg,Data):
67 if arg.getRank()==1 and arg.getShape()[0]==1:
68 return not None
69 else:
70 return None
71 else:
72 g=array(arg)
73 if g.rank==0:
74 return not None
75 else:
76 if g.rank==1 and g.shape[0]==1:
77 return not None
78 else:
79 return None
80
81 #
82 # ==============================================================
83
84 print "\nTests of DataVariable"
85
86 msh=bruce.Rectangle(2,3)
87
88 d1 = Data(1.0,Function(msh),True)
89 d2 = Data(2.0,Function(msh),True)
90 d3 = Data(3.0,Function(msh),True)
91 d4 = Data(4.0,Function(msh),True)
92
93 dv0 = DataVariable()
94 dv1 = DataVariable(d1)
95 dv2 = DataVariable(d2)
96 dv3 = DataVariable(d3)
97 dv4 = DataVariable(d4)
98
99 dv3.sum(dv4)
100 dv2.diff(dv3)
101 dv1.sum(dv2)
102
103 d5 = dv1.evaluate()
104
105 #print d5.toString()
106
107 sys.exit(0)
108 # end

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26