QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
fdmindicesonboundary.cpp
Go to the documentation of this file.
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
25
26namespace QuantLib {
28 const ext::shared_ptr<FdmLinearOpLayout>& layout,
29 Size direction, FdmDirichletBoundary::Side side) {
30
31 std::vector<Size> newDim(layout->dim());
32 newDim[direction] = 1;
33 const Size hyperSize
34 = std::accumulate(newDim.begin(), newDim.end(), Size(1), std::multiplies<>());
35 indices_.resize(hyperSize);
36
37 Size i=0;
38 for (const auto& iter : *layout) {
39 if ( ( side == FdmDirichletBoundary::Lower
40 && iter.coordinates()[direction] == 0)
42 && iter.coordinates()[direction]
43 == layout->dim()[direction]-1)) {
44 QL_REQUIRE(hyperSize > i, "index missmatch");
45 indices_[i++] = iter.index();
46 }
47 }
48
49
50 }
51
52 const std::vector<Size>& FdmIndicesOnBoundary::getIndices() const {
53 return indices_;
54 }
55}
BoundaryCondition< FdmLinearOp >::Side Side
const std::vector< Size > & getIndices() const
FdmIndicesOnBoundary(const ext::shared_ptr< FdmLinearOpLayout > &l, Size direction, FdmDirichletBoundary::Side side)
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Definition: errors.hpp:117
helper class to extract the indices on a boundary
memory layout of a fdm linear operator
std::size_t Size
size of a container
Definition: types.hpp:58
Definition: any.hpp:35