.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "generated/gallery/single_trapezoid_event.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. .. rst-class:: sphx-glr-example-title .. _sphx_glr_generated_gallery_single_trapezoid_event.py: Using an Asymmetric Heating Profile Under the Single-fluid Approximation ======================================================================== In this example, we force the electron and ion populations to have the same temperature to illustrate the single fluid case. .. GENERATED FROM PYTHON SOURCE LINES 7-20 .. code-block:: Python import astropy.units as u import matplotlib.pyplot as plt import numpy as np from astropy.visualization import quantity_support import ebtelplusplus from ebtelplusplus.models import DemModel, HeatingEvent, HeatingModel, PhysicsModel quantity_support() .. rst-class:: sphx-glr-script-out .. code-block:: none .MplQuantityConverter object at 0x71408bbee480> .. GENERATED FROM PYTHON SOURCE LINES 21-26 Set up a trapezoidal heating profile that rises for 250 s, stays constant for 750 s at a heating rate of 0.05 erg per cubic centimeter per second, and then decays linearly to the background rate over the course of 1000 s. .. GENERATED FROM PYTHON SOURCE LINES 26-32 .. code-block:: Python event = HeatingEvent(0*u.s, 2000*u.s, 250*u.s, 1000*u.s, 0.005*u.Unit('erg cm-3 s-1')) .. GENERATED FROM PYTHON SOURCE LINES 33-35 In this heating model, we equally partition the injected energy between the electrons and the ions. .. GENERATED FROM PYTHON SOURCE LINES 35-39 .. code-block:: Python heating = HeatingModel(background=3.5e-5*u.Unit('erg cm-3 s-1'), partition=0.5, events=[event]) .. GENERATED FROM PYTHON SOURCE LINES 40-42 Note that we also need to enforce the single-fluid requirement in our physics model. .. GENERATED FROM PYTHON SOURCE LINES 42-44 .. code-block:: Python physics = PhysicsModel(force_single_fluid=True) .. GENERATED FROM PYTHON SOURCE LINES 45-48 Now run the simulation for a 40 Mm loop lasting a total of 3 h. We'll also specify that we want to compute the DEM .. GENERATED FROM PYTHON SOURCE LINES 48-54 .. code-block:: Python result = ebtelplusplus.run(5e3*u.s, 40*u.Mm, heating=heating, physics=physics, dem=DemModel(calculate_dem=True)) .. GENERATED FROM PYTHON SOURCE LINES 55-57 Let's visualize the heating profile, temperature, and density as a function of time. .. GENERATED FROM PYTHON SOURCE LINES 57-64 .. code-block:: Python fig, axes = plt.subplots(3, 1, sharex=True) axes[0].plot(result.time, result.heat) axes[1].plot(result.time, result.electron_temperature, label='electron') axes[1].plot(result.time, result.ion_temperature, label='ion') axes[2].plot(result.time, result.density) axes[1].legend() .. image-sg:: /generated/gallery/images/sphx_glr_single_trapezoid_event_001.png :alt: single trapezoid event :srcset: /generated/gallery/images/sphx_glr_single_trapezoid_event_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 65-68 Finally, let's visualize the DEM distribution. We'll first time-average each component over the duration of the simulation. .. GENERATED FROM PYTHON SOURCE LINES 68-79 .. code-block:: Python delta_t = np.gradient(result.time) dem_avg_total = np.average(result.dem_tr+result.dem_corona, axis=0, weights=delta_t) dem_avg_tr = np.average(result.dem_tr, axis=0, weights=delta_t) dem_avg_corona = np.average(result.dem_corona, axis=0, weights=delta_t) .. GENERATED FROM PYTHON SOURCE LINES 80-81 And now we can plot each component .. GENERATED FROM PYTHON SOURCE LINES 81-93 .. code-block:: Python fig = plt.figure() ax = fig.add_subplot() ax.plot(result.dem_temperature, dem_avg_total, label='Total') ax.plot(result.dem_temperature, dem_avg_tr, label='TR') ax.plot(result.dem_temperature, dem_avg_corona, label='Corona') ax.set_xlim([10**(4.5), 10**(7.5)]*u.K) ax.set_ylim([10**(20.0), 10**(23.5)]*u.Unit('cm-5 K-1')) ax.set_xscale('log') ax.set_yscale('log') ax.legend() plt.show() .. image-sg:: /generated/gallery/images/sphx_glr_single_trapezoid_event_002.png :alt: single trapezoid event :srcset: /generated/gallery/images/sphx_glr_single_trapezoid_event_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.212 seconds) .. _sphx_glr_download_generated_gallery_single_trapezoid_event.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: single_trapezoid_event.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: single_trapezoid_event.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: single_trapezoid_event.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_