Coverage Report

Created: 2026-03-31 07:01

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/quantlib/ql/methods/finitedifferences/boundarycondition.hpp
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
/*! \file boundarycondition.hpp
21
    \brief boundary conditions for differential operators
22
*/
23
24
#ifndef quantlib_boundary_condition_hpp
25
#define quantlib_boundary_condition_hpp
26
27
#include <ql/utilities/null.hpp>
28
#include <ql/methods/finitedifferences/tridiagonaloperator.hpp>
29
30
namespace QuantLib {
31
32
    //! Abstract boundary condition class for finite difference problems
33
    /*! \ingroup findiff */
34
    template <class Operator>
35
    class BoundaryCondition {
36
      public:
37
        // types and enumerations
38
        typedef Operator operator_type;
39
        typedef typename Operator::array_type array_type;
40
        //! \todo Generalize for n-dimensional conditions
41
        enum Side { None, Upper, Lower };
42
        // destructor
43
0
        virtual ~BoundaryCondition() = default;
Unexecuted instantiation: QuantLib::BoundaryCondition<QuantLib::TridiagonalOperator>::~BoundaryCondition()
Unexecuted instantiation: QuantLib::BoundaryCondition<QuantLib::FdmLinearOp>::~BoundaryCondition()
44
        // interface
45
        /*! This method modifies an operator \f$ L \f$ before it is
46
            applied to an array \f$ u \f$ so that \f$ v = Lu \f$ will
47
            satisfy the given condition. */
48
        virtual void applyBeforeApplying(operator_type&) const = 0;
49
        /*! This method modifies an array \f$ u \f$ so that it satisfies
50
            the given condition. */
51
        virtual void applyAfterApplying(array_type&) const = 0;
52
        /*! This method modifies an operator \f$ L \f$ before the linear
53
            system \f$ Lu' = u \f$ is solved so that \f$ u' \f$ will
54
            satisfy the given condition. */
55
        virtual void applyBeforeSolving(operator_type&,
56
                                        array_type& rhs) const = 0;
57
        /*! This method modifies an array \f$ u \f$ so that it satisfies
58
            the given condition. */
59
        virtual void applyAfterSolving(array_type&) const = 0;
60
        /*! This method sets the current time for time-dependent
61
            boundary conditions. */
62
        virtual void setTime(Time t) = 0;
63
    };
64
65
66
67
    /*! \deprecated Part of the old FD framework; copy this function
68
                    in your codebase if needed.
69
                    Deprecated in version 1.42.
70
    */
71
    class [[deprecated("Part of the old FD framework; copy this function in your codebase if needed")]] NeumannBC : public BoundaryCondition<TridiagonalOperator> {
72
      public:
73
        NeumannBC(Real value, Side side);
74
        // interface
75
        void applyBeforeApplying(TridiagonalOperator&) const override;
76
        void applyAfterApplying(Array&) const override;
77
        void applyBeforeSolving(TridiagonalOperator&, Array& rhs) const override;
78
        void applyAfterSolving(Array&) const override;
79
0
        void setTime(Time) override {}
80
81
      private:
82
        Real value_;
83
        Side side_;
84
    };
85
86
    /*! \deprecated Part of the old FD framework; copy this function
87
                    in your codebase if needed.
88
                    Deprecated in version 1.42.
89
    */
90
    class [[deprecated("Part of the old FD framework; copy this function in your codebase if needed")]] DirichletBC : public BoundaryCondition<TridiagonalOperator> {
91
      public:
92
        DirichletBC(Real value, Side side);
93
        // interface
94
        void applyBeforeApplying(TridiagonalOperator&) const override;
95
        void applyAfterApplying(Array&) const override;
96
        void applyBeforeSolving(TridiagonalOperator&, Array& rhs) const override;
97
        void applyAfterSolving(Array&) const override;
98
0
        void setTime(Time) override {}
99
100
      private:
101
        Real value_;
102
        Side side_;
103
    };
104
105
}
106
107
108
#endif