ball.cc 2.55 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
46
47
48
49
50
51
52
53
54
};

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

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

  // ===== check for init file =====
  TEST_EXIT(argc == 2)("usage: ball initfile\n");

  // ===== init parameters =====
  Parameters::init(false, argv[1]);

  // ===== create projection =====
  WorldVector<double> ballCenter;
  ballCenter.set(0.0);
55
  new BallProject(1, 
56
57
58
59
60
61
62
63
64
		  BOUNDARY_PROJECTION, 
		  ballCenter, 
		  1.0);

  // ===== create and init the scalar problem ===== 
  ProblemScal ball("ball");
  ball.initialize(INIT_ALL);

  // === create adapt info ===
65
  AdaptInfo *adaptInfo = new AdaptInfo("ball->adapt");
66
67

  // === create adapt ===
68
  AdaptStationary *adapt = new AdaptStationary("ball->adapt",
69
70
71
72
					       &ball,
					       adaptInfo);
  
  // ===== create matrix operator =====
73
  Operator matrixOperator(Operator::MATRIX_OPERATOR, ball.getFeSpace());
74
  matrixOperator.addSecondOrderTerm(new Laplace_SOT);
75
76
77
  ball.addMatrixOperator(&matrixOperator);

  // ===== create rhs operator =====
78
79
  int degree = ball.getFeSpace()->getBasisFcts()->getDegree();
  Operator rhsOperator(Operator::VECTOR_OPERATOR, ball.getFeSpace());
80
  rhsOperator.addZeroOrderTerm(new CoordsAtQP_ZOT(new F(degree)));
81
82
  ball.addVectorOperator(&rhsOperator);

83
84
85
  // ===== add boundary conditions =====
  ball.addDirichletBC(1, new G);

86
87
88
89
90
91
92
93
94
  // ===== start adaption loop =====
  adapt->adapt();

  ball.writeFiles(adaptInfo, true);

  return 0;
}