vecellipt.cc 3.08 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
42
43
    double r2 = (x * x);
    double ux = exp(-10.0 * r2);
    return -(400.0 * r2 - 20.0 * dim) * ux;
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
  };
};

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

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

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

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

  // ===== create and init the scalar problem ===== 
  ProblemVec vecellipt("vecellipt");
  vecellipt.initialize(INIT_ALL);

  // === create adapt info ===
  AdaptInfo *adaptInfo = NEW AdaptInfo("vecellipt->adapt",
				       vecellipt.getNumComponents());

  // === create adapt ===
  AdaptStationary *adapt = NEW AdaptStationary("vecellipt->adapt",
					       &vecellipt,
					       adaptInfo);
  

  // ===== add boundary conditions =====
  vecellipt.addDirichletBC(1, 0, NEW G);

  // ===== create operators =====
  Operator matrixOperator00(Operator::MATRIX_OPERATOR,
			    vecellipt.getFESpace(0),
			    vecellipt.getFESpace(0));
  matrixOperator00.addSecondOrderTerm(NEW Laplace_SOT);
  vecellipt.addMatrixOperator(&matrixOperator00, 0, 0);

  Operator rhsOperator0(Operator::VECTOR_OPERATOR,
			vecellipt.getFESpace(0));

  int degree = vecellipt.getFESpace(0)->getBasisFcts()->getDegree();

  rhsOperator0.addZeroOrderTerm(NEW CoordsAtQP_ZOT(NEW F(degree)));

  vecellipt.addVectorOperator(&rhsOperator0, 0);

  Operator matrixOperator10(Operator::MATRIX_OPERATOR,
			    vecellipt.getFESpace(1),
			    vecellipt.getFESpace(0));

  Operator matrixOperator11(Operator::MATRIX_OPERATOR,
			    vecellipt.getFESpace(1),
			    vecellipt.getFESpace(1));

  matrixOperator10.addZeroOrderTerm(NEW Simple_ZOT);

  vecellipt.addMatrixOperator(&matrixOperator10, 1, 0);

  matrixOperator11.addZeroOrderTerm(NEW Simple_ZOT(-1.0));

  vecellipt.addMatrixOperator(&matrixOperator11, 1, 1);

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

  vecellipt.writeFiles(adaptInfo, true);

  return 0;
}