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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 153 - (show annotations)
Tue Oct 25 01:51:20 2005 UTC (14 years ago) by jgs
File MIME type: text/x-python
File size: 2182 byte(s)
Merge of development branch dev-02 back to main trunk on 2005-10-25

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26