.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_probabilistic_modeling/stochastic_processes/plot_export_field_vtk.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_probabilistic_modeling_stochastic_processes_plot_export_field_vtk.py: Export a field to VTK ===================== .. GENERATED FROM PYTHON SOURCE LINES 6-12 The objective here is to create a field and export it as a VTK file. A field is the agregation of a mesh :math:`\mathcal{M}` of a domain :math:`\mathcal{D} \in \mathbb{R}^n` and a sample of values in :math:`\mathbb{R}^d` associated to each vertex of the mesh. We note :math:`(\underline{t}_0, \dots, \underline{t}_{N-1})` the vertices of :math:`\mathcal{M}` and :math:`(\underline{x}_0, \dots, \underline{x}_{N-1})` the associated values in :math:`\mathbb{R}^d`. A field is stored in the *Field* object that stores the mesh and the values at each vertex of the mesh. It can be built from a mesh and values or as a realization of a stochastic process. .. GENERATED FROM PYTHON SOURCE LINES 14-20 .. code-block:: default import openturns as ot import openturns.viewer as viewer from matplotlib import pylab as plt import math as m ot.Log.Show(ot.Log.NONE) .. GENERATED FROM PYTHON SOURCE LINES 21-22 First, we define a regular 2-d mesh .. GENERATED FROM PYTHON SOURCE LINES 22-32 .. code-block:: default discretization = [10, 5] mesher = ot.IntervalMesher(discretization) lowerBound = [0.0, 0.0] upperBound = [2.0, 1.0] interval = ot.Interval(lowerBound, upperBound) mesh = mesher.build(interval) graph = mesh.draw() graph.setTitle('Regular 2-d mesh') view = viewer.View(graph) .. image-sg:: /auto_probabilistic_modeling/stochastic_processes/images/sphx_glr_plot_export_field_vtk_001.png :alt: Regular 2-d mesh :srcset: /auto_probabilistic_modeling/stochastic_processes/images/sphx_glr_plot_export_field_vtk_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 33-34 We now create a field from a mesh and some values .. GENERATED FROM PYTHON SOURCE LINES 34-41 .. code-block:: default values = ot.Normal([0.0]*2, [1.0]*2, ot.CorrelationMatrix(2) ).getSample(len(mesh.getVertices())) for i in range(len(values)): x = values[i] values[i] = 0.05 * x / x.norm() field = ot.Field(mesh, values) .. GENERATED FROM PYTHON SOURCE LINES 42-44 We can export the `field` to a VTK files. It can be read later with an external program such as Paraview. .. GENERATED FROM PYTHON SOURCE LINES 44-46 .. code-block:: default field.exportToVTKFile('field.vtk') .. GENERATED FROM PYTHON SOURCE LINES 47-48 Display figures .. GENERATED FROM PYTHON SOURCE LINES 48-49 .. code-block:: default plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.139 seconds) .. _sphx_glr_download_auto_probabilistic_modeling_stochastic_processes_plot_export_field_vtk.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: plot_export_field_vtk.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_export_field_vtk.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_