Reference documentation for deal.II version 8.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
Public Member Functions | Private Attributes | List of all members
Algorithms::ThetaTimestepping< VECTOR > Class Template Reference

#include <theta_timestepping.h>

Inheritance diagram for Algorithms::ThetaTimestepping< VECTOR >:
[legend]

Public Member Functions

 ThetaTimestepping (Operator< VECTOR > &op_explicit, Operator< VECTOR > &op_implicit)
 
virtual void operator() (NamedData< VECTOR * > &out, const NamedData< VECTOR * > &in)
 
virtual void notify (const Event &)
 
void set_output (OutputOperator< VECTOR > &output)
 
void declare_parameters (ParameterHandler &param)
 
void initialize (ParameterHandler &param)
 
const doublecurrent_time () const
 
const doublestep_size () const
 
const doubletheta () const
 
const TimestepDataexplicit_data () const
 
const TimestepDataimplicit_data () const
 
TimestepControltimestep_control ()
 
- Public Member Functions inherited from Algorithms::Operator< VECTOR >
 ~Operator ()
 
void clear_events ()
 
- Public Member Functions inherited from Subscriptor
 Subscriptor ()
 
 Subscriptor (const Subscriptor &)
 
virtual ~Subscriptor ()
 
Subscriptoroperator= (const Subscriptor &)
 
void subscribe (const char *identifier=0) const
 
void unsubscribe (const char *identifier=0) const
 
unsigned int n_subscriptions () const
 
void list_subscribers () const
 
 DeclException3 (ExcInUse, int, char *, std::string &,<< "Object of class "<< arg2<< " is still used by "<< arg1<< " other objects.\n"<< "(Additional information: "<< arg3<< ")\n"<< "Note the entry in the Frequently Asked Questions of "<< "deal.II (linked to from http://www.dealii.org/) for "<< "more information on what this error means.")
 
 DeclException2 (ExcNoSubscriber, char *, char *,<< "No subscriber with identifier \""<< arg2<< "\" did subscribe to this object of class "<< arg1)
 
template<class Archive >
void serialize (Archive &ar, const unsigned int version)
 

Private Attributes

TimestepControl control
 
double vtheta
 
bool adaptive
 
TimestepData d_explicit
 
TimestepData d_implicit
 
SmartPointer< Operator< VECTOR >
, ThetaTimestepping< VECTOR > > 
op_explicit
 
SmartPointer< Operator< VECTOR >
, ThetaTimestepping< VECTOR > > 
op_implicit
 
SmartPointer< OutputOperator
< VECTOR >, ThetaTimestepping
< VECTOR > > 
output
 

Additional Inherited Members

- Protected Attributes inherited from Algorithms::Operator< VECTOR >
Event notifications
 

Detailed Description

template<class VECTOR>
class Algorithms::ThetaTimestepping< VECTOR >

Application class performing the theta timestepping scheme.

The theta scheme is an abstraction of implicit and explicit Euler schemes, the Crank-Nicholson scheme and linear combinations of those. The choice of the actual scheme is controlled by the parameter theta as follows.

For fixed theta, the Crank-Nicholson scheme is the only second order scheme. Nevertheless, further stability may be achieved by choosing theta larger than ½, thereby introducing a first order error term. In order to avoid a loss of convergence order, the adaptive theta scheme can be used, where theta=½+c dt.

Assume that we want to solve the equation u' + Au = 0 with a step size k. A step of the theta scheme can be written as

\[ (M + \theta k A) u_{n+1} = (M - (1-\theta)k A) u_n. \]

Here, M is the mass matrix. We see, that the right hand side amounts to an explicit Euler step with modified step size in weak form (up to inversion of M). The left hand side corresponds to an implicit Euler step with modified step size (right hand side given). Thus, the implementation of the theta scheme will use two Operator objects, one for the explicit, one for the implicit part. Each of these will use its own TimestepData to account for the modified step sizes (and different times if the problem is not autonomous).

Usage of vectors in NamedData

ThetaTimestepping uses NamedData for communicating vectors. With outer or inner Operator objects. It does not use itself the input vectors provided, but forwards them to the explicit and implicit operators.

The explicit Operator op_explicit receives in its input in first place the vector "Previous iterate", which is the solution value after the previous timestep. It is followed by all vectors provided to ThetaTimestepping::operator() as input argument. op_explicit is supposed to write its result into the first position of its output argument, labeled "Result".

The implicit Operator op_implicit receives the result of op_explicit in its first input vector labeled "Previous time". It is followed by all vectors provided to ThetaTimestepping::operator() as input argument. The output of op_implicit is directly written into the output argument given to ThetaTimestepping.

Usage of ThetaTimestepping

The use ThetaTimestepping is more complicated than for instance Newton, since the inner operators will usually need to access the TimeStepData. Thus, we have a circular dependency of information, and we include the following example for its use. It can be found in examples/doxygen/theta_timestepping.cc

First, we define the two operators used by ThetaTimestepping and call them Implicit and Explicit. They both share the public interface of Operator, and additionally provide storage for the matrices to be used and a pointer to TimestepData. Note that we do not use a SmartPointer here, since the TimestepData will be destroyed before the operator.

class Explicit
: public Operator<Vector<double> >
{
public:
Explicit(const FullMatrix<double> &matrix);
const NamedData<Vector<double>*> &in);
void initialize_timestep_data(const TimestepData &);
private:
const TimestepData *timestep_data;
};
class Implicit
: public Operator<Vector<double> >
{
public:
Implicit(const FullMatrix<double> &matrix);
const NamedData<Vector<double>*> &in);
void initialize_timestep_data(const TimestepData &);
private:
const TimestepData *timestep_data;
};
// End of declarations

These operators will be implemented after the main program. But let us look at how they get used. First, let us define a matrix to be used for our system and also an OutputOperator in order to write the data of each timestep to a file.

int main()
{
FullMatrix<double> matrix(2);
matrix(0,0) = 1.;
matrix(1,1) = 1.;
matrix(0,1) = 31.4;
matrix(1,0) = -31.4;
OutputOperator<Vector<double> > out;
out.initialize_stream(std::cout);

Now we create objects for the implicit and explicit parts of the steps as well as the ThetaTimestepping itself. Notice how the TimestepData of ThetaTimestepping gets forwarded to the inner operators. There are two different data objects, because the timestep size is modified by theta.

Explicit op_explicit(matrix);
Implicit op_implicit(matrix);
ThetaTimestepping<Vector<double> > solver(op_explicit, op_implicit);
op_explicit.initialize_timestep_data(solver.explicit_data());
op_implicit.initialize_timestep_data(solver.implicit_data());
solver.set_output(out);

The next step is providing the vectors to be used. value is filled with the initial value and is also the vector where the solution at each timestep will be. Because the interface of Operator has to be able to handle several vectors, we need to store it in a NamedData object. Notice, that we need to create the intermediate pointer p. If we would use &value directly in the add function, the resulting object would be constant.

Vector<double> value(2);
value(0) = 1.;
Vector<double> *p = &value;
outdata.add(p, "value");

Finally, we are ready to tell the solver, that we are looknig at the initial timestep and run it.

solver.notify(Events::initial);
solver(outdata, indata);

Now we need to study the application of the implicit and explicit operator. We assume that the pointer matrix points to the matrix created in the main program, and that timestep_data points to the correct data object of ThetaTimestepping.

void
Explicit::operator() (NamedData<Vector<double>*> &out, const NamedData<Vector<double>*> &in)
{
{
m.equ(-timestep_data->step, *matrix);
for (unsigned int i=0; i<m.m(); ++i)
m(i,i) += 1.;
}
unsigned int i = in.find("Previous iterate");
m.vmult(*out(0), *in(i));
}

Author
Guido Kanschat
Date
2010

Definition at line 173 of file theta_timestepping.h.

Constructor & Destructor Documentation

template<class VECTOR >
Algorithms::ThetaTimestepping< VECTOR >::ThetaTimestepping ( Operator< VECTOR > &  op_explicit,
Operator< VECTOR > &  op_implicit 
)

Constructor, receiving the two operators stored in op_explicit and op_implicit. For their meening, see the description of those variables.

Definition at line 28 of file theta_timestepping.templates.h.

Member Function Documentation

template<class VECTOR >
void Algorithms::ThetaTimestepping< VECTOR >::operator() ( NamedData< VECTOR * > &  out,
const NamedData< VECTOR * > &  in 
)
virtual

The timestepping scheme. in should contain the initial value in first position. out

Implements Algorithms::Operator< VECTOR >.

Definition at line 66 of file theta_timestepping.templates.h.

template<class VECTOR >
void Algorithms::ThetaTimestepping< VECTOR >::notify ( const Event e)
virtual

Register an event triggered by an outer iteration.

Reimplemented from Algorithms::Operator< VECTOR >.

Definition at line 35 of file theta_timestepping.templates.h.

template<class VECTOR >
void Algorithms::ThetaTimestepping< VECTOR >::set_output ( OutputOperator< VECTOR > &  output)
inline

Define an operator which will output the result in each step. Note that no output will be generated without this.

Definition at line 360 of file theta_timestepping.h.

template<class VECTOR >
const double& Algorithms::ThetaTimestepping< VECTOR >::current_time ( ) const

The current time in the timestepping scheme.

template<class VECTOR >
const double& Algorithms::ThetaTimestepping< VECTOR >::step_size ( ) const

The current step size.

template<class VECTOR >
const double& Algorithms::ThetaTimestepping< VECTOR >::theta ( ) const

The weight between implicit and explicit part.

template<class VECTOR >
const TimestepData & Algorithms::ThetaTimestepping< VECTOR >::explicit_data ( ) const
inline

The data handed to the op_explicit time stepping operator.

The time in here is the time at the beginning of the current step, the time step is (1-theta) times the actual time step.

Definition at line 344 of file theta_timestepping.h.

template<class VECTOR >
const TimestepData & Algorithms::ThetaTimestepping< VECTOR >::implicit_data ( ) const
inline

The data handed to the op_implicit time stepping operator.

The time in here is the time at the beginning of the current step, the time step is theta times the actual time step.

Definition at line 353 of file theta_timestepping.h.

template<class VECTOR >
TimestepControl& Algorithms::ThetaTimestepping< VECTOR >::timestep_control ( )

Allow access to the control object.

Member Data Documentation

template<class VECTOR >
TimestepControl Algorithms::ThetaTimestepping< VECTOR >::control
private

The object controlling the time step size and computing the new time in each step.

Definition at line 262 of file theta_timestepping.h.

template<class VECTOR >
double Algorithms::ThetaTimestepping< VECTOR >::vtheta
private

The control parameter theta in the range [0,1].

Definition at line 268 of file theta_timestepping.h.

template<class VECTOR >
bool Algorithms::ThetaTimestepping< VECTOR >::adaptive
private

Use adaptive theta if true.

Definition at line 273 of file theta_timestepping.h.

template<class VECTOR >
TimestepData Algorithms::ThetaTimestepping< VECTOR >::d_explicit
private

The data for the explicit part of the scheme.

Definition at line 279 of file theta_timestepping.h.

template<class VECTOR >
TimestepData Algorithms::ThetaTimestepping< VECTOR >::d_implicit
private

The data for the implicit part of the scheme.

Definition at line 285 of file theta_timestepping.h.

template<class VECTOR >
SmartPointer<Operator<VECTOR>, ThetaTimestepping<VECTOR> > Algorithms::ThetaTimestepping< VECTOR >::op_explicit
private

The operator computing the explicit part of the scheme. This will receive in its input data the value at the current time with name "Current time solution". It should obtain the current time and time step size from explicit_data().

Its return value is Mu+cAu, where u is the current state vector, M the mass matrix, A the operator in space and c is the time step size in explicit_data().

Definition at line 308 of file theta_timestepping.h.

template<class VECTOR >
SmartPointer<Operator<VECTOR>, ThetaTimestepping<VECTOR> > Algorithms::ThetaTimestepping< VECTOR >::op_implicit
private

The operator solving the implicit part of the scheme. It will receive in its input data the vector "Previous time". Information on the timestep should be obtained from implicit_data().

Its return value is the solution u of Mu-cAu=f, where f is the dual space vector found in the "Previous time" entry of the input data, M the mass matrix, A the operator in space and c is the time step size in explicit_data().

Definition at line 331 of file theta_timestepping.h.

template<class VECTOR >
SmartPointer<OutputOperator<VECTOR>, ThetaTimestepping<VECTOR> > Algorithms::ThetaTimestepping< VECTOR >::output
private

The operator writing the output in each time step

Definition at line 337 of file theta_timestepping.h.


The documentation for this class was generated from the following files: