HeatProject.hh 2.87 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
// ===========================================================================
// ===== instationary problem ================================================
// ===========================================================================

/// Instationary problem
class Heat : public ProblemInstatScal
{
public:
  Heat(ProblemScal &heatSpace)
    : ProblemInstatScal("heat", heatSpace)
  {
    // init theta scheme
    theta = -1.0;
    GET_PARAMETER(0, name + "->theta", "%f", &theta);
    TEST_EXIT(theta >= 0)("theta not set!\n");
    if (theta == 0.0) {
      WARNING("You are using the explicit Euler scheme\n");
      WARNING("Use a sufficiently small time step size!!!\n");
    }
    MSG("theta = %f\n", theta);
    theta1 = theta - 1;
  }

  // ===== ProblemInstatBase methods ===================================

  /// set the time in all needed functions!
  void setTime(AdaptInfo *adaptInfo) 
  {
    rhsTime = adaptInfo->getTime() - (1 - theta) * adaptInfo->getTimestep();
    boundaryTime = adaptInfo->getTime();
    tau1 = 1.0 / adaptInfo->getTimestep();    
  }

  void closeTimestep(AdaptInfo *adaptInfo) 
  {
    ProblemInstatScal::closeTimestep(adaptInfo);
    WAIT;
  }

  // ===== initial problem methods =====================================

  /// Used by \ref problemInitial to solve the system of the initial problem
  void solve(AdaptInfo *adaptInfo) 
  {
    problemStat->getSolution()->interpol(exactSolution);
  }

  /// Used by \ref problemInitial to do error estimation for the initial problem.
  void estimate(AdaptInfo *adaptInfo) 
  {
    double errMax, errSum;

    errSum = Error<double>::L2Err(*exactSolution,
				  *(problemStat->getSolution()), 0, &errMax, false);
    adaptInfo->setEstSum(errSum, 0);
    adaptInfo->setEstMax(errMax, 0);
  }

  // ===== setting methods ===============================================

  /// Sets \ref exactSolution;
  void setExactSolution(AbstractFunction<double, WorldVector<double> > *fct) 
  {
    exactSolution = fct;
  } 

  // ===== getting methods ===============================================

  /// Returns pointer to \ref theta.
  double *getThetaPtr() 
  { 
    return &theta; 
  }

  /// Returns pointer to \ref theta1.
  double *getTheta1Ptr() 
  { 
    return &theta1; 
  }

  /// Returns pointer to \ref tau1
  double *getTau1Ptr() 
  { 
    return &tau1; 
  }

  /// Returns pointer to \ref rhsTime.
  double *getRHSTimePtr() 
  { 
    return &rhsTime; 
  }

  /// Returns pointer to \ref theta1.
  double *getBoundaryTimePtr() 
  {
    return &boundaryTime; 
  }

private:
  /// Used for theta scheme.
  double theta;

  /// theta - 1
  double theta1;

  /// 1.0 / timestep
  double tau1;

  /// time for right hand side functions.
  double rhsTime;

  /// time for boundary functions.
  double boundaryTime;

  /// Pointer to boundary function. Needed for initial problem.
  AbstractFunction<double, WorldVector<double> > *exactSolution;
};