Andras,
What you are asking to do may not make physical sense -- you can't just instantaneously shut down the tanks -- they oscillate because the physics says they should oscillate.
You can, however, model whatever you want including a system with discrete behavior (such as a sudden alteration of the system -- closing a valve, etc.). To do this, I would introduce a discrete variable that is either 1 or 0 and affectively "turn off" your system when you hit a condition. For example,
odesys = {
D[ h1[t] , t ] == ( Minus[ q1[t] ] / a1 )* d[t],
D[ h2[t] , t ] == ( q1[t] / a2 ) * d[t] ,
D[ q1[t] , t ] == pipefactor * ( h1[t] - h2[t] ) + pumphead[ t ] - frictionfactor * Abs[ q1[t] ] * q1[t] ,
h1[0] == 1.5 , h2[0] == 1.5 , q1[0] == 0., d[0] == 1
} ;
Where d[t] is the discrete variable, set it to 1 initially.
Now integrate it with
sol = NDSolve[ {odesys, WhenEvent[ (h1[t]>1.5), d[t] ->0]} , { h1 , h2 , q1 } , { t , 0. , 3000. } , DiscreteVariables->d[t]] ;
When your condition is hit (in this case When h1[t] crosses through the neutral point at 1.5, it shuts a valve and the two tank height derivative equations go to zero.
I hope this helps.
Regards,
Neil