MCPcopy Create free account
hub / github.com/Cantera/cantera / test_interactions

Method test_interactions

test/python/test_reactor.py:3077–3137  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

3075 assert r1.surfaces[0].kinetics.X[kPts] == approx(0.6334801862)
3076
3077 def test_interactions(self):
3078 # Reactors connected by a movable, H2-permeable surface
3079 kH2 = self.gas.species_index("H2")
3080 class TestReactor(ct.ExtensibleIdealGasReactor):
3081 def __init__(self, gas):
3082 super().__init__(gas)
3083 self.neighbor = None
3084 self.h2coeff = 12 # mass transfer coeff
3085 self.p_coeff = 5 # expansion coeff
3086
3087 def after_update_connected(self, do_pressure):
3088 self.conc_H2 = self.thermo.concentrations[kH2]
3089 self.P = self.thermo.P
3090
3091 def replace_eval_walls(self, t):
3092 if self.neighbor:
3093 self.expansion_rate = np.clip(
3094 self.p_coeff * (self.P - self.neighbor.P), -1.7, 1.7)
3095
3096 def after_eval(self, t, LHS, RHS):
3097 if self.neighbor:
3098 mdot_H2 = self.h2coeff * (self.neighbor.conc_H2 - self.conc_H2)
3099 RHS[kH2+3] += mdot_H2
3100 RHS[3:] -= self.thermo.Y * mdot_H2
3101 RHS[0] += mdot_H2
3102 # enthalpy flux is neglected, so energy isn't properly conserved
3103
3104 self.gas.TPX = 300, 2*101325, "H2:0.8, N2:0.2"
3105 r1 = TestReactor(self.gas)
3106 self.gas.TPX = 300, 101325, "H2:0.1, O2:0.9"
3107 r2 = TestReactor(self.gas)
3108 r1.neighbor = r2
3109 r2.neighbor = r1
3110 net = ct.ReactorNet([r1, r2])
3111 states1 = ct.SolutionArray(self.gas, extra=["t", "mass", "vdot"])
3112 states2 = ct.SolutionArray(self.gas, extra=["t", "mass", "vdot"])
3113 net.step()
3114 M0 = r1.mass * r1.thermo.Y + r2.mass * r2.thermo.Y
3115
3116 def deltaC():
3117 return r1.thermo["H2"].concentrations[0] - r2.thermo["H2"].concentrations[0]
3118 deltaCprev = deltaC()
3119
3120 V0 = r1.volume + r2.volume
3121 for t in np.linspace(0.01, 0.2, 50):
3122 net.advance(t)
3123 assert r1.expansion_rate == approx(-r2.expansion_rate)
3124 assert V0 == approx(r1.volume + r2.volume)
3125 deltaCnow = deltaC()
3126 assert deltaCnow < deltaCprev # difference is always decreasing
3127 deltaCprev = deltaCnow
3128 assert M0 == approx(r1.mass * r1.thermo.Y + r2.mass * r2.thermo.Y,rel=2e-8)
3129 states1.append(r1.thermo.state, t=net.time, mass=r1.mass,
3130 vdot=r1.expansion_rate)
3131 states2.append(r2.thermo.state, t=net.time, mass=r2.mass,
3132 vdot=r2.expansion_rate)
3133
3134 # Regression test values

Callers

nothing calls this directly

Calls 6

stepMethod · 0.95
advanceMethod · 0.95
appendMethod · 0.95
SolutionArrayMethod · 0.80
TestReactorClass · 0.70
ReactorNetMethod · 0.45

Tested by

no test coverage detected