ellipt.cc 2.07 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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
#include "AMDiS.h"

using namespace AMDiS;
using namespace std;

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

  /** \brief
   * Implementation of AbstractFunction::operator().
   */
  const double& operator()(const WorldVector<double>& x) const
  {
    static double result;
    result = exp(-10.0 * (x * x));
    return result;  
  };
};

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

  /** \brief
   * Implementation of AbstractFunction::operator().
   */
  const double& operator()(const WorldVector<double>& x) const {
    static double result = 0.0;
    int dow = x.getSize();
    double r2 = (x * x);
    double ux = exp(-10.0 * r2);
    result = -(400.0 * r2 - 20.0 * dow) * ux;
    return result;
  };
};

// // ===== main program // 
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 ===
  AdaptInfo *adaptInfo = NEW AdaptInfo("ellipt->adapt");

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

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

  // ===== create rhs operator =====
  Operator rhsOperator(Operator::VECTOR_OPERATOR, ellipt.getFESpace());
  rhsOperator.addZeroOrderTerm(NEW CoordsAtQP_ZOT(NEW F()));
  ellipt.addVectorOperator(&rhsOperator);

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

  ellipt.writeFiles(adaptInfo, true);
}