2
C rt_tddft_input_field.F
4
C Parses input deck for rt-tddft field (excitation) parameters.
7
subroutine rt_tddft_input_field (rtdb, field_name, nfields)
10
#include "rt_tddft.fh"
14
#include "mafdecls.fh"
19
integer, intent(in) :: rtdb
20
character*16, intent(in) :: field_name !hardcoded to match geom name max size
21
integer, intent(in) :: nfields !this is the number of the current field
25
character(*), parameter :: pname = "rt_tddft_input_field: "
32
type (rt_field_t) prev_field, this_field
39
double precision center
40
double precision frequency
41
double precision width
42
double precision phase
43
character*2 polarization !x,y,z for dipole; xx,xy,xz,... for quad
47
logical lhave_polarization
51
logical lhave_frequency
55
if (nfields .gt. rt_max_fields)
56
$ call errquit (pname//"cannot exceed max num fields", 0, 0)
59
lhave_center = .false.
60
lhave_polarization = .false.
63
lhave_frequency = .false.
69
C Parse the input; we will put in rtdb later after checking.
75
$ call errquit(pname//'Read failed input',0, INPUT_ERR)
76
if (.not. inp_a(test))
77
$ call errquit(pname//'Read failed keyword',0, INPUT_ERR)
82
C type (delta, cw, gaussian)
84
if (inp_compare(.false.,test,'type')) then
85
if (.not. inp_a (type))
86
$ call errquit (pname//"failed to read field type",0,0)
88
if ( (type.ne."cw").and.
89
$ (type.ne."delta").and.
90
$ (type.ne."hann").and.
91
$ (type.ne."gaussian") )
92
$ call errquit (pname//"invalid field type: "//type,0,0)
98
C spin which the field acts on
100
elseif (inp_compare(.false.,test,'spin')) then
101
if (.not. inp_a (spin))
102
$ call errquit (pname//
103
$ "failed to read field target spin",0,0)
110
C max value of the field
112
elseif (inp_compare(.false.,test,'max')) then
113
if (.not.inp_f(max)) call errquit (pname//
114
$ "max takes a float", 0, 0)
118
C center the field (only for gaussian and Hann)
120
elseif (inp_compare(.false.,test,'center')) then
121
if (.not.inp_f(center)) call errquit (pname//
122
$ "center takes a float >= 0", 0, 0)
123
lhave_center = .true.
127
C width the field (only for gaussian and Hann)
129
elseif (inp_compare(.false.,test,'width')) then
130
if (.not.inp_f(width)) call errquit (pname//
131
$ "width takes a float >= 0", 0, 0)
136
C frequency the field (only for gaussian and cw)
138
elseif (inp_compare(.false.,test,'frequency')) then
139
if (.not.inp_f(frequency)) call errquit (pname//
140
$ "frequency takes a float >= 0", 0, 0)
141
lhave_frequency = .true.
147
elseif (inp_compare(.false.,test,'polarization')) then
148
if (.not.inp_a(polarization)) call errquit (pname//
149
$ "polarization can be: x,y,z (for dipole); "//
150
$ "xx,xy,xz,... (for quad)", 0, 0)
151
lhave_polarization = .true.
156
C phase (only for gaussian and cw)
158
elseif (inp_compare(.false.,test,'phase')) then
159
if (.not.inp_f(phase)) call errquit (pname//
160
$ "phase takes a float >= 0", 0, 0)
167
else if (inp_compare(.false.,test,'end')) then
170
call errquit(pname//'Unknown directive: '//trim(test),
181
C Now check that we have all required parameters, no superfluous
182
C ones, no name clashes with other fields, and that params are
183
C reasonable (e.g., no negative times, etc).
186
if (nfields .gt. 1) then
187
do i = 1, nfields - 1
188
call rt_tddft_field_rtdb_get (rtdb, i, prev_field)
189
if (prev_field%name .eq. field_name)
190
$ call errquit (pname//"cannot have multiple fields"//
191
$ " with the same name: "//trim(field_name), 0, 0)
196
if (.not. lhave_type)
197
$ call errquit (pname//trim(field_name)//
198
$ ": must supply a field type", 0, 0)
201
if (spin.eq."alpha") then
203
elseif (spin.eq."beta") then
205
elseif (spin.eq."total") then
209
call errquit (pname//"invalid field spin: "//spin,0,0)
212
spin1 = "t" !default to acting on all spins
215
if (.not. lhave_spin) spin = "total" !default to acting on both spins
219
$ call errquit (pname//trim(field_name)//
220
$ ": must supply a field max", 0, 0)
222
if (.not. lhave_polarization)
223
$ call errquit (pname//trim(field_name)//
224
$ ": must supply a field polarization", 0,0)
226
if (type .eq. "cw") then
227
if (.not. lhave_frequency)
228
$ call errquit (pname//trim(field_name)//
229
$ ": must supply a frequency if doing cw", 0,0)
231
if (lhave_center) call errquit (pname//trim(field_name)//
232
$ ": cannot specify center if cw", 0,0)
234
if (lhave_width) call errquit (pname//trim(field_name)//
235
$ ": cannot specify width if cw", 0,0)
238
if (type .eq. "gaussian") then
239
if (.not. lhave_frequency)
240
$ call errquit (pname//trim(field_name)//
241
$ ": must supply a frequency if doing gaussian", 0,0)
243
if (.not. lhave_center) call errquit (pname//trim(field_name)//
244
$ ": must specify center if gaussian", 0,0)
246
if (.not. lhave_width) call errquit (pname//trim(field_name)//
247
$ ": must specify width if gaussian", 0,0)
250
if (type .eq. "hann") then
251
if (.not. lhave_frequency)
252
$ call errquit (pname//trim(field_name)//
253
$ ": must supply a frequency if doing Hann", 0,0)
255
if (.not. lhave_center) call errquit (pname//trim(field_name)//
256
$ ": must specify center if Hann", 0,0)
258
if (.not. lhave_width) call errquit (pname//trim(field_name)//
259
$ ": must specify width if Hann", 0,0)
263
if (type .eq. "delta") then
264
if (lhave_frequency) call errquit (pname//trim(field_name)//
265
$ ": cannot supply a frequency if doing delta", 0,0)
267
if (.not. lhave_center) then
268
center = 0d0 !default delta kick to t=0
269
lhave_center = .true.
273
c$$$ if (lhave_center) call errquit (pname//trim(field_name)//
274
c$$$ $ ": cannot specify center if delta", 0,0)
276
if (lhave_width) call errquit (pname//trim(field_name)//
277
$ ": cannot specify width if delta", 0,0)
280
if ( (polarization.ne."x").and.
281
$ (polarization.ne."y").and.
282
$ (polarization.ne."z") )
283
$ call errquit (pname//trim(field_name)//
284
$ ": polarization must be x, y, or z (quads disabled for now)",
287
C if ( (lhave_frequency).and.(frequency.lt.0d0) )
288
C $ call errquit (pname//trim(field_name)//
289
C $ ": frequency must be positive", 0, 0)
291
if ( (lhave_center).and.(center.lt.0d0) )
292
$ call errquit (pname//trim(field_name)//
293
$ ": center must be positive", 0, 0)
295
if ( (lhave_width).and.(width.lt.0d0) )
296
$ call errquit (pname//trim(field_name)//
297
$ ": width must be positive", 0, 0)
300
C (no, its OK to have a negative "max")
301
C if ( (lhave_max).and.(max.lt.0d0) )
302
C $ call errquit (pname//trim(field_name)//
303
C $ ": max must be positive", 0, 0)
307
C Frequency-related stuff only valid for CW and pulses (gaussian, hann)
309
if (lhave_phase .or. lhave_frequency) then
310
if ((type .ne. "cw").and.(type .ne. "gaussian")
311
$ .and. (type .ne. "hann")) call errquit (pname//
312
$ "phase and frequency only valid for "//
313
$ "CW, gaussian, and hann",0,0)
320
this_field%name = field_name
321
this_field%type = type
322
this_field%polarization = polarization
324
this_field%spin = spin1
326
if (type.eq."cw") then
327
this_field%frequency = frequency
328
this_field%phase = phase
329
this_field%width = -99d0
330
this_field%center = -99d0
333
if (type.eq."gaussian") then
334
this_field%frequency = frequency
335
this_field%phase = phase
336
this_field%width = width
337
this_field%center = center
340
if (type.eq."hann") then
341
this_field%frequency = frequency
342
this_field%phase = phase
343
this_field%width = width
344
this_field%center = center
347
if (type.eq."delta") then
348
this_field%frequency = -99d0
349
this_field%width = -99d0
350
this_field%center = center
353
call rt_tddft_field_rtdb_put (rtdb, nfields, this_field)
358
C====================================================================
360
C Generate entry name for field rtdb stuff (hack)
362
subroutine rt_tddft_field_rtdb_entry_name (i, name)
365
#include "errquit.fh"
367
#include "mafdecls.fh"
369
#include "rt_tddft.fh"
373
integer, intent(in) :: i
377
character(len=*), intent(out) :: name !was 17
381
character(len=*), parameter :: pname =
382
$ "rt_tddft_field_rtdb_entry_name"
386
character*5 istring !note length 5 limit size of int
389
if ( (i .gt. rt_max_fields).or.(i .lt. 1) )
390
$ call errquit(pname//"i must be between 1, rt_max_fields",0,0)
392
if (rt_max_fields .gt. 999) call errquit(pname//
393
$ "rt_max_fields too large; fix formatting", 0, 0)
395
write (istring, "(i0.5)") i
397
name = "rt_tddft:field_"//trim(istring)//"_"
402
C====================================================================
404
C Load field into rtbd. This is an ugly hack, but it's easier than
405
C adding a custom struct to the rtdb routines.
407
subroutine rt_tddft_field_rtdb_put (rtdb, i, field)
410
#include "rt_tddft.fh"
411
#include "errquit.fh"
413
#include "mafdecls.fh"
418
integer, intent(in) :: rtdb
419
integer, intent(in) :: i !index for the field
420
type(rt_field_t), intent(in) :: field
424
character(len=*), parameter :: pname = "rt_tddft_field_rtdb_put: "
428
character*32 basename
429
character*32 entry_name
431
if ( (i .gt. rt_max_fields).or.(i .lt. 1) )
432
$ call errquit(pname//"i must be between 1, rt_max_fields",0,0)
434
call rt_tddft_field_rtdb_entry_name (i, basename)
436
entry_name = trim(basename) // "name"
437
if (.not.rtdb_cput(rtdb,entry_name,1,field%name))
438
$ call errquit(pname//'Write failed to name rtdb',
441
entry_name = trim(basename) // "type"
442
if (.not.rtdb_cput(rtdb,entry_name,1,field%type))
443
$ call errquit(pname//'Write failed to type rtdb',
446
entry_name = trim(basename) // "polarization"
447
if (.not.rtdb_cput(rtdb,entry_name,1,field%polarization))
448
$ call errquit(pname//'Write failed to polarization rtdb',
451
entry_name = trim(basename) // "spin"
452
if (.not.rtdb_cput(rtdb,entry_name,1,field%spin))
453
$ call errquit(pname//'Write failed to spin rtdb',
456
entry_name = trim(basename) // "max"
457
if (.not.rtdb_put(rtdb,entry_name,mt_dbl,1,field%max))
458
$ call errquit(pname//'Write failed to max rtdb',0,RTDB_ERR)
460
entry_name = trim(basename) // "frequency"
461
if (.not.rtdb_put(rtdb,entry_name,mt_dbl,1,field%frequency))
462
$ call errquit(pname//'Write failed to frequency rtdb',
465
entry_name = trim(basename) // "width"
466
if (.not.rtdb_put(rtdb,entry_name,mt_dbl,1,field%width))
467
$ call errquit(pname//'Write failed to width rtdb',
470
entry_name = trim(basename) // "center"
471
if (.not.rtdb_put(rtdb,entry_name,mt_dbl,1,field%center))
472
$ call errquit(pname//'Write failed to center rtdb',
475
entry_name = trim(basename) // "phase"
476
if (.not.rtdb_put(rtdb,entry_name,mt_dbl,1,field%phase))
477
$ call errquit(pname//'Write failed to phase rtdb',
485
C Get field from rtdb and put into struct
487
subroutine rt_tddft_field_rtdb_get (rtdb, i, field)
490
#include "rt_tddft.fh"
491
#include "errquit.fh"
493
#include "mafdecls.fh"
498
integer, intent(in) :: rtdb
499
integer, intent(in) :: i !index for the field
503
type(rt_field_t), intent(out) :: field
508
character(len=*), parameter :: pname = "rt_tddft_field_rtdb_get: "
512
character*32 basename
513
character*32 entry_name
516
if ( (i .gt. rt_max_fields).or.(i .lt. 1) )
517
$ call errquit(pname//"i must be between 1, rt_max_fields",0,0)
519
call rt_tddft_field_rtdb_entry_name (i, basename)
522
entry_name = trim(basename) // "name"
523
if (.not.rtdb_cget(rtdb,entry_name,1,field%name))
524
$ call errquit(pname//'Read failed for name rtdb',
527
entry_name = trim(basename) // "type"
528
if (.not.rtdb_cget(rtdb,entry_name,1,field%type))
529
$ call errquit(pname//'Read failed for type rtdb',
532
entry_name = trim(basename) // "polarization"
533
if (.not.rtdb_cget(rtdb,entry_name,1,field%polarization))
534
$ call errquit(pname//'Read failed for polarization rtdb',
537
entry_name = trim(basename) // "spin"
538
if (.not.rtdb_cget(rtdb,entry_name,1,field%spin))
539
$ call errquit(pname//'Read failed for spin rtdb',
542
entry_name = trim(basename) // "max"
543
if (.not.rtdb_get(rtdb,entry_name,mt_dbl,1,field%max))
544
$ call errquit(pname//'Read failed for max rtdb',0,RTDB_ERR)
546
entry_name = trim(basename) // "frequency"
547
if (.not.rtdb_get(rtdb,entry_name,mt_dbl,1,field%frequency))
548
$ call errquit(pname//'Read failed for frequency rtdb',
551
entry_name = trim(basename) // "width"
552
if (.not.rtdb_get(rtdb,entry_name,mt_dbl,1,field%width))
553
$ call errquit(pname//'Read failed for width rtdb',
556
entry_name = trim(basename) // "center"
557
if (.not.rtdb_get(rtdb,entry_name,mt_dbl,1,field%center))
558
$ call errquit(pname//'Read failed for center rtdb',
561
entry_name = trim(basename) // "phase"
562
if (.not.rtdb_get(rtdb,entry_name,mt_dbl,1,field%phase))
563
$ call errquit(pname//'Read failed for phase rtdb',