mirror of
https://github.com/Cantera/cantera.git
synced 2025-02-25 18:55:29 -06:00
[Reactor] Make argument to ReactorNet.step optional and deprecated
The value of this argument has almost no effect on the integrator, and frequently confuses users since the ReactorNet can end up at a time either greater or less than the specified time. By removing this argument, the distinction betwen step() and advance(t) becomes much more clear.
This commit is contained in:
@@ -107,9 +107,10 @@ public:
|
||||
*/
|
||||
void advance(doublereal time);
|
||||
|
||||
//! Advance the state of all reactors in time. Take a single timestep
|
||||
//! toward *time*.
|
||||
double step(doublereal time);
|
||||
//! Advance the state of all reactors in time.
|
||||
//! @deprecated The *time* argument to this function is deprecated and will
|
||||
//! be removed after Cantera 2.3.
|
||||
double step(doublereal time=-999);
|
||||
|
||||
//@}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ t = 0.0
|
||||
# Rmax is the maximum relative reaction rate at any timestep
|
||||
Rmax = np.zeros(gas.n_reactions)
|
||||
while t < 0.02:
|
||||
t = sim.step(1.0)
|
||||
t = sim.step()
|
||||
tt.append(1000 * t)
|
||||
TT.append(r.T)
|
||||
rnet = abs(gas.net_rates_of_progress)
|
||||
@@ -73,7 +73,7 @@ for i,N in enumerate([40,50,60,70,80]):
|
||||
tt = []
|
||||
TT = []
|
||||
while t < 0.02:
|
||||
t = sim.step(1.0)
|
||||
t = sim.step()
|
||||
tt.append(1000 * t)
|
||||
TT.append(r.T)
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ r = ct.IdealGasReactor(gas)
|
||||
net = ct.ReactorNet([r])
|
||||
T = r.T
|
||||
while T < 1900:
|
||||
net.step(1.0)
|
||||
net.step()
|
||||
T = r.T
|
||||
|
||||
element = 'N'
|
||||
|
||||
@@ -81,7 +81,7 @@ outfile = open('combustor.csv','w')
|
||||
csvwriter = csv.writer(outfile)
|
||||
|
||||
while tnow < tfinal:
|
||||
tnow = sim.step(tfinal)
|
||||
tnow = sim.step()
|
||||
tres = combustor.mass/v.mdot(tnow)
|
||||
Tnow = combustor.T
|
||||
if abs(Tnow - Tprev) > 1.0 or tnow-tprev > 2e-2:
|
||||
|
||||
@@ -764,10 +764,14 @@ cdef class ReactorNet:
|
||||
"""
|
||||
self.net.advance(t)
|
||||
|
||||
def step(self, double t):
|
||||
def step(self, double t=-999):
|
||||
"""
|
||||
Take a single internal time step toward time *t* [s]. The time after
|
||||
taking the step is returned.
|
||||
Take a single internal time step. The time after taking the step is
|
||||
returned.
|
||||
|
||||
.. deprecated:: 2.2
|
||||
The argument *t* is deprecated and will be removed after
|
||||
Cantera 2.3.
|
||||
"""
|
||||
return self.net.step(t)
|
||||
|
||||
|
||||
@@ -363,7 +363,7 @@ class TestReactionPath(utilities.CanteraTest):
|
||||
net = ct.ReactorNet([r])
|
||||
T = r.T
|
||||
while T < 1900:
|
||||
net.step(1.0)
|
||||
net.step()
|
||||
T = r.T
|
||||
|
||||
for element in ['N','C','H','O']:
|
||||
|
||||
@@ -77,7 +77,7 @@ class TestReactor(utilities.CanteraTest):
|
||||
|
||||
def test_component_index(self):
|
||||
self.make_reactors(n_reactors=1)
|
||||
self.net.step(1.0)
|
||||
self.net.step()
|
||||
|
||||
N0 = self.net.n_vars - self.gas1.n_species
|
||||
for i, name in enumerate(self.gas1.species_names):
|
||||
@@ -122,7 +122,7 @@ class TestReactor(utilities.CanteraTest):
|
||||
|
||||
while t < tEnd:
|
||||
tPrev = t
|
||||
t = self.net.step(tEnd)
|
||||
t = self.net.step()
|
||||
self.assertTrue(t - tPrev <= 1.0001 * dt_max)
|
||||
self.assertNear(t, self.net.time)
|
||||
|
||||
@@ -160,7 +160,7 @@ class TestReactor(utilities.CanteraTest):
|
||||
t = 0
|
||||
|
||||
while t < tEnd:
|
||||
t = self.net.step(tEnd)
|
||||
t = self.net.step()
|
||||
nSteps += 1
|
||||
|
||||
return nSteps
|
||||
@@ -426,7 +426,7 @@ class TestReactor(utilities.CanteraTest):
|
||||
|
||||
t = 0
|
||||
while t < 1.0:
|
||||
t = self.net.step(1.0)
|
||||
t = self.net.step()
|
||||
p1 = self.r1.thermo.P
|
||||
p2 = self.r2.thermo.P
|
||||
self.assertNear(mdot(p1-p2), valve.mdot(t))
|
||||
@@ -452,7 +452,7 @@ class TestReactor(utilities.CanteraTest):
|
||||
|
||||
t = 0
|
||||
while t < 1.0:
|
||||
t = self.net.step(1.0)
|
||||
t = self.net.step()
|
||||
self.assertNear(mdot(t), mfc.mdot(t))
|
||||
dP = self.r1.thermo.P - outlet_reservoir.thermo.P
|
||||
self.assertNear(mdot(t) + 1e-5 * dP, pc.mdot(t))
|
||||
@@ -585,7 +585,7 @@ class TestWellStirredReactorIgnition(utilities.CanteraTest):
|
||||
i = 0
|
||||
while t < tf:
|
||||
i += 1
|
||||
t = self.net.step(tf)
|
||||
t = self.net.step()
|
||||
times.append(t)
|
||||
T.append(self.combustor.T)
|
||||
return times, T
|
||||
@@ -706,7 +706,7 @@ class TestConstPressureReactor(utilities.CanteraTest):
|
||||
self.create_reactors(add_surf=True)
|
||||
for (gas,net,iface,r) in ((self.gas1, self.net1, self.interface1, self.r1),
|
||||
(self.gas2, self.net2, self.interface2, self.r2)):
|
||||
net.step(1.0)
|
||||
net.step()
|
||||
|
||||
N0 = net.n_vars - gas.n_species - iface.n_species
|
||||
N1 = net.n_vars - iface.n_species
|
||||
@@ -765,7 +765,7 @@ class TestFlowReactor(utilities.CanteraTest):
|
||||
v0 = r.speed
|
||||
self.assertNear(v0, 10 / r.density)
|
||||
while t < 10.0:
|
||||
t = net.step(10.0)
|
||||
t = net.step()
|
||||
|
||||
self.assertNear(v0, r.speed)
|
||||
self.assertNear(r.distance, v0 * t)
|
||||
@@ -792,7 +792,7 @@ class TestFlowReactor(utilities.CanteraTest):
|
||||
t1 = net.time
|
||||
x1 = r.distance
|
||||
|
||||
t = net.step(1.0)
|
||||
t = net.step()
|
||||
|
||||
v = (r.distance - x1) / (net.time - t1)
|
||||
self.assertNear(r.speed, v, 1e-3)
|
||||
@@ -952,7 +952,7 @@ class TestReactorSensitivities(utilities.CanteraTest):
|
||||
|
||||
for T in (901, 905, 910, 950, 1500):
|
||||
while r2.T < T:
|
||||
net.step(1.0)
|
||||
net.step()
|
||||
|
||||
S = net.sensitivities()
|
||||
|
||||
@@ -984,7 +984,7 @@ class TestReactorSensitivities(utilities.CanteraTest):
|
||||
|
||||
def integrate(r, net):
|
||||
while r.T < 910:
|
||||
net.step(1.0)
|
||||
net.step()
|
||||
return net.sensitivities()
|
||||
|
||||
r1,net1 = setup()
|
||||
@@ -1215,7 +1215,7 @@ class CombustorTestImplementation(object):
|
||||
tfinal = 0.25
|
||||
self.data = []
|
||||
while tnow < tfinal:
|
||||
tnow = self.sim.step(tfinal)
|
||||
tnow = self.sim.step()
|
||||
self.data.append([tnow, self.combustor.T] +
|
||||
list(self.combustor.thermo.X))
|
||||
|
||||
@@ -1280,7 +1280,7 @@ class WallTestImplementation(object):
|
||||
tfinal = 0.01
|
||||
self.data = []
|
||||
while tnow < tfinal:
|
||||
tnow = self.sim.step(tfinal)
|
||||
tnow = self.sim.step()
|
||||
self.data.append([tnow,
|
||||
self.r1.T, self.r2.T,
|
||||
self.r1.thermo.P, self.r2.thermo.P,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
function t = step(r, tout)
|
||||
% STEP Take one internal time step.
|
||||
% t = step(r, tout)
|
||||
% t = step(r)
|
||||
% The integrator used to integrate the ODEs (CVODE) takes
|
||||
% variable-size steps, chosen so that a specified error
|
||||
% tolerance is maintained. At times when the solution is rapidly
|
||||
@@ -19,7 +19,7 @@ function t = step(r, tout)
|
||||
% t = 0.0
|
||||
% tout = 0.1
|
||||
% while t < tout
|
||||
% t = step(r, tout)
|
||||
% t = step(r)
|
||||
% ,,,
|
||||
% <commands to save desired variables>
|
||||
% ...
|
||||
@@ -29,12 +29,11 @@ function t = step(r, tout)
|
||||
%
|
||||
% :param r:
|
||||
% Instance of class :mat:func:`ReactorNet`
|
||||
% :param tout:
|
||||
% End time that the integrator should take one internal time
|
||||
% step towards. This end time may not be reached, or may be
|
||||
% exceeded by the internal time step.
|
||||
% :return:
|
||||
% Network time after the internal time step. Units: s
|
||||
%
|
||||
if nargin == 1
|
||||
tout = -999;
|
||||
end
|
||||
|
||||
t = reactornetmethods(21, reactornet_hndl(r), tout);
|
||||
|
||||
@@ -124,12 +124,16 @@ void ReactorNet::advance(doublereal time)
|
||||
|
||||
double ReactorNet::step(doublereal time)
|
||||
{
|
||||
if (time != -999) {
|
||||
warn_deprecated("ReactorNet::step(t)", "The argument to this function"
|
||||
" is deprecated and will be removed after Cantera 2.3.");
|
||||
}
|
||||
if (!m_init) {
|
||||
initialize();
|
||||
} else if (!m_integrator_init) {
|
||||
reinitialize();
|
||||
}
|
||||
m_time = m_integ->step(time);
|
||||
m_time = m_integ->step(m_time + 1.0);
|
||||
updateState(m_integ->solution());
|
||||
return m_time;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user