Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions bluemira/balance_of_plant/steady_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,14 +547,9 @@ def build(self):
p_hcd = self.params.P_hcd_ss.value
p_hcd_el = self.params.P_hcd_ss_el.value
p_separatrix = p_charged - p_radiation + p_hcd
(
p_n_blk,
p_n_div,
p_n_vv,
p_n_aux,
p_nrgm,
p_blk_decay,
) = self.neutron_strat.split(p_neutron)
(p_n_blk, p_n_div, p_n_vv, p_n_aux, p_nrgm, p_blk_decay) = (
self.neutron_strat.split(p_neutron)
)
p_rad_sep_blk, p_rad_sep_div, p_rad_sep_aux = self.rad_sep_strat.split(
p_radiation, p_separatrix
)
Expand Down
33 changes: 7 additions & 26 deletions bluemira/base/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def __init__(
ch_names = [ch.name for ch in children]
if len(ch_names) != len(set(ch_names)):
raise ComponentError(
f"Children have duplicate names for Component {name}",
f"Children have duplicate names for Component {name}"
)

self.parent = parent
Expand Down Expand Up @@ -107,10 +107,7 @@ def filter_components(
This function mutates components in the subtree
"""
for n in names:
named_comps = self.get_component(
n,
first=False,
)
named_comps = self.get_component(n, first=False)

if named_comps is None:
continue
Expand Down Expand Up @@ -139,10 +136,7 @@ def tree(self) -> str:
"""
return str(RenderTree(self))

def copy(
self,
parent: ComponentT | None = None,
) -> ComponentT:
def copy(self, parent: ComponentT | None = None) -> ComponentT:
"""
Copies this component and its children (recursively)
and sets `parent` as this copy's parent.
Expand All @@ -164,22 +158,15 @@ def copy(
This function should be overridden by implementors
"""
# Initially copy self with None children
self_copy = Component(
name=self.name,
parent=parent,
children=None,
)
self_copy = Component(name=self.name, parent=parent, children=None)
self_copy._plot_options = self._plot_options
self_copy._display_cad_options = self._display_cad_options
# Attaches children to parent
self.copy_children(parent=self_copy)

return self_copy

def copy_children(
self,
parent: ComponentT,
) -> list[ComponentT]:
def copy_children(self, parent: ComponentT) -> list[ComponentT]:
"""
Copies this component's children (recursively)
and sets `parent` as the copied children's parent.
Expand Down Expand Up @@ -411,10 +398,7 @@ def __init__(
self._shape = shape
self._material = material

def copy(
self,
parent: ComponentT | None = None,
) -> ComponentT:
def copy(self, parent: ComponentT | None = None) -> ComponentT:
"""
Copies this component and its children (recursively)
and sets `parent` as this copy's parent.
Expand Down Expand Up @@ -487,10 +471,7 @@ def __init__(
super().__init__(name, shape, material, parent, children)
self.conductor = conductor

def copy(
self,
parent: ComponentT | None = None,
) -> ComponentT:
def copy(self, parent: ComponentT | None = None) -> ComponentT:
"""
Copies this component and its children (recursively)
and sets `parent` as this copy's parent.
Expand Down
19 changes: 5 additions & 14 deletions bluemira/base/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ def __init__(self):
# M$ makes sense if a bit non-standard
super().__init__(
fmt_locale="en_GB",
preprocessors=[
lambda x: x.replace("$", "USD "),
],
preprocessors=[lambda x: x.replace("$", "USD ")],
)

self._gas_flow_temperature = None
Expand Down Expand Up @@ -428,9 +426,7 @@ def units_compatible(unit_1: str, unit_2: str) -> bool:


def raw_uc(
value: npt.ArrayLike,
unit_from: str | ureg.Unit,
unit_to: str | ureg.Unit,
value: npt.ArrayLike, unit_from: str | ureg.Unit, unit_to: str | ureg.Unit
) -> float | np.ndarray:
"""
Raw unit converter
Expand Down Expand Up @@ -563,16 +559,13 @@ def _temp_check(unit: Unit, val: complex | Quantity):
"""
if unit.dimensionality == UnitsContainer({"[temperature]": 1}) and np.any(
np.less(
val,
ABS_ZERO.get(unit, ureg.Quantity(0, ureg.kelvin).to(unit).magnitude),
val, ABS_ZERO.get(unit, ureg.Quantity(0, ureg.kelvin).to(unit).magnitude)
)
):
raise ValueError("Negative temperature in K specified.")


def kgm3_to_gcm3(
density: npt.ArrayLike,
) -> float | np.ndarray:
def kgm3_to_gcm3(density: npt.ArrayLike) -> float | np.ndarray:
"""
Convert a density in kg/m3 to g/cm3

Expand All @@ -588,9 +581,7 @@ def kgm3_to_gcm3(
return raw_uc(density, "kg.m^-3", "g.cm^-3")


def gcm3_to_kgm3(
density: npt.ArrayLike,
) -> float | np.ndarray:
def gcm3_to_kgm3(density: npt.ArrayLike) -> float | np.ndarray:
"""
Convert a density in g/cm3 to kg/m3

Expand Down
4 changes: 1 addition & 3 deletions bluemira/base/logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,7 @@ def render(
The text to be rendered by the logger
"""
log_renderable = super().render(
record=record,
traceback=traceback,
message_renderable=message_renderable,
record=record, traceback=traceback, message_renderable=message_renderable
)
if getattr(record, "_flushing", False):
self.console._flushing = True
Expand Down
4 changes: 1 addition & 3 deletions bluemira/base/look_and_feel.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,9 +355,7 @@ def version_banner() -> list[str]:
list[str]
The list of strings of text describing the version and code information
"""
mapping = {
"SLOC": "total",
}
mapping = {"SLOC": "total"}
root = get_bluemira_root()
if not Path(f"{root}/.git").is_dir() or shutil.which("git") is None:
return [
Expand Down
31 changes: 6 additions & 25 deletions bluemira/base/parameter_frame/_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,7 @@
from contextlib import suppress
from dataclasses import dataclass, fields
from operator import itemgetter
from typing import (
TYPE_CHECKING,
Any,
ClassVar,
get_args,
get_type_hints,
)
from typing import TYPE_CHECKING, Any, ClassVar, get_args, get_type_hints

import pint
from tabulate import tabulate
Expand Down Expand Up @@ -149,8 +143,7 @@ def __iter__(self) -> Iterator[Parameter]:
yield getattr(self, field.name)

def update(
self,
new_values: dict[str, ParameterValueType] | ParamDictT | ParameterFrame,
self, new_values: dict[str, ParameterValueType] | ParamDictT | ParameterFrame
):
"""Update the given frame"""
if isinstance(new_values, ParameterFrame):
Expand Down Expand Up @@ -276,10 +269,7 @@ def from_dict(
continue
raise ValueError(f"Data for parameter '{member}' not found.") from e

kwargs[member] = cls._member_data_to_parameter(
member,
param_data,
)
kwargs[member] = cls._member_data_to_parameter(member, param_data)

if not allow_unknown and len(data) > 0:
raise ValueError(f"Unknown parameter(s) {str(list(data))[1:-1]} in dict.")
Expand Down Expand Up @@ -376,10 +366,7 @@ def from_config_params(
for member in cls.__dataclass_fields__:
if member not in lp:
continue
kwargs[member] = cls._member_data_to_parameter(
member,
lp[member],
)
kwargs[member] = cls._member_data_to_parameter(member, lp[member])

gp = config_params.global_params
for member in cls.__dataclass_fields__:
Expand All @@ -399,9 +386,7 @@ def from_config_params(

@classmethod
def _member_data_to_parameter(
cls,
member: str,
member_param_data: ParamDictT,
cls, member: str, member_param_data: ParamDictT
) -> Parameter:
"""Convert a member's data to a Parameter object.

Expand All @@ -420,11 +405,7 @@ def _member_data_to_parameter(
_validate_units(member_param_data, value_type)
except pint.errors.PintError as pe:
raise ValueError("Unit conversion failed") from pe
return Parameter(
name=member,
**member_param_data,
_value_types=value_type,
)
return Parameter(name=member, **member_param_data, _value_types=value_type)

def to_dict(self) -> dict[str, dict[str, Any]]:
"""Serialise this ParameterFrame to a dictionary.
Expand Down
14 changes: 3 additions & 11 deletions bluemira/base/reactor.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@

from rich.progress import track

from bluemira.base.components import (
Component,
)
from bluemira.base.components import Component
from bluemira.base.error import ComponentError
from bluemira.base.look_and_feel import bluemira_warn
from bluemira.base.tools import (
Expand Down Expand Up @@ -271,12 +269,7 @@ def save_cad(
)
filename = filename or comp.name

save_components_cad(
comp,
Path(directory, filename),
cad_format,
**kwargs,
)
save_components_cad(comp, Path(directory, filename), cad_format, **kwargs)

def show_cad(
self,
Expand All @@ -302,8 +295,7 @@ def show_cad(

show_components_cad(
self._build_show_cad_component(
dim,
self._init_construction_param_values(construction_params, kwargs),
dim, self._init_construction_param_values(construction_params, kwargs)
),
**kwargs,
)
Expand Down
17 changes: 4 additions & 13 deletions bluemira/base/reactor_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class GlobalParams(ParameterFrame):
},
},
},
GlobalParams,
GlobalParams
)

"""
Expand All @@ -124,8 +124,7 @@ def __init__(

self.config_data = config_data
self.global_params = make_parameter_frame(
self.config_data.get(_PARAMETERS_KEY, {}),
global_params_type,
self.config_data.get(_PARAMETERS_KEY, {}), global_params_type
)

if not self.global_params:
Expand Down Expand Up @@ -190,10 +189,7 @@ def params_for(self, component_name: str, *args: str) -> ConfigParams:
warn=self.warn_on_empty_local_params,
)

return ConfigParams(
global_params=self.global_params,
local_params=local_params,
)
return ConfigParams(global_params=self.global_params, local_params=local_params)

def config_for(self, component_name: str, *args: str) -> dict:
"""
Expand Down Expand Up @@ -252,12 +248,7 @@ def _read_json_file(path: Path | str) -> dict:
def _pprint_dict(d: dict) -> str:
return pprint.pformat(d, sort_dicts=False, indent=1)

def _warn_on_duplicate_keys(
self,
shared_key: str,
arg: str,
existing_value,
):
def _warn_on_duplicate_keys(self, shared_key: str, arg: str, existing_value):
self._warn_or_debug_log(
"duplicate config key: "
f"'{shared_key}' in {arg} wil be overwritten with {existing_value}",
Expand Down
Loading
Loading