1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
// Copyright (C) 2005-2007 Garth N. Wells.
// Licensed under the GNU LGPL Version 2.1.
//
// Modified by Anders Logg, 2006-2007.
//
// First added: 2005-10-24
// Last changed: 2007-08-28
#include <dolfin/fem/BoundaryCondition.h>
#include <dolfin/function/Function.h>
#include "NonlinearPDE.h"
#include <dolfin/fem/Form.h>
#include <dolfin/log/dolfin_log.h>
using namespace dolfin;
//-----------------------------------------------------------------------------
NonlinearPDE::NonlinearPDE(Form& a,
Form& L,
Mesh& mesh,
BoundaryCondition& bc)
: a(a), L(L), mesh(mesh), assembler(mesh)
{
message("Creating nonlinear PDE with %d boundary condition(s).", bcs.size());
// Check ranks of forms
if ( a.form().rank() != 2 )
error("Expected a bilinear form but rank is %d.", a.form().rank());
if ( L.form().rank() != 1 )
error("Expected a linear form but rank is %d.", L.form().rank());
// Create array with one boundary condition
bcs.push_back(&bc);
}
//-----------------------------------------------------------------------------
NonlinearPDE::NonlinearPDE(Form& a,
Form& L,
Mesh& mesh,
Array<BoundaryCondition*>& bcs)
: a(a), L(L), mesh(mesh), bcs(bcs), assembler(mesh)
{
message("Creating nonlinear PDE with %d boundary condition(s).", bcs.size());
// Check ranks of forms
if ( a.form().rank() != 2 )
error("Expected a bilinear form but rank is %d.", a.form().rank());
if ( L.form().rank() != 1 )
error("Expected a linear form but rank is %d.", L.form().rank());
}
//-----------------------------------------------------------------------------
NonlinearPDE::~NonlinearPDE()
{
// Do nothing
}
//-----------------------------------------------------------------------------
void NonlinearPDE::update(const GenericVector& x)
{
// Do nothing
}
//-----------------------------------------------------------------------------
void NonlinearPDE::form(GenericMatrix& A, GenericVector& b, const GenericVector& x)
{
// Assemble
assembler.assemble(A, a);
assembler.assemble(b, L);
// Apply boundary conditions
for (uint i = 0; i < bcs.size(); i++)
bcs[i]->apply(A, b, x, a);
}
//-----------------------------------------------------------------------------
void NonlinearPDE::solve(Function& u, real& t, const real& T, const real& dt)
{
begin("Solving nonlinear PDE.");
// Initialise function
u.init(mesh, x, a, 1);
// Solve
while( t < T )
{
t += dt;
newton_solver.solve(*this ,x);
}
end();
}
//-----------------------------------------------------------------------------
|