source: inundation/ga/storm_surge/pyvolution/test_pmesh2domain.py @ 1102

Last change on this file since 1102 was 1028, checked in by steve, 20 years ago
File size: 5.7 KB
Line 
1#!/usr/bin/env python
2#
3
4import unittest
5#from math import sqrt
6#from Numeric import array, allclose, minimum, maximum, Float
7
8#from pytools.stats import mean
9#from domain import *
10#from boundary import *
11#from python_versions import compute_gradient
12#from config import epsilon
13#from shallow_water import attributes_2_field_values
14
15
16from Numeric import allclose, array
17
18from shallow_water import Domain
19
20from pmesh2domain import *
21
22from shallow_water import Domain, Reflective_boundary, Dirichlet_boundary,\
23     Transmissive_boundary
24
25
26class Test_pmesh2domain(unittest.TestCase):
27
28    def setUp(self):
29        pass
30
31    def tearDown(self):
32        pass
33
34    def test_pmesh2Domain(self):
35         import os
36         import tempfile
37
38         fileName = tempfile.mktemp(".tsh")
39         file = open(fileName,"w")
40         file.write("4 3 # <vertex #> <x> <y> [attributes]\n \
410 0.0 0.0 0.0 0.0 0.01 \n \
421 1.0 0.0 10.0 10.0 0.02  \n \
432 0.0 1.0 0.0 10.0 0.03  \n \
443 0.5 0.25 8.0 12.0 0.04  \n \
45# Vert att title  \n \
46elevation  \n \
47stage  \n \
48friction  \n \
492 # <triangle #> [<vertex #>] [<neigbouring triangle #>]  \n\
500 0 3 2 -1  -1  1 dsg\n\
511 0 1 3 -1  0 -1   ole nielsen\n\
524 # <segment #> <vertex #>  <vertex #> [boundary tag] \n\
530 1 0 2 \n\
541 0 2 3 \n\
552 2 3 \n\
563 3 1 1 \n\
573 0 # <x> <y> [attributes] ...Mesh Vertices... \n \
580 216.0 -86.0 \n \
591 160.0 -167.0 \n \
602 114.0 -91.0 \n \
613 # <vertex #>  <vertex #> [boundary tag] ...Mesh Segments... \n \
620 0 1 0 \n \
631 1 2 0 \n \
642 2 0 0 \n \
650 # <x> <y> ...Mesh Holes... \n \
660 # <x> <y> <attribute>...Mesh Regions... \n")
67         file.close()
68
69         tags = {}
70         b1 =  Dirichlet_boundary(conserved_quantities = array([0.0]))
71         b2 =  Dirichlet_boundary(conserved_quantities = array([1.0]))
72         b3 =  Dirichlet_boundary(conserved_quantities = array([2.0]))
73         tags["1"] = b1
74         tags["2"] = b2
75         tags["3"] = b3
76
77         domain = pmesh_to_domain_instance(fileName, Domain)
78         os.remove(fileName)
79
80         ## check the quantities
81         #print domain.quantities['elevation'].vertex_values
82         answer = [[0., 8., 0.],
83                   [0., 10., 8.]]
84         assert allclose(domain.quantities['elevation'].vertex_values,
85                        answer)
86
87         #print domain.quantities['stage'].vertex_values
88         answer = [[0., 12., 10.],
89                   [0., 10., 12.]]
90         assert allclose(domain.quantities['stage'].vertex_values,
91                        answer)
92
93         #print domain.quantities['friction'].vertex_values
94         answer = [[0.01, 0.04, 0.03],
95                   [0.01, 0.02, 0.04]]
96         assert allclose(domain.quantities['friction'].vertex_values,
97                        answer)
98
99         #print domain.quantities['friction'].vertex_values
100         assert allclose(domain.tagged_elements['dsg'][0],0)
101         assert allclose(domain.tagged_elements['ole nielsen'][0],1)
102
103         self.failUnless( domain.boundary[(1, 0)]  == '1',
104                          "test_tags_to_boundaries  failed. Single boundary wasn't added.")
105         self.failUnless( domain.boundary[(1, 2)]  == '2',
106                          "test_tags_to_boundaries  failed. Single boundary wasn't added.")
107         self.failUnless( domain.boundary[(0, 1)]  == '3',
108                          "test_tags_to_boundaries  failed. Single boundary wasn't added.")
109         self.failUnless( domain.boundary[(0, 0)]  == 'exterior',
110                          "test_tags_to_boundaries  failed. Single boundary wasn't added.")
111         #print "domain.boundary",domain.boundary
112         self.failUnless( len(domain.boundary)  == 4,
113                          "test_pmesh2Domain Too many boundaries")
114    def old_test_tags_to_boundaries (self):
115         meshDict = {}
116         p0 = [0.0, 0.0]
117         p1 = [1.0, 0.0]
118         p2 = [0.0, 1.0]
119         p3 = [0.646446609407, 0.353553390593]
120         meshDict['vertices'] = [p0,p1,p2,p3]
121         meshDict['vertex_attributes'] = [[0.0, 0.0,7.0],[10.0, 0.0,7.0],[0.0, 10.0,7.0],[6.46446609407, 3.53553390593,7.0]]
122         meshDict['triangles'] = [[0,3,2],[0,1,3]]
123         meshDict['triangle_tags'] = [6.6,6.6]
124         meshDict['triangle_neighbors'] = [[-1,-1,1],[-1,0,-1]]
125         meshDict['segments'] = [[1,0],[0,2],[2,3],[3,1]]
126         meshDict['segment_tags'] = [2,3,1,1]
127
128         domain = Domain.pmesh_dictionary_to_domain(meshDict)
129
130         #domain.set_tag_dict(tag_dict)
131         #Boundary tests
132         b1 =  Dirichlet_boundary(conserved_quantities = array([0.0]))
133         b2 =  Dirichlet_boundary(conserved_quantities = array([1.0]))
134         b3 =  Dirichlet_boundary(conserved_quantities = array([1.0]))
135         #test adding a boundary
136         tags = {}
137         tags[1] = b1
138         tags[2] = b2
139         tags[3] = b3
140         domain.set_boundary(tags)
141         inverted_id = Volume.instances[0].neighbours[0]
142         id = -(inverted_id+1)
143         boundary_value = Boundary_value.instances[id]
144         boundary_obj = boundary_value.boundary_object
145
146         self.failUnless( boundary_obj  == b1,
147                          "test_tags_to_boundaries  failed. Single boundary wasn't added.")
148
149         inverted_id = Volume.instances[0].neighbours[1]
150         id = -(inverted_id+1)
151         boundary_value = Boundary_value.instances[id]
152         boundary_obj = boundary_value.boundary_object
153         self.failUnless( boundary_obj  == b3,
154                          "test_tags_to_boundaries  failed. Single boundary wasn't added.")
155
156#-------------------------------------------------------------
157if __name__ == "__main__":
158    suite = unittest.makeSuite(Test_pmesh2domain, 'test')
159    runner = unittest.TextTestRunner()
160    runner.run(suite)
161
162
163
164
Note: See TracBrowser for help on using the repository browser.