Changeset 2601


Ignore:
Timestamp:
Mar 27, 2006, 1:54:32 PM (18 years ago)
Author:
duncan
Message:

Add mesh_file to Domain interface, ticket 56

Location:
inundation
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • inundation/examples/beach.py

    r2582 r2601  
    2828name = 'beach'
    2929print 'Creating domain from %s.tsh' %name
    30 domain = pmesh_to_domain_instance(name + '.tsh', Domain)
     30#domain = pmesh_to_domain_instance(name + '.tsh', Domain)
     31domain = Domain(mesh_file= name + '.tsh')
    3132
    3233domain.store = True
  • inundation/pyvolution/domain.py

    r2569 r2601  
    1414from generic_boundary_conditions import Time_boundary
    1515from generic_boundary_conditions import Transmissive_boundary
     16from pmesh2domain import _pmesh_to_domain
    1617
    1718import types
     
    1920class Domain(Mesh):
    2021
    21     def __init__(self, coordinates, vertices, boundary = None,
    22                  conserved_quantities = None, other_quantities = None,
    23                  tagged_elements = None, geo_reference = None,
    24                  use_inscribed_circle=False):
     22    def __init__(self, coordinates=None, vertices=None,
     23                 boundary=None,
     24                 conserved_quantities=None, other_quantities=None,
     25                 tagged_elements=None, geo_reference=None,
     26                 use_inscribed_circle=False,
     27                 mesh_file=None):
     28
     29        if mesh_file is not None:
     30            coordinates, vertices, boundary, vertex_quantity_dict \
     31                                ,tagged_elements, geo_reference = \
     32                                _pmesh_to_domain(file_name=mesh_file)
     33            # FIXME(DSG-DSG) have to do something with vertex_quantity_dict
    2534
    2635        Mesh.__init__(self, coordinates, vertices, boundary,
     
    100109        self.already_computed_flux = zeros((N, 3), Int)
    101110
     111        if mesh_file is not None:
     112            # If the mesh file passed any quantity values
     113            # , initialise with these values.
     114            self.set_quantity_vertices_dict(vertex_quantity_dict)
     115
     116       
    102117
    103118    def set_default_order(self, n):
  • inundation/pyvolution/shallow_water.py

    r2598 r2601  
    6969class Domain(Generic_Domain):
    7070
    71     def __init__(self, coordinates, vertices, boundary = None,
     71    def __init__(self, coordinates=None, vertices=None, boundary = None,
    7272                 tagged_elements = None, geo_reference = None,
    73                  use_inscribed_circle=False):
     73                 use_inscribed_circle=False,
     74                 mesh_file=None):
    7475
    7576        conserved_quantities = ['stage', 'xmomentum', 'ymomentum']
     
    7778        Generic_Domain.__init__(self, coordinates, vertices, boundary,
    7879                                conserved_quantities, other_quantities,
    79                                 tagged_elements, geo_reference, use_inscribed_circle)
     80                                tagged_elements, geo_reference, use_inscribed_circle, mesh_file)
    8081
    8182        from config import minimum_allowed_height, maximum_allowed_speed, g
     
    106107        self.quantities_to_be_stored = ['stage','xmomentum','ymomentum']
    107108
    108 
     109       
    109110    def set_quantities_to_be_stored(self, q):
    110111        """Specify which quantities will be stored in the sww file.
  • inundation/pyvolution/test_shallow_water.py

    r2566 r2601  
    32783278
    32793279
     3280    def test_pmesh2Domain(self):
     3281         import os
     3282         import tempfile
     3283
     3284         fileName = tempfile.mktemp(".tsh")
     3285         file = open(fileName,"w")
     3286         file.write("4 3 # <vertex #> <x> <y> [attributes]\n \
     32870 0.0 0.0 0.0 0.0 0.01 \n \
     32881 1.0 0.0 10.0 10.0 0.02  \n \
     32892 0.0 1.0 0.0 10.0 0.03  \n \
     32903 0.5 0.25 8.0 12.0 0.04  \n \
     3291# Vert att title  \n \
     3292elevation  \n \
     3293stage  \n \
     3294friction  \n \
     32952 # <triangle #> [<vertex #>] [<neigbouring triangle #>]  \n\
     32960 0 3 2 -1  -1  1 dsg\n\
     32971 0 1 3 -1  0 -1   ole nielsen\n\
     32984 # <segment #> <vertex #>  <vertex #> [boundary tag] \n\
     32990 1 0 2 \n\
     33001 0 2 3 \n\
     33012 2 3 \n\
     33023 3 1 1 \n\
     33033 0 # <x> <y> [attributes] ...Mesh Vertices... \n \
     33040 216.0 -86.0 \n \
     33051 160.0 -167.0 \n \
     33062 114.0 -91.0 \n \
     33073 # <vertex #>  <vertex #> [boundary tag] ...Mesh Segments... \n \
     33080 0 1 0 \n \
     33091 1 2 0 \n \
     33102 2 0 0 \n \
     33110 # <x> <y> ...Mesh Holes... \n \
     33120 # <x> <y> <attribute>...Mesh Regions... \n \
     33130 # <x> <y> <attribute>...Mesh Regions, area... \n\
     3314#Geo reference \n \
     331556 \n \
     3316140 \n \
     3317120 \n")
     3318         file.close()
     3319
     3320         tags = {}
     3321         b1 =  Dirichlet_boundary(conserved_quantities = array([0.0]))
     3322         b2 =  Dirichlet_boundary(conserved_quantities = array([1.0]))
     3323         b3 =  Dirichlet_boundary(conserved_quantities = array([2.0]))
     3324         tags["1"] = b1
     3325         tags["2"] = b2
     3326         tags["3"] = b3
     3327
     3328         #from pmesh2domain import pmesh_to_domain_instance
     3329         #domain = pmesh_to_domain_instance(fileName, Domain)
     3330         
     3331         domain = Domain(mesh_file=fileName)
     3332         
     3333         os.remove(fileName)
     3334         #print "domain.tagged_elements", domain.tagged_elements
     3335         ## check the quantities
     3336         #print domain.quantities['elevation'].vertex_values
     3337         answer = [[0., 8., 0.],
     3338                   [0., 10., 8.]]
     3339         assert allclose(domain.quantities['elevation'].vertex_values,
     3340                        answer)
     3341
     3342         #print domain.quantities['stage'].vertex_values
     3343         answer = [[0., 12., 10.],
     3344                   [0., 10., 12.]]
     3345         assert allclose(domain.quantities['stage'].vertex_values,
     3346                        answer)
     3347
     3348         #print domain.quantities['friction'].vertex_values
     3349         answer = [[0.01, 0.04, 0.03],
     3350                   [0.01, 0.02, 0.04]]
     3351         assert allclose(domain.quantities['friction'].vertex_values,
     3352                        answer)
     3353
     3354         #print domain.quantities['friction'].vertex_values
     3355         assert allclose(domain.tagged_elements['dsg'][0],0)
     3356         assert allclose(domain.tagged_elements['ole nielsen'][0],1)
     3357
     3358         self.failUnless( domain.boundary[(1, 0)]  == '1',
     3359                          "test_tags_to_boundaries  failed. Single boundary wasn't added.")
     3360         self.failUnless( domain.boundary[(1, 2)]  == '2',
     3361                          "test_tags_to_boundaries  failed. Single boundary wasn't added.")
     3362         self.failUnless( domain.boundary[(0, 1)]  == '3',
     3363                          "test_tags_to_boundaries  failed. Single boundary wasn't added.")
     3364         self.failUnless( domain.boundary[(0, 0)]  == 'exterior',
     3365                          "test_tags_to_boundaries  failed. Single boundary wasn't added.")
     3366         #print "domain.boundary",domain.boundary
     3367         self.failUnless( len(domain.boundary)  == 4,
     3368                          "test_pmesh2Domain Too many boundaries")
     3369         #FIXME change to use get_xllcorner
     3370         #print "d.geo_reference.xllcorner",domain.geo_reference.xllcorner
     3371         self.failUnless(domain.geo_reference.xllcorner  == 140.0,
     3372                          "bad geo_referece")
     3373    #************
     3374
    32803375        #-------------------------------------------------------------
    32813376if __name__ == "__main__":
Note: See TracChangeset for help on using the changeset viewer.