PageRenderTime 66ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/docs/source/install/examples.rst

https://code.google.com/p/pysph/
ReStructuredText | 176 lines | 129 code | 47 blank | 0 comment | 0 complexity | 825d15c44deb821355a0c860bc31e8a1 MD5 | raw file
  1. .. _examples:
  2. ----------------------
  3. Running the examples
  4. ----------------------
  5. The :file:`examples` directory is the best place to start off using
  6. PySPH. In it are examples for the different solvers implemented in
  7. for PySPH. The directory structure is shown below::
  8. examples/
  9. | -- controller
  10. | `-- mimic
  11. | -- dam-break
  12. | -- shock-tube
  13. ` -- stress
  14. Files in the :file:`examples` directory are "examples" that are used for
  15. validation. That is, they don't fit into the testing framework and
  16. they are not exactly examples.
  17. Each directory contains related examples. The relation being the type
  18. of solver employed. Thus, all examples in the :file:`shock-tube`
  19. directory employ a solver for the Euler equations while files in the
  20. :file:`stress` directory employ a solver that incorporates linear
  21. material strength.
  22. All examples can be run like so::
  23. $ cd <example_directory>
  24. $ python example.py [options]
  25. Output for the examples will be placed in a directory
  26. :file:`example_output` and output files will have the file-name
  27. :file:`example_pid_count.npz`, where :token:`pid` is the processor
  28. rank that created this file (default is 0 for serial runs) and
  29. :token:`count` is the iteration count for the solution output.
  30. Each example accepts command line arguments which may vary depending
  31. on the kind of solver employed. To get a list of valid options::
  32. $ python example.py -h
  33. -------------------------------------------------------
  34. Simple examples to try
  35. -------------------------------------------------------
  36. The following examples should not take too long to run and you should
  37. see some nice output. You would need to install Mayavi_ to use the
  38. PySPH viewer for the 2D examples.
  39. + :file:`examples/nbody.py`: An N-Body problem (:doc:`../intro/getting_started`)::
  40. $ python nbody.py --final-time=1
  41. $ pysph_viewer
  42. + :file:`examples/dam-break/dam_break_simple.py`: A 2D dam break
  43. problem with few particles.::
  44. $ python dam_break_simple.py &
  45. $ pysph_viewer
  46. + :file:`examples/stress/stress2d_balls.py`: 2D elastic collision of two balls::
  47. $ python stress2d_balls.py &
  48. $ pysph_viewer
  49. + :file:`examples/shock-tube/2D/noh.py`: A cylindrical implosion of
  50. gas that produces a shock that moves radially outward.::
  51. $ python noh.py
  52. $ pysph_viewer
  53. + :file:`examples/elliptical_drop.py`: An initially circular patch of
  54. incompressible fluid that deforms to an ellipse.::
  55. $ python examples.py
  56. $ pysph_viewer
  57. + :file:`examples/shock-tube/wc_blastwave.py`: A 1D simulation of 2
  58. blast waves that collide with each other. Refer to
  59. :doc:`../tutorials/shock_tube` to see how to view the results.
  60. -------------------------------------------------------
  61. Example: Running a dam break simulation with PySPH
  62. -------------------------------------------------------
  63. The above generic procedure to run an example is demonstrated by way
  64. of a concrete example, the 2D dam break problem. The example file we
  65. will be referring to is
  66. :file:`examples/dam-break/dam_break_wet_bed.py`, which simulates the
  67. evolution of a breaking dam in the presence of a wet bed of fluid as
  68. shown in the figure:
  69. .. _figure-wet-bed:
  70. .. figure:: ../images/wet-bed.png
  71. :align: center
  72. :width: 350
  73. The vertical gate is removed at a constant velocity of :math:`v =
  74. 1.5m/s`. The fluid is free to fall under the effect of gravity. The
  75. no-penetration boundary condition is applied at the solid walls. This
  76. example is defined as `SPHERIC
  77. <http://www.wiki.manchester.ac.uk/spheric/index.php/SPHERIC_Home_Page>`_
  78. validation case.
  79. The example can be run like so::
  80. $ cd examples/dam-break
  81. $ python dam_break_wet_bed.py
  82. A small progress indicator informs about the status of the
  83. example. The output files for this example are created in the
  84. directory :file:`dam_break_wet_bed_output`.
  85. If you are looking to run a quick example, the
  86. :file:`dam_break_simple.py` runs rather quickly.
  87. """""""""""""""""""""""""""""""""
  88. Viewing the output
  89. """""""""""""""""""""""""""""""""
  90. Viewing a running simulation
  91. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  92. There are two ways to view the output. You can view the output as the
  93. solver is running and depending on the simulation you may need to be
  94. patient. By default every solver will start up a special solver
  95. interface that can be used to view and control the running simulation.
  96. More internal details can be seen in :doc:`here
  97. </design/solver_interfaces>`. The upshot here is that you can view the
  98. results of the simulation while the solver is running. The results are
  99. most easily visualized using the `Mayavi
  100. <http://www.code.enthought.com/projects/mayavi>`_ viewer, this will work
  101. only if you have Mayavi installed. If you have Mayavi installed you may
  102. view the results by running the following command in another shell::
  103. $ pysph_viewer
  104. This will pop-up a full fledged UI with which you can view a running
  105. simulation. The solver will continue to run regardless of the state of
  106. the viewer so you may close the window at any time. The viewer has
  107. several options to see a listing of this run the following::
  108. $ pysph_viewer -h
  109. Viewing the output of a simulation
  110. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  111. Given a bunch of output files, like those generated by running the
  112. example above, you can view the output files as follows::
  113. $ cd dam_break_wet_bed_output
  114. $ pysph_viewer *.npz
  115. The viewer will load all available solution files starting from the
  116. initial configuration (:token:`count` 0). The current file is
  117. displayed in the left pane of the viewer. Also in the left pane are
  118. tabs for the different entities present in the simulation
  119. (:token:`gate`, :token:`tank`, :token:`fluid`). Ensure that the
  120. :guilabel:`Show legend` checkbox is only checked for the
  121. :guilabel:`fliud` tab. Now you can watch an animation of the solution
  122. by checking the :guilabel:`Play` checkbox in the upper part of the
  123. left pane. What results is an animation of the evolution with particle
  124. positions colored by their density values.
  125. You can also instruct the viewer to dump a sequence of :file:`.png`
  126. files by checking the :guilabel:`Record` checkbox under the
  127. :guilabel:`Movie` tab. This will produce a sequence of files named
  128. :file:`frame<frameno>.png` in the
  129. :file:`dam_break_wet_bed_output/movie` directory.