KASKADE 7 development version
workModel.hh
Go to the documentation of this file.
1/*
2 * workModel.hh
3 *
4 * Created on: May 4, 2015
5 * Author: sunayana_ghosh
6 */
7/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
8/* */
9/* This file is part of the library KASKADE 7 */
10/* https://www.zib.de/research/projects/kaskade7-finite-element-toolbox */
11/* */
12/* Copyright (C) 2015-2015 Zuse Institute Berlin */
13/* */
14/* KASKADE 7 is distributed under the terms of the ZIB Academic License. */
15/* see $KASKADE/academic.txt */
16/* */
17/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
18#ifndef KASKADE_TIMESTEPPING_EULERSDC_WORKMODEL_HH_
19#define KASKADE_TIMESTEPPING_EULERSDC_WORKMODEL_HH_
20
21//includes from current project
22#include "norm.hh"
23#include "util.hh"
24
25//includes from c, c++
26#include <cmath>
27#include <iostream>
28#include <vector>
29
30//includes from boost
31#include <boost/math/special_functions/round.hpp>
32#include <boost/math/tools/minima.hpp> //used for Brent's method to compute minima of a function
33
34//includes from DUNE
35#include "dune/common/dynmatrix.hh"
36#include "dune/common/dynvector.hh"
37
38namespace Kaskade {
39 //========================================================================================
40 // Implementation for enum class WorkModelType
41 //========================================================================================
42
48 //--C++11 strongly typed enums.
49 enum class WorkModelType {
50 ITERATION,
51 FED
52 };
53
61 //================================================================================================
62 // Implementation of the abstract base class WorkModel to compute the local tolerances.
63 //================================================================================================
64
71 template<class Vector, class Norm, class Utils>
73 {
74 public:
75 using field_type = typename Vector::value_type;
76 using RealVector = Dune::DynamicVector<double>;
77 using RealMatrix = Dune::DynamicMatrix<double>;
78
79
80
81 //pure virtual functions
82
93 virtual RealMatrix const& computeLocalTolerances(std::vector<Vector> const& yPrev,
94 std::vector<Vector> const& yCurrent,
95 std::vector<Vector> const& yNext) = 0;
96
106 virtual field_type lowerBoundIterJ(std::vector<Vector> const& yPrev,
107 std::vector<Vector> const& yCurrent,
108 field_type rho) = 0;
109
110
111 //virtual destructor
112 virtual ~WorkModel() {}
113 };
114
115 //========================================================================================================
116 // Implementation of the derived class Iteration representing the iteration work model.
117 //========================================================================================================
118
119 template<class Vector, class Norm, class Utils>
120 class Iteration : public WorkModel<Vector, Norm, Utils>
121 {
122 public:
123 using field_type = typename Vector::value_type;
124 using RealVector = Dune::DynamicVector<double>;
125 using RealMatrix = Dune::DynamicMatrix<double>;
126
127 //constructor for the derived class Iteration
129 std::vector<Vector> const& y0_, std::vector<Vector> const& y1_,
130 Norm& norm_, Utils& util_,
131 RealVector const& timePts_, RealMatrix const& integrationMatrix_,
132 field_type tolNewton_, int maxIterNewton_,
133 field_type rhoit_, int mmin_);
134
135 // function to compute cost
146 field_type computeCost(std::vector<Vector> const& yPrev,
147 std::vector<Vector> const& yCurrent,
148 std::vector<Vector> const& yNext,
149 RealMatrix const& tolMat);
150
151
161 field_type getIterJ(std::vector<Vector> const& yPrev,
162 std::vector<Vector> const& yCurrent,
163 std::vector<Vector> const& yNext,
164 field_type rho);
165
166
167 virtual RealMatrix const& computeLocalTolerances(std::vector<Vector> const& yPrev,
168 std::vector<Vector> const& yCurrent,
169 std::vector<Vector> const& yNext)
170 {
171 //To compute optimal local tolerances we first need the value of maxSDCIterations
172 auto rho = util.sdcContractionFactor(yPrev, yCurrent, yNext, norm);
173 //compute maxSDCIterations
174 auto maxSDCIterations = getIterJ(yPrev, yCurrent, yNext, rho);
175 //then we need to compute the value of mu which depends on maxSDCIterations
176 auto mu = computeMu(yPrev, yCurrent, rho, maxSDCIterations, nIntervals, tol, norm);
177 //compute the value of alphaVec
178 auto alphaVec = util.computeAlphaVec(timePts, integrationMatrix, yPrev, yCurrent, yNext);
179 //initialize the matrix
180 int itJ = (int) maxSDCIterations;
181 xijMat = RealMatrix(nIntervals, itJ, 0.0);
182 for (auto i = 0; i < nIntervals; ++i)
183 {
184 for (auto j = 0; j < itJ; ++j)
185 {
186 xijMat[i][j] = -1/(mu * std::pow(rho, itJ-1-j) * alphaVec[i]);
187 }
188 }
189 return xijMat;
190 }
191
192
193 //function computes the lower bound of maxSDCIterations
194 virtual field_type lowerBoundIterJ(std::vector<Vector> const& yPrev,
195 std::vector<Vector> const& yCurrent,
196 field_type rho)
197 {
198 auto val = Kaskade::normVecDiff(yPrev,yCurrent,norm);
199 auto lboundJ = std::log((1-rho) * tol / val) / std::log(rho);
200 return boost::math::round(lboundJ);
201 }
202
203
204 //delete later
205 field_type static f (std::vector<Vector> const& yPrev,
206 std::vector<Vector> const& yCurrent,
207 std::vector<Vector> const& yNext,
208 double rho)
209 {
210 auto yTotal = yPrev[0] + yCurrent[0] + yNext[0];
211 return (yTotal[0] + yTotal[1]) * rho;
212 }
213
214 //destructor
215 virtual ~Iteration(){}
216
217 private:
218 field_type tol;
219 std::vector<Vector> y0;
220 std::vector<Vector> y1;
221 Norm norm;
222 Utils util;
223 field_type normy01;
224 RealVector timePts;
225 RealMatrix integrationMatrix;
226 int nIntervals;
227 field_type maxPrecisionBrent = 20; //computation with 20 bit precision
228 field_type rhoit;
229 int mmin;
230 RealMatrix xijMat;
231
232 //private cost function
233
234 field_type static costFunction(std::vector<Vector> const& yPrev,
235 std::vector<Vector> const& yCurrent,
236 std::vector<Vector> const& yNext,
237 field_type maxSDCIterations,
238 Norm& norm,
239 Utils& util,
240 field_type normy01,
241 RealVector const& timePts,
242 RealMatrix const& integrationMatrix,
243 int nIntervals, field_type tol);
244
245
246 field_type static computeMu(std::vector<Vector> const& yPrev,
247 std::vector<Vector> const& yCurrent,
248 field_type rho,
249 field_type maxSDCIterations,
250 int nIntervals,
251 field_type tol,
252 Norm& norm);
253
254 field_type computeDerivativeMu(std::vector<Vector> const& yPrev,
255 std::vector<Vector> const& yCurrent,
256 field_type rho,
257 field_type maxSDCIterations);
258
259 field_type derivativeCostFunction(std::vector<Vector> const& yPrev,
260 std::vector<Vector> const& yCurrent,
261 field_type rho,
262 field_type alphaProd,
263 field_type c,
264 field_type maxSDCIterations);
265
266 //compute product of entries of alphaVec
267 field_type static computeProduct(RealVector const& alpha);
268
269
270 //This method is based on the ***assumption*** that cost function is monotonically decreasing
271 field_type computeIterJ(std::vector<Vector> const& yPrev,
272 std::vector<Vector> const& yCurrent,
273 std::vector<Vector> const& yNext,
274 field_type rho);
275
276
277 };
278
279
280 //=======================================================================================================
281 // Implementation of the derived class FiniteElementDiscretization representing the FED work model.
282 //======================================================================================================
283
284 template<class Vector, class Norm, class Utils>
285 class FiniteElementDiscretization : public WorkModel<Vector, Norm, Utils>
286 {
287 public:
288 using field_type = typename Vector::value_type;
289 using RealVector = Dune::DynamicVector<double>;
290 using RealMatrix = Dune::DynamicMatrix<double>;
291
292
293 //constructor for the derived class FiniteElementDiscretization
295 std::vector<Vector> const& y0_, std::vector<Vector> const& y1_,
296 Norm& norm_, Utils& util_,
297 RealVector const& timePts_, RealMatrix const& integrationMatrix_,
298 int dim_);
299
300
301 //function to compute cost
302 //(cannot be a pure virtual function since the parameters are different for different work models.)
303 field_type computeCost(RealMatrix const& tolMat);
304
305 field_type getIterJ(std::vector<Vector> const& yPrev,
306 std::vector<Vector> const& yCurrent,
307 field_type rho);
308
309 virtual RealMatrix const& computeLocalTolerances(std::vector<Vector> const& yPrev,
310 std::vector<Vector> const& yCurrent,
311 std::vector<Vector> const& yNext)
312 {
313 field_type d1 = 0.0;
314 field_type d2 = -1.0 / ((double) dim + 1.0);
315 auto rho = util.sdcContractionFactor(yPrev, yCurrent, yNext, norm);
316 //std::cout << "rho = " << rho << std::endl;
317 //compute max sdc iterations
318 maxSDCIterations = getIterJ(yPrev, yCurrent, rho);
319 auto alphaVec = util.computeAlphaVec(timePts, integrationMatrix, yPrev, yCurrent, yNext);
320 auto lambda = computeLambda(yPrev, yCurrent, yNext, maxSDCIterations);
321 //std::cout << "lambda = " << lambda << std::endl;
322 //initialize the matrix
323 int itJ = (int) maxSDCIterations;
324 xijMat = RealMatrix(nIntervals, itJ, 0.0);
325 for (auto i = 0; i < nIntervals; ++i)
326 {
327 auto val = std::pow(alphaVec[i], d2);
328 for (auto j = 0; j < itJ; ++j)
329 {
330 d1 = (maxSDCIterations-1-j)/(d2);
331 xijMat[i][j] = lambda * std::pow(rho, d1) * val;
332 }
333 }
334 return xijMat;
335 }
336
337
338 //function computes the lower bound of maxSDCIterations
339 virtual field_type lowerBoundIterJ(std::vector<Vector> const& yPrev,
340 std::vector<Vector> const& yCurrent,
341 field_type rho)
342 {
343 auto val = Kaskade::normVecDiff(yPrev, yCurrent, norm);
344 auto lboundJ = std::log((1-rho)*tol/val)/std::log(rho);
345 return boost::math::round(lboundJ);
346 }
347
348
349 //destructor
351
352 private:
353 field_type tol;
354 std::vector<Vector> y0;
355 std::vector<Vector> y1;
356 Norm norm;
357 field_type normy01;
358 Utils util;
359 RealVector timePts;
360 RealMatrix integrationMatrix;
361 int nIntervals;
362 int dim;
363 field_type maxSDCIterations;
364 RealMatrix xijMat;
365
366 //private methods
367 //computes A or B depending on the norm
368 field_type computeA(std::vector<Vector> const& yPrev,
369 std::vector<Vector> const& yCurrent,
370 std::vector<Vector> const& yNext);
371
372 field_type computeLambda(std::vector<Vector> const& yPrev,
373 std::vector<Vector> const& yCurrent,
374 std::vector<Vector> const& yNext,
375 field_type maxSDCIterations);
376 };
377
378 //=================================================================================================
379 // FUNCTION DEFINITION BEGINS FROM HERE
380 //=================================================================================================
381
382 //=================================================================================================
383 // ITERATION WORKMODEL
384 //=================================================================================================
385
386 //=================================================================================================
387 // Constructor for the class Iteration
388 //=================================================================================================
389
390 template<class Vector, class Norm, class Utils>
392 std::vector<Vector> const& y0_, std::vector<Vector> const& y1_,
393 Norm& norm_, Utils& util_,
394 RealVector const& timePts_, RealMatrix const& integrationMatrix_,
395 field_type tolNewton_, int maxPrecisionBrent_,
396 field_type rhoit_, int mmin_)
397 : tol(tol_), y0(y0_), y1(y1_),
398 norm(norm_), util(util_), normy01(Kaskade::normVecDiff(y0,y1,norm)),
399 timePts(timePts_), integrationMatrix(integrationMatrix_), nIntervals(timePts.size()-1),
400 maxPrecisionBrent(maxPrecisionBrent_),
401 rhoit(rhoit_), mmin(mmin_){}
402
403 //=================================================================================================
404 // Public member function for Iteration WorkModel to compute total cost.
405 //=================================================================================================
406
407 template<class Vector, class Norm, class Utils>
408 typename Vector::value_type Iteration<Vector, Norm, Utils>::computeCost(std::vector<Vector> const& yPrev,
409 std::vector<Vector> const& yCurrent,
410 std::vector<Vector> const& yNext,
411 RealMatrix const& tolMat)
412 {
413 //initialize the total cost
414 field_type totalCost = 0;
415 //compute SDC contraction factor
416 auto rho = util.sdcContractionFactor(yPrev, yCurrent, yNext, norm);
417 //compute c = log(|y1-y0|)
418 auto c = std::log(normy01);
419 //compute the constant k = -mmin * log(rhoit)
420 auto k = -mmin * std::log(rhoit);
421 //dimensions of the tolerance matrix
422 auto rows = tolMat.rows();
423 auto cols = tolMat.cols();
424 for (auto i = 0u; i < rows; ++i)
425 {
426 for (auto j = 0u; j < cols; ++j)
427 {
428 totalCost += std::max(k, c - std::log(tolMat[i][j]/std::pow(rho,j)));
429 }
430 }
431 return totalCost;
432 }
433
434 //=================================================================================================
435 // Public member function for Iteration WorkModel to get the maxSDCIterations.
436 //=================================================================================================
437 template<class Vector, class Norm, class Utils>
438 typename Vector::value_type Iteration<Vector, Norm, Utils>::getIterJ(std::vector<Vector> const& yPrev,
439 std::vector<Vector> const& yCurrent,
440 std::vector<Vector> const& yNext,
441 field_type rho)
442 {
443 auto maxSDCIterations = computeIterJ(yPrev, yCurrent, yNext, rho);
444 return boost::math::round(maxSDCIterations);
445 }
446
447
448 //=================================================================================================
449 // Private member function for Iteration WorkModel for the costFunction.
450 //=================================================================================================
451
452
453 //make it a static function, and do not use any private member variables.
454 template<class Vector, class Norm, class Utils>
455 typename Vector::value_type Iteration<Vector, Norm, Utils>::costFunction(std::vector<Vector> const& yPrev,
456 std::vector<Vector> const& yCurrent,
457 std::vector<Vector> const& yNext,
458 field_type maxSDCIterations,
459 Norm& norm,
460 Utils& util,
461 field_type normy01,
462 RealVector const& timePts,
463 RealMatrix const& integrationMatrix,
464 int nIntervals,
465 field_type tol)
466 {
467 //compute SDC contraction factor
468 auto rho = util.sdcContractionFactor(yPrev, yCurrent, yNext, norm);
469 //compute c = log(|y1-y0|)
470 auto c = std::log(normy01);
471 //compute mu
472 auto mu = computeMu(yPrev, yCurrent, rho, maxSDCIterations, nIntervals, tol, norm);
473 auto alphaVec = util.computeAlphaVec(timePts, integrationMatrix, yPrev, yCurrent, yNext);
474 auto alphaProd = computeProduct(alphaVec);
475 auto cost = nIntervals * c + nIntervals * maxSDCIterations * std::log(rho) + nIntervals * std::log(-mu) + std::log(alphaProd);
476 return cost;
477 }
478
479
480 //==========================================================================================================
481 // Private member function for Iteration WorkModel for computing the mu function as described in the paper
482 //==========================================================================================================
483 template<class Vector, class Norm, class Utils>
484 typename Vector::value_type Iteration<Vector, Norm, Utils>::computeMu(std::vector<Vector> const& yPrev,
485 std::vector<Vector> const& yCurrent,
486 field_type rho,
487 field_type maxSDCIterations,
488 int nIntervals,
489 field_type tol,
490 Norm& norm)
491 {
492 auto mu = -((1-rho) * (maxSDCIterations - 1) * nIntervals)/((1-rho) * tol - std::pow(rho, maxSDCIterations) * Kaskade::normVecDiff(yPrev,yCurrent,norm));
493 return mu;
494 }
495
496 //========================================================================================================================
497 // Private member function for Iteration WorkModel for computing the derivative of mu function as described in the paper
498 //========================================================================================================================
499 template<class Vector, class Norm, class Utils>
500 typename Vector::value_type Iteration<Vector, Norm, Utils>::computeDerivativeMu(std::vector<Vector> const& yPrev,
501 std::vector<Vector> const& yCurrent,
502 field_type rho,
503 field_type maxSDCIterations)
504 {
505 auto val = Kaskade::normVecDiff(yPrev,yCurrent,norm);
506 auto rhoJ = std::pow(rho, maxSDCIterations);
507 auto dervMu = nIntervals * (1-rho) *
508 (-(1-rho) * tol + val * rhoJ * (1 - (maxSDCIterations - 1) * std::log(rho)))/
509 (std::pow((rhoJ * val - (1-rho) * tol), 2));
510 return dervMu;
511 }
512
513 //========================================================================================================================
514 // Private member function for Iteration WorkModel for computing the derivative of cost Function
515 //========================================================================================================================
516 template<class Vector, class Norm, class Utils>
517 typename Vector::value_type Iteration<Vector, Norm, Utils>::derivativeCostFunction(std::vector<Vector> const& yPrev,
518 std::vector<Vector> const& yCurrent,
519 field_type rho,
520 field_type alphaProd,
521 field_type c,
522 field_type maxSDCIterations)
523 {
524
525 auto mu = computeMu(yPrev, yCurrent, rho, maxSDCIterations, nIntervals, tol, norm);
526 auto dervMu = computeDerivativeMu(yPrev, yCurrent, rho, maxSDCIterations);
527 auto dervCost = nIntervals * c + nIntervals * (2*maxSDCIterations - 1) * std::log(rho) + std::log(alphaProd)
528 + nIntervals * std::log(-mu) + nIntervals * (maxSDCIterations - 1) * dervMu/mu;
529 return dervCost;
530 }
531
532 //==========================================================================================================================
533 // Private member function for Iteration WorkModel for computing the product of alphaVector where all entries are positive
534 //==========================================================================================================================
535 template<class Vector, class Norm, class Utils>
536 typename Vector::value_type Iteration<Vector, Norm, Utils>::computeProduct(RealVector const& alpha)
537 {
538 field_type alphaProd = 1;
539 for(auto i = 0u; i < alpha.size(); ++i)
540 alphaProd *= alpha[i];
541
542 return alphaProd;
543 }
544
545 //============================================================================================
546 // Private member function for Iteration WorkModel for computing maxSDCIterations
547 //============================================================================================
548
549// //Use Brent's method to compute the minimum of the cost function
550// template<class Vector, class Norm, class Utils>
551// typename Vector::value_type Iteration<Vector, Norm, Utils>::computeIterJ(std::vector<Vector> const& yPrev,
552// std::vector<Vector> const& yCurrent,
553// std::vector<Vector> const& yNext,
554// field_type rho)
555// {
556// using Result = std::pair<double, double>;
557// //compute lower bound of maxSDCIterations to give as starting value for to Brent's method
558// field_type lbmaxSDCIterations = lowerBoundIterJ(yPrev, yCurrent, rho);
559// //initialize interval where the minima is searched
560// field_type left = lbmaxSDCIterations;
561// //initialize the lower bound on maxSDCIterations as input guess.
562// //auto func = std::bind(f, yPrev, yCurrent, yNext, std::placeholders::_1);
563// auto func = std::bind(costFunction, yPrev, yCurrent, yNext, std::placeholders::_1, norm, util, normy01,
564// timePts, integrationMatrix, nIntervals, tol);
565// Result soln = boost::math::tools::brent_find_minima(func, left, left+6, maxPrecisionBrent);
566//
567// return soln.first;
568// }
569
570 //Numeric method to find minimia of the function
571 template<class Vector, class Norm, class Utils>
572 typename Vector::value_type Iteration<Vector, Norm, Utils>::computeIterJ(std::vector<Vector> const& yPrev,
573 std::vector<Vector> const& yCurrent,
574 std::vector<Vector> const& yNext,
575 field_type rho)
576 {
577 //compute lower bound of maxSDCIterations
578 field_type lbmaxSDCIterations = lowerBoundIterJ(yPrev, yCurrent, rho);
579 field_type maxSDCIterations = lbmaxSDCIterations + 1;
580 //compute the cost at lbmaxSDCIterations
581 field_type minCost = costFunction(yPrev, yCurrent, yNext, lbmaxSDCIterations, norm, util, normy01,
582 timePts, integrationMatrix, nIntervals, tol);
583 field_type val = costFunction(yPrev, yCurrent, yNext, maxSDCIterations, norm, util, normy01,
584 timePts, integrationMatrix, nIntervals, tol);
585 while(val > minCost)
586 {
587 minCost = val;
588 maxSDCIterations++;
589 val = costFunction(yPrev, yCurrent, yNext, maxSDCIterations, norm, util, normy01,
590 timePts, integrationMatrix, nIntervals, tol);
591 }
592 return maxSDCIterations;
593 }
594
595
596
597 //=================================================================================================
598 // FINITE ELEMENT DISCRETIZATION WORKMODEL
599 //=================================================================================================
600
601 //=================================================================================================
602 // Constructor for the class FiniteElementDiscretization
603 //=================================================================================================
604 template<class Vector, class Norm, class Utils>
606 std::vector<Vector> const& y0_, std::vector<Vector> const& y1_,
607 Norm& norm_, Utils& util_,
608 RealVector const& timePts_, RealMatrix const& integrationMatrix_,
609 int dim_)
610 : tol(tol_),
611 y0(y0_), y1(y1_), norm(norm_), normy01(Kaskade::normVecDiff(y0, y1, norm)),
612 util(util_),
613 timePts(timePts_), integrationMatrix(integrationMatrix_), nIntervals(timePts.size()-1),
614 dim(dim_){}
615
616 //========================================================================================================
617 // Public member function computeCost for the class FiniteElementDiscretization, computes the total cost
618 //========================================================================================================
619 template<class Vector, class Norm, class Utils>
621 {
622 //initialize the total cost
623 field_type totalCost = 0.0;
624 //dimensions of the tolerance matrix
625 auto rows = tolMat.rows();
626 auto cols = tolMat.cols();
627 for (auto i = 0u; i < rows; ++i)
628 {
629 for (auto j = 0u; j < cols; ++j)
630 totalCost += 1/std::pow(tolMat[i][j], dim);
631 }
632 return totalCost;
633 }
634
635
636 //===========================================================================================================
637 // Public member function getIterJ for the class FiniteElementDiscretization, returns the maxSDCIterations
638 //===========================================================================================================
639 template<class Vector, class Norm, class Utils>
640 typename Vector::value_type FiniteElementDiscretization<Vector, Norm, Utils>::getIterJ(std::vector<Vector> const& yPrev,
641 std::vector<Vector> const& yCurrent,
642 field_type rho)
643 {
644 auto val = Kaskade::normVecDiff(yPrev, yCurrent, norm);
645 maxSDCIterations = (dim + 1)/(std::log(rho)) * std::log((1-rho)*tol / val);
646
647 return boost::math::round(maxSDCIterations);
648 }
649
650 //===============================================================================================================
651 // Private member function for FiniteElementDiscretization WorkModel for computing A or B depending on the norm
652 //===============================================================================================================
653 template<class Vector, class Norm, class Utils>
654 typename Vector::value_type FiniteElementDiscretization<Vector, Norm, Utils>::computeA(std::vector<Vector> const& yPrev,
655 std::vector<Vector> const& yCurrent,
656 std::vector<Vector> const& yNext)
657 {
658 //compute alphaVec
659 auto alphaVec = util.computeAlphaVec(timePts, integrationMatrix, yPrev, yCurrent, yNext);
660 //initialize alphaTildeVec
661 auto alphaTildeVec = RealVector(alphaVec.size(), 0.0);
662 //casting dim/(dim + 1) to double
663 double d = ((double) dim)/((double) dim + 1);
664 field_type sumAlphaTilde = 0.0;
665 //compute alphaTildeVec and A the sum of alphaTilde
666 for (auto i = 0u; i < alphaVec.size(); ++i)
667 {
668 alphaTildeVec[i] = std::pow(alphaVec[i], d);
669 sumAlphaTilde += alphaTildeVec[i];
670 }
671 return sumAlphaTilde;
672 }
673
674 //====================================================================================================================
675 // Private member function for FiniteElementDiscretization WorkModel for computing lambda as described in the paper.
676 //====================================================================================================================
677 template<class Vector, class Norm, class Utils>
678 typename Vector::value_type FiniteElementDiscretization<Vector, Norm, Utils>::computeLambda
679 (std::vector<Vector> const& yPrev,
680 std::vector<Vector> const& yCurrent,
681 std::vector<Vector> const& yNext,
682 field_type maxSDCIterations)
683 {
684 //compute rho, sdc-contraction factor
685 auto rho = util.sdcContractionFactor(yPrev, yCurrent, yNext, norm);
686 //casting
687 double d = ((double) dim)/((double) dim + 1);
688 field_type tildeRho = std::pow(rho, d);
689 auto sumAlphaTilde = computeA(yPrev, yCurrent, yNext);
690 auto val = Kaskade::normVecDiff(yPrev, yCurrent, norm);
691 auto lambda = ((1-rho) * tol - val * std::pow(rho, maxSDCIterations)) * (1 - tildeRho) / ((1 - rho) * (1 - std::pow(tildeRho, maxSDCIterations)) * sumAlphaTilde);
692
693 return lambda;
694 }
695
696} //end namespace Kaskade
697
698#endif /* KASKADE_TIMESTEPPING_EULERSDC_WORKMODEL_HH_ */
field_type computeCost(RealMatrix const &tolMat)
Definition: workModel.hh:620
FiniteElementDiscretization(field_type tol_, std::vector< Vector > const &y0_, std::vector< Vector > const &y1_, Norm &norm_, Utils &util_, RealVector const &timePts_, RealMatrix const &integrationMatrix_, int dim_)
Definition: workModel.hh:605
Dune::DynamicMatrix< double > RealMatrix
Definition: workModel.hh:290
typename Vector::value_type field_type
Definition: workModel.hh:288
virtual field_type lowerBoundIterJ(std::vector< Vector > const &yPrev, std::vector< Vector > const &yCurrent, field_type rho)
Definition: workModel.hh:339
virtual RealMatrix const & computeLocalTolerances(std::vector< Vector > const &yPrev, std::vector< Vector > const &yCurrent, std::vector< Vector > const &yNext)
Pure virtual function implemented in derived classes for different work models. Computes the local to...
Definition: workModel.hh:309
field_type getIterJ(std::vector< Vector > const &yPrev, std::vector< Vector > const &yCurrent, field_type rho)
Definition: workModel.hh:640
field_type computeCost(std::vector< Vector > const &yPrev, std::vector< Vector > const &yCurrent, std::vector< Vector > const &yNext, RealMatrix const &tolMat)
Definition: workModel.hh:408
typename Vector::value_type field_type
Definition: workModel.hh:123
field_type getIterJ(std::vector< Vector > const &yPrev, std::vector< Vector > const &yCurrent, std::vector< Vector > const &yNext, field_type rho)
Definition: workModel.hh:438
virtual RealMatrix const & computeLocalTolerances(std::vector< Vector > const &yPrev, std::vector< Vector > const &yCurrent, std::vector< Vector > const &yNext)
Pure virtual function implemented in derived classes for different work models. Computes the local to...
Definition: workModel.hh:167
virtual ~Iteration()
Definition: workModel.hh:215
Dune::DynamicMatrix< double > RealMatrix
Definition: workModel.hh:125
Iteration(field_type tol_, std::vector< Vector > const &y0_, std::vector< Vector > const &y1_, Norm &norm_, Utils &util_, RealVector const &timePts_, RealMatrix const &integrationMatrix_, field_type tolNewton_, int maxIterNewton_, field_type rhoit_, int mmin_)
Definition: workModel.hh:391
virtual field_type lowerBoundIterJ(std::vector< Vector > const &yPrev, std::vector< Vector > const &yCurrent, field_type rho)
Definition: workModel.hh:194
static field_type f(std::vector< Vector > const &yPrev, std::vector< Vector > const &yCurrent, std::vector< Vector > const &yNext, double rho)
Definition: workModel.hh:205
Abstract base class of various norms.
Definition: norm.hh:59
Abstract base class for different work models.
Definition: workModel.hh:73
Dune::DynamicMatrix< double > RealMatrix
Definition: workModel.hh:77
Dune::DynamicVector< double > RealVector
Definition: workModel.hh:76
virtual RealMatrix const & computeLocalTolerances(std::vector< Vector > const &yPrev, std::vector< Vector > const &yCurrent, std::vector< Vector > const &yNext)=0
Pure virtual function implemented in derived classes for different work models. Computes the local to...
virtual ~WorkModel()
Definition: workModel.hh:112
virtual field_type lowerBoundIterJ(std::vector< Vector > const &yPrev, std::vector< Vector > const &yCurrent, field_type rho)=0
typename Vector::value_type field_type
Definition: workModel.hh:75
Dune::FieldVector< T, n > max(Dune::FieldVector< T, n > x, Dune::FieldVector< T, n > const &y)
Componentwise maximum.
Definition: fixdune.hh:109
Functional::Scalar d1(Assembler &assembler, Functional const &f, typename Functional::AnsatzVars::VariableSet &x, typename Functional::Scalar tolerance=1e-6, typename Functional::Scalar increment=1e-12, bool toFile=false, std::string const &filename=std::string("d1error"))
Functional::Scalar d2(Assembler &assembler, Functional const &f, typename Functional::AnsatzVars::VariableSet const &x, typename Functional::Scalar increment=1e-12, typename Functional::Scalar tolerance=1e-6, bool toFile=false, std::string const &savefilename=std::string("d2error"))
Dune::DynamicVector< double > RealVector
Definition: util.hh:498
WorkModelType
Enum class to define the norm type is class Norm.
Definition: workModel.hh:49
Vector::value_type normVecDiff(std::vector< Vector > const &y0, std::vector< Vector > const &y1, Norm norm)
Some utility functions.
Definition: util.hh:450
Dune::DynamicMatrix< double > RealMatrix
Definition: util.hh:499