.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/05_engineering/plot_02_cstr_control.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code or to run this example in your browser via Binder. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_05_engineering_plot_02_cstr_control.py: Controlling an exothermic reactor at its unstable steady state ============================================================== A continuous stirred tank reactor with an exothermic first-order reaction has three steady states; the middle one is open-loop unstable (Seborg et al., 2016). The controller must move the reactor temperature from 350 K to 355 K and reject a 3 K rise of the feed temperature without a dangerous temperature excursion. Two controller families are tuned interactively: a PID with setpoint weighting, and a dynamic matrix controller (DMC; Cutler and Ramaker, 1980) supervising a stabilizing inner proportional loop. .. GENERATED FROM PYTHON SOURCE LINES 15-17 PID and DMC, the same simulated engineer ---------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 17-29 .. code-block:: Python import matplotlib.pyplot as plt import easyiec as ei from easyiec.problems import CSTRControl from easyiec.strategies import InteractiveCMAES results = {} for controller in ["pid", "dmc"]: problem = CSTRControl(controller=controller) user = ei.SimulatedUser(problem, target="default", noise=0.04, seed=2) results[controller] = (problem, ei.run(problem, InteractiveCMAES(pop_size=8), user, generations=12, seed=2)) print(controller, problem.describe(results[controller][1].best.genome)) .. rst-class:: sphx-glr-script-out .. code-block:: none pid PID controller (Kc=11.1, Ti=0.212, Td=0.00113, b=0.251). Setpoint 350→355 K: IAE=0.77 K·min, overshoot=0.0 %, settling=1.00 min, peak T=355.1 K; disturbance IAE=0.03; coolant total variation=45.4 K. dmc DMC controller (P=30, M=2, lambda=0.173, alpha=0.214). Setpoint 350→355 K: IAE=0.68 K·min, overshoot=0.0 %, settling=1.03 min, peak T=355.2 K; disturbance IAE=0.07; coolant total variation=56.4 K. .. GENERATED FROM PYTHON SOURCE LINES 30-34 The chosen responses -------------------- Reactor temperature, coolant temperature and concentration for the best PID and the best DMC tuning. .. GENERATED FROM PYTHON SOURCE LINES 34-39 .. code-block:: Python fig, axes = plt.subplots(1, 2, figsize=(10, 4)) for ax, (c, (problem, res)) in zip(axes, results.items()): problem.render(res.best.genome, ax=ax) ax.set_title(f"{c.upper()}: best true utility {res.best_true:.2f}", fontsize=9) .. image-sg:: /auto_examples/05_engineering/images/sphx_glr_plot_02_cstr_control_001.png :alt: PID: best true utility 0.65, DMC: best true utility 0.74 :srcset: /auto_examples/05_engineering/images/sphx_glr_plot_02_cstr_control_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 40-42 Progress of the two sessions ---------------------------- .. GENERATED FROM PYTHON SOURCE LINES 42-47 .. code-block:: Python ax = None for k, (c, (_, res)) in enumerate(results.items()): ax = ei.viz.plot_anytime(res, ax=ax, label=c.upper(), color=["#285780", "#D55E00"][k], show_shown=False) ax.legend(frameon=False, fontsize=8) plt.show() .. image-sg:: /auto_examples/05_engineering/images/sphx_glr_plot_02_cstr_control_002.png :alt: plot 02 cstr control :srcset: /auto_examples/05_engineering/images/sphx_glr_plot_02_cstr_control_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 20.506 seconds) .. _sphx_glr_download_auto_examples_05_engineering_plot_02_cstr_control.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: binder-badge .. image:: images/binder_badge_logo.svg :target: https://mybinder.org/v2/gh/ComplexSystemsIntelligence/easyiec/main?urlpath=lab/tree/notebooks/auto_examples/05_engineering/plot_02_cstr_control.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_02_cstr_control.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_02_cstr_control.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_02_cstr_control.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_