channel_init_part2 Subroutine

public subroutine channel_init_part2(me, krn, cfg)

Fluid port initialistion for channels

Arguments

Type IntentOptional Attributes Name
type(channel_t), intent(inout), target :: me
type(krn_t), intent(inout) :: krn
class(input_t), intent(in), pointer :: cfg

Calls

proc~~channel_init_part2~~CallsGraph proc~channel_init_part2 channel_init_part2 proc~krn_coo_add krn_t%krn_coo_add proc~channel_init_part2->proc~krn_coo_add proc~krn_update krn_t%krn_update proc~channel_init_part2->proc~krn_update interface~to_str to_str proc~krn_update->interface~to_str proc~port_list_update port_list_t%port_list_update proc~krn_update->proc~port_list_update proc~str_from_int str_from_int interface~to_str->proc~str_from_int proc~str_from_real str_from_real interface~to_str->proc~str_from_real

Called by

proc~~channel_init_part2~~CalledByGraph proc~channel_init_part2 channel_init_part2 program~reims_p reims_p program~reims_p->proc~channel_init_part2

Source Code

subroutine channel_init_part2(me, krn, cfg)
    !! Fluid port initialistion for channels
    type(channel_t), target, intent(inout) :: me
    type(krn_t),          intent(inout) :: krn
    class(input_t), pointer, intent(in) :: cfg  

    type(FF_flux_port_t), pointer :: FF_flux_ports(:)
    type(FF_src_port_t), pointer :: FF_src_ports(:)
    type(FS_port_t), pointer :: FS_ports(:)
    integer :: NbSubM,i,idx,idxI,idxJ,PrevRowIdx,PrevColIdx
    real(dp), pointer :: rhs(:)
    integer, allocatable :: list_thp_loc(:),list_FF_src_p_loc(:)

    ! FF_flux ports
    call krn%update(rhs_or_solution_view=rhs,FF_flux_p_loc=[1,(me%HeProp%NbCells-1)*Nb_VarC+1],FF_flux_p_view=FF_flux_ports)
    me%HeProp%in  => FF_flux_ports(1)
    me%HeProp%out => FF_flux_ports(2)
    me%HeProp%in%Area       = me%HeProp%Area
    me%HeProp%in%dxLoc      = me%HeProp%dxLoc(1)
    me%HeProp%in%Sgn4j      = -1.0_dp   
    me%HeProp%in%connected  = .false.  
    me%HeProp%out%Area      = me%HeProp%Area
    me%HeProp%out%dxLoc     = me%HeProp%dxLoc(me%HeProp%NbCells)
    me%HeProp%out%Sgn4j     = 1.0_dp   
    me%HeProp%out%connected = .false.   

    ! FS ports
    if(me%HeProp%ExtHeating=='link') then
      allocate(list_thp_loc(me%HeProp%NbCells),me%HeProp%thermP(me%HeProp%NbCells))
      list_thp_loc=[(1+(i-1)*Nb_VarC, i=1,me%HeProp%NbCells)]
      call krn%update(FS_p_loc=list_thp_loc,FS_p_view=FS_ports)
      do i=1,me%HeProp%NbCells
        me%HeProp%thermP(i)%p => FS_ports(i)
        me%HeProp%thermP(i)%p%AreaP = me%HeProp%Area
        me%HeProp%thermP(i)%p%DiamP = me%HeProp%Diam
        me%HeProp%thermP(i)%p%dxLoc = me%HeProp%dxLoc(i)
      enddo
    endif

    ! FF_src ports
    if(me%HeProp%FFsrcLink) then
      allocate(list_FF_src_p_loc(me%HeProp%NbCells),me%HeProp%thermF(me%HeProp%NbCells))
      list_FF_src_p_loc=[(1+(i-1)*Nb_VarC, i=1,me%HeProp%NbCells)]
      call krn%update(FF_src_p_loc=list_FF_src_p_loc,FF_src_p_view=FF_src_ports)
      do i=1,me%HeProp%NbCells
        me%HeProp%thermF(i)%p => FF_src_ports(i)
        me%HeProp%thermF(i)%p%AreaP = me%HeProp%Area
        me%HeProp%thermF(i)%p%DiamP = me%HeProp%Diam
      enddo
      me%HeProp%thermF(1)%p%can_be_shared = .true.
      me%HeProp%thermF(me%HeProp%NbCells)%p%can_be_shared = .true.
    endif       

    me%big%bvx(1:Nb_VarC,1:me%HeProp%NbCells) => rhs

    NbSubM=me%HeProp%NbCells
    allocate(me%bigLS%ValExp(NbSubM*Nb_VarC*Nb_VarC),me%bigLS%RowExp(NbSubM*Nb_VarC*Nb_VarC))
    allocate(me%bigLS%ColExp(NbSubM*Nb_VarC*Nb_VarC))

    NbSubM=2*2+(me%HeProp%NbCells-2)*3
    allocate(me%bigLS%ValImp(NbSubM*Nb_VarC*Nb_VarC),me%bigLS%RowImp(NbSubM*Nb_VarC*Nb_VarC))
    allocate(me%bigLS%ColImp(NbSubM*Nb_VarC*Nb_VarC))

    idx=1

    PrevColIdx=0
    PrevRowIdx=0
    do i=1,me%HeProp%NbCells
        ! PPt%bigLS%ColExp((i-1)*16+1:i*16) = PrevColIdx+idx_4x4_col
        ! PPt%bigLS%RowExp((i-1)*16+1:i*16) = PrevRowIdx+idx_4x4_row
        ! PPt%bigLS%ValExp((i-1)*16+1:i*16) = to_ptr_arr(PPt%bigPP%bmxPP(:,:,i)) ! TODO adapt this part
        do idxI=1,Nb_VarC
            do idxJ=1,Nb_VarC
                me%bigLS%ValExp(idx)%p => me%big%bmx(idxJ,idxI,i)
                me%bigLS%ColExp(idx)=PrevColIdx+idxJ
                me%bigLS%RowExp(idx)=PrevRowIdx+idxI

                me%bigLS%ValImp(idx)%p => me%big%bmx(idxJ,idxI,i)
                me%bigLS%ColImp(idx)=PrevColIdx+idxJ
                me%bigLS%RowImp(idx)=PrevRowIdx+idxI
                idx=idx+1
            enddo  
        enddo
        PrevColIdx=PrevColIdx+Nb_VarC
        PrevRowIdx=PrevRowIdx+Nb_VarC
    enddo
    call krn%coo_add(.true.,me%bigLS%ColExp,me%bigLS%RowExp,me%bigLS%ValExp)

    PrevColIdx=Nb_VarC
    PrevRowIdx=0
    do i=1,me%HeProp%NbCells-1
        do idxI=1,Nb_VarC
            do idxJ=1,Nb_VarC
                me%bigLS%ValImp(idx)%p => me%big%cmx(idxJ,idxI,i)
                me%bigLS%ColImp(idx)=PrevColIdx+idxJ
                me%bigLS%RowImp(idx)=PrevRowIdx+idxI          
                idx=idx+1
            enddo  
        enddo
        PrevColIdx=PrevColIdx+Nb_VarC
        PrevRowIdx=PrevRowIdx+Nb_VarC      
    enddo
    PrevColIdx=0
    PrevRowIdx=Nb_VarC
    do i=1,me%HeProp%NbCells-1
        do idxI=1,Nb_VarC
            do idxJ=1,Nb_VarC
                me%bigLS%ValImp(idx)%p => me%big%amx(idxJ,idxI,i)
                me%bigLS%ColImp(idx)=PrevColIdx+idxJ
                me%bigLS%RowImp(idx)=PrevRowIdx+idxI 
                idx=idx+1
            enddo  
        enddo
        PrevColIdx=PrevColIdx+Nb_VarC
        PrevRowIdx=PrevRowIdx+Nb_VarC
    enddo
    call krn%coo_add(.false.,me%bigLS%ColImp,me%bigLS%RowImp,me%bigLS%ValImp)

    deallocate(me%bigLS%ValExp,me%bigLS%RowExp,me%bigLS%ColExp)
    deallocate(me%bigLS%ValImp,me%bigLS%RowImp,me%bigLS%ColImp)

end subroutine channel_init_part2