Skip to content

Commit

Permalink
Heat modelling changes for the built environment (#164)
Browse files Browse the repository at this point in the history
* Add attributes and configs for Fever groups neccesary for priority modeling

* Add attribute `fever.tech_curve` for Nodes

* Specify which curves to use for which technology type for Fever

* Update built environment area attributes and remove outdated attributes

* Changes atlas number_of_residences attributes and specs

* Add validation for new Fever attributes

* Calculate Fever edge parent shares based on consumer and producer order

* Add fever attribute `present_share_in_demand`

* Change scaling factor into number of inhabitants

* Calculate fever attributes at runtime

* Bump Refinery  to quintel/refinery@5439199

---------

Co-authored-by: noracato <ncschinkel@gmail.com>
Co-authored-by: Roos de Kok <roos.dekok@quintel.com>
  • Loading branch information
3 people committed Jan 19, 2024
1 parent 3c1f70f commit d5c84b5
Show file tree
Hide file tree
Showing 49 changed files with 708 additions and 114 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ end

gemspec

gem 'refinery', ref: '72eacf8', github: 'quintel/refinery'
gem 'refinery', ref: '5439199', github: 'quintel/refinery'
gem 'rubel', ref: 'ad3d44e', github: 'quintel/rubel'

group :development do
Expand Down
8 changes: 4 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ GIT

GIT
remote: https://github.com/quintel/refinery.git
revision: 72eacf84c980ef797a0b7e63f55a39f5ca98640b
ref: 72eacf8
revision: 54391992ee6908712bc2abd5561e244e31a5fbe3
ref: 5439199
specs:
refinery (0.0.1)
ruby-graphviz
Expand Down Expand Up @@ -126,8 +126,8 @@ GEM
sync (0.5.0)
term-ansicolor (1.7.1)
tins (~> 1.0)
terminal-table (1.8.0)
unicode-display_width (~> 1.1, >= 1.1.1)
terminal-table (3.0.2)
unicode-display_width (>= 1.1.1, < 3)
thread_safe (0.3.6)
tins (1.25.0)
sync
Expand Down
4 changes: 4 additions & 0 deletions lib/atlas.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@
require_relative 'atlas/graph_config'
require_relative 'atlas/graph_values'
require_relative 'atlas/runner'
require_relative 'atlas/runner/fever_calculation'
require_relative 'atlas/runner/fever_calculation/group_calculator'
require_relative 'atlas/runner/fever_calculation/producer'
require_relative 'atlas/runner/pause_fever_calculations'
require_relative 'atlas/runner/scale_attributes'
require_relative 'atlas/runner/set_attributes_from_graph_values'
require_relative 'atlas/runner/set_rubel_attributes'
Expand Down
62 changes: 44 additions & 18 deletions lib/atlas/active_document/residences_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,53 @@ module Atlas
module ActiveDocument
class ResidencesValidator < ActiveModel::Validator
def validate(record)
return if record.number_of_apartments.nil? ||
record.number_of_terraced_houses.nil? ||
record.number_of_corner_houses.nil? ||
record.number_of_detached_houses.nil? ||
record.number_of_semi_detached_houses.nil?
return if record.present_number_of_apartments_before_1945.nil? ||
record.present_number_of_apartments_1945_1964.nil? ||
record.present_number_of_apartments_1965_1984.nil? ||
record.present_number_of_apartments_1985_2004.nil? ||
record.present_number_of_apartments_2005_present.nil? ||
record.present_number_of_detached_houses_before_1945.nil? ||
record.present_number_of_detached_houses_1945_1964.nil? ||
record.present_number_of_detached_houses_1965_1984.nil? ||
record.present_number_of_detached_houses_1985_2004.nil? ||
record.present_number_of_detached_houses_2005_present.nil? ||
record.present_number_of_semi_detached_houses_before_1945.nil? ||
record.present_number_of_semi_detached_houses_1945_1964.nil? ||
record.present_number_of_semi_detached_houses_1965_1984.nil? ||
record.present_number_of_semi_detached_houses_1985_2004.nil? ||
record.present_number_of_semi_detached_houses_2005_present.nil? ||
record.present_number_of_terraced_houses_before_1945.nil? ||
record.present_number_of_terraced_houses_1945_1964.nil? ||
record.present_number_of_terraced_houses_1965_1984.nil? ||
record.present_number_of_terraced_houses_1985_2004.nil? ||
record.present_number_of_terraced_houses_2005_present.nil?

sum_of_residences = record.number_of_apartments +
record.number_of_terraced_houses +
record.number_of_corner_houses +
record.number_of_detached_houses +
record.number_of_semi_detached_houses
sum_of_residences = record.present_number_of_apartments_before_1945 +
record.present_number_of_apartments_1945_1964 +
record.present_number_of_apartments_1965_1984 +
record.present_number_of_apartments_1985_2004 +
record.present_number_of_apartments_2005_present +
record.present_number_of_detached_houses_before_1945 +
record.present_number_of_detached_houses_1945_1964 +
record.present_number_of_detached_houses_1965_1984 +
record.present_number_of_detached_houses_1985_2004 +
record.present_number_of_detached_houses_2005_present +
record.present_number_of_semi_detached_houses_before_1945 +
record.present_number_of_semi_detached_houses_1945_1964 +
record.present_number_of_semi_detached_houses_1965_1984 +
record.present_number_of_semi_detached_houses_1985_2004 +
record.present_number_of_semi_detached_houses_2005_present +
record.present_number_of_terraced_houses_before_1945 +
record.present_number_of_terraced_houses_1945_1964 +
record.present_number_of_terraced_houses_1965_1984 +
record.present_number_of_terraced_houses_1985_2004 +
record.present_number_of_terraced_houses_2005_present

unless record.number_of_residences.round == sum_of_residences.round
record.errors.add(:number_of_residences,
"Number of apartments (#{ record.number_of_apartments}) "\
"Number of terraced houses (#{ record.number_of_terraced_houses}) "\
"Number of corner houses (#{ record.number_of_corner_houses}) "\
"Number of detached houses (#{ record.number_of_detached_houses}) "\
"Number of semi detached houses (#{ record.number_of_semi_detached_houses}) "\
unless record.present_number_of_residences.round == sum_of_residences.round
record.errors.add(:present_number_of_residences,
"Number of residences per type and construction year "\
"don't add up to the total number of residences "\
"(#{ record.number_of_residences })."
"(#{ record.present_number_of_residences })."
)
end
end
Expand Down
13 changes: 12 additions & 1 deletion lib/atlas/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,23 @@ def read?(basename)
private

def path_for_basename(basename)
Atlas.data_dir.join('config').join("#{clean_basename(basename)}.yml")
path_with_subfolder(Atlas.data_dir.join('config'), basename)
end

def clean_basename(basename)
basename.to_s.downcase.gsub(/[^a-z0-9_]/, '')
end

def path_with_subfolder(path, basename)
with_subfolder = basename.to_s.split('.')

if with_subfolder.length == 2
basename = with_subfolder[1]
path = path.join(with_subfolder[0])
end

path.join("#{clean_basename(basename)}.yml")
end
end
end
end
125 changes: 70 additions & 55 deletions lib/atlas/dataset.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class Dataset

attribute :has_agriculture, Boolean, default: true
attribute :has_buildings, Boolean, default: true
attribute :has_semi_detached_houses, Boolean, default: true
attribute :has_coastline, Boolean, default: true
attribute :has_cold_network, Boolean, default: false
attribute :has_electricity_storage, Boolean, default: true
Expand Down Expand Up @@ -51,17 +52,12 @@ class Dataset
# of whether we're calculating the entire region, or simulating a smaller
# sub-region.

[ :buildings_insulation_employment_constant,
:households_insulation_employment_constant,
:co2_emission_1990_aviation_bunkers,
[ :co2_emission_1990_aviation_bunkers,
:co2_emission_1990_marine_bunkers,
:co2_emissions_of_imported_electricity_g_per_kwh,
:co2_percentage_free,
:co2_price,
:offshore_ccs_potential_mt_per_year,
:economic_multiplier,
:employment_fraction_production,
:employment_local_fraction,
:export_electricity_primary_demand_factor,
:import_electricity_primary_demand_factor,
:man_hours_per_man_year,
Expand Down Expand Up @@ -92,48 +88,52 @@ class Dataset
:offshore_net_costs_present,
:flh_solar_pv_solar_radiation_max,
:hydrogen_electrolysis_solar_pv_capacity_ratio,
:insulation_detached_houses_low_share,
:insulation_detached_houses_medium_share,
:insulation_detached_houses_high_share,
:insulation_apartments_low_share,
:insulation_apartments_medium_share,
:insulation_apartments_high_share,
:insulation_semi_detached_houses_low_share,
:insulation_semi_detached_houses_medium_share,
:insulation_semi_detached_houses_high_share,
:insulation_corner_houses_low_share,
:insulation_corner_houses_medium_share,
:insulation_corner_houses_high_share,
:insulation_terraced_houses_low_share,
:insulation_terraced_houses_medium_share,
:insulation_terraced_houses_high_share,
:insulation_detached_houses_start_value,
:insulation_semi_detached_houses_start_value,
:insulation_apartments_start_value,
:insulation_corner_houses_start_value,
:insulation_terraced_houses_start_value,
:insulation_buildings_start_value,
:typical_roof_surface_corner_house_available_for_pv,
:typical_roof_surface_terraced_house_available_for_pv,
:typical_roof_surface_detached_house_available_for_pv,
:typical_roof_surface_semi_detached_house_available_for_pv,
:typical_roof_surface_apartment_available_for_pv,
:typical_useful_demand_space_heating_corner_house,
:typical_useful_demand_space_heating_detached_house,
:typical_useful_demand_space_heating_semi_detached_house,
:typical_useful_demand_space_heating_terraced_house,
:typical_useful_demand_space_heating_apartment,
:heat_demand_reduction_medium_insulation_corner_house,
:heat_demand_reduction_medium_insulation_detached_house,
:heat_demand_reduction_medium_insulation_semi_detached_house,
:heat_demand_reduction_medium_insulation_terraced_house,
:heat_demand_reduction_medium_insulation_apartments,
:heat_demand_reduction_high_insulation_corner_house,
:heat_demand_reduction_high_insulation_detached_house,
:heat_demand_reduction_high_insulation_semi_detached_house,
:heat_demand_reduction_high_insulation_terraced_house,
:heat_demand_reduction_high_insulation_apartments,
:heat_demand_reduction_high_insulation_buildings,
:present_share_of_apartments_before_1945_in_useful_demand_for_space_heating,
:present_share_of_apartments_1945_1964_in_useful_demand_for_space_heating,
:present_share_of_apartments_1965_1984_in_useful_demand_for_space_heating,
:present_share_of_apartments_1985_2004_in_useful_demand_for_space_heating,
:present_share_of_apartments_2005_present_in_useful_demand_for_space_heating,
:present_share_of_detached_houses_before_1945_in_useful_demand_for_space_heating,
:present_share_of_detached_houses_1945_1964_in_useful_demand_for_space_heating,
:present_share_of_detached_houses_1965_1984_in_useful_demand_for_space_heating,
:present_share_of_detached_houses_1985_2004_in_useful_demand_for_space_heating,
:present_share_of_detached_houses_2005_present_in_useful_demand_for_space_heating,
:present_share_of_semi_detached_houses_before_1945_in_useful_demand_for_space_heating,
:present_share_of_semi_detached_houses_1945_1964_in_useful_demand_for_space_heating,
:present_share_of_semi_detached_houses_1965_1984_in_useful_demand_for_space_heating,
:present_share_of_semi_detached_houses_1985_2004_in_useful_demand_for_space_heating,
:present_share_of_semi_detached_houses_2005_present_in_useful_demand_for_space_heating,
:present_share_of_terraced_houses_before_1945_in_useful_demand_for_space_heating,
:present_share_of_terraced_houses_1945_1964_in_useful_demand_for_space_heating,
:present_share_of_terraced_houses_1965_1984_in_useful_demand_for_space_heating,
:present_share_of_terraced_houses_1985_2004_in_useful_demand_for_space_heating,
:present_share_of_terraced_houses_2005_present_in_useful_demand_for_space_heating,
:typical_useful_demand_for_space_heating_apartments_before_1945,
:typical_useful_demand_for_space_heating_apartments_1945_1964,
:typical_useful_demand_for_space_heating_apartments_1965_1984,
:typical_useful_demand_for_space_heating_apartments_1985_2004,
:typical_useful_demand_for_space_heating_apartments_2005_present,
:typical_useful_demand_for_space_heating_apartments_future,
:typical_useful_demand_for_space_heating_detached_houses_before_1945,
:typical_useful_demand_for_space_heating_detached_houses_1945_1964,
:typical_useful_demand_for_space_heating_detached_houses_1965_1984,
:typical_useful_demand_for_space_heating_detached_houses_1985_2004,
:typical_useful_demand_for_space_heating_detached_houses_2005_present,
:typical_useful_demand_for_space_heating_detached_houses_future,
:typical_useful_demand_for_space_heating_semi_detached_houses_before_1945,
:typical_useful_demand_for_space_heating_semi_detached_houses_1945_1964,
:typical_useful_demand_for_space_heating_semi_detached_houses_1965_1984,
:typical_useful_demand_for_space_heating_semi_detached_houses_1985_2004,
:typical_useful_demand_for_space_heating_semi_detached_houses_2005_present,
:typical_useful_demand_for_space_heating_semi_detached_houses_future,
:typical_useful_demand_for_space_heating_terraced_houses_before_1945,
:typical_useful_demand_for_space_heating_terraced_houses_1945_1964,
:typical_useful_demand_for_space_heating_terraced_houses_1965_1984,
:typical_useful_demand_for_space_heating_terraced_houses_1985_2004,
:typical_useful_demand_for_space_heating_terraced_houses_2005_present,
:typical_useful_demand_for_space_heating_terraced_houses_future,
:typical_useful_demand_for_space_heating_buildings_present,
:typical_useful_demand_for_space_heating_buildings_future,
:heat_share_of_apartments_with_block_heating,
:heat_infrastructure_households_ht_indoor_investment_costs_apartments_with_block_heating_eur,
:heat_infrastructure_households_ht_indoor_investment_costs_apartments_without_block_heating_eur,
Expand Down Expand Up @@ -207,12 +207,32 @@ class Dataset
:coast_line,
:interconnector_capacity,
:total_land_area,
:number_of_buildings,
:number_of_cars,
:number_of_busses,
:number_of_trucks,
:number_of_vans,
:number_of_residences,
:present_number_of_residences,
:present_number_of_buildings,
:present_number_of_apartments_before_1945,
:present_number_of_apartments_1945_1964,
:present_number_of_apartments_1965_1984,
:present_number_of_apartments_1985_2004,
:present_number_of_apartments_2005_present,
:present_number_of_detached_houses_before_1945,
:present_number_of_detached_houses_1945_1964,
:present_number_of_detached_houses_1965_1984,
:present_number_of_detached_houses_1985_2004,
:present_number_of_detached_houses_2005_present,
:present_number_of_semi_detached_houses_before_1945,
:present_number_of_semi_detached_houses_1945_1964,
:present_number_of_semi_detached_houses_1965_1984,
:present_number_of_semi_detached_houses_1985_2004,
:present_number_of_semi_detached_houses_2005_present,
:present_number_of_terraced_houses_before_1945,
:present_number_of_terraced_houses_1945_1964,
:present_number_of_terraced_houses_1965_1984,
:present_number_of_terraced_houses_1985_2004,
:present_number_of_terraced_houses_2005_present,
:number_of_inhabitants,
:offshore_suitable_for_wind,
:residences_roof_surface_available_for_pv,
Expand All @@ -236,11 +256,6 @@ class Dataset
:non_energetic_emissions_other_ghg_agriculture_other,
:non_energetic_emissions_other_ghg_waste_management,
:indirect_emissions_co2,
:number_of_detached_houses,
:number_of_apartments,
:number_of_semi_detached_houses,
:number_of_corner_houses,
:number_of_terraced_houses
].each do |name|
attribute name, Float, proportional: true
end
Expand Down
49 changes: 48 additions & 1 deletion lib/atlas/node_attributes/fever.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,19 @@ module NodeAttributes
# calculation.
class Fever
include ValueObject
include ActiveModel::Validations

attr_accessor :share_in_group

values do
attribute :type, Symbol
attribute :group, Symbol
attribute :curve, String
attribute :curve, Hash[Symbol => Float]
attribute :share_in_group, Float
attribute :present_share_in_demand, Float

# Which of the technology curves to use for producers
attribute :technology_curve_type, Symbol

# Deferrable demands.
attribute :defer_for, Integer
Expand All @@ -32,12 +40,51 @@ class Fever
attribute :capacity, Hash[Symbol => Float]
end

validates :type, inclusion: %i[consumer producer]

validates_presence_of :technology_curve_type,
if: ->(mod) { mod.type == :producer },
message: 'must be set for producers'

validates :technology_curve_type,
inclusion: { in: ->(mod) { mod.class.technology_types } }

validates_presence_of :present_share_in_demand,
if: ->(mod) { mod.type == :consumer },
message: 'must be set for consumers'

validates_presence_of :curve,
if: ->(mod) { mod.type == :consumer },
message: 'must be set for consumers'

validate :validate_curve_types

def to_hash
hash = super
hash.delete(:capacity) if hash[:capacity].empty?

hash
end

def self.technology_types
@technology_types ||= %i[tech_day_night tech_constant default].freeze
end

def validate_curve_types
return unless type == :consumer

unless curve.is_a?(Hash)
errors.add(
:curve,
'must consist of a definition for each technology curve type, e.g. curve.tech_day_night'
)
return
end

if curve.keys.any? { |key| !Fever.technology_types.include?(key) }
errors.add(:curve, "keys must be one of #{Fever.technology_types}")
end
end
end
end
end

0 comments on commit d5c84b5

Please sign in to comment.