SIRIUS 7.5.0
Electronic structure library and applications
call_nlcg.hpp
Go to the documentation of this file.
1// Copyright (c) 2023 Simon Pintarelli, Anton Kozhevnikov, Thomas Schulthess
2// All rights reserved.
3//
4// Redistribution and use in source and binary forms, with or without modification, are permitted provided that
5// the following conditions are met:
6//
7// 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the
8// following disclaimer.
9// 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions
10// and the following disclaimer in the documentation and/or other materials provided with the distribution.
11//
12// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
13// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
14// PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
15// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
16// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
17// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
18// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
19
20/** \file call_nlcg.hpp
21 *
22 * \brief Wrapper to invoke nlcglib direct minimization.
23 */
24
25#ifndef __CALL_NLCG_HPP__
26#define __CALL_NLCG_HPP__
27
28// #include "context/config.hpp"
30#include "nlcglib/adaptor.hpp"
32#include "nlcglib/overlap.hpp"
33#include "nlcglib/nlcglib.hpp"
35
36namespace sirius {
37
38inline void
39call_nlcg(Simulation_context& ctx, config_t::nlcg_t const& nlcg_params, Energy& energy, K_point_set& kset,
40 Potential& potential)
41{
42 using numeric_t = std::complex<double>;
43
44 double temp = nlcg_params.T();
45 double tol = nlcg_params.tol();
46 double kappa = nlcg_params.kappa();
47 double tau = nlcg_params.tau();
48 int maxiter = nlcg_params.maxiter();
49 int restart = nlcg_params.restart();
50 auto nlcg_pu = ctx.processing_unit();
51 if(nlcg_params.processing_unit() != "") {
52 nlcg_pu = sddk::get_device_t(nlcg_params.processing_unit());
53 }
54
55 std::string smear = ctx.cfg().parameters().smearing();
56
57 nlcglib::smearing_type smearing;
58 if (smear.compare("fermi_dirac") == 0) {
59 smearing = nlcglib::smearing_type::FERMI_DIRAC;
60 } else if (smear.compare("gaussian_spline") == 0) {
61 smearing = nlcglib::smearing_type::GAUSSIAN_SPLINE;
62 } else if (smear.compare("gaussian") == 0) {
63 smearing = nlcglib::smearing_type::GAUSS;
64 } else if (smear.compare("methfessel_paxton") == 0) {
65 smearing = nlcglib::smearing_type::METHFESSEL_PAXTON;
66 } else if (smear.compare("cold") == 0) {
67 smearing = nlcglib::smearing_type::COLD;
68 } else {
69 RTE_THROW("invalid smearing type given");
70 }
71
72 Hamiltonian0<double> H0(potential, false /* precompute laplw */);
73
74 sirius::UltrasoftPrecond us_precond(kset, ctx, H0.Q());
75 sirius::Overlap_operators<sirius::S_k<numeric_t>> S(kset, ctx, H0.Q());
76
77 // ultrasoft pp
78 switch (nlcg_pu) {
79 case sddk::device_t::CPU: {
80 nlcglib::nlcg_us_cpu(energy, us_precond, S, smearing, temp, tol, kappa, tau, maxiter, restart);
81 break;
82 }
83 case sddk::device_t::GPU: {
84 nlcglib::nlcg_us_device(energy, us_precond, S, smearing, temp, tol, kappa, tau, maxiter, restart);
85 break;
86 }
87 }
88}
89
90} // namespace sirius
91
92#endif /* __CALL_NLCG_HPP__ */
Contains defintion of nlcglib interface.
Contains declaration and definition of sirius::Hamiltonian class.
Namespace of the SIRIUS library.
Definition: sirius.f90:5
Contains definition and implementation of Simulation_context class.
Provides preconditioner for ultrasoft case.