Coverage Report

Created: 2025-12-08 06:13

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/quantlib/ql/methods/finitedifferences/schemes/cranknicolsonscheme.cpp
Line
Count
Source
1
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3
/*
4
 Copyright (C) 2019 Klaus Spanderen
5
6
 This file is part of QuantLib, a free-software/open-source library
7
 for financial quantitative analysts and developers - http://quantlib.org/
8
9
 QuantLib is free software: you can redistribute it and/or modify it
10
 under the terms of the QuantLib license.  You should have received a
11
 copy of the license along with this program; if not, please email
12
 <quantlib-dev@lists.sf.net>. The license is also available online at
13
 <https://www.quantlib.org/license.shtml>.
14
15
 This program is distributed in the hope that it will be useful, but WITHOUT
16
 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17
 FOR A PARTICULAR PURPOSE.  See the license for more details.
18
*/
19
20
#include <ql/methods/finitedifferences/schemes/expliciteulerscheme.hpp>
21
#include <ql/methods/finitedifferences/schemes/cranknicolsonscheme.hpp>
22
23
namespace QuantLib {
24
    CrankNicolsonScheme::CrankNicolsonScheme(
25
        Real theta,
26
        const ext::shared_ptr<FdmLinearOpComposite> & map,
27
        const bc_set& bcSet,
28
        Real relTol,
29
        ImplicitEulerScheme::SolverType solverType)
30
0
    : dt_(Null<Real>()),
31
0
      theta_(theta),
32
0
      explicit_(ext::make_shared<ExplicitEulerScheme>(map, bcSet)),
33
0
      implicit_(ext::make_shared<ImplicitEulerScheme>(
34
0
          map, bcSet, relTol, solverType)) {
35
0
    }
36
37
0
    void CrankNicolsonScheme::step(array_type& a, Time t) {
38
0
        QL_REQUIRE(t-dt_ > -1e-8, "a step towards negative time given");
39
40
0
        if (theta_ != 1.0)
41
0
            explicit_->step(a, t, 1.0-theta_);
42
43
0
        if (theta_ != 0.0)
44
0
            implicit_->step(a, t, theta_);
45
0
    }
46
47
0
    void CrankNicolsonScheme::setStep(Time dt) {
48
0
        dt_ = dt;
49
0
        explicit_->setStep(dt_);
50
0
        implicit_->setStep(dt_);
51
0
    }
52
53
0
    Size CrankNicolsonScheme::numberOfIterations() const {
54
0
        return implicit_->numberOfIterations();
55
0
    }
56
}