Coverage Report

Created: 2026-06-08 06:47

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/quantlib/ql/methods/finitedifferences/boundarycondition.cpp
Line
Count
Source
1
/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3
/*
4
 Copyright (C) 2000, 2001, 2002, 2003 RiskMap srl
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/boundarycondition.hpp>
21
22
namespace QuantLib {
23
24
    QL_DEPRECATED_DISABLE_WARNING
25
26
    NeumannBC::NeumannBC(Real value, NeumannBC::Side side)
27
0
    : value_(value), side_(side) {}
28
29
0
    void NeumannBC::applyBeforeApplying(TridiagonalOperator& L) const {
30
0
        switch (side_) {
31
0
          case Lower:
32
0
            L.setFirstRow(-1.0,1.0);
33
0
            break;
34
0
          case Upper:
35
0
            L.setLastRow(-1.0,1.0);
36
0
            break;
37
0
          default:
38
0
            QL_FAIL("unknown side for Neumann boundary condition");
39
0
        }
40
0
    }
41
42
0
    void NeumannBC::applyAfterApplying(Array& u) const {
43
0
        switch (side_) {
44
0
          case Lower:
45
0
            u[0] = u[1] - value_;
46
0
            break;
47
0
          case Upper:
48
0
            u[u.size()-1] = u[u.size()-2] + value_;
49
0
            break;
50
0
          default:
51
0
            QL_FAIL("unknown side for Neumann boundary condition");
52
0
        }
53
0
    }
54
55
    void NeumannBC::applyBeforeSolving(TridiagonalOperator& L,
56
0
                                       Array& rhs) const {
57
0
        switch (side_) {
58
0
          case Lower:
59
0
            L.setFirstRow(-1.0,1.0);
60
0
            rhs[0] = value_;
61
0
            break;
62
0
          case Upper:
63
0
            L.setLastRow(-1.0,1.0);
64
0
            rhs[rhs.size()-1] = value_;
65
0
            break;
66
0
          default:
67
0
            QL_FAIL("unknown side for Neumann boundary condition");
68
0
        }
69
0
    }
70
71
0
    void NeumannBC::applyAfterSolving(Array&) const {}
72
73
74
75
    DirichletBC::DirichletBC(Real value, DirichletBC::Side side)
76
0
    : value_(value), side_(side) {}
77
78
0
    void DirichletBC::applyBeforeApplying(TridiagonalOperator& L) const {
79
0
        switch (side_) {
80
0
          case Lower:
81
0
            L.setFirstRow(1.0,0.0);
82
0
            break;
83
0
          case Upper:
84
0
            L.setLastRow(0.0,1.0);
85
0
            break;
86
0
          default:
87
0
            QL_FAIL("unknown side for Neumann boundary condition");
88
0
        }
89
0
    }
90
91
0
    void DirichletBC::applyAfterApplying(Array& u) const {
92
0
        switch (side_) {
93
0
          case Lower:
94
0
            u[0] = value_;
95
0
            break;
96
0
          case Upper:
97
0
            u[u.size()-1] = value_;
98
0
            break;
99
0
          default:
100
0
            QL_FAIL("unknown side for Neumann boundary condition");
101
0
        }
102
0
    }
103
104
    void DirichletBC::applyBeforeSolving(TridiagonalOperator& L,
105
0
                                         Array& rhs) const {
106
0
        switch (side_) {
107
0
          case Lower:
108
0
            L.setFirstRow(1.0,0.0);
109
0
            rhs[0] = value_;
110
0
            break;
111
0
          case Upper:
112
0
            L.setLastRow(0.0,1.0);
113
0
            rhs[rhs.size()-1] = value_;
114
0
            break;
115
0
          default:
116
0
            QL_FAIL("unknown side for Neumann boundary condition");
117
0
        }
118
0
    }
119
120
0
    void DirichletBC::applyAfterSolving(Array&) const {}
121
122
    QL_DEPRECATED_ENABLE_WARNING
123
124
}