From 2205cdca3be6159c1800ed60d75f1ed7566536d6 Mon Sep 17 00:00:00 2001 From: perrotcap Date: Tue, 3 Sep 2024 14:19:02 +0200 Subject: [PATCH 1/3] fixed d techno capital / d invest level --- energy_models/core/techno_type/techno_type.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/energy_models/core/techno_type/techno_type.py b/energy_models/core/techno_type/techno_type.py index d85e4b75..ce0c867a 100644 --- a/energy_models/core/techno_type/techno_type.py +++ b/energy_models/core/techno_type/techno_type.py @@ -1203,6 +1203,12 @@ def d_non_use_capital_d_utilisation_ratio(self): ) return d_non_use_capital_d_utilisation_ratio + def d_non_use_capital_d_invest_level(self, d_capital_d_invest_level): + applied_ratio = self.applied_ratio['applied_ratio'].values / 100. + utilisation_ratio = self.utilisation_ratio + return np.diag(applied_ratio * utilisation_ratio / 100.) * d_capital_d_invest_level + + def compute_dlanduse_dinvest(self): """ compute grad d_land_use / d_invest @@ -1430,8 +1436,8 @@ def compute_dnon_usecapital_dinvest(self, dcapex_dinvest, dprod_dinvest): dprod_dinvest * self.cost_details[f'Capex_{self.name}'].values.reshape( (len(self.years), 1))) - dnon_usecapital_dinvest = dtechnocapital_dinvest * ( - 1.0 - self.applied_ratio['applied_ratio'].values).reshape((len(self.years), 1)) + dnon_usecapital_dinvest = np.diag( + 1.0 - self.applied_ratio['applied_ratio'].values * self.utilisation_ratio / 100.) @ dtechnocapital_dinvest # we do not divide by / self.scaling_factor_invest_level because invest # and non_use_capital are in G$ From efc0bae5b2068a0b28275b4e077400c1aa620bf1 Mon Sep 17 00:00:00 2001 From: perrotcap Date: Tue, 3 Sep 2024 14:19:32 +0200 Subject: [PATCH 2/3] removed hardcoded dataframe descriptor --- .../energy_ghg_emissions_disc.py | 34 +------------------ 1 file changed, 1 insertion(+), 33 deletions(-) diff --git a/energy_models/core/energy_ghg_emissions/energy_ghg_emissions_disc.py b/energy_models/core/energy_ghg_emissions/energy_ghg_emissions_disc.py index 413dbf69..6f28d8a5 100644 --- a/energy_models/core/energy_ghg_emissions/energy_ghg_emissions_disc.py +++ b/energy_models/core/energy_ghg_emissions/energy_ghg_emissions_disc.py @@ -83,39 +83,7 @@ class EnergyGHGEmissionsDiscipline(SoSWrapp): GlossaryEnergy.EnergyProductionDetailedValue: {'type': 'dataframe', 'unit': 'TWh', 'visibility': SoSWrapp.SHARED_VISIBILITY, 'namespace': 'ns_energy', - 'dataframe_descriptor': { - GlossaryEnergy.Years: ('float', None, True), - f'production {GlossaryEnergy.methane} ({GlossaryEnergy.energy_unit})': ( - 'float', None, True), - f'production {GlossaryEnergy.hydrogen}.{GlossaryEnergy.gaseous_hydrogen} ({GlossaryEnergy.energy_unit})': ( - 'float', None, True), - f'production {GlossaryEnergy.biogas} ({GlossaryEnergy.energy_unit})': ( - 'float', None, True), - f'production {GlossaryEnergy.syngas} ({GlossaryEnergy.energy_unit})': ( - 'float', None, True), - f'production {GlossaryEnergy.fuel}.{GlossaryEnergy.liquid_fuel} ({GlossaryEnergy.energy_unit})': ( - 'float', None, True), - f'production {GlossaryEnergy.fuel}.{GlossaryEnergy.ethanol} ({GlossaryEnergy.energy_unit})': ( - 'float', None, True), - f'production {GlossaryEnergy.fuel}.{GlossaryEnergy.hydrotreated_oil_fuel} ({GlossaryEnergy.energy_unit})': ( - 'float', None, True), - f'production {GlossaryEnergy.solid_fuel} ({GlossaryEnergy.energy_unit})': ( - 'float', None, True), - f'production {GlossaryEnergy.biomass_dry} ({GlossaryEnergy.energy_unit})': ( - 'float', None, True), - f'production {GlossaryEnergy.electricity} ({GlossaryEnergy.energy_unit})': ( - 'float', None, True), - f'production {GlossaryEnergy.fuel}.{GlossaryEnergy.biodiesel} ({GlossaryEnergy.energy_unit})': ( - 'float', None, True), - f'production {GlossaryEnergy.hydrogen}.{GlossaryEnergy.liquid_hydrogen} ({GlossaryEnergy.energy_unit})': ( - 'float', None, True), - f'production {GlossaryEnergy.carbon_capture} ({GlossaryEnergy.mass_unit})': ( - 'float', None, True), - f'production {GlossaryEnergy.carbon_storage} ({GlossaryEnergy.mass_unit})': ( - 'float', None, True), - 'Total production': ('float', None, True), - 'Total production (uncut)': ('float', None, True), - }, + "dynamic_dataframe_columns": True, }, 'co2_emissions_ccus_Gt': {'type': 'dataframe', 'unit': 'Gt', 'visibility': ClimateEcoDiscipline.SHARED_VISIBILITY, From c9bba789f74eadd0138ad1da5b5c0d103ffedb21 Mon Sep 17 00:00:00 2001 From: perrotcap Date: Tue, 3 Sep 2024 15:40:55 +0200 Subject: [PATCH 3/3] fixed many gradients --- energy_models/core/energy_mix/energy_mix_disc.py | 4 ++-- .../techno_type/base_techno_models/carbon_capture_techno.py | 2 +- .../techno_type/disciplines/carbon_capture_techno_disc.py | 6 +++--- energy_models/core/techno_type/techno_type.py | 5 ++--- .../flue_gas_techno/flue_gas_techno_disc.py | 4 ++-- 5 files changed, 10 insertions(+), 11 deletions(-) diff --git a/energy_models/core/energy_mix/energy_mix_disc.py b/energy_models/core/energy_mix/energy_mix_disc.py index 4efbf0cd..b07dd157 100644 --- a/energy_models/core/energy_mix/energy_mix_disc.py +++ b/energy_models/core/energy_mix/energy_mix_disc.py @@ -395,7 +395,7 @@ def run(self): [(1. - alpha) * self.energy_model.production[GlossaryEnergy.TotalProductionValue][0] * delta_years / self.energy_model.production[GlossaryEnergy.TotalProductionValue].sum(), ]) - + if EnergyMix.PRODUCTION in self.energy_model.stream_prices: self.energy_model.stream_prices.drop( columns=[EnergyMix.PRODUCTION], inplace=True) @@ -781,7 +781,7 @@ def compute_sos_jacobian(self): (GlossaryEnergy.EnergyProductionDetailedValue, f'production {energy} ({stream_class_dict[energy].unit})'), (f'{ns_energy}.{GlossaryEnergy.EnergyProductionValue}', energy), - np.identity(len(years)) * scaling_factor_energy_production) + np.identity(len(years)) * scaling_factor_energy_production * 0.) # ---- Loop on energy again to differentiate production and consumption ----# for energy_input in energy_list: ns_energy_input = self.get_ns_energy(energy_input) diff --git a/energy_models/core/techno_type/base_techno_models/carbon_capture_techno.py b/energy_models/core/techno_type/base_techno_models/carbon_capture_techno.py index c5986b7e..f908aeb7 100644 --- a/energy_models/core/techno_type/base_techno_models/carbon_capture_techno.py +++ b/energy_models/core/techno_type/base_techno_models/carbon_capture_techno.py @@ -201,7 +201,7 @@ def compute_dnon_usecapital_dfluegas(self, dcapex_dfluegas, dprod_dfluegas): (len(self.years), 1))) dnon_usecapital_dfluegas = dtechnocapital_dfluegas * ( - 1.0 - self.applied_ratio['applied_ratio'].values).reshape((len(self.years), 1)) + 1.0 - self.applied_ratio['applied_ratio'].values * self.utilisation_ratio/ 100.).reshape((len(self.years), 1)) # we do not divide by / self.scaling_factor_invest_level because invest # and non_use_capital are in G$ diff --git a/energy_models/core/techno_type/disciplines/carbon_capture_techno_disc.py b/energy_models/core/techno_type/disciplines/carbon_capture_techno_disc.py index 03311016..e881440a 100644 --- a/energy_models/core/techno_type/disciplines/carbon_capture_techno_disc.py +++ b/energy_models/core/techno_type/disciplines/carbon_capture_techno_disc.py @@ -79,7 +79,7 @@ def set_partial_derivatives_flue_gas(self, energy_name=GlossaryEnergy.electricit inputs_dict[GlossaryEnergy.InvestLevelValue][GlossaryEnergy.Years] <= inputs_dict[GlossaryEnergy.YearEnd]][GlossaryEnergy.InvestValue].values, inputs_dict['techno_infos_dict'], inputs_dict['fg_ratio_effect']) - + utilisation_ratio = inputs_dict[GlossaryEnergy.UtilisationRatioValue][GlossaryEnergy.UtilisationRatioValue].values crf = self.techno_model.compute_capital_recovery_factor(inputs_dict['techno_infos_dict']) dfactory_dfluegas = dcapex_dfluegas * \ (crf + inputs_dict['techno_infos_dict']['Opex_percentage']) @@ -115,7 +115,7 @@ def set_partial_derivatives_flue_gas(self, energy_name=GlossaryEnergy.electricit self.set_partial_derivative_for_other_types( (GlossaryEnergy.TechnoProductionValue, f'{self.energy_name} ({self.techno_model.product_unit})'), ( GlossaryEnergy.FlueGasMean, GlossaryEnergy.FlueGasMean), - dprod_dfluegas * self.techno_model.applied_ratio['applied_ratio'].values[:, + dprod_dfluegas * (self.techno_model.applied_ratio['applied_ratio'].values * utilisation_ratio/ 100.)[:, np.newaxis] * scaling_factor_invest_level / scaling_factor_techno_production) production, consumption = self.get_sosdisc_outputs( @@ -132,7 +132,7 @@ def set_partial_derivatives_flue_gas(self, energy_name=GlossaryEnergy.electricit self.set_partial_derivative_for_other_types( (GlossaryEnergy.TechnoConsumptionValue, column), (GlossaryEnergy.FlueGasMean, GlossaryEnergy.FlueGasMean), - dprod_column_dfluegas * self.techno_model.applied_ratio['applied_ratio'].values[:, + dprod_column_dfluegas * (self.techno_model.applied_ratio['applied_ratio'].values * utilisation_ratio/ 100.)[:, np.newaxis] * scaling_factor_invest_level / scaling_factor_techno_production) self.set_partial_derivative_for_other_types( (GlossaryEnergy.TechnoConsumptionWithoutRatioValue, diff --git a/energy_models/core/techno_type/techno_type.py b/energy_models/core/techno_type/techno_type.py index ce0c867a..db549820 100644 --- a/energy_models/core/techno_type/techno_type.py +++ b/energy_models/core/techno_type/techno_type.py @@ -1419,8 +1419,7 @@ def compute_dprod_dratio(self, prod: np.ndarray, ratio_name: str, dapplied_ratio # Check that the ratio corresponds to something consumed for col in self.consumption_detailed.columns: if ratio_name in col and ratio_name != GlossaryEnergy.Years: - dprod_dratio = (np.identity(len(self.years)) * prod) * \ - dapplied_ratio_dratio[ratio_name] + dprod_dratio = np.diag(prod * self.utilisation_ratio / 100) * dapplied_ratio_dratio[ratio_name] return dprod_dratio def compute_dnon_usecapital_dinvest(self, dcapex_dinvest, dprod_dinvest): @@ -1450,7 +1449,7 @@ def compute_dnon_usecapital_dratio(self, dapplied_ratio_dratio): ''' mult_vect = self.cost_details[f'Capex_{self.name}'].values * \ self.production_woratio[f'{self.energy_name} ({self.product_unit})'].values - dnon_use_capital_dratio = -dapplied_ratio_dratio * np.diag(mult_vect) + dnon_use_capital_dratio = -dapplied_ratio_dratio * np.diag(mult_vect * self.utilisation_ratio / 100.) return dnon_use_capital_dratio def compute_dcapex_dinvest(self, invest_list, data_config): diff --git a/energy_models/models/carbon_capture/flue_gas_capture/flue_gas_techno/flue_gas_techno_disc.py b/energy_models/models/carbon_capture/flue_gas_capture/flue_gas_techno/flue_gas_techno_disc.py index 3d386771..f56b72c8 100644 --- a/energy_models/models/carbon_capture/flue_gas_capture/flue_gas_techno/flue_gas_techno_disc.py +++ b/energy_models/models/carbon_capture/flue_gas_capture/flue_gas_techno/flue_gas_techno_disc.py @@ -110,8 +110,8 @@ def compute_sos_jacobian(self): CCTechnoDiscipline.compute_sos_jacobian(self) grad_dict = self.techno_model.grad_price_vs_stream_price() - + carbon_emissions = self.get_sosdisc_outputs(GlossaryEnergy.CO2EmissionsValue) self.set_partial_derivatives_techno( - grad_dict, None) + grad_dict, carbon_emissions) self.set_partial_derivatives_flue_gas(GlossaryEnergy.clean_energy)