Example #1
0
    def plot(self,
             budget_terms=None,
             PhyTime=None,
             fig=None,
             ax=None,
             line_kw=None,
             **kwargs):

        budget_terms = self._check_terms(budget_terms)

        kwargs = cplt.update_subplots_kw(kwargs, figsize=[10, 5])
        fig, ax = cplt.create_fig_ax_with_squeeze(fig, ax, **kwargs)

        line_kw = cplt.update_line_kw(line_kw)
        xaxis_vals = self.avg_data._return_xaxis()

        for comp in budget_terms:
            budget_term = self.budgetDF[PhyTime, comp].copy()

            label = r"%s" % comp.title()
            ax.cplot(xaxis_vals, budget_term, label=label, **line_kw)
        ax.cplot(xaxis_vals,
                 np.sum(self.budgetDF.values, axis=0),
                 label="Total")
        ncol = cplt.get_legend_ncols(len(budget_terms))
        ax.clegend(ncol=ncol, vertical=False)
        return fig, ax
Example #2
0
    def plot_contour(self,
                     comp,
                     plane,
                     axis_val,
                     time=None,
                     fig=None,
                     ax=None,
                     pcolor_kw=None,
                     **kwargs):
        fig, ax = cplt.create_fig_ax_with_squeeze(fig, ax, **kwargs)
        pcolor_kw = cplt.update_pcolor_kw(pcolor_kw)

        time = self.check_times(time)
        comp = self.check_comp(comp)

        plane, coord = self.CoordDF.check_plane(plane)

        axis_index = self.CoordDF.index_calc(coord, axis_val)
        flow_slice = indexing.contour_indexer(self[time, comp], axis_index,
                                              coord)

        x_coord = self.CoordDF[plane[0]]
        y_coord = self.CoordDF[plane[1]]

        X, Y = np.meshgrid(x_coord, y_coord)

        ax = ax.pcolormesh(X, Y, flow_slice.squeeze(), **pcolor_kw)

        return fig, ax
Example #3
0
    def plot_Q_criterion(self,vals_list,x_split_pair=None,PhyTime=None,y_limit=None,y_mode='half_channel',Y_plus=True,avg_data=None,colors=None,surf_kw=None,fig=None,ax=None,**kwargs):
        PhyTime = self.check_PhyTime(PhyTime)
        vals_list = misc_utils.check_list_vals(vals_list)

        if y_limit is not None:
            y_lim_int = indexing.ycoords_from_norm_coords(self.avg_data,[y_limit],mode=y_mode)[0][0]
        else:
            y_lim_int = None

        kwargs = cplt.update_subplots_kw(kwargs,subplot_kw={'projection':'3d'})
        fig, ax = cplt.create_fig_ax_with_squeeze(fig=fig,ax=ax,**kwargs)

        Q = self.Q_crit_calc(PhyTime)
        for i,val in enumerate(vals_list):
            if colors is not None:
                color = colors[i%len(colors)]
                surf_kw['facecolor'] = color
            fig, ax1 = Q.plot_isosurface('Q',val,time=PhyTime,y_limit=y_lim_int,
                                            x_split_pair=x_split_pair,fig=fig,ax=ax,
                                            surf_kw=surf_kw)
            ax.axes.set_ylabel(r'$x/\delta$')
            ax.axes.set_xlabel(r'$z/\delta$')
            ax.axes.invert_xaxis()

        return fig, ax1
    def plot_contour(self,comp,modes,fig=None,ax=None,pcolor_kw=None,**kwargs):
        
        kwargs = cplt.update_subplots_kw(kwargs,figsize=[7,5])
        fig, ax = cplt.create_fig_ax_with_squeeze(fig=fig,ax=ax,**kwargs)
        coeffs = self.POD_coeffs[sorted(modes)]
        reconstruct_arrays = np.multiply(self.POD.POD_modesDF[comp][:,:,modes],coeffs)
        
        flow_reconstruct = np.sum(reconstruct_arrays,axis=-1)

        x_array = self.avg_data.CoordDF[self.POD._plane[0]]
        y_array = self.avg_data.CoordDF[self.POD._plane[1]]

        X, Z = np.meshgrid(x_array, y_array)
        pcolor_kw = cplt.update_pcolor_kw(pcolor_kw)

        ax1 = ax.pcolormesh(X,Z,flow_reconstruct,**pcolor_kw)
        ax1.axes.set_xlabel(r"$%s/\delta$" % self.POD._plane[0])
        ax1.axes.set_ylabel(r"$%s/\delta$" % self.POD._plane[1])

        ax1.axes.set_aspect('equal')

        cbar=fig.colorbar(ax1,ax=ax)
        cbar.set_label(r"$%s^\prime$"%comp)

        fig.tight_layout()

        return fig, ax1
Example #5
0
    def plot_lambda2(self,vals_list,x_split_pair=None,PhyTime=None,y_limit=None,y_mode='half_channel',Y_plus=True,avg_data=None,colors=None,surf_kw=None,fig=None,ax=None,**kwargs):
        """
        Creates isosurfaces for the lambda 2 criterion

        Parameters
        ----------
        vals_list : list of floats
            isovalues to be plotted
        x_split_list : list, optional
            Separating domain into different streamwise lengths useful if the domain is much 
            longer than its width, by default None
        PhyTime : float, optional
            Physical time to be plotted, None can be used if the instance contains a single 
            time, by default None
        ylim : float, optional
            wall-normal extent of the isosurface plot, by default None
        Y_plus : bool, optional
            Whether the above value is in wall units, by default True
        avg_data : CHAPSim_AVG, optional
            Instance of avg_data need if Y_plus is True, by default None
        colors : list of str, optional
            list to represent the order of the colors to be plotted, by default None
        fig : %(fig)s, optional
            Pre-existing figure, by default None
        ax : %(ax)s, optional
            Pre-existing axes, by default None

        Returns
        -------
        %(fig)s, %(ax)s
            output figure and axes objects

        """
        PhyTime = self.check_PhyTime(PhyTime)
        vals_list = misc_utils.check_list_vals(vals_list)

        if y_limit is not None:
            y_lim_int = indexing.ycoords_from_norm_coords(self.avg_data,[y_limit],mode=y_mode)[0][0]
        else:
            y_lim_int = None

        kwargs = cplt.update_subplots_kw(kwargs,subplot_kw={'projection':'3d'})
        fig, ax = cplt.create_fig_ax_with_squeeze(fig=fig,ax=ax,**kwargs)

        lambda_2DF = self.lambda2_calc(PhyTime)
        for i,val in enumerate(vals_list):
            if colors is not None:
                color = colors[i%len(colors)]
                surf_kw['facecolor'] = color
            fig, ax1 = lambda_2DF.plot_isosurface('lambda_2',val,time=PhyTime,y_limit=y_lim_int,
                                            x_split_pair=x_split_pair,fig=fig,ax=ax,
                                            surf_kw=surf_kw)
            ax.axes.set_ylabel(r'$x/\delta$')
            ax.axes.set_xlabel(r'$z/\delta$')
            ax.axes.invert_xaxis()

        return fig, ax1
    def plot_coeffs(self,n_modes,fig=None,ax=None,**kwargs):
        if n_modes > self.POD_coeffs.size:
            msg = "The number of modes must be less than the number of available coefficients"
            raise ValueError(msg)
        kwargs = cplt.update_subplots_kw(kwargs,figsize=[7,5])
        fig, ax = cplt.create_fig_ax_with_squeeze(fig,ax,**kwargs) 
        modes = [x+1 for x in range(n_modes)]
        ax.bar(modes,self.POD_coeffs[:n_modes])
        ax.set_xlabel(r"Modes")
        ax.set_ylabel(r"Coefficient $a$")

        return fig, ax
Example #7
0
    def plot_energy_levels(self, n_modes, fig=None, ax=None, **kwargs):

        kwargs = cplt.update_subplots_kw(kwargs, figsize=[7, 5])
        fig, ax = cplt.create_fig_ax_with_squeeze(fig, ax, **kwargs)

        total_energy = np.sum(self.EigenVals)
        energy_prop = self.EigenVals[:n_modes] / total_energy
        modes = [x + 1 for x in range(n_modes)]
        ax.bar(modes, energy_prop)
        ax.set_xlabel(r"Modes")
        ax.set_ylabel("Proportion of energy")

        return fig, ax
Example #8
0
    def plot_isosurface(self,
                        comp,
                        Value,
                        time=None,
                        y_limit=None,
                        x_split_pair=None,
                        fig=None,
                        ax=None,
                        surf_kw=None,
                        **kwargs):
        fig, ax = cplt.create_fig_ax_with_squeeze(fig,
                                                  ax,
                                                  projection='3d',
                                                  **kwargs)
        surf_kw = cplt.update_mesh_kw(surf_kw)

        time = self.check_times(time)
        comp = self.check_comp(comp)

        z_coords = self.CoordDF['z']
        y_coords = self.CoordDF['y']
        x_coords = self.CoordDF['x']

        if x_split_pair is None:
            x_split_pair = [np.amin(x_coords), np.amax(x_coords)]

        x_index_list = self.CoordDF.index_calc('x', x_split_pair)

        x_coords = x_coords[x_index_list[0]:x_index_list[1]]

        if y_limit is not None:
            y_index = self.CoordDF.index_calc('y', y_limit)[0]
            y_coords = y_coords[:y_index]
        else:
            y_index = y_coords.size

        Z, Y, X = misc_utils.meshgrid(z_coords, y_coords, x_coords)

        flow_array = self[time, comp][:, :y_index,
                                      x_index_list[0]:x_index_list[1]]

        ax = ax.plot_isosurface(Z, X, Y, flow_array, Value, **surf_kw)
        coord_lims = [
            np.amax(Z) - np.amin(Z),
            np.amax(X) - np.amin(X),
            np.amax(Y) - np.amin(Y)
        ]
        ax.axes.set_box_aspect(coord_lims)
        return fig, ax
Example #9
0
    def _plot_budget_x(self,
                       budget_terms,
                       y_vals_list,
                       Y_plus=True,
                       PhyTime=None,
                       fig=None,
                       ax=None,
                       **kwargs):

        budget_terms = self._check_terms(budget_terms)

        kwargs = cplt.update_subplots_kw(kwargs, figsize=[10, 5])
        fig, ax = cplt.create_fig_ax_with_squeeze(fig, ax**kwargs)

        xaxis_vals = self.avg_data._return_xaxis()
        for comp in budget_terms:
            if y_vals_list != 'max':
                if Y_plus:
                    y_index = indexing.Y_plus_index_calc(
                        self, self.CoordDF, y_vals_list)
                else:
                    y_index = indexing.coord_index_calc(
                        self.CoordDF, 'y', y_vals_list)
                budget_term = self.budgetDF[PhyTime, comp]

                y_vals_list = indexing.ycoords_from_coords(self,
                                                           y_vals_list,
                                                           mode='wall')[0]
                for i, y_val in enumerate(y_vals_list):
                    ax.cplot(budget_term[i],
                             label=r"%s $y^+=%.2g$" % (comp, y_val))

                ncol = cplt.get_legend_ncols(
                    len(budget_terms) * len(y_vals_list))
                ax.clegend(vertical=False, ncol=ncol, fontsize=16)

            else:
                budget_term = self.budgetDF[PhyTime, comp]
                budget_term = np.amax(budget_term, axis=0)
                ax.cplot(xaxis_vals, budget_term, label=r"maximum %s" % comp)

                ncol = cplt.get_legend_ncols(len(budget_terms))
                ax.clegend(vertical=False, ncol=ncol, fontsize=16)
        fig.tight_layout()
        return fig, ax
Example #10
0
    def plot_surf(self,
                  comp,
                  plane,
                  axis_val,
                  time=None,
                  x_split_pair=None,
                  fig=None,
                  ax=None,
                  surf_kw=None,
                  **kwargs):
        fig, ax = cplt.create_fig_ax_with_squeeze(fig,
                                                  ax,
                                                  projection='3d',
                                                  **kwargs)
        surf_kw = cplt.update_mesh_kw(surf_kw)

        time = self.check_times(time)
        comp = self.check_comp(comp)

        plane, coord = self.CoordDF.check_plane(plane)

        axis_index = self.CoordDF.index_calc(coord, axis_val)
        flow_slice = indexing.contour_indexer(self[time, comp], axis_index,
                                              coord)

        x_coord = self.CoordDF[plane[0]]
        y_coord = self.CoordDF[plane[1]]

        if x_split_pair is None or plane[0] != 'x':
            x_split_pair = [np.amin(x_coord), np.amax(x_coord)]

        x_index_list = self.CoordDF.index_calc('x', x_split_pair)

        x_coord = x_coord[x_index_list[0]:x_index_list[1]]

        X, Y = np.meshgrid(x_coord, y_coord)

        axis_index = self.CoordDF.index_calc(coord, axis_val)
        flow_slice = indexing.contour_indexer(self[time, comp], axis_index,
                                              coord)
        flow_slice = flow_slice[:, x_index_list[0]:x_index_list[1]]

        ax = ax.plot_surface(Y, X, flow_slice, **surf_kw)

        return fig, ax
Example #11
0
    def plot_vector(self,
                    plane,
                    axis_val,
                    time=None,
                    spacing=(1, 1),
                    scaling=1,
                    fig=None,
                    ax=None,
                    quiver_kw=None,
                    **kwargs):
        fig, ax = cplt.create_fig_ax_with_squeeze(fig, ax, **kwargs)
        quiver_kw = cplt.update_quiver_kw(quiver_kw)

        time = self.check_times(time)

        plane, coord = self.CoordDF.check_plane(plane)

        coord_1 = self.CoordDF[plane[0]][::spacing[0]]
        coord_2 = self.CoordDF[plane[1]][::spacing[1]]
        UV_slice = [chr(ord(x) - ord('x') + ord('u')) for x in plane]
        U = self[time, UV_slice[0]]
        V = self[time, UV_slice[1]]

        axis_index = self.CoordDF.index_calc(coord, axis_val)

        U_space, V_space = indexing.vector_indexer(U, V, axis_index, coord,
                                                   spacing[0], spacing[1])
        U_space = U_space.squeeze()
        V_space = V_space.squeeze()
        coord_1_mesh, coord_2_mesh = np.meshgrid(coord_1, coord_2)
        scale = np.amax(
            U_space[:, :]) * coord_1.size / np.amax(coord_1) / scaling
        ax = ax.quiver(coord_1_mesh,
                       coord_2_mesh,
                       U_space[:, :].T,
                       V_space[:, :].T,
                       angles='uv',
                       scale_units='xy',
                       scale=scale,
                       **quiver_kw)

        return fig, ax
Example #12
0
    def _plot_integral_budget(self,
                              budget_terms=None,
                              PhyTime=None,
                              wall_units=True,
                              fig=None,
                              ax=None,
                              line_kw=None,
                              **kwargs):

        y_coords = self.avg_data.CoordDF['y']

        budget_terms = self._check_terms(budget_terms)

        u_tau_star, delta_v_star = self.avg_data._wall_unit_calc(PhyTime)

        kwargs = cplt.update_subplots_kw(kwargs, figsize=[10, 5])
        fig, ax = cplt.create_fig_ax_with_squeeze(fig, ax, **kwargs)

        line_kw = cplt.update_line_kw(line_kw)
        xaxis_vals = self.avg_data._return_xaxis()

        for comp in budget_terms:
            integral_budget = np.zeros(self.avg_data.shape[1])
            budget_term = self.budgetDF[PhyTime, comp].copy()
            for i in range(self.avg_data.shape[1]):
                integral_budget[i] = 0.5 * integrate.simps(
                    budget_term[:, i], y_coords)
                if wall_units:
                    delta_star = 1.0
                    integral_budget[i] /= (delta_star * u_tau_star[i]**3 /
                                           delta_v_star[i])
            label = r"$\int^{\delta}_{-\delta}$ %s $dy$" % comp.title()
            ax.cplot(xaxis_vals, integral_budget, label=label, **line_kw)

        ncol = cplt.get_legend_ncols(len(budget_terms))
        ax.clegend(ncol=ncol, vertical=False)
        #ax.grid()
        return fig, ax