33 #ifndef __H__UG__LIB_DISC__TIME_DISC__THETA_TIME_STEP_IMPL__
34 #define __H__UG__LIB_DISC__TIME_DISC__THETA_TIME_STEP_IMPL__
39 #define M_PI 3.14159265358979323846264338327950288
44 template <
typename TAlgebra>
49 PROFILE_BEGIN_GROUP(MultiStepTimeDiscretization_prepare_step,
"discretization MultiStepTimeDiscretization");
51 if(prevSol->size() < m_prevSteps)
52 UG_THROW(
"MultiStepTimeDiscretization::prepare_step:"
53 " Number of previous solutions must be at least "<<
54 m_prevSteps <<
", but only "<< prevSol->size() <<
" passed.\n");
63 m_futureTime = update_scaling(m_vScaleMass, m_vScaleStiff,
64 m_dt, m_pPrevSol->time(0),
70 this->m_spDomDisc->prepare_timestep(m_pPrevSol, m_futureTime);
72 UG_CATCH_THROW(
"MultiStepTimeDiscretization: Cannot prepare time step.");
75 template <
typename TAlgebra>
80 PROFILE_BEGIN_GROUP(MultiStepTimeDiscretization_step_elem,
"discretization MultiStepTimeDiscretization");
82 if(prevSol->size() < m_prevSteps)
83 UG_THROW(
"MultiStepTimeDiscretization::prepare_step_elem:"
84 " Number of previous solutions must be at least "<<
85 m_prevSteps <<
", but only "<< prevSol->size() <<
" passed.\n");
94 m_futureTime = update_scaling(m_vScaleMass, m_vScaleStiff,
95 m_dt, m_pPrevSol->time(0),
101 this->m_spDomDisc->prepare_timestep(m_pPrevSol, m_futureTime, gl);
103 UG_CATCH_THROW(
"MultiStepTimeDiscretization: Cannot prepare time step.");
107 this->m_spDomDisc->prepare_timestep_elem(m_pPrevSol, gl);
108 }
UG_CATCH_THROW(
"MultiStepTimeDiscretization: Cannot prepare timestep element-wise.");
111 template <
typename TAlgebra>
115 PROFILE_BEGIN_GROUP(MultiStepTimeDiscretization_assemble_jacobian,
"discretization MultiStepTimeDiscretization");
117 if(m_pPrevSol->size() < m_prevSteps)
118 UG_THROW(
"MultiStepTimeDiscretization::assemble_jacobian:"
119 " Number of previous solutions must be at least "<<
120 m_prevSteps <<
", but only "<< m_pPrevSol->size() <<
" passed.");
128 int DummyRefCount = 2;
130 m_pPrevSol->push(pU, m_futureTime);
134 this->m_spDomDisc->assemble_jacobian(J, m_pPrevSol, m_vScaleStiff[0], gl);
135 }
UG_CATCH_THROW(
"MultiStepTimeDiscretization: Cannot assemble jacobian.");
138 m_pPrevSol->remove_latest();
141 template <
typename TAlgebra>
145 PROFILE_BEGIN_GROUP(MultiStepTimeDiscretization_assemble_defect,
"discretization MultiStepTimeDiscretization");
147 if(m_pPrevSol->size() < m_prevSteps)
148 UG_THROW(
"MultiStepTimeDiscretization::assemble_defect:"
149 " Number of previous solutions must be at least "<<
150 m_prevSteps <<
", but only "<< m_pPrevSol->size() <<
" passed.");
158 int DummyRefCount = 2;
160 m_pPrevSol->push(pU, m_futureTime);
164 this->m_spDomDisc->assemble_defect(d, m_pPrevSol, m_vScaleMass, m_vScaleStiff, gl);
168 m_pPrevSol->remove_latest();
171 template <
typename TAlgebra>
175 PROFILE_BEGIN_GROUP(MultiStepTimeDiscretization_adjust_solution,
"discretization MultiStepTimeDiscretization");
178 this->m_spDomDisc->adjust_solution(u, m_futureTime, gl);
179 }
UG_CATCH_THROW(
"MultiStepTimeDiscretization: Cannot adjust solution.");
182 template <
typename TAlgebra>
186 PROFILE_BEGIN_GROUP(MultiStepTimeDiscretization_assemble_linear,
"discretization MultiStepTimeDiscretization");
188 if(m_pPrevSol->size() < m_prevSteps)
189 UG_THROW(
"MultiStepTimeDiscretization::assemble_linear:"
190 " Number of previous solutions must be at least "<<
191 m_prevSteps <<
", but only "<< m_pPrevSol->size() <<
" passed.");
195 m_pPrevSol->push(m_pPrevSol->latest(), m_futureTime);
199 this->m_spDomDisc->assemble_linear(A, b, m_pPrevSol, m_vScaleMass, m_vScaleStiff, gl);
200 }
UG_CATCH_THROW(
"MultiStepTimeDiscretization: Cannot assemble jacobian.");
203 m_pPrevSol->remove_latest();
206 template <
typename TAlgebra>
210 PROFILE_BEGIN_GROUP(MultiStepTimeDiscretization_assemble_rhs,
"discretization MultiStepTimeDiscretization");
212 if(m_pPrevSol->size() < m_prevSteps)
213 UG_THROW(
"MultiStepTimeDiscretization::assemble_linear:"
214 " Number of previous solutions must be at least "<<
215 m_prevSteps <<
", but only "<< m_pPrevSol->size() <<
" passed.");
218 m_pPrevSol->push(m_pPrevSol->latest(), m_futureTime);
222 this->m_spDomDisc->assemble_rhs(b, m_pPrevSol, m_vScaleMass, m_vScaleStiff, gl);
223 }
UG_CATCH_THROW(
"MultiStepTimeDiscretization: Cannot assemble jacobian.");
226 m_pPrevSol->remove_latest();
229 template <
typename TAlgebra>
233 PROFILE_BEGIN_GROUP(MultiStepTimeDiscretization_assemble_rhs,
"discretization MultiStepTimeDiscretization");
235 if(m_pPrevSol->size() < m_prevSteps)
236 UG_THROW(
"MultiStepTimeDiscretization::assemble_linear:"
237 " Number of previous solutions must be at least "<<
238 m_prevSteps <<
", but only "<< m_pPrevSol->size() <<
" passed.");
246 int DummyRefCount = 2;
248 m_pPrevSol->push(pU, m_futureTime);
252 this->m_spDomDisc->assemble_rhs(b, m_pPrevSol, m_vScaleMass, m_vScaleStiff, gl);
256 m_pPrevSol->remove_latest();
259 template<
typename TAlgebra>
263 PROFILE_BEGIN_GROUP(MultiStepTimeDiscretization_calc_error,
"discretization MultiStepTimeDiscretization");
265 if(m_pPrevSol->size() < m_prevSteps)
266 UG_THROW(
"MultiStepTimeDiscretization::calc_error:"
267 " Number of previous solutions must be at least "<<
268 m_prevSteps <<
", but only "<< m_pPrevSol->size() <<
" passed.");
276 int DummyRefCount = 2;
278 m_pPrevSol->push(pU, m_futureTime);
284 this->m_spDomDisc->calc_error(m_pPrevSol, m_vScaleMass, m_vScaleStiff, gl, u_vtk);
286 UG_CATCH_THROW(
"MultiStepTimeDiscretization: Cannot assemble error estimators.");
289 m_pPrevSol->remove_latest();
293 template <
typename TAlgebra>
298 if (currSol->time(0) != m_futureTime)
299 UG_THROW(
"MultiStepTimeDiscretization::finish_step:"
300 " The solution of the SolutionTimeSeries used in this function"
301 " does not coincide with the current solution! ");
306 this->m_spDomDisc->finish_timestep(currSol);
308 UG_CATCH_THROW(
"MultiStepTimeDiscretization: Cannot finish timestep.");
311 template <
typename TAlgebra>
317 if(currSol->time(0) != m_futureTime)
318 UG_THROW(
"MultiStepTimeDiscretization::finish_step_elem:"
319 " The solution of the SolutionTimeSeries used in this function"
320 " does not coincide with the current solution! ");
325 this->m_spDomDisc->finish_timestep(currSol, gl);
327 UG_CATCH_THROW(
"MultiStepTimeDiscretization: Cannot finish timestep.");
331 this->m_spDomDisc->finish_timestep_elem(currSol, gl);
332 }
UG_CATCH_THROW(
"MultiStepTimeDiscretization: Cannot finish timestep element-wise.");
338 template <
typename TAlgebra>
344 template <
typename TAlgebra>
346 std::vector<number>& vSA,
360 return m_Time0 + 1./2. * dt;
372 UG_THROW(
"Midpoint scheme has only 2 stages")
375 else if(m_order == 2)
377 const number gamma = 1 - 1. / sqrt(2.);
387 return m_Time0 + gamma * dt;
395 vSA[1] = dt * (1. - gamma);
399 UG_THROW(
"Alexander(2) scheme has only 2 stages")
402 else if(m_order == 3)
417 return m_Time0 +
alpha * dt;
425 vSA[1] = dt * (tau-
alpha);
427 return m_Time0 + tau * dt;
441 UG_THROW(
"Alexander(3) scheme has only 3 stages")
444 else if(m_order == 4)
455 return m_Time0 + 1./4. * dt;
465 return m_Time0 + 3./4. * dt;
474 vSA[1] = dt * (-1./25.);
475 vSA[2] = dt * 17./50.;
477 return m_Time0 + 11./20. * dt;
487 vSA[1] = dt * (15./544.);
488 vSA[2] = dt * (-137./2720.);
489 vSA[3] = dt * (371./1360.);
491 return m_Time0 + 1./2. * dt;
502 vSA[1] = dt * (-85./12.);
503 vSA[2] = dt * (125./16.);
504 vSA[3] = dt * (-49./48.);
505 vSA[4] = dt * (25./24.);
507 return m_Time0 + 1. * dt;
509 UG_THROW(
"HairerWanner(4) scheme has only 5 stages")
512 else if(m_order == 3)
514 const number gamma = (3. + sqrt(3.))/6.;
524 return m_Time0 + gamma * dt;
532 vSA[1] = dt * (1. - 2*gamma);
534 return m_Time0 + (1-gamma)*dt;
548 UG_THROW(
"Crouzeix 3 scheme has only 3 stages")
551 else if(m_order == 4)
553 const number gamma = 1./2. + cos(M_PI/18.) / sqrt(3.);
554 const number delta = 1./(6. * (2*gamma-1) * (2*gamma-1));
564 return m_Time0 + gamma * dt;
572 vSA[1] = dt * (1./2. - gamma);
574 return m_Time0 + 1./2.*dt;
583 vSA[1] = dt * (1-4*gamma);
584 vSA[2] = dt * 2*gamma;
586 return m_Time0 + (1-gamma)* dt;
597 vSA[2] = dt * (1-2*delta);
602 UG_THROW(
"Crouzeix 4 scheme has only 4 stages")
606 UG_THROW(
"SDIRK: "<< m_order <<
" missing.");
610 template <
typename TAlgebra>
619 m_Time0 = prevSol->time(0);
620 this->m_futureTime = m_Time0;
622 this->m_pPrevSol->push(prevSol->solution(0)->clone(), prevSol->time(0));
628 m_lastTime = this->m_futureTime;
630 this->m_futureTime = update_scaling(this->m_vScaleMass, this->m_vScaleStiff,
636 this->m_spDomDisc->prepare_timestep(this->m_pPrevSol, this->m_futureTime);
641 template <
typename TAlgebra>
655 int DummyRefCount = 2;
657 this->m_pPrevSol->push(pU, this->m_futureTime);
661 this->m_spDomDisc->assemble_jacobian(J, this->m_pPrevSol, this->m_vScaleStiff[0], gl);
665 this->m_pPrevSol->remove_latest();
668 template <
typename TAlgebra>
682 int DummyRefCount = 2;
684 this->m_pPrevSol->push(pU, this->m_futureTime);
688 this->m_spDomDisc->assemble_defect(d, this->m_pPrevSol, this->m_vScaleMass, this->m_vScaleStiff, gl);
692 this->m_pPrevSol->remove_latest();
695 template <
typename TAlgebra>
699 PROFILE_BEGIN_GROUP(MultiStepTimeDiscretization_adjust_solution,
"discretization MultiStepTimeDiscretization");
702 this->m_spDomDisc->adjust_solution(u, this->m_futureTime, gl);
706 template <
typename TAlgebra>
713 template <
typename TAlgebra>
720 template <
typename TAlgebra>
Definition: smart_pointer.h:108
Definition: grid_level.h:42
TAlgebra::vector_type vector_type
Type of algebra vector.
Definition: assemble_interface.h:119
TAlgebra::matrix_type matrix_type
Type of algebra matrix.
Definition: assemble_interface.h:116
algebra_type::vector_type vector_type
Type of algebra vector.
Definition: theta_time_step.h:66
void assemble_jacobian(matrix_type &J, const vector_type &u, const GridLevel &gl)
assembles Jacobian (or Approximation of Jacobian)
Definition: theta_time_step_impl.h:113
virtual void finish_step(SmartPtr< VectorTimeSeries< vector_type > > currSol)
Definition: theta_time_step_impl.h:295
virtual void finish_step_elem(SmartPtr< VectorTimeSeries< vector_type > > currSol, const GridLevel &gl)
Definition: theta_time_step_impl.h:313
virtual void prepare_step_elem(SmartPtr< VectorTimeSeries< vector_type > > prevSol, number dt, const GridLevel &gl)
prepares the assembling of Defect/Jacobian for a time step
Definition: theta_time_step_impl.h:77
virtual void prepare_step(SmartPtr< VectorTimeSeries< vector_type > > prevSol, number dt)
prepares the assembling of Defect/Jacobian for a time step
Definition: theta_time_step_impl.h:46
void adjust_solution(vector_type &u, const GridLevel &gl)
sets dirichlet values in solution vector
Definition: theta_time_step_impl.h:173
void assemble_defect(vector_type &d, const vector_type &u, const GridLevel &gl)
assembles Defect
Definition: theta_time_step_impl.h:143
void calc_error(const vector_type &u, error_vector_type *u_vtk)
Error estimator ///.
Definition: theta_time_step_impl.h:261
void assemble_linear(matrix_type &A, vector_type &b, const GridLevel &gl)
Assembles Matrix and Right-Hand-Side for a linear problem.
Definition: theta_time_step_impl.h:184
void assemble_rhs(vector_type &b, const vector_type &u, const GridLevel &gl)
assembles rhs
Definition: theta_time_step_impl.h:231
void assemble_jacobian(matrix_type &J, const vector_type &u, const GridLevel &gl)
assembles Jacobian (or Approximation of Jacobian)
Definition: theta_time_step_impl.h:643
void assemble_linear(matrix_type &A, vector_type &b, const GridLevel &gl)
Assembles Matrix and Right-Hand-Side for a linear problem.
Definition: theta_time_step_impl.h:708
void assemble_rhs(vector_type &b, const vector_type &u, const GridLevel &gl)
assembles rhs
Definition: theta_time_step_impl.h:722
virtual void prepare_step(SmartPtr< VectorTimeSeries< vector_type > > prevSol, number dt)
prepares the assembling of Defect/Jacobian for a time step
Definition: theta_time_step_impl.h:612
virtual void set_stage(size_t stage)
sets the stage
Definition: theta_time_step_impl.h:339
void assemble_defect(vector_type &d, const vector_type &u, const GridLevel &gl)
assembles Defect
Definition: theta_time_step_impl.h:670
void adjust_solution(vector_type &u, const GridLevel &gl)
sets dirichlet values in solution vector
Definition: theta_time_step_impl.h:697
virtual number update_scaling(std::vector< number > &vSM, std::vector< number > &vSA, number dt)
Definition: theta_time_step_impl.h:345
time series of solutions and corresponding time point
Definition: solution_time_series.h:59
#define UG_CATCH_THROW(msg)
Definition: error.h:64
#define UG_THROW(msg)
Definition: error.h:57
double number
Definition: types.h:124
#define PROFILE_BEGIN_GROUP(name, groups)
Definition: profiler.h:255