Skip to content

Commit ffefdae

Browse files
Switched back to returning boolean from XRotor.operate, and expose rms as property instead.
1 parent 5942367 commit ffefdae

File tree

4 files changed

+22
-9
lines changed

4 files changed

+22
-9
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from setuptools.extension import Extension
2525
from setuptools.command.build_ext import build_ext
2626

27-
version = '0.0.8'
27+
version = '0.0.9'
2828

2929
options = {k: 'OFF' for k in ['--opt', '--debug', '--cuda']}
3030
for flag in options.keys():

src/fortran/interface.f90

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,11 @@ subroutine save_prop() bind(c, name='save_prop')
125125
call save(ctxt, 'output.prop')
126126
end subroutine save_prop
127127

128+
function get_rms() bind(c, name='get_rms')
129+
real(c_float) :: get_rms
130+
get_rms = ctxt%rms
131+
end function get_rms
132+
128133
subroutine get_performance(rpm, thrust, torque, power, efficiency) bind(c, name='get_performance')
129134
real(c_float), intent(out) :: rpm, thrust, torque, power, efficiency
130135

src/xrotor/test.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,13 @@ def test_solve_for_rpm(self):
9494
"""
9595
xr = XRotor()
9696
xr.case = Case.from_dict(case)
97-
rms = xr.operate(1, 2000)
97+
conv = xr.operate(1, 2000)
9898
perf = xr.performance
9999

100100
print_perf(perf)
101101

102-
self.assertTrue(rms < 1.0e-7)
102+
self.assertTrue(conv)
103+
self.assertTrue(xr.rms < 1.0e-7)
103104
self.assertAlmostEqual(perf.rpm, 2000, 0)
104105
self.assertAlmostEqual(perf.thrust, 481, 0)
105106
self.assertAlmostEqual(perf.torque, 105, 0)
@@ -117,12 +118,13 @@ def test_solve_for_thrust(self):
117118
"""
118119
xr = XRotor()
119120
xr.case = Case.from_dict(case)
120-
rms = xr.operate(2, 500)
121+
conv = xr.operate(2, 500)
121122
perf = xr.performance
122123

123124
print_perf(perf)
124125

125-
self.assertTrue(rms < 1.0e-7)
126+
self.assertTrue(conv)
127+
self.assertTrue(xr.rms < 1.0e-7)
126128
self.assertAlmostEqual(perf.rpm, 2019, 0)
127129
self.assertAlmostEqual(perf.thrust, 500, 0)
128130
self.assertAlmostEqual(perf.torque, 107, 0)

src/xrotor/xrotor.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ def __init__(self):
5050
self._lib = cdll.LoadLibrary(self._lib_path)
5151

5252
self._lib.get_print.restype = c_bool
53-
self._lib.operate.restype = c_float
53+
self._lib.operate.restype = c_bool
54+
self._lib.get_rms.restype = c_float
5455

5556
self._lib.init()
5657
self._case: Case = None
@@ -121,6 +122,11 @@ def station_conditions(self):
121122
self._lib.get_station_conditions(byref(c_int(n)), xi.ctypes.data_as(fptr), re.ctypes.data_as(fptr))
122123
return xi, re
123124

125+
@property
126+
def rms(self):
127+
"""float: The root-mean-squared error of the last XRotor analysis."""
128+
return float(self._lib.get_rms())
129+
124130
def operate(self, specify, value):
125131
"""Operate the propeller at a specified RPM or thrust.
126132
@@ -133,10 +139,10 @@ def operate(self, specify, value):
133139
134140
Returns
135141
-------
136-
rms : float
137-
Root-mean-squared error of XRotor's convergence. XRotor considers itself converged if rms < 1.0e-7.
142+
conv : bool
143+
True is XRotor converged.
138144
"""
139-
return float(self._lib.operate(byref(c_int(specify)), byref(c_float(value))))
145+
return self._lib.operate(byref(c_int(specify)), byref(c_float(value)))
140146

141147
def print_case(self):
142148
"""Print the characteristics of the run case at the last operating point to the terminal."""

0 commit comments

Comments
 (0)