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

Update of the centralised optimisation algorithm #3260

Merged
merged 64 commits into from
Jun 28, 2023

Conversation

MatNif
Copy link
Collaborator

@MatNif MatNif commented Oct 27, 2022

** this is ongoing work, the PR is launched to make the review easier, I will update this message when the branch is ready for a final review before the merge **

The new optimisation problem this update is based on is described in issue #3254.
The code structure is described in the class diagram here, which will be updated regularly to reflect the latest changes of the code.

Introduction of all relevant classes and the functions necessary to build the domain (the domain summarises the boundary conditions for the optimisation of the energy system in the respective scenario's zone)
MatNif and others added 6 commits October 31, 2022 14:45
This commit introduces a new data base of energy carriers. It is a bit simpler than the 'feedstock'-database used by the old optimisation algorithm.
Energy potentials are also linked to these energy carriers in this commit.
The schemas now contain then new 'ENERGY_CARRIERS' database.
Removing artefacts of the vapour compression chiller model removed in PR #3187 (issue #3137)
(#3187)
Fixing a few typos in the database and adding it to the reference-case to fix workflows.
This portion of the script creates new networks based on the connected buildings given by the 'individual' and calculates their operating conditions (this is largely based on the existing network scripts)
@MatNif
Copy link
Collaborator Author

MatNif commented Nov 14, 2022

@shanshanhsieh , @lguilhermers whenever you find the time to review yesterday's commit ('introducing networks') could you check if the following code lines make sense to you? These parts were all taken from the old thermal networks script.

line 124 optimization_new/network.py (line 351 technologies/thermal_network/simplified_thermal_network.py):
Why does the linear pressure loss conversion uses a factor of 1000?

line 189 optimization_new/network.py (line 466 technologies/thermal_network/simplified_thermal_network.py):
Why are the thermal losses of supply pipes counted twice instead of counting losses of return pipes?

line 470 optimization_new/network.py (line 320 technologies/thermal_network/simplified_thermal_network.py):
Why is the conversion factor FT_TO_M used twice and why is a factor of 1000 used for the conversion here again?

line 475-477 optimization_new/network.py (line 335 technologies/thermal_network/simplified_thermal_network.py):
Why is the thermal unit design head multiplied by a factor of 1.2? How should it be accounted for, depending on the number of substations\buildings in the network?

@@ -79,3 +79,8 @@

#natural gas conncetion
GAS_CONNECTION_COST = 15.5 / 1000 # CHF / W, from Energie360 15.5 CHF / kW

# Thermal Network
TYPE_MAT_DEFAULT = 'T1'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unclear to me what this variable means, is it material type? Perhaps add a comment to make more clear. Pipe diameter is self explanatory, but I would add the units is being considered, just for documentations

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. this is meant to declare the type of pipes (material and construction) that is used for the network. This is based on the existing thermal network code. I added a comment in the constants-file.
However, I just realised, that the pipe type is currently a bit meaningless. The only method this could play into is the calc_linear_thermal_loss_coefficient-function from simplified_thermal_network.py, but the function assumes a constant construction (steel pipe + calcium silicate insulation). So, there is currently no database in CEA specifying the properties of these types, but that could be added in the future.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it! Could it be relevant for the LCA parts, perhaps?

index_closest_mean_temp = (thermal_energy_carriers['mean_qual'] - temperature).abs().nsmallest(n=1).index[0]
energy_carrier_code = thermal_energy_carriers['code'].iloc[index_closest_mean_temp]
else:
energy_carrier_code = "T???"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

placeholder?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that is a placeholder for now. I'm currently linking that up. Should be part of the next bigger commit at the end of this week.

@lguilhermers
Copy link
Collaborator

lguilhermers commented Nov 15, 2022

In ENERGY_CARRIERS.xlsx, does it make sense to dfine a default for all thermal and radiation costs and ghg to 0.0? Or you expect to find some values for it? (In the case of leaving it blank bringing errors later on)

@lguilhermers
Copy link
Collaborator

lguilhermers commented Nov 15, 2022

Why is the conversion factor FT_TO_M used twice and why is a factor of 1000 used for the conversion here again?

both FT_TO_M seem reduntant to me, as it is a constant factor.
FT/kFT = FT/1000 *FT = M/ 1000 M (this number is adimentional so it doesn't matter)
I guess it was done literally for clarity, but can be removed without compromising the calculations.
The 1000 factor seems necessary because the original number is in kFT (similar to your first question)

@lguilhermers
Copy link
Collaborator

Why is the thermal unit design head multiplied by a factor of 1.2? How should it be accounted for, depending on the number of substations\buildings in the network?

This seems to me a safety factor, as you pointed. I think it should be declared before and individually, for clarity. Not sure how it would scale, but my guess is that it is for each substation.

@lguilhermers
Copy link
Collaborator

Why are the thermal losses of supply pipes counted twice instead of counting losses of return pipes?

I agree, even the comment says it is to account for return, which is calculated right before, so it seems logical to change that as well.

@MatNif
Copy link
Collaborator Author

MatNif commented Nov 15, 2022

In ENERGY_CARRIERS.xlsx, does it make sense to dfine a default for all thermal and radiation costs and ghg to 0.0? Or you expect to find some values for it? (In the case of leaving it blank bringing errors later on)

I think if the cells of a .csv-file are empty, they get read as 0.0 by default. But I'll check that either today or tomorrow.
My initial thinking was that it makes more sense to leave the cells empty because e.g. there is no real way to define what the price of UV-light is to an energy system?
But I guess putting zeros or dashes in those spots might make it more intuitive for a potential user that might want to change the data base themselves, so I changed the values now.

Small changes following the review of @lguilhermers .
Introduced two new classes describing energy carriers and energy flows. The latter is essentially a time series of quantities of a given energy carrier being transferred from a category of supply system components to another.
These changes introduce a new tab to the 'Optimization'-section of the front-end. Databases and the example reference case are also updated to match the new selection of components that can be installed in the supply system.
component choices were corrected and 'OrderedMultiChoiceParameter' was made a child of 'MultiChoiceParameter' instead of 'ChoiceParameter'
These changes build a district energy system for a given domain, including networks and supply system demands. The complete supply systems structure with its components and their corresponding capacities and operational modes are not yet implemented, however.
Added component model complexity parameter to the dashboard. In a first phase only 'constant' will work. This assumes a constant efficiency rating for all components.
Updated energy carrier and conversion (new) databases. This is linked to the introduction of the new component class and the new constant efficiency models for each of the supply system components.
MatNif and others added 13 commits May 15, 2023 15:11
Some of the config-inputs being called from different scripts caused the script to not be launched in the front end. This fix introduces the relevant parameters to the optimization-script's dashboard page to fix this.
Change folder structure for more clarity
Removing potentials from the expected input-files, to avoid inconsistent errors when only some potentials are considered in the optimization.
Implimented a first version of a tracker for the optimisation that is activated by setting debug=true
GHG emissions are no longer reduced if a supply system exports energy.
expand schemas to include files created by the optimization tracker
A bug was introduced into the thermal networks script when it was copied into the optimization script. This fix reverts this bug.
Previously to this fix, the mutation and recombination of capacity indicator vectors could effectively lead to a understocked supply systems (i.e. supply systems that could not meet the necessary demand, and would simply neglect part of the demand). This fix makes sure the supply system always offers the necessary capacity and meets demand.
Before this fix, passive components did not get properly activated when building the 'SupplySystemStructure'-object and therefore let to errors raising a mismatch between energy carriers of demand and what the installed components can supply.
This change finally allows for multiprocessing to work on the new optimization branch.
@MatNif MatNif marked this pull request as ready for review June 13, 2023 09:17
@MatNif MatNif requested a review from ShiZhongming June 13, 2023 09:34
@MatNif
Copy link
Collaborator Author

MatNif commented Jun 13, 2023

@reyery , @ShiZhongming

Would you be able to give the multiprocessing a go on Mac. If that works and you can't see any other immediate issues, I think we can merge. I'm sure, as people use it, more errors/unexpected behaviors will become apparent, but I think it would be easier to handle fixes to those through normal issues from here on out.

lowered minimum capacity of some components, to allow for an adequate supply system component to be installed in small stand-alone buildings.
@ShiZhongming ShiZhongming removed the request for review from shanshanhsieh June 14, 2023 09:04
@ShiZhongming
Copy link
Collaborator

Hi @MatNif
I use CEA on MacOS.
I have tested this PR both in Singapore and Zurich for DC and DH cases. Both worked fine using PyCharm and Dashboard (multi-processing=false).
When multi-processing=true, the reverted error is:
AttributeError: 'NoneType' object has no attribute 'consolidate'
Does the multi-processing work on Windows?

Prior to this fix, the pareto-optimal supply systems layouts of the different thermal networks were not combined properly, leading to skewed results and inconsistent improvements in the overall pareto-front. This fix rectifies that error.
This fix takes into account that supply systems might not have a component in each of the supply system categories and adapts the criteria for building the capacity indicator vectors accordingly.
If multiprocessing was set to false and 'generate-detailed-outputs' to true, the code would run into an error because the 'tracker' object was not initialized. This fixes that error.
@ShiZhongming
Copy link
Collaborator

@MatNif
Thanks for the fix.
I have tested it in Singapore and Zurich for DC and DH cases using PyCharm and Dashboard with multi-processing set to true. All worked! Thank you ; )

The tracker is generated only in debug mode (config.general.debug = true) and not when 'detailed outputs' are generated. This change corrects yesterday's fix accordingly.
@reyery
Copy link
Member

reyery commented Jun 28, 2023

@MatNif should the "new" database files replace the old ones?

@MatNif
Copy link
Collaborator Author

MatNif commented Jun 28, 2023

Hi @reyery,
The short answer is no.
We have not yet removed the old optimisation and that still gets all of its information from the old databases. Once we gain a bit more confidence in the new script, I'll procede to remove the old script along with the old databases.

Copy link
Member

@reyery reyery left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was able to successful run it on my Windows machine

@reyery reyery merged commit cb24a66 into master Jun 28, 2023
3 checks passed
@reyery reyery deleted the 3254-expanding-centralised-optimisation branch June 28, 2023 08:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Expanding functionalities of centralised optimisation
4 participants