MassimoCimmino / pygfunction

An open-source toolbox for the evaluation of thermal response factors (g-functions) of geothermal borehole fields.
BSD 3-Clause "New" or "Revised" License
46 stars 21 forks source link

Increase re-initialization speed of pipe objects #185

Closed j-c-cook closed 2 years ago

j-c-cook commented 2 years ago

Massimo has done most of the work in #183 and #184. This is to try to help with finishing touches to get the changes implemented into the master branch.

j-c-cook commented 2 years ago

@MassimoCimmino

We could work around defining the thermal_resistances_dict by accessing the object itself. It would require for thermal_resistances to be passed self (technically this should be cls). However, there appears to be a decrease in performance. I have not investigated if this is due to the heavier weight of passing self, or that the hasattr and getattr functions are slower than accessing a dictionary. See https://github.com/MassimoCimmino/pygfunction/pull/185/commits/5009eb4ea84d16bcdbaaf21667e07343c7fb4816

HighLevel/find_near_square.py results
=====================================
* Single U-tube
---------------
Calculation time: 18.11 seconds
Height: 130.1818 meters
Number of boreholes: 156
Total Drilling: 20308.4 meters

* Double U-tube
---------------
Calculation time: 28.29 seconds
Height: 133.2133 meters
Number of boreholes: 144
Total Drilling: 19182.7 meters

* Coaxial tube
--------------
Calculation time: 18.25 seconds
Height: 132.7505 meters
Number of boreholes: 144
Total Drilling: 19116.1 meters
MassimoCimmino commented 2 years ago

I am open to any ideas that would make this implementation cleaner.

Your timings suggests there is an issue with saving or accessing the previous outputs. Timings are similar to your results from here, before memoization.

j-c-cook commented 2 years ago

I'd rather have the speed of your implementation. I am going to close this PR.