.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples_gallery/storing_data.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_examples_gallery_storing_data.py: Storing data during simulation ============================== Example of how to store data during a simulation. .. GENERATED FROM PYTHON SOURCE LINES 8-36 .. image-sg:: /examples_gallery/images/sphx_glr_storing_data_001.png :alt: storing data :srcset: /examples_gallery/images/sphx_glr_storing_data_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none /home/docs/.asdf/installs/python/3.13.9/lib/python3.13/zipfile/__init__.py:1642: UserWarning: Duplicate name: 'trajectory/.zattrs' return self._open_to_write(zinfo, force_zip64=force_zip64) /home/docs/.asdf/installs/python/3.13.9/lib/python3.13/zipfile/__init__.py:1642: UserWarning: Duplicate name: 'trajectory/.zattrs' return self._open_to_write(zinfo, force_zip64=force_zip64) /home/docs/.asdf/installs/python/3.13.9/lib/python3.13/zipfile/__init__.py:1642: UserWarning: Duplicate name: 'trajectory/data/.zarray' return self._open_to_write(zinfo, force_zip64=force_zip64) /home/docs/.asdf/installs/python/3.13.9/lib/python3.13/zipfile/__init__.py:1642: UserWarning: Duplicate name: 'trajectory/time/.zarray' return self._open_to_write(zinfo, force_zip64=force_zip64) /home/docs/.asdf/installs/python/3.13.9/lib/python3.13/zipfile/__init__.py:1642: UserWarning: Duplicate name: 'trajectory/data/.zarray' return self._open_to_write(zinfo, force_zip64=force_zip64) /home/docs/.asdf/installs/python/3.13.9/lib/python3.13/zipfile/__init__.py:1642: UserWarning: Duplicate name: 'trajectory/time/.zarray' return self._open_to_write(zinfo, force_zip64=force_zip64) {'actors': [{'class': 'DiffusionActor', 'parameters': {'boundary_conditions': 'auto_periodic_neumann', 'diffusivity': 1.0}, 'pde': {'class': 'DiffusionPDE'}, 'element_names': ['background']}, {'class': 'SphericalDropletActor', 'parameters': {'background_correction': False, 'diffusivity': 1.0, 'drift_enabled': True, 'equilibrium_concentration': '1e-5 / radius', 'mean_reaction_inside': 'automatic', 'num_threads': 1, 'reaction_outside': '0', 'shell_sector_count': 6, 'shell_sector_method': 'size', 'shell_sector_size': 'dx', 'shell_thickness': 'dx'}, 'element_names': ['droplets', 'background']}], 'controller': {'mpi_run': False, 't_start': 0, 't_end': 10.0, 'profiler': {'solver': 0.0, 'tracker': 0.0}}, 'item_type': 'object', 'package_version': '0.57.0', 'solver': {'class': 'SimulationSolver'}, 'state': {'parameters': {'bounds': None, 'invisible_elements': set(), 'plot_args': {}}}} | .. code-block:: Python from droplets import SphericalDroplet from pde import ScalarField, UnitGrid import emulsim # set up state grid = UnitGrid([32, 32], periodic=True) background = emulsim.ScalarFieldElement.from_field(ScalarField(grid, 0.1)) droplet_data = [SphericalDroplet(grid.get_random_point(), 1) for _ in range(3)] droplets = emulsim.SphericalDropletsElement.from_droplets(droplet_data) state = emulsim.State({"background": background, "droplets": droplets}) # set up simulation simulation = emulsim.Simulation(state) simulation.add_actor("background", emulsim.DiffusionActor()) simulation.add_actor(("droplets", "background"), emulsim.SphericalDropletActor()) # run simulation and store data periodically tracker = emulsim.TrajectoryTracker( "trajectory.zip", interrupts=2, mode="truncate", info=simulation.info ) simulation.run(t_range=10, tracker=tracker) # retrieve data and plot last state stored_data = emulsim.Trajectory("trajectory.zip") print(stored_data.info) # recover the auxillary information stored_data[-1].plot() # plot the last time point of the stored data .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 6.001 seconds) .. _sphx_glr_download_examples_gallery_storing_data.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: storing_data.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: storing_data.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: storing_data.zip `