[docs]classVerticalStabilizer:"""Vertical stability controller wrapper for a tokamak."""def__init__(self,n_index:float,Ip_MA:float,R0:float,m_eff:float,tau_wall:float,smc:SuperTwistingSMC,):self.n_index=n_indexself.Ip=Ip_MA*1e6self.R0=R0self.m_eff=m_effself.tau_wall=tau_wallself.smc=smc
[docs]defstep(self,Z_meas:float,Z_ref:float,dZ_dt_meas:float,dt:float)->float:"""Compute vertical stabilization command from position error and velocity."""e=Z_meas-Z_refu=self.smc.step(e,dZ_dt_meas,dt)returnu
[docs]deflyapunov_certificate(alpha:float,beta:float,L_max:float)->bool:"""Verify gain conditions: alpha > sqrt(2 L_max), beta > L_max."""cond1=alpha>math.sqrt(2.0*max(L_max,1e-12))cond2=beta>max(L_max,1e-12)returncond1andcond2
[docs]defestimate_convergence_time(alpha:float,beta:float,L_max:float,s0:float)->float:"""Upper bound on time to reach s=0."""ifL_max<0oralpha<=math.sqrt(2.0*L_max):returnfloat("inf")denom=alpha-math.sqrt(2.0*L_max)ifdenom<=0:returnfloat("inf")return2.0*math.sqrt(abs(s0))/denom