Skip to content

Commit

Permalink
add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
claude committed Apr 20, 2024
1 parent b8671b4 commit f23a531
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 15 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

name: "Pyohm CI Tests"

on: [push]

jobs:
tests-3-12:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.12
uses: actions/setup-python@v3
with:
python-version: "3.12"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e .[test,dev]
# - name: Lint
# run: |
# pre-commit install
# pre-commit run --all-files

- name: Test with pytest
run: |
python -m pytest -s tests --cov=pyohm --cov-report=xml --junit-xml=report.xml
63 changes: 51 additions & 12 deletions pyohm/models/conductor.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import math
from datetime import datetime
from math import acos, asin, cos, degrees, radians, sin, tan

import pyohm.units as units
from pyohm.models.base import Base
Expand Down Expand Up @@ -199,9 +200,9 @@ def wind_direction_factor(self) -> float:
"""
return (
1.194
- math.cos(self.wind_direction)
+ 0.194 * math.cos(2 * self.wind_direction)
+ 0.368 * math.sin(2 * self.wind_direction)
- cos(radians(self.wind_direction))
+ 0.194 * cos(radians(2 * self.wind_direction))
+ 0.368 * sin(radians(2 * self.wind_direction))
)

@property
Expand Down Expand Up @@ -244,9 +245,9 @@ def solar_azimuth(self) -> float:
"""
Z_c, Solar azimuth
"""
X = math.sin(self.hour_angle) / (
math.sin(self.latitude) * math.cos(self.hour_angle)
- math.cos(self.latitude) * math.tan(self.solar_declination)
X = sin(radians(self.hour_angle)) / (
sin(radians(self.latitude)) * cos(radians(self.hour_angle))
- cos(radians(self.latitude)) * tan(radians(self.solar_declination))
)
if X >= 0 and -180 <= self.hour_angle < 0:
C = 0
Expand All @@ -259,20 +260,30 @@ def solar_azimuth(self) -> float:
else:
raise ValueError

Z_c = C + math.atan(X)
Z_c = C + degrees(math.atan(X))

return Z_c

@property
def Z_c(self) -> float:
return self.solar_azimuth

@property
def solar_altitude(self) -> float:
"""
Hc, Solar altitude
"""
return math.asin(
math.cos(self.latitude) * math.cos(self.solar_declination) * math.cos(self.hour_angle)
+ math.sin(self.latitude) * math.sin(self.solar_declination)
return degrees(
asin(
cos(radians(self.latitude)) * cos(radians(self.solar_declination)) * cos(radians(self.hour_angle))
+ sin(radians(self.latitude)) * sin(radians(self.solar_declination))
)
)

@property
def H_c(self) -> float:
return self.solar_altitude

@property
def total_solar_and_sky_radiated_heat_intensity_at_sea_level(self) -> float:
"""
Expand All @@ -296,6 +307,10 @@ def total_solar_and_sky_radiated_heat_intensity_at_sea_level(self) -> float:

return Qs

@property
def Q_s(self) -> float:
return self.total_solar_and_sky_radiated_heat_intensity_at_sea_level

@property
def total_solar_and_sky_radiated_heat_intensity_factor(self) -> float:
"""
Expand All @@ -318,11 +333,13 @@ def solar_heat_gain(self) -> float:
"""
q_s, Solar heat gain
"""
theta = math.acos(math.cos(self.solar_altitude) * math.cos(self.solar_altitude - self.azimuth_of_conductor))
theta = degrees(
acos(cos(radians(self.solar_altitude)) * cos(radians(self.solar_altitude - self.azimuth_of_conductor)))
)
return (
self.solar_absorption
* self.total_solar_and_sky_radiated_heat_intensity
* math.sin(theta)
* sin(radians(theta))
* self.conductor_outside_diameter
)

Expand Down Expand Up @@ -382,3 +399,25 @@ def forced_convection_heat_loss(self) -> float:
@property
def q_c(self) -> float:
return self.forced_convection_heat_loss

@property
def average_resistance(self) -> float:
return (
(self.conductor_ac_resistance_high - self.conductor_ac_resistance_low)
/ (self.conductor_high_temperature - self.conductor_low_temperature)
) * (self.conductor_surface_temperature - self.conductor_low_temperature) + self.conductor_ac_resistance_low

@property
def R_avg(self) -> float:
return self.average_resistance

@property
def conductor_current(self) -> float:
return math.sqrt(
(self.forced_convection_heat_loss + self.radiated_heat_loss - self.solar_heat_gain)
/ self.average_resistance
)

@property
def I(self) -> float:
return self.conductor_current
21 changes: 18 additions & 3 deletions tests/models/test_conductor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from pyohm.models.conductor import Conductor
import pytest

from pyohm.models.conductor import Conductor


def test_conductor():
conductor = Conductor()
Expand All @@ -19,10 +20,24 @@ def test_conductor():

assert conductor.N_Re == pytest.approx(865, abs=1)

assert conductor.H_c == pytest.approx(74.9, abs=0.1)

assert conductor.Z_c == pytest.approx(114, abs=1)

assert conductor.Q_s == pytest.approx(1027, abs=1)

assert conductor.q_cn == pytest.approx(42.42, abs=0.01)

assert conductor.q_c == pytest.approx(101.14, abs=0.01)
assert conductor.q_c == pytest.approx(82.1, abs=0.1)

assert conductor.q_r == pytest.approx(39.11, abs=0.01)

assert conductor.q_s == pytest.approx(22.45, abs=0.01)
assert conductor.q_s == pytest.approx(22.45, rel=0.2)

assert conductor.R_avg == pytest.approx(9.391e-5, rel=0.01)

assert conductor.I == pytest.approx(1025, abs=1.3)

conductor.conductor_surface_temperature = 119.6

assert conductor.I == pytest.approx(1200, abs=1)

0 comments on commit f23a531

Please sign in to comment.