.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples_tutorials/example_analyticsol.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_examples_tutorials_example_analyticsol.py: ================================================================================ Analytical solutions ================================================================================ Example of analytical solution computing. .. GENERATED FROM PYTHON SOURCE LINES 9-17 .. code-block:: default import os import numpy as np import matplotlib.pyplot as plt from matplotlib import cm import matplotlib.tri as mtri import freshkiss3d as fk import freshkiss3d.extra.plots as fk_plt .. GENERATED FROM PYTHON SOURCE LINES 18-23 Plotting functions: -------------------- Visualization are scaled by a factor 2 in the z-direction. .. GENERATED FROM PYTHON SOURCE LINES 24-56 .. code-block:: default scale = 2. def create_figure(time): plt.rcParams["figure.figsize"] = [10, 8] fig = plt.figure() ax = fig.add_subplot(111, projection='3d') H = np.asarray(thacker2d_analytic.H) z = np.asarray(thacker2d_analytic.topography) elevation = np.asarray(thacker2d_analytic.elevation) NT = triangular_mesh.NT triang = mtri.Triangulation(x, y, trivtx) triang2 = mtri.Triangulation(TG.x, TG.y, TG.trivtx) #set-up masked triangles: isbad = np.ndarray( (NT), dtype=bool) for T in range(NT): eps = 1.e-5 V0 = TG.trivtx[T,0] V1 = TG.trivtx[T,1] V2 = TG.trivtx[T,2] isbad_0 = np.greater(eps, H[V0]) isbad_1 = np.greater(eps, H[V1]) isbad_2 = np.greater(eps, H[V2]) isbad[T] = isbad_0 or isbad_1 or isbad_2 triang.set_mask(isbad) ax.plot_trisurf(triang2, scale*z, lw=0.01, edgecolor="w", color='grey', alpha=0.2) csetb = ax.tricontour(triang2, scale*z, 1, zdir='x', offset=4, color='grey') csetb = ax.tricontour(triang2, scale*z, 1, zdir='y', offset=0, color='grey') ax.plot_trisurf(triang, scale*elevation, lw=0.0, edgecolor="w", cmap=cm.jet,alpha=0.9) cset = ax.tricontour(triang, scale*elevation, 1, zdir='x', offset=4, cmap=cm.coolwarm) cset = ax.tricontour(triang, scale*elevation, 1, zdir='y', offset=0, cmap=cm.coolwarm) ax.set_title("Free surface at time={}".format(time)) .. GENERATED FROM PYTHON SOURCE LINES 57-59 Mesh: -------------------- .. GENERATED FROM PYTHON SOURCE LINES 60-74 .. code-block:: default os.system('gmsh -2 -format msh2 ../simulations/inputs/thacker2d_huge.geo -o inputs/thacker2d.msh') TG, vertex_labels, boundary_labels = fk.read_msh('inputs/thacker2d.msh') os.system('rm inputs/thacker2d.msh') x = np.asarray(TG.x) y = np.asarray(TG.y) trivtx = np.asarray(TG.trivtx) x *= 0.4 y *= 0.4 triangular_mesh = fk.TriangularMesh(TG, vertex_labels, boundary_labels) .. GENERATED FROM PYTHON SOURCE LINES 75-80 Define analytic solution: --------------------------- First a object Thacker2D containning the thacker 2d analytic solution needs to be declared: .. GENERATED FROM PYTHON SOURCE LINES 81-91 .. code-block:: default when = [0., 0.5, 1., 1.5] thacker2d_analytic = fk.Thacker2D(triangular_mesh, a=1., h0=0.1, compute_error=True, error_type='L2', error_output='none') .. GENERATED FROM PYTHON SOURCE LINES 92-94 .. warning:: When comparisons with analytic solution have to be performed, make sure topography given to problem.layer is inherited from 'analytic_sol'.topography .. GENERATED FROM PYTHON SOURCE LINES 97-102 Compute analytic solution: --------------------------- Then you can call the thacker2d_analytic() method in order to compute the analytic solution at a given time: .. GENERATED FROM PYTHON SOURCE LINES 103-110 .. code-block:: default for time in when: thacker2d_analytic(time) create_figure(time) plt.show() .. rst-class:: sphx-glr-horizontal * .. image-sg:: /auto_examples_tutorials/images/sphx_glr_example_analyticsol_001.png :alt: Free surface at time=0.0 :srcset: /auto_examples_tutorials/images/sphx_glr_example_analyticsol_001.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples_tutorials/images/sphx_glr_example_analyticsol_002.png :alt: Free surface at time=0.5 :srcset: /auto_examples_tutorials/images/sphx_glr_example_analyticsol_002.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples_tutorials/images/sphx_glr_example_analyticsol_003.png :alt: Free surface at time=1.0 :srcset: /auto_examples_tutorials/images/sphx_glr_example_analyticsol_003.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples_tutorials/images/sphx_glr_example_analyticsol_004.png :alt: Free surface at time=1.5 :srcset: /auto_examples_tutorials/images/sphx_glr_example_analyticsol_004.png :class: sphx-glr-multi-img .. rst-class:: sphx-glr-script-out .. code-block:: none /builds/builds/y49yFuNK/0/freshkiss3d/freshkiss3d/examples/tutorials/example_analyticsol.py:49: UserWarning: The following kwargs were not used by contour: 'color' csetb = ax.tricontour(triang2, scale*z, 1, zdir='x', offset=4, color='grey') /builds/builds/y49yFuNK/0/freshkiss3d/freshkiss3d/examples/tutorials/example_analyticsol.py:50: UserWarning: The following kwargs were not used by contour: 'color' csetb = ax.tricontour(triang2, scale*z, 1, zdir='y', offset=0, color='grey') .. GENERATED FROM PYTHON SOURCE LINES 111-112 .. note:: When solving a problem (i.e. using problem.solve()), you can pass 'thacker2d_analytic' trough 'analitic_sol' parameter that will automaticly compute analytical solution during iteration process. See API for more information. .. GENERATED FROM PYTHON SOURCE LINES 115-116 .. seealso:: A wide variety of analytic solutions for single layer Saint-Venant system can be found in: https://hal.archives-ouvertes.fr/hal-00628246/document .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 26.204 seconds) .. _sphx_glr_download_auto_examples_tutorials_example_analyticsol.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: example_analyticsol.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: example_analyticsol.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_