1
// Copyright (C) 2006 Johan Jansson.
2
// Licensed under the GNU GPL Version 2.
4
// Modified by Anders Logg 2006.
7
// Last changed: 2006-05-04
11
#include <dolfin/dolfin_log.h>
12
#include <dolfin/FEM.h>
13
#include <dolfin/Matrix.h>
14
#include <dolfin/Vector.h>
15
#include <dolfin/GMRES.h>
16
#include <dolfin/LU.h>
17
#include <dolfin/BilinearForm.h>
18
#include <dolfin/LinearForm.h>
19
#include <dolfin/Mesh.h>
20
#include <dolfin/BoundaryCondition.h>
21
#include <dolfin/Function.h>
22
#include <dolfin/TimeDependentPDE.h>
23
#include <dolfin/Parametrized.h>
24
#include <dolfin/TimeStepper.h>
26
using namespace dolfin;
28
TimeDependentPDE::TimeDependentPDE(BilinearForm& a, LinearForm& L, Mesh& mesh,
29
BoundaryCondition& bc, int N, real T) : GenericPDE(), x(0),
31
_mesh(&mesh), _bc(&bc),
37
for(unsigned int i = 0; i < this->L().num_functions; i++)
39
Function* f = this->L().function(i);
43
//-----------------------------------------------------------------------------
44
TimeDependentPDE::~TimeDependentPDE()
48
//-----------------------------------------------------------------------------
49
dolfin::uint TimeDependentPDE::solve(Function& U)
57
// Make sure u is a discrete function associated with the trial space
58
// u.init(*_mesh, _a->trial());
61
// dotx = new Vector(N);
63
//int N = FEM::size(*_mesh, _Lf->test());
65
cout << "N: " << N << endl;
66
cout << "x size: " << x->size() << endl;
69
// Initialize ODE (requires x)
70
ode = new TimeDependentODE(*this, N, T);
71
ts = new TimeStepper(*ode);
74
dolfin_info("Solving time dependent PDE.");
76
// File solutionfile("solution.pvd");
84
// Start time-stepping
86
// cout << "t: " << t << endl;
93
// if((counter % 333 * 2) == 0)
104
//-----------------------------------------------------------------------------
105
void TimeDependentPDE::u0(uBlasVector& u)
107
cout << "TimeDependentPDE::u0" << endl;
109
u.copy(*x, 0, 0, u.size());
111
//-----------------------------------------------------------------------------
112
void TimeDependentPDE::fu(const Vector& x, Vector& dotx, real t)
115
//-----------------------------------------------------------------------------
116
dolfin::uint TimeDependentPDE::elementdim()
119
return _a->trial().elementdim();
121
//-----------------------------------------------------------------------------
122
BilinearForm& TimeDependentPDE::a()
127
//-----------------------------------------------------------------------------
128
LinearForm& TimeDependentPDE::L()
133
//-----------------------------------------------------------------------------
134
Mesh& TimeDependentPDE::mesh()
136
dolfin_assert(_mesh);
139
//-----------------------------------------------------------------------------
140
BoundaryCondition& TimeDependentPDE::bc()
145
//-----------------------------------------------------------------------------
146
void TimeDependentPDE::init(Function& U)
149
//-----------------------------------------------------------------------------
150
void TimeDependentPDE::save(Function& U, real t)
153
void TimeDependentPDE::preparestep()
156
//-----------------------------------------------------------------------------
157
void TimeDependentPDE::prepareiteration()
160
//-----------------------------------------------------------------------------
161
TimeDependentODE::TimeDependentODE(TimeDependentPDE& pde, int N, real T) :
165
//-----------------------------------------------------------------------------
166
void TimeDependentODE::u0(uBlasVector& u)
168
cout << "TimeDependentODE::u0" << endl;
171
//-----------------------------------------------------------------------------
172
void TimeDependentODE::f(const uBlasVector& u, real t, uBlasVector& y)
174
pde->x->copy(u, 0, 0, u.size());
176
pde->prepareiteration();
178
pde->fu(*(pde->x), *(pde->dotx), t);
180
y.copy(*(pde->dotx), 0, 0, u.size());
182
//-----------------------------------------------------------------------------
183
bool TimeDependentODE::update(const uBlasVector& u, real t, bool end)
187
//-----------------------------------------------------------------------------