HyPar  1.0
Finite-Difference Hyperbolic-Parabolic PDE Solver on Cartesian Grids
plotSolution Namespace Reference

Functions

def plotSolution
 

Detailed Description

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

Function Documentation

◆ plotSolution()

def plotSolution.plotSolution (   a_ndims)

Definition at line 11 of file plotSolution.py.

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