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

calling 'calculate_derivatives_thermal' once #563

Merged
merged 9 commits into from
Nov 13, 2023

Conversation

SimonRubenDrauz
Copy link
Collaborator

@SimonRubenDrauz SimonRubenDrauz commented Sep 8, 2023

  • Just calling 'calculate_derivatives_thermal' once instead of calling it for each component seperately
  • renaming TINIT and T_OUT in TINIT and TOUTINIT in branch

- rename TINIT in TINIT_IN and T_OUT in TINIT_OUT in Branch
@codecov
Copy link

codecov bot commented Sep 8, 2023

Codecov Report

Attention: 17 lines in your changes are missing coverage. Please review.

Comparison is base (6a87439) 85.23% compared to head (2aae8dc) 85.06%.
Report is 11 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #563      +/-   ##
===========================================
- Coverage    85.23%   85.06%   -0.17%     
===========================================
  Files           90       90              
  Lines         6202     6181      -21     
===========================================
- Hits          5286     5258      -28     
- Misses         916      923       +7     
Files Coverage Δ
...component_models/abstract_models/base_component.py 92.30% <100.00%> (+1.92%) ⬆️
.../component_models/abstract_models/branch_models.py 83.67% <100.00%> (-4.94%) ⬇️
...odels/abstract_models/branch_w_internals_models.py 91.15% <100.00%> (+0.07%) ⬆️
...dels/abstract_models/branch_wo_internals_models.py 85.45% <100.00%> (+0.26%) ⬆️
...mponent_models/abstract_models/circulation_pump.py 90.62% <ø> (+1.07%) ⬆️
...omponent_models/circulation_pump_mass_component.py 100.00% <ø> (ø)
...nent_models/circulation_pump_pressure_component.py 100.00% <ø> (ø)
...dapipes/component_models/flow_control_component.py 100.00% <100.00%> (ø)
...pipes/component_models/heat_exchanger_component.py 98.00% <100.00%> (-0.12%) ⬇️
pandapipes/component_models/pipe_component.py 84.81% <ø> (-0.47%) ⬇️
... and 11 more

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@dlohmeier dlohmeier left a comment

Choose a reason for hiding this comment

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

In general, I like this whole approach and it's about time to put together all branches when calculating the thermal derivatives. One thing that strikes me is the variable TINIT / TINIT_IN that we define in branch_idx and that you rename here. This is not a solver variable, so I would suggest to throw out this variable fully. It leads to confusion, because "the branch temperature" is not defined. It would make more sense to me to always define which temperatures precisely I need in what constellation. If I want the intermediate of the two neighboring junctions, I have to get from_nodes and to_nodes beforehand.

@SimonRubenDrauz
Copy link
Collaborator Author

@dlohmeier: What I do not understand: What do you mean by throwing out the variable? Shall we rename it? I wouldn't throw it out completely because we use it in different functions.

@dlohmeier
Copy link
Collaborator

Yes, it is used, but it can be replaced by a call like

from_nodes = branch_pit[:, FROM_NODE].astype(np.int32)
to_nodes = branch_pit[:, TO_NODE].astype(np.int32)
t_init = (node_pit[from_nodes, T_INIT] + node_pit[to_nodes, T_INIT]) / 2

The advantage is that there is more control over what value really is needed in the specific case. If we assume that a fluid property of a branch element depends on the branch temperature, it makes sense to rethink how the temperature of this branch should be calculated. In case of thermal calculation, we would definitely need to change the above statement to:

from_nodes = branch_pit[:, FROM_NODE].astype(np.int32)
t_init = (node_pit[from_nodes, T_INIT] + branch_pit[:, T_OUT]) / 2

but in case of hydraulic simulation, T_OUT might not be properly initialized. We have to check this again, but I think that it is more useful to assume that the temperature is a very local (point) variable that cannot be a branch variable and each time you need "the temperature" of a branch, you have to define it yourself.

dlohmeier
dlohmeier previously approved these changes Sep 14, 2023
Copy link
Collaborator

@dlohmeier dlohmeier left a comment

Choose a reason for hiding this comment

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

This now looks good to me.

@SimonRubenDrauz
Copy link
Collaborator Author

@dlohmeier: I just checked how T_OUT is initialized in a pipe. Actually it is exactly what you described above:

grafik

Thus, both equations above should get the same result in the hyadraulics calculation. So we could use this definition:

t_init = (node_pit[from_nodes, T_INIT] + branch_pit[:, T_OUT]) / 2

to always calculate the correct temperature:

@SimonRubenDrauz
Copy link
Collaborator Author

SimonRubenDrauz commented Sep 15, 2023

I reconsidered your point and decided to throw out TINIT completely. I agree that it is really misleading and causes confusion. And the result is that I found something what really confuses me.
In some files we use the branch temperature combined with p_from/p_to. You can find this in the pump_component, result_extraction for example where we determine v_mean/v_from/v_to. I also apated it. I guess, it was a mistake. What do you think?

@@ -95,7 +95,7 @@ def test_heat_only(use_numba):
nonlinear_method="automatic", mode="hydraulics", use_numba=use_numba)

p = ntw._pit["node"][:, 5]
v = ntw._pit["branch"][:, 12]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Wouldn't it make more sense to import this? Less error prone...

@dlohmeier
Copy link
Collaborator

I like the adjustments here. Guess we have to look at the pump again, but it seems that you were able to fix a few error prone implementations here.

@SimonRubenDrauz
Copy link
Collaborator Author

@dlohmeier, can we merge this PR. All changes have been realized which you recommended.

Copy link
Collaborator

@dlohmeier dlohmeier left a comment

Choose a reason for hiding this comment

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

Looks really good to me. This should improve performance and be a great preparation of using numba for thermal simulation as well, and we got rid of yet another branch variable. :-D

@SimonRubenDrauz SimonRubenDrauz merged commit b7963eb into e2nIEE:develop Nov 13, 2023
13 of 14 checks passed
@SimonRubenDrauz SimonRubenDrauz deleted the global_thermal branch November 13, 2023 07:44
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

Successfully merging this pull request may close these issues.

3 participants