1
// Copyright (C) 2005-2009 Anders Logg.
2
// Licensed under the GNU LGPL Version 2.1.
4
// First added: 2005-10-14
5
// Last changed: 2009-09-08
9
using namespace dolfin;
11
/// Test problem taken from "Multirate time stepping for parabolic PDEs"
12
/// by Savcenco, Hundsdorfer and Verwer:
14
/// u' - epsilon u'' = gamma u^2 (1 - u) in (0, L) x (0, T).
16
/// The solution is a reaction front sweeping across the domain.
18
/// This is a simplified (only multi-adaptive) version of the ODE
19
/// benchmark found under bench/ode/reaction
21
class Reaction : public ODE
26
Reaction(unsigned int N, real T, real L, real epsilon, real gamma)
27
: ODE(N, T), L(L), epsilon(epsilon), gamma(gamma)
30
h = L / static_cast<real>(N - 1);
31
lambda = 0.5*sqrt(2.0*gamma/epsilon);
32
v = 0.5*sqrt(2.0*gamma*epsilon);
34
// Set sparse dependency pattern
35
for (unsigned int i = 0; i < N; i++)
37
dependencies.setsize(i, 3);
38
if (i > 0) dependencies.set(i, i - 1);
39
dependencies.set(i, i);
40
if (i < (N - 1)) dependencies.set(i, i + 1);
47
for (unsigned int i = 0; i < N; i++)
49
const real x = static_cast<real>(i)*h;
50
u[i] = 1.0 / (1.0 + real_exp(lambda*(x - 1.0)));
54
/// Right-hand side, multi-adaptive version
55
real f(const real* u, real t, unsigned int i)
62
else if (i == (N - 1))
65
sum = u[i + 1] - 2.0*ui + u[i - 1];
67
return epsilon * sum / (h*h) + gamma * ui*ui * (1.0 - ui);
72
real L; // Length of domain
73
real epsilon; // Diffusivity
74
real gamma; // Reaction rate
76
real lambda; // Parameter for initial data
77
real v; // Speed of reaction front
83
info("Reaction ODE demo needs to be fixed.");
85
// FIXME: Does not work with GMP enabled
87
// Set some parameters
89
const real epsilon = 0.01;
90
const real gamma = 1000.0;
92
const unsigned int N = 5000;
95
Reaction ode(N, T, L, epsilon, gamma);
96
ode.parameters["method"] = "mcg";
97
ode.parameters["order"] = 1;
98
ode.parameters["nonlinear_solver"] = "fixed-point";
99
ode.parameters["tolerance"] = 1e-3;
100
ode.parameters["partitioning_threshold"] = 0.5;
101
ode.parameters["initial_time_step"] = 1e-5;
102
ode.parameters["maximum_time_step"] = 1e-3;
103
ode.parameters["adaptive_samples"] = true;