def system_jacobian(self, state_vars, time): current, theta, potential=state_vars if self.simulation_options["method"]=="sinusoidal": Et=isolver_martin_brent.et(self.nd_param.nd_param_dict["E_start"],self.nd_param.nd_param_dict["nd_omega"], self.nd_param.nd_param_dict["phase"], self.nd_param.nd_param_dict["d_E"], time) dEdt=isolver_martin_brent.dEdt(self.nd_param.nd_param_dict["nd_omega"], self.nd_param.nd_param_dict["phase"], self.nd_param.nd_param_dict["d_E"], time) elif self.simulation_options["method"]=="ramped": Et=isolver_martin_brent.c_et(self.nd_param.nd_param_dict["E_start"], self.nd_param.nd_param_dict["E_reverse"], (self.nd_param.nd_param_dict["E_reverse"]-self.nd_param.nd_param_dict["E_start"]) ,self.nd_param.nd_param_dict["nd_omega"], self.nd_param.nd_param_dict["phase"], 1,self.nd_param.nd_param_dict["d_E"],time) dEdt=isolver_martin_brent.c_dEdt(self.nd_param.nd_param_dict["tr"] ,self.nd_param.nd_param_dict["nd_omega"], self.nd_param.nd_param_dict["phase"], 1,self.nd_param.nd_param_dict["d_E"],time) elif self.simulation_options["method"]=="dcv": Et=isolver_martin_brent.dcv_et(self.nd_param.nd_param_dict["E_start"], self.nd_param.nd_param_dict["E_reverse"], (self.nd_param.nd_param_dict["E_reverse"]-self.nd_param.nd_param_dict["E_start"]) , 1,time) dEdt=isolver_martin_brent.dcv_dEdt(self.nd_param.nd_param_dict["tr"],1,time) Er=Et-(self.nd_param.nd_param_dict["Ru"]*current) ErE0=Er-self.nd_param.nd_param_dict["E_0"] alpha=self.nd_param.nd_param_dict["alpha"] exp11=self.nd_param.nd_param_dict["k_0"]*np.exp((1-alpha)*ErE0) exp12=self.nd_param.nd_param_dict["k_0"]*np.exp((-alpha)*ErE0) Cdlp=self.nd_param.nd_param_dict["Cdl"]*(1+self.nd_param.nd_param_dict["CdlE1"]*Er+self.nd_param.nd_param_dict["CdlE2"]*(Er**2)+self.nd_param.nd_param_dict["CdlE3"]*(Er**3)) jacobian=np.zeros((2, 2)) dtheta_dI=(-(1-theta)*(1-alpha)*exp11*self.nd_param.nd_param_dict["Ru"])-(theta*alpha*self.nd_param.nd_param_dict["Ru"]*exp12) #dtheta_dE=((1-theta)*(1-alpha)*exp11)+(theta*alpha*exp12) dtheta_dtheta=-exp11-exp12 jacobian[1, :]=[dtheta_dI, dtheta_dtheta] jacobian[0, 0]=(-1/(self.nd_param.nd_param_dict["Ru"]*Cdlp))+(self.nd_param.nd_param_dict["gamma"]/Cdlp*self.nd_param.nd_param_dict["Ru"])*dtheta_dI #jacobian[0, 1]=(self.nd_param.nd_param_dict["gamma"]/Cdlp*self.nd_param.nd_param_dict["Ru"])*dtheta_dE jacobian[0, 1]=(self.nd_param.nd_param_dict["gamma"]/Cdlp*self.nd_param.nd_param_dict["Ru"])*dtheta_dtheta return jacobian
def voltage_query(self, time): if self.current_class.simulation_options["method"] == "sinusoidal": Et = isolver_martin_brent.et( self.nd_param.nd_param_dict["E_start"], self.nd_param.nd_param_dict["nd_omega"], self.nd_param.nd_param_dict["phase"], self.nd_param.nd_param_dict["d_E"], time) dEdt = isolver_martin_brent.dEdt( self.nd_param.nd_param_dict["nd_omega"], self.nd_param.nd_param_dict["phase"], self.nd_param.nd_param_dict["d_E"], time) elif self.current_class.simulation_options["method"] == "ramped": Et = -1 * isolver_martin_brent.c_et( self.nd_param.nd_param_dict["E_start"], self.nd_param.nd_param_dict["E_reverse"], (self.nd_param.nd_param_dict["E_reverse"] - self.nd_param.nd_param_dict["E_start"]), self.nd_param.nd_param_dict["nd_omega"], self.nd_param.nd_param_dict["phase"], 1, self.nd_param.nd_param_dict["d_E"], time) dEdt = -1 * isolver_martin_brent.c_dEdt( self.nd_param.nd_param_dict["tr"], self.nd_param.nd_param_dict["nd_omega"], self.nd_param.nd_param_dict["phase"], 1, self.nd_param.nd_param_dict["d_E"], time) elif self.current_class.simulation_options["method"] == "dcv": Et = isolver_martin_brent.dcv_et( self.nd_param.nd_param_dict["E_start"], self.nd_param.nd_param_dict["E_reverse"], (self.nd_param.nd_param_dict["E_reverse"] - self.nd_param.nd_param_dict["E_start"]), 1, time) dEdt = isolver_martin_brent.dcv_dEdt( self.nd_param.nd_param_dict["tr"], 1, time) elif self.current_class.simulation_options["method"] == "square_wave": time_position = int(np.ceil(time)) Et = SWV_surface.potential( time_position, self.nd_param.nd_param_dict["sampling_factor"], self.nd_param.nd_param_dict["scan_increment"], self.nd_param.nd_param_dict["SW_amplitude"], self.nd_param. nd_param_dict["E_start"]) / self.nd_param.sw_class.c_E0 dEdt = None elif self.current_class.simulation_options[ "method"] == "square_wave_fourier": Et = SWV_surface.fourier_Et( math.pi, self.nd_param.nd_param_dict["scan_increment"], self.nd_param.nd_param_dict["fourier_order"], self.nd_param.nd_param_dict["SW_amplitude"], self.nd_param.nd_param_dict["E_start"], time) dEdt = SWV_surface.fourier_dEdt( math.pi, self.nd_param.nd_param_dict["scan_increment"], self.nd_param.nd_param_dict["fourier_order"], self.nd_param.nd_param_dict["SW_amplitude"], time) #print(Et) Et = Et / self.nd_param.sw_class.c_E0 dEdt = dEdt / self.nd_param.sw_class.c_E0 return Et, dEdt
def define_voltages(self): voltages=np.zeros(len(self.time_vec)) if self.simulation_options["method"]=="sinusoidal": for i in range(0, len(self.time_vec)): voltages[i]=isolver_martin_brent.et(self.nd_param.E_start,self.nd_param.nd_omega, self.nd_param.phase, self.nd_param.d_E, (self.time_vec[i])) elif self.simulation_options["method"]=="ramped": for i in range(0, len(self.time_vec)): voltages[i]=isolver_martin_brent.c_et(self.nd_param.E_start, self.nd_param.E_reverse, (self.nd_param.E_reverse-self.nd_param.E_start) ,self.nd_param.nd_omega, self.nd_param.phase, 1,self.nd_param.d_E,(self.time_vec[i])) elif self.simulation_options["method"]=="dcv": for i in range(0, len(self.time_vec)): voltages[i]=isolver_martin_brent.dcv_et(self.nd_param.E_start, self.nd_param.E_reverse, (self.nd_param.E_reverse-self.nd_param.E_start) , 1,(self.time_vec[i])) return voltages
def define_voltages(self, transient=False): voltages=np.zeros(len(self.time_vec)) if self.simulation_options["method"]=="sinusoidal": for i in range(0, len(self.time_vec)): voltages[i]=isolver_martin_brent.et(self.nd_param.nd_param_dict["E_start"],self.nd_param.nd_param_dict["nd_omega"], self.nd_param.nd_param_dict["phase"], self.nd_param.nd_param_dict["d_E"], (self.time_vec[i])) elif self.simulation_options["method"]=="ramped": for i in range(0, len(self.time_vec)): voltages[i]=isolver_martin_brent.c_et(self.nd_param.nd_param_dict["E_start"], self.nd_param.nd_param_dict["E_reverse"], (self.nd_param.nd_param_dict["E_reverse"]-self.nd_param.nd_param_dict["E_start"]) ,self.nd_param.nd_param_dict["nd_omega"], self.nd_param.nd_param_dict["phase"], 1,self.nd_param.nd_param_dict["d_E"],(self.time_vec[i])) elif self.simulation_options["method"]=="dcv": for i in range(0, len(self.time_vec)): voltages[i]=isolver_martin_brent.dcv_et(self.nd_param.nd_param_dict["E_start"], self.nd_param.nd_param_dict["E_reverse"], (self.nd_param.nd_param_dict["E_reverse"]-self.nd_param.nd_param_dict["E_start"]) , 1,(self.time_vec[i])) if transient==True: voltages=voltages[self.time_idx] return voltages
def current_ode_sys(self, state_vars, time): current, theta, potential=state_vars if self.simulation_options["method"]=="sinusoidal": Et=isolver_martin_brent.et(self.nd_param.nd_param_dict["E_start"],self.nd_param.nd_param_dict["nd_omega"], self.nd_param.nd_param_dict["phase"], self.nd_param.nd_param_dict["d_E"], time) dEdt=isolver_martin_brent.dEdt(self.nd_param.nd_param_dict["nd_omega"], self.nd_param.nd_param_dict["phase"], self.nd_param.nd_param_dict["d_E"], time) elif self.simulation_options["method"]=="ramped": Et=isolver_martin_brent.c_et(self.nd_param.nd_param_dict["E_start"], self.nd_param.nd_param_dict["E_reverse"], (self.nd_param.nd_param_dict["E_reverse"]-self.nd_param.nd_param_dict["E_start"]) ,self.nd_param.nd_param_dict["nd_omega"], self.nd_param.nd_param_dict["phase"], 1,self.nd_param.nd_param_dict["d_E"],time) dEdt=isolver_martin_brent.c_dEdt(self.nd_param.nd_param_dict["tr"] ,self.nd_param.nd_param_dict["nd_omega"], self.nd_param.nd_param_dict["phase"], 1,self.nd_param.nd_param_dict["d_E"],time) elif self.simulation_options["method"]=="dcv": Et=isolver_martin_brent.dcv_et(self.nd_param.nd_param_dict["E_start"], self.nd_param.nd_param_dict["E_reverse"], (self.nd_param.nd_param_dict["E_reverse"]-self.nd_param.nd_param_dict["E_start"]) , 1,time) dEdt=isolver_martin_brent.dcv_dEdt(self.nd_param.nd_param_dict["tr"],1,time) Er=Et-(self.nd_param.nd_param_dict["Ru"]*current) ErE0=Er-self.nd_param.nd_param_dict["E_0"] alpha=self.nd_param.nd_param_dict["alpha"] self.Cdlp=self.nd_param.nd_param_dict["Cdl"]*(1+self.nd_param.nd_param_dict["CdlE1"]*Er+self.nd_param.nd_param_dict["CdlE2"]*(Er**2)+self.nd_param.nd_param_dict["CdlE3"]*(Er**3)) d_thetadt=((1-theta)*self.nd_param.nd_param_dict["k_0"]*np.exp((1-alpha)*ErE0))-(theta*self.nd_param.nd_param_dict["k_0"]*np.exp((-alpha)*ErE0)) dIdt=(dEdt-(current/self.Cdlp)+self.nd_param.nd_param_dict["gamma"]*d_thetadt*(1/self.Cdlp))/self.nd_param.nd_param_dict["Ru"] f=[dIdt, d_thetadt, dEdt] return f