## [dd20b8]: include / propagator / OdePropagator.hpp  Maximize  Restore  History

### 109 lines (95 with data), 4.1 kB

  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 /* * Copyright (C) 2013-2014 Ulf Lorenz * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Library General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see . */ #ifndef PROPAGATOR_ODEPROPAGATOR_HPP #define PROPAGATOR_ODEPROPAGATOR_HPP #include #include #include #include #include namespace wavepacket { /** Template class for the various standard ODE solvers. * * The differential equation to solve is the Schroedinger equation * * \f[ * \dot \psi(t) = -i \hat H(t) \psi(t) * \f] * * or an analogous Liouville equation (note that most of the high-level operators * (SchroedingerOperator etc.) implicitly add the (-i)-term). * * If the wave function is represented by the value at its grid points (or * equivalently by the expansion coefficients when expanding in a basis), then * this equation turns into a set of ordinary differential equations (ODEs) coupled * by the matrix H. These can then be solved using common ODE solvers. * * Do *not* use this template class directly, it only combines the code for * all ODE-based propagators, but has the actual type of the algorithm as a * template parameter. Instead, use one of the typedefs: * * - OdePropagator_RK54 for the 4-th order CashKarp algorithm * - OdePropagator_RK5 for the 5-th order Dopri algorithm * - OdePropagator_RK78 for the seventh-order Fehlberg algorithm * - OdePropagator_BS for the Bulirsch-Stoer algorithm. * * All propagators implement error control, so you do not have to worry about * step sizes. * * Implementation detail: The template parameter for this function is a factory * structure, which also knows the type to return, see ControlledFactory and * SimpleFactory below. * * \ingroup propagator */ template class OdePropagator : public Propagator { public: /** Creates a new propagator. * * @param hamilt the Hamiltonian/Liouvillian to use. * @param relError the relative error to tolerate per elementary step * @param absError the absolute error to tolerate per elementary step * * @throws std::invalid_argument if the Hamiltonian is an invalid pointer or * an error is negative. */ explicit OdePropagator(const std::shared_ptr& hamilt, double relError=1e-6, double absError=1e-10); CTensor propagate(const CTensor& state, double t0, double t1) override; private: Factory factory; std::shared_ptr hamiltonian; typename Factory::controlled_type solver; }; // definition of the individual propagators // note: ode_private.hpp contains the internal definitions. typedef OdePropagator> OdePropagator_BS; typedef OdePropagator> OdePropagator_RK54; typedef OdePropagator> OdePropagator_RK5; typedef OdePropagator> OdePropagator_RK78; // define a single template instantiation extern template class OdePropagator>; extern template class OdePropagator>; extern template class OdePropagator>; extern template class OdePropagator>; } // namespace wavepacket #endif /* PROPAGATOR_ODEPROPAGATOR_HPP */