LCOV - code coverage report
Current view: top level - src - input_cp2k_field.F (source / functions) Hit Total Coverage
Test: CP2K Regtests (git:b4bd748) Lines: 111 111 100.0 %
Date: 2025-03-09 07:56:22 Functions: 6 6 100.0 %

          Line data    Source code
       1             : !--------------------------------------------------------------------------------------------------!
       2             : !   CP2K: A general program to perform molecular dynamics simulations                              !
       3             : !   Copyright 2000-2025 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       18308 :    SUBROUTINE create_per_efield_section(section)
      52             :       TYPE(section_type), POINTER                        :: section
      53             : 
      54             :       TYPE(keyword_type), POINTER                        :: keyword
      55             : 
      56       18308 :       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       54924 :                           n_keywords=6, n_subsections=1, repeats=.TRUE.)
      64             : 
      65       18308 :       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       18308 :                           default_r_val=0._dp)
      72       18308 :       CALL section_add_keyword(section, keyword)
      73       18308 :       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       18308 :                           type_of_var=real_t, default_r_vals=(/0.0_dp, 0.0_dp, 1.0_dp/))
      80       18308 :       CALL section_add_keyword(section, keyword)
      81       18308 :       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       36616 :                           lone_keyword_l_val=.TRUE.)
      89       18308 :       CALL section_add_keyword(section, keyword)
      90       18308 :       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       18308 :                           type_of_var=real_t, default_r_vals=(/1.0_dp, 1.0_dp, 1.0_dp/))
      97       18308 :       CALL section_add_keyword(section, keyword)
      98       18308 :       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       18308 :                           n_var=-1, type_of_var=real_t, default_r_vals=(/0.0_dp/))
     107       18308 :       CALL section_add_keyword(section, keyword)
     108       18308 :       CALL keyword_release(keyword)
     109             : 
     110             :       CALL keyword_create(keyword, __LOCATION__, name="START_FRAME", &
     111             :                           description="First frame the field is applied. "// &
     112             :                           "(0: first frame) "// &
     113             :                           "Attention: ignored for eeq", &
     114             :                           usage="START_FRAME 0", &
     115       18308 :                           default_i_val=0)
     116       18308 :       CALL section_add_keyword(section, keyword)
     117       18308 :       CALL keyword_release(keyword)
     118             : 
     119             :       CALL keyword_create(keyword, __LOCATION__, name="END_FRAME", &
     120             :                           description="Last frame the field is applied. "// &
     121             :                           "If an end frame is specified, the number of active frames "// &
     122             :                           "must be a multiple of the number of "// &
     123             :                           "the given intensity values. (-1: no end) "// &
     124             :                           "Attention: ignored for eeq", &
     125             :                           usage="END_FRAME -1", &
     126       18308 :                           default_i_val=-1)
     127       18308 :       CALL section_add_keyword(section, keyword)
     128       18308 :       CALL keyword_release(keyword)
     129             : 
     130       18308 :    END SUBROUTINE create_per_efield_section
     131             : ! **************************************************************************************************
     132             : !> \brief creates the section for time dependent nonperiodic fields
     133             : !> \param section ...
     134             : !> \author Florian Schiffmann
     135             : ! **************************************************************************************************
     136        9162 :    SUBROUTINE create_efield_section(section)
     137             :       TYPE(section_type), POINTER                        :: section
     138             : 
     139             :       TYPE(keyword_type), POINTER                        :: keyword
     140             :       TYPE(section_type), POINTER                        :: subsection
     141             : 
     142        9162 :       CPASSERT(.NOT. ASSOCIATED(section))
     143             :       CALL section_create(section, __LOCATION__, name="EFIELD", &
     144             :                           description="Parameters for finite, time  dependent electric fields. "// &
     145             :                           "For time dependent  propagation in periodic systems, set "// &
     146             :                           "DFT%REAL_TIME_PROPAGATION%VELOCITY_GAUGE to true. "// &
     147             :                           "For static fields use EXTERNAL_POTENTIAL.", &
     148        9162 :                           n_keywords=6, n_subsections=1, repeats=.TRUE.)
     149             : 
     150        9162 :       NULLIFY (keyword, subsection)
     151             : 
     152             :       CALL keyword_create(keyword, __LOCATION__, name="INTENSITY", &
     153             :                           description="Intensity of the electric field. For real-time propagation (RTP) units are "// &
     154             :                           "in W*cm-2 which corresponds "// &
     155             :                           "to a maximal amplitude in a.u. of sqrt(I/(3.50944*10^16)). "// &
     156             :                           "For a constant local field in isolated system calclulations, units are in a.u..", &
     157             :                           usage="INTENSITY  0.001", &
     158        9162 :                           default_r_val=0._dp)
     159        9162 :       CALL section_add_keyword(section, keyword)
     160        9162 :       CALL keyword_release(keyword)
     161             : 
     162             :       CALL keyword_create(keyword, __LOCATION__, name="POLARISATION", &
     163             :                           description="Polarisation vector of electric field", &
     164             :                           usage="POLARISATION  0.0 0.0 1.0", &
     165             :                           repeats=.FALSE., n_var=3, &
     166        9162 :                           type_of_var=real_t, default_r_vals=(/0.0_dp, 0.0_dp, 1.0_dp/))
     167        9162 :       CALL section_add_keyword(section, keyword)
     168        9162 :       CALL keyword_release(keyword)
     169             : 
     170             :       CALL keyword_create(keyword, __LOCATION__, name="WAVELENGTH", &
     171             :                           description="Wavelength of efield field for real-time propagation (RTP) calculations.", &
     172             :                           usage="Wavelength  1.E0", &
     173        9162 :                           default_r_val=0._dp, unit_str="nm")
     174        9162 :       CALL section_add_keyword(section, keyword)
     175        9162 :       CALL keyword_release(keyword)
     176             : 
     177             :       CALL keyword_create(keyword, __LOCATION__, name="PHASE", &
     178             :                           description="Phase offset of the cosine given in multiples of pi. "// &
     179             :                           "Used in real-time propagation (RTP) calculations.", &
     180             :                           usage="Phase  1.E0", &
     181        9162 :                           default_r_val=0._dp)
     182        9162 :       CALL section_add_keyword(section, keyword)
     183        9162 :       CALL keyword_release(keyword)
     184             : 
     185             :       CALL keyword_create(keyword, __LOCATION__, name="ENVELOP", &
     186             :                           description="Shape of the efield pulse used in real-time propagation (RTP) calculations.", &
     187             :                           usage="ENVELOP CONSTANT", &
     188             :                           default_i_val=constant_env, &
     189             :                           enum_c_vals=s2a("CONSTANT", "GAUSSIAN", "RAMP", "CUSTOM"), &
     190             :                           enum_desc=s2a("No envelop function is applied to the strength", &
     191             :                                         "A Gaussian function is used as envelop ", &
     192             :                                         "Linear tune in/out of the field", &
     193             :                                         "A custom field read from a file"), &
     194        9162 :                           enum_i_vals=(/constant_env, gaussian_env, ramp_env, custom_env/))
     195        9162 :       CALL section_add_keyword(section, keyword)
     196        9162 :       CALL keyword_release(keyword)
     197             : 
     198             :       CALL keyword_create(keyword, __LOCATION__, name="VEC_POT_INITIAL", &
     199             :                           description="Initial value of the vector "// &
     200             :                           "potential (for velocity gauge). This input is "// &
     201             :                           "made especially for restarting RTP calculation. "// &
     202             :                           "Unit is atomic unit. "// &
     203             :                           "Note that if several field sections are defined, only the first one will be used.", &
     204             :                           usage="vec_pot_initial  1.0E-2 0.0 0.0", &
     205             :                           repeats=.FALSE., &
     206             :                           n_var=3, type_of_var=real_t, &
     207        9162 :                           default_r_vals=(/0.0_dp, 0.0_dp, 0.0_dp/))
     208        9162 :       CALL section_add_keyword(section, keyword)
     209        9162 :       CALL keyword_release(keyword)
     210             : 
     211        9162 :       CALL create_constant_env_section(subsection)
     212        9162 :       CALL section_add_subsection(section, subsection)
     213        9162 :       CALL section_release(subsection)
     214             : 
     215        9162 :       CALL create_gaussian_env_section(subsection)
     216        9162 :       CALL section_add_subsection(section, subsection)
     217        9162 :       CALL section_release(subsection)
     218             : 
     219        9162 :       CALL create_ramp_env_section(subsection)
     220        9162 :       CALL section_add_subsection(section, subsection)
     221        9162 :       CALL section_release(subsection)
     222             : 
     223        9162 :       CALL create_custom_env_section(subsection)
     224        9162 :       CALL section_add_subsection(section, subsection)
     225        9162 :       CALL section_release(subsection)
     226             : 
     227        9162 :    END SUBROUTINE create_efield_section
     228             : 
     229             : ! **************************************************************************************************
     230             : !> \brief ...
     231             : !> \param section ...
     232             : ! **************************************************************************************************
     233        9162 :    SUBROUTINE create_constant_env_section(section)
     234             :       TYPE(section_type), POINTER                        :: section
     235             : 
     236             :       TYPE(keyword_type), POINTER                        :: keyword
     237             : 
     238        9162 :       CPASSERT(.NOT. ASSOCIATED(section))
     239             :       CALL section_create(section, __LOCATION__, name="CONSTANT_ENV", &
     240             :                           description="parameters for a constant envelop", &
     241        9162 :                           n_keywords=6, n_subsections=1, repeats=.TRUE.)
     242             : 
     243        9162 :       NULLIFY (keyword)
     244             : 
     245             :       CALL keyword_create(keyword, __LOCATION__, name="START_STEP", &
     246             :                           description="First step the field is applied ", &
     247             :                           usage="START_STEP 0", &
     248        9162 :                           default_i_val=0)
     249        9162 :       CALL section_add_keyword(section, keyword)
     250        9162 :       CALL keyword_release(keyword)
     251             : 
     252             :       CALL keyword_create(keyword, __LOCATION__, name="END_STEP", &
     253             :                           description="Last step the field is applied", &
     254             :                           usage="END_STEP 2", &
     255        9162 :                           default_i_val=-1)
     256        9162 :       CALL section_add_keyword(section, keyword)
     257        9162 :       CALL keyword_release(keyword)
     258             : 
     259        9162 :    END SUBROUTINE create_constant_env_section
     260             : 
     261             : ! **************************************************************************************************
     262             : !> \brief ...
     263             : !> \param section ...
     264             : ! **************************************************************************************************
     265        9162 :    SUBROUTINE create_gaussian_env_section(section)
     266             :       TYPE(section_type), POINTER                        :: section
     267             : 
     268             :       TYPE(keyword_type), POINTER                        :: keyword
     269             : 
     270        9162 :       CPASSERT(.NOT. ASSOCIATED(section))
     271             :       CALL section_create(section, __LOCATION__, name="GAUSSIAN_ENV", &
     272             :                           description="parameters for a gaussian envelop", &
     273        9162 :                           n_keywords=6, n_subsections=1, repeats=.TRUE.)
     274             : 
     275        9162 :       NULLIFY (keyword)
     276             : 
     277             :       CALL keyword_create(keyword, __LOCATION__, name="T0", &
     278             :                           description="Center of the gaussian envelop (maximum of the gaussian)", &
     279             :                           usage="T0 2.0E0", &
     280             :                           default_r_val=0.0E0_dp, &
     281        9162 :                           unit_str="fs")
     282        9162 :       CALL section_add_keyword(section, keyword)
     283        9162 :       CALL keyword_release(keyword)
     284             : 
     285             :       CALL keyword_create(keyword, __LOCATION__, name="SIGMA", &
     286             :                           description="Width of the gaussian ", &
     287             :                           usage="SIGMA 2.0E0", &
     288             :                           default_r_val=-1.0E0_dp, &
     289        9162 :                           unit_str="fs")
     290        9162 :       CALL section_add_keyword(section, keyword)
     291        9162 :       CALL keyword_release(keyword)
     292             : 
     293        9162 :    END SUBROUTINE create_gaussian_env_section
     294             : 
     295             : ! **************************************************************************************************
     296             : !> \brief ...
     297             : !> \param section ...
     298             : ! **************************************************************************************************
     299        9162 :    SUBROUTINE create_ramp_env_section(section)
     300             :       TYPE(section_type), POINTER                        :: section
     301             : 
     302             :       TYPE(keyword_type), POINTER                        :: keyword
     303             : 
     304        9162 :       CPASSERT(.NOT. ASSOCIATED(section))
     305             :       CALL section_create(section, __LOCATION__, name="RAMP_ENV", &
     306             :                           description="Parameters for an trapeziodal envelop ", &
     307        9162 :                           n_keywords=6, n_subsections=1, repeats=.TRUE.)
     308             : 
     309        9162 :       NULLIFY (keyword)
     310             : 
     311             :       CALL keyword_create(keyword, __LOCATION__, name="START_STEP_IN", &
     312             :                           description="Step when the electric field starts to be applied ", &
     313             :                           usage="START_STEP_IN 0", &
     314        9162 :                           default_i_val=0)
     315        9162 :       CALL section_add_keyword(section, keyword)
     316        9162 :       CALL keyword_release(keyword)
     317             : 
     318             :       CALL keyword_create(keyword, __LOCATION__, name="END_STEP_IN", &
     319             :                           description="Step when the field reaches the full strength", &
     320             :                           usage="END_STEP_IN 2", &
     321        9162 :                           default_i_val=-1)
     322        9162 :       CALL section_add_keyword(section, keyword)
     323        9162 :       CALL keyword_release(keyword)
     324             : 
     325             :       CALL keyword_create(keyword, __LOCATION__, name="START_STEP_OUT", &
     326             :                           description="Step when the field starts to vanish ", &
     327             :                           usage="START_STEP_OUT 0", &
     328        9162 :                           default_i_val=0)
     329        9162 :       CALL section_add_keyword(section, keyword)
     330        9162 :       CALL keyword_release(keyword)
     331             : 
     332             :       CALL keyword_create(keyword, __LOCATION__, name="END_STEP_OUT", &
     333             :                           description="Step when the field disappears", &
     334             :                           usage="END_STEP_OUT 2", &
     335        9162 :                           default_i_val=-1)
     336        9162 :       CALL section_add_keyword(section, keyword)
     337        9162 :       CALL keyword_release(keyword)
     338             : 
     339        9162 :    END SUBROUTINE create_ramp_env_section
     340             : 
     341             : ! **************************************************************************************************
     342             : !> \brief ...
     343             : !> \param section ...
     344             : ! **************************************************************************************************
     345        9162 :    SUBROUTINE create_custom_env_section(section)
     346             :       TYPE(section_type), POINTER                        :: section
     347             : 
     348             :       TYPE(keyword_type), POINTER                        :: keyword
     349             : 
     350        9162 :       CPASSERT(.NOT. ASSOCIATED(section))
     351             :       CALL section_create(section, __LOCATION__, name="CUSTOM_ENV", &
     352             :                           description="Parameters for a custom efield", &
     353        9162 :                           n_keywords=2, n_subsections=1, repeats=.TRUE.)
     354             : 
     355        9162 :       NULLIFY (keyword)
     356             : 
     357             :       CALL keyword_create(keyword, __LOCATION__, name="EFIELD_FILE_NAME", &
     358             :                           description="Specify file that contains the electric field [V/m].", &
     359             :                           usage="EFIELD_FILE_NAME filename", &
     360        9162 :                           n_var=1, type_of_var=char_t, default_c_val="")
     361        9162 :       CALL section_add_keyword(section, keyword)
     362        9162 :       CALL keyword_release(keyword)
     363             : 
     364             :       CALL keyword_create(keyword, __LOCATION__, name="TIMESTEP", &
     365             :                           description="The time step between the entries in the list with the electric field.", &
     366             :                           usage="TIMESTEP 1", &
     367             :                           unit_str="fs", &
     368        9162 :                           default_r_val=1.0_dp)
     369        9162 :       CALL section_add_keyword(section, keyword)
     370        9162 :       CALL keyword_release(keyword)
     371             : 
     372        9162 :    END SUBROUTINE create_custom_env_section
     373             : 
     374             : END MODULE input_cp2k_field

Generated by: LCOV version 1.15