2
########################################################
4
# Copyright (c) 2003-2010 by University of Queensland
5
# Earth Systems Science Computational Center (ESSCC)
6
# http://www.uq.edu.au/esscc
8
# Primary Business: Queensland, Australia
9
# Licensed under the Open Software License version 3.0
10
# http://www.opensource.org/licenses/osl-3.0.php
12
########################################################
14
__copyright__="""Copyright (c) 2003-2010 by University of Queensland
15
Earth Systems Science Computational Center (ESSCC)
16
http://www.uq.edu.au/esscc
17
Primary Business: Queensland, Australia"""
18
__license__="""Licensed under the Open Software License version 3.0
19
http://www.opensource.org/licenses/osl-3.0.php"""
20
__url__="https://launchpad.net/escript-finley"
25
from esys.escript import *
26
from esys.dudley import Rectangle
29
from test_objects import Test_Dump, Test_SetDataPointValue, Test_saveCSV, Test_TableInterpolation
30
from test_objects import Test_Domain, Test_GlobalMinMax, Test_Lazy
32
from test_shared import Test_Shared
35
DUDLEY_WORKDIR=os.environ['DUDLEY_WORKDIR']
39
NE=4 # number elements, must be even
41
class Test_SharedOnDudley(Test_Shared):
43
self.domain=Rectangle(NE,NE)
49
class Test_DomainOnDudley(Test_Domain):
51
self.boundary_tag_list = [1, 2, 10, 20]
52
self.domain =Rectangle(NE,NE+1,2)
55
del self.boundary_tag_list
57
def test_tagsContinuousFunction(self):
59
tags=ContinuousFunction(self.domain).getListOfTags()
60
self.failUnless(len(tags)==len(ref_tags), "tags list has wrong length.")
61
for i in ref_tags: self.failUnless(i in tags,"tag %s is missing."%i)
63
def test_tagsFunction(self):
65
tags=Function(self.domain).getListOfTags()
66
self.failUnless(len(tags)==len(ref_tags), "tags list has wrong length.")
67
for i in ref_tags: self.failUnless(i in tags,"tag %s is missing."%i)
68
def test_tagsReducedFunction(self):
70
tags=ReducedFunction(self.domain).getListOfTags()
71
self.failUnless(len(tags)==len(ref_tags), "tags list has wrong length.")
72
for i in ref_tags: self.failUnless(i in tags,"tag %s is missing."%i)
73
def test_tagsFunctionOnBoundary(self):
74
ref_tags=[1, 2, 10, 20]
75
tags=FunctionOnBoundary(self.domain).getListOfTags()
76
# For an MPI-distributed domain some tags may be missing
77
if getMPISizeWorld() == 1: self.failUnless(len(tags)==len(ref_tags), "tags list has wrong length.")
78
for i in tags: self.failUnless(i in ref_tags,"tag %s is missing."%i)
79
def test_tagsReducedFunctionOnBoundary(self):
80
ref_tags=[1, 2, 10, 20]
81
tags=ReducedFunctionOnBoundary(self.domain).getListOfTags()
82
# For an MPI-distributed domain some tags may be missing
83
if getMPISizeWorld() == 1: self.failUnless(len(tags)==len(ref_tags), "tags list has wrong length.")
84
for i in tags: self.failUnless(i in ref_tags,"tag %s is missing."%i)
86
class Test_DataOpsOnDudley(Test_Dump, Test_SetDataPointValue, Test_GlobalMinMax, Test_Lazy):
88
self.domain =Rectangle(NE,NE+1,2)
89
self.domain_with_different_number_of_samples =Rectangle(2*NE,NE+1,2)
90
self.domain_with_different_number_of_data_points_per_sample =Rectangle(2*NE,NE+1,2,integrationOrder=2)
91
self.domain_with_different_sample_ordering =Rectangle(NE,NE+1,2, optimize=True)
92
self.filename_base=DUDLEY_WORKDIR
93
self.mainfs=Function(self.domain)
94
self.otherfs=Solution(self.domain)
98
del self.domain_with_different_number_of_samples
99
del self.domain_with_different_number_of_data_points_per_sample
100
del self.domain_with_different_sample_ordering
106
class Test_TableInterpolationOnDudley(Test_TableInterpolation):
108
self.domain=Rectangle(4,4)
109
self.functionspaces=[ContinuousFunction(self.domain), Function(self.domain), ReducedFunction(self.domain),
110
FunctionOnBoundary(self.domain), ReducedFunctionOnBoundary(self.domain)]
111
#We aren't testing DiracDeltaFunction
112
self.xn=3 # number of grids on x axis
113
self.yn=3 # number of grids on y axis
117
del self.functionspaces
122
class Test_CSVOnDudley(Test_saveCSV):
124
self.domain =Rectangle(NE,NE+1)
125
self.linecount1=31 #see test_save1 for the meaning of these params
127
self.line_expected=[0.25, 0., 0.25]
132
#This test checks to see that all FunctionSpaces can be saved
133
def test_singleFS(self):
134
fname="test_singlefs.csv"
135
fss=[ContinuousFunction(self.domain), Function(self.domain), ReducedFunction(self.domain),
136
FunctionOnBoundary(self.domain), ReducedFunctionOnBoundary(self.domain),
137
DiracDeltaFunction(self.domain)]
140
print "Testing "+str(f)+"\n"
141
saveDataCSV(fname, D=d)
143
def test_multiFS(self):
144
fname="test_multifs.csv"
145
sol=Data(8,Solution(self.domain))
146
ctsfn=Data(9,ContinuousFunction(self.domain))
148
dirac=Data(-1,DiracDeltaFunction(self.domain))
149
saveDataCSV(fname, A=sol, B=ctsfn, C=dirac)
151
fun=Data(5,Function(self.domain))
152
rfun=Data(3,ReducedFunction(self.domain))
153
saveDataCSV(fname, A=sol,B=ctsfn,C=fun, D=rfun)
155
bound=Data(1,FunctionOnBoundary(self.domain))
156
rbound=Data(3,ReducedFunctionOnBoundary(self.domain))
157
saveDataCSV(fname,A=sol,B=ctsfn,C=bound, D=rbound)
160
if __name__ == '__main__':
161
suite = unittest.TestSuite()
162
#suite.addTest(unittest.makeSuite(Test_SharedOnDudley))
163
#suite.addTest(unittest.makeSuite(Test_DataOpsOnDudley))
164
#suite.addTest(unittest.makeSuite(Test_DomainOnDudley))
165
#suite.addTest(unittest.makeSuite(Test_TableInterpolationOnDudley))
166
suite.addTest(unittest.makeSuite(Test_CSVOnDudley))
167
s=unittest.TextTestRunner(verbosity=2).run(suite)
168
if not s.wasSuccessful(): sys.exit(1)