Skip to content

dftd4_load_rational_damping third arg uneffective #333

@JiashuLiang

Description

@JiashuLiang

I found that for dftd4_load_rational_damping function, if the third argument (mdb in C, atm in Fortran) is false, s9 will still be set to 1.0. Could you help check whether this is a bug?

Traceback

  1. C-API Layer (include/dftd4.h):
    The function signature is dftd4_load_rational_damping(..., bool mdb).

  2. Fortran API Layer (src/dftd4/api.f90):
    The C function calls load_rational_damping_api.

    function load_rational_damping_api(verror, charptr, atm)
       ...
       logical(c_bool), value, intent(in) :: atm
       real(wp), allocatable :: s9
       ...
       if (atm) s9 = 1.0_wp
       call get_rational_damping(method, tmp, s9)

    If atm (the third argument) is false, the variable s9 remains unallocated.

  3. Parameter Retrieval (src/dftd4/param.f90):
    The get_rational_damping interface calls get_rational_damping_name, which calls get_rational_damping_id.
    Since s9 was unallocated in the caller, it is treated as not present in the optional arguments chain.

    In get_rational_damping_id:

    mbd = .true.
    if (present(s9)) mbd = abs(s9) > epsilon(s9)

    Because s9 is not present, mbd defaults to .true.. This triggers the call to get_d4eeq_bjatm_parameter.

  4. Default Value Assignment:
    Inside get_d4eeq_bjatm_parameter, the helper function dftd_param is called without s9.

    pure function dftd_param(..., s9)
       ...
       s9_ = 1.0_wp
       if (present(s9)) s9_ = s9

    Since s9 is missing, it defaults to 1.0.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions