From 87688f46aaa96a087494cbe20c843a5dbff420dc Mon Sep 17 00:00:00 2001 From: kanschat Date: Thu, 22 May 2014 20:17:16 +0000 Subject: [PATCH] adjust ThetaTimestepping example and documentation to AnyData git-svn-id: https://svn.dealii.org/trunk@32965 0785d39b-7218-0410-832d-ea1e28bc413d --- .../examples/doxygen/theta_timestepping.cc | 70 ++++++------------- .../deal.II/algorithms/theta_timestepping.h | 49 ++++++++----- 2 files changed, 56 insertions(+), 63 deletions(-) diff --git a/deal.II/examples/doxygen/theta_timestepping.cc b/deal.II/examples/doxygen/theta_timestepping.cc index 94871bd102..caf390eba9 100644 --- a/deal.II/examples/doxygen/theta_timestepping.cc +++ b/deal.II/examples/doxygen/theta_timestepping.cc @@ -30,33 +30,25 @@ using namespace dealii; using namespace Algorithms; -class Explicit - : public Operator > +class Explicit : public Operator > { public: Explicit(const FullMatrix &matrix); - void operator() (NamedData*> &out, - const NamedData*> &in); + void operator() (AnyData &out, const AnyData &in); - void initialize_timestep_data(const TimestepData &); private: - const TimestepData *timestep_data; SmartPointer, Explicit> matrix; FullMatrix m; }; -class Implicit - : public Operator > +class Implicit : public Operator > { public: Implicit(const FullMatrix &matrix); - void operator() (NamedData*> &out, - const NamedData*> &in); - - void initialize_timestep_data(const TimestepData &); -private: - const TimestepData *timestep_data; + void operator() (AnyData &out, const AnyData &in); + + private: SmartPointer, Implicit> matrix; FullMatrix m; }; @@ -66,10 +58,10 @@ private: int main() { FullMatrix matrix(2); - matrix(0,0) = 1.; - matrix(1,1) = 1.; - matrix(0,1) = 31.4; - matrix(1,0) = -31.4; + matrix(0,0) = 0.; + matrix(1,1) = 0.; + matrix(0,1) = 3.14; + matrix(1,0) = -3.14; OutputOperator > out; out.initialize_stream(std::cout); @@ -77,16 +69,13 @@ int main() Explicit op_explicit(matrix); Implicit op_implicit(matrix); ThetaTimestepping > 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); Vector value(2); value(0) = 1.; - NamedData*> indata; - NamedData*> outdata; - Vector *p = &value; - outdata.add(p, "value"); + AnyData indata; + AnyData outdata; + outdata.add(&value, "value"); solver.notify(Events::initial); solver(outdata, indata); @@ -102,24 +91,18 @@ Explicit::Explicit(const FullMatrix &M) void -Explicit::initialize_timestep_data(const TimestepData &t) -{ - timestep_data = &t; -} - - -void -Explicit::operator() (NamedData*> &out, const NamedData*> &in) +Explicit::operator() (AnyData &out, const AnyData &in) { + const double timestep = *in.read_ptr("Timestep"); if (this->notifications.test(Events::initial) || this->notifications.test(Events::new_timestep_size)) { - m.equ(-timestep_data->step, *matrix); + m.equ(-timestep, *matrix); for (unsigned int i=0; inotifications.clear(); - unsigned int i = in.find("Previous iterate"); - m.vmult(*out(0), *in(i)); + m.vmult(*out.entry*>(0), + *in.read_ptr >("Previous iterate")); } @@ -132,26 +115,19 @@ Implicit::Implicit(const FullMatrix &M) void -Implicit::initialize_timestep_data(const TimestepData &t) -{ - timestep_data = &t; -} - - -void -Implicit::operator() (NamedData*> &out, const NamedData*> &in) +Implicit::operator() (AnyData &out, const AnyData &in) { + const double timestep = *in.read_ptr("Timestep"); if (this->notifications.test(Events::initial) || this->notifications.test(Events::new_timestep_size)) { - m.equ(timestep_data->step, *matrix); + m.equ(timestep, *matrix); for (unsigned int i=0; inotifications.clear(); - - unsigned int i = in.find("Previous time"); - m.vmult(*out(0), *in(i)); + m.vmult(*out.entry*>(0), + *in.read_ptr >("Previous time")); } diff --git a/deal.II/include/deal.II/algorithms/theta_timestepping.h b/deal.II/include/deal.II/algorithms/theta_timestepping.h index 0fc7df05cf..0d86380de1 100644 --- a/deal.II/include/deal.II/algorithms/theta_timestepping.h +++ b/deal.II/include/deal.II/algorithms/theta_timestepping.h @@ -140,7 +140,7 @@ namespace Algorithms * @until 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 + * us look first 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. * @@ -148,10 +148,9 @@ namespace Algorithms * @until out.initialize * * 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. + * steps as well as the ThetaTimestepping itself. We initialize the + * timestepping with the output operator in order to be able to see + * the output in every step. * * @until set_output * @@ -159,29 +158,47 @@ namespace Algorithms * 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. + * it in an AnyData object. Since our problem has no additional + * parameters, the input AnyData object remains empty. * * @until add * - * Finally, we are ready to tell the solver, that we are looknig at + * Finally, we are ready to tell the solver, that we are starting at * the initial timestep and run it. * - * @until outdata - * @skip Explicit::initialize + * @until } + * + * First the constructor, which simply copies the system matrix into + * the member pointer for later use. + * + * @skip Explicit:: + * @until } * * 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. + * the matrix created in the main program (the constructor did this + * for us). Here, we first get the time step size from the AnyData + * object that was provided as input. Then, if we are in the first + * step or if the timestep has changed, we fill the local matrix + * m, such that with the given matrix \f$M\f$, it becomes + * \f[ + * m = I - \Delta t M. + * \f] + * After we have worked off the notifications, we clear them, such + * that the matrix is only generated when necessary. * * @skipline void - * @until vmult + * @until clear + * + * Now we multiply the input vector with the new matrix and store on output. + * * @until } + * The code for the implicit operator is almost the same, except + * that we change the sign in front of the timestep and use the + * inverse of t he matrix. * + * @until vmult + * @until } * @author Guido Kanschat * @date 2010 */ -- 2.39.5