Skip to content

Commit a026b6e

Browse files
Merge pull request OpenMDAO#83 from swryan/example_cycles
Clarified how to test example cycles & made fixes to some related test scripts
2 parents d794eec + 663c86b commit a026b6e

File tree

5 files changed

+64
-30
lines changed

5 files changed

+64
-30
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
### Summary
2+
3+
Summary of PR.
4+
5+
### Related Issues
6+
7+
- Resolves #
8+
9+
### Backwards incompatibilities
10+
11+
None
12+
13+
### New Dependencies
14+
15+
None

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Here is the OpenMDAO version you need for the specific versions of pyCycle
2727
| 4.2.0 | 3.10.0 or greater |
2828

2929
## Version 4.2 --- PyPI release
30-
No significant code changes, but minor adjustments to the package name in `setup.py` to enable publishing to PyPI.
30+
No significant code changes, but minor adjustments to the package name in `setup.py` to enable publishing to PyPI.
3131

3232
## Citation
3333

@@ -59,9 +59,9 @@ If you use pyCycle, please cite this paper:
5959

6060
pip install 'om-pycycle[all]'
6161

62-
Why is it `om-pycycle` on PyPI?
63-
Because another package already claimed `pyCycle`!
64-
Note that the import does not change though.
62+
Why is it `om-pycycle` on PyPI?
63+
Because another package already claimed `pyCycle`!
64+
Note that the import does not change though.
6565
You still use `import pycycle` regardless.
6666

6767

@@ -90,7 +90,7 @@ or for pyCycle V4.0.0:
9090

9191
Use pip to install:
9292

93-
pip install -e .
93+
pip install -e .[all]
9494

9595

9696
## Testing
@@ -100,10 +100,10 @@ After installation if you wat to run the unit test suite you can do so via the `
100100
testflo pycycle
101101

102102
This will run all the unit tests within the pycycle repository, but note that it will NOT run the longer regression tests from the
103-
`example_cycles` folder.
104-
If you want to run the regression tests, then you need to clone the repository, CD into the `example_cycles` folder and call
103+
`example_cycles` folder. These tests are written as 'benchmark' tests.
104+
If you want to run these tests, then you need to clone the repository, CD into the `example_cycles` folder and call
105105

106-
testflo .
106+
testflo -b .
107107

108108

109109
## Version 4.0 Announcements

example_cycles/N+3ref/N3_SPD.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,27 @@
44
from pprint import pprint
55

66
import openmdao.api as om
7+
from openmdao.utils.general_utils import set_pyoptsparse_opt
78

89
import pycycle.api as pyc
910

1011
from N3ref import N3, viewer, MPN3
1112

13+
# check that pyoptsparse is installed
14+
OPT, OPTIMIZER = set_pyoptsparse_opt('SNOPT')
15+
if OPTIMIZER:
16+
from openmdao.drivers.pyoptsparse_driver import pyOptSparseDriver
17+
18+
1219
def N3_SPD_model():
1320

1421
prob = om.Problem()
1522

16-
prob.model = MPN3()
23+
prob.model = MPN3()
1724

1825
# setup the optimization
1926
prob.driver = om.pyOptSparseDriver()
20-
prob.driver.options['optimizer'] = 'SNOPT'
27+
prob.driver.options['optimizer'] = OPTIMIZER
2128
prob.driver.options['debug_print'] = ['desvars', 'nl_cons', 'objs']
2229
prob.driver.opt_settings={'Major step limit': 0.05}
2330

@@ -53,15 +60,15 @@ def N3_SPD_model():
5360
# Define the design point
5461
prob.set_val('TOC.splitter.BPR', 23.94514401),
5562
prob.set_val('TOC.balance.rhs:hpc_PR', 53.6332)
56-
prob.set_val('TOC.fc.W', 820.44097898, units='lbm/s')
63+
prob.set_val('TOC.fc.W', 820.44097898, units='lbm/s')
5764

5865
# Set specific cycle parameters
5966
prob.set_val('fan:PRdes', 1.300),
6067
prob.set_val('lpc:PRdes', 3.000),
6168
prob.set_val('T4_ratio.TR', 0.926470588)
6269
prob.set_val('RTO_T4', 3400.0, units='degR')
6370
prob.set_val('SLS.balance.rhs:FAR', 28620.84, units='lbf')
64-
prob.set_val('CRZ.balance.rhs:FAR', 5510.72833567, units='lbf')
71+
prob.set_val('CRZ.balance.rhs:FAR', 5510.72833567, units='lbf')
6572
prob.set_val('RTO.hpt_cooling.x_factor', 0.9)
6673

6774
# Set initial guesses for balances
@@ -116,4 +123,4 @@ def N3_SPD_model():
116123
for pt in ['TOC']+prob.model.od_pts:
117124
viewer(prob, pt)
118125

119-
print("time", time.time() - st)
126+
print("time", time.time() - st)

example_cycles/N+3ref/benchmark_N3_SPD.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
1-
import numpy as np
1+
import numpy as np
22
import unittest
33
import os
44

55
import openmdao.api as om
66
from openmdao.utils.assert_utils import assert_near_equal
7+
from openmdao.utils.general_utils import set_pyoptsparse_opt
78

89
import pycycle.api as pyc
910

1011
from N3_SPD import N3_SPD_model
1112

13+
# check that pyoptsparse is installed
14+
OPT, OPTIMIZER = set_pyoptsparse_opt('SNOPT')
15+
16+
1217
class N3MDPOptTestCase(unittest.TestCase):
1318

19+
@unittest.skipUnless(OPT, "This test requires pyOptSparse.")
1420
def benchmark_case1(self):
1521

1622
prob = N3_SPD_model()
@@ -20,15 +26,15 @@ def benchmark_case1(self):
2026
# Define the design point
2127
prob.set_val('TOC.splitter.BPR', 23.94514401),
2228
prob.set_val('TOC.balance.rhs:hpc_PR', 53.6332)
23-
prob.set_val('TOC.fc.W', 820.44097898, units='lbm/s')
29+
prob.set_val('TOC.fc.W', 820.44097898, units='lbm/s')
2430

2531
# Set specific cycle parameters
2632
prob.set_val('fan:PRdes', 1.300),
2733
prob.set_val('lpc:PRdes', 3.000),
2834
prob.set_val('T4_ratio.TR', 0.926470588)
2935
prob.set_val('RTO_T4', 3400.0, units='degR')
3036
prob.set_val('SLS.balance.rhs:FAR', 28620.84, units='lbf')
31-
prob.set_val('CRZ.balance.rhs:FAR', 5510.72833567, units='lbf')
37+
prob.set_val('CRZ.balance.rhs:FAR', 5510.72833567, units='lbf')
3238
prob.set_val('RTO.hpt_cooling.x_factor', 0.9)
3339

3440
# Set initial guesses for balances
@@ -126,7 +132,7 @@ def benchmark_case1(self):
126132
assert_near_equal(prob['CRZ.balance.fan_Nmech'], 2118.62554023, tol)#
127133
assert_near_equal(prob['CRZ.balance.lp_Nmech'], 6567.78766693, tol)#
128134
assert_near_equal(prob['CRZ.balance.hp_Nmech'], 20574.43651756, tol)#
129-
assert_near_equal(prob['CRZ.hpc.Fl_O:tot:T'], 1481.9756247, tol)#
135+
assert_near_equal(prob['CRZ.hpc.Fl_O:tot:T'], 1481.9756247, tol)#
130136

131137

132138
if __name__ == "__main__":

example_cycles/electric_propulsor.py

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
import pycycle.api as pyc
44

5+
# protection incase env doesn't have matplotlib installed, since its not strictly required
6+
try:
7+
import matplotlib
8+
import matplotlib.pyplot as plt
9+
except ImportError:
10+
plt = None
11+
512

613
class Propulsor(pyc.Cycle):
714

@@ -10,10 +17,10 @@ def setup(self):
1017
design = self.options['design']
1118

1219
USE_TABULAR = True
13-
if USE_TABULAR:
20+
if USE_TABULAR:
1421
self.options['thermo_method'] = 'TABULAR'
1522
self.options['thermo_data'] = pyc.AIR_JETA_TAB_SPEC
16-
else:
23+
else:
1724
self.options['thermo_method'] = 'CEA'
1825
self.options['thermo_data'] = pyc.species_data.janaf
1926
FUEL_TYPE = 'JP-7'
@@ -24,7 +31,7 @@ def setup(self):
2431
self.add_subsystem('inlet', pyc.Inlet())
2532
self.add_subsystem('fan', pyc.Compressor(map_data=pyc.FanMap, map_extrap=True))
2633
self.add_subsystem('nozz', pyc.Nozzle())
27-
34+
2835
self.add_subsystem('perf', pyc.Performance(num_nozzles=1, num_burners=0))
2936

3037

@@ -125,15 +132,14 @@ def setup(self):
125132
self.pyc_add_pnt(pt, Propulsor(design=False, thermo_method='CEA'))
126133

127134
self.set_input_defaults(pt+'.fc.MN', val=self.od_MNs[i])
128-
self.set_input_defaults(pt+'.fc.alt', val=self.od_alts, units='m')
129-
self.set_input_defaults(pt+'.fan.map.RlineMap', val=self.od_Rlines[i])
135+
self.set_input_defaults(pt+'.fc.alt', val=self.od_alts, units='m')
136+
self.set_input_defaults(pt+'.fan.map.RlineMap', val=self.od_Rlines[i])
130137

131138
self.pyc_use_default_des_od_conns()
132139

133140
self.pyc_connect_des_od('nozz.Throat:stat:area', 'balance.rhs:W')
134141

135142
super().setup()
136-
137143

138144

139145
if __name__ == "__main__":
@@ -158,13 +164,13 @@ def setup(self):
158164

159165
# Set initial guesses for balances
160166
prob['design.balance.W'] = 200.
161-
167+
162168
for i, pt in enumerate(mp_propulsor.od_pts):
163-
169+
164170
# initial guesses
165-
prob['off_design.fan.PR'] = 1.2
166-
prob['off_design.balance.W'] = 406.790
167-
prob['off_design.balance.Nmech'] = 1. # normalized value
171+
prob[pt+'.fan.PR'] = 1.2
172+
prob[pt+'.balance.W'] = 406.790
173+
prob[pt+'.balance.Nmech'] = 1. # normalized value
168174

169175
st = time.time()
170176

@@ -184,7 +190,7 @@ def setup(self):
184190
print('\n', '#'*10, pt, '#'*10)
185191
viewer(prob, pt)
186192

187-
map_plots(prob,'design')
188-
193+
if plt:
194+
map_plots(prob,'design')
189195

190196
print("Run time", run_time)

0 commit comments

Comments
 (0)