Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/203_Ampliacion_OPF_lineal' into …
Browse files Browse the repository at this point in the history
…devel

# Conflicts:
#	.idea/workspace.xml
  • Loading branch information
SanPen committed Apr 8, 2024
2 parents 3f4c4a8 + ebcc433 commit a895a02
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/GridCalEngine/Compilers/circuit_to_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -1228,9 +1228,13 @@ def get_fluid_node_data(circuit: MultiCircuit,
if time_series:
data.inflow[k] = elm.inflow_prof[t_idx]
data.spillage_cost[k] = elm.spillage_cost_prof[t_idx]
data.max_soc[k] = elm.max_soc_prof[t_idx]
data.min_soc[k] = elm.min_soc_prof[t_idx]
else:
data.inflow[k] = elm.inflow
data.spillage_cost[k] = elm.spillage_cost
data.max_soc[k] = elm.max_soc
data.min_soc[k] = elm.min_soc

return data, plant_dict

Expand Down
5 changes: 4 additions & 1 deletion src/GridCalEngine/DataStructures/fluid_node_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ def __init__(self, nelm: int):

self.min_level = np.zeros(nelm, dtype=float)
self.max_level = np.zeros(nelm, dtype=float)
self.min_soc = np.zeros(nelm, dtype=float)
self.max_soc = np.zeros(nelm, dtype=float)
self.initial_level = np.zeros(nelm, dtype=float)
# self.bus_index = np.empty() # TODO: check if relevant
self.inflow = np.zeros(nelm, dtype=float)
self.spillage_cost = np.zeros(nelm, dtype=float)

Expand All @@ -61,6 +62,8 @@ def copy(self) -> "FluidNodeData":

data.min_level = self.min_level.copy()
data.max_level = self.max_level.copy()
data.min_soc = self.min_soc.copy()
data.max_soc = self.max_soc.copy()
data.initial_level = self.initial_level.copy()

data.inflow = self.inflow.copy()
Expand Down
53 changes: 53 additions & 0 deletions src/GridCalEngine/Devices/Fluid/fluid_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ def __init__(self,
code: str = '',
min_level: float = 0.0,
max_level: float = 0.0,
min_soc: float = 0.0,
max_soc: float = 1.0,
current_level: float = 0.0,
spillage_cost: float = 1000.0,
inflow: float = 0.0,
Expand All @@ -58,6 +60,8 @@ def __init__(self,

self.min_level = min_level # hm3
self.max_level = max_level # hm3
self.max_soc = max_soc # p.u.
self.min_soc = min_soc # p.u.
self.initial_level = current_level # hm3
self.spillage_cost = spillage_cost # m3/s
self.inflow = inflow # m3/s
Expand All @@ -67,12 +71,23 @@ def __init__(self,
self._inflow_prof = Profile(default_value=inflow) # m3/s
self._spillage_cost_prof = Profile(default_value=spillage_cost) # e/(m3/s)

self._max_soc_prof = Profile(default_value=max_soc) # p.u.
self._min_soc_prof = Profile(default_value=min_soc) # p.u.

self.register(key='min_level', units='hm3', tpe=float,
definition="Minimum amount of fluid at the node/reservoir")

self.register(key='max_level', units='hm3', tpe=float,
definition="Maximum amount of fluid at the node/reservoir")

self.register(key='min_soc', units='p.u.', tpe=float,
definition="Minimum SOC of fluid at the node/reservoir",
profile_name='min_soc_prof')

self.register(key='max_soc', units='p.u.', tpe=float,
definition="Maximum SOC of fluid at the node/reservoir",
profile_name='max_soc_prof')

self.register(key='initial_level', units='hm3', tpe=float,
definition="Initial level of the node/reservoir")

Expand Down Expand Up @@ -124,6 +139,40 @@ def inflow_prof(self, val: Union[Profile, np.ndarray]):
else:
raise Exception(str(type(val)) + 'not supported to be set into a inflow_prof')

@property
def max_soc_prof(self) -> Profile:
"""
Max soc profile
:return: Profile
"""
return self._max_soc_prof

@max_soc_prof.setter
def max_soc_prof(self, val: Union[Profile, np.ndarray]):
if isinstance(val, Profile):
self._max_soc_prof = val
elif isinstance(val, np.ndarray):
self._max_soc_prof.set(arr=val)
else:
raise Exception(str(type(val)) + 'not supported to be set into a max soc prof')

@property
def min_soc_prof(self) -> Profile:
"""
Min soc profile
:return: Profile
"""
return self._min_soc_prof

@min_soc_prof.setter
def min_soc_prof(self, val: Union[Profile, np.ndarray]):
if isinstance(val, Profile):
self._min_soc_prof = val
elif isinstance(val, np.ndarray):
self._min_soc_prof.set(arr=val)
else:
raise Exception(str(type(val)) + 'not supported to be set into a min soc prof')

def copy(self):
"""
Make a deep copy of this object
Expand All @@ -135,6 +184,8 @@ def copy(self):

fluid_node.min_level = self.min_level # hm3
fluid_node.max_level = self.max_level # hm3
fluid_node.min_soc = self.min_soc # p.u.
fluid_node.max_soc = self.max_soc # p.u.
fluid_node.initial_level = self.initial_level # hm3
fluid_node.spillage_cost = self.spillage_cost # m3/s
fluid_node.inflow = self.inflow # m3/s
Expand All @@ -143,6 +194,8 @@ def copy(self):

fluid_node.inflow_prof = self.inflow_prof # m3/s
fluid_node.spillage_cost_prof = self.spillage_cost_prof # e/(m3/s)
fluid_node.max_soc_prof = self.max_soc_prof # m3
fluid_node.min_soc_prof = self.min_soc_prof # m3

return fluid_node

Expand Down
13 changes: 11 additions & 2 deletions src/GridCalEngine/Simulations/OPF/linear_opf_ts.py
Original file line number Diff line number Diff line change
Expand Up @@ -1318,10 +1318,19 @@ def add_hydro_formulation(t: Union[int, None],
f_obj += node_data.spillage_cost[m] * node_vars.spillage[t, m]
# f_obj += node_vars.spillage[t, m]

node_vars.current_level[t, m] = prob.add_var(lb=node_data.min_level[m],
ub=node_data.max_level[m],
min_abs_level = node_data.max_level[m] * node_data.min_soc[m]

node_vars.current_level[t, m] = prob.add_var(lb=min_abs_level,
ub=node_data.max_level[m] * node_data.max_soc[m],
name=join("level_", [t, m], "_"))

if min_abs_level < node_data.min_level[m]:
logger.add_error(msg='Node SOC is below the allowed minimum level',
value=min_abs_level,
expected_value=node_data.min_level[m],
device_class="FluidNode",
device_property=f"Min SOC at {t}")

for m in range(path_data.nelm):
path_vars.flow[t, m] = prob.add_var(lb=path_data.min_flow[m],
ub=path_data.max_flow[m],
Expand Down

0 comments on commit a895a02

Please sign in to comment.