Ignore:
Timestamp:
May 24, 2010, 1:24:33 PM (14 years ago)
Author:
hudson
Message:

Various refactorings, all unit tests pass.
Domain renamed to generic domain.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • anuga_core/source/anuga/abstract_2d_finite_volumes/pmesh2domain.py

    r7276 r7737  
    1111
    1212
    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 level
    28     #            due to mutual dependency with domain.py
    29     from anuga.abstract_2d_finite_volumes.domain import Domain
    30 
    31     # ensure that the required 'DomainClass' actually is an instance of Domain
    32     msg = ('The class %s is not a subclass of the generic domain class %s'
    33            % (DomainClass, Domain))
    34     assert issubclass(DomainClass, Domain), msg
    35 
    36     # instantiate the result class
    37     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 elevation
    44     if (vertex_quantity_dict.has_key('elevation') and
    45         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 result
    50 
    5113
    5214##
    5315# @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.
    5517# @param DomainClass Class of return instance.
    5618# @param use_cache True if caching is to be used.
    5719# @param verbose True if this function is to be verbose.
    5820# @return An instance of 'DomainClass' containing the file data.
    59 def pmesh_to_domain_instance(file_name, DomainClass, use_cache=False,
     21def pmesh_to_domain_instance(source, DomainClass, use_cache=False,
    6022                             verbose=False):
    6123    """Converts a mesh file(.tsh or .msh), to a Domain instance.
     
    7133    if use_cache is True:
    7234        from caching import cache
    73         result = cache(_pmesh_to_domain_instance, (file_name, DomainClass),
     35        result = cache(_pmesh_to_domain_instance, (source, DomainClass),
    7436                       dependencies=[file_name], verbose=verbose)
    7537    else:
    76         result = apply(_pmesh_to_domain_instance, (file_name, DomainClass))       
     38        result = apply(_pmesh_to_domain_instance, (source, DomainClass))       
    7739       
    7840    return result
     
    8446# @param DomainClass Class of return instance.
    8547# @return The DomainClass instance containing the file data.
    86 def _pmesh_to_domain_instance(file_name, DomainClass):
     48def _pmesh_to_domain_instance(source, DomainClass):
    8749    """Converts a mesh file(.tsh or .msh), to a Domain instance.
    8850
    8951    Internal function. See public interface pmesh_to_domain_instance for details
    9052    """
    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
    9855
    9956    # ensure the required class is a subclass of Domain
    10057    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)
    10368
    10469    domain = DomainClass(coordinates = vertex_coordinates,
Note: See TracChangeset for help on using the changeset viewer.