def plot_for(z, d): cs = CalcSimWrapper() ds = InputDatastore('../InputData', 'NiCu', 973) ce = ComparisonEngine(cs) D = ds.interpolated_diffusivity(10001) R = ds.interpolated_resistivity(10001) dx = 0.5 * 35e-8 ndx = 200 dt = 0.01 ndt = int(2 * 60 * 60 / 0.01) init = ones(ndx) init[ndx/2:] = 0 x = linspace(0, 25, 200) ddict = ds.interpolated_experiment_dict(x) for I in ddict.keys(): if I == 0: dv = 1 else: dv = d r = cs.emigration_factor(z, I, 973) mdl = cs.calc_simulation(D, R, init, ndt, dt, dx, r, dv) ce = ComparisonEngine(cs) lsq, shfit = ce.calibrate(mdl, ddict[I]) smdl = ce.shift_data(mdl) plot(x, ddict[I], label=str.format('Exper. (I={} A/cm^2)', I/100/100)) plot(x, smdl, label=str.format('Model. (I={} A/cm^2)', I/100/100)) legend(loc=3) show()
def quicksim(z, cvf, I, exper, direction): ce = ComparisonEngine(accelcs) if direction == 'reverse': I = -np.abs(I) else: I = np.abs(I) diffusivity = dstore.interpolated_diffusivity(10001, args.temperature, precise=True) resistivity = dstore.interpolated_resistivity(10001, args.temperature) r = accelcs.emigration_factor(z, I * 100 * 100, args.temperature) simd = accelcs.calc_simulation(diffusivity, resistivity, init_cond, ndt, dt, dx, r, cvf) lsq, shift = ce.calibrate(simd, exper) shifted_simd = ce.shift_data(simd) return shifted_simd, lsq
def do_work(T, I): with dstorelock: Davg = dstore.interpolated_diffusivity(1001, T).mean() n_secs_sim = 1e-12 / Davg dt = n_secs_sim / (defaults.simulation_tsteps * 1) cse = CalcSimExecutor(dstore, T, dt=dt, ndt=(defaults.simulation_tsteps * 1)) try: current = cse.compute(z, cvfunc(I), I, direction)[:, 1] nocurrent = cse.compute(0, 1, 0, direction)[:, 1] except SimulationUnstableError: print('F****d up on T = {}, I = {}'.format(T, I)) print('Max D = {}'.format(cse.Dvector.max())) raise shiftengine = ComparisonEngine(cse.cs) lsq, _ = shiftengine.calibrate(current, nocurrent) return lsq
def do_work(self, z, dmult, IAbs, ISigned): """ Actually does one item of work from the search() method :param z: The effective valence :param dmult: The premultiplication factor for D :return: A measure of how good the model fits the data for these parameters """ logging.debug(str.format('Executing workload ({}, {}))', z, dmult)) r = self.calcsim_wrapper.emigration_factor(z, ISigned * 100 * 100, self.emigration_T) simresults = self.calcsim_wrapper.calc_simulation(self.diffusivity, self.resistivity, self.init_cond, self.ndt, self.dt, self.dx, r, dmult) ce = ComparisonEngine(self.calcsim_wrapper) lsq, shift = ce.calibrate(simresults, self.exper_data[IAbs]) return lsq
def do_stage1(self): """Our stage 1 is to do the requested simulation and spit out a csv file with (x, sim, exper) """ simexec = CalcSimExecutor(self.dstore, self.args.temperature) try: simdata = simexec.compute(self.args.z, self.args.cvf, self.args.current, self.args.direction) except SimulationUnstableError: print('Bang! Dmax = {}, Dmin = {}'.format(simexec.Dvector.max(), simexec.Dvector.min())) raise experdata = self.dstore.interpolated_experiment(self.args.current, simdata[:, 0], self.args.direction) ce = ComparisonEngine(CalcSimWrapper()) ce.calibrate(simdata[:, 1], experdata) simdata[:, 1] = ce.shift_data(simdata[:, 1]) self.fulldata = np.column_stack((simdata, experdata)) self.ostore.add_matrix(self.fulldata, '.csv')
matplotlib.rcParams['ytick.labelsize'] = 20 def get_edict(x): return ds.interpolated_experiment_fw_dict(x) if direction == 'forward' else ds.interpolated_experiment_rv_dict(x) figure() cse = CalcSimExecutor(ds, T) colours = ['#0000FF', '#FF0000', '#003300', '#DD8500'] colours.reverse() for I, sh in [[0, 0], [400, 0], [800, 0], [1000, 0]]: cvf = 0.53e-3 * I + 1 simd = cse.compute(z, cvf, I, direction) x = simd[:, 0] edict = get_edict(x) expr = edict[I] shifter = ComparisonEngine(cse.cs) shifter.calibrate(simd[:, 1], expr) #simd[:, 1] = shifter.shift_data(simd[:, 1]) x += sh cl = colours.pop() #plot(x, expr, linestyle='-', label='I = {}A/cm^2'.format(I)) plot(x, simd[:, 1], linestyle='-', color=cl, linewidth=2, label=r'$\mathrm{'+str(I)+'A/cm}^2$') xlim([5, 20]) xticks(arange(5, 21, 5)) xlabel('Position (micron)') ylabel('Cu Composition (at. frac.)') lg = legend(loc='center left') lg.get_frame().set_alpha(0) lg.get_frame().set_edgecolor('white')
for I in I_plot: cvf_plot_list.append(cbounds[I][1]) cvf_plot = np.array(cvf_plot_list) ebars_list_lower = [] ebars_list_upper = [] for I in I_plot: ebars_list_lower.append(cbounds[I][0]) ebars_list_upper.append(cbounds[I][2]) ebars = np.array([ebars_list_lower, ebars_list_upper]) plot_data = np.column_stack((I_plot, cvf_plot)) outfile = get_fname('cvfplot_combined.png') dmplots.plot_cvf_function_ebars(plot_data, ebars, 'combined', outfile) #and politely output simulations cse = CalcSimExecutor(ds, T) ce = ComparisonEngine(cse.cs) x = linspace(0, 25, 100) for direction in ('forward', 'reverse'): for I in cresults.keys(): for idx, edge in ((0, 'lower'), (1, 'best'), (2, 'upper')): outfile = get_fname(str.format('Comparison_I{}_{}_{}bound.png', I, direction, edge)) cvf = cbounds[I][1] if idx == 0: cvf -= cbounds[I][idx] elif idx == 2: cvf += cbounds[I][idx] print('using cvf = ' + str(cvf)) edict = ds.edict_for_direction(direction) exper = ds.interpolated_experiment_dict(x, edict)[I] simd = cse.compute(zaverage_rounded, cvf, I, direction) exper = np.column_stack((x, exper))
I = 3000 cvfunc = lambda ID: 0.0014 * ID ioff() figure() for T in (1000, 1100, 1200): Davg = dstore.interpolated_diffusivity(1001, T).mean() n_secs_sim = 1e-12 / Davg ndt = int(n_secs_sim / defaults.simulation_dt) cse = CalcSimExecutor(dstore, T) current_whole = cse.compute(z, cvfunc(I), I, "forward") nocurrent = cse.compute(0, 1, 0, "forward")[:, 1] x = current_whole[:, 0] current = current_whole[:, 1] shiftengine = ComparisonEngine(cse.cs) lsq, _ = shiftengine.calibrate(current, nocurrent) s_current = shiftengine.shift_data(current) plot(x, s_current, label="{}K, current".format(T)) plot(x, nocurrent, label="{}K, no current".format(T)) xlabel("x coordinate (micron)") ylabel("Cu concentration (at. fraction)") title("Comparison of different Temps with correction") legend(loc="lower left") show()
ylabel("Cu. Composition (at. fraction)") title("Investigation of checkerboard") subplot(212) xlabel("Position (micron)") ylabel(r"$\Delta$Cu Composition (at. fraction)") for T in (1046, 1048, 1050, 1052): Davg = dstore.interpolated_diffusivity(1001, T).mean() n_secs_sim = 1e-12 / Davg dt = n_secs_sim / (defaults.simulation_tsteps * 1) cse = CalcSimExecutor(dstore, T, dt=dt, ndt=(defaults.simulation_tsteps * 1)) simd_lc = cse.compute(z, cvfunc(2600), 2600, "forward") simd_hc = cse.compute(z, cvfunc(2700), 2700, "forward") shiftengine = ComparisonEngine(cse.cs) shiftengine.calibrate(simd_lc[:, 1], simd_hc[:, 1]) simd_lc[:, 1] = shiftengine.shift_data(simd_lc[:, 1]) subplot(211) plot(simd_lc[:, 0], simd_lc[:, 1], label="T = {}K, I = {}A/cm^2".format(T, 2600)) plot(simd_hc[:, 0], simd_hc[:, 1], label="T = {}K, I = {}A/cm^2".format(T, 2700)) subplot(212) plot(simd_lc[:, 0], simd_hc[:, 1] - simd_lc[:, 1], label="T = {}K".format(T)) subplot(211) legend(loc="best") subplot(212) legend(loc="best") savefig("../checkerboard_investigation.png")
aparser.add_argument('--dataprefix', metavar='PREFIX', type=str, default='NiCu', help='Prefix to data files') aparser.add_argument('--output', metavar='FILE', type=str, required=True, help='File to output to') aparser.add_argument('--z', type=float, required=True, help='Effective valence') aparser.add_argument('--cvf', type=float, required=True, help='Vacancy concentration factor') aparser.add_argument('--direction', type=str, default='forward', help='Direction of application of current') args = aparser.parse_args() accelcs = CalcSimWrapper() dstore = InputDatastore(args.inputdata, args.dataprefix, 973, args.direction) ce = ComparisonEngine(accelcs) x = np.linspace(0, 25, num=100) exper_data = dstore.interpolated_experiment_dict(x)[args.current] diffusivity = dstore.interpolated_diffusivity(10001) resistivity = dstore.interpolated_resistivity(10001) init_cond = np.ones(100) init_cond[50:] = 0 emigration_T = 973 dt = 0.05 ndt = int(2 * 60 * 60 / 0.05) dx = 25e-6 / 100 r = accelcs.emigration_factor(args.z, args.current * 100 * 100, emigration_T) simd = accelcs.calc_simulation(diffusivity, resistivity, init_cond, ndt, dt, dx, r, args.cvf)