QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
parallelevolver.hpp
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) 2005 Joseph Wang
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/*! \file parallelevolver.hpp
21 \brief Parallel evolver for multiple arrays
22
23 This class takes the evolver class and creates a new class which evolves
24 each of the evolvers in parallel. Part of what this does is to take the
25 types for each evolver class and then wrapper them so that they create
26 new types which are sets of the old types.
27
28 This class is intended to be run in situations where there are parallel
29 differential equations such as with some convertible bond models.
30*/
31
32#ifndef quantlib_system_evolver_hpp
33#define quantlib_system_evolver_hpp
34
38#include <vector>
39
40namespace QuantLib {
41
42 /*! \deprecated Use the new finite-differences framework instead.
43 Deprecated in version 1.32.
44 */
45 template <typename array_type>
46 class [[deprecated("Use the new finite-differences framework instead")]] StepConditionSet {
47 typedef ext::shared_ptr<StepCondition<array_type> > itemType;
48 std::vector<itemType> stepConditions_;
49 public:
50 void applyTo(std::vector<array_type>& a, Time t) const {
51 //#pragma omp parallel for
52 for (Size i=0; i < stepConditions_.size(); i++) {
53 stepConditions_[i]->applyTo(a[i], t);
54 }
55 }
56 void push_back(const itemType& a) {
57 stepConditions_.push_back(a);
58 }
59 };
60
61 template <typename bc_set>
63 std::vector<bc_set> bcSet_;
64 public:
65 void push_back(const bc_set& a) {
66 bcSet_.push_back(a);
67 }
68 const bc_set& operator[](Size i) const {
69 return bcSet_[i];
70 }
71 };
72
73 /*! \deprecated Use the new finite-differences framework instead.
74 Deprecated in version 1.32.
75 */
76 template <typename traits>
77 class [[deprecated("Use the new finite-differences framework instead")]] ParallelEvolverTraits {
78 public:
79 typedef std::vector<typename traits::array_type> array_type;
80 typedef std::vector<typename traits::operator_type> operator_type;
81 typedef std::vector<typename traits::bc_type> bc_type;
86 };
87
88 /*! \deprecated Use the new finite-differences framework instead.
89 Deprecated in version 1.32.
90 */
91 template <class Evolver>
92 class [[deprecated("Use the new finite-differences framework instead")]] ParallelEvolver {
93 public:
94 // typedefs
98 typedef typename traits::operator_type operator_type;
99 typedef typename traits::array_type array_type;
100 typedef typename traits::bc_set bc_set;
101 // constructors
102 ParallelEvolver(const operator_type& L,
103 const bc_set& bcs) {
104 evolvers_.reserve(L.size());
105 for (Size i=0; i < L.size(); i++) {
106 evolvers_.push_back(ext::shared_ptr<Evolver>(new
107 Evolver(L[i], bcs[i])));
108 }
109 }
111 Time t) {
112 //#pragma omp parallel for
113 for (Size i=0; i < evolvers_.size(); i++) {
114 evolvers_[i]->step(a[i], t);
115 }
116 }
117 void setStep(Time dt) {
118 for (Size i=0; i < evolvers_.size(); i++) {
119 evolvers_[i]->setStep(dt);
120 }
121 }
122 private:
123 std::vector<ext::shared_ptr<Evolver> > evolvers_;
124 };
125
126}
127
128
129#endif
std::vector< bc_set > bcSet_
const bc_set & operator[](Size i) const
void push_back(const bc_set &a)
std::vector< ext::shared_ptr< Evolver > > evolvers_
ParallelEvolver(const operator_type &L, const bc_set &bcs)
traits::array_type array_type
QL_DEPRECATED_DISABLE_WARNING typedef ParallelEvolverTraits< typename Evolver::traits > traits
void step(array_type &a, Time t)
QL_DEPRECATED_ENABLE_WARNING typedef traits::operator_type operator_type
QL_DEPRECATED_DISABLE_WARNING typedef StepConditionSet< typename traits::array_type > condition_type
std::vector< typename traits::array_type > array_type
BoundaryConditionSet< typename traits::bc_set > bc_set
std::vector< typename traits::operator_type > operator_type
std::vector< typename traits::bc_type > bc_type
std::vector< itemType > stepConditions_
void push_back(const itemType &a)
ext::shared_ptr< StepCondition< array_type > > itemType
void applyTo(std::vector< array_type > &a, Time t) const
const DefaultType & t
generic finite difference model
Real Time
continuous quantity with 1-year units
Definition: types.hpp:62
std::size_t Size
size of a container
Definition: types.hpp:58
Definition: any.hpp:35
Numerical method class.
#define QL_DEPRECATED_DISABLE_WARNING
Definition: qldefines.hpp:216
#define QL_DEPRECATED_ENABLE_WARNING
Definition: qldefines.hpp:217
conditions to be applied at every time step