mg_add_children Subroutine

public subroutine mg_add_children(mg, id)

Arguments

Type IntentOptional Attributes Name
type(mg_t), intent(inout) :: mg
integer, intent(in) :: id

Id of box that gets children


Called by

proc~~mg_add_children~3~~CalledByGraph proc~mg_add_children~3 mg_add_children proc~mg_build_rectangle~3 mg_build_rectangle proc~mg_build_rectangle~3->proc~mg_add_children~3 proc~mg_tree_from_amrvac mg_tree_from_amrvac proc~mg_tree_from_amrvac->proc~mg_add_children~3 proc~mg_tree_from_amrvac->proc~mg_build_rectangle~3 proc~mg_setup_multigrid mg_setup_multigrid proc~mg_setup_multigrid->proc~mg_tree_from_amrvac proc~mg_update_refinement mg_update_refinement proc~mg_update_refinement->proc~mg_tree_from_amrvac proc~amr_coarsen_refine amr_coarsen_refine proc~amr_coarsen_refine->proc~mg_update_refinement proc~improve_initial_condition improve_initial_condition proc~improve_initial_condition->proc~mg_setup_multigrid proc~main main proc~main->proc~mg_setup_multigrid proc~main->proc~improve_initial_condition proc~resettree_convert resettree_convert proc~main->proc~resettree_convert proc~settree settree proc~main->proc~settree proc~timeintegration timeintegration proc~main->proc~timeintegration proc~resettree resettree proc~resettree->proc~amr_coarsen_refine proc~resettree_convert->proc~amr_coarsen_refine proc~settree->proc~amr_coarsen_refine program~agile agile program~agile->proc~main proc~timeintegration->proc~resettree

Source Code

  subroutine mg_add_children(mg, id)
    type(mg_t), intent(inout) :: mg
    integer, intent(in)       :: id
    !< Id of box that gets children
    integer                   :: lvl, i, nb, child_nb(2**(3-1))
    integer                   :: c_ids(mg_num_children)
    integer                   :: c_id, c_ix_base(3)

    if (mg%n_boxes + mg_num_children > size(mg%boxes)) then
       error stop "mg_add_children: not enough space"
    end if

    c_ids                 = [(mg%n_boxes+i, i=1,mg_num_children)]
    mg%n_boxes            = mg%n_boxes + mg_num_children
    mg%boxes(id)%children = c_ids
    c_ix_base             = 2 * mg%boxes(id)%ix - 1
    lvl                   = mg%boxes(id)%lvl+1

    do i = 1, mg_num_children
       c_id                     = c_ids(i)
       mg%boxes(c_id)%rank      = mg%boxes(id)%rank
       mg%boxes(c_id)%ix        = c_ix_base + mg_child_dix(:, i)
       mg%boxes(c_id)%lvl       = lvl
       mg%boxes(c_id)%parent    = id
       mg%boxes(c_id)%children  = mg_no_box
       mg%boxes(c_id)%neighbors = mg_no_box
       mg%boxes(c_id)%r_min     = mg%boxes(id)%r_min + mg%dr(:,&
           lvl) * mg_child_dix(:, i) * mg%box_size
       mg%boxes(c_id)%dr(:)     = mg%dr(:, lvl)
    end do

    ! Set boundary conditions at children
    do nb = 1, mg_num_neighbors
       if (mg%boxes(id)%neighbors(nb) < mg_no_box) then
          child_nb = c_ids(mg_child_adj_nb(:, nb)) ! Neighboring children
          mg%boxes(child_nb)%neighbors(nb) = mg%boxes(id)%neighbors(nb)
       end if
    end do
  end subroutine mg_add_children