Skip to content

Commit

Permalink
Reduced code duplication with some fixtures moved to conftest.py
Browse files Browse the repository at this point in the history
  • Loading branch information
genisott committed Nov 28, 2024
1 parent 6681273 commit 1619af9
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 124 deletions.
66 changes: 10 additions & 56 deletions tests/acceptance_tests/test_cigre_ampacity_cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,72 +7,26 @@
import linerate


@pytest.fixture
def drake_conductor_a():
return linerate.Conductor(
core_diameter=10.4e-3,
conductor_diameter=28.1e-3,
outer_layer_strand_diameter=4.4e-3,
emissivity=0.8,
solar_absorptivity=0.8,
temperature1=25,
temperature2=75,
resistance_at_temperature2=8.688e-5,
resistance_at_temperature1=7.283e-5,
aluminium_cross_section_area=float("nan"),
constant_magnetic_effect=1,
current_density_proportional_magnetic_effect=0,
max_magnetic_core_relative_resistance_increase=1,
)


@pytest.fixture
def example_weather_a():
return linerate.Weather(
air_temperature=40,
wind_direction=np.radians(30), # Conductor azimuth is 90, so 90 - 30 is 30
wind_speed=0.61,
clearness_ratio=1,
)


@pytest.fixture
def example_span_a(drake_conductor_a):
start_tower = linerate.Tower(latitude=30, longitude=0.0001, altitude=0)
end_tower = linerate.Tower(latitude=30, longitude=-0.0001, altitude=0)
return linerate.Span(
conductor=drake_conductor_a,
start_tower=start_tower,
end_tower=end_tower,
ground_albedo=0.1,
num_conductors=1,
)


@pytest.fixture
def example_model_a(example_span_a, example_weather_a):
return linerate.Cigre601(example_span_a, example_weather_a, np.datetime64("2016-06-10 11:00"))


def test_example_a_convective_cooling(example_model_a):
assert example_model_a.compute_convective_cooling(100, None) == approx(77.6, abs=0.5)
def test_example_a_convective_cooling(example_model_1_conductors):
assert example_model_1_conductors.compute_convective_cooling(100, None) == approx(77.6, abs=0.5)


def test_example_a_radiative_cooling(example_model_a):
assert example_model_a.compute_radiative_cooling(100, None) == approx(39.1, abs=0.5)
def test_example_a_radiative_cooling(example_model_1_conductors):
assert example_model_1_conductors.compute_radiative_cooling(100, None) == approx(39.1, abs=0.5)


def test_example_a_solar_heating(example_model_a):
assert example_model_a.compute_solar_heating(100, None) == approx(27.2, abs=0.5)
def test_example_a_solar_heating(example_model_1_conductors):
assert example_model_1_conductors.compute_solar_heating(100, None) == approx(27.2, abs=0.5)


def test_example_a_resistance(example_model_a):
assert example_model_a.compute_resistance(100, None) == approx(9.3905e-5, abs=0.0001e-5)
def test_example_a_resistance(example_model_1_conductors):
assert example_model_1_conductors.compute_resistance(100, None) == approx(9.3905e-5, abs=0.0001e-5)


def test_example_a_ampacity(example_model_a):
def test_example_a_ampacity(example_model_1_conductors):
# There are noticable roundoff errors in the report
assert example_model_a.compute_steady_state_ampacity(100, tolerance=1e-8) == approx(
assert example_model_1_conductors.compute_steady_state_ampacity(100, tolerance=1e-8) == approx(
976, abs=1.5
)

Expand Down
66 changes: 66 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,69 @@ def rng(random_seed):
import numpy as np

return np.random.default_rng(random_seed)


import numpy as np
import pytest
import linerate

@pytest.fixture
def drake_conductor_a():
return linerate.Conductor(
core_diameter=10.4e-3,
conductor_diameter=28.1e-3,
outer_layer_strand_diameter=4.4e-3,
emissivity=0.8,
solar_absorptivity=0.8,
temperature1=25,
temperature2=75,
resistance_at_temperature2=8.688e-5,
resistance_at_temperature1=7.283e-5,
aluminium_cross_section_area=float("nan"),
constant_magnetic_effect=1,
current_density_proportional_magnetic_effect=0,
max_magnetic_core_relative_resistance_increase=1,
)

@pytest.fixture
def example_weather_a():
return linerate.Weather(
air_temperature=40,
wind_direction=np.radians(30), # Conductor azimuth is 90, so 90 - 30 is 30
wind_speed=0.61,
clearness_ratio=1,
)

@pytest.fixture
def example_span_1_conductor(drake_conductor_a):
start_tower = linerate.Tower(latitude=30, longitude=0.0001, altitude=0)
end_tower = linerate.Tower(latitude=30, longitude=-0.0001, altitude=0)
return linerate.Span(
conductor=drake_conductor_a,
start_tower=start_tower,
end_tower=end_tower,
ground_albedo=0.1,
num_conductors=1,
)

@pytest.fixture
def example_span_2_conductors(drake_conductor_a):
start_tower = linerate.Tower(latitude=30, longitude=0.0001, altitude=0)
end_tower = linerate.Tower(latitude=30, longitude=-0.0001, altitude=0)
return linerate.Span(
conductor=drake_conductor_a,
start_tower=start_tower,
end_tower=end_tower,
ground_albedo=0.1,
num_conductors=2,
)

@pytest.fixture
def example_model_1_conductors(example_span_1_conductor, example_weather_a):
return linerate.Cigre601(example_span_1_conductor,
example_weather_a, np.datetime64("2016-06-10 11:00"))

@pytest.fixture
def example_model_2_conductors(example_span_2_conductors, example_weather_a):
return linerate.Cigre601(example_span_2_conductors,
example_weather_a, np.datetime64("2016-06-10 11:00"))
68 changes: 0 additions & 68 deletions tests/models/test_thermal_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,74 +5,6 @@

import linerate


@pytest.fixture
def drake_conductor_a():
return linerate.Conductor(
core_diameter=10.4e-3,
conductor_diameter=28.1e-3,
outer_layer_strand_diameter=4.4e-3,
emissivity=0.8,
solar_absorptivity=0.8,
temperature1=25,
temperature2=75,
resistance_at_temperature2=8.688e-5,
resistance_at_temperature1=7.283e-5,
aluminium_cross_section_area=float("nan"),
constant_magnetic_effect=1,
current_density_proportional_magnetic_effect=0,
max_magnetic_core_relative_resistance_increase=1,
)


@pytest.fixture
def example_weather_a():
return linerate.Weather(
air_temperature=40,
wind_direction=np.radians(30), # Conductor azimuth is 90, so 90 - 30 is 30
wind_speed=0.61,
clearness_ratio=1,
)


@pytest.fixture
def example_span_1_conductor(drake_conductor_a):
start_tower = linerate.Tower(latitude=30, longitude=0.0001, altitude=0)
end_tower = linerate.Tower(latitude=30, longitude=-0.0001, altitude=0)
return linerate.Span(
conductor=drake_conductor_a,
start_tower=start_tower,
end_tower=end_tower,
ground_albedo=0.1,
num_conductors=1,
)


@pytest.fixture
def example_span_2_conductors(drake_conductor_a):
start_tower = linerate.Tower(latitude=30, longitude=0.0001, altitude=0)
end_tower = linerate.Tower(latitude=30, longitude=-0.0001, altitude=0)
return linerate.Span(
conductor=drake_conductor_a,
start_tower=start_tower,
end_tower=end_tower,
ground_albedo=0.1,
num_conductors=2,
)


# Using Cigre601 model to test ThermalModel.compute_conductor_temperature
@pytest.fixture
def example_model_1_conductors(example_span_1_conductor, example_weather_a):
return linerate.Cigre601(example_span_1_conductor,
example_weather_a, np.datetime64("2016-06-10 11:00"))

@pytest.fixture
def example_model_2_conductors(example_span_2_conductors, example_weather_a):
return linerate.Cigre601(example_span_2_conductors,
example_weather_a, np.datetime64("2016-06-10 11:00"))


def test_compute_conductor_temperature(example_model_1_conductors, example_model_2_conductors):
# Check that the ampacity of a span with two conductors is divided
# when computing the conductor temperature.
Expand Down

0 comments on commit 1619af9

Please sign in to comment.