subroutine last_tasks_for_channels(me,sim)
type(channel_t), intent(inout) :: me
type(simulation_t), intent(in) :: sim
real(dp) :: mdot,HHH,Rout,Pout,eout,cout
integer :: jj
me%err = 0_dp
me%err_den = 0_dp
do jj=1,me%HeProp%NbCells
! Write to HDF5
me%hdf%data(jj,1) = me%StVar%He_pr(Pri_p,jj)/1.0e5_dp ! He Pressure (Bar)
me%hdf%data(jj,2) = me%StVar%He_pr(Pri_ro,jj) ! He Density (kg/m3)
me%hdf%data(jj,3) = me%StVar%He_pr(Pri_u,jj) ! He Velocity (m/s)
me%hdf%data(jj,4) = me%HeProp%Area*me%StVar%He_pr(Pri_u,jj)*me%StVar%He_pr(Pri_ro,jj) ! He MassFlowRate (kg/s)
me%hdf%data(jj,5) = me%StVar%He_pr(Pri_T,jj) ! He Temperature (K)
call state_roT(me%StVar%He_pr(Pri_ro,jj), me%StVar%He_pr(Pri_T,jj), Rout, Pout, eout, cout)
mdot=me%HeProp%Area*me%StVar%He_pr(Pri_u,jj)*me%StVar%He_pr(Pri_ro,jj)
HHH=eout+Pout/me%StVar%He_pr(Pri_ro,jj)+0.5_dp*(me%StVar%He_pr(Pri_u,jj)**2)
me%hdf%data(jj,6)=mdot*HHH ! He Mdot*H
me%hdf%data(jj,7)=me%StVar%He_pr(Pri_R,jj) ! He R eq
me%hdf%data(jj,8)=me%srcPP%Su(jj)
! For step management
if(sim%explicit) then
me%err = me%err + (me%StVar%He_pr(Pri_p,jj) - me%StVarOld%He_pr(Pri_p,jj))**2
me%err_den = me%err_den + me%StVarOld%He_pr(Pri_p,jj)**2
else
me%err = me%err + ( (1.0_dp/6.0_dp) * (sim%dtPrev1+sim%dt) * ( &
(me%StVar %He_cs(2,jj)-me%StVarOld %He_cs(2,jj)) / sim%dt - &
(me%StVarOld %He_cs(2,jj)-me%StVarOld2%He_cs(2,jj)) * (sim%dt+sim%dtPrev1) / sim%dtPrev1**2 + &
(me%StVarOld2%He_cs(2,jj)-me%StVarOld3%He_cs(2,jj)) * sim%dt/sim%dtPrev1 / sim%dtPrev2 ))**2
me%err_den = me%err_den + (me%StVarOld%He_cs(2,jj))**2
endif
enddo
end subroutine last_tasks_for_channels