/src/quantlib/ql/methods/finitedifferences/operators/triplebandlinearop.hpp
Line | Count | Source (jump to first uncovered line) |
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 | | Copyright (C) 2014 Johannes Göttker-Schnetmann |
8 | | |
9 | | This file is part of QuantLib, a free-software/open-source library |
10 | | for financial quantitative analysts and developers - http://quantlib.org/ |
11 | | |
12 | | QuantLib is free software: you can redistribute it and/or modify it |
13 | | under the terms of the QuantLib license. You should have received a |
14 | | copy of the license along with this program; if not, please email |
15 | | <quantlib-dev@lists.sf.net>. The license is also available online at |
16 | | <http://quantlib.org/license.shtml>. |
17 | | |
18 | | This program is distributed in the hope that it will be useful, but WITHOUT |
19 | | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
20 | | FOR A PARTICULAR PURPOSE. See the license for more details. |
21 | | */ |
22 | | |
23 | | /*! \file triplebandlinearop.hpp |
24 | | \brief general triple band linear operator |
25 | | */ |
26 | | |
27 | | #ifndef quantlib_triple_band_linear_op_hpp |
28 | | #define quantlib_triple_band_linear_op_hpp |
29 | | |
30 | | #include <ql/methods/finitedifferences/operators/fdmlinearop.hpp> |
31 | | #include <memory> |
32 | | |
33 | | namespace QuantLib { |
34 | | |
35 | | class FdmMesher; |
36 | | |
37 | | class TripleBandLinearOp : public FdmLinearOp { |
38 | | public: |
39 | | TripleBandLinearOp(Size direction, |
40 | | const ext::shared_ptr<FdmMesher>& mesher); |
41 | | |
42 | | TripleBandLinearOp(const TripleBandLinearOp& m); |
43 | | TripleBandLinearOp(TripleBandLinearOp&& m) noexcept; |
44 | | TripleBandLinearOp& operator=(const TripleBandLinearOp& m); |
45 | | TripleBandLinearOp& operator=(TripleBandLinearOp&& m) noexcept; |
46 | 0 | ~TripleBandLinearOp() override = default; |
47 | | |
48 | | Array apply(const Array& r) const override; |
49 | | Array solve_splitting(const Array& r, Real a, Real b = 1.0) const; |
50 | | |
51 | | TripleBandLinearOp mult(const Array& u) const; |
52 | | // interpret u as the diagonal of a diagonal matrix, multiplied on LHS |
53 | | TripleBandLinearOp multR(const Array& u) const; |
54 | | // interpret u as the diagonal of a diagonal matrix, multiplied on RHS |
55 | | TripleBandLinearOp add(const TripleBandLinearOp& m) const; |
56 | | TripleBandLinearOp add(const Array& u) const; |
57 | | |
58 | | // some very basic linear algebra routines |
59 | | void axpyb(const Array& a, const TripleBandLinearOp& x, |
60 | | const TripleBandLinearOp& y, const Array& b); |
61 | | |
62 | | void swap(TripleBandLinearOp& m) noexcept; |
63 | | |
64 | | SparseMatrix toMatrix() const override; |
65 | | |
66 | | protected: |
67 | | TripleBandLinearOp() = default; |
68 | | |
69 | | Size direction_; |
70 | | std::unique_ptr<Size[]> i0_, i2_; |
71 | | std::unique_ptr<Size[]> reverseIndex_; |
72 | | std::unique_ptr<Real[]> lower_, diag_, upper_; |
73 | | |
74 | | ext::shared_ptr<FdmMesher> mesher_; |
75 | | }; |
76 | | |
77 | | |
78 | 0 | inline TripleBandLinearOp::TripleBandLinearOp(TripleBandLinearOp&& m) noexcept { |
79 | 0 | swap(m); |
80 | 0 | } |
81 | | |
82 | 0 | inline TripleBandLinearOp& TripleBandLinearOp::operator=(const TripleBandLinearOp& m) { |
83 | 0 | TripleBandLinearOp tmp(m); |
84 | 0 | swap(tmp); |
85 | 0 | return *this; |
86 | 0 | } |
87 | | |
88 | 0 | inline TripleBandLinearOp& TripleBandLinearOp::operator=(TripleBandLinearOp&& m) noexcept { |
89 | 0 | swap(m); |
90 | 0 | return *this; |
91 | 0 | } |
92 | | |
93 | | } |
94 | | |
95 | | #endif |