QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
glued1dmesher.cpp
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 <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
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
29namespace QuantLib {
30
32 const Fdm1dMesher& leftMesher,
33 const Fdm1dMesher& rightMesher)
34 : Fdm1dMesher(leftMesher.locations().size()+rightMesher.locations().size()
35 - ( close(leftMesher.locations().back(),
36 rightMesher.locations().front()) ? 1 :0) ),
37 commonPoint_( close(leftMesher.locations().back(),
38 rightMesher.locations().front()) ) {
39
40 QL_REQUIRE(leftMesher.locations().back()
41 <= rightMesher.locations().front(),
42 "left meshers rightmost point (" <<
43 leftMesher.locations().back() <<
44 ") may not be greater than right meshers leftmost point (" <<
45 rightMesher.locations().front() << ")");
46
47 std::copy(leftMesher.locations().begin(),leftMesher.locations().end(),
48 locations_.begin());
49 std::copy(rightMesher.locations().begin() + (commonPoint_ ? 1 : 0),
50 rightMesher.locations().end(),
51 locations_.begin()+leftMesher.locations().size());
52
53 for (Size i=0; i < locations_.size()-1; ++i) {
54 dplus_[i] = dminus_[i+1] = locations_[i+1] - locations_[i];
55 }
56 dplus_.back() = dminus_.front() = Null<Real>();
57 }
58}
std::vector< Real > locations_
Definition: fdm1dmesher.hpp:47
const std::vector< Real > & locations() const
Definition: fdm1dmesher.hpp:44
std::vector< Real > dplus_
Definition: fdm1dmesher.hpp:48
std::vector< Real > dminus_
Definition: fdm1dmesher.hpp:48
Glued1dMesher(const Fdm1dMesher &leftMesher, const Fdm1dMesher &rightMesher)
template class providing a null value for a given type.
Definition: null.hpp:76
std::size_t Size
size of a container
Definition: types.hpp:58
Definition: any.hpp:35
bool close(const Quantity &m1, const Quantity &m2, Size n)
Definition: quantity.cpp:163