DISPATCH
rt_nbors_mod.f90
1 !===============================================================================
2 !> Module to add nbor lists for RT sub-tasks, and modify the parent MHD tasks
3 !===============================================================================
5  USE solver_mod
6  USE rt_mod
7  USE patch_mod
8  USE link_mod
9  USE task_mod
10  USE trace_mod
11  USE io_unit_mod
12  USE bits_mod
13  implicit none
14  private
15  !.............................................................................
16  type, public:: rt_nbors_t
17  contains
18  procedure, nopass:: init
19  end type
20  type(rt_nbors_t), public:: rt_nbors
21 CONTAINS
22 
23 !===============================================================================
24 !> In the syncronized RT/MHD arrangement the steps and relations needed are:
25 !>
26 !> 1) The omega0 task needs the MHD nbors to dnload and call EOS for RT
27 !> 2) Each omega task needs the upstream omega task
28 !> 3) Each omega task neds the omega0 task
29 !> 4) The MHD task needs all omega task, while not vice versa.
30 !>
31 !> The upstream nbors should have the settings needed=T, needs_me=F, download=T,
32 !> while the downstream tasks should have needed=F, needs_me=T, download=F.
33 !===============================================================================
34 SUBROUTINE init (mhd)
35  class(solver_t):: mhd
36  !.............................................................................
37  integer:: i_omega
38  class(rt_t), pointer:: omega0, omega, upstream
39  class(link_t), pointer:: nbor
40  class(task_t), pointer:: nb_task
41  logical:: needs, needs_me, download
42  !-----------------------------------------------------------------------------
43  call trace%begin ('rt_nbors_t%init')
44  omega0 => mhd%rt
45  call omega0%clear(bits%init_nbors)
46  !-----------------------------------------------------------------------------
47  ! 1) The omega0 needs the MHD task for the MHD variables, but no download
48  !-----------------------------------------------------------------------------
49  needs=.true.; needs_me=.false.; download=.false.
50  call init_nbor_pair (omega0, needs, mhd, needs_me, download)
51  !-----------------------------------------------------------------------------
52  ! Loop over all ray directions, and add nbors and nbor relations. The only
53  ! downloads that are needed are from upstream omega tasks
54  !-----------------------------------------------------------------------------
55  do i_omega=1,omega0%n_omega
56  omega => omega0%omega(i_omega)
57  !---------------------------------------------------------------------------
58  ! Loop over all MHD nbors
59  !---------------------------------------------------------------------------
60  nbor => mhd%link%nbor
61  do while (associated(nbor))
62  !-------------------------------------------------------------------------
63  ! Cast the nbors to solver_t type
64  !-------------------------------------------------------------------------
65  nb_task => nbor%task
66  select type (nb_task)
67  class is (solver_t)
68  !-------------------------------------------------------------------------
69  ! Select omega sub-tasks
70  !-------------------------------------------------------------------------
71  if (associated(nb_task%rt)) then
72  if (nb_task%rt%n_omega == 0) then
73  !-----------------------------------------------------------------------
74  ! 2) The omega0 task needs the MHD nbors, and needs download
75  !-----------------------------------------------------------------------
76  needs=.true.; needs_me=.false.; download=.true.
77  call init_nbor_pair (omega0, needs, nb_task, needs_me, download)
78  else
79  !-----------------------------------------------------------------------
80  ! The omega0%needs() function tests for upstream nbor omega
81  !-----------------------------------------------------------------------
82  upstream => nb_task%rt%omega(i_omega)
83  if (omega%needs (omega, upstream) .and. upstream%on) then
84  !---------------------------------------------------------------------
85  ! 3) The omega tasks need the upstream tasks, and should download from
86  ! them, but the upstream tasks do not need the downstream omega tasks
87  !---------------------------------------------------------------------
88  needs=.true.; needs_me=.false.; download=.true.
89  call init_nbor_pair (omega, needs, upstream, needs_me, download)
90  end if
91  end if
92  end if
93  end select
94  nbor => nbor%next
95  end do
96  !-----------------------------------------------------------------------
97  ! 4) The omega task needs the RT task, which does not need the omega tasks
98  !-----------------------------------------------------------------------
99  needs=.true.; needs_me=.false.; download=.false.
100  call init_nbor_pair (omega, needs, omega0, needs_me, download)
101  !---------------------------------------------------------------------------
102  ! 5) The MHD task needs the omega tasks, which do not need the MHD task
103  !---------------------------------------------------------------------------
104  needs=.true.; needs_me=.false.; download=.false.
105  call init_nbor_pair (mhd, needs, omega, needs_me, download)
106  end do
107  call trace%end()
108 END SUBROUTINE init
109 
110 !===============================================================================
111 !> Add mutual nbor relations to two nbor lists, making sure that the needed and
112 !> needs_me flags are mutually consistent.
113 !===============================================================================
114 SUBROUTINE init_nbor_pair (task1, needed, task2, needs_me, download)
115  class(task_t):: task1, task2
116  logical:: needed, needs_me, download
117  class(link_t), pointer:: link1, link2, nbor1, nbor2
118  !-----------------------------------------------------------------------------
119  call trace%begin ('rt_t%init_nbor_pairs')
120  select type (task1)
121  class is (patch_t)
122  link1 => task1%link
123  end select
124  select type (task2)
125  class is (patch_t)
126  link2 => task2%link
127  end select
128  !-----------------------------------------------------------------------------
129  ! Add the 2nd linked task as an nbor to the 1st linked task
130  !-----------------------------------------------------------------------------
131  allocate (nbor1)
132  nbor1%link => link2
133  nbor1%task => nbor1%link%task
134  nbor1%needed = needed
135  nbor1%needs_me = needs_me
136  nbor1%download = download
137  !-----------------------------------------------------------------------------
138  ! Add the 1st linked task as an nbor to the 2nd linked task
139  !-----------------------------------------------------------------------------
140  allocate (nbor2)
141  nbor2%link => link1
142  nbor2%task => nbor2%link%task
143  nbor2%needed = needs_me
144  nbor2%needs_me = needed
145  nbor2%download = .false.
146  !-----------------------------------------------------------------------------
147  ! If the 1st task is a virtual task, it should not download from the 2nd task
148  ! and also does not need it (in the sense that it gets updated by MPI). If
149  ! the needs me flag is also false, then none of two tasks should be in the
150  ! nbor list of the other (this applies if the 1st task is a virtual downstream
151  ! RT task)
152  !-----------------------------------------------------------------------------
153  if (link1%task%is_set (bits%virtual)) then
154  nbor1%download = .false.
155  nbor1%needed = .false.
156  nbor2%needs_me = .false.
157  if (.not.nbor1%needs_me) then
158  call trace%end()
159  return
160  end if
161  end if
162  !-----------------------------------------------------------------------------
163  ! If the 2nd task is a virtual task the same applies, except the meaning of
164  ! the flags is reversed (this applies if the 2nd task is a virtual downstream
165  ! RT task)
166  !-----------------------------------------------------------------------------
167  if (link2%task%is_set (bits%virtual)) then
168  nbor2%download = .false.
169  nbor2%needs_me = .false.
170  nbor1%needed = .false.
171  if (.not.nbor2%needed) then
172  call trace%end()
173  return
174  end if
175  end if
176  !-----------------------------------------------------------------------------
177  ! Add the two tasks, which now are guaranteed to have matching flags
178  !-----------------------------------------------------------------------------
179  call link1%add_nbor_by_rank (link1%nbor, nbor1)
180  call link2%add_nbor_by_rank (link2%nbor, nbor2)
181  call trace%end()
182 END SUBROUTINE init_nbor_pair
183 
184 END MODULE rt_nbors_mod
Module to set up angles and bins for an RT patch with only absorption. This means that the only extra...
Definition: rt_mod.f90:46
Template module for patches, which adds pointers to memory and mesh, and number of dimensions and var...
Definition: patch_mod.f90:6
Module to add nbor lists for RT sub-tasks, and modify the parent MHD tasks.
Definition: rt_nbors_mod.f90:4
This module contains all experiment specific information necessary to solve the heat diffusion proble...
Definition: solver_mod.f90:5
Template module for tasks.
Definition: task_mod.f90:4