Skip to content

Commit

Permalink
merge post_integration to validation
Browse files Browse the repository at this point in the history
  • Loading branch information
b4pm-devops committed Feb 18, 2025
2 parents 13b0a16 + 969d4db commit 253d311
Show file tree
Hide file tree
Showing 31 changed files with 37 additions and 373 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class IndependentInvestDiscipline(SoSWrapp):
GlossaryEnergy.YearEnd: GlossaryEnergy.YearEndVar,
GlossaryEnergy.invest_mix: {'type': 'dataframe', 'unit': 'G$',
'dataframe_edition_locked': False,
'visibility': SoSWrapp.SHARED_VISIBILITY, 'namespace': 'ns_invest',
'dynamic_dataframe_columns': True
},
GlossaryEnergy.energy_list: {'type': 'list', 'subtype_descriptor': {'list': 'string'},
Expand All @@ -66,12 +67,6 @@ class IndependentInvestDiscipline(SoSWrapp):
'visibility': SoSWrapp.SHARED_VISIBILITY, 'namespace': 'ns_energy_study',
'editable': False,
'structuring': True},
GlossaryEnergy.ReforestationInvestmentValue: {'type': 'dataframe', 'unit': 'G$', 'visibility': 'Shared',
'dataframe_descriptor': {GlossaryEnergy.Years: ('float', None, False),
GlossaryEnergy.ReforestationInvestmentValue: (
'float', None, False)},
'namespace': 'ns_invest',
'dataframe_edition_locked': False},
GlossaryEnergy.MaxBudgetValue : GlossaryEnergy.MaxBudgetDf,
GlossaryEnergy.MaxBudgetConstraintRefValue: GlossaryEnergy.MaxBudgetConstraintRef
}
Expand Down Expand Up @@ -114,21 +109,7 @@ def setup_sos_disciplines(self):
if energy_list is not None:
for energy in energy_list:
if energy == BiomassDry.name:
dynamic_inputs['managed_wood_investment'] = {
'type': 'dataframe', 'unit': 'G$', 'visibility': 'Shared',
'dataframe_descriptor': {GlossaryEnergy.Years: ('float', None, False),
GlossaryEnergy.InvestmentsValue: ('float', None, False)},
'namespace': 'ns_forest', 'dataframe_edition_locked': False, }
dynamic_inputs['deforestation_investment'] = {
'type': 'dataframe', 'unit': 'G$', 'visibility': 'Shared',
'dataframe_descriptor': {GlossaryEnergy.Years: ('float', None, False),
GlossaryEnergy.InvestmentsValue: ('float', None, False)},
'namespace': 'ns_forest', 'dataframe_edition_locked': False}
dynamic_inputs['crop_investment'] = {
'type': 'dataframe', 'unit': 'G$', 'visibility': 'Shared',
'dataframe_descriptor': {GlossaryEnergy.Years: ('float', None, False),
GlossaryEnergy.InvestmentsValue: ('float', None, False)},
'namespace': 'ns_crop', 'dataframe_edition_locked': False}
pass
else:
# Add technologies_list to inputs
dynamic_inputs[f'{energy}.{GlossaryEnergy.techno_list}'] = {
Expand Down Expand Up @@ -224,39 +205,6 @@ def compute_sos_jacobian(self):
(GlossaryEnergy.invest_mix, techno),
np.identity(len(years)))

self.set_partial_derivative_for_other_types(
(GlossaryEnergy.EnergyInvestmentsWoTaxValue, GlossaryEnergy.EnergyInvestmentsWoTaxValue),
(GlossaryEnergy.ReforestationInvestmentValue, GlossaryEnergy.ReforestationInvestmentValue),
identity * 1e-3)

self.set_partial_derivative_for_other_types(
(GlossaryEnergy.EnergyInvestmentsMinimizationObjective,),
(GlossaryEnergy.ReforestationInvestmentValue, GlossaryEnergy.ReforestationInvestmentValue),
ones * 1e-3)

self.set_partial_derivative_for_other_types(
(GlossaryEnergy.MaxBudgetConstraintValue, GlossaryEnergy.MaxBudgetConstraintValue),
(GlossaryEnergy.ReforestationInvestmentValue, GlossaryEnergy.ReforestationInvestmentValue),
identity / max_budget_constraint_ref)

energy_list = inputs_dict[GlossaryEnergy.energy_list]
if BiomassDry.name in energy_list:
for techno in ['managed_wood_investment', 'deforestation_investment', 'crop_investment']:
self.set_partial_derivative_for_other_types(
(GlossaryEnergy.EnergyInvestmentsWoTaxValue, GlossaryEnergy.EnergyInvestmentsWoTaxValue),
(techno, GlossaryEnergy.InvestmentsValue),
identity * 1e-3)

self.set_partial_derivative_for_other_types(
(GlossaryEnergy.EnergyInvestmentsMinimizationObjective,),
(techno, GlossaryEnergy.InvestmentsValue),
ones * 1e-3)

self.set_partial_derivative_for_other_types(
(GlossaryEnergy.MaxBudgetConstraintValue, GlossaryEnergy.MaxBudgetConstraintValue),
(techno, GlossaryEnergy.InvestmentsValue),
identity / max_budget_constraint_ref)

def get_chart_filter_list(self):

chart_filters = []
Expand Down Expand Up @@ -331,39 +279,6 @@ def pimp_string(val: str):

new_chart_energy.series.append(serie)

reforestation_investment = self.get_sosdisc_inputs(GlossaryEnergy.ReforestationInvestmentValue)
chart_name = 'Distribution of reforestation investments'
agriculture_chart = TwoAxesInstanciatedChart(GlossaryEnergy.Years, 'Invest [G$]',
chart_name=chart_name, stacked_bar=True)
serie_agriculture = InstanciatedSeries(
reforestation_investment[GlossaryEnergy.Years].values.tolist(),
reforestation_investment[GlossaryEnergy.ReforestationInvestmentValue].values.tolist(), 'Reforestation', 'bar')
agriculture_chart.series.append(serie_agriculture)
instanciated_charts.append(agriculture_chart)
serie = InstanciatedSeries(
reforestation_investment[GlossaryEnergy.Years].values.tolist(),
reforestation_investment[GlossaryEnergy.ReforestationInvestmentValue].tolist(), 'Reforestation', 'bar')

new_chart_energy.series.append(serie)

if BiomassDry.name in energy_list:
chart_name = 'Distribution of agriculture sector investments'
agriculture_chart = TwoAxesInstanciatedChart(GlossaryEnergy.Years, 'Invest [G$]',
chart_name=chart_name, stacked_bar=True)

for techno in ['managed_wood_investment', 'deforestation_investment', 'crop_investment']:
invest = self.get_sosdisc_inputs(techno)
serie_agriculture = InstanciatedSeries(
invest[GlossaryEnergy.Years].values.tolist(),
invest[GlossaryEnergy.InvestmentsValue].values.tolist(), techno.replace("_investment", ""),
'bar')
agriculture_chart.series.append(serie_agriculture)
serie = InstanciatedSeries(
invest[GlossaryEnergy.Years].values.tolist(),
invest[GlossaryEnergy.InvestmentsValue].tolist(), techno.replace("_investment", ""), 'bar')
new_chart_energy.series.append(serie)
instanciated_charts.append(agriculture_chart)
instanciated_charts.insert(0, new_chart_energy)

instanciated_charts.insert(0, new_chart_energy)

Expand Down
8 changes: 0 additions & 8 deletions energy_models/core/investments/independent_invest.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import numpy as np
import pandas as pd

from energy_models.core.stream_type.energy_models.biomass_dry import BiomassDry
from energy_models.glossaryenergy import GlossaryEnergy

from .base_invest import BaseInvest
Expand Down Expand Up @@ -55,13 +54,6 @@ def compute_energy_investment_wo_tax(self, inputs_dict: dict):
techno_invests = inputs_dict[GlossaryEnergy.invest_mix][self.distribution_list]
techno_invest_sum = techno_invests.sum(axis=1).values

techno_invest_sum += inputs_dict[GlossaryEnergy.ReforestationInvestmentValue][
GlossaryEnergy.ReforestationInvestmentValue].values
energy_list = inputs_dict[GlossaryEnergy.energy_list]

if BiomassDry.name in energy_list:
for techno in ['managed_wood_investment', 'deforestation_investment', 'crop_investment']:
techno_invest_sum += inputs_dict[techno][GlossaryEnergy.InvestmentsValue].values
energy_investment_wo_tax = pd.DataFrame(
{GlossaryEnergy.Years: inputs_dict[GlossaryEnergy.invest_mix][GlossaryEnergy.Years],
GlossaryEnergy.EnergyInvestmentsWoTaxValue: techno_invest_sum / 1e3}) # T$
Expand Down
12 changes: 10 additions & 2 deletions energy_models/core/techno_type/techno_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ def configure_parameters(self, inputs_dict):
self.resources_used_for_production = inputs_dict[GlossaryEnergy.ResourcesUsedForProductionValue]
self.resources_used_for_building = inputs_dict[GlossaryEnergy.ResourcesUsedForBuildingValue]
self.streams_used_for_production = inputs_dict[GlossaryEnergy.StreamsUsedForProductionValue]
if GlossaryEnergy.biomass_dry in self.streams_used_for_production:
self.streams_used_for_production.remove(GlossaryEnergy.biomass_dry)
self.lifetime = inputs_dict[GlossaryEnergy.LifetimeName]

def configure_parameters_update(self, inputs_dict):
Expand Down Expand Up @@ -485,7 +487,10 @@ def compute_cost_of_other_streams_usage(self):
GlossaryEnergy.Years: self.years,
}
for stream in self.streams_used_for_production:
cost_of_streams_usage[stream] = self.cost_details[f"{stream}_needs"].values * self.stream_prices[stream].values
if stream == GlossaryEnergy.biomass_dry:
cost_of_streams_usage[stream] = 0.
else:
cost_of_streams_usage[stream] = self.cost_details[f"{stream}_needs"].values * self.stream_prices[stream].values

self.cost_of_streams_usage = pd.DataFrame(cost_of_streams_usage)

Expand Down Expand Up @@ -1146,7 +1151,10 @@ def compute_co2_emissions_from_ressources_usage(self):
def compute_co2_emissions_from_streams_usage(self):
"""Computes the co2 emissions due to streams usage"""
for stream in self.streams_used_for_production:
self.carbon_intensity_generic[stream] = self.cost_details[f"{stream}_needs"].values * self.streams_CO2_emissions[stream].values
if stream == GlossaryEnergy.biomass_dry:
self.carbon_intensity_generic[stream] = 0
else:
self.carbon_intensity_generic[stream] = self.cost_details[f"{stream}_needs"].values * self.streams_CO2_emissions[stream].values

def compute_new_power_production_resource_consumption(self):
"""
Expand Down
8 changes: 2 additions & 6 deletions energy_models/glossaryenergy.py
Original file line number Diff line number Diff line change
Expand Up @@ -683,10 +683,6 @@ class GlossaryEnergy(GlossaryWitnessCore):
f"{fuel}.{biodiesel}": {stream_type: energy_type, value: [Transesterification]},
f"{fuel}.{ethanol}": {stream_type: energy_type, value: [BiomassFermentation]},
solid_fuel: {stream_type: energy_type, value: [CoalExtraction, Pelletizing]},
biomass_dry: {
stream_type: agriculture_type,
value: [ManagedWood, UnmanagedWood, CropEnergy],
},
electricity: {stream_type: energy_type, value: [WindOffshore]},
f"{hydrogen}.{liquid_hydrogen}": {
stream_type: energy_type,
Expand Down Expand Up @@ -775,7 +771,6 @@ class GlossaryEnergy(GlossaryWitnessCore):
f"{fuel}.{biodiesel}": {stream_type: energy_type, value: [Transesterification]},
f"{fuel}.{ethanol}": {stream_type: energy_type, value: [BiomassFermentation]},
solid_fuel: {stream_type: energy_type, value: [CoalExtraction, Pelletizing]},
biomass_dry: {stream_type: agriculture_type, value: []},
electricity: {
stream_type: energy_type,
value: [
Expand All @@ -790,7 +785,7 @@ class GlossaryEnergy(GlossaryWitnessCore):
BiogasFired,
CoalGen,
OilGen,
BiomassFired,
#BiomassFired,
],
},
carbon_capture: {
Expand Down Expand Up @@ -1061,6 +1056,7 @@ class GlossaryEnergy(GlossaryWitnessCore):
Geothermal: [],
Crop: [],
Forest: [],
GlossaryWitnessCore.Forestry: [],
RWGS: [WaterResource],
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

from energy_models.core.stream_type.carbon_models.carbon_capture import CarbonCapture
from energy_models.core.stream_type.energy_models.biomass_dry import BiomassDry
from energy_models.core.stream_type.energy_models.heat import hightemperatureheat
from energy_models.core.techno_type.base_techno_models.electricity_techno import (
ElectricityTechno,
)
Expand All @@ -34,9 +33,11 @@ def compute_byproducts_production(self):
self.production_detailed[
f'{ElectricityTechno.energy_name} ({self.product_unit})']

"""
self.production_detailed[f'{hightemperatureheat.name} ({self.product_unit})'] = \
self.consumption_detailed[f'{BiomassDry.name} ({self.product_unit})'] - \
self.production_detailed[f'{ElectricityTechno.energy_name} ({self.product_unit})'] # TWh
"""


def get_theoretical_co2_prod(self, unit='kg/kWh'):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
TwoAxesInstanciatedChart,
)

from energy_models.core.stream_type.energy_models.biomass_dry import BiomassDry
from energy_models.core.stream_type.energy_models.heat import hightemperatureheat
from energy_models.core.techno_type.disciplines.electricity_techno_disc import (
ElectricityTechnoDiscipline,
)
Expand Down Expand Up @@ -134,24 +132,3 @@ def get_charts_consumption_and_production(self):

return instanciated_chart

def compute_sos_jacobian(self):
ElectricityTechnoDiscipline.compute_sos_jacobian(self)

# the generic gradient for production column is not working because of
# abandoned mines not proportional to production

scaling_factor_invest_level, scaling_factor_techno_production = self.get_sosdisc_inputs(
['scaling_factor_invest_level', 'scaling_factor_techno_production'])
applied_ratio = self.get_sosdisc_outputs(
'applied_ratio')['applied_ratio'].values

dprod_name_dinvest = (
self.dprod_dinvest.T * applied_ratio).T * scaling_factor_invest_level / scaling_factor_techno_production
consumption_gradient = self.techno_consumption_derivative[
f'{BiomassDry.name} ({self.techno_model.product_unit})']
# self.techno_consumption_derivative[f'{SolidFuel.name} ({self.product_unit})']
self.set_partial_derivative_for_other_types(
(GlossaryEnergy.TechnoProductionValue,
f'{hightemperatureheat.name} ({self.techno_model.product_unit})'),
(GlossaryEnergy.InvestLevelValue, GlossaryEnergy.InvestValue),
(consumption_gradient - dprod_name_dinvest))
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ def setup_usecase(self, study_folder_path=None):
co2_land_emissions = pd.DataFrame({
GlossaryEnergy.Years: self.years,
"Crop": 0.,
"Forest": 0.,
"Forestry": 0.,
})

CO2_indus_emissions_df = pd.DataFrame({
Expand Down Expand Up @@ -605,7 +605,7 @@ def setup_usecase(self, study_folder_path=None):
f"{self.study_name}.{self.coupling_name}.{energy_mix_name}.{GlossaryEnergy.AllStreamsDemandRatioValue}": all_streams_demand_ratio,
f"{self.study_name}.is_stream_demand": True,
f"{self.study_name}.max_mda_iter": 50,
f"{self.study_name}.inner_mda_name": "MDAGSNewton",
f"{self.study_name}.inner_mda_name": "MDAGaussSeidel",
f"{self.study_name}.{self.coupling_name}.{energy_mix_name}.{GlossaryEnergy.RessourcesCO2EmissionsValue}": resources_CO2_emissions,
f"{self.study_name}.{self.coupling_name}.{energy_mix_name}.{GlossaryEnergy.ResourcesPriceValue}": resources_prices,
f"{self.study_name}.{self.coupling_name}.{energy_mix_name}.{GlossaryEnergy.TargetEnergyProductionValue}": target_energy_prod,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def setup_usecase(self, study_folder_path=None):
f'{self.study_name}.tolerance': 1.0e-7,
f'{self.study_name}.n_processes': 1,
f'{self.study_name}.linearization_mode': 'adjoint',
f'{self.study_name}.inner_mda_name': 'MDAGSNewton',
f'{self.study_name}.inner_mda_name': 'MDAGaussSeidel',
}
values_dict_list.append(numerical_values_dict)

Expand Down
Empty file.

This file was deleted.

Loading

0 comments on commit 253d311

Please sign in to comment.