QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
secondderivativeop.cpp
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
22#include <ql/methods/finitedifferences/meshers/fdmmesher.hpp>
23#include <ql/methods/finitedifferences/operators/fdmlinearoplayout.hpp>
24#include <ql/methods/finitedifferences/operators/secondderivativeop.hpp>
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 const Size co = iter.coordinates()[direction_];
43 if (co == 0 || co == mesher->layout()->dim()[direction]-1) {
44 lower_[i] = diag_[i] = upper_[i] = 0.0;
45 }
46 else {
47 lower_[i] = 2.0/zetam1;
48 diag_[i] = -2.0/zeta0;
49 upper_[i] = 2.0/zetap1;
50 }
51 }
52 }
53}
SecondDerivativeOp(Size direction, const ext::shared_ptr< FdmMesher > &mesher)
std::unique_ptr< Real[]> diag_
std::unique_ptr< Real[]> lower_
std::unique_ptr< Real[]> upper_
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