## QUICK # xs = [0.] # ys = [0.] # zs = df_true.Z.unique()[::200] ####### xs = [-0.8, -0.4, 0., 0.4, 0.8] ys = [0.] zs = df_true.Z.unique()[::25] X, Y, Z = np.meshgrid(xs,ys,zs,indexing='ij') X = X.flatten() Y = Y.flatten() Z = Z.flatten() # load Mau13 coils # geom_df = read_solenoid_geom_combined('../dev/params/', 'DS_V13_adjusted') geom_df = read_solenoid_geom_combined('../dev/params/', 'DS_V13') def Mu2e_DS_B(x=0., y=0., z=10.571): x -= 3.904 Bs = [] names = [] for i in range(len(geom_df)): geom_coil = geom_df.iloc[i] for j in range(1, int(geom_coil.N_layers+1)): # CoilIG = CoilIntegrator(geom_coil, dxyz=np.array([2e-3,2e-3, 2e-3/geom_coil.Ri]), layer=j) CoilIG = CoilIntegrator(geom_coil, dxyz=np.array([1e-3,1e-3, 1e-3/geom_coil.Ri]), layer=j) Bs.append(CoilIG.integrate(x0=x, y0=y, z0=z)) names.append(f'Coil_{geom_coil.Coil_Num}_Layer_{j}') Bs = np.array(Bs) return np.sum(Bs, axis=0)# , Bs, names
# redirect stdout to log file dt = datetime.strftime(datetime.now(), '%Y-%m-%d_%H%M%S') log_file = open(datadir + f"logs/{dt}_calculate_{reg}_region.log", "w") old_stdout = sys.stdout sys.stdout = log_file # print configs in file print(f'Region: {reg}') print(f'Testing on subset of coils? {args.Testing}\n') # step size for integrator drz = np.array([5e-3, 1e-2]) # create grid df = generate_cartesian_grid_df(regions[reg]) # define base save name base_name = f'Mau13.SolCalc.{reg}_region.standard' # load geometry geom_df_mu2e = read_solenoid_geom_combined(paramdir, paramname) # TESTING (only a few coils) if args.Testing == 'y': geom_df_mu2e = geom_df_mu2e.iloc[5:8] # loop through all coils N_coils = len(geom_df_mu2e) for i in range(N_coils): # for geom in geom_df_mu2e.itertuples(): j = int(round(geom_df_mu2e.iloc[i].Coil_Num)) # print coil number to screen for reference print(f'Calculating coil {i+1}/' + f'{N_coils}', file=old_stdout) # instantiate integrator mySolCalc = SolCalcIntegrator(geom_df_mu2e.iloc[i], drz=drz) # integrate on grid (and update the grid df) df = mySolCalc.integrate_grid(df) # save single coil results
# ys = [0.] # zs = df_true.Z.unique()[::200] ####### ''' xs = [-0.8, -0.4, 0., 0.4, 0.8] ys = [0.] zs = df_true.Z.unique()[::25] X, Y, Z = np.meshgrid(xs,ys,zs,indexing='ij') X = X.flatten() Y = Y.flatten() Z = Z.flatten() ''' # load Mau13 coils # geom_df = read_solenoid_geom_combined('../dev/params/', 'DS_V13_adjusted') geom_df = read_solenoid_geom_combined( '/home/ckampa/coding/helicalc/dev/params/', 'current_loop') geom_df['pitch_bar'] = 0 # pitch is zero for a ring geom_df['z'] = -0.0002 # fix slight offset geom_coil = geom_df.iloc[0] # CoilIG = CoilIntegrator(geom_coil, dxyz=np.array([1e-3, 1e-3, 1e-3/geom_coil.Ri]), layer=1) CoilIG = CoilIntegrator(geom_coil, dxyz=np.array([5e-4, 5e-4, 1e-4 / geom_coil.Ri]), layer=1) B_calcs = [] for row in tqdm(df.itertuples(), total=len(df)): B_calcs.append(CoilIG.integrate(row.X, row.Y, row.Z)) B_calcs = np.array(B_calcs) df['Bx_calc'] = B_calcs[:, 0] df['By_calc'] = B_calcs[:, 1]
Bzs = np.array(Bzs).flatten()[:len(df)] xs = vals_list[0].flatten()[:len(df)] ys = vals_list[1].flatten()[:len(df)] zs = vals_list[2].flatten()[:len(df)] df.loc[:, f'Bx_solcalc_{i}'] = Bxs df.loc[:, f'By_solcalc_{i}'] = Bys df.loc[:, f'Bz_solcalc_{i}'] = Bzs return df if __name__ == '__main__': from helicalc import helicalc_dir from helicalc.geometry import read_solenoid_geom_combined geom_df_mu2e = read_solenoid_geom_combined(helicalc_dir + 'dev/params/', 'Mu2e_V13') i = 0 # 1st coil in the PS #i = 5 # coil in the TS # testing grid # df_PS = pd.read_pickle('/home/ckampa/coding/mu2e_utils/BField_plot/data/PSMap_no-offset.pkl') # step size drz = np.array([5e-3, 1e-2]) # set up integrator mySolCalc = SolCalcIntegrator(geom_df_mu2e.iloc[i], drz=drz) print( f'Sample Calc @ x,y,z = (3.904, 0, -6.8): Bx, By, Bz = {mySolCalc.integrate_single(3.904, 0, -6.8)}' ) # grid does not work from this file # integrate on PS map # should take ~10 seconds # class method
from dash_table.Format import Format, Scheme # SolCalc from helicalc import helicalc_dir, helicalc_data from helicalc.solcalc import SolCalcIntegrator from helicalc.geometry import read_solenoid_geom_combined from helicalc.cylinders import get_thick_cylinders_padded external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css'] # load nominal PS geom # paramdir = '/home/ckampa/coding/helicalc/dev/params/' paramdir = helicalc_dir + 'dev/params/' paramfile = 'Mu2e_V13' df_PS_nom = read_solenoid_geom_combined(paramdir, paramfile).iloc[:3] # calculate layer thickness # FIXME! # integration params drz = np.array([5e-3, 1e-2]) # editable vs. dependent columns cols_edit = [ 'Ri', 'x', 'y', 'z', 'rot0', 'rot1', 'rot2', 'N_layers', 'N_turns', 'I_turn' ] cols_stat = [ 'Coil_Num', 'Ro', 'L', 'I_tot', 'N_turns_tot', 'helicity', 'h_cable', 'w_cable', 'h_sc', 'w_sc', 't_gi', 't_ci', 't_il', 'phi0_deg', 'phi1_deg',