def test_ManageData_Read(self): md_dump = ManageData(dump_file=self.file_name) md_dump.PushData(data=np.random.rand(10), key='paperino') md_dump.PushData(data='pippo, pluto', key='pappo') md_dump.Dump() del md_dump md_read = ManageData(dump_file=self.file_name) read_flag = md_read.Read() del md_read os.remove(self.file_name) self.assertTrue(read_flag)
def test_ManageData_ReadAndDump(self): md_dump = ManageData(dump_file=self.file_name) md_dump.PushData(data=np.random.rand(10), key='paperino') md_dump.PushData(data='pippo, pluto', key='pappo') md_dump.Dump() del md_dump md_read = ManageData(dump_file=self.file_name) md_read.Read() os.rename(self.file_name, self.file_name_mv) md_read.Dump() del md_read file_cmp = filecmp.cmp(self.file_name, self.file_name_mv) os.remove(self.file_name) os.remove(self.file_name_mv) self.assertTrue(file_cmp)
E_sym_YN = {E8_P2F8_sym: 'No', E8_P4F6_sym: 'Yes'} gibbs_rad = defaultdict( # G lambda: defaultdict( # 'B2F6' lambda: defaultdict( # 'P4Iso=' + YN lambda: defaultdict(dict) # 'droplet' ))) from idpy.Utils.ManageData import ManageData for _psi in [psis[0]]: for _stencil in [E8_P2F8_sym, E8_P4F6_sym]: _data_swap = ManageData( dump_file=laplace_files_E8[StencilPsiKey(_stencil, _psi)]) _is_file_there = _data_swap.Read() if not _is_file_there: raise Exception("Could not find file!", laplace_files_E8[StencilPsiKey(_stencil, _psi)]) for G in Gs[_psi]: _swap_gibbs_rad = [] for L in Ls: _data_key = str(G) + "_" + str(L) _swap_gibbs_rad.append( _data_swap.PullData(_data_key)['R_Gibbs']) gibbs_rad['G=' + str(G)]['B2F6']['P4Iso=' + E_sym_YN[_stencil]]['droplet'] = \ np.array(_swap_gibbs_rad) UFields = {}
E6_P4F6_sym: 'E6P4', E8_P2F8_sym: 'E8P2', E8_P4F6_sym: 'E8P4', E10_P2F10_sym: 'E10P2', E10_P4F6_sym: 'E10P4', E12_P2F12_sym: 'E12P2', E12_P4F6_sym: 'E12P4' } for L in [255, 351]: for _psi in psis: for G in Gs[_psi]: for _stencil in stencil_sym_list: _data_swap = ManageData( dump_file=droplets_files[StencilPsiKey(_stencil, _psi)]) _is_file_there = _data_swap.Read() if not _is_file_there: raise Exception( "Could not find file!", droplets_files[StencilPsiKey(_stencil, _psi)]) _data_key = str(G) + "_" + str(L) UFields['G' + str(G) + 'LX' + str(L) + E_sym_dict[_stencil]] = \ _data_swap.PullData(_data_key) ################################################ ########### END DATA HANDLING ################## ################################################ # https://stackoverflow.com/questions/14737681/fill-the-right-column-of-a-matplotlib-legend-first
E_sym_dict_m1, E_str_dict_m1 = {}, {} for _ in E_sym_dict: E_sym_dict_m1[E_sym_dict[_]] = _ for _ in E_str_dict: E_str_dict_m1[E_str_dict[_]] = _ UFields = {} gibbs_rad = {} from idpy.Utils.ManageData import ManageData AveU = ManageData(dump_file = 'AverageProfiles') if not AveU.Read(): print("File 'AverageProfiles' not found (!): computing and saving the average profiles") for L in [255]: for _psi in psis: for G in Gs[_psi]: for _stencil in stencil_sym_list: _data_swap = ManageData(dump_file = droplets_files[StencilPsiKey(_stencil, _psi)]) _is_file_there = _data_swap.Read() if not _is_file_there: raise Exception("Could not find file!", droplets_files[StencilPsiKey(_stencil, _psi)]) _data_key = str(G) + "_" + str(L) UFields['G' + str(G) + 'LX' + str(L) + E_sym_dict[_stencil]] = \ _data_swap.PullData(_data_key)
def __init__(self, stencil=None, G=None, c2=None, psi_f=None, dump_file='SCEqCache'): ManageData.__init__(self, dump_file=dump_file) if stencil is None: raise Exception("Missing argument stencil") if G is None: raise Exception("Missing argument G") if c2 is None: raise Exception("Missing argument c2") if psi_f is None: raise Exception("Missing argument psi_f") ''' Looking for the file and data ''' self.is_file, self.is_key = ManageData.Read(self), False self.dict_string = (str(psi_f) + "_" + str(float(G)) + "_" + str(c2) + "_" + str(stencil.w_sol[0])) if self.is_file: if self.dict_string in ManageData.WhichData(self): self.data = ManageData.PullData(self, self.dict_string) self.is_key = True if self.is_key is False: ''' I need to do this until I write a new pressure tensor class that also computes the Taylor expansion for the flat interface and consequently the expression for \varepsilon ''' w1, w2, w4, w5, w8 = sp_symbols("w(1) w(2) w(4) w(5) w(8)") w9, w10, w13, w16, w17 = sp_symbols("w(9) w(10) w(13) w(16) w(17)") w_sym_list = [w1, w2, w4, w5, w8, w9, w10, w13, w16, w17] _eps_expr = (+48 * w4 + 96 * w5 + 96 * w8 + 288 * w9 + 576 * w10 + 704 * w13 + 960 * w16 + 1920 * w17) _eps_expr /= (+6 * w1 + 12 * w2 + 72 * w4 + 156 * w5 + 144 * w8 + 342 * w9 + 696 * w10 + 812 * w13 + 1056 * w16 + 2124 * w17) self.eps_lambda = sp_lambdify([w_sym_list], _eps_expr) _e2_expr = stencil.e_expr[2] self.e2_lambda = sp_lambdify([w_sym_list], _e2_expr) _weights_list = None if len(stencil.w_sol[0]) != 10: len_diff = 10 - len(stencil.w_sol[0]) if len_diff < 0: raise Exception("The number of weights must be 5 at most!") _weights_list = stencil.w_sol[0] + [0 for i in range(len_diff)] else: _weights_list = stencil.w_sol[0] _shan_chen = \ ShanChen(psi_f = psi_f, G_val = G, theta_val = c2, e2_val = self.e2_lambda(_weights_list)) _shan_chen.PressureTensorInit(stencil) _shan_chen.FlatInterfaceProperties() _shan_chen.FInterface.MechanicEquilibrium() _mech_eq_target = _shan_chen.FInterface.mech_eq_target _sigma_f = \ _shan_chen.FInterface.SurfaceTension(_mech_eq_target) _n_g = _shan_chen.FInterface.mech_eq_target[0][0] _n_l = _shan_chen.FInterface.mech_eq_target[1][0] _p_0 = _shan_chen.FInterface.mech_eq_target[1][1] _n_c = _shan_chen.n_c _G_c = _shan_chen.G_c _data_dict = { 'G_c': _G_c, 'n_c': _n_c, 'n_l': _n_l, 'n_g': _n_g, 'p_0': _p_0, 'sigma_f': _sigma_f } self.PushData(data=_data_dict, key=self.dict_string) self.Dump()