Exemple #1
0
    def _coord_extract_new(self,path_to_folder,abs_path,tgpost,ioflg):
        full_path = misc_utils.check_paths(path_to_folder,'0_log_monitors',
                                                            '.')

        if not abs_path:
            x_coord_file = os.path.abspath(os.path.join(full_path,'CHK_COORD_XND.dat'))
            y_coord_file = os.path.abspath(os.path.join(full_path,'CHK_COORD_YND.dat'))
            z_coord_file = os.path.abspath(os.path.join(full_path,'CHK_COORD_ZND.dat'))
        else:
            x_coord_file = os.path.join(full_path,'CHK_COORD_XND.dat')
            y_coord_file = os.path.join(full_path,'CHK_COORD_YND.dat')
            z_coord_file = os.path.join(full_path,'CHK_COORD_ZND.dat')
    #===================================================================
        #Extracting XND from the .dat file
    
        file=open(x_coord_file,'rb')
        x_coord=np.loadtxt(file,comments='#',usecols=1)
        
        if tgpost and not ioflg:
            XND = x_coord[:-1]
        else:
            index = int(self.metaDF['NCL1_tg']) + 1 
            if (tgpost and ioflg):
                XND = x_coord[:index]
                XND -= XND[0]
            elif self.metaDF['iCase'] == 5:
                index = int(self.metaDF['NCL1_io']) + 1
                XND = x_coord[:index]
            else:
                XND = x_coord[index:]
        file.close()
        #===========================================================
    
        #Extracting YCC from the .dat file
        file=open(y_coord_file,'rb')
        y_coord=np.loadtxt(file,usecols=1,skiprows=1)
        index = int(self.metaDF['NCL2']) + 1 
        YCC=y_coord[index:]
        YND = y_coord[:index]
        y_size = YCC.size
        file.close()
        #============================================================
    
        file=open(z_coord_file,'rb')
        ZND=np.loadtxt(file,comments='#',usecols=1)

        #============================================================
        XCC, ZCC = self._coord_interp(XND,ZND)

        z_size = ZCC.size
        x_size = XCC.size
        y_size = YCC.size
        file.close()

        CoordDF = cd.datastruct({'x':XCC,'y':YCC,'z':ZCC})
        Coord_ND_DF = cd.datastruct({'x':XND,'y':YND,'z':ZND})
        NCL = [x_size, y_size, z_size]
        return CoordDF, Coord_ND_DF, NCL
    def _quad_extract(self,
                      h_list,
                      path_to_folder='.',
                      time0=None,
                      abs_path=True):
        times = misc_utils.time_extract(path_to_folder, abs_path)
        if time0 is not None:
            times = list(filter(lambda x: x > time0, times))
        if cp.rcParams['TEST']:
            times.sort()
            times = times[-3:]
        self._meta_data = self._module._meta_class(path_to_folder, abs_path)
        self.NCL = self._meta_data.NCL

        try:
            self._avg_data = self._module._avg_io_class(
                max(times), self._meta_data, path_to_folder, time0, abs_path)
        except Exception:
            times.remove(max(times))
            self._avg_data = self._module._avg_io_class(
                max(times), self._meta_data, path_to_folder, time0)
        i = 1
        for timing in times:
            fluct_data = self._module._fluct_io_class(
                timing,
                self._avg_data,
                time0=time0,
                path_to_folder=path_to_folder,
                abs_path=abs_path)
            fluct_uv, quadrant_array = self._quadrant_extract(
                fluct_data.fluctDF, timing, self.NCL)
            coe3 = (i - 1) / i
            coe2 = 1 / i
            if i == 1:
                quad_anal_array = self._quad_calc(self._avg_data, fluct_uv,
                                                  quadrant_array, self.NCL,
                                                  h_list, timing)
            else:
                local_quad_anal_array = self._quad_calc(
                    self._avg_data, fluct_uv, quadrant_array, self.NCL, h_list,
                    timing)
                assert local_quad_anal_array.shape == quad_anal_array.shape, "shape of previous array (%d,%d) " % quad_anal_array.shape\
                    + " and current array (%d,%d) must be the same" % local_quad_anal_array.shape
                quad_anal_array = quad_anal_array * coe3 + local_quad_anal_array * coe2
            gc.collect()
            i += 1
        index = [[], []]
        for h in h_list:
            index[0].extend([h] * 4)
        index[1] = [1, 2, 3, 4] * len(h_list)
        self.shape = self._avg_data.shape
        self.QuadAnalDF = cd.datastruct(quad_anal_array, index=index)
Exemple #3
0
    def _POD_extract(self,
                     comp,
                     path_to_folder='.',
                     method='svd',
                     low_memory=True,
                     abs_path=True,
                     time0=None,
                     subdomain=None,
                     nsnapshots=100,
                     nmodes=10):
        max_time = misc_utils.max_time_calc(path_to_folder, abs_path)
        self.avg_data = self._module._avg_class(max_time,
                                                path_to_folder=path_to_folder,
                                                abs_path=abs_path,
                                                time0=time0)

        if subdomain is not None:
            self._coorddata.create_subdomain(**subdomain)

        self._meta_data = self.avg_data._meta_data

        times = misc_utils.time_extract(path_to_folder, abs_path)

        if time0:
            times = list(filter(lambda x: x > time0, times))

        times = times[-nsnapshots:]

        if rcParams['TEST']:
            times = times[-7:]
            nmodes = 7

        if nmodes > len(times):
            nmodes = len(times)

        if method.lower() == "svd":
            PODmodes, self._eig_values = self._performSVD(
                comp, path_to_folder, abs_path, self.avg_data, times, nmodes,
                subdomain)
        elif method.lower() == "snapshots":
            PODmodes, self._eig_values = self._performSnapShots(
                comp, path_to_folder, abs_path, low_memory, self.avg_data,
                times, nmodes, subdomain)
        else:
            msg = f"Method selected ({method}) is not valid"
            raise ValueError(msg)

        index = [[None] * len(comp), list(comp)]
        self.POD_modesDF = cd.datastruct(PODmodes, index=index)
    def _budget_extract(self, PhyTime):
        laminar = self._laminar_extract(PhyTime)
        turbulent = self._turbulent_extract(PhyTime)
        inertia = self._inertia_extract(PhyTime)

        array_concat = [laminar, turbulent, inertia]

        budget_array = np.stack(array_concat, axis=0)
        budget_index = ['laminar', 'turbulent', 'non-homogeneous']
        phystring_index = [PhyTime] * 3

        budgetDF = cd.datastruct(budget_array,
                                 index=[phystring_index, budget_index])

        return budgetDF
    def _quad_extract(self,
                      h_list,
                      path_to_folder='.',
                      time0=None,
                      abs_path=True):
        times = misc_utils.time_extract(path_to_folder, abs_path)
        if time0 is not None:
            times = list(filter(lambda x: x > time0, times))
        if cp.rcParams['TEST']:
            times.sort()
            times = times[-3:]
        meta_data = self._module._meta_class(path_to_folder, abs_path)
        NCL = meta_data.NCL

        avg_data = self._module._avg_tg_base_class(
            times,
            meta_data=meta_data,
            path_to_folder=path_to_folder,
            time0=time0,
            abs_path=abs_path)

        for timing in times:
            fluct_data = self._module._fluct_tg_class(
                timing,
                avg_data,
                path_to_folder=path_to_folder,
                abs_path=abs_path)
            fluct_uv, quadrant_array = self._quadrant_extract(
                fluct_data.fluctDF, timing, NCL)

            if 'quad_anal_array' not in locals():
                quad_anal_array = self._quad_calc(avg_data, fluct_uv,
                                                  quadrant_array, NCL, h_list,
                                                  timing)
            else:
                local_quad_anal_array = self._quad_calc(
                    avg_data, fluct_uv, quadrant_array, NCL, h_list, timing)
                quad_anal_array = np.vstack(
                    [quad_anal_array, local_quad_anal_array])
            gc.collect()
        index = [[], []]
        for h in h_list:
            index[0].extend([h] * 4)
        index[1] = [1, 2, 3, 4] * len(h_list)
        shape = avg_data.shape
        QuadAnalDF = cd.datastruct(quad_anal_array, index=index)

        return meta_data, NCL, avg_data, QuadAnalDF, shape
    def _budget_extract(self, PhyTime, comp):

        advection = self._advection_extract(PhyTime, comp)
        pressure_grad = self._pressure_grad(PhyTime, comp)
        viscous = self._viscous_extract(PhyTime, comp)
        Reynolds_stress = self._turb_transport(PhyTime, comp)

        array_concat = [advection, pressure_grad, viscous, Reynolds_stress]

        budget_array = np.stack(array_concat, axis=0)

        budget_index = [
            'advection', 'pressure gradient', 'viscous stresses',
            'reynolds stresses'
        ]
        phystring_index = [PhyTime] * 4

        budgetDF = cd.datastruct(budget_array,
                                 index=[phystring_index, budget_index])

        return budgetDF
    def _fluctDF_calc(self, inst_data, avg_data):
        avg_times = avg_data.get_times()
        inst_times = list(set([x[0] for x in inst_data.InstDF.index]))
        u_comp = [x[1] for x in avg_data.flow_AVGDF.index]
        indices = inst_data.InstDF.index
        fluct = np.zeros((len(indices), *inst_data.shape))
        if len(avg_times) == 1:
            j = 0
            for time in inst_times:
                avg_index = avg_data._return_index(time)
                for comp in u_comp:
                    avg_values = avg_data.flow_AVGDF[None, comp]
                    inst_values = inst_data.InstDF[time, comp]

                    for i in range(inst_data.shape[0]):
                        for k in range(inst_data.shape[2]):
                            fluct[j, i, :,
                                  k] = inst_values[i, :,
                                                   k] - avg_values[:,
                                                                   avg_index]
                    j += 1
        elif all(time in avg_times for time in inst_times):
            for j, index in enumerate(indices):
                avg_index = avg_data._return_index(index[0])
                avg_values = avg_data.flow_AVGDF[None, index[1]]
                inst_values = inst_data.InstDF[index]
                for i in range(inst_data.shape[0]):
                    for k in range(inst_data.shape[2]):
                        fluct[j, i, :,
                              k] = inst_values[i, :, k] - avg_values[:,
                                                                     avg_index]
        else:
            raise ValueError(
                "avg_data must either be length 1 or the same length as inst_data"
            )
        # DF_shape = (len(indices),np.prod(inst_data.shape))
        return cd.datastruct(
            fluct, index=inst_data.InstDF.index)  #.data(inst_data.shape)
    def _budget_extract(self, PhyTime, comp1, comp2):

        production = self._production_extract(PhyTime, comp1, comp2)
        advection = self._advection_extract(PhyTime, comp1, comp2)
        turb_transport = self._turb_transport(PhyTime, comp1, comp2)
        pressure_diffusion = self._pressure_diffusion(PhyTime, comp1, comp2)
        pressure_strain = self._pressure_strain(PhyTime, comp1, comp2)
        viscous_diff = self._viscous_diff(PhyTime, comp1, comp2)
        dissipation = self._dissipation_extract(PhyTime, comp1, comp2)

        array_concat = [production,advection,turb_transport,pressure_diffusion,\
                        pressure_strain,viscous_diff,dissipation]

        budget_array = np.stack(array_concat, axis=0)

        budget_index = ['production','advection','turbulent transport','pressure diffusion',\
                     'pressure strain','viscous diffusion','dissipation']
        phystring_index = [PhyTime] * 7

        budgetDF = cd.datastruct(budget_array,
                                 index=[phystring_index, budget_index])

        return budgetDF
    def _create_uniform(self, PhyTime):
        advection = self.budgetDF[PhyTime, 'advection']
        centre_index = int(0.5 * advection.shape[0])
        advection_centre = advection[centre_index]

        uniform_bf = self.budgetDF[PhyTime,
                                   'pressure gradient'] + advection_centre
        non_uniform_bf = advection - advection_centre

        times = self.budgetDF.outer_index
        for time in times:
            key1 = (time, 'advection')
            key2 = (time, 'pressure gradient')
            del self.budgetDF[key1]
            del self.budgetDF[key2]

        cal_dict = {
            (PhyTime, 'uniform'): uniform_bf,
            (PhyTime, 'non-uniform'): non_uniform_bf
        }
        index = [[PhyTime] * 2, ['uniform', 'non-uniform']]
        dstruct = cd.datastruct(np.array([uniform_bf, non_uniform_bf]),
                                index=index)
        self.budgetDF.concat(dstruct)
Exemple #10
0
    def _coord_extract_old(self,path_to_folder,abs_path,tgpost,ioflg):
        """ Function to extract the coordinates from their .dat file """
        
        full_path = misc_utils.check_paths(path_to_folder,'0_log_monitors',
                                                            '.')

        if not abs_path:
            x_coord_file = os.path.abspath(os.path.join(full_path,'CHK_COORD_XND.dat'))
            y_coord_file = os.path.abspath(os.path.join(full_path,'CHK_COORD_YND.dat'))
            z_coord_file = os.path.abspath(os.path.join(full_path,'CHK_COORD_ZND.dat'))
        else:
            x_coord_file = os.path.join(full_path,'CHK_COORD_XND.dat')
            y_coord_file = os.path.join(full_path,'CHK_COORD_YND.dat')
            z_coord_file = os.path.join(full_path,'CHK_COORD_ZND.dat')
        #===================================================================
        #Extracting XND from the .dat file
    
        file=open(x_coord_file,'rb')
        x_coord=np.loadtxt(file,comments='#')
        x_size=  int(x_coord[0])
        x_coord=np.delete(x_coord,0)
        
        if tgpost and not ioflg:
            XND = x_coord[:-1]
        else:
            for i in range(x_size):
                if x_coord[i] == 0.0:
                    index=i
                    break
            if tgpost and ioflg:
                XND = x_coord[:index+1]
                XND -= XND[0]
            else:
                XND = x_coord[index+1:]
        file.close()
        #===========================================================
    
        #Extracting YCC from the .dat file
        file=open(y_coord_file,'rb')
        y_coord=np.loadtxt(file,comments='#',usecols=1)
        y_size = int(y_coord[0])
        for i in range(y_coord.size):
            if y_coord[i] == 1.0:
                index=i
                break
        
        # YCC=np.delete(y_coord,np.arange(index+1))
        YND = y_coord[:index+1]
        YCC = y_coord[(index+1):]
        y_size = YCC.size
        file.close()
        #============================================================
    
        file=open(z_coord_file,'rb')
        z_coord=np.loadtxt(file,comments='#')
        z_size = int(z_coord[0])
        ZND=np.delete(z_coord,0)
        #============================================================
        XCC, ZCC = self._coord_interp(XND,ZND)

        z_size = ZCC.size
        x_size = XCC.size
        y_size = YCC.size
        file.close()

        CoordDF = cd.datastruct({'x':XCC,'y':YCC,'z':ZCC})
        Coord_ND_DF = cd.datastruct({'x':XND,'y':YND,'z':ZND})
        NCL = [x_size, y_size, z_size]
        return CoordDF, Coord_ND_DF, NCL
Exemple #11
0
    def _extract_fluct(self,
                       x,
                       y,
                       path_to_folder=None,
                       time0=None,
                       gridsize=200,
                       y_mode='half-channel',
                       use_ini=True,
                       xy_inner=True,
                       tgpost=False,
                       abs_path=True):

        times = misc_utils.time_extract(path_to_folder, abs_path)
        if time0 is not None:
            times = list(filter(lambda x: x > time0, times))
        if cp.rcParams['TEST']:
            times.sort()
            times = times[-5:]
        self._meta_data = self._module._meta_class(path_to_folder, abs_path)

        try:
            self.avg_data = self._module._avg_io_class(max(times),
                                                       self._meta_data,
                                                       path_to_folder, time0,
                                                       abs_path)
        except Exception:
            times.remove(max(times))
            self.avg_data = self._module._avg_io_class(max(times),
                                                       self._meta_data,
                                                       path_to_folder, time0)

        if xy_inner:
            if len(x) != len(y):
                msg = "length of x coordinate array must be same"+\
                        " as the y coord array. Lengths provided %d (x),"%len(x)+\
                            " %d (y)"%len(y)
                raise ValueError(msg)

            x_coord_list = x
            y_coord_list = y
        else:
            x_coord_list = []
            y_coord_list = []
            for x_val in x:
                for y_val in y:
                    x_coord_list.append(x_val)
                    y_coord_list.append(y_val)

        x_index = indexing.coord_index_calc(self.avg_data.CoordDF, 'x',
                                            x_coord_list)

        self._x_loc_norm = x_coord_list if not use_ini else [0] * len(
            y_coord_list)
        y_index = indexing.y_coord_index_norm(self.avg_data, y_coord_list,
                                              self._x_loc_norm, y_mode)

        y_index = np.diag(np.array(y_index))
        u_prime_array = [[] for _ in range(len(y_index))]
        v_prime_array = [[] for _ in range(len(y_index))]

        for time in times:
            fluct_data = self._module._fluct_io_class(time, self.avg_data,
                                                      path_to_folder, abs_path)
            u_prime_data = fluct_data.fluctDF[time, 'u']
            v_prime_data = fluct_data.fluctDF[time, 'v']
            for i in range(len(y_index)):
                u_prime_array[i].extend(u_prime_data[:, y_index[i],
                                                     x_index[i]])
                v_prime_array[i].extend(v_prime_data[:, y_index[i],
                                                     x_index[i]])
                if cp.rcParams['SymmetryAVG'] and self.metaDF['iCase'] == 1:
                    y_size = u_prime_data.shape[1]
                    u_prime_array[i].extend(u_prime_data[:, -1 - y_index[i],
                                                         x_index[i]])
                    v_prime_array[i].extend(
                        -1 * v_prime_data[:, -1 - y_index[i], x_index[i]])
            # del fluct_data#; del u_prime_data; del v_prime_data
            gc.collect()

        pdf_array = [[] for _ in range(len(y_index))]
        u_array = [[] for _ in range(len(y_index))]
        v_array = [[] for _ in range(len(y_index))]
        estimator = seaborn._statistics.KDE(gridsize=gridsize)
        for i, y in enumerate(y_index):
            pdf_array[i], (u_array[i],
                           v_array[i]) = estimator(np.array(u_prime_array[i]),
                                                   np.array(v_prime_array[i]))

            # ax = seaborn.kdeplot(u_prime_array[i],v_prime_array[i],gridsize=gridsize)
            # for artist in ax.get_children():
            #     if isinstance(artist,mpl.contour.QuadContourSet):

        index = list(zip(x_coord_list, y_coord_list))

        pdf_array = np.array(pdf_array)
        u_array = np.array(u_array)
        v_array = np.array(v_array)

        self._y_mode = y_mode
        self.pdf_arrayDF = cd.datastruct(pdf_array, index=index)
        self.u_arrayDF = cd.datastruct(u_array, index=index)
        self.v_arrayDF = cd.datastruct(v_array, index=index)
Exemple #12
0
    def _autocov_extract(self,
                         comp1,
                         comp2,
                         path_to_folder='.',
                         time0=None,
                         abs_path=True,
                         max_x_sep=None,
                         max_z_sep=None):
        times = misc_utils.time_extract(path_to_folder, abs_path)
        if time0 is not None:
            times = list(filter(lambda x: x > time0, times))

        if cp.rcParams['TEST']:
            times.sort()
            times = times[-3:]

        self._meta_data = self._module.CHAPSim_meta(path_to_folder)
        self.comp = (comp1, comp2)
        self.NCL = self._meta_data.NCL
        self._avg_data = self._module._avg_tg_base_class(
            times,
            meta_data=self._meta_data,
            path_to_folder=path_to_folder,
            time0=time0,
            abs_path=abs_path)

        if max_z_sep is None:
            max_z_sep = int(self.NCL[2] / 2)
        elif max_z_sep > self.NCL[2]:
            raise ValueError(
                "\033[1;32 Variable max_z_sep must be less than half NCL3 in readdata file\n"
            )
        if max_x_sep is None:
            max_x_sep = int(self._NCL[0] / 2)
        elif max_x_sep > self.NCL[0]:
            raise ValueError(
                "\033[1;32 Variable max_x_sep must be less than half NCL3 in readdata file\n"
            )

        # self.shape_x = (max_x_sep,self.NCL[1],len(times))
        # self.shape_z = (max_z_sep,self.NCL[1],len(times))

        shape_x = (max_x_sep, self.NCL[1], len(times))
        shape_z = (max_z_sep, self.NCL[1], len(times))

        for timing in times:
            fluct_data = self._module._fluct_tg_class(
                timing,
                self._avg_data,
                path_to_folder=path_to_folder,
                abs_path=abs_path)
            if 'R_z' not in locals():
                R_z, R_x = self._autocov_calc(fluct_data, comp1, comp2, timing,
                                              max_x_sep, max_z_sep)
            else:
                local_R_z, local_R_x = self._autocov_calc(
                    fluct_data, comp1, comp2, timing, max_x_sep, max_z_sep)
                R_z = np.vstack([R_z, local_R_z])
                R_x = np.vstack([R_x, local_R_x])
            gc.collect()

        R_z = R_z.T.reshape(shape_z)
        R_x = R_x.T.reshape(shape_x)

        self.autocorrDF = cd.datastruct({'x': R_x, 'z': R_z})
Exemple #13
0
    def _autocov_extract(self,
                         comp1,
                         comp2,
                         path_to_folder=".",
                         time0=None,
                         abs_path=True,
                         max_x_sep=None,
                         max_z_sep=None):

        times = misc_utils.time_extract(path_to_folder, abs_path)
        if time0 is not None:
            times = list(filter(lambda x: x > time0, times))

        if cp.rcParams['TEST']:
            times.sort()
            times = times[-5:]

        self._meta_data = self._module._meta_class(path_to_folder)
        self.comp = (comp1, comp2)

        try:
            self._avg_data = self._module._avg_io_class(
                max(times), self._meta_data, path_to_folder, time0, abs_path)
        except Exception:
            times.remove(max(times))
            self._avg_data = self._module._avg_io_class(
                max(times), self._meta_data, path_to_folder, time0)

        if max_z_sep is None:
            max_z_sep = int(self.NCL[2] * 0.5)
        elif max_z_sep > self.NCL[2]:
            raise ValueError(
                "Variable max_z_sep must be less than half NCL3 in readdata file\n"
            )

        if max_x_sep is None:
            max_x_sep = int(self.NCL[0] * 0.5)
        elif max_x_sep > self.NCL[0]:
            raise ValueError(
                "Variable max_x_sep must be less than half NCL3 in readdata file\n"
            )

        # self.shape_x = (max_x_sep,self.NCL[1],self.NCL[0]-max_x_sep)
        # self.shape_z = (max_z_sep,self.NCL[1],self.NCL[0])

        for i, timing in enumerate(times):

            fluct_data = self._module._fluct_io_class(
                timing,
                self._avg_data,
                time0=time0,
                path_to_folder=path_to_folder,
                abs_path=abs_path)
            coe3 = i / (i + 1)
            coe2 = 1 / (i + 1)

            if i == 0:
                R_x, R_z = self._autocov_calc(fluct_data, comp1, comp2, timing,
                                              max_x_sep, max_z_sep)
            else:
                local_R_x, local_R_z = self._autocov_calc(
                    fluct_data, comp1, comp2, timing, max_x_sep, max_z_sep)
                if R_x.shape != local_R_x.shape or R_z.shape != local_R_z.shape:
                    msg = "There is a problem. the shapes of the local and averaged array are different"
                    raise ValueError(msg)
                R_x = R_x * coe3 + local_R_x * coe2
                R_z = R_z * coe3 + local_R_z * coe2

        if cp.rcParams['SymmetryAVG'] and self.metaDF['iCase'] == 1:
            vy_count = comp1.count('v') + comp2.count('v')
            R_x = 0.5 * (R_x + R_x[:, ::-1] * (-1)**vy_count)
            R_z = 0.5 * (R_z + R_z[:, ::-1] * (-1)**vy_count)

        self.autocorrDF = cd.datastruct({
            'x': R_x,
            'z': R_z
        })  #.data([shape_x,shape_z])