def vorticity_calc(self,PhyTime=None): """ Calculate the vorticity vector Parameters ---------- PhyTime : float, optional Physical time, by default None Returns ------- datastruct Datastruct with the vorticity vector in it """ self.check_PhyTime(self.InstDF,PhyTime) vorticity = np.zeros((3,*self.shape),dtype='f8') u_velo = self.InstDF[PhyTime,'u'] v_velo = self.InstDF[PhyTime,'v'] w_velo = self.InstDF[PhyTime,'w'] vorticity[0] = gradient.Grad_calc(self.CoordDF,w_velo,'y') - gradient.Grad_calc(self.CoordDF,v_velo,'z') vorticity[1] = gradient.Grad_calc(self.CoordDF,u_velo,'z') - gradient.Grad_calc(self.CoordDF,w_velo,'x') vorticity[2] = gradient.Grad_calc(self.CoordDF,v_velo,'x') - gradient.Grad_calc(self.CoordDF,u_velo,'y') index = [(PhyTime,x) for x in ['x','y','z']] return cd.flowstruct3D(self._coorddata,vorticity,index=index)
def _getFluctDF(self,modes): coeffs = self.POD_coeffs[modes] indices =self.POD.POD_modesDF.index flow_reconstruct = np.inner(self.POD.POD_modesDF.values[:,:,:,:,modes],coeffs) return cd.flowstruct3D(self._coorddata,flow_reconstruct,Domain=self.Domain,index=indices)
def lambda2_calc(self,PhyTime=None): """ Calculation of lambda to visualise vortex cores Parameters ---------- PhyTime : float, optional Physical time to be plotted, None can be used if the instance contains a single time, by default None x_start_index : int, optional streamwise location to start to calculation, by default None x_end_index : int, optional streamwise location to end to calculation, by default None y_index : int, optional First y_index of the mesh to be calculated, by default None Returns ------- %(ndarray)s Array of the lambda2 calculation """ PhyTime = self.check_PhyTime(PhyTime) #Calculating strain rate tensor velo_list = ['u','v','w'] coord_list = ['x','y','z'] strain_rate = np.zeros((*self.shape,3,3)) rot_rate = np.zeros((*self.shape,3,3)) i=0 for velo1,coord1 in zip(velo_list,coord_list): j=0 for velo2,coord2 in zip(velo_list,coord_list): velo_field1 = self.InstDF[PhyTime,velo1] velo_field2 = self.InstDF[PhyTime,velo2] strain_rate[:,:,:,i,j] = 0.5*(gradient.Grad_calc(self.CoordDF,velo_field1,coord2) \ + gradient.Grad_calc(self.CoordDF,velo_field2,coord1)) rot_rate[:,:,:,i,j] = 0.5*(gradient.Grad_calc(self.CoordDF,velo_field1,coord2) \ - gradient.Grad_calc(self.CoordDF,velo_field2,coord1)) j+=1 i+=1 del velo_field1 ; del velo_field2 S2_Omega2 = np.matmul(strain_rate,strain_rate) + np.matmul(rot_rate,rot_rate) del strain_rate ; del rot_rate S2_Omega2_eigvals, e_vecs = np.linalg.eigh(S2_Omega2) del e_vecs; del S2_Omega2 lambda2 = np.sort(S2_Omega2_eigvals,axis=3)[:,:,:,1] return cd.flowstruct3D(self._coorddata,{(PhyTime,'lambda_2'):lambda2})
def Q_crit_calc(self,PhyTime=None): PhyTime = self.check_PhyTime(PhyTime) #Calculating strain rate tensor velo_list = ['u','v','w'] coord_list = ['x','y','z'] D = np.zeros((*self.shape,3,3)) for i,velo in enumerate(velo_list): velo_field = self.InstDF[PhyTime,velo] for j,coord in enumerate(coord_list): D[:,:,:,i,j] = gradient.Grad_calc(self.CoordDF,velo_field,coord) del velo_field Q = 0.5*(np.trace(D,axis1=3,axis2=4,dtype=rcParams['dtype'])**2 - \ np.trace(np.matmul(D,D,dtype=rcParams['dtype']),axis1=3,axis2=4,dtype=rcParams['dtype'])) del D return cd.flowstruct3D(self._coorddata,{(PhyTime,'Q'):Q})
def _fluctDF_calc(self, inst_data, avg_data): fluct = np.zeros((len(inst_data.InstDF.index), *inst_data.shape[:])) avg_time = list(set([x[0] for x in avg_data.flow_AVGDF.index])) assert len( avg_time ) == 1, "In this context therecan only be one time in avg_data" fluct = np.zeros((len(inst_data.InstDF.index), *inst_data.shape[:]), dtype=cp.rcParams['dtype']) j = 0 for j, (time, comp) in enumerate(inst_data.InstDF.index): avg_values = avg_data.flow_AVGDF[avg_time[0], comp] inst_values = inst_data.InstDF[time, comp] for i in range(inst_data.shape[0]): fluct[j, i] = inst_values[i] - avg_values del inst_values return cd.flowstruct3D(self._coorddata, fluct, index=inst_data.InstDF.index.copy())
def _flow_extract(self,Time_input,path_to_folder,abs_path,tgpost): """ Extract velocity and pressure from the instantanous files """ instant = "%0.9E" % Time_input file_folder = "1_instant_D" if tgpost: file_string = "DNS_perixz_INSTANT_T" + instant else: file_string = "DNS_perioz_INSTANT_T" + instant veloVector = ["_U","_V","_W","_P"] file_ext = ".D" full_path = misc_utils.check_paths(path_to_folder,'1_instant_rawdata', '1_instant_D') file_list=[] for velo in veloVector: if not abs_path: file_list.append(os.path.abspath(os.path.join(full_path, file_string + velo + file_ext))) else: file_list.append(os.path.join(full_path, file_string + velo + file_ext)) # #A list of all the relevant files for this timestep # open_list =[] # #opening all the relevant files and placing them in a list # for file in file_list: # file_temp = open(file,'rb') # open_list.append(file_temp) # #allocating arrays # int_info=np.zeros((4,4)) # r_info = np.zeros((4,3)) # i=0 # #reading metadata from file # for file in open_list: # int_info[i]=np.fromfile(file,dtype='int32',count=4) # r_info[i]=np.fromfile(file,dtype='float64',count=3) # i+=1 # PhyTime=r_info[0,0] # NCL1=int(int_info[0,0]) # NCL2=int(int_info[0,1]) # NCL3=int(int_info[0,2]) # dummy_size=NCL1*NCL2*NCL3 # flow_info=np.zeros((4,dummy_size)) # i=0 # #Extracting flow information # for file in open_list: # flow_info[i]=np.fromfile(file,dtype='float64',count=dummy_size) # i+=1 flow_info, NCL1, NCL2, NCL3, PhyTime = self._file_extract(file_list) #Reshaping and interpolating flow data so that it is centred flow_info=flow_info.reshape((4,NCL3,NCL2,NCL1)) flow_info = self.__velo_interp(flow_info,NCL3,NCL2,NCL1) gc.collect() Phy_string = '%.9g' % PhyTime # creating datastruct index index = [[Phy_string]*4,['u','v','w','P']] # creating datastruct so that data can be easily accessible elsewhere Instant_DF = cd.flowstruct3D(self._coorddata,flow_info,index=index,copy=False)# pd.DataFrame(flow_info1,index=index) # for file in open_list: # file.close() return Instant_DF
def plot_mode_contour(self, comp, modes, axis_val, plane='xz', y_mode='wall', fig=None, ax=None, pcolor_kw=None, **kwargs): modes = misc_utils.check_list_vals(modes) axes_output = True if isinstance(ax, mpl.axes.Axes) else False axis_val = misc_utils.check_list_vals(axis_val) if len(axis_val) > 1: msg = "This routine can only process one slice in a single call" raise ValueError(msg) for i, mode in enumerate(modes): PODmodes = self.POD_modesDF.values[:, :, :, :, mode] POD_modeDF = cd.flowstruct3D(self._coorddata, PODmodes, index=self.POD_modesDF.index) plane, coord = POD_modeDF.CoordDF.check_plane(plane) if coord == 'y': val = indexing.ycoords_from_coords(self.avg_data, axis_val, mode=y_mode)[0][0] int_val = indexing.ycoords_from_norm_coords(self.avg_data, axis_val, mode=y_mode)[0][0] else: int_val = val = indexing.true_coords_from_coords( self.CoordDF, coord, axis_val)[0] if i == 0: x_size, z_size = POD_modeDF.get_unit_figsize(plane) figsize = [x_size, z_size * len(modes)] kwargs = cplt.update_subplots_kw(kwargs, figsize=figsize) fig, ax = cplt.create_fig_ax_without_squeeze(len(modes), fig=fig, ax=ax, **kwargs) title_symbol = misc_utils.get_title_symbol(coord, y_mode, False) fig, ax[i] = POD_modeDF.plot_contour(comp, plane, int_val, time=None, fig=fig, ax=ax[i], pcolor_kw=pcolor_kw) ax[i].axes.set_xlabel(r"$%s/\delta$" % plane[0]) ax[i].axes.set_ylabel(r"$%s/\delta$" % plane[1]) ax[i].axes.set_title(r"$%s=%.2g$" % (title_symbol, val), loc='right') ax[i].axes.set_title(r"Mode %d" % (mode + 1), loc='left') cbar = fig.colorbar(ax[i], ax=ax[i].axes) ax[i].axes.set_aspect('equal') if axes_output: return fig, ax[0] else: return fig, ax