#! /usr/bin/env python # def ns2de_gnuplot ( header, n, x, y, u, v, p, s ): #*****************************************************************************80 # ## NS2DE_GNUPLOT writes the Navier-Stokes velocity field to files for GNUPLOT. # # 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 flow field samples. # # Input, real S, a scale factor for the velocity vectors. # # # Write the data file. # data_filename = header + '_data.txt' data_unit = open ( data_filename, 'w' ) for i in range ( 0, n ): st = ' %g' % ( x[i] ) data_unit.write ( st ) st = ' %g' % ( y[i] ) data_unit.write ( st ) st = ' %g' % ( u[i] ) data_unit.write ( st ) st = ' %g' % ( v[i] ) data_unit.write ( st ) st = ' %g' % ( s * u[i] ) data_unit.write ( st ) st = ' %g' % ( s * v[i] ) data_unit.write ( st ) st = ' %g' % ( p[i] ) data_unit.write ( st ) data_unit.write ( '\n' ); data_unit.close ( ) print ( '' ) print ( ' Data written to "%s".' % ( data_filename ) ) # # Write the command file. # command_filename = header + '_commands.txt' plot_filename = header + '.png' command_unit = open ( command_filename, 'w' ) command_unit.write ( '# %s\n' % ( command_filename ) ) command_unit.write ( '#\n' ) command_unit.write ( 'set term png\n' ) command_unit.write ( 'set output "%s"\n' % ( plot_filename ) ) command_unit.write ( '#\n' ) command_unit.write ( '# Add titles and labels.\n' ) command_unit.write ( '#\n' ) command_unit.write ( 'set xlabel "<--- X --->"\n' ) command_unit.write ( 'set ylabel "<--- Y --->"\n' ) command_unit.write ( 'set title "Navier-Stokes velocity field"\n' ) command_unit.write ( 'unset key\n' ) command_unit.write ( '#\n' ) command_unit.write ( '# Add grid lines.\n' ) command_unit.write ( '#\n' ) command_unit.write ( 'set grid\n' ) command_unit.write ( 'set size ratio -1\n' ) command_unit.write ( '#\n' ) command_unit.write ( '# Timestamp the plot.\n' ) command_unit.write ( '#\n' ) command_unit.write ( 'set timestamp\n' ) command_unit.write ( 'plot "%s" using 1:2:5:6 with vectors \\\n' % ( data_filename ) ) command_unit.write ( ' head filled lt 2 linecolor rgb "blue"\n' ) command_unit.write ( 'quit\n' ) data_unit.close ( ) print ( ' Commands written to "%s".' % ( command_filename ) ) return def ns2de_gnuplot_lukas_test ( ): #*****************************************************************************80 # ## NS2DE_GNUPLOT_LUKAS_TEST plots the Lukas Bystricky flow 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_lukas import uvp_lukas print ( '' ) print ( 'NS2DE_GNUPLOT_LUKAS_TEST:' ) print ( ' Python version: %s' % ( platform.python_version ( ) ) ) print ( ' Generate the Lukas Bystricky velocity field on a regular grid.' ) print ( ' Store in GNUPLOT data and command files.' ) 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_gnuplot ( header, n, x, y, u, v, p, s ) # # Terminate. # print ( '' ) print ( 'NS2DE_GNUPLOT_LUKAS_TEST:' ) print ( ' Normal end of execution.' ) return def ns2de_gnuplot_poiseuille_test ( ): #*****************************************************************************80 # ## NS2DE_GNUPLOT_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_GNUPLOT_POISEUILLE_TEST:' ) print ( ' Python version: %s' % ( platform.python_version ( ) ) ) print ( ' Generate a Poiseuille velocity field on a regular grid.' ) print ( ' Store in GNUPLOT data and command files.' ) 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 = 0.5 ns2de_gnuplot ( header, n, x, y, u, v, p, s ) # # Terminate. # print ( '' ) print ( 'NS2DE_GNUPLOT_POISEUILLE_TEST:' ) print ( ' Normal end of execution.' ) return def ns2de_gnuplot_spiral_test ( ): #*****************************************************************************80 # ## NS2DE_GNUPLOT_SPIRAL_TEST plots a Spiral 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_spiral import uvp_spiral print ( '' ) print ( 'NS2DE_GNUPLOT_SPIRAL_TEST:' ) print ( ' Python version: %s' % ( platform.python_version ( ) ) ) print ( ' Generate a Spiral Flow velocity field on a regular grid.' ) print ( ' Store in GNUPLOT data and command files.' ) 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_gnuplot ( header, n, x, y, u, v, p, s ) # # Terminate. # print ( '' ) print ( 'NS2DE_GNUPLOT_SPIRAL_TEST:' ) print ( ' Normal end of execution.' ) return def ns2de_gnuplot_taylor_test ( ): #*****************************************************************************80 # ## NS2DE_GNUPLOT_TAYLOR_TEST plots a Taylor 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_taylor import uvp_taylor print ( '' ) print ( 'NS2DE_GNUPLOT_TAYLOR_TEST:' ) print ( ' Python version: %s' % ( platform.python_version ( ) ) ) print ( ' Generate a Taylor velocity field on a regular grid.' ) print ( ' Store in GNUPLOT data and command files.' ) 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_gnuplot ( header, n, x, y, u, v, p, s ) # # Terminate. # print ( '' ) print ( 'NS2DE_GNUPLOT_TAYLOR_TEST:' ) print ( ' Normal end of execution.' ) return def ns2de_gnuplot_vortex_test ( ): #*****************************************************************************80 # ## NS2DE_GNUPLOT_VORTEX_TEST plots a Vortex velocity field. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 24 July 2015 # # Author: # # John Burkardt # import platform from grid_2d import grid_2d from uvp_vortex import uvp_vortex print ( '' ) print ( 'NS2DE_GNUPLOT_VORTEX_TEST:' ) print ( ' Python version: %s' % ( platform.python_version ( ) ) ) print ( ' Generate a Vortex velocity field on a regular grid.' ) print ( ' Store in GNUPLOT data and command files.' ) 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.10 ns2de_gnuplot ( header, n, x, y, u, v, p, s ) # # Terminate. # print ( '' ) print ( 'NS2DE_GNUPLOT_VORTEX_TEST:' ) print ( ' Normal end of execution.' ) return if ( __name__ == '__main__' ): from timestamp import timestamp timestamp ( ) ns2de_gnuplot_lukas_test ( ) ns2de_gnuplot_poiseuille_test ( ) ns2de_gnuplot_spiral_test ( ) ns2de_gnuplot_taylor_test ( ) ns2de_gnuplot_vortex_test ( ) timestamp ( )