DOpE
shifted_crank_nicolson_problem.h
Go to the documentation of this file.
1 
24 #ifndef SHIFTEDCRANKNICOLSONProblem_H_
25 #define SHIFTEDCRANKNICOLSONProblem_H_
26 
27 #include "initialproblem.h"
28 #include "primal_ts_base.h"
29 
30 namespace DOpE
31 {
52  template<typename OPTPROBLEM, typename SPARSITYPATTERN, typename VECTOR,
53  int dopedim, int dealdim,
54  template<int, int> class FE = dealii::FESystem,
55  template<int, int> class DH = dealii::DoFHandler>
56  class ShiftedCrankNicolsonProblem : public PrimalTSBase<OPTPROBLEM,
57  SPARSITYPATTERN, VECTOR, dopedim, dealdim, FE, DH>
58  {
59  public:
60  ShiftedCrankNicolsonProblem(OPTPROBLEM& OP) :
61  PrimalTSBase<OPTPROBLEM, SPARSITYPATTERN, VECTOR, dopedim, dealdim,
62  FE, DH>(OP)
63  {
64  initial_problem_ = NULL;
65  }
67  {
68  if (initial_problem_ != NULL)
69  delete initial_problem_;
70  }
71 
72  /******************************************************/
73 
74  std::string
76  {
77  return "shifted Crank-Nicolson";
78  }
79  /******************************************************/
80 
83  {
84  if (initial_problem_ == NULL)
85  {
86  initial_problem_ = new InitialProblem<ShiftedCrankNicolsonProblem,
87  VECTOR, dealdim>(*this);
88  }
89  return *initial_problem_;
90  }
91 
92  /******************************************************/
95  {
96  return *this;
97  }
98 
99  /******************************************************/
100 
101  template<typename EDC>
102  void
103  ElementEquation(const EDC& dc,
104  dealii::Vector<double> &local_vector, double scale, double /*scale_ico*/)
105  {
106  if (this->GetPart() == "New")
107  {
108  damped_cn_theta = 0.5
109  + this->GetProblem().GetBaseProblem().GetSpaceTimeHandler()->GetStepSize();
110 
111  dealii::Vector<double> tmp(local_vector);
112  tmp = 0.0;
113  // implicit parts; e.g. for fluid problems: pressure and incompressibilty of v, get scaled with scale
114  // The remaining parts; e.g. for fluid problems: laplace, convection, etc.:
115  // Multiplication by 1/2 + k due to CN discretization
116 
117  this->GetProblem().ElementEquation(dc, tmp, damped_cn_theta * scale , scale);
118  local_vector += tmp;
119 
120  tmp = 0.0;
121  this->GetProblem().ElementTimeEquation(dc, tmp,
122  scale);
123  local_vector += tmp;
124 
125  this->GetProblem().ElementTimeEquationExplicit(dc, local_vector,
126  scale);
127  }
128  else if (this->GetPart() == "Old")
129  {
130  damped_cn_theta = 0.5
131  + this->GetProblem().GetBaseProblem().GetSpaceTimeHandler()->GetStepSize();
132 
133  dealii::Vector<double> tmp(local_vector);
134  tmp = 0.0;
135 
136  // The explicit parts with old_time_values; e.g. for fluid problems: laplace, convection, etc.
137  // Multiplication by 1/2 + k due to CN discretization
138  this->GetProblem().ElementEquation(dc, tmp, (1.0 - damped_cn_theta) * scale, 0.);
139  local_vector += tmp;
140 
141  this->GetProblem().ElementTimeEquation(dc, local_vector,
142  (-1) * scale);
143  }
144  else
145  {
146  abort();
147  }
148  }
149 
150  /******************************************************/
151 
152  template<typename EDC>
153  void
154  ElementRhs(const EDC& edc,
155  dealii::Vector<double> &local_vector, double scale)
156  {
157  if (this->GetPart() == "New")
158  {
159  damped_cn_theta = 0.5
160  + this->GetProblem().GetBaseProblem().GetSpaceTimeHandler()->GetStepSize();
161  this->GetProblem().ElementRhs(edc, local_vector, damped_cn_theta * scale);
162  }
163  else if (this->GetPart() == "Old")
164  {
165  damped_cn_theta = 0.5
166  + this->GetProblem().GetBaseProblem().GetSpaceTimeHandler()->GetStepSize();
167  this->GetProblem().ElementRhs(edc, local_vector,
168  (1 - damped_cn_theta) * scale);
169  }
170  else
171  {
172  abort();
173  }
174  }
175 
176  /******************************************************/
177 
178  void
180  const std::map<std::string, const dealii::Vector<double>*> &param_values,
181  const std::map<std::string, const VECTOR*> &domain_values,
182  VECTOR& rhs_vector, double scale)
183  {
184  if (this->GetPart() == "New")
185  {
186  damped_cn_theta = 0.5
187  + this->GetProblem().GetBaseProblem().GetSpaceTimeHandler()->GetStepSize();
188  this->GetProblem().PointRhs(param_values, domain_values, rhs_vector,
189  damped_cn_theta * scale);
190  }
191  else if (this->GetPart() == "Old")
192  {
193  damped_cn_theta = 0.5
194  + this->GetProblem().GetBaseProblem().GetSpaceTimeHandler()->GetStepSize();
195  this->GetProblem().PointRhs(param_values, domain_values, rhs_vector,
196  (1 - damped_cn_theta) * scale);
197  }
198  else
199  {
200  abort();
201  }
202  }
203 
204  /******************************************************/
205 
206  template<typename EDC>
207  void
208  ElementMatrix(const EDC& edc,
209  dealii::FullMatrix<double> &local_matrix)
210  {
211  assert(this->GetPart() == "New");
212  damped_cn_theta = 0.5
213  + this->GetProblem().GetBaseProblem().GetSpaceTimeHandler()->GetStepSize();
214  dealii::FullMatrix<double> m(local_matrix);
215 
216  // multiplication with 1/2 + k due to CN discretization for the 'normal' parts
217  // no multiplication with 1/2 + k for the implicit parts
218  //due to implicit treatment of pressure, etc. (in the case of fluid problems)
219  this->GetProblem().ElementMatrix(edc, local_matrix, damped_cn_theta, 1.);
220 
221  m = 0.;
222  this->GetProblem().ElementTimeMatrix(edc, m);
223  local_matrix.add(
224  1.0,
225  m);
226 
227  m = 0.;
228  this->GetProblem().ElementTimeMatrixExplicit(edc, m);
229  local_matrix.add(
230  1.0,
231  m);
232  }
233 
234  /******************************************************/
235 
236  template<typename FDC>
237  void
238  FaceEquation(const FDC& fdc,
239  dealii::Vector<double> &local_vector, double scale, double /*scale_ico*/)
240  {
241  if (this->GetPart() == "New")
242  {
243  damped_cn_theta = 0.5
244  + this->GetProblem().GetBaseProblem().GetSpaceTimeHandler()->GetStepSize();
245  this->GetProblem().FaceEquation(fdc, local_vector, damped_cn_theta * scale, scale);
246  }
247  else if (this->GetPart() == "Old")
248  {
249  damped_cn_theta = 0.5
250  + this->GetProblem().GetBaseProblem().GetSpaceTimeHandler()->GetStepSize();
251  this->GetProblem().FaceEquation(fdc, local_vector, (1.0 - damped_cn_theta) * scale, 0.);
252  }
253  else
254  {
255  abort();
256  }
257 
258  }
259 
260  /******************************************************/
261 
262  template<typename FDC>
263  void
264  InterfaceEquation(const FDC& fdc,
265  dealii::Vector<double> &local_vector, double scale, double /*scale_ico*/)
266  {
267  if (this->GetPart() == "New")
268  {
269  damped_cn_theta = 0.5
270  + this->GetProblem().GetBaseProblem().GetSpaceTimeHandler()->GetStepSize();
271  this->GetProblem().InterfaceEquation(fdc, local_vector,
272  damped_cn_theta * scale,scale );
273  }
274  else if (this->GetPart() == "Old")
275  {
276  damped_cn_theta = 0.5
277  + this->GetProblem().GetBaseProblem().GetSpaceTimeHandler()->GetStepSize();
278  this->GetProblem().InterfaceEquation(fdc, local_vector, (1.0 - damped_cn_theta) * scale, 0.);
279  }
280  else
281  {
282  abort();
283  }
284 
285  }
286 
287  /******************************************************/
288 
289  template<typename FDC>
290  void
291  FaceRhs(const FDC& fdc,
292  dealii::Vector<double> &local_vector, double scale = 1.)
293  {
294  this->GetProblem().FaceRhs(fdc, local_vector, scale);
295  }
296 
297  /******************************************************/
298 
299  template<typename FDC>
300  void
301  FaceMatrix(const FDC& fdc,
302  dealii::FullMatrix<double> &local_matrix)
303  {
304  assert(this->GetPart() == "New");
305  damped_cn_theta = 0.5
306  + this->GetProblem().GetBaseProblem().GetSpaceTimeHandler()->GetStepSize();
307 
308  dealii::FullMatrix<double> m(local_matrix);
309 
310  m = 0.;
311  // Multiplication with 1/2 + k due to CN time discretization
312  this->GetProblem().FaceMatrix(fdc, m, damped_cn_theta, 1.);
313 
314  local_matrix.add(1., m);
315 
316  }
317 
318  /******************************************************/
319 
320  template<typename FDC>
321  void
322  InterfaceMatrix(const FDC& fdc,
323  dealii::FullMatrix<double> &local_matrix)
324  {
325  assert(this->GetPart() == "New");
326  damped_cn_theta = 0.5
327  + this->GetProblem().GetBaseProblem().GetSpaceTimeHandler()->GetStepSize();
328 
329  dealii::FullMatrix<double> m(local_matrix);
330 
331  m = 0.;
332  // Multiplication with 1/2 + k due to CN time discretization
333  this->GetProblem().InterfaceMatrix(fdc, m, damped_cn_theta, 1.);
334 
335  local_matrix.add(1., m);
336 
337  }
338 
339  /******************************************************/
340 
341  template<typename FDC>
342  void
343  BoundaryEquation(const FDC& fdc,
344  dealii::Vector<double> &local_vector, double scale, double /*scale_ico*/)
345  {
346  if (this->GetPart() == "New")
347  {
348  damped_cn_theta = 0.5
349  + this->GetProblem().GetBaseProblem().GetSpaceTimeHandler()->GetStepSize();
350  this->GetProblem().BoundaryEquation(fdc, local_vector,
351  damped_cn_theta * scale,scale);
352  }
353  else if (this->GetPart() == "Old")
354  {
355  damped_cn_theta = 0.5
356  + this->GetProblem().GetBaseProblem().GetSpaceTimeHandler()->GetStepSize();
357  this->GetProblem().BoundaryEquation(fdc, local_vector,
358  (1.0 - damped_cn_theta) * scale, 0.);
359  }
360  else
361  {
362  abort();
363  }
364 
365  }
366 
367  /******************************************************/
368 
369  template<typename FDC>
370  void
371  BoundaryRhs(const FDC& fdc,
372  dealii::Vector<double> &local_vector, double scale)
373  {
374  this->GetProblem().BoundaryRhs(fdc, local_vector, scale);
375  }
376 
377  /******************************************************/
378 
379  template<typename FDC>
380  void
381  BoundaryMatrix(const FDC& fdc,
382  dealii::FullMatrix<double> &local_matrix)
383  {
384  assert(this->GetPart() == "New");
385  damped_cn_theta = 0.5
386  + this->GetProblem().GetBaseProblem().GetSpaceTimeHandler()->GetStepSize();
387  dealii::FullMatrix<double> m(local_matrix);
388 
389  m = 0.;
390  // Multiplication with 1/2 + k due to CN time discretization
391  this->GetProblem().BoundaryMatrix(fdc, m, damped_cn_theta, 1.);
392  local_matrix.add(1., m);
393 
394  }
395 
396  private:
397  double damped_cn_theta;
399  };
400 }
401 
402 #endif
void BoundaryEquation(const FDC &fdc, dealii::Vector< double > &local_vector, double scale, double)
Definition: shifted_crank_nicolson_problem.h:343
void BoundaryMatrix(const FDC &fdc, dealii::FullMatrix< double > &local_matrix)
Definition: shifted_crank_nicolson_problem.h:381
void FaceMatrix(const FDC &fdc, dealii::FullMatrix< double > &local_matrix)
Definition: shifted_crank_nicolson_problem.h:301
InitialProblem< ShiftedCrankNicolsonProblem, VECTOR, dealdim > & GetInitialProblem()
Definition: shifted_crank_nicolson_problem.h:82
void ElementEquation(const EDC &dc, dealii::Vector< double > &local_vector, double scale, double)
Definition: shifted_crank_nicolson_problem.h:103
Definition: primal_ts_base.h:49
void FaceEquation(const FDC &fdc, dealii::Vector< double > &local_vector, double scale, double)
Definition: shifted_crank_nicolson_problem.h:238
std::string GetName()
Definition: shifted_crank_nicolson_problem.h:75
ShiftedCrankNicolsonProblem(OPTPROBLEM &OP)
Definition: shifted_crank_nicolson_problem.h:60
Definition: shifted_crank_nicolson_problem.h:56
void InterfaceMatrix(const FDC &fdc, dealii::FullMatrix< double > &local_matrix)
Definition: shifted_crank_nicolson_problem.h:322
Definition: initialproblem.h:42
~ShiftedCrankNicolsonProblem()
Definition: shifted_crank_nicolson_problem.h:66
void BoundaryRhs(const FDC &fdc, dealii::Vector< double > &local_vector, double scale)
Definition: shifted_crank_nicolson_problem.h:371
void ElementRhs(const EDC &edc, dealii::Vector< double > &local_vector, double scale)
Definition: shifted_crank_nicolson_problem.h:154
OPTPROBLEM & GetProblem()
Definition: ts_base.h:480
void FaceRhs(const FDC &fdc, dealii::Vector< double > &local_vector, double scale=1.)
Definition: shifted_crank_nicolson_problem.h:291
ShiftedCrankNicolsonProblem & GetBaseProblem()
Definition: shifted_crank_nicolson_problem.h:94
std::string GetPart() const
Definition: ts_base.h:493
void PointRhs(const std::map< std::string, const dealii::Vector< double > * > &param_values, const std::map< std::string, const VECTOR * > &domain_values, VECTOR &rhs_vector, double scale)
Definition: shifted_crank_nicolson_problem.h:179
void ElementMatrix(const EDC &edc, dealii::FullMatrix< double > &local_matrix)
Definition: shifted_crank_nicolson_problem.h:208
void InterfaceEquation(const FDC &fdc, dealii::Vector< double > &local_vector, double scale, double)
Definition: shifted_crank_nicolson_problem.h:264