Skip to content

Commit

Permalink
Major refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
alopezrivera committed May 4, 2024
1 parent c3782ba commit ebe1119
Show file tree
Hide file tree
Showing 15 changed files with 97 additions and 50 deletions.
8 changes: 6 additions & 2 deletions examples/analysis/design/altitude.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# SPDX-FileCopyrightText: © 2021 Antonio López Rivera <[email protected]>
# SPDX-License-Identifier: GPL-3.0-only

import sys
from pathlib import Path
sys.path.append(str(Path(__file__).parents[3]))

"""
Huracan
-------
Expand Down Expand Up @@ -89,8 +93,8 @@ def engine(M, t, p):

panes([thrust, eff],
h,
x_labels=['T [kN]', '$\eta_T$'],
y_label='h [km]',
labels_x=['T [kN]', '$\eta_T$'],
label_y='h [km]',
colors=[cmap(Mi) for Mi in M],
line_width=2,
top=0.95,
Expand Down
4 changes: 4 additions & 0 deletions examples/analysis/off-design/thrust.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# SPDX-FileCopyrightText: © 2021 Antonio López Rivera <[email protected]>
# SPDX-License-Identifier: GPL-3.0-only

import sys
from pathlib import Path
sys.path.append(str(Path(__file__).parents[3]))

"""
Huracan
-------
Expand Down
4 changes: 4 additions & 0 deletions examples/engines/turbofan/turbofan_2s-3s-ic.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# SPDX-FileCopyrightText: © 2021 Antonio López Rivera <[email protected]>
# SPDX-License-Identifier: GPL-3.0-only

import sys
from pathlib import Path
sys.path.append(str(Path(__file__).parents[3]))

"""
Huracan
-------
Expand Down
4 changes: 4 additions & 0 deletions examples/engines/turbofan/turbofan_2s-3s.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# SPDX-FileCopyrightText: © 2021 Antonio López Rivera <[email protected]>
# SPDX-License-Identifier: GPL-3.0-only

import sys
from pathlib import Path
sys.path.append(str(Path(__file__).parents[3]))

"""
Huracan
-------
Expand Down
4 changes: 4 additions & 0 deletions examples/engines/turbofan/turbofan_2s_2s.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# SPDX-FileCopyrightText: © 2021 Antonio López Rivera <[email protected]>
# SPDX-License-Identifier: GPL-3.0-only

import sys
from pathlib import Path
sys.path.append(str(Path(__file__).parents[3]))

"""
Huracan
-------
Expand Down
4 changes: 4 additions & 0 deletions examples/engines/turbojet/turbojet_1s-2s-ab.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# SPDX-FileCopyrightText: © 2021 Antonio López Rivera <[email protected]>
# SPDX-License-Identifier: GPL-3.0-only

import sys
from pathlib import Path
sys.path.append(str(Path(__file__).parents[3]))

"""
Huracan
-------
Expand Down
4 changes: 4 additions & 0 deletions examples/engines/turboprop/turboprop_1s-1s.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# SPDX-FileCopyrightText: © 2021 Antonio López Rivera <[email protected]>
# SPDX-License-Identifier: GPL-3.0-only

import sys
from pathlib import Path
sys.path.append(str(Path(__file__).parents[3]))

"""
Huracan
-------
Expand Down
77 changes: 37 additions & 40 deletions huracan/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@
from mpl_plotter.color.schemes import colorscheme_one
from mpl_plotter.color.functions import delta

from alexandria.shell import print_color, print_result
from alexandria.data_structs.string import join_set_distance

from huracan.constants import R
from huracan.utils import markers
from huracan.utils import markers, join_set_distance


class component:
Expand Down Expand Up @@ -430,13 +427,13 @@ def log(self):

for c in self.components:
section_name = join_set_distance(c.stage, c.__class__.__name__.capitalize().replace("_", " "), d)
print_color(section_name, 'green')
print(section_name)

if c.__class__.__name__ == 'nozzle':
if c.choked:
print_color(' '*d + 'Choked flow', 'red')
print_result(' '*(d+1) + 'T0', c.t0, '[K]')
print_result(' '*(d+1) + 'p0', c.p0, '[Pa]')
print(' '*d + 'Choked flow')
print(f'{" "*d} T0 {str(c.t0)[:10]} [K]')
print(f'{" "*d} p0 {str(c.p0)[:10]} [Pa]')

"""
Stream runtime functions
Expand Down Expand Up @@ -729,8 +726,8 @@ def plot_T_S(self,

figure((9, 5))

defaults = {'x_label': '$\Delta$S [kJ/K/n]',
'y_label': 'T$_0$ [K]',}
defaults = {'label_x': r'$\Delta$S [kJ/K/n]',
'label_y': r'T$_0$ [K]',}

further_custom = {**defaults, **kwargs}

Expand All @@ -753,8 +750,8 @@ def plot_p_V(self,

figure((9, 5))

defaults = {'x_label': 'v$_0$ [m$^3$/n]',
'y_label': 'p$_0$ [kPa]'}
defaults = {'label_x': 'v$_0$ [m$^3$/n]',
'label_y': 'p$_0$ [kPa]'}

further_custom = {**defaults, **kwargs}

Expand All @@ -777,8 +774,8 @@ def plot_H_p(self,

figure((9, 5))

defaults = {'x_label': 'p$_0$ [kPa]',
'y_label': 'H$_0$ [kJ]',}
defaults = {'label_x': 'p$_0$ [kPa]',
'label_y': 'H$_0$ [kJ]',}

further_custom = {**defaults, **kwargs}

Expand All @@ -801,8 +798,8 @@ def plot_T_p(self,

figure((9, 5))

defaults = {'x_label': 'p$_0$ [kPa]',
'y_label': 'T$_0$ [K]'}
defaults = {'label_x': 'p$_0$ [kPa]',
'label_y': 'T$_0$ [K]'}

further_custom = {**defaults, **kwargs}

Expand All @@ -817,7 +814,7 @@ def plot_T_p(self,
def plot_cycle_graph(self,
x, y,
plot_label,
x_label, y_label,
label_x, label_y,
color=colorscheme_one()[0],
show=False,
**kwargs
Expand All @@ -832,19 +829,19 @@ class arguments can be passed to this function.

defaults = {
# Specifics
'point_size': 30,
'scatter_size': 30,
# Markers
'marker': 'x',
'scatter_marker': 'x',
# Color
'color': delta(color, -0.3),
# Arrangement
'zorder': 2,
# Further customization
'aspect': 1/2,
'x_tick_number': 10,
'y_tick_number': 10,
'demo_pad_plot': True,
'y_label_pad': 5,
'tick_number_x': 10,
'tick_number_y': 10,
'pad_demo': True,
'label_pad_y': 5,
}

further_custom = {**defaults, **kwargs}
Expand All @@ -866,8 +863,8 @@ class arguments can be passed to this function.
fig=fig,
# Further customization
plot_label=plot_label,
label_x=x_label,
label_y=y_label,
label_x=label_x,
label_y=label_y,
show=show,
**further_custom)

Expand Down Expand Up @@ -1062,7 +1059,7 @@ def efficiency_total(self):
def plot(self,
x, y,
x_scale=None, y_scale=None,
x_label=None, y_label=None,
label_x=None, label_y=None,
show=False,
plot_label=None, # When called from a _system_takeover the plot_label and color
color=colorscheme_one()[0], # arguments are passed to the function, but disregarded.
Expand Down Expand Up @@ -1117,8 +1114,8 @@ def plot(self,
# Plot defaults
subplot_defaults = {
'plot_label': f'{".".join([str(c) for c in stream.stream_id])}',
'x_label': x_label,
'y_label': y_label,
'label_x': label_x,
'label_y': label_y,
'color': colorscheme_one()[self.streams.index(stream)],
'zorder': self.streams.index(stream),
}
Expand Down Expand Up @@ -1159,9 +1156,9 @@ def gen_plotter(**defaults):
connector_args = {'color': subplot_defaults['color'],
'zorder': self.streams.index(stream),
'plot_label': None,
'x_label': None,
'y_label': None,
'marker': ''
'label_x': None,
'label_y': None,
'scatter_marker': ''
}

if colorblind:
Expand Down Expand Up @@ -1189,7 +1186,7 @@ def gen_plotter(**defaults):
autocolor=False,
show=show,
**{**kwargs, **defaults})

def plot_T_p(self,
show=False,
plot_label=None,
Expand All @@ -1204,8 +1201,8 @@ def plot_T_p(self,
args.pop('self', None)
args.pop('kwargs', None)

self.plot(x='p0', x_label='p$_0$ [kPa]',
y='t0', y_label='T$_0$ [K]',
self.plot(x='p0', label_x='p$_0$ [kPa]',
y='t0', label_y='T$_0$ [K]',
**{**args, **kwargs})

def plot_p_V(self,
Expand All @@ -1221,8 +1218,8 @@ def plot_p_V(self,
args.pop('self', None)
args.pop('kwargs', None)

self.plot(x='V', x_label='v$_0$ [m$^3$/n]',
y='p0', y_label='p$_0$ [kPa]',
self.plot(x='V', label_x='v$_0$ [m$^3$/n]',
y='p0', label_y='p$_0$ [kPa]',
**{**args, **kwargs})

def plot_T_S(self,
Expand All @@ -1238,8 +1235,8 @@ def plot_T_S(self,
args.pop('self', None)
args.pop('kwargs', None)

self.plot(x='S', x_label='$\Delta$S [kJ/K]',
y='t0', y_label='T$_0$ [K]',
self.plot(x='S', label_x=r'$\Delta$S [kJ/K]',
y='t0', label_y=r'T$_0$ [K]',
**{**args, **kwargs})

def plot_H_p(self,
Expand All @@ -1255,6 +1252,6 @@ def plot_H_p(self,
args.pop('self', None)
args.pop('kwargs', None)

self.plot(x='p0', x_label='p$_0$ [kPa]',
y='H', y_label='H$_0$ [kJ]',
self.plot(x='p0', label_x='p$_0$ [kPa]',
y='H', label_y='H$_0$ [kJ]',
**{**args, **kwargs})
4 changes: 4 additions & 0 deletions huracan/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
import inspect


def join_set_distance(a, b, d):
return a + ' '*(d - len(a)) + b


def setattr_namespace(o, namespace):
"""
Set all variables declared in a namespace as as attributes
Expand Down
5 changes: 2 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
mpl-plotter>=4.0.2
numpy>=1.21.2
Python-Alexandria>=2.0.0
numpy
mpl-plotter>=55.5.0
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
packages=setuptools.find_packages(),
install_requires=[
"numpy>=1.21.2",
"Python-Alexandria>=2.0.0",
"mpl_plotter>=4.0.2"
],
classifiers=[
Expand Down
9 changes: 8 additions & 1 deletion tests/test_gas.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
# SPDX-FileCopyrightText: © 2021 Antonio López Rivera <[email protected]>
# SPDX-License-Identifier: GPL-3.0-only

# Path
import sys
from pathlib import Path
sys.path.append(str(Path(__file__).parents[1]))

# General imports
import unittest

# Huracan
from huracan.thermo.fluids import gas, fuel

mf = 700
m = 0.6
t = 288
p = 101325
fr = 0
fr = 0.1

g = gas(mf = mf,
cp = lambda T: 1150 if T > 600 else 1000,
Expand Down
7 changes: 7 additions & 0 deletions tests/test_stream.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
# SPDX-FileCopyrightText: © 2021 Antonio López Rivera <[email protected]>
# SPDX-License-Identifier: GPL-3.0-only

# Path
import sys
from pathlib import Path
sys.path.append(str(Path(__file__).parents[1]))

# General imports
import unittest

# Huracan
from huracan.components import inlet, compressor, turbine, nozzle
from huracan.thermo.fluids import gas

Expand Down
7 changes: 7 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
# SPDX-FileCopyrightText: © 2021 Antonio López Rivera <[email protected]>
# SPDX-License-Identifier: GPL-3.0-only

# Path
import sys
from pathlib import Path
sys.path.append(str(Path(__file__).parents[1]))

# General imports
import unittest

# Huracan
from huracan.utils import setattr_namespace


Expand Down
5 changes: 2 additions & 3 deletions tests/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
# SPDX-License-Identifier: MPL-2.0


from alexandria.shell import print_color
from alexandria.data_structs.string import join_set_distance
from huracan.utils import join_set_distance


def verify(prediction, measurement, error_margin=0.001, log=False, name='Error'):
Expand All @@ -23,4 +22,4 @@ def verify(prediction, measurement, error_margin=0.001, log=False, name='Error')

if log:
s = join_set_distance(name, '=', 10)
print_color(s + f' {abs(prediction-measurement)/measurement*100:.2f}% of measurement.', 'yellow')
print(s + f' {abs(prediction-measurement)/measurement*100:.2f}% of measurement.')

0 comments on commit ebe1119

Please sign in to comment.