ellipt.cc 2.26 KB
Newer Older
1
2
3
4
5
#include "AMDiS.h"

using namespace AMDiS;
using namespace std;

6
7
8
9
10
// ===========================================================================
// ===== function definitions ================================================
// ===========================================================================

/// Dirichlet boundary function
11
12
13
14
class G : public AbstractFunction<double, WorldVector<double> >
{
public:

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
26
class F : public AbstractFunction<double, WorldVector<double> >
{
public:

27
28
29
  /// Implementation of AbstractFunction::operator().
  double operator()(const WorldVector<double>& x) const 
  {
30
31
32
    int dow = x.getSize();
    double r2 = (x * x);
    double ux = exp(-10.0 * r2);
33
34
    return -(400.0 * r2 - 20.0 * dow) * ux;
  }
35
36
};

37
38
39
40
// ===========================================================================
// ===== main program ========================================================
// ===========================================================================

41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
int main(int argc, char* argv[])
{
  FUNCNAME("main");

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

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

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

  // === create adapt info ===
56
  AdaptInfo *adaptInfo = new AdaptInfo("ellipt->adapt");
57
58

  // === create adapt ===
59
  AdaptStationary *adapt = new AdaptStationary("ellipt->adapt",
60
61
62
63
					       &ellipt,
					       adaptInfo);
  
  // ===== add boundary conditions =====
64
  ellipt.addDirichletBC(1, new G);
65
66
67

  // ===== create matrix operator =====
  Operator matrixOperator(Operator::MATRIX_OPERATOR, ellipt.getFESpace());
68
  matrixOperator.addSecondOrderTerm(new Laplace_SOT);
69
70
71
72
  ellipt.addMatrixOperator(&matrixOperator);

  // ===== create rhs operator =====
  Operator rhsOperator(Operator::VECTOR_OPERATOR, ellipt.getFESpace());
73
  rhsOperator.addZeroOrderTerm(new CoordsAtQP_ZOT(new F()));
74
75
76
77
78
79
80
81
82
  ellipt.addVectorOperator(&rhsOperator);

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

  ellipt.writeFiles(adaptInfo, true);
}