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

Make internal class attributes private #105

Merged
merged 1 commit into from
Jul 28, 2023
Merged
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
16 changes: 8 additions & 8 deletions roseau/load_flow/io/dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,16 @@ def network_from_dict(
transformers_params = {tp["id"]: TransformerParameters.from_dict(tp) for tp in data["transformers_params"]}

# Buses, loads and sources
buses = {bd["id"]: en_class.bus_class.from_dict(bd) for bd in data["buses"]}
loads = {ld["id"]: en_class.load_class.from_dict(ld | {"bus": buses[ld["bus"]]}) for ld in data["loads"]}
buses = {bd["id"]: en_class._bus_class.from_dict(bd) for bd in data["buses"]}
loads = {ld["id"]: en_class._load_class.from_dict(ld | {"bus": buses[ld["bus"]]}) for ld in data["loads"]}
sources = {
sd["id"]: en_class.voltage_source_class.from_dict(sd | {"bus": buses[sd["bus"]]}) for sd in data["sources"]
sd["id"]: en_class._voltage_source_class.from_dict(sd | {"bus": buses[sd["bus"]]}) for sd in data["sources"]
}

# Grounds and potential refs
grounds: dict[Id, Ground] = {}
for ground_data in data["grounds"]:
ground = en_class.ground_class(ground_data["id"])
ground = en_class._ground_class(ground_data["id"])
for ground_bus in ground_data["buses"]:
ground.connect(buses[ground_bus["id"]], ground_bus["phase"])
grounds[ground_data["id"]] = ground
Expand All @@ -86,7 +86,7 @@ def network_from_dict(
msg = f"Potential reference data {pref_data['id']} missing bus or ground."
logger.error(msg)
raise RoseauLoadFlowException(msg, RoseauLoadFlowExceptionCode.JSON_PREF_INVALID)
potential_refs[pref_data["id"]] = en_class.pref_class(
potential_refs[pref_data["id"]] = en_class._pref_class(
pref_data["id"], element=bus_or_ground, phase=pref_data.get("phases")
)

Expand All @@ -105,17 +105,17 @@ def network_from_dict(
lp = lines_params[branch_data["params_id"]]
gid = branch_data.get("ground")
ground = grounds[gid] if gid is not None else None
branches_dict[id] = en_class.line_class(
branches_dict[id] = en_class._line_class(
id, bus1, bus2, parameters=lp, phases=phases1, length=length, ground=ground, geometry=geometry
)
elif branch_data["type"] == "transformer":
tp = transformers_params[branch_data["params_id"]]
branches_dict[id] = en_class.transformer_class(
branches_dict[id] = en_class._transformer_class(
id, bus1, bus2, parameters=tp, phases1=phases1, phases2=phases2, geometry=geometry
)
elif branch_data["type"] == "switch":
assert phases1 == phases2
branches_dict[id] = en_class.switch_class(id, bus1, bus2, phases=phases1, geometry=geometry)
branches_dict[id] = en_class._switch_class(id, bus1, bus2, phases=phases1, geometry=geometry)
else:
msg = f"Unknown branch type for branch {id}: {branch_data['type']}"
logger.error(msg)
Expand Down
46 changes: 23 additions & 23 deletions roseau/load_flow/models/loads/flexible_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,8 +441,8 @@ class FlexibleParameter(JsonMixin):
:ref:`Flexible Parameters documentation <models-flexible_load-flexible_parameters>`
"""

control_class: type[Control] = Control
projection_class: type[Projection] = Projection
_control_class: type[Control] = Control
_projection_class: type[Projection] = Projection

@ureg.wraps(None, (None, None, None, None, "VA"), strict=False)
def __init__(self, control_p: Control, control_q: Control, projection: Projection, s_max: float) -> None:
Expand Down Expand Up @@ -489,9 +489,9 @@ def constant(cls) -> Self:
load.
"""
return cls(
control_p=cls.control_class.constant(),
control_q=cls.control_class.constant(),
projection=cls.projection_class(type="euclidean"),
control_p=cls._control_class.constant(),
control_q=cls._control_class.constant(),
projection=cls._projection_class(type="euclidean"),
s_max=1.0,
)

Expand Down Expand Up @@ -539,11 +539,11 @@ def p_max_u_production(
Returns:
A flexible parameter which performs "p_max_u_production" control.
"""
control_p = cls.control_class.p_max_u_production(u_up=u_up, u_max=u_max, alpha=alpha_control)
control_p = cls._control_class.p_max_u_production(u_up=u_up, u_max=u_max, alpha=alpha_control)
return cls(
control_p=control_p,
control_q=cls.control_class.constant(),
projection=cls.projection_class(type="euclidean", alpha=alpha_proj, epsilon=epsilon_proj),
control_q=cls._control_class.constant(),
projection=cls._projection_class(type="euclidean", alpha=alpha_proj, epsilon=epsilon_proj),
s_max=s_max,
)

Expand Down Expand Up @@ -588,11 +588,11 @@ def p_max_u_consumption(
Returns:
A flexible parameter which performs "p_max_u_consumption" control.
"""
control_p = cls.control_class.p_max_u_consumption(u_min=u_min, u_down=u_down, alpha=alpha_control)
control_p = cls._control_class.p_max_u_consumption(u_min=u_min, u_down=u_down, alpha=alpha_control)
return cls(
control_p=control_p,
control_q=cls.control_class.constant(),
projection=cls.projection_class("euclidean", alpha=alpha_proj, epsilon=epsilon_proj),
control_q=cls._control_class.constant(),
projection=cls._projection_class("euclidean", alpha=alpha_proj, epsilon=epsilon_proj),
s_max=s_max,
)

Expand Down Expand Up @@ -646,11 +646,11 @@ def q_u(
Returns:
A flexible parameter which performs "q_u" control.
"""
control_q = cls.control_class.q_u(u_min=u_min, u_down=u_down, u_up=u_up, u_max=u_max, alpha=alpha_control)
control_q = cls._control_class.q_u(u_min=u_min, u_down=u_down, u_up=u_up, u_max=u_max, alpha=alpha_control)
return cls(
control_p=cls.control_class.constant(),
control_p=cls._control_class.constant(),
control_q=control_q,
projection=cls.projection_class(type="euclidean", alpha=alpha_proj, epsilon=epsilon_proj),
projection=cls._projection_class(type="euclidean", alpha=alpha_proj, epsilon=epsilon_proj),
s_max=s_max,
)

Expand Down Expand Up @@ -716,12 +716,12 @@ def pq_u_production(
.. seealso::
:meth:`p_max_u_production` and :meth:`q_u` for more details.
"""
control_p = cls.control_class.p_max_u_production(u_up=up_up, u_max=up_max, alpha=alpha_control)
control_q = cls.control_class.q_u(u_min=uq_min, u_down=uq_down, u_up=uq_up, u_max=uq_max, alpha=alpha_control)
control_p = cls._control_class.p_max_u_production(u_up=up_up, u_max=up_max, alpha=alpha_control)
control_q = cls._control_class.q_u(u_min=uq_min, u_down=uq_down, u_up=uq_up, u_max=uq_max, alpha=alpha_control)
return cls(
control_p=control_p,
control_q=control_q,
projection=cls.projection_class(type="euclidean", alpha=alpha_proj, epsilon=epsilon_proj),
projection=cls._projection_class(type="euclidean", alpha=alpha_proj, epsilon=epsilon_proj),
s_max=s_max,
)

Expand Down Expand Up @@ -787,12 +787,12 @@ def pq_u_consumption(
.. seealso::
:meth:`p_max_u_consumption` and :meth:`q_u` for more details.
"""
control_p = cls.control_class.p_max_u_consumption(u_min=up_min, u_down=up_down, alpha=alpha_control)
control_q = cls.control_class.q_u(u_min=uq_min, u_down=uq_down, u_up=uq_up, u_max=uq_max, alpha=alpha_control)
control_p = cls._control_class.p_max_u_consumption(u_min=up_min, u_down=up_down, alpha=alpha_control)
control_q = cls._control_class.q_u(u_min=uq_min, u_down=uq_down, u_up=uq_up, u_max=uq_max, alpha=alpha_control)
return cls(
control_p=control_p,
control_q=control_q,
projection=cls.projection_class(type="euclidean", alpha=alpha_proj, epsilon=epsilon_proj),
projection=cls._projection_class(type="euclidean", alpha=alpha_proj, epsilon=epsilon_proj),
s_max=s_max,
)

Expand All @@ -801,9 +801,9 @@ def pq_u_consumption(
#
@classmethod
def from_dict(cls, data: JsonDict) -> Self:
control_p = cls.control_class.from_dict(data["control_p"])
control_q = cls.control_class.from_dict(data["control_q"])
projection = cls.projection_class.from_dict(data["projection"])
control_p = cls._control_class.from_dict(data["control_p"])
control_q = cls._control_class.from_dict(data["control_q"])
projection = cls._projection_class.from_dict(data["projection"])
return cls(control_p=control_p, control_q=control_q, projection=projection, s_max=data["s_max"])

def to_dict(self) -> JsonDict:
Expand Down
20 changes: 10 additions & 10 deletions roseau/load_flow/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,16 +149,16 @@ class ElectricalNetwork(JsonMixin):
DEFAULT_WARM_START: bool = True
DEFAULT_SOLVER: Solver = "newton_goldstein"

# Default classes to use
branch_class = AbstractBranch
line_class = Line
transformer_class = Transformer
switch_class = Switch
load_class = AbstractLoad
voltage_source_class = VoltageSource
bus_class = Bus
ground_class = Ground
pref_class = PotentialRef
# Elements classes (for internal use only)
_branch_class = AbstractBranch
_line_class = Line
_transformer_class = Transformer
_switch_class = Switch
_load_class = AbstractLoad
_voltage_source_class = VoltageSource
_bus_class = Bus
_ground_class = Ground
_pref_class = PotentialRef

#
# Methods to build an electrical network
Expand Down