Skip to content

Make use of C_inv in bioCHP model#9

Merged
Zetison merged 9 commits intomainfrom
fix/bioCHP_C_inv_usage
Dec 18, 2025
Merged

Make use of C_inv in bioCHP model#9
Zetison merged 9 commits intomainfrom
fix/bioCHP_C_inv_usage

Conversation

@Zetison
Copy link
Collaborator

@Zetison Zetison commented Dec 16, 2025

This PR fixes missing usage of the C_inv parameter (investment cost) from the bioCHP model. The tests are adjusted accordingly.

Also, fixed test to avoid machine epsilon precision inaccuracies, e.g., 3.552y13678800501e-15 > 0 triggers the bioCHP sink test.

Also enable CSPandPV-node usage for power_thermal=0 or power_pv=0 from Tecnalia_Solar-Energy-Model.

@Zetison Zetison requested a review from Copilot December 16, 2025 13:18
@Zetison Zetison self-assigned this Dec 16, 2025
@Zetison Zetison added the bug Something isn't working label Dec 16, 2025
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR integrates investment cost functionality into the bioCHP model by utilizing the previously unused C_inv parameter. The changes enable investment modeling for bioCHP nodes by switching from operational to investment-based model types.

  • Updated bioCHP model to incorporate investment data structures using the C_inv parameter
  • Changed test model type from OperationalModel to InvestmentModel with discount rate
  • Adjusted test expectations to reflect the behavioral changes from investment modeling

Reviewed changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/EnergyModelsLanguageInterfaces.jl Added import for EnergyModelsInvestments module
src/datastructures.jl Modified BioCHP constructor to create investment data using C_inv and set initial capacity to zero
test/utils.jl Changed model type from OperationalModel to InvestmentModel with 7% discount rate
test/test_bioCHP.jl Updated test assertions for emissions and deficits to match new investment model behavior
test/runtests.jl Refactored include paths to use joinpath for cross-platform compatibility

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Zetison Zetison requested a review from JulStraus December 17, 2025 08:12
Copy link
Member

@JulStraus JulStraus left a comment

Choose a reason for hiding this comment

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

Looking through it, two things come directly to my mind:

  1. this PR enforces that we always load EnergyModelsInvestments when loading EMLI. Otherwise, we might potentially run into problems when the model is created? As I do not have a proper C++ compiler on my PC, can you test locally what happens in an environment in which you have EMLI, TS, and EMB loaded, but not EMI. Is it working in this situation to build and optimize a problem?
  2. The max installed capacity is based on the specified electric capacity and we allow for ContinuousInvestments to reach the capacity. This is essentially a limitation of the current approach.

I honestly do not know a good approach for the implementation right now, but I would also not like to rush the things pre Christmas to get it implemented. there are quite a few things which should be solved differently, see my individual comments.

My suggestion is hence to:

  1. comment out the lines changed for CHP (l. 864-875) and revert the capacity line and
  2. identify whether C_inv and specify in this case, if the costs are absolute or relative.

I would then create a different constructor in an EnergyModelsInvestments extension in which we also specify the initial capacity and the desired capacity for the investment data. But that can wait until after the new year.

@Zetison Zetison requested a review from JulStraus December 18, 2025 09:59
Copy link
Member

@JulStraus JulStraus left a comment

Choose a reason for hiding this comment

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

I think my previous comment was a bit misunderstood. I did not mean that we should only have the constructor in the EMI extension. Instead, I wanted a second constructor in the EMI extension which allows for the case with investments.

This would the correspond to the following constructor within src/datastructures.jl

function BioCHP(
    id::Any,
    cap::TimeProfile,
    mass_fractions::Dict{<:ResourceBio,<:Real},
    heat_output_ratios::Dict{<:ResourceHeat,<:Real},
    electricity_resource::Resource;
    data::Vector{Data} = Data[],
    libpath::String = joinpath(
        @__DIR__,
        "..",
        "..",
        "CHP_modelling",
        "build",
        "lib",
        "libbioCHP_wrapper.so",
    ),
)

and the following constructor within ext/EMIExt/EMIExt.jl

function EMLI.BioCHP(
    id::Any,
    cap_invest::TimeProfile,
    cap_init::TimeProfile,
    mass_fractions::Dict{<:ResourceBio,<:Real},
    heat_output_ratios::Dict{<:ResourceHeat,<:Real},
    electricity_resource::Resource;
    data::Vector{Data} = Data[],
    libpath::String = joinpath(
        @__DIR__,
        "..",
        "..",
        "CHP_modelling",
        "build",
        "lib",
        "libbioCHP_wrapper.so",
    ),
)

I just realized now that we must in this situation specify cap_init and cannot have it as a keyword argument as it would otherwise not work...

This implies that everything excluding the return statement and the creation of the investment data can be a subfunction which is called by both constructors.

Copy link
Member

@JulStraus JulStraus left a comment

Choose a reason for hiding this comment

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

Looks good to me now. Please do a squash and merge with a change to the commit message (e.g., I do not think my commits must be included) after the CI went successful.

@Zetison Zetison merged commit 60502f2 into main Dec 18, 2025
3 checks passed
@JulStraus JulStraus deleted the fix/bioCHP_C_inv_usage branch December 18, 2025 12:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants