QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
fdmmeshercomposite.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/operators/fdmlinearoplayout.hpp>
23#include <ql/methods/finitedifferences/meshers/fdmmeshercomposite.hpp>
24
25namespace QuantLib {
26
27 namespace {
28 typedef ext::shared_ptr<Fdm1dMesher> T;
29
30 ext::shared_ptr<FdmLinearOpLayout> getLayoutFromMeshers(
31 const std::vector<ext::shared_ptr<Fdm1dMesher> > & meshers) {
32 std::vector<Size> dim(meshers.size());
33 for (Size i=0; i < dim.size(); ++i) {
34 dim[i] = meshers[i]->size();
35 }
36 return ext::make_shared<FdmLinearOpLayout>(std::move(dim));
37 }
38 }
39
41 const ext::shared_ptr<Fdm1dMesher>& mesher)
42 : FdmMesher(getLayoutFromMeshers({mesher})),
43 mesher_({mesher}) {
44 }
45
46
48 const ext::shared_ptr<Fdm1dMesher>& m1,
49 const ext::shared_ptr<Fdm1dMesher>& m2)
50 : FdmMesher(getLayoutFromMeshers({m1, m2})),
51 mesher_({m1, m2}) {
52 }
53
55 const ext::shared_ptr<Fdm1dMesher>& m1,
56 const ext::shared_ptr<Fdm1dMesher>& m2,
57 const ext::shared_ptr<Fdm1dMesher>& m3)
58 : FdmMesher(getLayoutFromMeshers({m1, m2, m3})),
59 mesher_({m1, m2, m3}) {
60 }
61
63 const ext::shared_ptr<Fdm1dMesher>& m1,
64 const ext::shared_ptr<Fdm1dMesher>& m2,
65 const ext::shared_ptr<Fdm1dMesher>& m3,
66 const ext::shared_ptr<Fdm1dMesher>& m4)
67 : FdmMesher(getLayoutFromMeshers({m1, m2, m3, m4})),
68 mesher_({m1, m2, m3, m4}) {
69 }
70
72 const std::vector<ext::shared_ptr<Fdm1dMesher> > & mesher)
73 : FdmMesher(getLayoutFromMeshers(mesher)), mesher_(mesher) {
74 }
75
77 const ext::shared_ptr<FdmLinearOpLayout>& layout,
78 const std::vector<ext::shared_ptr<Fdm1dMesher> > & mesher)
79 : FdmMesher(layout), mesher_(mesher) {
80 for (Size i=0; i < mesher.size(); ++i) {
81 QL_REQUIRE(mesher[i]->size() == layout->dim()[i],
82 "size of 1d mesher " << i << " does not fit to layout");
83 }
84 }
85
87 Size direction) const {
88 return mesher_[direction]->dplus(iter.coordinates()[direction]);
89 }
90
92 Size direction) const {
93 return mesher_[direction]->dminus(iter.coordinates()[direction]);
94 }
95
97 Size direction) const {
98 return mesher_[direction]->location(iter.coordinates()[direction]);
99 }
100
102 Array retVal(layout_->size());
103
104 for (const auto& iter : *layout_) {
105 retVal[iter.index()] =
106 mesher_[direction]->locations()[iter.coordinates()[direction]];
107 }
108
109 return retVal;
110 }
111
112 const std::vector<ext::shared_ptr<Fdm1dMesher> >&
114 return mesher_;
115 }
116}
1-D array used in linear algebra.
Definition: array.hpp:52
const std::vector< Size > & coordinates() const
Real dminus(const FdmLinearOpIterator &iter, Size direction) const override
Array locations(Size direction) const override
const std::vector< ext::shared_ptr< Fdm1dMesher > > & getFdm1dMeshers() const
FdmMesherComposite(const ext::shared_ptr< FdmLinearOpLayout > &layout, const std::vector< ext::shared_ptr< Fdm1dMesher > > &mesher)
Real dplus(const FdmLinearOpIterator &iter, Size direction) const override
const std::vector< ext::shared_ptr< Fdm1dMesher > > mesher_
Real location(const FdmLinearOpIterator &iter, Size direction) const override
const ext::shared_ptr< FdmLinearOpLayout > layout_
Definition: fdmmesher.hpp:56
const ext::shared_ptr< FdmLinearOpLayout > & layout() const
Definition: fdmmesher.hpp:51
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