/src/quantlib/ql/experimental/finitedifferences/glued1dmesher.cpp
Line | Count | Source |
1 | | /* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | |
3 | | /* |
4 | | Copyright (C) 2012 Peter Caspers |
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 | | <https://www.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 glued1dmesher.cpp |
21 | | \brief One-dimensional grid mesher combining two existing ones |
22 | | */ |
23 | | |
24 | | #include <ql/experimental/finitedifferences/glued1dmesher.hpp> |
25 | | #include <ql/errors.hpp> |
26 | | #include <ql/math/comparison.hpp> |
27 | | #include <ql/utilities/null.hpp> |
28 | | |
29 | | namespace QuantLib { |
30 | | |
31 | | Glued1dMesher::Glued1dMesher( |
32 | | const Fdm1dMesher& leftMesher, |
33 | | const Fdm1dMesher& rightMesher) |
34 | 0 | : Fdm1dMesher(leftMesher.locations().size()+rightMesher.locations().size() |
35 | 0 | - ( close(leftMesher.locations().back(), |
36 | 0 | rightMesher.locations().front()) ? 1 :0) ), |
37 | 0 | commonPoint_( close(leftMesher.locations().back(), |
38 | 0 | rightMesher.locations().front()) ) { |
39 | |
|
40 | 0 | QL_REQUIRE(leftMesher.locations().back() |
41 | 0 | <= rightMesher.locations().front(), |
42 | 0 | "left meshers rightmost point (" << |
43 | 0 | leftMesher.locations().back() << |
44 | 0 | ") may not be greater than right meshers leftmost point (" << |
45 | 0 | rightMesher.locations().front() << ")"); |
46 | | |
47 | 0 | std::copy(leftMesher.locations().begin(),leftMesher.locations().end(), |
48 | 0 | locations_.begin()); |
49 | 0 | std::copy(rightMesher.locations().begin() + (commonPoint_ ? 1 : 0), |
50 | 0 | rightMesher.locations().end(), |
51 | 0 | locations_.begin()+leftMesher.locations().size()); |
52 | |
|
53 | 0 | for (Size i=0; i < locations_.size()-1; ++i) { |
54 | 0 | dplus_[i] = dminus_[i+1] = locations_[i+1] - locations_[i]; |
55 | 0 | } |
56 | 0 | dplus_.back() = dminus_.front() = Null<Real>(); |
57 | 0 | } |
58 | | } |