Plugins
linear_implicit_timestep.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014-2016: G-CSC, Goethe University Frankfurt
3  * Author: Arne Naegel
4  *
5  * This file is part of UG4.
6  *
7  * UG4 is free software: you can redistribute it and/or modify it under the
8  * terms of the GNU Lesser General Public License version 3 (as published by the
9  * Free Software Foundation) with the following additional attribution
10  * requirements (according to LGPL/GPL v3 §7):
11  *
12  * (1) The following notice must be displayed in the Appropriate Legal Notices
13  * of covered and combined works: "Based on UG4 (www.ug4.org/license)".
14  *
15  * (2) The following notice must be displayed at a prominent place in the
16  * terminal output of covered works: "Based on UG4 (www.ug4.org/license)".
17  *
18  * (3) The following bibliography is recommended for citation and must be
19  * preserved in all covered files:
20  * "Reiter, S., Vogel, A., Heppner, I., Rupp, M., and Wittum, G. A massively
21  * parallel geometric multigrid solver on hierarchically distributed grids.
22  * Computing and visualization in science 16, 4 (2013), 151-164"
23  * "Vogel, A., Reiter, S., Rupp, M., Nägel, A., and Wittum, G. UG4 -- a novel
24  * flexible software system for simulating pde based models on high performance
25  * computers. Computing and visualization in science 16, 4 (2013), 165-179"
26  *
27  * This program is distributed in the hope that it will be useful,
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30  * GNU Lesser General Public License for more details.
31  */
32 
33 #ifndef LIMEX_H_
34 #define LIMEX_H_
35 
36 // extern libraries
37 #include <vector>
38 #include <cmath>
39 
40 // ug libraries
41 #include "common/common.h"
43 
48 
51 
52 namespace ug{
53 
57 
69 template <class TAlgebra>
71 : public ITimeDiscretization<TAlgebra>,
72  public DebugWritingObject<TAlgebra>
73 
74 {
75 public:
78 
80  typedef TAlgebra algebra_type;
81 
84 
87 
90 
91 public:
94  : ITimeDiscretization<TAlgebra>(spDD),
95  m_pPrevSol(NULL),
96  m_dt(0.0),
97  m_futureTime(0.0),
100  m_useCachedMatrices(true)
101  {}
102 
106  : ITimeDiscretization<TAlgebra>(spDefectDisc),
107  m_pPrevSol(NULL),
108  m_dt(0.0),
109  m_futureTime(0.0),
112  m_useCachedMatrices(true)
113  {}
114 
119  : ITimeDiscretization<TAlgebra>(spDefectDisc),
120  m_pPrevSol(NULL),
121  m_dt(0.0),
122  m_futureTime(0.0),
124  m_spGammaDisc(spGammaDisc), m_spGammaOp(SPNULL), m_bGammaNeedsUpdate(true),
125  m_useCachedMatrices(true)
126  {}
127 
129  virtual ~LinearImplicitEuler(){};
130 
131 public:
133  virtual size_t num_prev_steps() const {return m_prevSteps;}
134 
136  virtual void prepare_step(SmartPtr<VectorTimeSeries<vector_type> > prevSol,
137  number dt);
138 
141  number dt, const GridLevel& gl);
142 
145 
148  const GridLevel& gl);
149 
150  virtual number future_time() const {return m_futureTime;}
151 
152 public:
153 
155  void assemble_jacobian(matrix_type& J, const vector_type& u, const GridLevel& gl);
156 
158  void assemble_defect(vector_type& d, const vector_type& u, const GridLevel& gl);
159 
161  void assemble_linear(matrix_type& A, vector_type& b, const GridLevel& gl);
162 
163  void assemble_rhs(vector_type& b, const vector_type& u, const GridLevel& gl);
164 
165  void assemble_rhs(vector_type& b, const GridLevel& gl);
166 
167  void adjust_solution(vector_type& u, const GridLevel& gl);
168 
169  virtual size_t num_stages() const {return 1;};
170  virtual void set_stage(size_t stage) {};
171 
172 
176  bool use_linear_mode() const { return m_useLinearMode; }
177 
180  void set_matrix_cache(bool useCache) { m_useCachedMatrices = useCache; }
181 
182 protected:
183 
184  virtual number update_scaling(std::vector<number>& vSM,
185  std::vector<number>& vSA,
186  number dt, number currentTime,
188 
189  {
190  // resize scaling factors
191  vSM.resize(1);
192  vSM[0] = 1.0;
193 
194  vSA.resize(1);
195  vSA[0] = dt;
196 
197  return currentTime + dt;
198  }
199 
200  static const size_t m_prevSteps=1;
201  std::vector<number> m_vScaleMass;
202  std::vector<number> m_vScaleStiff;
203 
207 
208  // discretization for defect
210 
211 
212  // constant matrix $$ \tau J$$
217 
218  // Matrix: $\Gamma[u0, u0']$
222 
224 
226 
227 public:
228 
230  void invalidate()
231  {
233  m_bMatrixJNeedsUpdate = true;
235  }
236 
239  { m_spGammaOp = SPNULL; m_bGammaNeedsUpdate = true; }
240 
242  {m_spGammaDisc = spGammaDisc;}
243 
245 
246 protected:
249 
250 };
251 
252 // end group limex
254 
255 } // namespace ug
256 #endif
SmartPtr< IDomainDiscretization< TAlgebra > > m_spDomDisc
Definition: linear_implicit_timestep.h:74
ITimeDiscretization< TAlgebra > base_type
Type of base class.
Definition: linear_implicit_timestep.h:77
static const size_t m_prevSteps
number of previous steps needed.
Definition: linear_implicit_timestep.h:200
void disable_linear_mode()
Definition: linear_implicit_timestep.h:175
void assemble_jacobian(matrix_type &J, const vector_type &u, const GridLevel &gl)
Meant to assemble J(u) c = d(u), but abused here... (u not used!)
Definition: linear_implicit_timestep.cpp:195
virtual number future_time() const
Definition: linear_implicit_timestep.h:150
SmartPtr< AssembledLinearOperator< algebra_type > > m_spGammaOp
Gamma operator.
Definition: linear_implicit_timestep.h:220
algebra_type::vector_type vector_type
Type of algebra vector.
Definition: linear_implicit_timestep.h:86
SmartPtr< matrix_type > m_spMatrixCacheMk
Definition: linear_implicit_timestep.h:223
bool use_linear_mode() const
Definition: linear_implicit_timestep.h:176
SmartPtr< IDomainDiscretization< algebra_type > > m_spMatrixJDisc
Definition: linear_implicit_timestep.h:213
TAlgebra algebra_type
Type of algebra.
Definition: linear_implicit_timestep.h:80
LinearImplicitEuler(SmartPtr< IDomainDiscretization< algebra_type > > spDD)
CTOR.
Definition: linear_implicit_timestep.h:93
std::vector< number > m_vScaleMass
Scaling for mass part.
Definition: linear_implicit_timestep.h:201
void enable_linear_mode()
Some simplifications for linear systems. (In this case, the mass matrix is not re-assembled....
Definition: linear_implicit_timestep.h:174
LinearImplicitEuler(SmartPtr< IDomainDiscretization< algebra_type > > spDefectDisc, SmartPtr< IDomainDiscretization< algebra_type > > spMatrixJDisc, SmartPtr< IDomainDiscretization< algebra_type > > spGammaDisc)
CTOR.
Definition: linear_implicit_timestep.h:116
IDomainDiscretization< algebra_type > domain_discretization_type
Domain Discretization type.
Definition: linear_implicit_timestep.h:89
virtual size_t num_prev_steps() const
Definition: linear_implicit_timestep.h:133
virtual ~LinearImplicitEuler()
DTOR.
Definition: linear_implicit_timestep.h:129
bool m_bMatrixJNeedsUpdate
Definition: linear_implicit_timestep.h:215
virtual void set_stage(size_t stage)
Definition: linear_implicit_timestep.h:170
bool m_useCachedMatrices
Definition: linear_implicit_timestep.h:225
SmartPtr< IDomainDiscretization< algebra_type > > m_spGammaDisc
Gamma disc.
Definition: linear_implicit_timestep.h:219
void set_gamma_disc(SmartPtr< IDomainDiscretization< algebra_type > > spGammaDisc)
Definition: linear_implicit_timestep.h:241
void assemble_linear(matrix_type &A, vector_type &b, const GridLevel &gl)
Should return (M+tau A) delta = tau f.
Definition: linear_implicit_timestep.cpp:380
number m_futureTime
Future Time.
Definition: linear_implicit_timestep.h:206
void set_matrix_cache(bool useCache)
Definition: linear_implicit_timestep.h:180
SmartPtr< AssembledLinearOperator< algebra_type > > m_spMatrixJOp
Operator.
Definition: linear_implicit_timestep.h:214
void adjust_solution(vector_type &u, const GridLevel &gl)
Definition: linear_implicit_timestep.cpp:147
virtual void prepare_step(SmartPtr< VectorTimeSeries< vector_type > > prevSol, number dt)
Definition: linear_implicit_timestep.cpp:50
void assemble_defect(vector_type &d, const vector_type &u, const GridLevel &gl)
Meant to assemble d(u), but abused here... (u not used!)
Definition: linear_implicit_timestep.cpp:305
LinearImplicitEuler(SmartPtr< IDomainDiscretization< algebra_type > > spDefectDisc, SmartPtr< IDomainDiscretization< algebra_type > > spMatrixJDisc)
CTOR.
Definition: linear_implicit_timestep.h:104
void invalidate()
Invalidate all cached operators.
Definition: linear_implicit_timestep.h:230
bool m_useLinearMode
Definition: linear_implicit_timestep.h:216
virtual void finish_step(SmartPtr< VectorTimeSeries< vector_type > > currSol)
Definition: linear_implicit_timestep.h:144
algebra_type::matrix_type matrix_type
Type of algebra matrix.
Definition: linear_implicit_timestep.h:83
number m_dt
Time Step size.
Definition: linear_implicit_timestep.h:205
virtual void finish_step_elem(SmartPtr< VectorTimeSeries< vector_type > > currSol, const GridLevel &gl)
Definition: linear_implicit_timestep.cpp:163
virtual size_t num_stages() const
Definition: linear_implicit_timestep.h:169
virtual void prepare_step_elem(SmartPtr< VectorTimeSeries< vector_type > > prevSol, number dt, const GridLevel &gl)
Definition: linear_implicit_timestep.cpp:102
SmartPtr< VectorTimeSeries< vector_type > > m_pPrevSol
Previous solutions.
Definition: linear_implicit_timestep.h:204
void disable_matrix_cache()
Definition: linear_implicit_timestep.h:179
void assemble_rhs(vector_type &b, const vector_type &u, const GridLevel &gl)
Definition: linear_implicit_timestep.cpp:354
void invalidate_gamma()
Invalidate Gamma operator.
Definition: linear_implicit_timestep.h:238
virtual number update_scaling(std::vector< number > &vSM, std::vector< number > &vSA, number dt, number currentTime, ConstSmartPtr< VectorTimeSeries< vector_type > > prevSol)
Definition: linear_implicit_timestep.h:184
void enable_matrix_cache()
Definition: linear_implicit_timestep.h:178
std::vector< number > m_vScaleStiff
Scaling for stiffness part.
Definition: linear_implicit_timestep.h:202
bool m_bGammaNeedsUpdate
Definition: linear_implicit_timestep.h:221
ParallelMatrix< SparseMatrix< double > > matrix_type
ParallelVector< Vector< double > > vector_type
const NullSmartPtr SPNULL
double number