/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* Copyright (C) 2005 Joseph Wang This file is part of QuantLib, a free-software/open-source library for financial quantitative analysts and developers - http://quantlib.org/ QuantLib is free software: you can redistribute it and/or modify it under the terms of the QuantLib license. You should have received a copy of the license along with this program; if not, please email . The license is also available online at . This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the license for more details. */ /*! \file parallelevolver.hpp \brief Parallel evolver for multiple arrays This class takes the evolver class and creates a new class which evolves each of the evolvers in parallel. Part of what this does is to take the types for each evolver class and then wrapper them so that they create new types which are sets of the old types. This class is intended to be run in situations where there are parallel differential equations such as with some convertible bond models. */ #ifndef quantlib_system_evolver_hpp #define quantlib_system_evolver_hpp #include #include #include #include namespace QuantLib { //! Parallel evolver for multiple arrays /*! \ingroup findiff */ template class StepConditionSet { typedef boost::shared_ptr > itemType; std::vector stepConditions_; public: void applyTo(std::vector& a, Time t) const { for (Size i=0; i < stepConditions_.size(); i++) { stepConditions_[i]->applyTo(a[i], t); } } void push_back(const itemType& a) { stepConditions_.push_back(a); } }; template class BoundaryConditionSet { std::vector bcSet_; public: void push_back(const bc_set& a) { bcSet_.push_back(a); } const bc_set& operator[](Size i) const { return bcSet_[i]; } }; template class ParallelEvolverTraits { public: typedef std::vector array_type; typedef std::vector operator_type; typedef std::vector bc_type; typedef BoundaryConditionSet bc_set; typedef StepConditionSet condition_type; }; template class ParallelEvolver { public: // typedefs typedef ParallelEvolverTraits traits; typedef typename traits::operator_type operator_type; typedef typename traits::array_type array_type; typedef typename traits::bc_set bc_set; // constructors ParallelEvolver(const operator_type& L, const bc_set& bcs) { evolvers_.reserve(L.size()); for (Size i=0; i < L.size(); i++) { evolvers_.push_back(boost::shared_ptr(new Evolver(L[i], bcs[i]))); } } void step(array_type& a, Time t) { for (Size i=0; i < evolvers_.size(); i++) { evolvers_[i]->step(a[i], t); } } void setStep(Time dt) { for (Size i=0; i < evolvers_.size(); i++) { evolvers_[i]->setStep(dt); } } private: std::vector > evolvers_; }; } #endif