QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
firstderivativeop.cpp
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) 2008 Andreas Gaida
5 Copyright (C) 2008 Ralph Schreyer
6 Copyright (C) 2008 Klaus Spanderen
7
8 This file is part of QuantLib, a free-software/open-source library
9 for financial quantitative analysts and developers - http://quantlib.org/
10
11 QuantLib is free software: you can redistribute it and/or modify it
12 under the terms of the QuantLib license. You should have received a
13 copy of the license along with this program; if not, please email
14 <quantlib-dev@lists.sf.net>. The license is also available online at
15 <http://quantlib.org/license.shtml>.
16
17 This program is distributed in the hope that it will be useful, but WITHOUT
18 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 FOR A PARTICULAR PURPOSE. See the license for more details.
20*/
21
25
26namespace QuantLib {
27
29 Size direction,
30 const ext::shared_ptr<FdmMesher>& mesher)
31 : TripleBandLinearOp(direction, mesher) {
32
33 for (const auto& iter : *mesher->layout()) {
34 const Size i = iter.index();
35 const Real hm = mesher->dminus(iter, direction_);
36 const Real hp = mesher->dplus(iter, direction_);
37
38 const Real zetam1 = hm*(hm+hp);
39 const Real zeta0 = hm*hp;
40 const Real zetap1 = hp*(hm+hp);
41
42 if (iter.coordinates()[direction_] == 0) {
43 //upwinding scheme
44 lower_[i] = 0.0;
45 diag_[i] = -(upper_[i] = 1/hp);
46 }
47 else if ( iter.coordinates()[direction_]
48 == mesher->layout()->dim()[direction]-1) {
49 // downwinding scheme
50 lower_[i] = -(diag_[i] = 1/hm);
51 upper_[i] = 0.0;
52 }
53 else {
54 lower_[i] = -hp/zetam1;
55 diag_[i] = (hp-hm)/zeta0;
56 upper_[i] = hm/zetap1;
57 }
58 }
59 }
60}
61
FirstDerivativeOp(Size direction, const ext::shared_ptr< FdmMesher > &mesher)
std::unique_ptr< Real[]> diag_
std::unique_ptr< Real[]> lower_
std::unique_ptr< Real[]> upper_
memory layout of a fdm linear operator
mesher for a fdm grid
first derivative linear operator
QL_REAL Real
real number
Definition: types.hpp:50
std::size_t Size
size of a container
Definition: types.hpp:58
Definition: any.hpp:35