OK! Well, I do it as you said. Exept for the gearbox angular velocity. For me it was:
gearbox_av = drive_wheel_av_sum / drive_wheel_count
So I don't need to divide it by drive wheel count? Also, do I integrate the wheel torque seperately?
Is it like this?
engine_av += T / I * dt
gearbox_av += T / I * gr * dt
wheel_av += T * gr * diff / I * dt
You don't have to divide it if you solve it on differential, otherwise dividing sum of wheels angular velocity should be fine.
I have a bit more complicated setup where each component is updates twice on each update cycle. First time I update them in order or Engine->Clutch->GearBox->Wheel (I don't have a differential yet) then after reaction force is calculated, update is going backwards Wheel->Gearbox->Clutch->Engine.
Reaction force doesn't change angular velocity of the wheel immediately. Instead, reaction force is passed back to gearbox, where I check if gearbox is locked or not. If it's locked then torque is passed back to clutch. If gearbox is unlocked, then reaction torque changes angular velocity of the gearbox drive shaft and consequently of the drive wheel on the next update if gearbox stays unlocked (in neutral).
The same logic is applied in clutch, torque comes from the engine and I check if clutch is locked, if it's locked torque passes further, if it's not than angular velocity on the wheel side of the clutch should be integrated. Again, on the reverse update, when torque comes from the gearbox, I check if clutch is locked. So each elements is updated twice but on each step different set of input parameters is used. On "forward" update I provide Torque, angular velocity and moment of inertia from engine to clutch, from clutch to gearbox and so on. On "reverse" update it goes backwards: from the wheels, torque, angular velocity and moment of inertia are passed to gearbox then to clutch then to engine.
This allows to sum up for example moment of inertia from each element, all the way to the engine when everything is locked down. At the same time, if I need full moment of inertia of the drive train on the wheels, I have it too, because each element will take input moment of inertia, add own moment of inertia and pass it further. Exception is when something is not locked.
The reason why I'm saying this is because in "engine_av += T / I * dt" moment of inertia will be own moment of inertia of the engine only if clutch is unlocked, when it's locked it will be a sum of all moment of inertia of drive train, including effective moment of inertia on a gearbox.
This - "gearbox_av += T / I * gr * dt" doesn't make much sense to me because you either calculate effective moment of inertia from the gear using MOI of Engine+Clutch+lay shaft or you are integrating drive shaft part which have effective moment of inertia of the wheel passed through differential.
Third part "wheel_av += T * gr * diff / I * dt" is not applicable if integration was already done at the drive shaft of gearbox if gearbox is unlocked, otherwise it would be done at the clutch all the way back (if clutch is unlocked) or at the engine if all elements of drive train are locked. To be fair, I don't have a differential. But they way I would approach this is by integrating velocity on each wheel separately. To do that, you take effective moment of inertia coming from differential and use it in calculation of how much wheel is slowed down by reaction force, but take into account that as one wheel is slowed down, the other will speed up as this is how differential works. I'm afraid I can't say more about differential as I didn't implemented it yet in such setup and not sure how exactly things should be done.