oemof / DHNx

District heating system optimisation and simulation models
MIT License
27 stars 12 forks source link

ValueError: Pipe id <built-in function id> already has an investment > 0! #66

Closed phuismann closed 1 year ago

phuismann commented 3 years ago

I hope it's okay to more or less ask a support question here, but I'm kinda lost at this error.

I'm getting "ValueError: Pipe id already has an investment > 0!" when trying to optimise my district heating network. It is probably an issue regarding the structure of my investment/pipes.csv table:

image

(Disregard the capex)

Its running with nonconvex 0 and cap_min == 0, but I'd like to have cap_min > 0.

joroeder commented 3 years ago

I think in this early stages of the package, it is fine. By this direct user feedback, in many cases, we come to an issue or we might want to improve something else, like an additional warning or check.

So, the optimization itself is running, right? The error is caused by the processing of results ..

The thing is that the way you define the pipes, first, a small pipe is installed, because it is cheapest. Then, if the demand is > 27, the next cheapest pipe is installed, so DN32, and so on ... This way, for a single edge, multiple pipes are installed. That's why I put an error there, in my opinion it does not make sense to have multiple types for a single edge. And be aware, that the capex_pipes are defined per kW_installed. And isn't it the case that small DN numbers are more expensive per kW?!

For now, you can still check and evaluate the "raw" oemof results then ..

For the near future, a warning would be a good solution as well, and the processing of the results could be adapted for the case of multiple investments for each pipe. you can start a PR for that, if you want ...

phuismann commented 3 years ago

Thank you!

Oh, I think there is a misunderstanding in what the pipes.csv should look like. Multiple pipe types should be different pipe manufactures rather than different sizes of pipes right? I thought an installed pipe-type replaces a previously assigned pipe-type! And yes the capes are not the right ones!

I think a small tutorial for an optimisation problem with multiple pipe types would be benefitial!

joroeder commented 3 years ago

Oh, I think there is a misunderstanding in what the pipes.csv should look like. Multiple pipe types should be different pipe manufactures rather than different sizes of pipes right?

Both is possible. You can use the pipes types table for discrete DN numbers, or piecewise linearized, and so on. You can also think of different manufacturer data ... this is up to the user. Be aware that each row creates an oemof-solph heatpipeline investment object for each edges of the network. That means that the mathematical problem will increase as well.

I think a small tutorial for an optimisation problem with multiple pipe types would be benefitial!

Yes, I also think this would help. Do you want to do that? :wink:

phuismann commented 3 years ago

"This way, for a single edge, multiple pipes are installed." > But shouldn't only one pipe type be installed ultimately even when I have multiple pipe types to choose from?

I'll see if I can add an example when I have mine running correctly!

joroeder commented 3 years ago

"This way, for a single edge, multiple pipes are installed." > But shouldn't only one pipe type be installed ultimately even when I have multiple pipe types to choose from?

At the moment, it is possible that there are multiple pipes "installed" per edges. There is no additional constraint, which forces only one investment for each edges. Maybe you think of a constraint like this:

invest_status_typ_A + invest_status_type_B + invest_status_type_C <= 1

This is not implemented. I think in 99 % of cases it is not economically better to install two small instead of one bigger pipe. This is why I think that such a constraint is not necessary.

Maybe, we need to be more precise on what we mean by "installed": that the investment capacity of one of the oemof-solph heatpipeline options is > 0 after the optimisation. The oemof-solph heatpipeline components themselves exists for all types given.

I'll see if I can add an example when I have mine running correctly!

Yeah sure, take your time, it would be very interesting!

joroeder commented 3 years ago

@FruitVul so, the acutal issue is solved for you? Then, I would close this issue.

For your interest, there will be a DHNx seesion at the next oemof meeting, please see: https://github.com/oemof/oemof/wiki/Meeting-December-2020-%28online%29 you are welcome to join!

phuismann commented 3 years ago

@joroeder haven't solved it, but I think it's just a misunderstanding of how to use the invest/network/pipes.csv table.

Maybe for you to clarify what I want to do:

I want to have the network typology and diameters optimized for my dhn network on the basis of pipe parameters. I thought that I have to add all the available pipes to choose from to the pipes.csv, but from what you have said It seems to be the wrong way to go about this.

joroeder commented 3 years ago

@FruitVul Are you still working on that?

In the pipes tables, you insert the coefficients for linearized function of the pipeline costs and pipeline thermal loss. You could have a look at https://journals.aau.dk/index.php/sepm/article/view/6248/5826, Figure 6, that shows an example for the linearization of the costs and losses. You could also add multiple rows to use a piecewise linearization. Or use a heatpipeline component for every DN number, as in your example above. This is up to the user. If you could provide a small example, that would also help.

I agree that the input format might be confusing at the moment. I plan to add further pre-processing for the optimization, that might help. If you want you could support the development, I would be happy about feedback ...

phuismann commented 3 years ago

@joroeder yes I will eventually work on it again! Will update you when I find the time. Thanks!

LuixLore commented 2 years ago

Hello @joroeder and @FruitVul,

im facing the same error when running introduction.py. For understanding if "Optimize_Investment()" would also choose the cheapest pipe when creating a thermal network i added a second Pipe with lower capex and (much) lower cap_max resulting in the same warning as @FruitVul had.

Thank you for the suggestion of the paper - DHNx, as well as the cost-linearisation is much clearer to me now.

Still I don't understand how to solve the problem that, that Optimize_Investment() not only chooses the route of the network , but also decides between different pipe types the DN that is cheapest but still allowing sufficient heat supply. I would expect an output maybe like in the example provided (introduction.py), where not only pipe-type-A is chosen as a hp-type but also other options are possible corresponding to the chosen DN for each pipe. image

I was thinking what you could mean by your suggestion of "use a heatpipeline component for every DN number, as in your example above", but it was hard for me to find an answer/solution..could you maybe elaborate a bit more what you mean by that? Or maybe you found a different approach ?

Im currently writing my masterthesis about rural district heating networks and would like to use DHNx for the optimization of the network design. I just started to find my way through DHNx and its possibilities - still i would be very happy to contribute to further development.

Thank you and kind regards

Luise

joroeder commented 2 years ago

Could you provide the input data and script?

So long, you could proceed with one-segement linearization as provided in the example or paper (so just use one line in the pipes data table: here ). I think the solving time is much shorter than providing specific DN numbers, or multiple segments. Especially in large networks, a more detailed segmentation would lead to long calculation times. And I also think that the results do not largly change. from the resulting capacities (which have the unit thermal power), you need to back-calculate to a DN number with your assumptions about temperature spread and specific pressure drop, you use as design criterion.

We are at the moment adding some pre-calculation, this might also be interesting .. see #83 #82

joroeder commented 2 years ago

Im currently writing my masterthesis about rural district heating networks and would like to use DHNx for the optimization of the network design. I just started to find my way through DHNx and its possibilities - still i would be very happy to contribute to further development.

Thank you for your comment! Yes, that would be great. Contributions are welcome. And also by using and testing the tool, errors might be detected and the process will be improved.

LuixLore commented 2 years ago

Thank you for answering so fast: I think i get your point and it makes sense to me. I refered to the provided investment_optimization/introduction example provided here. I used its input data about "twn" and "investment".

I invested some time into understanding the results of the mentioned example (in its original version, no changes added). Attached I'm providing you the .xlsx doc - maybe its helping someone whos facing similar questions. Results_investment_optimization_introduction_Evaluation_Lorenz.xlsx

Thanks for the hint to use the capacity as a base for choosing the pipe-types (DN) that sufficient for the transportation of the heat - I wasnt considering that. I will keep on working on an approach to use deltaT, approved velocity range corresponding to inner diameter,... to get back the cheapest/smallest, but technically feasible pipes to meet the heatdemand of the consumers.

I will keep you updated when i have results!

joroeder commented 2 years ago

I tested a segment-wise and a discrete pipes table with the example introduction and it worked. Also an example with 2-segments worked. Please find attached the two pipes.csv parameter tables.

I further added an excel sheet with the pipeline data, which is the basis. Maybe, this makes things more clear. Everybody must think himself about the thermal capacities for each DN number, which is the reference basis for the costs and losses, this is not part of DHNx yet, but will be added as mentioned above.

pipes_discrete.csv

pipes_2_segments.csv

example_pipeline_data.xlsx

gitfeldhase commented 1 year ago

Hello everyone,

since this Issue was already used to discuss the optimization of the network, I am wondering if somebody could help me out. I am a masterstudent as well working with dhnx and had the same issues mentioned by @LuixLore. I do not understand 100% how the optimisation works. For the pipes.csv I used the default invest_data, see the appended pipes.csv.

I run a small example with every building having the same P_heat_max. On the attached picture I visualized the potential pipes before the optimisation and after. In red I coulored how I thought the grid would look like since I thought the optimisation tries to minimize the investment costs, but instead a very long second branch is used for the routing. It seems that for the routing problem the oemof model uses only the shortest path for every consumer to the heat source instead of the cheapest investment. Screenshot from 2022-11-28 16-56-51

I get this warning in my log: There is NO investment in both directions at thefollowing pipes for " pipe-typ-A "

Can you help me out what the log means and what am I missing about the routing problem?

Thank you very much, this Thread already helped a lot for a deeper understanding of the investment options.

Best regards

Lars pipes.csv

gitfeldhase commented 1 year ago

Maybe also a great example would be if you @joroeder could quickly show how the pipes.csv must have looked like for the linearization in your publication (http://doi.org/10.5278/ijsepm.6248), I think this will answer a lot of questions for future readers.

I assume it must have looked something like this?: cap_min: 0 cap_max: 10000 capex_pipes: 0.105 fix_costs: 137.5 L_factor: 0.007 L_factor_fix: 9.953 nonconvex: 0 active: 1

Please correct me if I have a misunderstanding.

joroeder commented 1 year ago

It seems that for the routing problem the oemof model uses only the shortest path for every consumer to the heat source instead of the cheapest investment. Screenshot from 2022-11-28 16-56-51

It is based on a cost-minization, so in your case, the reason probably is that you do not consider fixed cost, as nonconvex is false? So the connection of the building as in your results is the cheapest way. Try to set nonconvex to 1 and add fix_costs.

I get this warning in my log: There is NO investment in both directions at thefollowing pipes for " pipe-typ-A "

Can you help me out what the log means and what am I missing about the routing problem?

That is a good question, could you send the example?

joroeder commented 1 year ago

Maybe also a great example would be if you @joroeder could quickly show how the pipes.csv must have looked like for the linearization in your publication (http://doi.org/10.5278/ijsepm.6248), I think this will answer a lot of questions for future readers.

I assume it must have looked something like this?: cap_min: 0 cap_max: 10000 capex_pipes: 0.105 fix_costs: 137.5 L_factor: 0.007 L_factor_fix: 9.953 nonconvex: 0 active: 1

Please correct me if I have a misunderstanding.

Please see here #100

gitfeldhase commented 1 year ago

It seems that for the routing problem the oemof model uses only the shortest path for every consumer to the heat source instead of the cheapest investment. Screenshot from 2022-11-28 16-56-51

It is based on a cost-minization, so in your case, the reason probably is that you do not consider fixed cost, as nonconvex is false? So the connection of the building as in your results is the cheapest way. Try to set nonconvex to 1 and add fix_costs.

I get this warning in my log: There is NO investment in both directions at thefollowing pipes for " pipe-typ-A " Can you help me out what the log means and what am I missing about the routing problem?

That is a good question, could you send the example?

Thanks a lot for the answer!

Here is the data of the example: preprocessed_example.zip

invest_data.zip

Apparently I get the same result with nonconvex = 1 and additional fix costs, no matter how high I choose the additional fix costs.

Best regards and thanks for the support!

Lars

joroeder commented 1 year ago

I will close this issue, as the different issues seem to be solved, or addressed in separate issues: