Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: derating analysis errors #1279

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
1 change: 1 addition & 0 deletions .github/workflows/on-issue-close.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:

jobs:
label_issue_closed:
name: Add Closed Label
runs-on: ubuntu-latest
steps:
- name: Add in progress label
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/on-pr-close.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ on:

jobs:
label_pr_closed:
name: Add closed label
runs-on: ubuntu-latest
steps:
- name: Add in progress label
- name: Add label
uses: weibullguy/labeler@master
with:
add-labels: "status: closed"
Expand Down
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ repos:
additional_dependencies: [tomli]
args: [--in-place, --config, ./pyproject.toml]
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: 'v0.0.265'
rev: 'v0.0.267'
hooks:
- id: ruff
args: [ --select, "PL", --select, "F" ]
Expand All @@ -39,7 +39,7 @@ repos:
additional_dependencies: [toml]
args: [--config, ./pyproject.toml]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.1.1
rev: v1.3.0
hooks:
- id: mypy
additional_dependencies: [types-python-dateutil]
Expand Down
7 changes: 5 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,8 @@ max-args = 6
non-cap = [
"milhdbk217f",
]
wrap-summaries = 88
wrap-descriptions = 88
black = true
style = "sphinx"

[tool.mypy]
allow_subclassing_any = true
Expand Down Expand Up @@ -295,6 +295,9 @@ ignore = [
'D213',
]

[tool.flake8]
max-line-length = 88

[tool.ruff]
select = ["PL",]
exclude = ["*.pyi"]
9 changes: 8 additions & 1 deletion src/ramstk/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,10 @@
_attributes = _record.get_attributes()
_values = ()
for _field in fields:
_values = _values + (_attributes[_field],)
if len(fields) == 1:
_values = _attributes[_field]

Check warning on line 267 in src/ramstk/__main__.py

View check run for this annotation

Codecov / codecov/patch

src/ramstk/__main__.py#L267

Added line #L267 was not covered by tests
else:
_values = _values + (_attributes[_field],)
config_list[_attributes[key_column]] = _values


Expand Down Expand Up @@ -689,6 +692,10 @@
"mild_maxt_limit",
],
)
_program_db.dic_views[

Check warning on line 695 in src/ramstk/__main__.py

View check run for this annotation

Codecov / codecov/patch

src/ramstk/__main__.py#L695

Added line #L695 was not covered by tests
"hardwarebom"
]._dic_stress_limits = user_configuration.RAMSTK_STRESS_LIMITS

do_load_configuration_list(
user_configuration.RAMSTK_USERS,
site_db,
Expand Down
12 changes: 10 additions & 2 deletions src/ramstk/analyses/derating/models/capacitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
# Standard Library Imports
from typing import Dict, List, Tuple

VARIABLE_IDX = 16
"""Subcategory index of first variable capacitor type."""


def do_derating_analysis(
environment_id: int,
Expand Down Expand Up @@ -64,15 +67,20 @@
if isinstance(_subcategory, dict):
_subcategory = _subcategory[kwargs["specification_id"]]

if subcategory_id < VARIABLE_IDX:
_stress_limits = stress_limits["fixed"]
else:
_stress_limits = stress_limits["variable"]

Check warning on line 73 in src/ramstk/analyses/derating/models/capacitor.py

View check run for this annotation

Codecov / codecov/patch

src/ramstk/analyses/derating/models/capacitor.py#L73

Added line #L73 was not covered by tests

_overstress, _reason = _do_check_temperature_limit(
kwargs["temperature_case"],
kwargs["temperature_rated_max"],
stress_limits[_subcategory]["temperature"][environment_id],
_stress_limits[_subcategory]["temperature"][environment_id],
)

_ostress, _rsn = _do_check_voltage_limit(
kwargs["voltage_ratio"],
stress_limits[_subcategory]["voltage"][environment_id],
_stress_limits[_subcategory]["voltage"][environment_id],
)
_overstress = _overstress or _ostress
_reason += _rsn
Expand Down
133 changes: 71 additions & 62 deletions src/ramstk/analyses/derating/models/semiconductor.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
# Copyright since 2017 Doyle "weibullguy" Rowland doyle.rowland <AT> reliaqual <DOT> com
"""Semiconductor derating analysis functions."""


# Standard Library Imports
import contextlib
from typing import Dict, List, Tuple


Expand All @@ -33,73 +35,80 @@ def do_derating_analysis(
"""
_overstress: int = 0
_reason: str = ""
_stress_limits: Dict = {}

with contextlib.suppress(KeyError):
_subcategory = {
1: "diode",
3: "transistor",
4: "transistor",
6: "transistor",
7: "transistor",
8: "transistor",
9: "transistor",
10: "thyristor",
}[subcategory_id]
_stress_limits = stress_limits[_subcategory]
with contextlib.suppress(KeyError):
_type = {
1: {
1: "general_purpose",
2: "general_purpose",
3: "power_rectifier",
4: "schottky",
5: "power_rectifier",
6: "suppressor",
7: "regulator",
8: "regulator",
},
3: "bjt",
4: "fet",
6: "bjt",
7: "bjt",
9: "fet",
}[subcategory_id]
if isinstance(_type, dict):
_type = _type[kwargs["type_id"]]
_stress_limits = _stress_limits[_type]
with contextlib.suppress(KeyError):
_quality = {
1: "jantx",
2: "jantx",
3: "military",
4: "commercial",
5: "commercial",
}[kwargs["quality_id"]]
_stress_limits = _stress_limits[_quality]
with contextlib.suppress(KeyError):
_overstress, _reason = _do_check_current_limit(
kwargs["current_ratio"],
_stress_limits["current"][environment_id],
)

_subcategory = {
1: "diode",
3: "transistor",
4: "transistor",
6: "transistor",
7: "transistor",
8: "transistor",
9: "transistor",
10: "thyristor",
}[subcategory_id]
_type = {
1: {
1: "general_purpose",
2: "general_purpose",
3: "power_rectifier",
4: "schottky",
5: "power_rectifier",
6: "suppressor",
7: "regulator",
8: "regulator",
},
3: "bjt",
4: "fet",
6: "bjt",
7: "bjt",
9: "fet",
}[subcategory_id]
if isinstance(_type, dict):
_type = _type[kwargs["type_id"]]

_quality = {
1: "jantx",
2: "jantx",
3: "military",
4: "commercial",
5: "commercial",
}[kwargs["quality_id"]]

_overstress, _reason = _do_check_current_limit(
kwargs["current_ratio"],
stress_limits[_subcategory][_type][_quality]["current"][environment_id],
)

if (
_subcategory == "diode" and _type in ["schottky,", "regulator", "suppressor"]
) or _subcategory == "transistor":
_ostress, _rsn = _do_check_power_limit(
kwargs["power_ratio"],
stress_limits[_subcategory][_type][_quality]["power"][environment_id],
if (
_subcategory == "diode"
and _type in ["schottky,", "regulator", "suppressor"]
) or _subcategory == "transistor":
_ostress, _rsn = _do_check_power_limit(
kwargs["power_ratio"],
_stress_limits["power"][environment_id],
)
_overstress = _overstress or _ostress
_reason += _rsn

_ostress, _rsn = _do_check_temperature_limit(
kwargs["temperature_junction"],
_stress_limits["temperature"][environment_id],
)
_overstress = _overstress or _ostress
_reason += _rsn

_ostress, _rsn = _do_check_temperature_limit(
kwargs["temperature_junction"],
stress_limits[_subcategory][_type][_quality]["temperature"][environment_id],
)
_overstress = _overstress or _ostress
_reason += _rsn

_ostress, _rsn = _do_check_voltage_limit(
kwargs["voltage_ratio"],
stress_limits[_subcategory][_type][_quality]["voltage"][environment_id],
)
_overstress = _overstress or _ostress
_reason += _rsn
_ostress, _rsn = _do_check_voltage_limit(
kwargs["voltage_ratio"],
_stress_limits["voltage"][environment_id],
)
_overstress = _overstress or _ostress
_reason += _rsn

return _overstress, _reason

Expand Down
26 changes: 16 additions & 10 deletions src/ramstk/analyses/milhdbk217f/models/inductor.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@
2: {1: 329.0, 2: 352.0, 3: 364.0, 4: 409.0},
}

ZERO = 0.0
VARIABLE_IDX = 2


def calculate_part_count(**attributes: Dict[str, Union[float, int, str]]) -> float:
"""Wrap get_part_count_lambda_b().
Expand Down Expand Up @@ -195,24 +198,27 @@ def calculate_part_stress(
)

_power_input = attributes["voltage_dc_operating"] * attributes["current_operating"]
if attributes["subcategory_id"] == 2 and attributes["specification_id"] == 2:
if (
attributes["subcategory_id"] == VARIABLE_IDX
and attributes["specification_id"] == 2 # noqa: PLR2004
):
attributes["temperature_rise"] = get_temperature_rise_spec_sheet(
int(attributes["page_number"])
)
elif attributes["power_operating"] > 0.0 and attributes["area"] > 0.0:
elif attributes["power_operating"] > ZERO and attributes["area"] > ZERO:
attributes["temperature_rise"] = calculate_temperature_rise_power_loss_surface(
attributes["power_operating"], attributes["area"]
)
elif attributes["power_operating"] > 0.0 and attributes["weight"] > 0.0:
elif attributes["power_operating"] > ZERO and attributes["weight"] > ZERO:
attributes["temperature_rise"] = calculate_temperature_rise_power_loss_weight(
attributes["power_operating"], attributes["weight"]
)
elif _power_input > 0.0 and attributes["weight"] > 0.0:
elif _power_input > ZERO and attributes["weight"] > ZERO:
attributes["temperature_rise"] = calculate_temperature_rise_input_power_weight(
_power_input, attributes["weight"]
)
else:
attributes["temperature_rise"] = 0.0
attributes["temperature_rise"] = ZERO
attributes["temperature_hot_spot"] = calculate_hot_spot_temperature(
attributes["temperature_active"], attributes["temperature_rise"]
)
Expand All @@ -225,7 +231,7 @@ def calculate_part_stress(
attributes["hazard_rate_active"] = (
attributes["lambda_b"] * attributes["piQ"] * attributes["piE"]
)
if attributes["subcategory_id"] == 2:
if attributes["subcategory_id"] == VARIABLE_IDX:
attributes["hazard_rate_active"] = (
attributes["hazard_rate_active"] * attributes["piC"]
)
Expand Down Expand Up @@ -439,12 +445,12 @@ def set_default_values(
:return: attributes; the updated attribute dict.
:rtype: dict
"""
if attributes["rated_temperature_max"] <= 0.0:
attributes["rated_temperature_max"] = _set_default_max_rated_temperature(
if attributes["temperature_rated_max"] <= ZERO:
attributes["temperature_rated_max"] = _set_default_max_rated_temperature(
attributes["subcategory_id"]
)

if attributes["temperature_rise"] <= 0.0:
if attributes["temperature_rise"] <= ZERO:
attributes["temperature_rise"] = _set_default_temperature_rise(
attributes["subcategory_id"],
attributes["family_id"],
Expand Down Expand Up @@ -476,4 +482,4 @@ def _set_default_temperature_rise(
:return: _temperature_rise
:rtype: float
"""
return 30.0 if subcategory_id == 1 and family_id == 3 else 10.0
return 30.0 if subcategory_id == 1 and family_id == 3 else 10.0 # noqa: PLR2004
Loading
Loading