Changeset 2056
- Timestamp:
- Nov 24, 2005, 10:27:59 AM (19 years ago)
- Location:
- inundation
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
inundation/examples/run_gippsland.py
r2022 r2056 1 1 from pyvolution.data_manager import asc_csiro2sww 2 import time 3 4 t0 = time.time() 5 2 6 3 7 asc_csiro2sww('bathymetry_expanded','elev_expanded','ucur_expanded', 4 'vcur_expanded', 'test.sww',zscale=1000, mean_stage = 100, 8 'vcur_expanded', 'test_extent_true_38.25__37.7__147__148.25.sww',zscale=1, 9 mean_stage = 0, 5 10 fail_on_NaN = False, 6 elevation_NaN_filler = 0) 11 elevation_NaN_filler = 0 12 , 13 minlat = -38.25, maxlat = -37.7, ###-37.75, 14 minlon = 147.0, maxlon = 148.25 15 , verbose = True 16 ) 17 18 print 'That took %.2f seconds' %(time.time()-t0) -
inundation/pyvolution/pmesh2domain.py
r1557 r2056 7 7 """ 8 8 9 # FXME (DSG-DSG): Combine with function pmesh_to_domain_instance 10 def pmesh_instance_to_domain_instance(mesh, 11 DomainClass, 12 setting_function=None): 13 """ 14 """ 15 import sys 16 from domain import Domain 17 18 vertex_coordinates, vertices, tag_dict, vertex_quantity_dict \ 19 ,tagged_elements_dict, geo_reference = \ 20 pmesh_to_domain(mesh_instance=mesh, 21 setting_function=setting_function) 22 23 24 assert issubclass(DomainClass, Domain),"DomainClass is not a subclass of Domain." 25 26 27 domain = DomainClass(coordinates = vertex_coordinates, 28 vertices = vertices, 29 boundary = tag_dict, 30 tagged_elements = tagged_elements_dict, 31 geo_reference = geo_reference ) 32 33 # set the water stage to be the elevation 34 if vertex_quantity_dict.has_key('elevation') and not vertex_quantity_dict.has_key('stage'): 35 vertex_quantity_dict['stage'] = vertex_quantity_dict['elevation'] 36 37 domain.set_quantity_vertices_dict(vertex_quantity_dict) 38 #print "vertex_quantity_dict",vertex_quantity_dict 39 return domain 9 40 10 41 def pmesh_to_domain_instance(fileName, DomainClass, setting_function = None): … … 16 47 vertex_coordinates, vertices, tag_dict, vertex_quantity_dict \ 17 48 ,tagged_elements_dict, geo_reference = \ 18 pmesh_to_domain(fileName, setting_function=setting_function) 49 pmesh_to_domain(fileName=fileName, 50 setting_function=setting_function) 19 51 20 52 … … 52 84 53 85 54 def pmesh_to_domain(fileName, setting_function = None): 86 def pmesh_to_domain(fileName=None, 87 mesh_instance=None, 88 setting_function=None): 55 89 """ 56 90 convert a pmesh dictionary to a list of Volumes. … … 69 103 from load_mesh.loadASCII import import_mesh_file 70 104 71 mesh_dict = import_mesh_file(fileName) 105 if fileName is None: 106 mesh_dict = mesh_instance.Mesh2IODict() 107 else: 108 mesh_dict = import_mesh_file(fileName) 72 109 #print "mesh_dict",mesh_dict 73 110 vertex_coordinates = mesh_dict['vertices'] … … 98 135 #print "DSG pm2do tagged_elements", tagged_elements 99 136 return tagged_elements 100 101 #FIXME: The issue is whether this format should be stored in the tsh file102 #instead of having to be created here?103 104 #This information is pyvolution focused, not mesh generation focused.105 #This is an appropriate place for the info to be created. -DSG106 107 #FIXME: Another issue is that the tsh file stores consecutive108 #indices explicitly. This is really redundant.109 #Suggest looking at obj and our own sww format and also consider110 #using netCDF.111 112 # It is redundant. It was the format originally decided on.113 # I'm happy for it to change. -DSG114 137 115 138 def pmesh_dict_to_tag_dict(mesh_dict): -
inundation/pyvolution/test_pmesh2domain.py
r1422 r2056 3 3 4 4 import unittest 5 #from math import sqrt6 #from Numeric import array, allclose, minimum, maximum, Float7 8 #from pytools.stats import mean9 #from domain import *10 #from boundary import *11 #from python_versions import compute_gradient12 #from config import epsilon13 #from shallow_water import attributes_2_field_values14 15 5 16 6 from Numeric import allclose, array … … 25 15 from coordinate_transforms.geo_reference import Geo_reference 26 16 17 #This is making pyvolution dependent on pmesh. 18 # not good. this should be in a seperate package.(directory) 19 from pmesh.mesh import importMeshFromFile 27 20 28 21 class Test_pmesh2domain(unittest.TestCase): … … 123 116 self.failUnless(domain.geo_reference.xllcorner == 140.0, 124 117 "bad geo_referece") 118 #************ 119 120 def test_pmesh2Domain_instance(self): 121 import os 122 import tempfile 123 124 fileName = tempfile.mktemp(".tsh") 125 file = open(fileName,"w") 126 file.write("4 3 # <vertex #> <x> <y> [attributes]\n \ 127 0 0.0 0.0 0.0 0.0 0.01 \n \ 128 1 1.0 0.0 10.0 10.0 0.02 \n \ 129 2 0.0 1.0 0.0 10.0 0.03 \n \ 130 3 0.5 0.25 8.0 12.0 0.04 \n \ 131 # Vert att title \n \ 132 elevation \n \ 133 stage \n \ 134 friction \n \ 135 2 # <triangle #> [<vertex #>] [<neigbouring triangle #>] \n\ 136 0 0 3 2 -1 -1 1 dsg\n\ 137 1 0 1 3 -1 0 -1 ole nielsen\n\ 138 4 # <segment #> <vertex #> <vertex #> [boundary tag] \n\ 139 0 1 0 2 \n\ 140 1 0 2 3 \n\ 141 2 2 3 \n\ 142 3 3 1 1 \n\ 143 3 0 # <x> <y> [attributes] ...Mesh Vertices... \n \ 144 0 216.0 -86.0 \n \ 145 1 160.0 -167.0 \n \ 146 2 114.0 -91.0 \n \ 147 3 # <vertex #> <vertex #> [boundary tag] ...Mesh Segments... \n \ 148 0 0 1 0 \n \ 149 1 1 2 0 \n \ 150 2 2 0 0 \n \ 151 0 # <x> <y> ...Mesh Holes... \n \ 152 0 # <x> <y> <attribute>...Mesh Regions... \n \ 153 0 # <x> <y> <attribute>...Mesh Regions, area... \n\ 154 #Geo reference \n \ 155 56 \n \ 156 140 \n \ 157 120 \n") 158 file.close() 159 160 mesh_instance = importMeshFromFile(fileName) 161 162 tags = {} 163 b1 = Dirichlet_boundary(conserved_quantities = array([0.0])) 164 b2 = Dirichlet_boundary(conserved_quantities = array([1.0])) 165 b3 = Dirichlet_boundary(conserved_quantities = array([2.0])) 166 tags["1"] = b1 167 tags["2"] = b2 168 tags["3"] = b3 169 170 domain = pmesh_instance_to_domain_instance(mesh_instance, Domain) 171 os.remove(fileName) 172 #print "domain.tagged_elements", domain.tagged_elements 173 ## check the quantities 174 #print domain.quantities['elevation'].vertex_values 175 answer = [[0., 8., 0.], 176 [0., 10., 8.]] 177 assert allclose(domain.quantities['elevation'].vertex_values, 178 answer) 179 180 #print domain.quantities['stage'].vertex_values 181 answer = [[0., 12., 10.], 182 [0., 10., 12.]] 183 assert allclose(domain.quantities['stage'].vertex_values, 184 answer) 185 186 #print domain.quantities['friction'].vertex_values 187 answer = [[0.01, 0.04, 0.03], 188 [0.01, 0.02, 0.04]] 189 assert allclose(domain.quantities['friction'].vertex_values, 190 answer) 191 192 #print domain.quantities['friction'].vertex_values 193 assert allclose(domain.tagged_elements['dsg'][0],0) 194 assert allclose(domain.tagged_elements['ole nielsen'][0],1) 195 196 self.failUnless( domain.boundary[(1, 0)] == '1', 197 "test_tags_to_boundaries failed. Single boundary wasn't added.") 198 self.failUnless( domain.boundary[(1, 2)] == '2', 199 "test_tags_to_boundaries failed. Single boundary wasn't added.") 200 self.failUnless( domain.boundary[(0, 1)] == '3', 201 "test_tags_to_boundaries failed. Single boundary wasn't added.") 202 self.failUnless( domain.boundary[(0, 0)] == 'exterior', 203 "test_tags_to_boundaries failed. Single boundary wasn't added.") 204 #print "domain.boundary",domain.boundary 205 self.failUnless( len(domain.boundary) == 4, 206 "test_pmesh2Domain Too many boundaries") 207 #FIXME change to use get_xllcorner 208 #print "d.geo_reference.xllcorner",domain.geo_reference.xllcorner 209 self.failUnless(domain.geo_reference.xllcorner == 140.0, 210 "bad geo_referece") 125 211 212 #*********** 126 213 def old_test_tags_to_boundaries (self): 127 214 meshDict = {}
Note: See TracChangeset
for help on using the changeset viewer.