Skip to content

Commit

Permalink
feat: add power limits to all components (pi, po, pl)
Browse files Browse the repository at this point in the history
  • Loading branch information
geddy11 committed May 27, 2024
1 parent 320fc09 commit ce36738
Show file tree
Hide file tree
Showing 13 changed files with 223 additions and 92 deletions.
193 changes: 122 additions & 71 deletions docs/nb/Component files.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/nb/Sensor daisy chain.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@
"metadata": {},
"outputs": [],
"source": [
"diode_vdrop = {\"vi\": [48], \"io\":[1e-3, 1e-2, 0.1, 1, 5], \"vdrop\":[[.25, .325, 0.4, 0.65, 1.1]]}\n",
"diode_vdrop = {\"vi\": [48], \"io\":[1e-3, 1e-2, 0.1, 1, 2, 3, 5], \"vdrop\":[[.25, .325, 0.4, 0.65, 0.8, 0.9, 1.1]]}\n",
"buck_eff = {\"vi\": [48, 36, 24, 12], \"io\": [1e-3, 10e-3, 0.1, 0.2, 0.3], \n",
" \"eff\":[[0.61,0.63,0.66,0.68,0.69],[0.63,0.65,0.68,0.705,0.72],[0.66,.68,0.72,0.73,0.74],[0.7,0.72,0.76,0.78,0.77]]}"
]
Expand Down
75 changes: 62 additions & 13 deletions src/sysloss/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ class _ComponentTypes(Enum):
"vo": [0.0, MAX_DEFAULT],
"ii": [0.0, MAX_DEFAULT],
"io": [0.0, MAX_DEFAULT],
"pi": [0.0, MAX_DEFAULT],
"po": [0.0, MAX_DEFAULT],
"pl": [0.0, MAX_DEFAULT],
}


Expand Down Expand Up @@ -181,7 +184,7 @@ class Source:
rs : float, optional
Source resistance., by default 0.0
limits : dict, optional
Voltage and current limits., by default LIMITS_DEFAULT
Voltage, current and power limits., by default LIMITS_DEFAULT. The following limits apply: io, po, pl.
"""

@property
Expand Down Expand Up @@ -259,7 +262,9 @@ def _solv_pwr_loss(self, vi, vo, ii, io, phase, phase_conf={}):

def _solv_get_warns(self, vi, vo, ii, io, phase, phase_conf={}):
"""Check limits"""
return _get_warns(self._limits, {"ii": ii, "io": io})
return _get_warns(
self._limits, {"io": io, "po": vo * io, "pl": self._params["rs"] * io * io}
)

def _get_params(self, pdict):
"""Return dict with component parameters"""
Expand All @@ -279,7 +284,7 @@ class PLoad:
pwr : float
Load power (W).
limits : dict, optional
Voltage and current limits., by default LIMITS_DEFAULT
Voltage, current and power limits., by default LIMITS_DEFAULT. The following limits apply: vi, ii
pwrs : float, optional
Load sleep power (W), by default PWRS_DEFAULT
"""
Expand Down Expand Up @@ -382,7 +387,7 @@ class ILoad(PLoad):
ii : float
Load current (A).
limits : dict, optional
Voltage and current limits., by default LIMITS_DEFAULT
Voltage, current and power limits., by default LIMITS_DEFAULT. The following limits apply: vi, pi
iis : float, optional
Load sleep current (A), by default PWRS_DEFAULT
"""
Expand Down Expand Up @@ -436,6 +441,13 @@ def _solv_inp_curr(self, vi, vo, io, phase, phase_conf={}):

return abs(i)

def _solv_get_warns(self, vi, vo, ii, io, phase, phase_conf={}):
"""Check limits"""
if phase_conf and phase != "":
if phase not in phase_conf:
return ""
return _get_warns(self._limits, {"vi": vi, "pi": vi * ii})

def _get_params(self, pdict):
"""Return dict with component parameters"""
ret = pdict
Expand All @@ -454,7 +466,7 @@ class RLoad(PLoad):
rs : float
Load resistance (ohm).
limits : dict, optional
Voltage and current limits., by default LIMITS_DEFAULT
Voltage, current and power limits., by default LIMITS_DEFAULT. The following limits apply: vi, ii, pi
"""

def __init__(
Expand Down Expand Up @@ -500,6 +512,13 @@ def _solv_inp_curr(self, vi, vo, io, phase, phase_conf={}):
r = phase_conf[phase]
return abs(vi) / r

def _solv_get_warns(self, vi, vo, ii, io, phase, phase_conf={}):
"""Check limits"""
if phase_conf and phase != "":
if phase not in phase_conf:
return ""
return _get_warns(self._limits, {"vi": vi, "ii": ii, "pi": vi * ii})

def _get_params(self, pdict):
"""Return dict with component parameters"""
ret = pdict
Expand All @@ -519,7 +538,7 @@ class RLoss:
rs : float
Loss resistance (ohm).
limits : dict, optional
Voltage and current limits., by default LIMITS_DEFAULT
Voltage, current and power limits., by default LIMITS_DEFAULT. The following limits apply: vi, vo, ii, io, pi, po, pl
"""

@property
Expand Down Expand Up @@ -601,7 +620,18 @@ def _solv_pwr_loss(self, vi, vo, ii, io, phase, phase_conf={}):

def _solv_get_warns(self, vi, vo, ii, io, phase, phase_conf={}):
"""Check limits"""
return _get_warns(self._limits, {"vi": vi, "vo": vo, "ii": ii, "io": io})
return _get_warns(
self._limits,
{
"vi": vi,
"vo": vo,
"ii": ii,
"io": io,
"pi": vi * ii,
"po": vo * io,
"pl": vi * ii - vo * io,
},
)

def _get_params(self, pdict):
"""Return dict with component parameters"""
Expand All @@ -622,7 +652,7 @@ class VLoss:
vdrop : float | dict
Voltage drop (V), a constant value (float) or interpolation data (dict).
limits : dict, optional
Voltage and current limits., by default LIMITS_DEFAULT
Voltage, current and power limits., by default LIMITS_DEFAULT. The following limits apply: vi, vo, ii, io, pi, po, pl
"""

@property
Expand Down Expand Up @@ -719,7 +749,18 @@ def _solv_pwr_loss(self, vi, vo, ii, io, phase, phase_conf={}):

def _solv_get_warns(self, vi, vo, ii, io, phase, phase_conf={}):
"""Check limits"""
return _get_warns(self._limits, {"vi": vi, "vo": vo, "ii": ii, "io": io})
return _get_warns(
self._limits,
{
"vi": vi,
"vo": vo,
"ii": ii,
"io": io,
"pi": vi * ii,
"po": vo * io,
"pl": vi * ii - vo * io,
},
)

def _get_annot(self):
"""Get interpolation figure annotations in format [xlabel, ylabel, title]"""
Expand Down Expand Up @@ -759,7 +800,7 @@ class Converter:
iq : float, optional
Quiescent (no-load) current (A)., by default 0.0
limits : dict, optional
Voltage and current limits., by default LIMITS_DEFAULT
Voltage, current and power limits., by default LIMITS_DEFAULT. The following limits apply: vi, vo, ii, io, pi, po, pl
iis : float, optional
Sleep (shut-down) current (A), by default 0.0
Expand Down Expand Up @@ -900,7 +941,11 @@ def _solv_get_warns(self, vi, vo, ii, io, phase, phase_conf=[]):
if phase_conf:
if phase not in phase_conf:
return ""
return _get_warns(self._limits, {"vi": vi, "vo": vo, "ii": ii, "io": io})
pi, pl, _ = self._solv_pwr_loss(vi, vo, ii, io, phase, phase_conf=[])
return _get_warns(
self._limits,
{"vi": vi, "vo": vo, "ii": ii, "io": io, "pi": pi, "po": pi - pl, "pl": pl},
)

def _get_annot(self):
"""Get interpolation figure annotations in format [xlabel, ylabel, title]"""
Expand Down Expand Up @@ -947,7 +992,7 @@ class LinReg:
iq : float | dict, optional
Ground current (A)., by default 0.0
limits : dict, optional
Voltage and current limits., by default LIMITS_DEFAULT
Voltage, current and power limits., by default LIMITS_DEFAULT. The following limits apply: vi, vo, ii, io, pi, po, pl
iis : float, optional
Sleep (shut-down) current (A), by default 0.0
Expand Down Expand Up @@ -1087,7 +1132,11 @@ def _solv_get_warns(self, vi, vo, ii, io, phase, phase_conf=[]):
if phase_conf:
if phase not in phase_conf:
return ""
return _get_warns(self._limits, {"vi": vi, "vo": vo, "ii": ii, "io": io})
pi, pl, _ = self._solv_pwr_loss(vi, vo, ii, io, phase, phase_conf=[])
return _get_warns(
self._limits,
{"vi": vi, "vo": vo, "ii": ii, "io": io, "pi": pi, "po": pi - pl, "pl": pl},
)

def _get_annot(self):
"""Get interpolation figure annotations in format [xlabel, ylabel, title]"""
Expand Down
17 changes: 12 additions & 5 deletions src/sysloss/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,7 @@ def params(self, limits: bool = False) -> pd.DataFrame:
self._rel_update()
names, typ, parent, vo, vdrop = [], [], [], [], []
iq, rs, eff, ii, pwr, iis = [], [], [], [], [], []
lii, lio, lvi, lvo, pwrs = [], [], [], [], []
lii, lio, lvi, lvo, lpi, lpo, lpl, pwrs = [], [], [], [], [], [], [], []
domain, dname = [], "none"
src_cnt = 0

Expand Down Expand Up @@ -903,6 +903,9 @@ def params(self, limits: bool = False) -> pd.DataFrame:
lio += [_get_opt(self._g[n]._limits, "io", LIMITS_DEFAULT["io"])]
lvi += [_get_opt(self._g[n]._limits, "vi", LIMITS_DEFAULT["vi"])]
lvo += [_get_opt(self._g[n]._limits, "vo", LIMITS_DEFAULT["vo"])]
lpi += [_get_opt(self._g[n]._limits, "pi", LIMITS_DEFAULT["pi"])]
lpo += [_get_opt(self._g[n]._limits, "po", LIMITS_DEFAULT["po"])]
lpl += [_get_opt(self._g[n]._limits, "pl", LIMITS_DEFAULT["pl"])]
# report
res = {}
res["Component"] = names
Expand All @@ -920,10 +923,14 @@ def params(self, limits: bool = False) -> pd.DataFrame:
res["pwr (W)"] = pwr
res["pwrs (W)"] = pwrs
if limits:
res["vi limits (V)"] = lvi
res["vo limits (V)"] = lvo
res["ii limits (A)"] = lii
res["io limits (A)"] = lio
res["vi limit (V)"] = lvi
res["vo limit (V)"] = lvo
res["ii limit (A)"] = lii
res["io limit (A)"] = lio
res["pi limit (A)"] = lpi
res["po limit (A)"] = lpo
res["pl limit (A)"] = lpl

return pd.DataFrame(res)

def set_sys_phases(self, phases: dict):
Expand Down
3 changes: 3 additions & 0 deletions tests/data/converter.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ vi = [ 0.0, 1000000.0,]
vo = [ 0.0, 1000000.0,]
ii = [ 0.0, 1000000.0,]
io = [ 0.0, 1000000.0,]
pi = [ 0.0, 1000000.0,]
po = [ 0.0, 1000000.0,]
pl = [ 0.0, 1000000.0,]
3 changes: 3 additions & 0 deletions tests/data/iload.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ vi = [ 0.0, 1000000.0,]
vo = [ 0.0, 1000000.0,]
ii = [ 0.0, 1000000.0,]
io = [ 0.0, 1000000.0,]
pi = [ 0.0, 1000000.0,]
po = [ 0.0, 1000000.0,]
pl = [ 0.0, 1000000.0,]
3 changes: 3 additions & 0 deletions tests/data/linreg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ vi = [ 0.0, 1000000.0,]
vo = [ 0.0, 1000000.0,]
ii = [ 0.0, 1000000.0,]
io = [ 0.0, 1000000.0,]
pi = [ 0.0, 1000000.0,]
po = [ 0.0, 1000000.0,]
pl = [ 0.0, 1000000.0,]
3 changes: 3 additions & 0 deletions tests/data/pload.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ vi = [ 0.0, 1000000.0,]
vo = [ 0.0, 1000000.0,]
ii = [ 0.0, 1000000.0,]
io = [ 0.0, 1000000.0,]
pi = [ 0.0, 1000000.0,]
po = [ 0.0, 1000000.0,]
pl = [ 0.0, 1000000.0,]
3 changes: 3 additions & 0 deletions tests/data/rload.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ vi = [ 0.0, 1000000.0,]
vo = [ 0.0, 1000000.0,]
ii = [ 0.0, 1000000.0,]
io = [ 0.0, 1000000.0,]
pi = [ 0.0, 1000000.0,]
po = [ 0.0, 1000000.0,]
pl = [ 0.0, 1000000.0,]
3 changes: 3 additions & 0 deletions tests/data/rloss.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ vi = [ 0.0, 1000000.0,]
vo = [ 0.0, 1000000.0,]
ii = [ 0.0, 1000000.0,]
io = [ 0.0, 1000000.0,]
pi = [ 0.0, 1000000.0,]
po = [ 0.0, 1000000.0,]
pl = [ 0.0, 1000000.0,]
3 changes: 3 additions & 0 deletions tests/data/source.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ vi = [ 0.0, 1000000.0,]
vo = [ 0.0, 1000000.0,]
ii = [ 0.0, 1000000.0,]
io = [ 0.0, 1000000.0,]
pi = [ 0.0, 1000000.0,]
po = [ 0.0, 1000000.0,]
pl = [ 0.0, 1000000.0,]
3 changes: 3 additions & 0 deletions tests/data/vloss.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ vi = [ 0.0, 1000000.0,]
vo = [ 0.0, 1000000.0,]
ii = [ 0.0, 1000000.0,]
io = [ 0.0, 1000000.0,]
pi = [ 0.0, 1000000.0,]
po = [ 0.0, 1000000.0,]
pl = [ 0.0, 1000000.0,]
4 changes: 2 additions & 2 deletions tests/unit/test_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def test_case12():
"6V",
vo=6.0,
limits={
"ii": [0.0, 0.101],
"io": [0.0, 0.101],
},
),
)
Expand All @@ -251,7 +251,7 @@ def test_case12():
def test_case13():
"""Multi-source"""
case13 = System("Case13 system", Source("3.3V", vo=3.3))
case13.add_source(Source("12V", vo=12, limits={"ii": [0, 1e-3]}))
case13.add_source(Source("12V", vo=12, limits={"io": [0, 1e-3]}))
case13.add_comp("3.3V", comp=PLoad("MCU", pwr=0.2))
case13.add_comp("12V", comp=PLoad("Test", pwr=1.5))
with pytest.raises(ValueError):
Expand Down

0 comments on commit ce36738

Please sign in to comment.