Example #1
0
def upload_delphin_to_database(delphin_file: str,  queue_priority: int) -> delphin_db.Delphin.id:
    """
    Uploads a Delphin file to a database.rst.

    :param delphin_file: Path to a Delphin 6 project file
    :param queue_priority: Queue priority for the simulation
    :return: Database entry id
    """

    entry = delphin_db.Delphin()
    entry.queue_priority = queue_priority

    delphin_dict = delphin_parser.dp6_to_dict(delphin_file)
    entry.dp6_file = delphin_dict
    entry.materials = material_interact.find_material_ids(material_interact.list_project_materials(entry))

    if len(delphin_dict['DelphinProject']['Discretization']) > 2:
        entry.dimensions = 3
    elif len(delphin_dict['DelphinProject']['Discretization']) > 1:
        entry.dimensions = 2
    else:
        entry.dimensions = 1

    entry.save()

    return entry.id
def create_2d_designs(folder):
    bricks = pd.read_excel(os.path.join(folder, 'Brick.xlsx'))
    plasters = pd.read_excel(os.path.join(folder, 'Plaster.xlsx'))
    ref_folder = os.path.join(folder, 'delphin')

    for file in os.listdir(ref_folder):
        delphin_dict = delphin_parser.dp6_to_dict(
            os.path.join(ref_folder, file))

        for p_index, p_id in enumerate(plasters['Material ID']):
            new_material = material_interactions.get_material_info(p_id)
            plaster_delphin = delphin_permutations.change_layer_material(
                delphin_dict, 'Lime cement mortar [717]', new_material)

            for index, mat_id in enumerate(bricks['Material ID']):
                new_material = material_interactions.get_material_info(mat_id)
                new_delphin = delphin_permutations.change_layer_material(
                    plaster_delphin, 'Old Building Brick Dresden ZP [504]',
                    new_material)
                file_name = f'{file.split(".")[0]}_{plasters.iloc[p_index, 1]}_{bricks.iloc[index, 1]}.d6p'
                xmltodict.unparse(new_delphin,
                                  output=open(
                                      os.path.join(folder, 'design',
                                                   file_name), 'w'),
                                  pretty=True)
def create_1d_designs(folder):
    bricks = pd.read_excel(os.path.join(folder, 'Brick.xlsx'))
    plasters = pd.read_excel(os.path.join(folder, 'Plaster.xlsx'))

    ref_folder = os.path.join(folder, 'delphin')
    temp_folder = os.path.join(folder, 'temp')

    thickness = [0.228, 0.348, 0.468]

    for file in os.listdir(ref_folder):
        for thick in thickness:
            delphin_dict = delphin_parser.dp6_to_dict(
                os.path.join(ref_folder, file))
            thick_delphin = delphin_permutations.change_layer_width(
                delphin_dict, 'Old Building Brick Dresden ZP [504]', thick)
            thick_delphin = delphin_permutations.update_output_locations(
                thick_delphin)

            for p_index, p_id in enumerate(plasters['Material ID']):
                new_material = material_interactions.get_material_info(p_id)
                new_delphin = delphin_permutations.change_layer_material(
                    thick_delphin, 'Lime cement mortar [717]', new_material)
                file_name = '_'.join(
                    file.split('_')[:2]
                ) + f'_{int((thick+0.012)*100)}cm_1D_{plasters.iloc[p_index, 1]}.d6p'
                xmltodict.unparse(new_delphin,
                                  output=open(
                                      os.path.join(temp_folder, file_name),
                                      'w'),
                                  pretty=True)

    for file in os.listdir(temp_folder):
        delphin_dict = delphin_parser.dp6_to_dict(
            os.path.join(temp_folder, file))

        for index, mat_id in enumerate(bricks['Material ID']):
            new_material = material_interactions.get_material_info(mat_id)
            new_delphin = delphin_permutations.change_layer_material(
                delphin_dict, 'Old Building Brick Dresden ZP [504]',
                new_material)
            file_name = f'{file.split(".")[0]}_{bricks.iloc[index, 1]}.d6p'
            xmltodict.unparse(new_delphin,
                              output=open(
                                  os.path.join(folder, 'design', file_name),
                                  'w'),
                              pretty=True)
Example #4
0
def test_change_orientation():
    source_path = os.path.dirname(os.path.realpath(__file__)) + '/test_files'
    test_path, _ = helper.setup_test_folders()
    delphin_dict = delphin_parser.dp6_to_dict(source_path +
                                              '/delphin_project.d6p')
    new_delphin = delphin_permutations.change_orientation(delphin_dict, 300)

    xmltodict.unparse(new_delphin,
                      output=open(test_path + '/modified_delphin_project.d6p',
                                  'w'),
                      pretty=True)
    helper.clean_up_test_folders()
    assert new_delphin['DelphinProject']['Conditions']['Interfaces'][
        'Interface'][0]['IBK:Parameter']['#text'] == str(300)
Example #5
0
def test_change_coefficient_1():
    source_path = os.path.dirname(os.path.realpath(__file__)) + '/test_files'
    test_path, _ = helper.setup_test_folders()
    delphin_dict = delphin_parser.dp6_to_dict(source_path +
                                              '/delphin_project.d6p')
    new_delphin = delphin_permutations.change_boundary_coefficient(
        delphin_dict, 'Indoor heat conduction', 'ExchangeCoefficient', 12)

    xmltodict.unparse(new_delphin,
                      output=open(test_path + '/modified_delphin_project.d6p',
                                  'w'),
                      pretty=True)
    helper.clean_up_test_folders()
    assert new_delphin['DelphinProject']['Conditions']['BoundaryConditions'][
        'BoundaryCondition'][0]['IBK:Parameter']['#text'] == str(12)
Example #6
0
def test_change_weather():
    source_path = os.path.dirname(os.path.realpath(__file__)) + '/test_files'
    test_path, _ = helper.setup_test_folders()
    delphin_dict = delphin_parser.dp6_to_dict(source_path +
                                              '/delphin_project.d6p')
    weather_path = os.path.dirname(
        os.path.realpath(__file__)) + '/test_files/temperature.ccd'
    new_delphin = delphin_permutations.change_weather(delphin_dict, 'Temp Out',
                                                      weather_path)
    xmltodict.unparse(new_delphin,
                      output=open(test_path + '/modified_delphin_project.d6p',
                                  'w'),
                      pretty=True)
    helper.clean_up_test_folders()

    assert new_delphin['DelphinProject']['Conditions']['ClimateConditions'][
        'ClimateCondition'][2]['Filename'] == weather_path
Example #7
0
def test_change_layer_width():
    source_path = os.path.dirname(os.path.realpath(__file__)) + '/test_files'
    test_path, _ = helper.setup_test_folders()
    delphin_dict = delphin_parser.dp6_to_dict(source_path +
                                              '/delphin_project.d6p')
    old_width = sum(
        delphin_permutations.convert_discretization_to_list(delphin_dict))

    new_delphin = delphin_permutations.change_layer_width(
        delphin_dict, 'Normal Brick [512]', 1.0)
    xmltodict.unparse(new_delphin,
                      output=open(test_path + '/modified_delphin_project.d6p',
                                  'w'),
                      pretty=True)
    helper.clean_up_test_folders()

    assert sum(delphin_permutations.convert_discretization_to_list(
        new_delphin)) - old_width - 0.65 <= 0.002
Example #8
0
def test_change_material_1():
    source_path = os.path.dirname(os.path.realpath(__file__)) + '/test_files'
    test_path, _ = helper.setup_test_folders()
    delphin_dict = delphin_parser.dp6_to_dict(source_path +
                                              '/delphin_project.d6p')
    new_material = OrderedDict(
        (('@name', 'Aerated Concrete [6]'), ('@color', '#ff404060'),
         ('@hatchCode', '13'), ('#text',
                                '${Material Database}/AeratedConcrete_6.m6')))
    new_delphin = delphin_permutations.change_layer_material(
        delphin_dict, 'Normal Brick [512]', new_material)
    xmltodict.unparse(new_delphin,
                      output=open(test_path + '/modified_delphin_project.d6p',
                                  'w'),
                      pretty=True)
    helper.clean_up_test_folders()

    assert new_delphin['DelphinProject']['Materials']['MaterialReference'][
        1] == new_material
Example #9
0
def test_get_layers_1():
    source_path = os.path.dirname(os.path.realpath(__file__)) + '/test_files'
    delphin_dict = delphin_parser.dp6_to_dict(source_path +
                                              '/delphin_project.d6p')
    delphin_layers = delphin_permutations.get_layers(delphin_dict)

    correct_layer_dict = {
        0: {
            'material': 'Lime Cement Plaster light [630]',
            'x_width': 0.009999999999999998,
            'x_index': (0, 6)
        },
        1: {
            'material': 'Normal Brick [512]',
            'x_width': 0.3499998,
            'x_index': (7, 37)
        },
        2: {
            'material': 'iQ-Fix [437]',
            'x_width': 0.005,
            'x_index': (45, 49)
        },
        3: {
            'material': 'iQ-Therm [438]',
            'x_width': 0.08,
            'x_index': (50, 68)
        },
        4: {
            'material': 'iQ-Top [726]',
            'x_width': 0.009999999999999998,
            'x_index': (69, 75)
        },
        5: {
            'material': 'Restoration Render [210]',
            'x_width': 0.010000000000000002,
            'x_index': (38, 44)
        }
    }
    assert delphin_layers == correct_layer_dict