From f1983adb487bb531c1c68226596b26eebf99876a Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Wed, 6 Oct 2010 21:50:48 -0400 Subject: Add Heun-Euler adaptive method. --- src/vZ/HE12.hpp | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 src/vZ/HE12.hpp (limited to 'src/vZ/HE12.hpp') diff --git a/src/vZ/HE12.hpp b/src/vZ/HE12.hpp new file mode 100644 index 0000000..0f7a299 --- /dev/null +++ b/src/vZ/HE12.hpp @@ -0,0 +1,107 @@ +/************************************************************************* + * Copyright (C) 2009-2010 Tavian Barnes * + * * + * This file is part of The vZ Library. * + * * + * The vZ Library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public License as * + * published by the Free Software Foundation; either version 3 of the * + * License, or (at your option) any later version. * + * * + * The vZ Library 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 * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this program. If not, see * + * . * + *************************************************************************/ + +#ifndef VZ_HE12_HPP +#define VZ_HE12_HPP + +namespace vZ +{ + // Heun-Euler method + // + // Second-order with embedded first-order + // Its tableau is: + // + // 0 | + // 1 | 1 + // --+--------- + // | 1/2 1/2 + // | 1 0 + // + // k1 = dt*f(y[n]) + // k2 = dt*f(y[n] + dt*k1) + // y[n + 1] = y[n] + 1/2*(k1 + k2) + template + class GenericHE12Integrator : public GenericAdaptiveIntegrator + { + public: + typedef typename GenericAdaptiveIntegrator::Scalar Scalar; + typedef typename GenericAdaptiveIntegrator::Function Function; + + GenericHE12Integrator(Function f) + : GenericAdaptiveIntegrator(f, 2, s_a, s_b, s_bStar) { } + ~GenericHE12Integrator() { } + + private: + typedef typename GenericAdaptiveIntegrator::ACoefficients ACoefficients; + typedef typename GenericAdaptiveIntegrator::BCoefficients BCoefficients; + + static ACoefficients s_a; + static BCoefficients s_b; + static BCoefficients s_bStar; + + static Scalar s_a2Arr[1]; + static std::vector s_aArr[1]; + static Scalar s_bArr[2]; + static Scalar s_bStarArr[2]; + }; + + // Type alias + typedef GenericHE12Integrator HE12Integrator; + + // Implementation + + template + typename GenericHE12Integrator::Scalar + GenericHE12Integrator::s_a2Arr[1] = { + Scalar(1) + }; + + template + std::vector::Scalar> + GenericHE12Integrator::s_aArr[1] = { + std::vector(s_a2Arr, s_a2Arr + 1) + }; + + template + typename GenericHE12Integrator::ACoefficients + GenericHE12Integrator::s_a(s_aArr, s_aArr + 1); + + template + typename GenericHE12Integrator::Scalar + GenericHE12Integrator::s_bArr[2] = { + Scalar(1)/Scalar(2), Scalar(1)/Scalar(2) + }; + + template + typename GenericHE12Integrator::BCoefficients + GenericHE12Integrator::s_b(s_bArr, s_bArr + 2); + + template + typename GenericHE12Integrator::Scalar + GenericHE12Integrator::s_bStarArr[2] = { + Scalar(1), Scalar(0) + }; + + template + typename GenericHE12Integrator::BCoefficients + GenericHE12Integrator::s_bStar(s_bStarArr, s_bStarArr + 2); +} + +#endif // VZ_HE12_HPP -- cgit v1.2.3