1
// Copyright (C) 2003-2005 Anders Logg.
2
// Licensed under the GNU LGPL Version 2.1.
4
// First added: 2003-11-28
7
#include <dolfin/log/dolfin_log.h>
8
#include <dolfin/math/dolfin_math.h>
11
using namespace dolfin;
17
//-----------------------------------------------------------------------------
18
Dual::Dual(ODE& primal, Function& u) : ODE(primal.size()), rhs(primal, u)
20
// Set sparsity to transpose of sparsity for the primal
21
sparsity.transp(primal.sparsity);
26
//-----------------------------------------------------------------------------
31
//-----------------------------------------------------------------------------
32
real Dual::u0(unsigned int i)
34
return 1.0 / sqrt(static_cast<real>(N));
36
//-----------------------------------------------------------------------------
37
real Dual::f(const Vector& phi, real t, unsigned int i)
39
// FIXME: Here we can do some optimization. Since we compute the sum
40
// FIXME: over all dual dependencies of i we will do the update of
41
// FIXME: buffer values many times. Since there is probably some overlap
42
// FIXME: we could precompute a new sparsity pattern taking all these
43
// FIXME: dependencies into account and then updating the buffer values
44
// FIXME: outside the sum.
48
if ( sparsity.sparse() )
50
const Array<unsigned int>& row(sparsity.row(i));
51
for (unsigned int pos = 0; pos < row.size(); pos++)
52
sum += rhs.dfdu(row[pos], i, T - t) * phi(row[pos]);
56
for (unsigned int j = 0; j < N; j++)
57
sum += rhs.dfdu(j, i, T - t) * phi(j);
62
//-----------------------------------------------------------------------------