Пример #1
0
    def setUp(self):
        self.env = BaseEnvironment()
        self.heat_storage = Mock(spec=SimulatedHeatStorage)
        self.power_meter = SimulatedPowerMeter(0, self.env)
        self.cu = SimulatedCogenerationUnit(1, self.env)
        self.cu.heat_storage = self.heat_storage
        self.cu.power_meter = self.power_meter

        self.cu.config['minimal_workload'] = 0.20
        self.cu.off_time = self.env.now - 1
        self.gas_input = 20.0
        self.cu.config['max_gas_input'] = self.gas_input
        self.electrical_efficiency = 0.25
        self.cu.config['electrical_efficiency'] = self.electrical_efficiency
        self.thermal_efficiency = 0.7
        self.cu.config['thermal_efficiency'] = self.thermal_efficiency
        self.total_hours_of_operation = 1
        self.cu.total_hours_of_operation = self.total_hours_of_operation
Пример #2
0
    def setUp(self):
        self.env = BaseEnvironment()
        self.heat_storage = Mock(spec=SimulatedHeatStorage)()
        self.power_meter = SimulatedPowerMeter(0, self.env)
        self.cu = SimulatedCogenerationUnit(1, self.env)
        self.cu.heat_storage = self.heat_storage
        self.cu.power_meter = self.power_meter

        self.max_gas_input = 19.0
        self.cu.config['max_gas_input'] = self.max_gas_input
        self.electrical_efficiency = 0.25
        self.cu.config['electrical_efficiency'] = self.electrical_efficiency
        self.thermal_efficiency = 0.6
        self.cu.config['thermal_efficiency'] = self.thermal_efficiency
        self.max_efficiency_loss = 0.10
        self.cu.max_efficiency_loss = self.max_efficiency_loss
        self.maintenance_interval_hours = 2000
        self.cu.config[
            'maintenance_interval_hours'] = self.maintenance_interval_hours
        self.minimal_workload = 0.40
        self.cu.config['minimal_workload'] = self.minimal_workload
        self.cu.config['minimal_off_time'] = 5.0 * 60.0
        self.off_time = self.env.now
        self.cu.off_time = self.off_time
        self.current_electrical_production = 0.0
        self.cu.current_electrical_production = self.current_electrical_production
        self.total_electrical_production = 0.0
        self.cu.total_electrical_production = self.total_electrical_production
        self.total_thermal_production = 0.0
        self.cu.total_thermal_production = self.total_thermal_production

        self.total_gas_consumption = 0.0
        self.cu.total_gas_consumption = self.total_gas_consumption

        self.cu.overwrite_workload = None
        self.cu.running = True

        self.heat_storage.input_energy = 0
        self.power_meter.energy_produced = 0
Пример #3
0
 def setUp(self):
     self.env = BaseEnvironment()
     self.power_meter = SimulatedPowerMeter(0, env=self.env)
Пример #4
0
class SimulatedPowerMeterTests(unittest.TestCase):
    def setUp(self):
        self.env = BaseEnvironment()
        self.power_meter = SimulatedPowerMeter(0, env=self.env)

    def test_power_meter_creation(self):
        self.assertEqual(self.power_meter.total_fed_in_electricity, 0)
        self.assertEqual(self.power_meter.total_purchased, 0)
        self.assertEqual(self.power_meter.energy_produced, 0)
        self.assertEqual(self.power_meter.energy_consumed, 0)

    def test_add_energy(self):
        self.power_meter.energy_produced = 0
        for i in range(20):
            self.power_meter.add_energy(0.5)

        self.assertEqual(self.power_meter.energy_produced, 20 * 0.5)

    def test_consume_energy(self):
        self.power_meter.energy_consumed = 0
        self.initialize_purchased_and_fed_in()

        for i in range(20):
            self.power_meter.consume_energy(0.5)

        self.assertEqual(self.power_meter.energy_consumed, 20 * 0.5)
        self.assertEqual(self.power_meter.total_purchased, 0)
        self.assertEqual(self.power_meter.total_fed_in_electricity, 0)

    def test_get_reward(self):
        self.power_meter.total_fed_in_electricity = 25

        self.assertEqual(self.power_meter.get_reward(), 25 * electrical_feed_in_reward_per_kwh)

    def test_get_costs(self):
        self.power_meter.total_purchased = 25

        self.assertEqual(self.power_meter.get_costs(), 25 * electrical_costs_per_kwh)

    def test_step_resets_energies(self):
        self.power_meter.energy_consumed = 3
        self.power_meter.energy_produced = 5

        self.power_meter.step()

        self.assertEqual(self.power_meter.energy_consumed, 0)
        self.assertEqual(self.power_meter.energy_produced, 0)

    def test_step_when_deficit_of_energy(self):
        self.power_meter.energy_consumed = 5
        self.power_meter.energy_produced = 3
        self.initialize_purchased_and_fed_in()

        self.power_meter.step()

        self.assertEqual(self.power_meter.total_purchased, 5 - 3)
        self.assertEqual(self.power_meter.total_fed_in_electricity, 0)

    def test_step_when_excess_of_energy(self):
        self.power_meter.energy_consumed = 3
        self.power_meter.energy_produced = 5
        self.initialize_purchased_and_fed_in()

        self.power_meter.step()

        self.assertEqual(self.power_meter.total_fed_in_electricity, 5 - 3)
        self.assertEqual(self.power_meter.total_purchased, 0)

    def test_step_no_energy_diff(self):
        self.power_meter.energy_consumed = 1
        self.power_meter.energy_produced = 1
        self.initialize_purchased_and_fed_in()

        self.power_meter.step()

        self.assertEqual(self.power_meter.total_fed_in_electricity, 0)
        self.assertEqual(self.power_meter.total_purchased, 0)

    def initialize_purchased_and_fed_in(self):
        self.power_meter.total_purchased = 0
        self.power_meter.total_fed_in_electricity = 0
Пример #5
0
 def setUp(self):
     self.env = BaseEnvironment()
     self.power_meter = SimulatedPowerMeter(0, env=self.env)
Пример #6
0
class SimulatedPowerMeterTests(unittest.TestCase):
    def setUp(self):
        self.env = BaseEnvironment()
        self.power_meter = SimulatedPowerMeter(0, env=self.env)

    def test_power_meter_creation(self):
        self.assertEqual(self.power_meter.total_fed_in_electricity, 0)
        self.assertEqual(self.power_meter.total_purchased, 0)
        self.assertEqual(self.power_meter.energy_produced, 0)
        self.assertEqual(self.power_meter.energy_consumed, 0)

    def test_add_energy(self):
        self.power_meter.energy_produced = 0
        for i in range(20):
            self.power_meter.add_energy(0.5)

        self.assertEqual(self.power_meter.energy_produced, 20 * 0.5)

    def test_consume_energy(self):
        self.power_meter.energy_consumed = 0
        self.initialize_purchased_and_fed_in()

        for i in range(20):
            self.power_meter.consume_energy(0.5)

        self.assertEqual(self.power_meter.energy_consumed, 20 * 0.5)
        self.assertEqual(self.power_meter.total_purchased, 0)
        self.assertEqual(self.power_meter.total_fed_in_electricity, 0)

    def test_get_reward(self):
        self.power_meter.total_fed_in_electricity = 25

        self.assertEqual(self.power_meter.get_reward(),
                         25 * electrical_feed_in_reward_per_kwh)

    def test_get_costs(self):
        self.power_meter.total_purchased = 25

        self.assertEqual(self.power_meter.get_costs(),
                         25 * electrical_costs_per_kwh)

    def test_step_resets_energies(self):
        self.power_meter.energy_consumed = 3
        self.power_meter.energy_produced = 5

        self.power_meter.step()

        self.assertEqual(self.power_meter.energy_consumed, 0)
        self.assertEqual(self.power_meter.energy_produced, 0)

    def test_step_when_deficit_of_energy(self):
        self.power_meter.energy_consumed = 5
        self.power_meter.energy_produced = 3
        self.initialize_purchased_and_fed_in()

        self.power_meter.step()

        self.assertEqual(self.power_meter.total_purchased, 5 - 3)
        self.assertEqual(self.power_meter.total_fed_in_electricity, 0)

    def test_step_when_excess_of_energy(self):
        self.power_meter.energy_consumed = 3
        self.power_meter.energy_produced = 5
        self.initialize_purchased_and_fed_in()

        self.power_meter.step()

        self.assertEqual(self.power_meter.total_fed_in_electricity, 5 - 3)
        self.assertEqual(self.power_meter.total_purchased, 0)

    def test_step_no_energy_diff(self):
        self.power_meter.energy_consumed = 1
        self.power_meter.energy_produced = 1
        self.initialize_purchased_and_fed_in()

        self.power_meter.step()

        self.assertEqual(self.power_meter.total_fed_in_electricity, 0)
        self.assertEqual(self.power_meter.total_purchased, 0)

    def initialize_purchased_and_fed_in(self):
        self.power_meter.total_purchased = 0
        self.power_meter.total_fed_in_electricity = 0