- Timestamp:
- May 24, 2010, 1:24:33 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_core/source/anuga/abstract_2d_finite_volumes/pmesh2domain.py
r7276 r7737 11 11 12 12 13 ##14 # @brief Convert a pmesh instance to a domain instance.15 # @param mesh The pmesh instance to convert.16 # @param DomainClass The class to instantiate and return.17 # @return The converted pmesh instance (as a 'DomainClass' instance).18 def pmesh_instance_to_domain_instance(mesh, DomainClass):19 """Convert a pmesh instance/object into a domain instance.20 21 Uses pmesh_to_domain_instance to convert a mesh file to a domain instance.22 """23 24 (vertex_coordinates, vertices, tag_dict, vertex_quantity_dict,25 tagged_elements_dict, geo_reference) = pmesh_to_domain(mesh_instance=mesh)26 27 # NOTE(Ole): This import cannot be at the module level28 # due to mutual dependency with domain.py29 from anuga.abstract_2d_finite_volumes.domain import Domain30 31 # ensure that the required 'DomainClass' actually is an instance of Domain32 msg = ('The class %s is not a subclass of the generic domain class %s'33 % (DomainClass, Domain))34 assert issubclass(DomainClass, Domain), msg35 36 # instantiate the result class37 result = DomainClass(coordinates=vertex_coordinates,38 vertices=vertices,39 boundary=tag_dict,40 tagged_elements=tagged_elements_dict,41 geo_reference=geo_reference)42 43 # set the water stage to be the elevation44 if (vertex_quantity_dict.has_key('elevation') and45 not vertex_quantity_dict.has_key('stage')):46 vertex_quantity_dict['stage'] = vertex_quantity_dict['elevation']47 result.set_quantity_vertices_dict(vertex_quantity_dict)48 49 return result50 51 13 52 14 ## 53 15 # @brief Convert a mesh file to a Domain instance. 54 # @param file_name Name of the file to convert (TSH or MSH).16 # @param source Name of the file to convert (TSH or MSH), or a mesh. 55 17 # @param DomainClass Class of return instance. 56 18 # @param use_cache True if caching is to be used. 57 19 # @param verbose True if this function is to be verbose. 58 20 # @return An instance of 'DomainClass' containing the file data. 59 def pmesh_to_domain_instance( file_name, DomainClass, use_cache=False,21 def pmesh_to_domain_instance(source, DomainClass, use_cache=False, 60 22 verbose=False): 61 23 """Converts a mesh file(.tsh or .msh), to a Domain instance. … … 71 33 if use_cache is True: 72 34 from caching import cache 73 result = cache(_pmesh_to_domain_instance, ( file_name, DomainClass),35 result = cache(_pmesh_to_domain_instance, (source, DomainClass), 74 36 dependencies=[file_name], verbose=verbose) 75 37 else: 76 result = apply(_pmesh_to_domain_instance, ( file_name, DomainClass))38 result = apply(_pmesh_to_domain_instance, (source, DomainClass)) 77 39 78 40 return result … … 84 46 # @param DomainClass Class of return instance. 85 47 # @return The DomainClass instance containing the file data. 86 def _pmesh_to_domain_instance( file_name, DomainClass):48 def _pmesh_to_domain_instance(source, DomainClass): 87 49 """Converts a mesh file(.tsh or .msh), to a Domain instance. 88 50 89 51 Internal function. See public interface pmesh_to_domain_instance for details 90 52 """ 91 92 (vertex_coordinates, vertices, tag_dict, vertex_quantity_dict, 93 tagged_elements_dict, geo_reference) = pmesh_to_domain(file_name=file_name) 94 95 # NOTE(Ole): This import cannot be at the module level due to mutual 96 # dependency with domain.py 97 from anuga.abstract_2d_finite_volumes.domain import Domain 53 54 from anuga.abstract_2d_finite_volumes.generic_domain import Generic_Domain 98 55 99 56 # ensure the required class is a subclass of Domain 100 57 msg = ('The class %s is not a subclass of the generic domain class %s' 101 % (DomainClass, Domain)) 102 assert issubclass(DomainClass, Domain), msg 58 % (DomainClass, Generic_Domain)) 59 assert issubclass(DomainClass, Generic_Domain), msg 60 61 if type(source).__name__ == 'str': 62 parm = {'file_name': source} 63 else: 64 parm = {'mesh_instance': source} 65 66 (vertex_coordinates, vertices, tag_dict, vertex_quantity_dict, 67 tagged_elements_dict, geo_reference) = pmesh_to_domain(**parm) 103 68 104 69 domain = DomainClass(coordinates = vertex_coordinates,
Note: See TracChangeset
for help on using the changeset viewer.