Reaktoro 
A unified framework for modeling chemically reactive systems
DaeSolver.hpp
1 // Reaktoro is a unified framework for modeling chemically reactive systems.
2 //
3 // Copyright (C) 2014-2015 Allan Leal
4 //
5 // This program is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18 #pragma once
19 
20 // C++ includes
21 #include <functional>
22 #include <memory>
23 
24 // Reaktoro includes
25 #include <Reaktoro/Math/Matrix.hpp>
26 
27 namespace Reaktoro {
28 
30 using DaeFunction = std::function<int(double t, const Vector& u, const Vector& udot, Vector& F)>;
31 
33 using DaeJacobian = std::function<int(double t, const Vector& u, const Vector& udot, Matrix& J)>;
34 
37 struct DaeOptions
38 {
39 };
40 
44 {
45 public:
47  DaeProblem();
48 
50  DaeProblem(const DaeProblem& other);
51 
53  virtual ~DaeProblem();
54 
56  auto operator=(DaeProblem other) -> DaeProblem&;
57 
59  auto setNumEquations(unsigned num) -> void;
60 
62  auto setFunction(const DaeFunction& f) -> void;
63 
65  auto setJacobian(const DaeJacobian& J) -> void;
66 
68  auto initialized() const -> bool;
69 
71  auto numEquations() const -> unsigned;
72 
74  auto function() const -> const DaeFunction&;
75 
77  auto jacobian() const -> const DaeJacobian&;
78 
85  auto function(double t, const Vector& y, const Vector& ydot, Vector& f) const -> int;
86 
93  auto jacobian(double t, const Vector& y, const Vector& ydot, Matrix& J) const -> int;
94 
95 private:
96  struct Impl;
97 
98  std::unique_ptr<Impl> pimpl;
99 };
100 
104 {
105 public:
107  DaeSolver();
108 
110  DaeSolver(const DaeSolver& other);
111 
113  virtual ~DaeSolver();
114 
116  auto operator=(DaeSolver other) -> DaeSolver&;
117 
120  auto setOptions(const DaeOptions& options) -> void;
121 
124  auto setProblem(const DaeProblem& problem) -> void;
125 
130  auto initialize(double tstart, const Vector& y) -> void;
131 
135  auto integrate(double& t, Vector& y) -> void;
136 
141  auto integrate(double& t, Vector& y, double tfinal) -> void;
142 
147  auto solve(double& t, double dt, Vector& y) -> void;
148 
149 private:
150  struct Impl;
151 
152  std::unique_ptr<Impl> pimpl;
153 };
154 
155 } // namespace Reaktoro
Eigen::MatrixXd Matrix
Define an alias to the matrix type of the Eigen library.
Definition: Matrix.hpp:387
A class that defines a system of differential-algebraic equations (DAE) problem.
Definition: DaeSolver.hpp:43
A class for solving differential-algebraic equations (DAE).
Definition: DaeSolver.hpp:103
Eigen::VectorXd Vector
Define an alias to the vector type of the Eigen library.
Definition: Matrix.hpp:384
std::function< int(double t, const Vector &u, const Vector &udot, Matrix &J)> DaeJacobian
The function signature of the Jacobian of the right-hand side function of a system of ordinary differ...
Definition: DaeSolver.hpp:33
std::function< int(double t, const Vector &u, const Vector &udot, Vector &F)> DaeFunction
The function signature of the right-hand side function of a system of ordinary differential equations...
Definition: DaeSolver.hpp:30
The namespace containing all components of the Reaktoro library.
Definition: ChemicalScalar.hpp:24
A struct that defines the options for the DaeSolver.
Definition: DaeSolver.hpp:37