V3FIT
vmec_context.f
Go to the documentation of this file.
1 !*******************************************************************************
4 !
5 ! Note separating the Doxygen comment block here so detailed decription is
6 ! found in the Module not the file.
7 !
10 !*******************************************************************************
11  MODULE vmec_context
12  USE stel_kinds
13  USE data_parameters
14  USE xstuff
15  USE vmec_input, Only: raxis_cc, raxis_cs, zaxis_cc, zaxis_cs
16  USE v3f_vmec_comm
17  USE profiler
18  USE mpi_inc
19 
20  IMPLICIT NONE
21 
22 !*******************************************************************************
23 ! DERIVED-TYPE DECLARATIONS
24 ! 1) vmec_context_class class
25 !
26 !*******************************************************************************
27 !-------------------------------------------------------------------------------
30 !-------------------------------------------------------------------------------
33  REAL (rprec), DIMENSION(:), POINTER :: xc => null()
34 
36  REAL (rprec), DIMENSION(:), POINTER :: raxis_cc => null()
38  REAL (rprec), DIMENSION(:), POINTER :: raxis_cs => null()
40  REAL (rprec), DIMENSION(:), POINTER :: zaxis_cc => null()
42  REAL (rprec), DIMENSION(:), POINTER :: zaxis_cs => null()
43 
44 ! threed1 file variables.
46  REAL (rprec) :: vvc_smaleli
48  REAL (rprec) :: vvc_kappa_p
49  END TYPE
50 
51  CONTAINS
52 !*******************************************************************************
53 ! CONSTRUCTION SUBROUTINES
54 !*******************************************************************************
55 !-------------------------------------------------------------------------------
61 !-------------------------------------------------------------------------------
62  FUNCTION vmec_context_construct()
63 
64  IMPLICIT NONE
65 
66 ! Declare Arguments
68 
69 ! local variables
70  REAL (rprec) :: start_time
71 
72 ! Start of executable code
73  start_time = profiler_get_start_time()
74 
75  ALLOCATE(vmec_context_construct)
76 
77  ALLOCATE(vmec_context_construct%xc(SIZE(xc)))
78  ALLOCATE(vmec_context_construct%raxis_cc(SIZE(raxis_cc)))
79  ALLOCATE(vmec_context_construct%raxis_cs(SIZE(raxis_cs)))
80  ALLOCATE(vmec_context_construct%zaxis_cc(SIZE(zaxis_cc)))
81  ALLOCATE(vmec_context_construct%zaxis_cs(SIZE(zaxis_cs)))
82 
84 
85  CALL profiler_set_stop_time('vmec_context_construct', start_time)
86 
87  END FUNCTION
88 
89 !*******************************************************************************
90 ! DESTRUCTION SUBROUTINES
91 !*******************************************************************************
92 !-------------------------------------------------------------------------------
98 !-------------------------------------------------------------------------------
99  SUBROUTINE vmec_context_destruct(this)
100 
101  IMPLICIT NONE
102 
103 ! Declare Arguments
104  TYPE (vmec_context_class), POINTER :: this
105 
106 ! Start of executable code
107  IF (ASSOCIATED(this%xc)) THEN
108  DEALLOCATE(this%xc)
109  this%xc => null()
110  END IF
111 
112  IF (ASSOCIATED(this%raxis_cc)) THEN
113  DEALLOCATE(this%raxis_cc)
114  this%raxis_cc => null()
115  END IF
116 
117  IF (ASSOCIATED(this%raxis_cs)) THEN
118  DEALLOCATE(this%raxis_cs)
119  this%raxis_cs => null()
120  END IF
121 
122  IF (ASSOCIATED(this%zaxis_cc)) THEN
123  DEALLOCATE(this%zaxis_cc)
124  this%zaxis_cc => null()
125  END IF
126 
127  IF (ASSOCIATED(this%zaxis_cs)) THEN
128  DEALLOCATE(this%zaxis_cs)
129  this%zaxis_cs => null()
130  END IF
131 
132  DEALLOCATE(this)
133 
134  END SUBROUTINE
135 
136 !*******************************************************************************
137 ! SETTER SUBROUTINES
138 !*******************************************************************************
139 !-------------------------------------------------------------------------------
145 !-------------------------------------------------------------------------------
146  SUBROUTINE vmec_context_set_context(this)
147  USE v3_utilities
148 
149  IMPLICIT NONE
150 
151 ! Declare Arguments
152  TYPE (vmec_context_class), INTENT(in) :: this
153 
154 ! local variables
155  REAL (rprec) :: start_time
156 
157 ! Start of executable code
158  start_time = profiler_get_start_time()
159 
160  CALL assert_eq(SIZE(this%xc), SIZE(xc), "xc size change. " // &
161  & "Cannot set context.")
162  xc = this%xc
163 
164  raxis_cc = this%raxis_cc
165  raxis_cs = this%raxis_cs
166  zaxis_cc = this%zaxis_cc
167  zaxis_cs = this%zaxis_cs
168 
169  vvc_smaleli = this%vvc_smaleli
170  vvc_kappa_p = this%vvc_kappa_p
171 
172  CALL profiler_set_stop_time('vmec_context_set_context', &
173  & start_time)
174 
175  END SUBROUTINE
176 
177 !*******************************************************************************
178 ! GETTER SUBROUTINES
179 !*******************************************************************************
180 !-------------------------------------------------------------------------------
186 !-------------------------------------------------------------------------------
187  SUBROUTINE vmec_context_get_context(this)
188 
189  IMPLICIT NONE
190 
191 ! Declare Arguments
192  TYPE (vmec_context_class), INTENT(inout) :: this
193 
194 ! local variables
195  REAL (rprec) :: start_time
196 
197 ! Start of executable code
198  start_time = profiler_get_start_time()
199 
200  IF(SIZE(this%xc) .ne. SIZE(xc)) THEN
201  DEALLOCATE(this%xc)
202  ALLOCATE(this%xc(SIZE(xc)))
203  END IF
204  this%xc = xc
205 
206  this%raxis_cc = raxis_cc
207  this%raxis_cs = raxis_cs
208  this%zaxis_cc = zaxis_cc
209  this%zaxis_cs = zaxis_cs
210 
211  this%vvc_smaleli = vvc_smaleli
212  this%vvc_kappa_p = vvc_kappa_p
213 
214  CALL profiler_set_stop_time('vmec_context_get_context', &
215  & start_time)
216 
217  END SUBROUTINE
218 
219 !*******************************************************************************
220 ! MPI SUBROUTINES
221 !*******************************************************************************
222 !-------------------------------------------------------------------------------
231 !-------------------------------------------------------------------------------
232  SUBROUTINE vmec_context_sync_state(this, recon_comm)
233  USE v3_utilities
234 
235  IMPLICIT NONE
236 
237 ! Declare Arguments
238  TYPE (vmec_context_class), INTENT(inout) :: this
239  INTEGER, INTENT(in) :: recon_comm
240 
241 #if defined(MPI_OPT)
242 ! local variables
243  INTEGER :: error
244  INTEGER :: temp_size
245  INTEGER :: mpi_rank
246 
247 ! Start of executable code
248  CALL mpi_comm_rank(recon_comm, mpi_rank, error)
249 
250 ! If the size of the xc array changed size we cannot sync.
251  temp_size = SIZE(xc)
252  CALL mpi_bcast(temp_size, 1, mpi_integer, 0, recon_comm, error)
253 
254  IF (mpi_rank .gt. 0) THEN
255  CALL assert_eq(temp_size, SIZE(xc), &
256  & 'Cannot sync xc arrays. Arrays changed size.')
257  END IF
258  CALL mpi_bcast(xc, temp_size, mpi_real8, 0, recon_comm, error)
259 
260  CALL mpi_bcast(raxis_cc, SIZE(raxis_cc), mpi_real8, 0, recon_comm, &
261  & error)
262  CALL mpi_bcast(raxis_cs, SIZE(raxis_cs), mpi_real8, 0, recon_comm, &
263  & error)
264  CALL mpi_bcast(zaxis_cc, SIZE(zaxis_cc), mpi_real8, 0, recon_comm, &
265  & error)
266  CALL mpi_bcast(zaxis_cs, SIZE(zaxis_cs), mpi_real8, 0, recon_comm, &
267  & error)
268 
269  CALL mpi_bcast(vvc_smaleli, 1, mpi_real8, 0, recon_comm, error)
270  CALL mpi_bcast(vvc_kappa_p, 1, mpi_real8, 0, recon_comm, error)
271 
272 #endif
273  END SUBROUTINE
274 
275 !-------------------------------------------------------------------------------
285 !-------------------------------------------------------------------------------
286  SUBROUTINE vmec_context_sync_child(this, index, recon_comm)
287  USE v3_utilities
288 
289  IMPLICIT NONE
290 
291 ! Declare Arguments
292  TYPE (vmec_context_class), INTENT(inout) :: this
293  INTEGER, INTENT(in) :: index
294  INTEGER, INTENT(in) :: recon_comm
295 
296 #if defined(MPI_OPT)
297 ! local variables
298  INTEGER :: error
299  INTEGER :: temp_size
300  INTEGER :: mpi_rank
301 
302 ! Start of executable code
303  CALL mpi_comm_rank(recon_comm, mpi_rank, error)
304 
305 ! If the size of the xc array changed size we cannot sync.
306  temp_size = SIZE(xc)
307  IF (mpi_rank .eq. index) THEN
308  CALL mpi_ssend(temp_size, 1, mpi_integer, 0, mpi_rank, &
309  & recon_comm, error)
310 
311  CALL mpi_ssend(xc, temp_size, mpi_real8, 0, mpi_rank, &
312  & recon_comm, error)
313 
314  CALL mpi_ssend(raxis_cc, SIZE(raxis_cc), mpi_real8, 0, &
315  & mpi_rank, recon_comm, error)
316  CALL mpi_ssend(raxis_cs, SIZE(raxis_cs), mpi_real8, 0, &
317  & mpi_rank, recon_comm, error)
318  CALL mpi_ssend(zaxis_cc, SIZE(zaxis_cc), mpi_real8, 0, &
319  & mpi_rank, recon_comm, error)
320  CALL mpi_ssend(zaxis_cs, SIZE(zaxis_cs), mpi_real8, 0, &
321  & mpi_rank, recon_comm, error)
322 
323  CALL mpi_ssend(vvc_smaleli, 1, mpi_real8, 0, mpi_rank, &
324  & recon_comm, error)
325  CALL mpi_ssend(vvc_kappa_p, 1, mpi_real8, 0, mpi_rank, &
326  & recon_comm, error)
327 
328  ELSE IF (mpi_rank .eq. 0) THEN
329  CALL mpi_recv(temp_size, 1, mpi_integer, index, index, &
330  & recon_comm, mpi_status_ignore, error)
331  CALL assert_eq(temp_size, SIZE(xc), &
332  & 'Cannot sync xc arrays. Arrays changed size.')
333 
334  CALL mpi_recv(xc, temp_size, mpi_real8, index, index, &
335  & recon_comm, mpi_status_ignore, error)
336 
337  CALL mpi_recv(raxis_cc, SIZE(raxis_cc), mpi_real8, index, &
338  & index, recon_comm, mpi_status_ignore, error)
339  CALL mpi_recv(raxis_cs, SIZE(raxis_cs), mpi_real8, index, &
340  & index, recon_comm, mpi_status_ignore, error)
341  CALL mpi_recv(zaxis_cc, SIZE(zaxis_cc), mpi_real8, index, &
342  & index, recon_comm, mpi_status_ignore, error)
343  CALL mpi_recv(zaxis_cs, SIZE(zaxis_cs), mpi_real8, index, &
344  & index, recon_comm, mpi_status_ignore, error)
345 
346  CALL mpi_recv(vvc_smaleli, 1, mpi_real8, index, index, &
347  & recon_comm, mpi_status_ignore, error)
348  CALL mpi_recv(vvc_kappa_p, 1, mpi_real8, index, index, &
349  & recon_comm, mpi_status_ignore, error)
350 
351  END IF
352 
353 #endif
354  END SUBROUTINE
355 
356  END MODULE
profiler
Defines functions for measuring an tabulating performance of function and subroutine calls....
Definition: profiler.f:13
v3_utilities::assert_eq
Definition: v3_utilities.f:62
vmec_context::vmec_context_construct
type(vmec_context_class) function, pointer vmec_context_construct()
Construct a new vmec_context_class object.
Definition: vmec_context.f:63
mpi_inc
Umbrella module avoid multiple inlcudes of the mpif.h header.
Definition: mpi_inc.f:11
vmec_context::vmec_context_set_context
subroutine vmec_context_set_context(this)
Sets the current context to the vmec_context_class object.
Definition: vmec_context.f:147
vmec_context::vmec_context_class
Base class representing a vmec_context. This contains a copy of every variable that is needed to defi...
Definition: vmec_context.f:31
profiler::profiler_get_start_time
real(rprec) function profiler_get_start_time()
Gets the start time of profiled function.
Definition: profiler.f:194
vmec_context::vmec_context_sync_state
subroutine vmec_context_sync_state(this, recon_comm)
Syncronize the vmec_context to children.
Definition: vmec_context.f:233
vmec_context::vmec_context_sync_child
subroutine vmec_context_sync_child(this, index, recon_comm)
Syncronize a child vmec_context to the parent.
Definition: vmec_context.f:287
vmec_context
Defines the base class of the type vmec_context_class. This contains the state variables needed by VM...
Definition: vmec_context.f:11
data_parameters
This modules contains parameters used by equilibrium models.
Definition: data_parameters.f:10
profiler::profiler_set_stop_time
subroutine profiler_set_stop_time(symbol_name, start_time)
Gets the end time of profiled function.
Definition: profiler.f:121
vmec_context::vmec_context_destruct
subroutine vmec_context_destruct(this)
Deconstruct a vmec_context_class object.
Definition: vmec_context.f:100
vmec_context::vmec_context_get_context
subroutine vmec_context_get_context(this)
Gets the current context from the VMEC internal state.
Definition: vmec_context.f:188