QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
boundarycondition.cpp
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#include <ql/methods/finitedifferences/boundarycondition.hpp>
21
22namespace QuantLib {
23
25 : value_(value), side_(side) {}
26
28 switch (side_) {
29 case Lower:
30 L.setFirstRow(-1.0,1.0);
31 break;
32 case Upper:
33 L.setLastRow(-1.0,1.0);
34 break;
35 default:
36 QL_FAIL("unknown side for Neumann boundary condition");
37 }
38 }
39
41 switch (side_) {
42 case Lower:
43 u[0] = u[1] - value_;
44 break;
45 case Upper:
46 u[u.size()-1] = u[u.size()-2] + value_;
47 break;
48 default:
49 QL_FAIL("unknown side for Neumann boundary condition");
50 }
51 }
52
54 Array& rhs) const {
55 switch (side_) {
56 case Lower:
57 L.setFirstRow(-1.0,1.0);
58 rhs[0] = value_;
59 break;
60 case Upper:
61 L.setLastRow(-1.0,1.0);
62 rhs[rhs.size()-1] = value_;
63 break;
64 default:
65 QL_FAIL("unknown side for Neumann boundary condition");
66 }
67 }
68
70
71
72
74 : value_(value), side_(side) {}
75
77 switch (side_) {
78 case Lower:
79 L.setFirstRow(1.0,0.0);
80 break;
81 case Upper:
82 L.setLastRow(0.0,1.0);
83 break;
84 default:
85 QL_FAIL("unknown side for Neumann boundary condition");
86 }
87 }
88
90 switch (side_) {
91 case Lower:
92 u[0] = value_;
93 break;
94 case Upper:
95 u[u.size()-1] = value_;
96 break;
97 default:
98 QL_FAIL("unknown side for Neumann boundary condition");
99 }
100 }
101
103 Array& rhs) const {
104 switch (side_) {
105 case Lower:
106 L.setFirstRow(1.0,0.0);
107 rhs[0] = value_;
108 break;
109 case Upper:
110 L.setLastRow(0.0,1.0);
111 rhs[rhs.size()-1] = value_;
112 break;
113 default:
114 QL_FAIL("unknown side for Neumann boundary condition");
115 }
116 }
117
119
120}
1-D array used in linear algebra.
Definition: array.hpp:52
Size size() const
dimension of the array
Definition: array.hpp:495
void applyAfterApplying(Array &) const override
DirichletBC(Real value, Side side)
void applyBeforeApplying(TridiagonalOperator &) const override
void applyAfterSolving(Array &) const override
void applyBeforeSolving(TridiagonalOperator &, Array &rhs) const override
void applyAfterApplying(Array &) const override
void applyBeforeApplying(TridiagonalOperator &) const override
void applyAfterSolving(Array &) const override
void applyBeforeSolving(TridiagonalOperator &, Array &rhs) const override
NeumannBC(Real value, Side side)
Base implementation for tridiagonal operator.
QL_REAL Real
real number
Definition: types.hpp:50
Definition: any.hpp:35