Commit c5f01fbd authored by Lore, Jeremy's avatar Lore, Jeremy
Browse files

Update routines to add hint, and add example. This commit is likely...

Update routines to add hint, and add example. This commit is likely inefficient, will update to use a single hint
parent 17f5b18e
Loading
Loading
Loading
Loading
+13 −3
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@
!-----------------------------------------------------------------------------
Module M3DC1_routines_mod
Use kind_mod, Only: real64, int32
Use fusion_io
Implicit None
Integer(int32), Parameter  :: num_sets_max = 10
Integer(int32), Save :: m3dc1_itime = -1
@@ -30,6 +31,7 @@ Logical :: m3dc1_toroidal_on_err = .false.
Integer, Private, Save :: num_sets
Integer(int32), Private, Save :: isrc(num_sets_max), imag(num_sets_max), imag_2d, ivec_2d
Real(real64), Private, Save   :: psi_axis, psi_lcfs
type(fio_search_hint), Private, Save :: hint(num_sets_max)

Contains

@@ -122,9 +124,14 @@ Do iset = 1,num_sets
!  Call fio_set_real_option_f(FIO_LINEAR_SCALE, m3dc1_factors(iset), ierr)
!  Call fio_get_field_f(isrc(iset), FIO_MAGNETIC_FIELD, imag_pert(iset), ierr)

! Initialize hint
call fio_allocate_search_hint_f(isrc(iset), hint(iset), ierr)

  
Enddo



End Subroutine prepare_m3dc1_fields


@@ -155,7 +162,7 @@ Do i=1,Npts
  Do iset = 1,num_sets
    x(2) = x(2) + m3dc1_phases_deg(iset)*pi/180._real64
    b_tmp = 0._Real64
    Call fio_eval_field_f(imag(iset), x, b_tmp, ierr_b)  ! b_tmp(R,phi,Z)
    Call fio_eval_field_f(imag(iset), x, b_tmp, ierr_b, hint=hint(iset))  ! b_tmp(R,phi,Z)
    
    If (ierr_b .ne. 0) Then
      If (m3dc1_toroidal_on_err) Then
@@ -205,7 +212,7 @@ Do i=1,Npts
  x(3) = z(i)
  b_tmp = 0._real64

  Call fio_eval_field_f(imag_2d, x, b_tmp, ierr_b)  ! b_tmp(R,phi,Z)
  Call fio_eval_field_f(imag_2d, x, b_tmp, ierr_b, hint=hint(1))  ! b_tmp(R,phi,Z)

  If (ierr_b .ne. 0) Then
    If (m3dc1_toroidal_on_err) Then
@@ -266,7 +273,7 @@ Do i=1,Npts
  x(3) = z(i)
  a_tmp = 0._real64
  
  Call fio_eval_field_f(ivec_2d, x, a_tmp, ierr_a)  ! A(R,phi,Z)
  Call fio_eval_field_f(ivec_2d, x, a_tmp, ierr_a, hint=hint(1))  ! A(R,phi,Z)
  If (ierr_a .ne. 0) Then
    ierr = 1
  Endif
@@ -312,7 +319,10 @@ Do iset = 1,num_sets
    Call fio_close_field_f(ivec_2d, ierr)
  Endif
  Call fio_close_source_f(isrc(iset), ierr)
  call fio_deallocate_search_hint_f(isrc(iset), hint(iset), ierr)
Enddo


End Subroutine close_m3dc1_fields

End Module M3DC1_routines_mod
+29 −12
Original line number Diff line number Diff line
@@ -4,23 +4,28 @@ Use m3dc1_routines_mod
Implicit None
Real(real64), Allocatable :: bg2(:,:), rg(:), zg(:), pg(:)
Integer(int32) :: ierr_b, num_pts, i, m3dc1_nsets
Character(250) :: m3dc1_filenames(2)



m3dc1_nsets = 2  ! MUST EQUAL LENGTH OF FILENAMES AND SCALE_FACTORS!!
m3dc1_filenames(1) = '/home/jjl/m3dc1/164723/03059/n=3/eb1_2f_iu/C1.h5'
m3dc1_filenames(2) = '/home/jjl/m3dc1/164723/03059/n=3/eb1_2f_il/C1.h5'

m3dc1_itime = 0 ! 0:vac 1 response
m3dc1_factors(1) = 3.69d0
m3dc1_factors(2) = 3.69d0
Character(250) :: m3dc1_filenames(4)
Real(Kind=4)  :: tarray(2),tres,tres0

m3dc1_nsets = 4
m3dc1_filenames(1) = '/home/jjl/M3DC1_runs/orlov_2300/n=1/eb1_1f_probeg/C1.h5'
m3dc1_filenames(2) = '/home/jjl/M3DC1_runs/orlov_2300/n=2/eb1_1f_probeg/C1.h5'
m3dc1_filenames(3) = '/home/jjl/M3DC1_runs/orlov_2300/n=3/eb1_1f_probeg/C1.h5'
m3dc1_filenames(4) = '/home/jjl/M3DC1_runs/orlov_2300/n=4/eb1_1f_probeg/C1.h5'
m3dc1_factors(1:4) = 2.
m3dc1_phases_deg(1:4) = 0.
m3dc1_itime = 0  ! 0 vacuum, 1 response
m3dc1_field_type = 0 ! total (0) or perturbed only (1)
m3dc1_toroidal_on_err = .false.
m3dc1_field_type = 1  ! 1=perturbed_only

Call Etime(tarray,tres0)
Call prepare_m3dc1_fields(m3dc1_filenames(1:m3dc1_nsets))
Write(*,'(a,i0)') '---------> M3DC1 time (0 vacuum, 1 response): ',m3dc1_itime
Write(*,*) '---------> M3DC1 scale factor: ',m3dc1_factors(1:m3dc1_nsets)

Call Etime(tarray,tres)
Write(*,*) ' Initialization took ',tres-tres0,' seconds'
Call Etime(tarray,tres0)



@@ -33,8 +38,20 @@ pg = 30.d0*3.14159d0/180.d0

Write(*,*) 'Evaluating B at [R,Z,phi] = ',rg,zg,pg
Call bfield_m3dc1(rg,pg,zg,num_pts,bg2,ierr_b)     
write(*,*) 'Bout [Br,Bz,Bphi] = ',bg2
Call Etime(tarray,tres)
Write(*,*) ' First call took ',tres-tres0,' seconds'
Call Etime(tarray,tres0)


Write(*,*) 'Evaluating B at [R,Z,phi] = ',rg,zg,pg
Call bfield_m3dc1(rg,pg,zg,num_pts,bg2,ierr_b)     
write(*,*) 'Bout [Br,Bz,Bphi] = ',bg2
Call Etime(tarray,tres)
Write(*,*) ' Second call took ',tres-tres0,' seconds'
Call Etime(tarray,tres0)


Deallocate(bg2,rg,zg,pg)

End Program Test_m3dc1_bfield
+38 −0
Original line number Diff line number Diff line
&bfield_nml
gfile_name = '/home/jjl/Florian/g147170.02300'


!rmp_type = 'g3d' ! options: 'g3d', 'g3d+rmpcoil', 'm3dc1_full_field', 'g3d+m3dc1'

rmp_type = 'm3dc1_full_field' ! options: 'g3d', 'g3d+rmpcoil', 'm3dc1_full_field', 'g3d+m3dc1'
m3dc1_nsets = 1
m3dc1_filenames(1) = '/home/jjl/M3DC1_runs/orlov_2300/n=1/eb1_1f_probeg/C1.h5'
!m3dc1_filenames(2) = '/home/jjl/M3DC1_runs/orlov_2300/n=2/eb1_1f_probeg/C1.h5'
!m3dc1_filenames(3) = '/home/jjl/M3DC1_runs/orlov_2300/n=3/eb1_1f_probeg/C1.h5'
!m3dc1_filenames(4) = '/home/jjl/M3DC1_runs/orlov_2300/n=4/eb1_1f_probeg/C1.h5'
m3dc1_scale_factors = 1*2.
m3dc1_phase_shift_deg = 1*0.
m3dc1_time = 0  ! 0 vacuum, 1 response



/

&settings_nml

Nsym = 3

rstart = 1.95d0
rend = 2.1d0
zstart = 0.d0
zend = 0.d0

num_pts = 10
phistart_deg = 0.d0
ntransits = 100
dphi_line_deg = 0.5d0

follow_both_ways = .true.
calc_psiN_min = .true.

/