First time here? Check out the Help page!
1 | initial version |
If you're trying to just change the conductivity before running the simulation, you're indeed better off doing it by manipulating the IDF file then.
Reading and writing the IDF will have almost no overhead, and if the overhead is a concern to you and you think openstudio
(or eppy
, or whatever you want to use) is too slow, just have an IDF template file with a specific placeholder, eg %CONDUCTIVITY%
, load it in python, do a string replace, then write again. That will takes about 400 µs for a 6000-lines-long IDF file per the testing I just did.
In [1]: %%timeit
...: with open('tmp.idf', 'r') as f:
...: content = f.read()
...: with open('in.idf', 'w') as f:
...: f.write(content.replace('%CONDUCTIVITY%', '0.029'))
403 µs ± 7.94 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)
But you could also preload the IDF into openstudio or eppy or whatever, then keep changing the IDF and just pay the price of the change + save (instead of having to load too). But anyways, my point is that your bottleneck will be by far the E+ simulation time anyways, so you shouldn't be too concerned about the conductivity part.
2 | No.2 Revision |
If you're trying to just change the conductivity before running the simulation, you're indeed better off doing it by manipulating the IDF file then.
Reading and writing the IDF will have almost no overhead, and if the overhead is a concern to you and you think openstudio
(or eppy
, or whatever you want to use) is too slow, just have an IDF template file with a specific placeholder, eg %CONDUCTIVITY%
, load it in python, do a string replace, then write again. That will takes about 400 µs for a 6000-lines-long IDF file per the testing I just did.
In [1]: %%timeit
...: with open('tmp.idf', 'r') as f:
...: content = f.read()
...: with open('in.idf', 'w') as f:
...: f.write(content.replace('%CONDUCTIVITY%', '0.029'))
403 µs ± 7.94 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)
But you could also preload the IDF into openstudio or eppy or whatever, then keep changing the IDF and just pay the price of the change + save (instead of having to load too). But anyways, my point is that your bottleneck will be by far the E+ simulation time anyways, so you shouldn't be too concerned about the conductivity part.
Anyways, here is the same exact thing, using the openstudio
Python bindings (PyPi openstudio, just do pip install openstudio
on Python 3.7 to 3.9) (since your stack is Python, makes sense to stay in Python) to manipulate the IDF file (not using an OSM model if you don't have one to begin with). It's slower as expected, but you get a much smarter API, that allows you to get objects by type / name, will validate your entries based on the IDD constraints (if I try to set a negative conductivity it will not allow me to do so)
In [1]: import openstudio
In [2]: %%timeit
...: w = openstudio.Workspace.load('tmp.idf').get()
...: mat = w.getObjectByTypeAndName('Material', 'Wall Insulation [42]').get()
...: # Conductivity is the 4th field, so 3 (0-indexed)
...: assert mat.setDouble(3, 0.029)
...: w.save('in.idf', True)
78.7 ms ± 583 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)