#! /usr/bin/env python3 # def ns2de_matplotlib ( header, n, x, y, u, v, p, s ): #*****************************************************************************80 # ## NS2DE_MATPLOTLIB plots a velocity vector field with MATPLOTLIB. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 22 July 2015 # # Author: # # John Burkardt # # Parameters: # # Input, string HEADER, a header to be used to name the files. # # Input, integer N, the number of evaluation points. # # Input, real X(N), Y(N), the coordinates of the evaluation points. # # Input, real U(N), V(N), P(N), the solution samples. # # Input, real S, a scale factor for the velocity vectors. # import matplotlib.pyplot as plt myplot = plt.figure ( ) ax = plt.gca ( ) ax.quiver ( x, y, u, v ) ax.set_xlabel ( '<--X-->' ) ax.set_ylabel ( '<--Y-->' ) ax.set_title ( header ) ax.axis ( 'equal' ) plt.draw ( ) plt.show ( ) plot_filename = header + '_matplotlib.png' myplot.savefig ( plot_filename ) return def ns2de_matplotlib_lukas_test ( ): #*****************************************************************************80 # ## NS2DE_MATPLOTLIB_LUKAS_TEST plots a Lukas Bystricky velocity field. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 07 March 2015 # # Author: # # John Burkardt # import platform from grid_2d import grid_2d from uvp_lukas import uvp_lukas print ( '' ) print ( 'NS2DE_MATPLOTLIB_LUKAS_TEST:' ) print ( ' Python version: %s' % ( platform.python_version ( ) ) ) print ( ' Generate a Lukas Bystricky Flow field on a regular grid.' ) print ( ' Display it using MATPLOTLIB' ) x_lo = 0.0 x_hi = 1.0 x_num = 21 y_lo = 0.0 y_hi = 1.0 y_num = 21 x, y = grid_2d ( x_num, x_lo, x_hi, y_num, y_lo, y_hi ) nu = 1.0 rho = 1.0 n = x_num * y_num t = 0.0 u, v, p = uvp_lukas ( nu, rho, n, x, y, t ) header = 'lukas' s = 0.25 ns2de_matplotlib ( header, n, x, y, u, v, p, s ) # # Terminate. # print ( '' ) print ( 'NS2DE_MATPLOTLIB_LUKAS_TEST:' ) print ( ' Normal end of execution.' ) return def ns2de_matplotlib_poiseuille_test ( ): #*****************************************************************************80 # ## NS2DE_MATPLOTLIB_POISEUILLE_TEST plots a Poiseuille velocity field. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 22 July 2015 # # Author: # # John Burkardt # import platform from grid_2d import grid_2d from uvp_poiseuille import uvp_poiseuille print ( '' ) print ( 'NS2DE_MATPLOTLIB_POISEUILLE_TEST:' ) print ( ' Python version: %s' % ( platform.python_version ( ) ) ) print ( ' Generate a Poiseuille velocity field on a regular grid.' ) print ( ' Display it using MATPLOTLIB' ) x_lo = 0.0 x_hi = 6.0 x_num = 61 y_lo = -1.0 y_hi = +1.0 y_num = 21 x, y = grid_2d ( x_num, x_lo, x_hi, y_num, y_lo, y_hi ) nu = 1.0 rho = 1.0 n = x_num * y_num t = 0.0 u, v, p = uvp_poiseuille ( nu, rho, n, x, y, t ) header = 'poiseuille' s = 5.0 ns2de_matplotlib ( header, n, x, y, u, v, p, s ) # # Terminate. # print ( '' ) print ( 'NS2DE_MATPLOTLIB_POISEUILLE_TEST:' ) print ( ' Normal end of execution.' ) return def ns2de_matplotlib_spiral_test ( ): #*****************************************************************************80 # ## NS2DE_MATPLOTLIB_SPIRAL_TEST plots a Spiral velocity field. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 31 January 2015 # # Author: # # John Burkardt # import platform from grid_2d import grid_2d from uvp_spiral import uvp_spiral print ( '' ) print ( 'NS2DE_MATPLOTLIB_SPIRAL_TEST:' ) print ( ' Python version: %s' % ( platform.python_version ( ) ) ) print ( ' Generate a Spiral Flow velocity field on a regular grid.' ) print ( ' Display it using MATPLOTLIB' ) x_lo = 0.0 x_hi = 1.0 x_num = 21 y_lo = 0.0 y_hi = 1.0 y_num = 21 x, y = grid_2d ( x_num, x_lo, x_hi, y_num, y_lo, y_hi ) nu = 1.0 rho = 1.0 n = x_num * y_num t = 0.0 u, v, p = uvp_spiral ( nu, rho, n, x, y, t ) header = 'spiral' s = 5.0 ns2de_matplotlib ( header, n, x, y, u, v, p, s ) # # Terminate. # print ( '' ) print ( 'NS2DE_MATPLOTLIB_SPIRAL_TEST:' ) print ( ' Normal end of execution.' ) return def ns2de_matplotlib_taylor_test ( ): #*****************************************************************************80 # ## NS2DE_MATPLOTLIB_TAYLOR_TEST plots a Taylor Flow field. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 23 January 2015 # # Author: # # John Burkardt # import platform from grid_2d import grid_2d from uvp_taylor import uvp_taylor print ( '' ) print ( 'NS2DE_MATPLOTLIB_TAYLOR_TEST:' ) print ( ' Python version: %s' % ( platform.python_version ( ) ) ) print ( ' Generate a Taylor velocity field on a regular grid.' ) print ( ' Display it using MATPLOTLIB' ) x_lo = 0.5 x_hi = 2.5 x_num = 21 y_lo = 0.5 y_hi = 2.5 y_num = 21 x, y = grid_2d ( x_num, x_lo, x_hi, y_num, y_lo, y_hi ) nu = 1.0 rho = 1.0 n = x_num * y_num t = 0.0 u, v, p = uvp_taylor ( nu, rho, n, x, y, t ) header = 'taylor' s = 0.10 ns2de_matplotlib ( header, n, x, y, u, v, p, s ) # # Terminate. # print ( '' ) print ( 'NS2DE_MATPLOTLIB_TAYLOR_TEST:' ) print ( ' Normal end of execution.' ) return def ns2de_matplotlib_vortex_test ( ): #*****************************************************************************80 # ## NS2DE_MATPLOTLIB_VORTEX_TEST plots a Vortex velocity field. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 22 July 2015 # # Author: # # John Burkardt # import platform from grid_2d import grid_2d from uvp_vortex import uvp_vortex print ( '' ) print ( 'NS2DE_MATPLOTLIB_VORTEX_TEST:' ) print ( ' Python version: %s' % ( platform.python_version ( ) ) ) print ( ' Generate a Vortex velocity field on a regular grid.' ) print ( ' Display it using MATPLOTLIB' ) x_lo = 0.5 x_hi = 1.5 x_num = 21 y_lo = 0.5 y_hi = 1.5 y_num = 21 x, y = grid_2d ( x_num, x_lo, x_hi, y_num, y_lo, y_hi ) nu = 1.0 rho = 1.0 n = x_num * y_num t = 0.0 u, v, p = uvp_vortex ( nu, rho, n, x, y, t ) header = 'vortex' s = 0.25 ns2de_matplotlib ( header, n, x, y, u, v, p, s ) # # Terminate. # print ( '' ) print ( 'NS2DE_MATPLOTLIB_VORTEX_TEST:' ) print ( ' Normal end of execution.' ) return if ( __name__ == '__main__' ): from timestamp import timestamp timestamp ( ) ns2de_matplotlib_lukas_test ( ) ns2de_matplotlib_poiseuille_test ( ) ns2de_matplotlib_spiral_test ( ) ns2de_matplotlib_taylor_test ( ) ns2de_matplotlib_vortex_test ( ) timestamp ( )