Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend idd after download #37

Open
shyamamrith opened this issue Nov 22, 2023 · 1 comment
Open

Extend idd after download #37

shyamamrith opened this issue Nov 22, 2023 · 1 comment
Assignees

Comments

@shyamamrith
Copy link
Collaborator

Since EnergyPlus is now downloaded from the official repo, the idd file needs extending each time to support a higher number of vertices (this had previously been included in the packaged version of EP). Can possibly just include an extended idd file to replace the downloaded one.

@shyamamrith shyamamrith self-assigned this Nov 22, 2023
@IvKor
Copy link
Collaborator

IvKor commented Jun 7, 2024

'''
idd.py
_______________________________________________________________________________
Script which generates additional fields in the Energy+.idd file.
Additional fields are created for following objects:
- BuildingSurface:Detailed
- Shading:Site:Detailed
- Shading:Building:Detailed
- Shading:Zone:Detailed

The reason for additional field for these two objects is inability to create
roof/floor/shading elements with more than 120 (default) available vertices.

The original Energy+.idd file is kept with the appended extension (.iddORG)

@author: Ivan Korolija
'''
from pathlib import Path


new_vertices_no = 500  # Number of new vertices
# Absolute path to the folder where the Energy+.idd file is located.
idd_path = '/mnt/data/EnergyPlus/ep24.1'


def building_element(i, N, unt, typ):
    x, y, z = i*3, i*3+1, i*3+2
    if i == N - 1:
        ext_element = [
            '  N{}, \\field Vertex {} X-coordinate'.format(363 + x, 121 + i),
            unt, typ,
            '  N{}, \\field Vertex {} Y-coordinate'.format(363 + y, 121 + i),
            unt, typ,
            '  N{}; \\field Vertex {} Z-coordinate'.format(363 + z, 121 + i),
            unt, typ]
    else:
        ext_element = [
            '  N{}, \\field Vertex {} X-coordinate'.format(363 + x, 121 + i),
            unt, typ,
            '  N{}, \\field Vertex {} Y-coordinate'.format(363 + y, 121 + i),
            unt, typ,
            '  N{}, \\field Vertex {} Z-coordinate'.format(363 + z, 121 + i),
            unt, typ]
    return ext_element


def shading_element(i, N, unt, typ):
    x, y, z = i*3, i*3+1, i*3+2
    if i == N - 1:
        ext_element = [
            '  N{}, \\field Vertex {} X-coordinate'.format(362 + x, 121 + i),
            unt, typ,
            '  N{}, \\field Vertex {} Y-coordinate'.format(362 + y, 121 + i),
            unt, typ,
            '  N{}; \\field Vertex {} Z-coordinate'.format(362 + z, 121 + i),
            unt, typ]
    else:
        ext_element = [
            '  N{}, \\field Vertex {} X-coordinate'.format(362 + x, 121 + i),
            unt, typ,
            '  N{}, \\field Vertex {} Y-coordinate'.format(362 + y, 121 + i),
            unt, typ,
            '  N{}, \\field Vertex {} Z-coordinate'.format(362 + z, 121 + i),
            unt, typ]
    return ext_element


if __name__ == '__main__':

    # Check whether Energy+.idd file is present in the provided folder
    idd_fn = Path(idd_path) / 'Energy+.idd'
    if not idd_fn.is_file():
        raise SystemExit('No Energy+.idd file in the folder.')
    else:
        # units and type strings which follow idd vertices
        unt = '       \\units m'
        typ = '       \\type real'
        # lists to store new vertices. N362 and N361 are last Z coordinates of
        # building and shading objects where ';' is replaces with ','
        build_det = ['  N362, \\field Vertex 120 Z-coordinate', unt, typ]
        sh_det = ['  N361, \\field Vertex 120 Z-coordinate', unt, typ]
        # append lists with new vertices
        for n in range(new_vertices_no):
            build_det.extend(building_element(n, new_vertices_no, unt, typ))
            sh_det.extend(shading_element(n, new_vertices_no, unt, typ))
        # load the idd file in the list
        with open(idd_fn, 'r') as myfile:
            idd = myfile.readlines()
        idd = [line.strip('\n') for line in idd]
        # remove two lines after lines starting with N361; and N362;
        rem_index = list()
        for i, item in enumerate(idd):
            if item.startswith(('  N361;', '  N362;')):
                rem_index.extend([i+1, i+2])
        for index in sorted(rem_index, reverse=True):
            del idd[index]
        # replace lines starting with N361; and N362 with a new vertices list
        idd_updated = list()
        for i in idd:
            if i == '  N362; \\field Vertex 120 Z-coordinate':
                item = build_det
            elif i == '  N361; \\field Vertex 120 Z-coordinate':
                item = sh_det
            else:
                item = [i]
            idd_updated.extend(item)
        # backup the original idd file
        idd_fn.rename(idd_fn.with_suffix('.iddORG'))
        # save the idd file with extended vertices
        with open(idd_fn, 'w') as fp:
            fp.write('\n'.join(idd_updated))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants