QuantLib: a free/open-source library for quantitative finance
Fully annotated sources - version 1.32
Loading...
Searching...
No Matches
fdmdirichletboundary.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
23#include <ql/methods/finitedifferences/meshers/fdmmesher.hpp>
24#include <ql/methods/finitedifferences/operators/fdmlinearoplayout.hpp>
25#include <ql/methods/finitedifferences/utilities/fdmdirichletboundary.hpp>
26#include <ql/methods/finitedifferences/utilities/fdmindicesonboundary.hpp>
27
28namespace QuantLib {
29
31 const ext::shared_ptr<FdmMesher>& mesher,
32 Real valueOnBoundary, Size direction,
34 : side_(side),
35 valueOnBoundary_(valueOnBoundary),
36 indices_(FdmIndicesOnBoundary(mesher->layout(),
37 direction, side).getIndices()) {
38
39 if (side_ == Lower) {
40 xExtreme_ = mesher->locations(direction)[0];
41 }
42 else if (side_ == Upper) {
43 xExtreme_ = mesher
44 ->locations(direction)[mesher->layout()->dim()[direction]-1];
45 }
46 else {
47 QL_FAIL("internal error");
48 }
49 }
50
52 }
53
55 for (unsigned long indice : indices_) {
56 x[indice] = valueOnBoundary_;
57 }
58 }
59
61 array_type&) const {
62 }
63
65 this->applyAfterApplying(rhs);
66 }
67
69 return ( (side_ == Lower && x < xExtreme_)
70 || (side_ == Upper && x > xExtreme_)) ? valueOnBoundary_ : value;
71 }
72}
1-D array used in linear algebra.
Definition: array.hpp:52
void applyAfterSolving(array_type &) const override
BoundaryCondition< FdmLinearOp >::Side Side
void applyAfterApplying(array_type &) const override
FdmDirichletBoundary(const ext::shared_ptr< FdmMesher > &mesher, Real valueOnBoundary, Size direction, Side side)
void applyBeforeApplying(operator_type &) const override
void applyBeforeSolving(operator_type &, array_type &) const override
const std::vector< Size > indices_
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