Skip to content

Commit 418d6d0

Browse files
kurt-rheecwhanseechedey-lskandersolarAdamRJensen
authored
Add a simple transformer effficiency model to pvlib (#2053)
* wrote a simple transformer efficiency model * edited documentation to include latex, unsure if it will compile correctly in docs. * removed "if __main__" * removed "if __main__" * changed whatsnew rst * updated to be in compliance with Flake8 * Update pvlib/transformer.py Co-authored-by: Cliff Hansen <[email protected]> * Update pvlib/transformer.py Co-authored-by: Cliff Hansen <[email protected]> * Update pvlib/transformer.py Co-authored-by: Cliff Hansen <[email protected]> * + added transformer to index.rst + added transformer.rst to pvlib/docs/source/sphinx/reference * Update docs/sphinx/source/reference/transformer.rst Co-authored-by: Cliff Hansen <[email protected]> * Update pvlib/transformer.py Co-authored-by: Cliff Hansen <[email protected]> * updated names of loss values and changed to [unitless] * Update pvlib/transformer.py Co-authored-by: Cliff Hansen <[email protected]> * Update pvlib/transformer.py Co-authored-by: Cliff Hansen <[email protected]> * Update pvlib/transformer.py Co-authored-by: Cliff Hansen <[email protected]> * Update pvlib/transformer.py Co-authored-by: Cliff Hansen <[email protected]> * Update pvlib/transformer.py Co-authored-by: Cliff Hansen <[email protected]> * Update pvlib/transformer.py Co-authored-by: Cliff Hansen <[email protected]> * Update pvlib/transformer.py Co-authored-by: Cliff Hansen <[email protected]> * Update pvlib/transformer.py Co-authored-by: Cliff Hansen <[email protected]> * forgot to update arguments in test function * updated formatting of docstring * Update pvlib/transformer.py Co-authored-by: Cliff Hansen <[email protected]> * Update pvlib/transformer.py Co-authored-by: Cliff Hansen <[email protected]> * Update pvlib/transformer.py Co-authored-by: Cliff Hansen <[email protected]> * Update pvlib/transformer.py Co-authored-by: Cliff Hansen <[email protected]> * Update pvlib/transformer.py Co-authored-by: Cliff Hansen <[email protected]> * adding space between equations in docstring * fixing flake8 linting * removing whitespace * Update docs/sphinx/source/reference/transformer.rst Co-authored-by: Echedey Luis <[email protected]> * Update pvlib/transformer.py Co-authored-by: Echedey Luis <[email protected]> * Update pvlib/transformer.py Co-authored-by: Cliff Hansen <[email protected]> * Update pvlib/transformer.py Co-authored-by: Echedey Luis <[email protected]> * Update pvlib/transformer.py Co-authored-by: Echedey Luis <[email protected]> * Update pvlib/transformer.py Co-authored-by: Echedey Luis <[email protected]> * Update docs/sphinx/source/whatsnew/v0.11.0.rst Co-authored-by: Echedey Luis <[email protected]> * Update pvlib/transformer.py Co-authored-by: Echedey Luis <[email protected]> * Update pvlib/tests/test_transformer.py Co-authored-by: Echedey Luis <[email protected]> * Update pvlib/transformer.py Co-authored-by: Echedey Luis <[email protected]> * Update pvlib/transformer.py Co-authored-by: Kevin Anderson <[email protected]> * Update pvlib/transformer.py Co-authored-by: Kevin Anderson <[email protected]> * Update docs/sphinx/source/whatsnew/v0.11.0.rst Co-authored-by: Adam R. Jensen <[email protected]> * Update pvlib/transformer.py Co-authored-by: Echedey Luis <[email protected]> * Update pvlib/transformer.py Co-authored-by: Echedey Luis <[email protected]> * clean up derivation and docstring * change code calculations to match docstring * test recovery of no-load and full-load values * bit more cleanup * typo * Apply suggestions from code review Co-authored-by: Cliff Hansen <[email protected]> * Apply suggestions from code review --------- Co-authored-by: Cliff Hansen <[email protected]> Co-authored-by: Echedey Luis <[email protected]> Co-authored-by: Kevin Anderson <[email protected]> Co-authored-by: Adam R. Jensen <[email protected]>
1 parent 1eecaa3 commit 418d6d0

File tree

5 files changed

+192
-0
lines changed

5 files changed

+192
-0
lines changed

docs/sphinx/source/reference/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ API reference
2020
bifacial
2121
scaling
2222
location
23+
transformer
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.. currentmodule:: pvlib
2+
3+
Transformer losses
4+
==================
5+
6+
Methods to account for losses in transformers
7+
8+
.. autosummary::
9+
:toctree: generated/
10+
11+
transformer.simple_efficiency

docs/sphinx/source/whatsnew/v0.11.0.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ Deprecations
3333

3434
Enhancements
3535
~~~~~~~~~~~~
36+
* Add a simple transformer efficiency model :py:func:`pvlib.transformer.simple_efficiency`.
37+
(:issue:`1269`, :pull:`2053`)
3638
* Add function :py:func:`pvlib.shading.shaded_fraction1d`, to calculate the
3739
shade perpendicular to ``axis_azimuth``. The function is applicable to both
3840
fixed-tilt and one-axis tracking systems.
@@ -70,6 +72,7 @@ Requirements
7072
Contributors
7173
~~~~~~~~~~~~
7274
* Cliff Hansen (:ghuser:`cwhanse`)
75+
* Kurt Rhee (:ghuser:`kurt-rhee`)
7376
* Mark Mikofski (:ghuser:`mikofski`)
7477
* Siddharth Kaul (:ghuser:`k10blogger`)
7578
* Ioannis Sifnaios (:ghuser:`IoannisSifnaios`)

pvlib/tests/test_transformer.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import pandas as pd
2+
3+
from numpy.testing import assert_allclose
4+
5+
from pvlib import transformer
6+
7+
8+
def test_simple_efficiency():
9+
10+
# define test inputs
11+
input_power = pd.Series([
12+
-800.0,
13+
436016.609823837,
14+
1511820.16603752,
15+
1580687.44677249,
16+
1616441.79660171
17+
])
18+
no_load_loss = 0.002
19+
load_loss = 0.007
20+
transformer_rating = 2750000
21+
22+
# define expected test results
23+
expected_output_power = pd.Series([
24+
-6300.10103234071,
25+
430045.854892526,
26+
1500588.39919874,
27+
1568921.77089526,
28+
1604389.62839879
29+
])
30+
31+
# run test function with test inputs
32+
calculated_output_power = transformer.simple_efficiency(
33+
input_power=input_power,
34+
no_load_loss=no_load_loss,
35+
load_loss=load_loss,
36+
transformer_rating=transformer_rating
37+
)
38+
39+
# determine if expected results are obtained
40+
assert_allclose(calculated_output_power, expected_output_power)
41+
42+
43+
def test_simple_efficiency_known_values():
44+
no_load_loss = 0.005
45+
load_loss = 0.01
46+
rating = 1000
47+
args = (no_load_loss, load_loss, rating)
48+
49+
# verify correct behavior at no-load condition
50+
assert_allclose(
51+
transformer.simple_efficiency(no_load_loss*rating, *args),
52+
0.0
53+
)
54+
55+
# verify correct behavior at rated condition
56+
assert_allclose(
57+
transformer.simple_efficiency(rating*(1 + no_load_loss + load_loss),
58+
*args),
59+
rating,
60+
)

pvlib/transformer.py

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
"""
2+
This module contains functions for transformer modeling.
3+
4+
Transformer models calculate AC power output and losses at a given input power.
5+
"""
6+
7+
8+
def simple_efficiency(
9+
input_power, no_load_loss, load_loss, transformer_rating
10+
):
11+
r'''
12+
Calculate the power at the output terminal of the transformer
13+
after taking into account efficiency using a simple calculation.
14+
15+
The equation used in this function can be derived from [1]_.
16+
17+
For a zero input power, the output power will be negative.
18+
This means the transformer will consume energy from the grid at night if
19+
it stays connected (due to the parallel impedance in the equivalent
20+
circuit).
21+
If the input power is negative, the output power will be even more
22+
negative; so the model can be used bidirectionally when drawing
23+
energy from the grid.
24+
25+
Parameters
26+
----------
27+
input_power : numeric
28+
The real AC power input to the transformer. [W]
29+
30+
no_load_loss : numeric
31+
The constant losses experienced by a transformer, even
32+
when the transformer is not under load. Fraction of transformer rating,
33+
value from 0 to 1. [unitless]
34+
35+
load_loss: numeric
36+
The load dependent losses experienced by the transformer.
37+
Fraction of transformer rating, value from 0 to 1. [unitless]
38+
39+
transformer_rating: numeric
40+
The nominal output power of the transformer. [VA]
41+
42+
Returns
43+
-------
44+
output_power : numeric
45+
Real AC power output. [W]
46+
47+
Notes
48+
-------
49+
First, assume that the load loss :math:`L_{load}` (as a fraction of rated power
50+
:math:`P_{nom}`) is proportional to the square of output power:
51+
52+
.. math::
53+
54+
L_{load}(P_{out}) &= L_{load}(P_{rated}) \times (P_{out} / P_{nom})^2
55+
56+
&= L_{full, load} \times (P_{out} / P_{nom})^2
57+
58+
Total loss is the constant no-load loss plus the variable load loss:
59+
60+
.. math::
61+
62+
L_{total}(P_{out}) &= L_{no, load} + L_{load}(P_{out})
63+
64+
&= L_{no, load} + L_{full, load} \times (P_{out} / P_{nom})^2
65+
66+
67+
By conservation of energy, total loss is the difference between input and
68+
output power:
69+
70+
.. math::
71+
72+
\frac{P_{in}}{P_{nom}} &= \frac{P_{out}}{P_{nom}} + L_{total}(P_{out})
73+
74+
&= \frac{P_{out}}{P_{nom}} + L_{no, load} + L_{full, load} \times (P_{out} / P_{nom})^2
75+
76+
Now use the quadratic formula to solve for :math:`P_{out}` as a function of
77+
:math:`P_{in}`.
78+
79+
.. math::
80+
81+
\frac{P_{out}}{P_{nom}} &= \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}
82+
83+
a &= L_{full, load}
84+
85+
b &= 1
86+
87+
c &= L_{no, load} - P_{in} / P_{nom}
88+
89+
Therefore:
90+
91+
.. math::
92+
93+
P_{out} = P_{nom} \frac{-1 \pm \sqrt{1 - 4 L_{full, load}
94+
95+
\times (L_{no, load} - P_{in}/P_{nom})}}{2 L_{full, load}}
96+
97+
The positive root should be chosen, so that the output power is
98+
positive.
99+
100+
101+
References
102+
----------
103+
.. [1] Central Station Engineers of the Westinghouse Electric Corporation,
104+
"Electrical Transmission and Distribution Reference Book" 4th Edition.
105+
pg. 101.
106+
''' # noqa: E501
107+
108+
input_power_normalized = input_power / transformer_rating
109+
110+
a = load_loss
111+
b = 1
112+
c = no_load_loss - input_power_normalized
113+
114+
output_power_normalized = (-b + (b**2 - 4*a*c)**0.5) / (2 * a)
115+
116+
output_power = output_power_normalized * transformer_rating
117+
return output_power

0 commit comments

Comments
 (0)