コード例 #1
0
def load_inp_file():
    r"""
    Loads in an APM-MODEL input file if it was supplied and pulls out
    required information.
    """
    global namespace, export, apm_input_file, map_data_field, block_mesh
    #
    # loading file and getting all uncommented lines
    apm_input_file = InputFile(namespace.input_file)
    input_args = apm_input_file.get_uncommented_values()
    #
    # building actual path to map file based on input file location
    file_path = os.path.realpath(namespace.input_file)
    map_path = input_args['APER-MAP'].value
    map_path = os.path.join(os.path.split(file_path)[0], map_path)
    map_path = os.path.realpath(map_path)
    #
    try:
        map_data_field = DataField(map_path)
    except FileNotFoundError:
        logger.warn('Aperture map file was not found at path: '+map_path)
    #
    # setting transport and bc params from file
    input_params = [
        ('MAP', 'avg_fact', 1.0),
        ('HIGH-MASK', 'high_mask', 1.0E6),
        ('LOW-MASK', 'low_mask', 0.0),
        ('ROUGHNESS', 'roughness', 0.0),
        ('VOXEL', 'voxel_size', 1.0),
        ('INLET-PRESS', 'inlet_p', None),
        ('OUTLET-PRESS', 'outlet_p', None),
        ('INLET-RATE', 'inlet_rate', None),
        ('OUTLET-RATE', 'outlet_rate', None),
        ('FLUID-VISCOSITY', 'fluid_visc', 0.001),
        ('FLUID-DENSITY', 'fluid_dens', 1000)
    ]
    sim_params = {}
    for keyword, key, default in input_params:
        sim_params[key] = default
        # checking if keyword exists
        if keyword not in input_args:
            continue
        # setting value of keywork
        value = float(input_args[keyword].value)
        unit = input_args[keyword].unit
        sim_params[key] = value
        if not unit:
            continue
        # converting unit of value if needed
        try:
            sim_params[key] = value * get_conversion_factor(unit)
        except (KeyError, ValueError) as err:
            del sim_params[key]
            msg = 'Could not process input line: {} - Encountered {}: {}'
            msg = msg.format(apm_input_file[keyword].line,
                             err.__class__.__name__,
                             str(err))
            logger.warn(msg)
    #
    # getting inlet/outlet sides
    sides = {'left': 'right', 'right': 'left', 'top': 'bottom', 'bottom': 'top'}
    sim_params['inlet'] = sides[apm_input_file['OUTLET-SIDE'].value.lower()]
    sim_params['outlet'] = apm_input_file['OUTLET-SIDE'].value.lower()
    namespace.sim_params = sim_params
    #
    if map_data_field is None:
        return
    #
    # applying any geometric changes needed to the fracture data
    value = sim_params['roughness']
    map_data_field.data_map = map_data_field.data_map - value
    map_data_field.data_vector = map_data_field.data_vector - value
    #
    value = sim_params['high_mask']
    map_data_field.data_map[map_data_field.data_map > value] = value
    map_data_field.data_vector[map_data_field.data_vector > value] = value
    #
    value = sim_params['low_mask']
    map_data_field.data_map[map_data_field.data_map < value] = value
    map_data_field.data_vector[map_data_field.data_vector < value] = value
    #
    # setting mesh parameters
    mesh_params = {
        'convertToMeters': sim_params['voxel_size'],
        'numbersOfCells': '(5 5 5)',
        'boundary.'+sim_params['inlet']+'.type': 'patch',
        'boundary.'+sim_params['outlet']+'.type': 'patch'
    }
    #
    # creating blockMeshDict file
    block_mesh = BlockMeshDict(map_data_field,
                               sim_params['avg_fact'],
                               mesh_params)
    export.block_mesh_dict = block_mesh