HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
plotSolution Namespace Reference

Functions

def plotSolution
 

Detailed Description

Python script to create plots from the solution of a
HyPar simulation.

Function Documentation

def plotSolution.plotSolution (   a_ndims)

Definition at line 11 of file plotSolution.py.

11 
12 def plotSolution( a_ndims: int,
13  a_nvars: int,
14  a_size: np.ndarray,
15  a_time: float,
16  a_x: np.ndarray,
17  a_U: np.ndarray,
18  a_fname: str ):
19 
20  plt_dir_name='plots'
21  if not os.path.exists(plt_dir_name):
22  os.makedirs(plt_dir_name)
23 
24  if a_ndims == 1 :
25 
26  font = {'size':22}
27  matplotlib.rc('font', **font)
28  figsize=(15,9)
29 
30  for var in range(a_nvars):
31  try:
32  fig = plt.figure(figsize=figsize)
33  ax = plt.axes()
34  ax.set( xlim=(np.min(a_x), np.max(a_x)),
35  ylim=(np.min(a_U[var::a_nvars]),
36  np.max(a_U[var::a_nvars]) ) )
37  ax.plot(a_x, a_U[var::a_nvars], lw=2)
38  ax.set_title('var {:}, t={:.3}'.format(var,a_time))
39  plt.grid(visible=True, linestyle=':', linewidth=1)
40  if a_nvars == 1 :
41  plt_fname = plt_dir_name+'/'+a_fname
42  else:
43  plt_fname = plt_dir_name+'/var'+f'{var:02d}'+'_'+a_fname
44  print('Saving %s' % plt_fname)
45  plt.savefig(plt_fname)
46  plt.close()
47  except:
48  print('Error in plotBinarySolution: unable to generate plot for var %d' % var)
49  print('Error in plotBinarySolution: nvars is %d' % a_nvars)
50 
51  elif a_ndims == 2 :
52 
53  font = {'size':22}
54  matplotlib.rc('font', **font)
55  colormap='jet'
56  figsize=(12,10)
57 
58  x = a_x[:a_size[0]]
59  y = a_x[a_size[0]:]
60  y2d, x2d = np.meshgrid(y, x)
61 
62  for var in range(a_nvars):
63  try:
64  fig = plt.figure(figsize=figsize)
65  ax = plt.axes()
66  ax.set( xlim=(np.min(x), np.max(x)),
67  ylim=(np.min(y), np.max(y)) )
68  sol2d = np.transpose(a_U.reshape(a_size[1],a_size[0],a_nvars))
69  plot = ax.pcolor(x2d, y2d, sol2d[var,:,:], cmap=colormap)
70  ax.set_title('var {:}, t={:.3}'.format(var,a_time))
71  fig.colorbar(plot, ax=ax)
72  if a_nvars == 1 :
73  plt_fname = plt_dir_name+'/'+a_fname
74  else:
75  plt_fname = plt_dir_name+'/var'+f'{var:02d}'+'_'+a_fname
76  print('Saving %s' % plt_fname)
77  plt.savefig(plt_fname)
78  plt.close()
79  except:
80  print('Error in plotBinarySolution: unable to generate plot for var %d' % var)
81  print('Error in plotBinarySolution: nvars is %d' % a_nvars)
82 
83  else :
84 
85  print('plotSolution.py: No plotting implemented for a_ndims=%d', a_ndims)
86