Newer
Older
template <class VectorType, class MatrixType, class FunctionType, size_t dim>
BackwardEuler<VectorType, MatrixType, FunctionType, dim>::BackwardEuler(
MatrixType const &_A, MatrixType const &_M, MatrixType const &_C,
double _wc, VectorType const &_u_initial, VectorType const &_v_initial,
Dune::BitSetVector<dim> const &_dirichletNodes,
FunctionType const &_dirichletFunction)
: A(_A),
u(_u_initial),
v(_v_initial),
dirichletNodes(_dirichletNodes),
dirichletFunction(_dirichletFunction) {}
template <class VectorType, class MatrixType, class FunctionType, size_t dim>
void BackwardEuler<VectorType, MatrixType, FunctionType, dim>::nextTimeStep() {
template <class VectorType, class MatrixType, class FunctionType, size_t dim>
void BackwardEuler<VectorType, MatrixType, FunctionType, dim>::setup(
VectorType const &ell, double _tau, double relativeTime, VectorType &rhs,
postProcessCalled = false;
tau = _tau;
/* We start out with the formulation
M a + C v + A u = ell
Backward Euler means
a1 = 1.0/tau ( v1 - v0 )
u1 = tau v1 + u0
in summary, we get at time t=1
M [1.0/tau ( v1 - v0 )] + C v1
+ A [tau v1 + u0] = ell
or
1.0/tau M v1 + C v1 + tau A v1
= [1.0/tau M + C + tau A] v1
= ell + 1.0/tau M v0 - A u0
*/
// set up LHS (for fixed tau, we'd only really have to do this once)
{
Dune::MatrixIndexSet indices(A.N(), A.M());
indices.import(A);
indices.import(M);
indices.import(C);
AM = 0.0;
Arithmetic::addProduct(AM, (1.0 - wc) / tau, M);
Arithmetic::addProduct(AM, wc, C);
Arithmetic::addProduct(AM, tau, A);
rhs = ell;
Arithmetic::addProduct(rhs, (1.0 - wc) / tau, M, v_o);
Arithmetic::subtractProduct(rhs, A, u_o);
// v_o makes a good initial iterate; we could use anything, though
for (size_t i = 0; i < dirichletNodes.size(); ++i)
switch (dirichletNodes[i].count()) {
case 0:
continue;
case dim:
dirichletFunction.evaluate(relativeTime, iterate[i][0]);
break;
case 1:
if (dirichletNodes[i][0]) {
dirichletFunction.evaluate(relativeTime, iterate[i][0]);
break;
}
if (dirichletNodes[i][1]) {
break;
}
assert(false);
default:
assert(false);
}
}
template <class VectorType, class MatrixType, class FunctionType, size_t dim>
void BackwardEuler<VectorType, MatrixType, FunctionType, dim>::postProcess(
postProcessCalled = true;
Arithmetic::addProduct(u, tau, v);
}
template <class VectorType, class MatrixType, class FunctionType, size_t dim>
void BackwardEuler<VectorType, MatrixType, FunctionType,
dim>::extractDisplacement(VectorType &displacement) const {
if (!postProcessCalled)
DUNE_THROW(Dune::Exception, "It seems you forgot to call postProcess!");
displacement = u;
}
template <class VectorType, class MatrixType, class FunctionType, size_t dim>
void BackwardEuler<VectorType, MatrixType, FunctionType, dim>::extractVelocity(
VectorType &velocity) const {
if (!postProcessCalled)
DUNE_THROW(Dune::Exception, "It seems you forgot to call postProcess!");
velocity = v;
}