subroutine channel_init_part1(me, krn, cfg, h5, sim)
type(channel_t), intent(out) :: me
type(krn_t), intent(inout) :: krn
class(input_t), pointer, intent(in) :: cfg
class(hdf5_t), intent(inout) :: h5
type(simulation_t), intent(inout) :: sim
real(dp) :: Rout,Pout,eout,cout, u_init, p_init, T_init
integer :: i, nb_non_zeros_exp, nb_non_zeros_imp, nb_FS_ports, nb_FF_src_ports
if(cfg%has_key('nodes')) then ! means uniform mesh
me%HeProp%NbCells = cfg%int('nodes')
me%HeProp%Length = cfg%dbl('length')
allocate(me%HeProp%dxLoc(me%HeProp%NbCells))
me%HeProp%dxLoc(:)=me%HeProp%Length/me%HeProp%NbCells
else ! variable mesh
me%HeProp%NbCells=size(cfg%dbl1d('length'))
allocate(me%HeProp%dxLoc(me%HeProp%NbCells))
me%HeProp%dxLoc(:)=cfg%dbl1d('length')
me%HeProp%Length = sum(me%HeProp%dxLoc(:))
endif
! For HDF5
me%hdf%name = cfg%str('id')
me%hdf%node_x = [(sum(me%HeProp%dxLoc(1:i-1)) + me%HeProp%dxLoc(i)/2, &
i = 1, me%HeProp%NbCells)]
call h5%add_to_table(me%hdf,'channel')
me%HeProp%FFsrcLink = cfg%bin('channel_link',.false.)
me%HeProp%ExtHeating = cfg%str('thermal','flux')
if(me%HeProp%ExtHeating=='flux') then
call me%HeProp%Temp_or_Q_Wall%init(sim,cfg,'flux',me%hdf%node_x)
else if(me%HeProp%ExtHeating=='temp') then
call me%HeProp%Temp_or_Q_Wall%init(sim,cfg,'temp',me%hdf%node_x)
call nusselt_init(me%nuss,cfg)
if(.not. associated(me%nuss)) me%HeProp%Ht = cfg%dbl('heat_transfert_coef')
endif
call friction_init(me%fct,cfg)
if(cfg%has_key('diameter') .and. cfg%has_key('area')) then ! expects the 2 values for a Katheder type friction factor
me%HeProp%Diam = cfg%dbl('diameter')
me%HeProp%Area = cfg%dbl('area')
else
if(cfg%has_key('diameter')) then
me%HeProp%Diam = cfg%dbl('diameter')
me%HeProp%Area = Pi_value*me%HeProp%Diam**2/4.0_dp
else if(cfg%has_key('area')) then
me%HeProp%Area = cfg%dbl('area')
me%HeProp%Diam = sqrt(4.0_dp*me%HeProp%Area/Pi_value)
else
error stop 'channel: missing required key "diameter" or "area"'
endif
endif
call all_channel_allocation_nb(me)
u_init=cfg%dbl('initial/u',0.0_dp)
p_init=cfg%dbl('initial/p')
T_init=cfg%dbl('initial/t')
do i=1,me%HeProp%NbCells
me%StVar%He_pr(Pri_u,i)=u_init
me%StVar%He_pr(Pri_ro,i)=ro_pT(p_init,T_init)
me%StVar%He_pr(Pri_T,i)=T_init
call state_roT(me%StVar%He_pr(Pri_ro,i), me%StVar%He_pr(Pri_T,i), Rout, Pout, eout, cout)
me%StVar%He_pr(Pri_R,i) = 1.0_dp ! Value by default
if(R_Correction) me%StVar%He_pr(Pri_R,i) = Rout
me%StVar%He_pr(Pri_p,i)=Pout
me%StVar%He_pr(Pri_e,i)=eout
me%StVar%He_pr(Pri_c,i)=cout
call v_prim_to_v_Conss(i,me%StVar%He_pr,me%StVar%He_cs)
enddo
nb_non_zeros_exp=Nb_VarC*Nb_VarC*me%HeProp%NbCells
nb_non_zeros_imp=2*Nb_VarC*Nb_VarC
do i=2,me%HeProp%NbCells-1
nb_non_zeros_imp=nb_non_zeros_imp+3*Nb_VarC*Nb_VarC
enddo
nb_non_zeros_imp=nb_non_zeros_imp+2*Nb_VarC*Nb_VarC
if(me%HeProp%ExtHeating=='link') then
nb_FS_ports=me%HeProp%NbCells
else
nb_FS_ports=0
endif
if(me%HeProp%FFsrcLink) then
nb_FF_src_ports=me%HeProp%NbCells
else
nb_FF_src_ports=0
endif
me%HeProp%name = cfg%str('id')
call krn%add(me%HeProp%name,Nb_VarC*me%HeProp%NbCells,nb_non_zeros_exp,nb_non_zeros_imp,2,nb_FS_ports,nb_FF_src_ports,0,0)
end subroutine channel_init_part1