I wish to change the term, T'[t] to 0 when S[t]<=0 when I solve ODEs. I have used WhenEvent in my NDSolve part, but it seems not work. The code is
Nrmlphoton[t_] = 4.64903*10^22*Piecewise[{{5904.29 t + 3.13641*10^8 t^2 - 7.0716*10^12 t^3 + 5.50886*10^16 t^4 - 1.91492*10^20 t^5 + 2.51145*10^23 t^6, 0 <= t < 0.0002274269422873725`}, {-2.86583*10^6 t + 1.69452*10^10 t^2 - 4.01716*10^13 t^3 + 4.77113*10^16 t^4 - 2.83738*10^19 t^5 + 6.75503*10^21 t^6, 0.0007374377891266094` < t < 0.0009481855159674386`}, {6.63274*10^6 t - 2.17507*10^10 t^2 + 2.82046*10^13 t^3 - 1.81037*10^16 t^4 + 5.75833*10^18 t^5 - 7.26732*10^20 t^6, 0.0014995956366184178` < t < 0.0016925447841110407`}, {0, 0.0002274269422873725` <= t <= 0.0007374377891266094`}, {0, 0.0009481855159674386` <= t <= 0.0014995956366184178`}, {0, t >= 0.0016925447841110407`}}] OpticCoupl = 0.5; ISCEff = 0.625; w = 2 Pi 1.45 10^9; Q = 3.5 10^3; (**Tres = Q/w;**) (**q0 =(Exp[6.63 10^-34 1.45 10^9/(1.38 10^-23 298)]-1)^-1**) q0 = 4277; qthermal = 4277; B = 4 10^-8; Kx = 2.7 10^4; Ky = 0.6 10^4; Kz = 1.7 10^3; Wxz = 1.1 10^4; Wyz = 2.2 10^4; Wxy = 4.4 10^3; Px = 0.76; Py = 0.16; Pz = 0.08; Ns = 2.8 10^17; sol = NDSolve[{T'[t] == Nrmlphoton ISCEff OpticCoupl, S'[t] == -T'[t] + Kx X[t] + Ky Y[t] + Kz Z[t], X'[t] == T'[t] Px - X[t] Kx - (X[t] - Z[t]) Wxz - (X[t] - Y[t]) Wxy - B (X[t] - Z[t]) q[t], Y'[t] == T'[t] Py - Y[t] Ky - (Y[t] - Z[t]) Wyz - (Y[t] - X[t]) Wxy, Z'[t] == T'[t] Pz - Z[t] Kz + (X[t] - Z[t]) Wxz + (Y[t] - Z[t]) Wyz + B (X[t] - Z[t]) q[t], q'[t] == -(w/Q) (q[t] - qthermal) + B (X[t] - Z[t]) q[t], q[0] == q0, X[0] == Y[0] == Z[0] == T[0] == 0, S[0] == Ns, WhenEvent[S[t] <= 0, T'[t] -> 0]}, {X, Y, Z, q, S}, {t, 0, 0.002}] I got the error:
NDSolve::svnder: The variables {T'} in (T'])[t]->0 cannot be set as state variables while solving as an ODE because some are the highest order derivatives. You may be able to use these if you solve as a system of DAEs by using Method->{"EquationSimplification"->"Residual"}.
After using the Method->{"EquationSimplification"->"Residual"}, the code cannot run at all.
NDSolve::nderr: Error test failure at t == 0.`; unable to continue.
May I ask for some help? Thank you!

S[t]< =0, then we assumeT' [t]=0. But then againS[t]>0. In this case, we assume $T'(t)\ne 0$ or leaveT'[t]=0? $\endgroup$T'[t]=0whenS[t]<=0and whenS[t]>0, still keep the functionT'[t] == Nrmlphoton ISCEff OpticCoupl. $\endgroup$Nrmlphotonin my original post. It should now doesn't have syntax errors. $\endgroup$