Commit cca4b9c2 authored by Salko Jr, Robert's avatar Salko Jr, Robert
Browse files

Expand channel void plotter to be able to model multiple channels

parent 04a7ec4f
Loading
Loading
Loading
Loading
+15 −22
Original line number Diff line number Diff line
@@ -773,10 +773,19 @@ class Hdf5Interface(object):
           chData  (list): List of solution data

        """
        return me._getChanMeshAndData('chan_enthalpy_liq', state, chan)
        return me.getChanMeshAndData('chan_enthalpy_liq', state, chan)

    def _getChanMeshAndData(me, dataset, state, chan):
        """ Returns both the axial mesh and axial data vector for passed channel/dataset"""
    def getChanMeshAndData(me, dataset, state, chan):
        """ Returns both the axial mesh and axial data vector for passed channel/dataset

        Args:
           dataset (str) : Name of the dataset in the HDF5 file
           state (int) : STATE index (1-based) from which to extract data
           chan (int) : Channel index (1-based) from which to extract data

        """
        me._datasetValid(dataset, state)
        me._chanIndexValid(chan)
        return me.getChanAxialMesh(chan, dataset), me.getChanDataset(dataset, state, chan)

    def getChanEquilibriumQuality(me, chan, state=1):
@@ -794,7 +803,7 @@ class Hdf5Interface(object):
        dataset = 'chan_equilibrium_quality'
        me._datasetValid(dataset, state)
        me._chanIndexValid(chan)
        return me._getChanMeshAndData(dataset, state, chan)
        return me.getChanMeshAndData(dataset, state, chan)

    def getMaxChanData(me, dataset, state=None):
        """ Finds max location of channel data in model
@@ -832,22 +841,6 @@ class Hdf5Interface(object):

        return maxState, maxChan, maxLevel, maxVal

    def getChanVoid(me, chan, state=1):
        """ Returns the channel void distribution and axial mesh

        Args:
           chan (int) : Channel ID from which to retrieve data
           state (int) : State number from which to retrieve data (will default to 1)

        Returns:
           chanAxial (list): List of axial locations from which data is available
           chanData  (list): List of solution data

        """
        dataset = 'chan_void_vap'
        me._datasetValid(dataset, state)
        me._chanIndexValid(chan)
        return me._getChanMeshAndData(dataset, state, chan)

    def getChanHeight(me, chan):
        """ Returns the axial height of the passed channel index
@@ -894,7 +887,7 @@ class Hdf5Interface(object):
        dataset = 'chan_pressure'
        me._datasetValid(dataset, state)
        me._chanIndexValid(chan)
        return me._getChanMeshAndData(dataset, state, chan)
        return me.getChanMeshAndData(dataset, state, chan)

    def getMassFluxTot(me, chan, state=1):
        """ Returns the channel total mass flux distribution and axial mesh
@@ -910,7 +903,7 @@ class Hdf5Interface(object):
        """
        mdotLiq = me.getChanDataset('chan_mdot_liq', state, chan)
        mdotVap = me.getChanDataset('chan_mdot_vap', state, chan)
        axial, mdotDrp = me._getChanMeshAndData('chan_mdot_drp', state, chan)
        axial, mdotDrp = me.getChanMeshAndData('chan_mdot_drp', state, chan)
        mdotTot = np.array(mdotLiq)+np.array(mdotVap)+np.array(mdotDrp)
        return axial, list(mdotTot/me.h5['CORE/chan_area'][()][chan-1])
+53 −7
Original line number Diff line number Diff line
@@ -128,15 +128,41 @@ class PlotTools(object):
   def _chName(me, state, ch):
       return "STATE_{:04d}_CHAN_{:05d}".format(state, ch)

   def _plotAxial(me, x, y, xname, figname, title=None, yname="Axial [m]"):
       """ Makes an axial plot"""
   def _plotAxial(me, x, y, xname, figname, labels, title=None, yname="Axial [m]"):
       """ Makes an axial plot

       x (list or dict): x-axis data to plot.  Pass a dictionary for multiple datasets.
       y (list or dict): y-axis data to plot.  Pass a dictionary for multiple datasets.
       xname (str): Name of x-axis data.
       figname (str): Name of figure
       labels (str or list): If x/y were a list, then this should be a string.  If they were dicts, this should be
          a list of equal length to the dicts.  It gives the labels for including in the legend.
       title (str): Title for the plot
       yname (str): The name of the y plot

       """
       fig, ax = plt.subplots()
       if title:
          plt.title(title)
       ax.grid()
       ax.set_ylabel(yname)
       ax.set_xlabel(xname)
       ax.plot(x, y)
       assert(isinstance(y, list) or isinstance(y, dict))
       if isinstance(y, list):
          assert(isinstance(x, list))
          assert(isinstance(labels, str))
          ax.plot(x, y, label=labels)
          addLegend=False
       else:
          assert(isinstance(x, dict))
          assert(len(x)==len(y))
          assert(x.keys()==y.keys())
          assert(isinstance(labels, list))
          assert(len(labels)==len(x))
          for i, name in enumerate(y.keys()):
             ax.plot(x[name], y[name], label=labels[i])
             addLegend=True
       ax.legend()
       plt.savefig(figname)
       plt.close(fig)

@@ -149,9 +175,29 @@ class PlotTools(object):
          figname (str): Name of the figure.
       """
       stateMax, chMax, levMax, voidMax = me.h5obj.getMaxChanData('chan_void_vap', state)
       (z, void) = me.h5obj.getChanVoid(chMax, stateMax)
       location = me._chName(stateMax, chMax)
       if state is None:
          state_ = stateMax
       else:
          state_ = state
       if ch is None:
          ch_ = [chMax]
       else:
          assert(isinstance(ch, int) or isinstance(ch, list))
          if isinstance(ch, int):
             ch_ = [list(set(ch))]
          else:
             ch_ = ch
       location = "S{:d}".format(state_)
       for c in ch_:
          location=location+"_C{:d}".format(c)
       location = location+"_chan_void_vap"
       if not figname:
           figname = location+"_void_vap.png"
       me._plotAxial(void, z, "Void [-]", figname, location)
           figname = location+".png"
       zs = {}
       voids = {}
       labels = []
       for c in ch_:
          (zs[c], voids[c]) = me.h5obj.getChanMeshAndData('chan_void_vap', state_, c)
          labels.append("ch {:4d}".format(c))
       me._plotAxial(voids, zs, "Void [-]", figname, labels, location)
+3 −2
Original line number Diff line number Diff line
@@ -5,8 +5,9 @@ def main():
   parser = argparse.ArgumentParser(description="Plot the axial void distribution in a channel.  All indices are 1-based.")
   parser.add_argument('h5name', type=str, help="HDF5 file")
   parser.add_argument('--state', type=int, nargs="?", help="State to plot.  Defaults to state with max void.")
   parser.add_argument('--ch', type=int, nargs="?", help="Channel to plot.  Defaults to channel with max void.")
   parser.add_argument('--figname', type=str, nargs="?", help="Name of figure.  Defaults to name based on location of DNBR.")
   parser.add_argument('--ch', type=int, action='append', help="""Channel to plot.  Defaults to channel with max void.
         Can plot multiple channels (e.g. --ch 1 --ch 2 --ch 3 ...)""")
   parser.add_argument('--figname', type=str, nargs="?", help="Name of figure.  Defaults to name based on location and dataset type.")
   args = parser.parse_args()

   plotter = PlotTools(args.h5name)