ProblemInterpolScal.cc 1.56 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include "ProblemInterpolScal.h"
#include "Mesh.h"
#include "DOFVector.h"
#include "Parameters.h"
#include "AdaptInfo.h"

namespace AMDiS {

  ProblemInterpolScal::ProblemInterpolScal(const char *name,
					   ProblemScal *spaceProblem,
					   AbstractFunction<double, WorldVector<double> > *fct,
					   AbstractFunction<WorldVector<double>, WorldVector<double> > *grdFct)
    : ProblemScal(name),
      interpolFct_(fct),
      grdInterpolFct_(grdFct)
  {
    Flag adoptFlag = 
      INIT_SYSTEM | 
      INIT_MESH |
      INIT_FE_SPACE;

    Flag initFlag = INIT_ALL & ~adoptFlag & ~INIT_SOLVER & ~INIT_ESTIMATOR;
  
    initialize(initFlag, spaceProblem, adoptFlag);
  }

  void ProblemInterpolScal::solve(AdaptInfo *adaptInfo) {
    mesh_->dofCompress();
    solution_->interpol(interpolFct_);
  }

  void ProblemInterpolScal::estimate(AdaptInfo *adaptInfo, double) {
    FUNCNAME("ProblemIterpolScal::estimate()");
    double errMax = 0.0, errSum = 0.0;
    int errorNorm = 0;

    int relErr = 0;
    GET_PARAMETER(0, name_ + "->rel error", "%d", &relErr);

    if (grdInterpolFct_) 
      errorNorm = 1;
    else
      if (interpolFct_) 
	errorNorm = 2;

    switch (errorNorm) {
    case 1:
      errSum = Error<double>::H1Err(*grdInterpolFct_, *solution_, relErr, &errMax, true);
      break;
    case 2:
      errSum = Error<double>::L2Err(*interpolFct_, *solution_, relErr, &errMax, true);
      break;
    default: 
      ERROR_EXIT("invalid error norm\n");
    }

    MSG("estimate: %e\n", errSum);

    adaptInfo->setEstSum(errSum, 0);
    adaptInfo->setEstMax(errMax, 0);
  }

}