From 5f66665e8e6444c70318d6b5cebebb015b9d2af8 Mon Sep 17 00:00:00 2001 From: Michiel den Haan Date: Fri, 21 May 2021 09:53:23 +0200 Subject: [PATCH] Add various primary demand specs Closes #148, #150, #151 --- lib/preset_collection.rb | 9 +- spec/demand/biomass_multi_scenario_spec.rb | 107 --------------------- spec/demand/primary_demand_spec.rb | 22 +++++ 3 files changed, 26 insertions(+), 112 deletions(-) delete mode 100644 spec/demand/biomass_multi_scenario_spec.rb create mode 100644 spec/demand/primary_demand_spec.rb diff --git a/lib/preset_collection.rb b/lib/preset_collection.rb index eb075d7..c72a1e7 100644 --- a/lib/preset_collection.rb +++ b/lib/preset_collection.rb @@ -16,11 +16,10 @@ class PresetCollection attr_reader :presets PRESET_SCENARIOS = { - nvdt: [112_999_0, 112_999_0], - basic: [472_389, 428_904, 929_277], - high_hydrogen: [123_456, 243_568], - regional: [345_689, 801_831] - }.freeze + nvdt: [1329317, 1329318, 1329319, 1329320], + ii3050: [1370826, 1370828, 1370830, 1370832], + high_hydrogen: [123_456, 243_568] + } def initialize(presets) @presets = presets diff --git a/spec/demand/biomass_multi_scenario_spec.rb b/spec/demand/biomass_multi_scenario_spec.rb deleted file mode 100644 index 785f64e..0000000 --- a/spec/demand/biomass_multi_scenario_spec.rb +++ /dev/null @@ -1,107 +0,0 @@ -# Sliders ... - -require 'spec_helper' - -describe 'BiomasMultiScenario' do - let(:default_margin) { 1.0E-12 } - - Turk::PresetCollection.from_key(:nvdt).each do |scenario| - it 'results in the total demand of the dry biomass resources to be equal to the distribution demand' do - expect(scenario.turk_distribution_dry_biomass.value) - .to be_within(default_margin * scenario.turk_demand_dry_biomass.value) - .of(scenario.turk_demand_dry_biomass.value) - end - - it 'results in the total demand of the wet biomass resources to be equal to the distribution demand' do - expect(scenario.turk_distribution_wet_biomass.value) - .to be_within(default_margin * scenario.turk_demand_wet_biomass.value) - .of(scenario.turk_demand_wet_biomass.value) - end - - it 'results in the total demand of the oily biomass resources to be equal to the distribution demand' do - # with an error margin of 1.0E-4 - margin = 1.0E-4 - expect(scenario.turk_distribution_oily_biomass.value) - .to be_within(margin * scenario.turk_demand_oily_biomass.value) - .of(scenario.turk_demand_oily_biomass.value) - end - - it 'results in the total demand of the biogenic waste resources to be equal to the distribution demand' do - expect(scenario.turk_distribution_biogenic_waste.value) - .to be_within(default_margin * scenario.turk_demand_biogenic_waste.value) - .of(scenario.turk_demand_biogenic_waste.value) - end - - it 'results in all input and output flows of the biomass sankey nodes to be equal' do - expect(scenario.turk_total_input_in_biomass_sankey.value) - .to be_within(default_margin * scenario.turk_total_output_in_biomass_sankey.value) - .of(scenario.turk_total_output_in_biomass_sankey.value) - end - - it 'results in equal input and output flows of the biogenic_waste node in the biomass sankey' do - expect(scenario.turk_input_of_biogenic_waste_in_biomass_sankey.value) - .to be_within(default_margin * scenario.turk_output_of_biogenic_waste_in_biomass_sankey.value) - .of(scenario.turk_output_of_biogenic_waste_in_biomass_sankey.value) - end - - it 'results in equal input and output flows of the wet node in the biomass sankey' do - expect(scenario.turk_input_of_wet_in_biomass_sankey.value) - .to be_within(default_margin * scenario.turk_output_of_wet_in_biomass_sankey.value) - .of(scenario.turk_output_of_wet_in_biomass_sankey.value) - end - - it 'results in equal input and output flows of the oily node in the biomass sankey' do - expect(scenario.turk_input_of_oily_in_biomass_sankey.value) - .to be_within(default_margin * scenario.turk_output_of_oily_in_biomass_sankey.value) - .of(scenario.turk_output_of_oily_in_biomass_sankey.value) - end - - it 'results in equal input and output flows of the dry node in the biomass sankey' do - expect(scenario.turk_input_of_dry_in_biomass_sankey.value) - .to be_within(default_margin * scenario.turk_output_of_dry_in_biomass_sankey.value) - .of(scenario.turk_output_of_dry_in_biomass_sankey.value) - end - - it 'results in equal input and output flows of the biogas node in the biomass sankey' do - expect(scenario.turk_input_of_biogas_in_biomass_sankey.value) - .to be_within(default_margin * scenario.turk_output_of_biogas_in_biomass_sankey.value) - .of(scenario.turk_output_of_biogas_in_biomass_sankey.value) - end - - it 'results in equal input and output flows of the greengas node in the biomass sankey' do - expect(scenario.turk_input_of_greengas_in_biomass_sankey.value) - .to be_within(default_margin * scenario.turk_output_of_greengas_in_biomass_sankey.value) - .of(scenario.turk_output_of_greengas_in_biomass_sankey.value) - end - - it 'results in equal input and output flows of the biofuels node in the biomass sankey' do - expect(scenario.turk_input_of_biofuels_in_biomass_sankey.value) - .to be_within(default_margin * scenario.turk_output_of_biofuels_in_biomass_sankey.value) - .of(scenario.turk_output_of_biofuels_in_biomass_sankey.value) - end - - it 'results in equal input and output flows of the electricity_prod node in the biomass sankey, - taking into account a correction for heaters with >100\% efficiencies' do - expect( - scenario.turk_input_of_electricity_prod_in_biomass_sankey.value + - scenario.turk_input_of_electricity_prod_in_biomass_sankey_efficiency_correction.value - ).to be_within(default_margin * scenario.turk_output_of_electricity_prod_in_biomass_sankey.value) - .of(scenario.turk_output_of_electricity_prod_in_biomass_sankey.value) - end - - it 'results in equal input and output flows of the central_heat_prod node in the biomass sankey, - taking into account a correction for heaters with >100\% efficiencies' do - expect( - scenario.turk_input_of_central_heat_prod_in_biomass_sankey.value + - scenario.turk_input_of_central_heat_prod_in_biomass_sankey_efficiency_correction.value - ).to be_within(default_margin * scenario.turk_output_of_central_heat_prod_in_biomass_sankey.value) - .of(scenario.turk_output_of_central_heat_prod_in_biomass_sankey.value) - end - - it 'results in equal input and output flows of the hydrogen_prod node in the biomass sankey' do - expect(scenario.turk_input_of_hydrogen_prod_in_biomass_sankey.value) - .to be_within(default_margin * scenario.turk_output_of_hydrogen_prod_in_biomass_sankey.value) - .of(scenario.turk_output_of_hydrogen_prod_in_biomass_sankey.value) - end - end -end diff --git a/spec/demand/primary_demand_spec.rb b/spec/demand/primary_demand_spec.rb new file mode 100644 index 0000000..e2ba429 --- /dev/null +++ b/spec/demand/primary_demand_spec.rb @@ -0,0 +1,22 @@ +require 'spec_helper' + +describe 'Primary Demand' do + let(:default_margin) { 1.0E-12 } + + Turk::PresetCollection.from_key(:ii3050).each do |scenario| + # Test whether application group covers all final demand and exports + it 'primary demand of the application group nodes should always equal primary demand of the nodes in the final_demand_group and energy_export group' do + expect(scenario.primary_demand_of_application_group.value) + .to be_within(default_margin * scenario.primary_demand_of_final_demand_and_export.value) + .of(scenario.primary_demand_of_final_demand_and_export.value) + end + + # Test whether total primary demand is accounted for by final demand, exports and curtailment. Refinery gas is also added to this list due to this issue: https://github.com/quintel/etsource/issues/1156. + it 'total primary demand in the graph should always equal primary demand of the nodes in the final_demand_group, energy_export group and curtailment.' do + puts scenario.id + expect(scenario.total_primary_demand.value) + .to be_within(default_margin * scenario.primary_demand_of_final_demand_export_curtailment_and_refinery_gas.value) + .of(scenario.primary_demand_of_final_demand_export_curtailment_and_refinery_gas.value) + end + end +end