LCOV - code coverage report
Current view: top level - src - input_cp2k_field.F (source / functions) Coverage Total Hit
Test: CP2K Regtests (git:561f475) Lines: 100.0 % 117 117
Test Date: 2026-06-21 06:48:54 Functions: 100.0 % 6 6

            Line data    Source code
       1              : !--------------------------------------------------------------------------------------------------!
       2              : !   CP2K: A general program to perform molecular dynamics simulations                              !
       3              : !   Copyright 2000-2026 CP2K developers group <https://cp2k.org>                                   !
       4              : !                                                                                                  !
       5              : !   SPDX-License-Identifier: GPL-2.0-or-later                                                      !
       6              : !--------------------------------------------------------------------------------------------------!
       7              : 
       8              : ! **************************************************************************************************
       9              : !> \brief function that build the field section of the input
      10              : !> \par History
      11              : !>      02.2017 moved out of input_cp2k_dft [JHU]
      12              : !> \author fawzi
      13              : ! **************************************************************************************************
      14              : MODULE input_cp2k_field
      15              :    USE bibliography, ONLY: Souza2002, &
      16              :                            Stengel2009, &
      17              :                            Umari2002
      18              :    USE input_constants, ONLY: constant_env, &
      19              :                               custom_env, &
      20              :                               gaussian, &
      21              :                               gaussian_env, &
      22              :                               ramp_env
      23              :    USE input_keyword_types, ONLY: keyword_create, &
      24              :                                   keyword_release, &
      25              :                                   keyword_type
      26              :    USE input_section_types, ONLY: section_add_keyword, &
      27              :                                   section_add_subsection, &
      28              :                                   section_create, &
      29              :                                   section_release, &
      30              :                                   section_type
      31              :    USE input_val_types, ONLY: char_t, &
      32              :                               real_t
      33              :    USE kinds, ONLY: dp
      34              :    USE string_utilities, ONLY: s2a
      35              : #include "./base/base_uses.f90"
      36              : 
      37              :    IMPLICIT NONE
      38              :    PRIVATE
      39              : 
      40              :    CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'input_cp2k_field'
      41              : 
      42              :    PUBLIC :: create_per_efield_section, create_efield_section
      43              : 
      44              : CONTAINS
      45              : 
      46              : ! **************************************************************************************************
      47              : !> \brief creates the section for static periodic fields
      48              : !> \param section ...
      49              : !> \author Florian Schiffmann
      50              : ! **************************************************************************************************
      51        20696 :    SUBROUTINE create_per_efield_section(section)
      52              :       TYPE(section_type), POINTER                        :: section
      53              : 
      54              :       TYPE(keyword_type), POINTER                        :: keyword
      55              : 
      56        20696 :       CPASSERT(.NOT. ASSOCIATED(section))
      57              :       CALL section_create(section, __LOCATION__, name="PERIODIC_EFIELD", &
      58              :                           description="parameters for finite periodic electric field computed using"// &
      59              :                           " the Berry phase approach. IMPORTANT: Can only be used in combination"// &
      60              :                           " with OT. Can not be used in combination with RTP or EMD,"// &
      61              :                           " e.g. RESTART_RTP has to be .FALSE. when restarting the job.", &
      62              :                           citations=[Souza2002, Umari2002], &
      63        62088 :                           n_keywords=6, n_subsections=1, repeats=.TRUE.)
      64              : 
      65        20696 :       NULLIFY (keyword)
      66              : 
      67              :       CALL keyword_create(keyword, __LOCATION__, name="INTENSITY", &
      68              :                           description="Intensity of the electric field in a.u, "// &
      69              :                           "not allowed together with INTENSITY_LIST", &
      70              :                           usage="INTENSITY  0.001", &
      71        20696 :                           default_r_val=0._dp)
      72        20696 :       CALL section_add_keyword(section, keyword)
      73        20696 :       CALL keyword_release(keyword)
      74              : 
      75              :       CALL keyword_create(keyword, __LOCATION__, name="POLARISATION", &
      76              :                           description="Polarisation vector of electric field", &
      77              :                           usage="POLARISATION  0.0 0.0 1.0", &
      78              :                           repeats=.FALSE., n_var=3, &
      79        20696 :                           type_of_var=real_t, default_r_vals=[0.0_dp, 0.0_dp, 1.0_dp])
      80        20696 :       CALL section_add_keyword(section, keyword)
      81        20696 :       CALL keyword_release(keyword)
      82              : 
      83              :       CALL keyword_create(keyword, __LOCATION__, name="DISPLACEMENT_FIELD", &
      84              :                           description="Use the displacement field formulation.", &
      85              :                           usage="DISPLACEMENT_FIELD T", &
      86              :                           citations=[Stengel2009], &
      87              :                           default_l_val=.FALSE., &
      88        41392 :                           lone_keyword_l_val=.TRUE.)
      89        20696 :       CALL section_add_keyword(section, keyword)
      90        20696 :       CALL keyword_release(keyword)
      91              : 
      92              :       CALL keyword_create(keyword, __LOCATION__, name="D_FILTER", &
      93              :                           description="Filter for displacement field (x,y,z-direction)", &
      94              :                           usage="D_FILTER  1.0 0.0 0.0", &
      95              :                           repeats=.FALSE., n_var=3, &
      96        20696 :                           type_of_var=real_t, default_r_vals=[1.0_dp, 1.0_dp, 1.0_dp])
      97        20696 :       CALL section_add_keyword(section, keyword)
      98        20696 :       CALL keyword_release(keyword)
      99              : 
     100              :       CALL keyword_create(keyword, __LOCATION__, name="INTENSITY_LIST", &
     101              :                           description="Intensities of the electric field in a.u. "// &
     102              :                           "They are applied sequentially, one per frame. "// &
     103              :                           "If the number of frames exceeds the number of values, "// &
     104              :                           "the list is cyclically repeated. Attention: not implemented for eeq.", &
     105              :                           usage="INTENSITY_LIST {real} {real} .. {real}", &
     106        20696 :                           n_var=-1, type_of_var=real_t, default_r_vals=[0.0_dp])
     107        20696 :       CALL section_add_keyword(section, keyword)
     108        20696 :       CALL keyword_release(keyword)
     109              : 
     110              :       CALL keyword_create(keyword, __LOCATION__, name="INTENSITIES_FILE_NAME", &
     111              :                           description="File containting a list of intensities, "// &
     112              :                           "one per line, in a.u. "// &
     113              :                           "They are applied sequentially, one per frame. "// &
     114              :                           "If the number of frames exceeds the number of values, "// &
     115              :                           "the list is cyclically repeated. Attention: not implemented for eeq.", &
     116              :                           usage="INTENSITIES_FILE_NAME filename", &
     117        20696 :                           default_lc_val="")
     118        20696 :       CALL section_add_keyword(section, keyword)
     119        20696 :       CALL keyword_release(keyword)
     120              : 
     121              :       CALL keyword_create(keyword, __LOCATION__, name="START_FRAME", &
     122              :                           description="First frame the field is applied. "// &
     123              :                           "(0: first frame) "// &
     124              :                           "Attention: ignored for eeq", &
     125              :                           usage="START_FRAME 0", &
     126        20696 :                           default_i_val=0)
     127        20696 :       CALL section_add_keyword(section, keyword)
     128        20696 :       CALL keyword_release(keyword)
     129              : 
     130              :       CALL keyword_create(keyword, __LOCATION__, name="END_FRAME", &
     131              :                           description="Last frame the field is applied. "// &
     132              :                           "If an end frame is specified, the number of active frames "// &
     133              :                           "must be a multiple of the number of "// &
     134              :                           "the given intensity values. (-1: no end) "// &
     135              :                           "Attention: ignored for eeq", &
     136              :                           usage="END_FRAME -1", &
     137        20696 :                           default_i_val=-1)
     138        20696 :       CALL section_add_keyword(section, keyword)
     139        20696 :       CALL keyword_release(keyword)
     140              : 
     141        20696 :    END SUBROUTINE create_per_efield_section
     142              : ! **************************************************************************************************
     143              : !> \brief creates the section for time dependent nonperiodic fields
     144              : !> \param section ...
     145              : !> \author Florian Schiffmann
     146              : ! **************************************************************************************************
     147        10356 :    SUBROUTINE create_efield_section(section)
     148              :       TYPE(section_type), POINTER                        :: section
     149              : 
     150              :       TYPE(keyword_type), POINTER                        :: keyword
     151              :       TYPE(section_type), POINTER                        :: subsection
     152              : 
     153        10356 :       CPASSERT(.NOT. ASSOCIATED(section))
     154              :       CALL section_create(section, __LOCATION__, name="EFIELD", &
     155              :                           description="Parameters for finite, time  dependent electric fields. "// &
     156              :                           "For time dependent  propagation in periodic systems, set "// &
     157              :                           "DFT%REAL_TIME_PROPAGATION%VELOCITY_GAUGE to true. "// &
     158              :                           "For static fields use EXTERNAL_POTENTIAL.", &
     159        10356 :                           n_keywords=6, n_subsections=1, repeats=.TRUE.)
     160              : 
     161        10356 :       NULLIFY (keyword, subsection)
     162              : 
     163              :       CALL keyword_create(keyword, __LOCATION__, name="INTENSITY", &
     164              :                           description="Intensity of the electric field. "// &
     165              :                           "For real-time propagation (RTP) calculations, the intensity is in "// &
     166              :                           "$\mathrm{W/cm^2}$. The corresponding peak electric field amplitude "// &
     167              :                           "$E_0$ in atomic units ($E_H/a_B \approx 82.4\,\mathrm{V/nm}$) is "// &
     168              :                           "$E_0 = \sqrt{I\,[\mathrm{W/cm^2}]\;/\;(3.5094410 \cdot 10^{16})} "// &
     169              :                           "\cdot E_H/a_B$, "// &
     170              :                           "derived from the atomic unit of energy flux $I_0 = cE_H^2/(8\pi)$ "// &
     171              :                           "and the relation $I = E_0^2$ in atomic units. "// &
     172              :                           "For a constant local field in an isolated-system calculation, "// &
     173              :                           "units are in a.u. In place of intensity, AMPLITUDE can be provided.", &
     174              :                           usage="INTENSITY  0.001", &
     175        10356 :                           default_r_val=0._dp)
     176        10356 :       CALL section_add_keyword(section, keyword)
     177        10356 :       CALL keyword_release(keyword)
     178              : 
     179              :       CALL keyword_create(keyword, __LOCATION__, name="AMPLITUDE", &
     180              :                           description="Amplitude of the electric field of the light wave. "// &
     181              :                           "One can specify either INTENSITY or AMPLITUDE. An error will be "// &
     182              :                           "raised if both are specified.", &
     183              :                           usage="AMPLITUDE [Vnm-1] 1.06", unit_str="Vm-1", &
     184        10356 :                           default_r_val=0._dp)
     185        10356 :       CALL section_add_keyword(section, keyword)
     186        10356 :       CALL keyword_release(keyword)
     187              : 
     188              :       CALL keyword_create(keyword, __LOCATION__, name="POLARISATION", &
     189              :                           description="Polarisation vector of electric field", &
     190              :                           usage="POLARISATION  0.0 0.0 1.0", &
     191              :                           repeats=.FALSE., n_var=3, &
     192        10356 :                           type_of_var=real_t, default_r_vals=[0.0_dp, 0.0_dp, 1.0_dp])
     193        10356 :       CALL section_add_keyword(section, keyword)
     194        10356 :       CALL keyword_release(keyword)
     195              : 
     196              :       CALL keyword_create(keyword, __LOCATION__, name="WAVELENGTH", &
     197              :                           description="Wavelength of efield field for real-time propagation (RTP) calculations.", &
     198              :                           usage="Wavelength  1.E0", &
     199        10356 :                           default_r_val=0._dp, unit_str="nm")
     200        10356 :       CALL section_add_keyword(section, keyword)
     201        10356 :       CALL keyword_release(keyword)
     202              : 
     203              :       CALL keyword_create(keyword, __LOCATION__, name="PHASE", &
     204              :                           description="Phase offset of the cosine given in multiples of pi. "// &
     205              :                           "Used in real-time propagation (RTP) calculations.", &
     206              :                           usage="Phase  1.E0", &
     207        10356 :                           default_r_val=0._dp)
     208        10356 :       CALL section_add_keyword(section, keyword)
     209        10356 :       CALL keyword_release(keyword)
     210              : 
     211              :       CALL keyword_create(keyword, __LOCATION__, name="ENVELOP", &
     212              :                           description="Shape of the efield pulse used in real-time propagation (RTP) calculations.", &
     213              :                           usage="ENVELOP CONSTANT", &
     214              :                           default_i_val=constant_env, &
     215              :                           enum_c_vals=s2a("CONSTANT", "GAUSSIAN", "RAMP", "CUSTOM"), &
     216              :                           enum_desc=s2a("No envelop function is applied to the strength", &
     217              :                                         "A Gaussian function is used as envelop ", &
     218              :                                         "Linear tune in/out of the field", &
     219              :                                         "A custom field read from a file"), &
     220        10356 :                           enum_i_vals=[constant_env, gaussian_env, ramp_env, custom_env])
     221        10356 :       CALL section_add_keyword(section, keyword)
     222        10356 :       CALL keyword_release(keyword)
     223              : 
     224              :       CALL keyword_create(keyword, __LOCATION__, name="VEC_POT_INITIAL", &
     225              :                           description="Initial value of the vector "// &
     226              :                           "potential (for velocity gauge). This input is "// &
     227              :                           "made especially for restarting RTP calculation. "// &
     228              :                           "Unit is atomic unit. "// &
     229              :                           "Note that if several field sections are defined, only the first one will be used.", &
     230              :                           usage="vec_pot_initial  1.0E-2 0.0 0.0", &
     231              :                           repeats=.FALSE., &
     232              :                           n_var=3, type_of_var=real_t, &
     233        10356 :                           default_r_vals=[0.0_dp, 0.0_dp, 0.0_dp])
     234        10356 :       CALL section_add_keyword(section, keyword)
     235        10356 :       CALL keyword_release(keyword)
     236              : 
     237        10356 :       CALL create_constant_env_section(subsection)
     238        10356 :       CALL section_add_subsection(section, subsection)
     239        10356 :       CALL section_release(subsection)
     240              : 
     241        10356 :       CALL create_gaussian_env_section(subsection)
     242        10356 :       CALL section_add_subsection(section, subsection)
     243        10356 :       CALL section_release(subsection)
     244              : 
     245        10356 :       CALL create_ramp_env_section(subsection)
     246        10356 :       CALL section_add_subsection(section, subsection)
     247        10356 :       CALL section_release(subsection)
     248              : 
     249        10356 :       CALL create_custom_env_section(subsection)
     250        10356 :       CALL section_add_subsection(section, subsection)
     251        10356 :       CALL section_release(subsection)
     252              : 
     253        10356 :    END SUBROUTINE create_efield_section
     254              : 
     255              : ! **************************************************************************************************
     256              : !> \brief ...
     257              : !> \param section ...
     258              : ! **************************************************************************************************
     259        10356 :    SUBROUTINE create_constant_env_section(section)
     260              :       TYPE(section_type), POINTER                        :: section
     261              : 
     262              :       TYPE(keyword_type), POINTER                        :: keyword
     263              : 
     264        10356 :       CPASSERT(.NOT. ASSOCIATED(section))
     265              :       CALL section_create(section, __LOCATION__, name="CONSTANT_ENV", &
     266              :                           description="parameters for a constant envelop", &
     267        10356 :                           n_keywords=6, n_subsections=1, repeats=.TRUE.)
     268              : 
     269        10356 :       NULLIFY (keyword)
     270              : 
     271              :       CALL keyword_create(keyword, __LOCATION__, name="START_STEP", &
     272              :                           description="First step the field is applied ", &
     273              :                           usage="START_STEP 0", &
     274        10356 :                           default_i_val=0)
     275        10356 :       CALL section_add_keyword(section, keyword)
     276        10356 :       CALL keyword_release(keyword)
     277              : 
     278              :       CALL keyword_create(keyword, __LOCATION__, name="END_STEP", &
     279              :                           description="Last step the field is applied", &
     280              :                           usage="END_STEP 2", &
     281        10356 :                           default_i_val=-1)
     282        10356 :       CALL section_add_keyword(section, keyword)
     283        10356 :       CALL keyword_release(keyword)
     284              : 
     285        10356 :    END SUBROUTINE create_constant_env_section
     286              : 
     287              : ! **************************************************************************************************
     288              : !> \brief ...
     289              : !> \param section ...
     290              : ! **************************************************************************************************
     291        10356 :    SUBROUTINE create_gaussian_env_section(section)
     292              :       TYPE(section_type), POINTER                        :: section
     293              : 
     294              :       TYPE(keyword_type), POINTER                        :: keyword
     295              : 
     296        10356 :       CPASSERT(.NOT. ASSOCIATED(section))
     297              :       CALL section_create(section, __LOCATION__, name="GAUSSIAN_ENV", &
     298              :                           description="parameters for a gaussian envelop", &
     299        10356 :                           n_keywords=6, n_subsections=1, repeats=.TRUE.)
     300              : 
     301        10356 :       NULLIFY (keyword)
     302              : 
     303              :       CALL keyword_create(keyword, __LOCATION__, name="T0", &
     304              :                           description="Center of the gaussian envelop (maximum of the gaussian)", &
     305              :                           usage="T0 2.0E0", &
     306              :                           default_r_val=0.0E0_dp, &
     307        10356 :                           unit_str="fs")
     308        10356 :       CALL section_add_keyword(section, keyword)
     309        10356 :       CALL keyword_release(keyword)
     310              : 
     311              :       CALL keyword_create(keyword, __LOCATION__, name="SIGMA", &
     312              :                           description="Width of the gaussian ", &
     313              :                           usage="SIGMA 2.0E0", &
     314              :                           default_r_val=-1.0E0_dp, &
     315        10356 :                           unit_str="fs")
     316        10356 :       CALL section_add_keyword(section, keyword)
     317        10356 :       CALL keyword_release(keyword)
     318              : 
     319        10356 :    END SUBROUTINE create_gaussian_env_section
     320              : 
     321              : ! **************************************************************************************************
     322              : !> \brief ...
     323              : !> \param section ...
     324              : ! **************************************************************************************************
     325        10356 :    SUBROUTINE create_ramp_env_section(section)
     326              :       TYPE(section_type), POINTER                        :: section
     327              : 
     328              :       TYPE(keyword_type), POINTER                        :: keyword
     329              : 
     330        10356 :       CPASSERT(.NOT. ASSOCIATED(section))
     331              :       CALL section_create(section, __LOCATION__, name="RAMP_ENV", &
     332              :                           description="Parameters for an trapeziodal envelop ", &
     333        10356 :                           n_keywords=6, n_subsections=1, repeats=.TRUE.)
     334              : 
     335        10356 :       NULLIFY (keyword)
     336              : 
     337              :       CALL keyword_create(keyword, __LOCATION__, name="START_STEP_IN", &
     338              :                           description="Step when the electric field starts to be applied ", &
     339              :                           usage="START_STEP_IN 0", &
     340        10356 :                           default_i_val=0)
     341        10356 :       CALL section_add_keyword(section, keyword)
     342        10356 :       CALL keyword_release(keyword)
     343              : 
     344              :       CALL keyword_create(keyword, __LOCATION__, name="END_STEP_IN", &
     345              :                           description="Step when the field reaches the full strength", &
     346              :                           usage="END_STEP_IN 2", &
     347        10356 :                           default_i_val=-1)
     348        10356 :       CALL section_add_keyword(section, keyword)
     349        10356 :       CALL keyword_release(keyword)
     350              : 
     351              :       CALL keyword_create(keyword, __LOCATION__, name="START_STEP_OUT", &
     352              :                           description="Step when the field starts to vanish ", &
     353              :                           usage="START_STEP_OUT 0", &
     354        10356 :                           default_i_val=0)
     355        10356 :       CALL section_add_keyword(section, keyword)
     356        10356 :       CALL keyword_release(keyword)
     357              : 
     358              :       CALL keyword_create(keyword, __LOCATION__, name="END_STEP_OUT", &
     359              :                           description="Step when the field disappears", &
     360              :                           usage="END_STEP_OUT 2", &
     361        10356 :                           default_i_val=-1)
     362        10356 :       CALL section_add_keyword(section, keyword)
     363        10356 :       CALL keyword_release(keyword)
     364              : 
     365        10356 :    END SUBROUTINE create_ramp_env_section
     366              : 
     367              : ! **************************************************************************************************
     368              : !> \brief ...
     369              : !> \param section ...
     370              : ! **************************************************************************************************
     371        10356 :    SUBROUTINE create_custom_env_section(section)
     372              :       TYPE(section_type), POINTER                        :: section
     373              : 
     374              :       TYPE(keyword_type), POINTER                        :: keyword
     375              : 
     376        10356 :       CPASSERT(.NOT. ASSOCIATED(section))
     377              :       CALL section_create(section, __LOCATION__, name="CUSTOM_ENV", &
     378              :                           description="Parameters for a custom efield", &
     379        10356 :                           n_keywords=2, n_subsections=1, repeats=.TRUE.)
     380              : 
     381        10356 :       NULLIFY (keyword)
     382              : 
     383              :       CALL keyword_create(keyword, __LOCATION__, name="EFIELD_FILE_NAME", &
     384              :                           description="Specify file that contains the electric field [V/m].", &
     385              :                           usage="EFIELD_FILE_NAME filename", &
     386        10356 :                           n_var=1, type_of_var=char_t, default_c_val="")
     387        10356 :       CALL section_add_keyword(section, keyword)
     388        10356 :       CALL keyword_release(keyword)
     389              : 
     390              :       CALL keyword_create(keyword, __LOCATION__, name="TIMESTEP", &
     391              :                           description="The time step between the entries in the list with the electric field.", &
     392              :                           usage="TIMESTEP 1", &
     393              :                           unit_str="fs", &
     394        10356 :                           default_r_val=1.0_dp)
     395        10356 :       CALL section_add_keyword(section, keyword)
     396        10356 :       CALL keyword_release(keyword)
     397              : 
     398        10356 :    END SUBROUTINE create_custom_env_section
     399              : 
     400              : END MODULE input_cp2k_field
        

Generated by: LCOV version 2.0-1