set_segments_from_grid.F90 3.01 KB

    nxmin=conductor_data(conductor)%nxmin
    nxmax=conductor_data(conductor)%nxmax
    nymin=conductor_data(conductor)%nymin
    nymax=conductor_data(conductor)%nymax
    
    layer_number=0
      
    if (conductor_data(conductor)%mesh_to_layer_type.EQ.1) then
! each marked cell in the grid becomes a layer and hence a segment
    
      do ix=nxmin,nxmax
        do iy=nymin,nymax
      if ( conductor_data(conductor)%grid(ix,iy).EQ.1 ) then
    
        layer_number=layer_number+1
      
        apx=conductor_data(conductor)%xc+real(ix)*conductor_data(conductor)%dl
        apy=conductor_data(conductor)%yc+real(iy)*conductor_data(conductor)%dl
    
            conductor_data(conductor)%x(layer_number)=apx
            conductor_data(conductor)%y(layer_number)=apy
            conductor_data(conductor)%w(layer_number)=conductor_data(conductor)%dl
            conductor_data(conductor)%h(layer_number)=conductor_data(conductor)%dl
              
            conductor_data(conductor)%d(layer_number)=0.0
            conductor_data(conductor)%anwinc(layer_number)=conductor_data(conductor)%nwinc
            conductor_data(conductor)%anhinc(layer_number)=conductor_data(conductor)%nwinc
              
      end if
        end do
      end do

    else if (conductor_data(conductor)%mesh_to_layer_type.EQ.2) then
    
! each row of cells in the grid becomes a segment
    do iy=nymin,nymax
    
      in_conductor=.FALSE.
      cx1=0
      cx2=0
      
      do ix=nxmin,nxmax
      
        if ( (.NOT.in_conductor).AND.(conductor_data(conductor)%grid(ix,iy).EQ.1) ) then
    
! we have moved from air to conductor so save this x cell number
           cx1=ix
       in_conductor=.TRUE.
       
    else if ( (in_conductor).AND.(conductor_data(conductor)%grid(ix,iy).EQ.0) ) then
! we have moved from air to conductor so save this x cell number

           cx2=ix-1
       in_conductor=.FALSE.
       
       layer_number=layer_number+1
       
       cw=real(cx2-cx1+1)*conductor_data(conductor)%dl
       ch=conductor_data(conductor)%dl
       
       apx=conductor_data(conductor)%xc+real(cx2+cx1)/2.0
       apy=conductor_data(conductor)%yc+real(iy)*conductor_data(conductor)%dl
    
           conductor_data(conductor)%x(layer_number)=apx
           conductor_data(conductor)%y(layer_number)=apy
           conductor_data(conductor)%w(layer_number)=cw
           conductor_data(conductor)%h(layer_number)=ch
               
           conductor_data(conductor)%d(layer_number)=0.0
           conductor_data(conductor)%anwinc(layer_number)=conductor_data(conductor)%nwinc
           conductor_data(conductor)%anhinc(layer_number)=conductor_data(conductor)%nwinc

           cx1=0
           cx2=0
    
    end if
    
      end do ! next col

    end do ! next row

    else
      write(*,*)'Unknown mesh_to_layer_type:',conductor_data(conductor)%mesh_to_layer_type, &
                'in conductor',conductor
      STOP 1
    end if
    
! the number of layers may have changed if we have combined grid cells      
    conductor_data(conductor)%tot_n_layers=layer_number