.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_tutorials/basics/g_code_listing_01.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_tutorials_basics_g_code_listing_01.py: Basic workflow ============== This examples demonstrates a basic workflow using the `py-fmas` library code. .. codeauthor:: Oliver Melchert .. GENERATED FROM PYTHON SOURCE LINES 11-13 We start by simply importing the required `fmas` into the current namespace. .. GENERATED FROM PYTHON SOURCE LINES 13-16 .. code-block:: default import fmas .. GENERATED FROM PYTHON SOURCE LINES 17-20 If an adequate input file is located within the current working directory, the function `read_h5`, located in module `data_io`, can be used to read-in the propagation setting stored in the input file `input_file.h5`: .. GENERATED FROM PYTHON SOURCE LINES 20-23 .. code-block:: default glob = fmas.data_io.read_h5('input_file.h5') .. GENERATED FROM PYTHON SOURCE LINES 24-26 Next, the problem specific data structures, given by the computational grid and the propagation model, can be initialized: .. GENERATED FROM PYTHON SOURCE LINES 26-41 .. code-block:: default grid = fmas.grid.Grid( t_max = glob.t_max, t_num = glob.t_num, z_max = glob.z_max, z_num = glob.z_num) model = fmas.models.FMAS_S_R( w = grid.w, beta_w = glob.beta_w, n2 = glob.n2, fR = glob.fR, tau1 = glob.tau1, tau2 = glob.tau2) .. GENERATED FROM PYTHON SOURCE LINES 42-44 The provided initial condition, which represents the real-valued optical field can be converted to the complex-valued analytic signal as shown below: .. GENERATED FROM PYTHON SOURCE LINES 44-47 .. code-block:: default ic = fmas.analytic_signal.AS(glob.E_0t) .. GENERATED FROM PYTHON SOURCE LINES 48-51 Below we implement a user-action function that can be passed to the propagation algorithm. Upon propagation it will evaluated at every :math:`z`-step .. GENERATED FROM PYTHON SOURCE LINES 51-58 .. code-block:: default import numpy as np def Cp(i, zi, w, uw): Iw = np.abs(uw)**2 return np.sum(Iw[w>0]/w[w>0]) .. GENERATED FROM PYTHON SOURCE LINES 59-62 Next, we initialzize the :math:`z`-propagation algorithm, given by the `Runge-Kutta in the interaction picture` (RK4IP) method, set the initial condition, and perform :math:`z`-propagation: .. GENERATED FROM PYTHON SOURCE LINES 62-75 .. code-block:: default solver = fmas.solver.IFM_RK4IP( model.Lw, model.Nw, user_action = Cp) solver.set_initial_condition( grid.w, ic.w_rep) solver.propagate( z_range = glob.z_max, n_steps = glob.z_num, n_skip = glob.z_skip) .. GENERATED FROM PYTHON SOURCE LINES 76-80 After the propagation algorithm has terminated, the generated simulation data can be stored within an output file in HDF5-format. Therefore, the data is organized as dictionary with custom keys for the stored data objects, which is then passed to the function `save_h5` implemented in module `data_io`: .. GENERATED FROM PYTHON SOURCE LINES 80-90 .. code-block:: default res = { "t": grid.t, "z": solver.z, "w": solver.w, "u": solver.utz, "Cp": solver.ua_vals} fmas.data_io.save_h5('out_file.h5', **res) .. GENERATED FROM PYTHON SOURCE LINES 91-93 A simple plot of the generated data can be obtained using convenience functions implemented in module `tools`: .. GENERATED FROM PYTHON SOURCE LINES 93-97 .. code-block:: default fmas.tools.plot_evolution( solver.z, grid.t, solver.utz, t_lim = (-500,2200), w_lim = (1.,4.)) .. image:: /auto_tutorials/basics/images/sphx_glr_g_code_listing_01_001.png :alt: $|u|^2/{\rm{max}}\left(|u|^2\right)$, $|u_\omega|^2/{\rm{max}}\left(|u_\omega|^2\right)$ :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 34.082 seconds) .. _sphx_glr_download_auto_tutorials_basics_g_code_listing_01.py: .. only :: html .. container:: sphx-glr-footer :class: sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: g_code_listing_01.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: g_code_listing_01.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_