ball.cc 2.65 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include "AMDiS.h"

using namespace std;
using namespace AMDiS;

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

/** \brief
 * Dirichlet boundary function
 */
class G : public AbstractFunction<double, WorldVector<double> >
{
public:
  MEMORY_MANAGED(G);

  /** \brief
   * Implementation of AbstractFunction::operator().
   */
21
22
23
  double operator()(const WorldVector<double>& x) const {
    return exp(-10.0 * (x * x));
  }
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
};

/** \brief
 * RHS function
 */
class F : public AbstractFunction<double, WorldVector<double> >
{
public:
  MEMORY_MANAGED(F);

  F(int degree) : AbstractFunction<double, WorldVector<double> >(degree) {};

  /** \brief
   * Implementation of AbstractFunction::operator().
   */
39
  double operator()(const WorldVector<double>& x) const {
40
    int dim = x.getSize();
41
    double r2 = x * x;
42
    double ux = exp(-10.0*r2);
43
44
    return -(400.0 * r2 - 20.0 * dim) * ux;
  }
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
};

// ===========================================================================
// ===== 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);
  NEW BallProject(1, 
		  BOUNDARY_PROJECTION, 
		  ballCenter, 
		  1.0);

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

  // === create adapt info ===
  AdaptInfo *adaptInfo = NEW AdaptInfo("ball->adapt");

  // === create adapt ===
  AdaptStationary *adapt = NEW AdaptStationary("ball->adapt",
					       &ball,
					       adaptInfo);
  
  // ===== add boundary conditions =====
  ball.addDirichletBC(1, NEW G);

  // ===== create matrix operator =====
  Operator matrixOperator(Operator::MATRIX_OPERATOR, ball.getFESpace());
  matrixOperator.addSecondOrderTerm(NEW Laplace_SOT);
  ball.addMatrixOperator(&matrixOperator);

  // ===== create rhs operator =====
  int degree = ball.getFESpace()->getBasisFcts()->getDegree();
  Operator rhsOperator(Operator::VECTOR_OPERATOR, ball.getFESpace());
  rhsOperator.addZeroOrderTerm(NEW CoordsAtQP_ZOT(NEW F(degree)));
  ball.addVectorOperator(&rhsOperator);

  // ===== start adaption loop =====
  adapt->adapt();

  ball.writeFiles(adaptInfo, true);

  return 0;
}