QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
boundarycondition.hpp
Go to the documentation of this file.
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 <http://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>
29
30namespace QuantLib {
31
32 //! Abstract boundary condition class for finite difference problems
33 /*! \ingroup findiff */
34 template <class Operator>
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 virtual ~BoundaryCondition() = default;
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. */
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 // Time-independent boundary conditions for tridiagonal operators
66
67 //! Neumann boundary condition (i.e., constant derivative)
68 /*! \warning The value passed must not be the value of the derivative.
69 Instead, it must be comprehensive of the grid step
70 between the first two points--i.e., it must be the
71 difference between f[0] and f[1].
72 \todo generalize to time-dependent conditions.
73
74 \ingroup findiff
75 */
76 class NeumannBC : public BoundaryCondition<TridiagonalOperator> {
77 public:
78 NeumannBC(Real value, Side side);
79 // interface
80 void applyBeforeApplying(TridiagonalOperator&) const override;
81 void applyAfterApplying(Array&) const override;
82 void applyBeforeSolving(TridiagonalOperator&, Array& rhs) const override;
83 void applyAfterSolving(Array&) const override;
84 void setTime(Time) override {}
85
86 private:
89 };
90
91 //! Neumann boundary condition (i.e., constant value)
92 /*! \todo generalize to time-dependent conditions.
93
94 \ingroup findiff
95 */
96 class DirichletBC : public BoundaryCondition<TridiagonalOperator> {
97 public:
98 DirichletBC(Real value, Side side);
99 // interface
100 void applyBeforeApplying(TridiagonalOperator&) const override;
101 void applyAfterApplying(Array&) const override;
102 void applyBeforeSolving(TridiagonalOperator&, Array& rhs) const override;
103 void applyAfterSolving(Array&) const override;
104 void setTime(Time) override {}
105
106 private:
109 };
110
111}
112
113
114
115
116#endif
1-D array used in linear algebra.
Definition: array.hpp:52
Abstract boundary condition class for finite difference problems.
virtual void applyAfterSolving(array_type &) const =0
virtual void applyBeforeSolving(operator_type &, array_type &rhs) const =0
virtual void applyBeforeApplying(operator_type &) const =0
Operator::array_type array_type
virtual void applyAfterApplying(array_type &) const =0
virtual ~BoundaryCondition()=default
virtual void setTime(Time t)=0
Neumann boundary condition (i.e., constant value)
void applyAfterApplying(Array &) const override
void applyBeforeApplying(TridiagonalOperator &) const override
void applyAfterSolving(Array &) const override
void applyBeforeSolving(TridiagonalOperator &, Array &rhs) const override
void setTime(Time) override
Neumann boundary condition (i.e., constant derivative)
void applyAfterApplying(Array &) const override
void applyBeforeApplying(TridiagonalOperator &) const override
void applyAfterSolving(Array &) const override
void applyBeforeSolving(TridiagonalOperator &, Array &rhs) const override
void setTime(Time) override
Base implementation for tridiagonal operator.
const DefaultType & t
Real Time
continuous quantity with 1-year units
Definition: types.hpp:62
QL_REAL Real
real number
Definition: types.hpp:50
Definition: any.hpp:35
null values
tridiagonal operator