1
// Copyright (C) 2003-2005 Johan Jansson and Anders Logg.
1
// Copyright (C) 2003-2006 Johan Jansson and Anders Logg.
2
2
// Licensed under the GNU GPL Version 2.
5
// Last changed: 2005-11-10
4
// First added: 2003-10-21
5
// Last changed: 2006-08-21
10
10
#include <dolfin/constants.h>
11
11
#include <dolfin/Event.h>
12
#include <dolfin/uBlasVector.h>
13
#include <dolfin/uBlasSparseMatrix.h>
12
14
#include <dolfin/Dependencies.h>
13
15
#include <dolfin/Sample.h>
17
20
/// A ODE represents an initial value problem of the form
19
22
/// u'(t) = f(u(t),t) on (0,T],
23
26
/// where u(t) is a vector of length N.
28
/// To define an ODE, a user must create a subclass of ODE and
29
/// create the function u0() defining the initial condition, as well
30
/// the function f() defining the right-hand side.
32
/// DOLFIN provides two types of ODE solvers: a set of standard
33
/// mono-adaptive solvers with equal adaptive time steps for all
34
/// components as well as a set of multi-adaptive solvers with
35
/// individual and adaptive time steps for the different
36
/// components. The right-hand side f() is defined differently for
37
/// the two sets of methods, with the multi-adaptive solvers
38
/// requiring a component-wise evaluation of the right-hand
39
/// side. Only one right-hand side function f() needs to be defined
40
/// for use of any particular solver.
42
/// It is also possible to solve implicit systems of the form
44
/// M(u(t), t) u'(t) = f(u(t),t) on (0,T],
48
/// by setting the option "implicit" to true and defining the
55
/// Create an ODE of size N with final time T
30
56
ODE(uint N, real T);
35
/// Return initial value for given component
36
virtual real u0(uint i) = 0;
38
/// Evaluate right-hand side (multi-adaptive version)
39
// FIXME:: make this abstract?
40
virtual real f(const real u[], real t, uint i);
42
/// Evaluate right-hand side (mono-adaptive version)
43
virtual void f(const real u[], real t, real y[]);
45
/// Compute product y = Mx for implicit system
46
virtual void M(const real x[], real y[], const real u[], real t);
48
/// Compute product y = Jx for Jacobian J
49
virtual void J(const real x[], real y[], const real u[], real t);
51
/// Jacobian (optional)
52
virtual real dfdu(const real u[], real t, uint i, uint j);
54
/// Time step to use for whole system (optional)
61
/// Set initial values
62
virtual void u0(uBlasVector& u) = 0;
64
/// Evaluate right-hand side y = f(u, t), mono-adaptive version (default, optional)
65
virtual void f(const uBlasVector& u, real t, uBlasVector& y);
67
/// Evaluate right-hand side f_i(u, t), multi-adaptive version (optional)
68
virtual real f(const uBlasVector& u, real t, uint i);
70
/// Compute product y = Mx for implicit system (optional)
71
virtual void M(const uBlasVector& x, uBlasVector& y, const uBlasVector& u, real t);
73
/// Compute product y = Jx for Jacobian J (optional)
74
virtual void J(const uBlasVector& x, uBlasVector& y, const uBlasVector& u, real t);
76
/// Compute entry of Jacobian (optional)
77
virtual real dfdu(const uBlasVector& u, real t, uint i, uint j);
79
/// Time step to use for the whole system at a given time t (optional)
55
80
virtual real timestep(real t, real k0) const;
57
/// Time step to use for given component (optional)
82
/// Time step to use for a given component at a given time t (optional)
58
83
virtual real timestep(real t, uint i, real k0) const;
60
85
/// Update ODE, return false to stop (optional)
61
virtual bool update(const real u[], real t, bool end);
86
virtual bool update(const uBlasVector& u, real t, bool end);
63
88
/// Save sample (optional)
64
89
virtual void save(Sample& sample);
66
/// Number of components N
91
/// Automatically detect sparsity (optional)
94
/// Compute sparsity from given matrix (optional)
95
void sparse(const uBlasSparseMatrix& A);
97
/// Return number of components N
69
/// End time (final time)
100
/// Return end time (final time T)
70
101
real endtime() const;
75
/// Automatically detect sparsity
78
/// Compute sparsity from given matrix
79
void sparse(const Matrix& A);
82
107
friend class Dual;