Changeset 2056


Ignore:
Timestamp:
Nov 24, 2005, 10:27:59 AM (19 years ago)
Author:
duncan
Message:

create a domain instance from a pmesh.mesh instance

Location:
inundation
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • inundation/examples/run_gippsland.py

    r2022 r2056  
    11from pyvolution.data_manager import asc_csiro2sww
     2import time
     3
     4t0 = time.time()
     5
    26
    37asc_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,
    510              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
     18print 'That took %.2f seconds' %(time.time()-t0)
  • inundation/pyvolution/pmesh2domain.py

    r1557 r2056  
    77"""
    88
     9# FXME (DSG-DSG): Combine with function pmesh_to_domain_instance
     10def 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
    940
    1041def pmesh_to_domain_instance(fileName, DomainClass, setting_function = None):
     
    1647    vertex_coordinates, vertices, tag_dict, vertex_quantity_dict \
    1748                        ,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)
    1951
    2052
     
    5284
    5385
    54 def pmesh_to_domain(fileName, setting_function = None):
     86def pmesh_to_domain(fileName=None,
     87                    mesh_instance=None,
     88                    setting_function=None):
    5589    """
    5690    convert a pmesh dictionary to a list of Volumes.
     
    69103    from load_mesh.loadASCII import import_mesh_file
    70104
    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)
    72109    #print "mesh_dict",mesh_dict
    73110    vertex_coordinates = mesh_dict['vertices']
     
    98135    #print "DSG pm2do tagged_elements", tagged_elements
    99136    return tagged_elements
    100 
    101 #FIXME: The issue is whether this format should be stored in the tsh file
    102 #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. -DSG
    106 
    107 #FIXME: Another issue is that the tsh file stores consecutive
    108 #indices explicitly. This is really redundant.
    109 #Suggest looking at obj and our own sww format and also consider
    110 #using netCDF.
    111 
    112 # It is redundant.  It was the format originally decided on.
    113 # I'm happy for it to change. -DSG
    114137
    115138def pmesh_dict_to_tag_dict(mesh_dict):
  • inundation/pyvolution/test_pmesh2domain.py

    r1422 r2056  
    33
    44import 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 
    155
    166from Numeric import allclose, array
     
    2515from coordinate_transforms.geo_reference import Geo_reference
    2616
     17#This is making pyvolution dependent on pmesh.
     18# not good.  this should be in a seperate package.(directory)
     19from pmesh.mesh import importMeshFromFile
    2720
    2821class Test_pmesh2domain(unittest.TestCase):
     
    123116         self.failUnless(domain.geo_reference.xllcorner  == 140.0,
    124117                          "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 \
     1270 0.0 0.0 0.0 0.0 0.01 \n \
     1281 1.0 0.0 10.0 10.0 0.02  \n \
     1292 0.0 1.0 0.0 10.0 0.03  \n \
     1303 0.5 0.25 8.0 12.0 0.04  \n \
     131# Vert att title  \n \
     132elevation  \n \
     133stage  \n \
     134friction  \n \
     1352 # <triangle #> [<vertex #>] [<neigbouring triangle #>]  \n\
     1360 0 3 2 -1  -1  1 dsg\n\
     1371 0 1 3 -1  0 -1   ole nielsen\n\
     1384 # <segment #> <vertex #>  <vertex #> [boundary tag] \n\
     1390 1 0 2 \n\
     1401 0 2 3 \n\
     1412 2 3 \n\
     1423 3 1 1 \n\
     1433 0 # <x> <y> [attributes] ...Mesh Vertices... \n \
     1440 216.0 -86.0 \n \
     1451 160.0 -167.0 \n \
     1462 114.0 -91.0 \n \
     1473 # <vertex #>  <vertex #> [boundary tag] ...Mesh Segments... \n \
     1480 0 1 0 \n \
     1491 1 2 0 \n \
     1502 2 0 0 \n \
     1510 # <x> <y> ...Mesh Holes... \n \
     1520 # <x> <y> <attribute>...Mesh Regions... \n \
     1530 # <x> <y> <attribute>...Mesh Regions, area... \n\
     154#Geo reference \n \
     15556 \n \
     156140 \n \
     157120 \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")
    125211         
     212    #***********
    126213    def old_test_tags_to_boundaries (self):
    127214         meshDict = {}
Note: See TracChangeset for help on using the changeset viewer.