V3FIT
bmw_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 bmw_context
12  USE m_grid
13  USE primed_grid
14  USE unprimed_grid
16 
17  IMPLICIT NONE
18 
19 !*******************************************************************************
20 ! bmw context module parameters
21 !*******************************************************************************
23  INTEGER, PARAMETER :: series = 2
24 
25 !*******************************************************************************
26 ! DERIVED-TYPE DECLARATIONS
27 ! 1) bmw context base class
28 !
29 !*******************************************************************************
30 !-------------------------------------------------------------------------------
33 !-------------------------------------------------------------------------------
36  TYPE (m_grid_class), POINTER :: m_grid => null()
38  TYPE (primed_grid_class), POINTER :: p_grid => null()
40  TYPE (unprimed_grid_class), POINTER :: up_grid => null()
41  END TYPE
42 
43 !-------------------------------------------------------------------------------
45 !-------------------------------------------------------------------------------
47  MODULE PROCEDURE bmw_context_set_up_grid_m, &
49  END INTERFACE
50 
51  CONTAINS
52 !*******************************************************************************
53 ! CONSTRUCTION SUBROUTINES
54 !*******************************************************************************
55 !-------------------------------------------------------------------------------
68 !-------------------------------------------------------------------------------
69  FUNCTION bmw_context_construct(mgrid_file_name, wout_file_name, &
70  & siesta_file_name, flags, num_p, &
71  & parallel, io_unit)
72  USE read_wout_mod, Only: read_wout_file, extcur
74 
75  IMPLICIT NONE
76 
77 ! Declare Arguments
78  TYPE (bmw_context_class), POINTER :: bmw_context_construct
79  CHARACTER (len=*), INTENT(in) :: mgrid_file_name
80  CHARACTER (len=*), INTENT(in) :: wout_file_name
81  CHARACTER (len=*), INTENT(in) :: siesta_file_name
82  INTEGER, INTENT(in) :: flags
83  INTEGER, INTENT(inout) :: num_p
84  TYPE (bmw_parallel_context_class), INTENT(in) :: parallel
85  INTEGER, INTENT(in) :: io_unit
86 
87 ! local variables
88  REAL (rprec) :: start_time
89  INTEGER :: status
90 
91 ! Start of executable code
92  start_time = profiler_get_start_time()
93 
94  ALLOCATE(bmw_context_construct)
95 
96  CALL read_wout_file(wout_file_name, status)
97  IF (status .ne. 0) THEN
98  IF (parallel%offset .eq. 0) THEN
99  WRITE (io_unit,1000) trim(wout_file_name)
100  END IF
101  CALL bmw_parallel_context_abort(status)
102  END IF
103  IF (.not.ALLOCATED(extcur)) THEN
104  IF (parallel%offset .eq. 0) THEN
105  WRITE (io_unit,1001) trim(wout_file_name)
106  END IF
107  CALL bmw_parallel_context_abort(status)
108  END IF
109 
110  bmw_context_construct%m_grid => &
111  & m_grid_construct(mgrid_file_name, parallel, io_unit)
112 
113  IF (btest(flags, bmw_state_flags_mgrid)) THEN
114  num_p = SIZE(bmw_context_construct%m_grid%a_p, 3)
115  END IF
116 
117  bmw_context_construct%p_grid => &
118  & primed_grid_construct(num_p*bmw_context_construct%m_grid%nfp, &
119  & flags, siesta_file_name, parallel, &
120  & io_unit)
121 
122  CALL profiler_set_stop_time('bmw_context_construct', start_time)
123 
124 1000 FORMAT(a,' is an invalid wout file.')
125 1001 FORMAT(a,' is not a free boundary wout file.')
126 
127  END FUNCTION
128 
129 !*******************************************************************************
130 ! DESTRUCTION SUBROUTINES
131 !*******************************************************************************
132 !-------------------------------------------------------------------------------
138 !-------------------------------------------------------------------------------
139  SUBROUTINE bmw_context_destruct(this)
140 
141  IMPLICIT NONE
142 
143 ! Declare Arguments
144  TYPE (bmw_context_class), POINTER :: this
145 
146 ! Start of executable code
147  IF (ASSOCIATED(this%m_grid)) THEN
148  CALL m_grid_destruct(this%m_grid)
149  this%m_grid => null()
150  END IF
151 
152  IF (ASSOCIATED(this%p_grid)) THEN
153  CALL primed_grid_destruct(this%p_grid)
154  this%p_grid => null()
155  END IF
156 
157  IF (ASSOCIATED(this%up_grid)) THEN
158  CALL unprimed_grid_destruct(this%up_grid)
159  this%up_grid => null()
160  END IF
161 
162  DEALLOCATE(this)
163 
164  END SUBROUTINE
165 
166 !*******************************************************************************
167 ! SETTER SUBROUTINES
168 !*******************************************************************************
169 !-------------------------------------------------------------------------------
181 !-------------------------------------------------------------------------------
182  SUBROUTINE bmw_context_set_up_grid_m(this, p_start, p_end, &
183  & parallel, io_unit)
184 
185  IMPLICIT NONE
186 
187 ! Declare Arguments
188  TYPE (bmw_context_class), INTENT(inout) :: this
189  INTEGER, INTENT(in) :: p_start
190  INTEGER, INTENT(in) :: p_end
191  TYPE (bmw_parallel_context_class), INTENT(in) :: parallel
192  INTEGER, INTENT(in) :: io_unit
193 
194 ! local variables
195  REAL (rprec) :: start_time
196 
197 ! Start of executable code
198  start_time = profiler_get_start_time()
199 
200  this%up_grid => unprimed_grid_construct(this%m_grid, this%p_grid, &
201  & p_start, p_end, parallel, &
202  & io_unit)
203 
204  CALL profiler_set_stop_time('bmw_context_set_up_grid_m', &
205  & start_time)
206 
207  END SUBROUTINE
208 
209 !-------------------------------------------------------------------------------
222 !-------------------------------------------------------------------------------
223  SUBROUTINE bmw_context_set_up_grid_a(this, r_grid, z_grid, dphi, &
224  & parallel, io_unit)
225 
226  IMPLICIT NONE
227 
228 ! Declare Arguments
229  TYPE (bmw_context_class), INTENT(inout) :: this
230  REAL (rprec), DIMENSION(:,:,:), INTENT(in) :: r_grid
231  REAL (rprec), DIMENSION(:,:,:), INTENT(in) :: z_grid
232  REAL (rprec), INTENT(in) :: dphi
233  TYPE (bmw_parallel_context_class), INTENT(in) :: parallel
234  INTEGER, INTENT(in) :: io_unit
235 
236 ! local variables
237  REAL (rprec) :: start_time
238 
239 ! Start of executable code
240  start_time = profiler_get_start_time()
241 
242  this%up_grid => unprimed_grid_construct(this%m_grid, this%p_grid, &
243  & r_grid, z_grid, dphi, &
244  & parallel, io_unit)
245 
246  CALL profiler_set_stop_time('bmw_context_set_up_grid_a', &
247  & start_time)
248 
249  END SUBROUTINE
250 
251 !*******************************************************************************
252 ! NETCDF SUBROUTINES
253 !*******************************************************************************
281 
283 !-------------------------------------------------------------------------------
292 !-------------------------------------------------------------------------------
293  SUBROUTINE bmw_context_init_nc(this, result_file_name, parallel)
294  USE ezcdf
295 
296  IMPLICIT NONE
297 
298 ! Declare Arguments
299  TYPE (bmw_context_class), INTENT(in) :: this
300  CHARACTER (len=*), INTENT(in) :: result_file_name
301  TYPE (bmw_parallel_context_class), INTENT(in) :: parallel
302 
303 ! local variables
304  REAL (rprec) :: start_time
305 
306  END SUBROUTINE
307 
308 !-------------------------------------------------------------------------------
317 !-------------------------------------------------------------------------------
318  SUBROUTINE bmw_context_write(this, result_file_name, parallel)
319  USE ezcdf
320 
321  IMPLICIT NONE
322 
323 ! Declare Arguments
324  TYPE (bmw_context_class), INTENT(in) :: this
325  CHARACTER (len=*), INTENT(in) :: result_file_name
326  TYPE (bmw_parallel_context_class), INTENT(in) :: parallel
327 
328 ! local variables
329  REAL (rprec) :: start_time
330  INTEGER :: status
331  INTEGER :: result_iou
332 
333 ! local parameters
334  CHARACTER (len=*), DIMENSION(3), PARAMETER :: &
335  & up_dims = (/ 'r ','z ','phi' /)
336  CHARACTER (len=*), DIMENSION(3), PARAMETER :: &
337  & p_dims = (/ 'u','v','s' /)
338 
339 ! Start of executable code
340  start_time = profiler_get_start_time()
341 
342  IF (parallel%offset .eq. 0) THEN
343  CALL cdf_open(result_iou, trim(result_file_name), 'w', status)
344 
345  CALL cdf_define(result_iou, 'series', series)
346 
347  CALL cdf_define(result_iou, 'nfp', this%m_grid%nfp)
348 
349  CALL cdf_define(result_iou, 'rmin', this%m_grid%rmin)
350  CALL cdf_define(result_iou, 'rmax', this%m_grid%rmax)
351  CALL cdf_define(result_iou, 'zmin', this%m_grid%zmin)
352  CALL cdf_define(result_iou, 'zmax', this%m_grid%zmax)
353 
354  CALL cdf_define(result_iou, 'ar_grid', this%up_grid%a_r, &
355  & dimname=up_dims)
356  CALL cdf_define(result_iou, 'ap_grid', this%up_grid%a_p, &
357  & dimname=up_dims)
358  CALL cdf_define(result_iou, 'az_grid', this%up_grid%a_z, &
359  & dimname=up_dims)
360 
361  CALL cdf_define(result_iou, 'br_grid', this%up_grid%b_r, &
362  & dimname=up_dims)
363  CALL cdf_define(result_iou, 'bp_grid', this%up_grid%b_p, &
364  & dimname=up_dims)
365  CALL cdf_define(result_iou, 'bz_grid', this%up_grid%b_z, &
366  & dimname=up_dims)
367 
368  CALL cdf_define(result_iou, 'px_grid', this%p_grid%x, &
369  & dimname=p_dims)
370  CALL cdf_define(result_iou, 'py_grid', this%p_grid%y, &
371  & dimname=p_dims)
372  CALL cdf_define(result_iou, 'pz_grid', this%p_grid%z, &
373  & dimname=p_dims)
374 
375  CALL cdf_define(result_iou, 'jx_grid', this%p_grid%j_x, &
376  & dimname=p_dims)
377  CALL cdf_define(result_iou, 'jy_grid', this%p_grid%j_y, &
378  & dimname=p_dims)
379  CALL cdf_define(result_iou, 'jz_grid', this%p_grid%j_z, &
380  & dimname=p_dims)
381 
382  CALL cdf_write(result_iou, 'series', series)
383 
384  CALL cdf_write(result_iou, 'nfp', this%m_grid%nfp)
385 
386  CALL cdf_write(result_iou, 'rmin', this%m_grid%rmin)
387  CALL cdf_write(result_iou, 'rmax', this%m_grid%rmax)
388  CALL cdf_write(result_iou, 'zmin', this%m_grid%zmin)
389  CALL cdf_write(result_iou, 'zmax', this%m_grid%zmax)
390 
391  CALL cdf_write(result_iou, 'ar_grid', this%up_grid%a_r)
392  CALL cdf_write(result_iou, 'ap_grid', this%up_grid%a_p)
393  CALL cdf_write(result_iou, 'az_grid', this%up_grid%a_z)
394 
395  CALL cdf_write(result_iou, 'br_grid', this%up_grid%b_r)
396  CALL cdf_write(result_iou, 'bp_grid', this%up_grid%b_p)
397  CALL cdf_write(result_iou, 'bz_grid', this%up_grid%b_z)
398 
399  CALL cdf_write(result_iou, 'px_grid', this%p_grid%x)
400  CALL cdf_write(result_iou, 'py_grid', this%p_grid%y)
401  CALL cdf_write(result_iou, 'pz_grid', this%p_grid%z)
402 
403  CALL cdf_write(result_iou, 'jx_grid', this%p_grid%j_x)
404  CALL cdf_write(result_iou, 'jy_grid', this%p_grid%j_y)
405  CALL cdf_write(result_iou, 'jz_grid', this%p_grid%j_z)
406 
407  CALL cdf_close(result_iou)
408  END IF
409 
410  CALL profiler_set_stop_time('bmw_context_write', start_time)
411 
412  END SUBROUTINE
413 
414  END MODULE
primed_grid::primed_grid_class
Base class representing a primed grid. This is grid the volume integral will be summed over.
Definition: primed_grid.f:27
bmw_context::bmw_context_set_up_grid_a
subroutine bmw_context_set_up_grid_a(this, r_grid, z_grid, dphi, parallel, io_unit)
Set the unprimed grid.
Definition: bmw_context.f:225
bmw_context::bmw_context_write
subroutine bmw_context_write(this, result_file_name, parallel)
Write NetCDF based result file.
Definition: bmw_context.f:319
bmw_context::bmw_context_destruct
subroutine bmw_context_destruct(this)
Deconstruct a bmw_context_class object.
Definition: bmw_context.f:140
bmw_state_flags
Contains parameters defining the bit positions for flags that mark different options.
Definition: bmw_state_flags.f:11
m_grid
Defines the base class of the type m_grid_class. This contains the state variables to define the vacu...
Definition: m_grid.f:11
bmw_context::series
integer, parameter series
Version number.
Definition: bmw_context.f:23
m_grid::m_grid_construct
type(m_grid_class) function, pointer m_grid_construct(mgrid_file_name, parallel, io_unit)
Construct a m_grid_class object.
Definition: m_grid.f:68
primed_grid::primed_grid_construct
type(primed_grid_class) function, pointer primed_grid_construct(num_v, flags, siesta_file, parallel, io_unit)
Construct a primed_grid_class object.
Definition: primed_grid.f:68
primed_grid::primed_grid_destruct
subroutine primed_grid_destruct(this)
Deconstruct a primed_grid_class object.
Definition: primed_grid.f:1457
bmw_parallel_context
Defines the base class of the type bmw_parallel_context_class. This contains the state variables need...
Definition: bmw_parallel_context.f:11
unprimed_grid
Defines the base class of the type unprimed_grid_class. This contains the state variables to define t...
Definition: unprimed_grid.f:12
bmw_context
Defines the base class of the type bmw_context_class. This contains the state variables needed by BMW...
Definition: bmw_context.f:11
bmw_context::bmw_context_set_up_grid_m
subroutine bmw_context_set_up_grid_m(this, p_start, p_end, parallel, io_unit)
Set the unprimed grid.
Definition: bmw_context.f:184
bmw_parallel_context::bmw_parallel_context_abort
subroutine bmw_parallel_context_abort(status)
Abort the entire program.
Definition: bmw_parallel_context.f:177
m_grid::m_grid_destruct
subroutine m_grid_destruct(this)
Deconstruct a m_grid_class object.
Definition: m_grid.f:195
unprimed_grid::unprimed_grid_class
Base class representing a unprimed grid. This is grid the volume integral will be summed over.
Definition: unprimed_grid.f:30
bmw_context::bmw_context_class
Base class representing a bmw context. This contains all memory needed to operate bmw.
Definition: bmw_context.f:34
bmw_state_flags::bmw_state_flags_mgrid
integer, parameter bmw_state_flags_mgrid
Bit position for mgrid specified number of phi planes.
Definition: bmw_state_flags.f:37
bmw_context::bmw_context_construct
type(bmw_context_class) function, pointer bmw_context_construct(mgrid_file_name, wout_file_name, siesta_file_name, flags, num_p, parallel, io_unit)
Construct a bmw_context_class object.
Definition: bmw_context.f:72
unprimed_grid::unprimed_grid_destruct
subroutine unprimed_grid_destruct(this)
Deconstruct a unprimed_grid_class object.
Definition: unprimed_grid.f:589
m_grid::m_grid_class
Base class representing a m grid. This is grid contains information about the vacuum fields.
Definition: m_grid.f:26
bmw_parallel_context::bmw_parallel_context_class
Base class representing a bmw parallel context. This contains all memory needed parameters needed to ...
Definition: bmw_parallel_context.f:26
unprimed_grid::unprimed_grid_construct
Interface to constructors.
Definition: unprimed_grid.f:49
bmw_context::bmw_context_set_up_grid
Interface to set the unprimed grid.
Definition: bmw_context.f:46
primed_grid
Defines the base class of the type primed_grid_class. This contains the state variables to define the...
Definition: primed_grid.f:11
bmw_context::bmw_context_init_nc
subroutine bmw_context_init_nc(this, result_file_name, parallel)
Definition: bmw_context.f:294