1
// Copyright (C) 2005-2006 Anders Logg.
2
// Licensed under the GNU LGPL Version 2.1.
4
// First added: 2005-01-27
5
// Last changed: 2006-07-05
7
#ifndef __MULTI_ADAPTIVE_TIME_SLAB_H
8
#define __MULTI_ADAPTIVE_TIME_SLAB_H
10
#include <dolfin/dolfin_log.h>
11
#include <dolfin/constants.h>
12
#include <dolfin/uBlasVector.h>
13
#include <dolfin/Alloc.h>
14
#include <dolfin/Partition.h>
15
#include <dolfin/MultiAdaptivity.h>
16
#include <dolfin/TimeSlab.h>
24
/// This class represents a multi-adaptive time slab holding the
25
/// degrees of freedom for the solution of an ODE between two
26
/// synchronized time levels a and b, with individual time steps for
27
/// the different components of the system.
29
class MultiAdaptiveTimeSlab : public TimeSlab
34
MultiAdaptiveTimeSlab(ODE& ode);
37
~MultiAdaptiveTimeSlab();
39
/// Build time slab, return end time
40
real build(real a, real b);
42
/// Solve time slab system
45
/// Check if current solution can be accepted
46
bool check(bool first);
48
/// Shift time slab (prepare for next time slab)
51
/// Reset to initial data
54
/// Prepare sample at time t
57
/// Sample solution value of given component at given time
58
real usample(uint i, real t);
60
/// Sample time step size for given component at given time
61
real ksample(uint i, real t);
63
/// Sample residual for given component at given time
64
real rsample(uint i, real t);
66
/// Display time slab data
70
friend class MultiAdaptiveFixedPointSolver;
71
friend class MultiAdaptiveNewtonSolver;
72
friend class MultiAdaptiveJacobian;
73
friend class UpdatedMultiAdaptiveJacobian;
74
friend class MultiAdaptivePreconditioner;
75
friend class MultiAdaptivity;
79
// Reallocate all data
80
void allocData(real a, real b);
83
real createTimeSlab(real a, real b, uint offset);
85
// Create time slab data
86
void create_s(real t0, real t1, uint offset, uint end);
87
void create_e(uint index, uint subslab, real a, real b);
88
void create_j(uint index);
89
void create_d(uint index, uint element, uint subslab, real a0, real b0);
91
// Reallocation of data
92
void alloc_s(uint newsize);
93
void alloc_e(uint newsize);
94
void alloc_j(uint newsize);
95
void alloc_d(uint newsize);
97
// Compute length of time slab
98
real computeEndTime(real a, real b, uint offset, uint& end);
100
// Compute size of data
101
real computeDataSize(real a, real b, uint offset);
103
// Compute number of dependencies to components with smaller time steps
104
uint countDependencies(uint i0);
106
// Compute number of dependencies to components with smaller time steps
107
uint countDependencies(uint i0, real b0);
109
// Check if the given time is within the given interval
110
bool within(real t, real a, real b) const;
112
// Check if the first given interval is within the second interval
113
bool within(real a0, real b0, real a1, real b1) const;
115
// Cover all elements in sub slab and return e1, with e0 <= e < e1
116
uint coverSlab(int subslab, uint e0);
118
// Cover all elements in next sub slab and return next sub slab
119
uint coverNext(int subslab, uint element);
121
// Cover given time for all components
122
void coverTime(real t);
124
// Compute maximum of all element residuals
125
real computeMaxResiduals();
127
// Evaluate right-hand side at quadrature points of given element (cG)
128
void cGfeval(real* f, uint s0, uint e0, uint i0, real a0, real b0, real k0);
130
// Evaluate right-hand side at quadrature points of given element (dG)
131
void dGfeval(real* f, uint s0, uint e0, uint i0, real a0, real b0, real k0);
134
TimeSlabSolver* chooseSolver();
136
//--- Time slab data ---
138
real* sa; // Mapping s --> start time t of sub slab s
139
real* sb; // Mapping s --> end time t of sub slab s
141
uint* ei; // Mapping e --> component index i of element e
142
uint* es; // Mapping e --> time slab s containing element e
143
uint* ee; // Mapping e --> previous element e of element e
144
uint* ed; // Mapping e --> first dependency d of element e
146
real* jx; // Mapping j --> value of dof j
148
int* de; // Mapping d --> element e of dependency d
150
//--- Size of time slab data ---
152
Alloc size_s; // Allocation data for sub slabs s
153
Alloc size_e; // Allocation data for elements e
154
Alloc size_j; // Allocation data for dofs j
155
Alloc size_d; // Allocation data for dependencies d
157
uint ns; // Number of sub slabs
158
uint ne; // Number of elements
159
uint nj; // Number of dofs
160
uint nd; // Number of dependencies
162
//--- Auxiliary data, size N ---
164
TimeSlabSolver* solver; // The solver (size N if diagonally damped)
165
MultiAdaptivity adaptivity; // Adaptive time step regulation (size 3N)
166
Partition partition; // Time step partitioning (size N)
167
int* elast; // Last element for each component (size N)
168
real* f0; // Right-hand side at left end-point for cG (size N)
170
//--- Auxiliary data ---
171
uint emax; // Last covered element for sample
172
real kmin; // Minimum time step (exluding threshold modified)
174
uBlasVector u; // The interpolated solution at a given time