Skip to content

Commit

Permalink
Coges tested for all libraries
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinksyTRD committed Apr 2, 2024
1 parent 5372639 commit f50f829
Show file tree
Hide file tree
Showing 43 changed files with 19,971 additions and 1,239 deletions.
170 changes: 165 additions & 5 deletions RunFEEMSSim/00_machinery_calculation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,16 @@
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"The autoreload extension is already loaded. To reload it, use:\n",
" %reload_ext autoreload\n"
]
}
],
"source": [
"# | default_exp machinery_calculation\n",
"%load_ext autoreload\n",
Expand Down Expand Up @@ -708,6 +717,83 @@
" name: \"Other load 1\"\n",
" rated_power_kw: 1000\n",
" }\n",
" subsystems {\n",
" converter1 {\n",
" name: \"Converter 1\"\n",
" rated_power_kw: 3150\n",
" efficiency {\n",
" curve {\n",
" x_label: \"power load\"\n",
" y_label: \"efficiency\"\n",
" curve {\n",
" points {\n",
" x: 0.1\n",
" y: 0.9\n",
" }\n",
" points {\n",
" x: 0.25\n",
" y: 0.95\n",
" }\n",
" points {\n",
" x: 0.5\n",
" y: 0.96\n",
" }\n",
" points {\n",
" x: 0.75\n",
" y: 0.97\n",
" }\n",
" points {\n",
" x: 1\n",
" y: 0.96\n",
" }\n",
" }\n",
" }\n",
" }\n",
" order_from_switchboard_or_shaftline: 1\n",
" }\n",
" fuel_cell {\n",
" name: \"Fuel cell 1\"\n",
" rated_power_kw: 1000\n",
" efficiency {\n",
" curve {\n",
" x_label: \"power load\"\n",
" y_label: \"efficiency\"\n",
" curve {\n",
" points {\n",
" x: 0.1\n",
" y: 0.7\n",
" }\n",
" points {\n",
" x: 0.25\n",
" y: 0.85\n",
" }\n",
" points {\n",
" x: 0.5\n",
" y: 0.96\n",
" }\n",
" points {\n",
" x: 0.75\n",
" y: 0.97\n",
" }\n",
" points {\n",
" x: 1\n",
" y: 0.96\n",
" }\n",
" }\n",
" }\n",
" }\n",
" order_from_switchboard_or_shaftline: 2\n",
" fuel {\n",
" fuel_type: HYDROGEN\n",
" fuel_origin: RENEWABLE_NON_BIO\n",
" }\n",
" number_modules: 3\n",
" }\n",
" power_type: POWER_SOURCE\n",
" component_type: FUEL_CELL_SYSTEM\n",
" name: \"Fuel cell system 1\"\n",
" rated_power_kw: 3150\n",
" }\n",
" }\n",
" switchboards {\n",
" switchboard_id: 2\n",
Expand Down Expand Up @@ -982,10 +1068,87 @@
" rated_power_kw: 2000\n",
" rated_speed_rpm: 1000\n",
" }\n",
" subsystems {\n",
" converter1 {\n",
" name: \"Converter 1\"\n",
" rated_power_kw: 3150\n",
" efficiency {\n",
" curve {\n",
" x_label: \"power load\"\n",
" y_label: \"efficiency\"\n",
" curve {\n",
" points {\n",
" x: 0.1\n",
" y: 0.9\n",
" }\n",
" points {\n",
" x: 0.25\n",
" y: 0.95\n",
" }\n",
" points {\n",
" x: 0.5\n",
" y: 0.96\n",
" }\n",
" points {\n",
" x: 0.75\n",
" y: 0.97\n",
" }\n",
" points {\n",
" x: 1\n",
" y: 0.96\n",
" }\n",
" }\n",
" }\n",
" }\n",
" order_from_switchboard_or_shaftline: 1\n",
" }\n",
" fuel_cell {\n",
" name: \"Fuel cell 1\"\n",
" rated_power_kw: 1000\n",
" efficiency {\n",
" curve {\n",
" x_label: \"power load\"\n",
" y_label: \"efficiency\"\n",
" curve {\n",
" points {\n",
" x: 0.1\n",
" y: 0.7\n",
" }\n",
" points {\n",
" x: 0.25\n",
" y: 0.85\n",
" }\n",
" points {\n",
" x: 0.5\n",
" y: 0.96\n",
" }\n",
" points {\n",
" x: 0.75\n",
" y: 0.97\n",
" }\n",
" points {\n",
" x: 1\n",
" y: 0.96\n",
" }\n",
" }\n",
" }\n",
" }\n",
" order_from_switchboard_or_shaftline: 2\n",
" fuel {\n",
" fuel_type: HYDROGEN\n",
" fuel_origin: RENEWABLE_NON_BIO\n",
" }\n",
" number_modules: 3\n",
" }\n",
" power_type: POWER_SOURCE\n",
" component_type: FUEL_CELL_SYSTEM\n",
" name: \"Fuel cell system 1\"\n",
" rated_power_kw: 3150\n",
" }\n",
" }\n",
"}\n",
"\n",
"Average bsfc for engines: 305.69896408621025 g/kWh\n"
"Average bsfc for engines: 248.41624983126195 g/kWh\n"
]
}
],
Expand Down Expand Up @@ -1024,9 +1187,6 @@
"running_hours_mean = 0\n",
"for power_source in machinery_calculation.electric_system.power_sources:\n",
" running_hours_mean += (power_source.power_output > 0).mean()\n",
" generator_run_point = (\n",
" power_source.get_fuel_cons_load_bsfc_from_power_out_generator_kw()\n",
" )\n",
"for propulsor in machinery_calculation.electric_system.propulsion_drives:\n",
" average_power_consumption += propulsor.power_input.mean()\n",
"average_bsfc_for_engines = res.fuel_consumption_total_kg / (\n",
Expand Down
4 changes: 2 additions & 2 deletions RunFEEMSSim/01_pms_basic.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"{0.0: (False, False, False, True), 800.0: (False, False, True, True), 1600.0: (False, True, True, True), 2400.0: (True, True, True, True)}\n"
"{0.0: (False, False, False, False, True, False), 800.0: (False, False, False, True, True, False), 1600.0: (False, True, False, True, True, False), 2400.0: (False, False, False, False, False, True), 2520.0: (True, True, False, True, True, False), 3200.0: (False, False, False, False, True, True), 3320.0: (False, False, False, True, True, True), 4120.0: (False, True, False, True, True, True), 4920.0: (False, False, True, False, False, True), 5040.0: (True, True, False, True, True, True), 5720.0: (False, False, True, False, True, True), 5840.0: (False, False, True, True, True, True), 6640.0: (False, True, True, True, True, True), 7440.0: (True, True, True, True, True, True)}\n"
]
}
],
Expand All @@ -260,7 +260,7 @@
"system_proto = retrieve_machinery_system_from_file(path)\n",
"\n",
"load_table_dict = get_min_load_table_dict_from_proto_system(system_proto)\n",
"assert len(load_table_dict) == 4\n",
"np.testing.assert_equal(len(load_table_dict), 14)\n",
"print(load_table_dict)"
]
},
Expand Down
2 changes: 1 addition & 1 deletion RunFEEMSSim/RunFeemsSim/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.2.2"
__version__ = "0.2.3"
2 changes: 1 addition & 1 deletion RunFEEMSSim/settings.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ author = Kevin Koosup Yum
author_email = kevinkoosup.yum@sintef.no
copyright = SINTEF
branch = master
version = 0.2.2
version = 0.2.3
min_python = 3.10
audience = Developers
language = English
Expand Down
Binary file modified RunFEEMSSim/tests/mechanical_propulsion_with_electric_system.mss
Binary file not shown.
Binary file modified RunFEEMSSim/tests/system_proto.mss
Binary file not shown.
4 changes: 3 additions & 1 deletion feems/feems/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ def get_logger(name: str) -> logging.Logger:
ch = logging.StreamHandler()
ch.setLevel(logging.INFO)

formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
formatter = logging.Formatter(
"%(asctime)s - %(name)s - %(levelname)s - %(message)s"
)
ch.setFormatter(formatter)

logger.addHandler(ch)
Expand Down
51 changes: 38 additions & 13 deletions feems/feems/components_model/component_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ def __init__(
rated_speed: Speed_rpm = Speed_rpm(0.0),
file_name: str = None,
):
super(BasicComponent, self).__init__(name, type_, power_type, rated_power, rated_speed)
super(BasicComponent, self).__init__(
name, type_, power_type, rated_power, rated_speed
)
if file_name is not None:
df = pd.read_csv(file_name, index_col=0)
self.rated_power = df["Rated Power"].values[0]
Expand Down Expand Up @@ -123,7 +125,9 @@ def __init__(
raise InputError(err_msg)

#: Make a mapping between the power in to out
power_out = np.arange(-self.rated_power, self.rated_power, self.rated_power * 0.01)
power_out = np.arange(
-self.rated_power, self.rated_power, self.rated_power * 0.01
)
load = self.get_load(power_out)
power_in = power_out / self.get_efficiency_from_load_percentage(load)

Expand Down Expand Up @@ -154,7 +158,9 @@ def _get_power_output_and_load_from_input(
power_output = self._power_out_interp(power_input)
if strict_power_balance:
if type(power_input) is not np.ndarray:
power_output = newton(self._power_balance, power_output, args=(power_input,))
power_output = newton(
self._power_balance, power_output, args=(power_input,)
)
else:
no_points_per_batch = 50
no_points = len(power_input)
Expand Down Expand Up @@ -207,7 +213,9 @@ def get_power_input_from_bidirectional_output(
(
power_input[idx_forward_power],
load[idx_forward_power],
) = self._get_power_input_and_load_from_output(power_output[idx_forward_power])
) = self._get_power_input_and_load_from_output(
power_output[idx_forward_power]
)
(
power_input[idx_reverse_power],
load[idx_reverse_power],
Expand Down Expand Up @@ -238,7 +246,9 @@ def get_power_output_from_bidirectional_input(
(
power_output[idx_reverse_power],
load[idx_reverse_power],
) = self._get_power_input_and_load_from_output(power_input[idx_reverse_power])
) = self._get_power_input_and_load_from_output(
power_input[idx_reverse_power]
)
return power_output, load

def set_power_input_from_output(
Expand All @@ -257,7 +267,9 @@ def set_power_input_from_output(
self.power_output = power_output

#: Calculate the power input and %load considering the efficiency
self.power_input, load = self.get_power_input_from_bidirectional_output(power_output)
self.power_input, load = self.get_power_input_from_bidirectional_output(
power_output
)

#: Return the result
return self.power_input, load
Expand All @@ -278,7 +290,9 @@ def set_power_output_from_input(
self.power_input = power_input

#: Calculate the power output and %load considering the efficiency
self.power_output, load = self.get_power_output_from_bidirectional_input(power_input)
self.power_output, load = self.get_power_output_from_bidirectional_input(
power_input
)

#: Return the result
return self.power_output, load
Expand Down Expand Up @@ -322,10 +336,14 @@ def _d_power_balance(self, x: np.ndarray, power_input: Numeric) -> float:
load = self.get_load(x)
if not isinstance(power_input, np.ndarray):
if power_input > 0:
power_output = power_input * self.get_efficiency_from_load_percentage(load)
power_output = power_input * self.get_efficiency_from_load_percentage(
load
)
d_power_output = power_input * self._get_d_efficiency(x, 0.001 * x)
else:
power_output = power_input / self.get_efficiency_from_load_percentage(load)
power_output = power_input / self.get_efficiency_from_load_percentage(
load
)
d_power_output = (
-power_input
* self._get_d_efficiency(x, 0.001 * x)
Expand All @@ -341,19 +359,26 @@ def _d_power_balance(self, x: np.ndarray, power_input: Numeric) -> float:
] * self.get_efficiency_from_load_percentage(load[idx_forward_power])
d_power_output[idx_forward_power] = power_input[
idx_forward_power
] * self._get_d_efficiency(x[idx_forward_power], 0.001 * x[idx_forward_power])
] * self._get_d_efficiency(
x[idx_forward_power], 0.001 * x[idx_forward_power]
)
power_output[idx_reverse_power] = power_input[
idx_reverse_power
] / self.get_efficiency_from_load_percentage(load[idx_reverse_power])
d_power_output[idx_reverse_power] = (
-power_input[idx_reverse_power]
* self._get_d_efficiency(x[idx_reverse_power], 0.001 * x[idx_reverse_power])
/ (self.get_efficiency_from_load_percentage(load[idx_reverse_power])) ** 2
* self._get_d_efficiency(
x[idx_reverse_power], 0.001 * x[idx_reverse_power]
)
/ (self.get_efficiency_from_load_percentage(load[idx_reverse_power]))
** 2
)
power_balance = x - power_output
return (power_balance * (1 - d_power_output)).sum()

def _get_d_efficiency(self, power: np.ndarray, power_delta: np.ndarray) -> np.ndarray:
def _get_d_efficiency(
self, power: np.ndarray, power_delta: np.ndarray
) -> np.ndarray:
load = self.get_load(power)
load_delta = self.get_load(power + power_delta)
return (
Expand Down
Loading

0 comments on commit f50f829

Please sign in to comment.