~njansson/dolfin/hpc

« back to all changes in this revision

Viewing changes to src/kernel/ode/dolfin/MultiAdaptiveTimeSlab.h

  • Committer: Johannes Ring
  • Date: 2008-03-05 22:43:06 UTC
  • Revision ID: johannr@simula.no-20080305224306-2npsdyhfdpl2esji
The BIG commit!

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// Copyright (C) 2005-2006 Anders Logg.
2
 
// Licensed under the GNU LGPL Version 2.1.
3
 
//
4
 
// First added:  2005-01-27
5
 
// Last changed: 2006-07-05
6
 
 
7
 
#ifndef __MULTI_ADAPTIVE_TIME_SLAB_H
8
 
#define __MULTI_ADAPTIVE_TIME_SLAB_H
9
 
 
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>
17
 
 
18
 
namespace dolfin
19
 
{
20
 
  class ODE;
21
 
  class Method;
22
 
  class TimeSlabSolver;
23
 
  
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.
28
 
 
29
 
  class MultiAdaptiveTimeSlab : public TimeSlab
30
 
  {
31
 
  public:
32
 
 
33
 
    /// Constructor
34
 
    MultiAdaptiveTimeSlab(ODE& ode);
35
 
 
36
 
    /// Destructor
37
 
    ~MultiAdaptiveTimeSlab();
38
 
    
39
 
    /// Build time slab, return end time
40
 
    real build(real a, real b);
41
 
 
42
 
    /// Solve time slab system
43
 
    bool solve();
44
 
 
45
 
    /// Check if current solution can be accepted
46
 
    bool check(bool first);
47
 
    
48
 
    /// Shift time slab (prepare for next time slab)
49
 
    bool shift();
50
 
 
51
 
    /// Reset to initial data
52
 
    void reset();
53
 
    
54
 
    /// Prepare sample at time t
55
 
    void sample(real t);
56
 
 
57
 
    /// Sample solution value of given component at given time
58
 
    real usample(uint i, real t);
59
 
 
60
 
    /// Sample time step size for given component at given time
61
 
    real ksample(uint i, real t);
62
 
 
63
 
    /// Sample residual for given component at given time
64
 
    real rsample(uint i, real t);
65
 
 
66
 
    /// Display time slab data
67
 
    void disp() const;
68
 
 
69
 
    /// Friends
70
 
    friend class MultiAdaptiveFixedPointSolver;
71
 
    friend class MultiAdaptiveNewtonSolver;
72
 
    friend class MultiAdaptiveJacobian;
73
 
    friend class UpdatedMultiAdaptiveJacobian;
74
 
    friend class MultiAdaptivePreconditioner;
75
 
    friend class MultiAdaptivity;
76
 
 
77
 
  private:
78
 
 
79
 
    // Reallocate all data
80
 
    void allocData(real a, real b);
81
 
 
82
 
    // Create time slab
83
 
    real createTimeSlab(real a, real b, uint offset);
84
 
 
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);
90
 
   
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);
96
 
 
97
 
    // Compute length of time slab
98
 
    real computeEndTime(real a, real b, uint offset, uint& end);
99
 
 
100
 
    // Compute size of data
101
 
    real computeDataSize(real a, real b, uint offset);
102
 
    
103
 
    // Compute number of dependencies to components with smaller time steps
104
 
    uint countDependencies(uint i0);
105
 
 
106
 
    // Compute number of dependencies to components with smaller time steps
107
 
    uint countDependencies(uint i0, real b0);
108
 
 
109
 
    // Check if the given time is within the given interval
110
 
    bool within(real t, real a, real b) const;
111
 
 
112
 
    // Check if the first given interval is within the second interval
113
 
    bool within(real a0, real b0, real a1, real b1) const;
114
 
 
115
 
    // Cover all elements in sub slab and return e1, with e0 <= e < e1
116
 
    uint coverSlab(int subslab, uint e0);
117
 
 
118
 
    // Cover all elements in next sub slab and return next sub slab
119
 
    uint coverNext(int subslab, uint element);
120
 
 
121
 
    // Cover given time for all components
122
 
    void coverTime(real t);
123
 
 
124
 
    // Compute maximum of all element residuals
125
 
    real computeMaxResiduals();
126
 
 
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);
129
 
 
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);
132
 
 
133
 
    // Choose solver
134
 
    TimeSlabSolver* chooseSolver();
135
 
 
136
 
    //--- Time slab data ---
137
 
 
138
 
    real* sa; // Mapping s --> start time t of sub slab s
139
 
    real* sb; // Mapping s --> end time t of sub slab s
140
 
        
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
145
 
    
146
 
    real* jx; // Mapping j --> value of dof j
147
 
    
148
 
    int* de;  // Mapping d --> element e of dependency d
149
 
        
150
 
    //--- Size of time slab data ---
151
 
    
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
156
 
 
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
161
 
 
162
 
    //--- Auxiliary data, size N ---
163
 
 
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)
169
 
 
170
 
    //--- Auxiliary data ---
171
 
    uint emax;                  // Last covered element for sample
172
 
    real kmin;                  // Minimum time step (exluding threshold modified)
173
 
 
174
 
    uBlasVector u; // The interpolated solution at a given time
175
 
 
176
 
  };
177
 
 
178
 
}
179
 
 
180
 
#endif