QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
fdmtimedepdirichletboundary.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) 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
20
21/*! \file fdmtimedepdirichletboundary.cpp
22*/
23
28#include <algorithm>
29#include <utility>
30
31namespace QuantLib {
32
34 const ext::shared_ptr<FdmMesher>& mesher,
35 ext::function<Real(Real)> valueOnBoundary,
36 Size direction,
37 Side side)
38 : indices_(FdmIndicesOnBoundary(mesher->layout(), direction, side).getIndices()),
39 valueOnBoundary_(std::move(valueOnBoundary)), values_(indices_.size()) {}
40
42 const ext::shared_ptr<FdmMesher>& mesher,
43 ext::function<Array(Real)> valuesOnBoundary,
44 Size direction,
45 Side side)
46 : indices_(FdmIndicesOnBoundary(mesher->layout(), direction, side).getIndices()),
47 valuesOnBoundary_(std::move(valuesOnBoundary)), values_(indices_.size()) {}
48
50 if (valueOnBoundary_) {
51 std::fill(values_.begin(), values_.end(), valueOnBoundary_(t));
52 } else if (valuesOnBoundary_) {
54 } else {
55 QL_FAIL("no boundary values defined");
56 }
57 }
58
60 QL_REQUIRE(indices_.size() == values_.size(),
61 "values on boundary size (" << values_.size()
62 << ") does not match hypersurface size ("
63 << indices_.size() << ")");
64 for (auto iter = indices_.begin(); iter != indices_.end(); ++iter) {
65 a[*iter] = values_[iter - indices_.begin()];
66 }
67 }
68
70 this->applyAfterApplying(a);
71 }
72}
1-D array used in linear algebra.
Definition: array.hpp:52
const_iterator end() const
Definition: array.hpp:511
Size size() const
dimension of the array
Definition: array.hpp:495
const_iterator begin() const
Definition: array.hpp:503
void applyAfterSolving(array_type &) const override
BoundaryCondition< FdmLinearOp >::Side Side
void applyAfterApplying(array_type &) const override
FdmTimeDepDirichletBoundary(const ext::shared_ptr< FdmMesher > &mesher, ext::function< Real(Real)> valueOnBoundary, Size direction, Side side)
const ext::function< Array(Real)> valuesOnBoundary_
const ext::function< Real(Real)> valueOnBoundary_
const DefaultType & t
#define QL_REQUIRE(condition, message)
throw an error if the given pre-condition is not verified
Definition: errors.hpp:117
#define QL_FAIL(message)
throw an error (possibly with file and line information)
Definition: errors.hpp:92
helper class to extract the indices on a boundary
linear operator to model a multi dimensinal pde system
mesher for a fdm grid
time dependent Dirichlet boundary conditions
Real Time
continuous quantity with 1-year units
Definition: types.hpp:62
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
STL namespace.