DOpE
crank_nicolson_problem.h
Go to the documentation of this file.
1 
24 #ifndef CRANKNICOLSONProblem_H_
25 #define CRANKNICOLSONProblem_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 CrankNicolsonProblem : public PrimalTSBase<OPTPROBLEM,
57  SPARSITYPATTERN, VECTOR, dopedim, dealdim, FE, DH>
58  {
59  public:
60  CrankNicolsonProblem(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 "Crank-Nicolson";
78  }
79  /******************************************************/
80 
82  CrankNicolsonProblem<OPTPROBLEM, SPARSITYPATTERN, VECTOR, dopedim,
83  dealdim, FE, DH>, VECTOR, dealdim>&
85  {
86  if (initial_problem_ == NULL)
87  {
88  initial_problem_ = new InitialProblem<
89  CrankNicolsonProblem<OPTPROBLEM, SPARSITYPATTERN, VECTOR,
90  dopedim, dealdim, FE, DH>, VECTOR, dealdim>(*this);
91  }
92  return *initial_problem_;
93  }
94 
95  /******************************************************/
96  CrankNicolsonProblem<OPTPROBLEM, SPARSITYPATTERN, VECTOR, dopedim,
97  dealdim, FE, DH>&
99  {
100  return *this;
101  }
102 
103  /******************************************************/
104 
105  template<typename EDC>
106  void
107  ElementEquation(const EDC & edc,
108  dealii::Vector<double> &local_vector, double scale, double /*scale_ico*/)
109  {
110  if (this->GetPart() == "New")
111  {
112  dealii::Vector<double> tmp(local_vector);
113 
114  tmp = 0.0;
115  // The remaining parts; e.g. for fluid problems: laplace, convection, etc.
116  // Multiplication by 1/2 due to CN discretization
117  this->GetProblem().ElementEquation(edc, tmp, 0.5 * scale, scale);
118  local_vector += tmp;
119 
120  tmp = 0.0;
121  this->GetProblem().ElementTimeEquation(edc, tmp,
122  scale);
123  local_vector += tmp;
124 
125  this->GetProblem().ElementTimeEquationExplicit(edc, local_vector,
126  scale);
127 
128  }
129  else if (this->GetPart() == "Old")
130  {
131  dealii::Vector<double> tmp(local_vector);
132  tmp = 0.0;
133 
134  // The explicit parts with old_time_values; e.g. for fluid problems: laplace, convection, etc.
135  // Multiplication by 1/2 due to CN discretization
136  this->GetProblem().ElementEquation(edc, tmp, 0.5 * scale, 0.);
137  local_vector += tmp;
138 
139  this->GetProblem().ElementTimeEquation(
140  edc,
141  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  this->GetProblem().ElementRhs(edc, local_vector, 0.5 * scale);
160  }
161  else if (this->GetPart() == "Old")
162  {
163  this->GetProblem().ElementRhs(edc, local_vector, 0.5 * scale);
164  }
165  else
166  {
167  abort();
168  }
169  }
170 
171  /******************************************************/
172 
173  void
175  const std::map<std::string, const dealii::Vector<double>*> &param_values,
176  const std::map<std::string, const VECTOR*> &domain_values,
177  VECTOR& rhs_vector, double scale)
178  {
179  if (this->GetPart() == "New")
180  {
181  this->GetProblem().PointRhs(param_values, domain_values, rhs_vector,
182  0.5 * scale);
183  }
184  else if (this->GetPart() == "Old")
185  {
186  this->GetProblem().PointRhs(param_values, domain_values, rhs_vector,
187  (0.5) * scale);
188  }
189  else
190  {
191  abort();
192  }
193  }
194 
195  /******************************************************/
196 
197  template<typename EDC>
198  void
199  ElementMatrix(const EDC & edc,
200  dealii::FullMatrix<double> &local_matrix)
201  {
202  assert(this->GetPart() == "New");
203  dealii::FullMatrix<double> m(local_matrix);
204 
205  // multiplication with 1/2 for scale due to CN discretization,
206  //no multiplication with 1/2 for scale_ico due to implicit treatment of pressure, etc. (in the case of fluid problems)
207  this->GetProblem().ElementMatrix(edc, local_matrix, 0.5, 1.);
208 
209  m = 0.;
210  this->GetProblem().ElementTimeMatrix(edc, m);
211  local_matrix.add(
212  1.0 , m);
213 
214  m = 0.;
215  this->GetProblem().ElementTimeMatrixExplicit(edc, m);
216  local_matrix.add(
217  1.0 , m);
218  }
219 
220  /******************************************************/
221 
222  template<typename FDC>
223  void
224  FaceEquation(const FDC & fdc,
225  dealii::Vector<double> &local_vector, double scale, double /*scale_ico*/)
226  {
227  if (this->GetPart() == "New")
228  {
229  this->GetProblem().FaceEquation(fdc, local_vector, 0.5 * scale, scale);
230  }
231  else if (this->GetPart() == "Old")
232  {
233  this->GetProblem().FaceEquation(fdc, local_vector, 0.5 * scale,0.);
234  }
235  else
236  {
237  abort();
238  }
239 
240  }
241 
242  /******************************************************/
243 
244  template<typename FDC>
245  void
246  InterfaceEquation(const FDC & fdc,
247  dealii::Vector<double> &local_vector, double scale, double /*scale_ico*/)
248  {
249  if (this->GetPart() == "New")
250  {
251  this->GetProblem().InterfaceEquation(fdc, local_vector,
252  0.5 * scale, scale);
253  }
254  else if (this->GetPart() == "Old")
255  {
256  this->GetProblem().InterfaceEquation(fdc, local_vector,
257  0.5 * scale, 0.);
258  }
259  else
260  {
261  abort();
262  }
263 
264  }
265 
266  /******************************************************/
267 
268  template<typename FDC>
269  void
270  FaceRhs(const FDC & fdc,
271  dealii::Vector<double> &local_vector, double scale = 1.)
272  {
273  this->GetProblem().FaceRhs(fdc, local_vector, scale);
274  }
275 
276  /******************************************************/
277 
278  template<typename FDC>
279  void
280  FaceMatrix(const FDC & fdc,
281  dealii::FullMatrix<double> &local_matrix)
282  {
283  assert(this->GetPart() == "New");
284  // Hier nicht mit this->GetProblem().GetBaseProblem().GetSpaceTimeHandler()->GetStepSize() multiplizieren, da local_matrix schon skaliert ist
285  dealii::FullMatrix<double> m(local_matrix);
286 
287  m = 0.;
288  // Multiplication with 1/2 due to CN time discretization
289  this->GetProblem().FaceMatrix(fdc, m, 0.5, 1.);
290 
291  local_matrix.add(1., m);
292  }
293 
294  /******************************************************/
295 
296  template<typename FDC>
297  void
298  InterfaceMatrix(const FDC & fdc,
299  dealii::FullMatrix<double> &local_matrix)
300  {
301  assert(this->GetPart() == "New");
302  dealii::FullMatrix<double> m(local_matrix);
303 
304  m = 0.;
305  // Multiplication with 1/2 due to CN time discretization
306  this->GetProblem().InterfaceMatrix(fdc, m, 0.5, 1.);
307 
308  local_matrix.add(1., m);
309  }
310 
311  /******************************************************/
312 
313  template<typename FDC>
314  void
315  BoundaryEquation(const FDC & fdc,
316  dealii::Vector<double> &local_vector, double scale, double /*scale_ico*/)
317  {
318  if (this->GetPart() == "New")
319  {
320  this->GetProblem().BoundaryEquation(fdc, local_vector, 0.5 * scale, scale);
321  }
322  else if (this->GetPart() == "Old")
323  {
324  this->GetProblem().BoundaryEquation(fdc, local_vector, 0.5 * scale, 0.);
325  }
326  else
327  {
328  abort();
329  }
330 
331  }
332 
333  /******************************************************/
334 
335  template<typename FDC>
336  void
337  BoundaryRhs(const FDC & fdc,
338  dealii::Vector<double> &local_vector, double scale)
339  {
340  this->GetProblem().BoundaryRhs(fdc, local_vector, scale);
341  }
342 
343  /******************************************************/
344 
345  template<typename FDC>
346  void
347  BoundaryMatrix(const FDC & fdc,
348  dealii::FullMatrix<double> &local_matrix)
349  {
350  assert(this->GetPart() == "New");
351  dealii::FullMatrix<double> m(local_matrix);
352 
353  m = 0.;
354  // Multiplication with 1/2 due to CN time discretization
355  this->GetProblem().BoundaryMatrix(fdc, m, 0.5, 1.);
356  local_matrix.add(1., m);
357 
358  }
359  private:
361  };
362 }
363 
364 #endif
void ElementEquation(const EDC &edc, dealii::Vector< double > &local_vector, double scale, double)
Definition: crank_nicolson_problem.h:107
~CrankNicolsonProblem()
Definition: crank_nicolson_problem.h:66
void BoundaryEquation(const FDC &fdc, dealii::Vector< double > &local_vector, double scale, double)
Definition: crank_nicolson_problem.h:315
InitialProblem< CrankNicolsonProblem< OPTPROBLEM, SPARSITYPATTERN, VECTOR, dopedim, dealdim, FE, DH >, VECTOR, dealdim > & GetInitialProblem()
Definition: crank_nicolson_problem.h:84
void FaceRhs(const FDC &fdc, dealii::Vector< double > &local_vector, double scale=1.)
Definition: crank_nicolson_problem.h:270
void FaceEquation(const FDC &fdc, dealii::Vector< double > &local_vector, double scale, double)
Definition: crank_nicolson_problem.h:224
Definition: primal_ts_base.h:49
CrankNicolsonProblem(OPTPROBLEM &OP)
Definition: crank_nicolson_problem.h:60
void ElementRhs(const EDC &edc, dealii::Vector< double > &local_vector, double scale)
Definition: crank_nicolson_problem.h:154
void ElementMatrix(const EDC &edc, dealii::FullMatrix< double > &local_matrix)
Definition: crank_nicolson_problem.h:199
Definition: initialproblem.h:42
std::string GetName()
Definition: crank_nicolson_problem.h:75
void InterfaceMatrix(const FDC &fdc, dealii::FullMatrix< double > &local_matrix)
Definition: crank_nicolson_problem.h:298
OPTPROBLEM & GetProblem()
Definition: ts_base.h:480
void BoundaryRhs(const FDC &fdc, dealii::Vector< double > &local_vector, double scale)
Definition: crank_nicolson_problem.h:337
Definition: crank_nicolson_problem.h:56
void FaceMatrix(const FDC &fdc, dealii::FullMatrix< double > &local_matrix)
Definition: crank_nicolson_problem.h:280
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: crank_nicolson_problem.h:174
void InterfaceEquation(const FDC &fdc, dealii::Vector< double > &local_vector, double scale, double)
Definition: crank_nicolson_problem.h:246
void BoundaryMatrix(const FDC &fdc, dealii::FullMatrix< double > &local_matrix)
Definition: crank_nicolson_problem.h:347
CrankNicolsonProblem< OPTPROBLEM, SPARSITYPATTERN, VECTOR, dopedim, dealdim, FE, DH > & GetBaseProblem()
Definition: crank_nicolson_problem.h:98