ball.cc 2.37 KB
Newer Older
1
2
3
4
5
6
7
8
9
#include "AMDiS.h"

using namespace std;
using namespace AMDiS;

// ===========================================================================
// ===== function definitions ================================================
// ===========================================================================

10
/// Dirichlet boundary function
11
12
13
class G : public AbstractFunction<double, WorldVector<double> >
{
public:
14
15
16
17
  
  /// Implementation of AbstractFunction::operator().
  double operator()(const WorldVector<double>& x) const 
  {
18
19
    return exp(-10.0 * (x * x));
  }
20
21
};

22
/// RHS function
23
24
25
class F : public AbstractFunction<double, WorldVector<double> >
{
public:
26
  F(int degree) : AbstractFunction<double, WorldVector<double> >(degree) {}
27

28
29
30
  /// Implementation of AbstractFunction::operator().
  double operator()(const WorldVector<double>& x) const 
  {
31
    int dim = x.getSize();
32
    double r2 = x * x;
33
    double ux = exp(-10.0*r2);
34
35
    return -(400.0 * r2 - 20.0 * dim) * ux;
  }
36
37
38
39
40
41
42
43
44
45
};

// ===========================================================================
// ===== main program ========================================================
// ===========================================================================

int main(int argc, char* argv[])
{
  FUNCNAME("main");

46
  AMDiS::init(argc, argv);
47
48
49
50

  // ===== create projection =====
  WorldVector<double> ballCenter;
  ballCenter.set(0.0);
51
  new BallProject(1, 
52
53
54
55
56
		  BOUNDARY_PROJECTION, 
		  ballCenter, 
		  1.0);

  // ===== create and init the scalar problem ===== 
57
  ProblemStat ball("ball");
58
59
60
  ball.initialize(INIT_ALL);

  // === create adapt info ===
61
  AdaptInfo *adaptInfo = new AdaptInfo("ball->adapt", ball.getNumComponents());
62
63

  // === create adapt ===
64
  AdaptStationary *adapt = new AdaptStationary("ball->adapt", &ball, adaptInfo);
65
66
  
  // ===== create matrix operator =====
67
  Operator matrixOperator(ball.getFeSpace());
68
  matrixOperator.addTerm(new Simple_SOT);
69
  ball.addMatrixOperator(&matrixOperator, 0, 0);
70
71

  // ===== create rhs operator =====
72
  int degree = ball.getFeSpace()->getBasisFcts()->getDegree();
73
  Operator rhsOperator(ball.getFeSpace());
74
  rhsOperator.addTerm(new CoordsAtQP_ZOT(new F(degree)));
75
  ball.addVectorOperator(&rhsOperator, 0);
76

77
  // ===== add boundary conditions =====
78
  ball.addDirichletBC(1, 0, 0, new G);
79

80
81
82
83
84
  // ===== start adaption loop =====
  adapt->adapt();

  ball.writeFiles(adaptInfo, true);

85
  AMDiS::finalize();
86
87
88
}