elliptBaseProblem.cc 2.81 KB
Newer Older
Praetorius, Simon's avatar
Praetorius, Simon committed
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
#include "AMDiS.h"
#include "BaseProblem.h"

#include "boost/date_time/posix_time/posix_time.hpp"

using namespace AMDiS;
using namespace boost::posix_time;

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

/// Dirichlet boundary function
class G : public AbstractFunction<double, WorldVector<double> >
{
public:

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

/// RHS function
class F : public AbstractFunction<double, WorldVector<double> >
{
public:

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

  /// Implementation of AbstractFunction::operator().
  double operator()(const WorldVector<double>& x) const 
  {
    int dow = Global::getGeo(WORLD);
    double r2 = (x * x);
    double ux = exp(-10.0 * r2);
    return -(400.0 * r2 - 20.0 * dow) * ux;
  }
};

class ElliptBase : public StandardBaseProblem
{
public:
  typedef StandardBaseProblem super;

public:
  ElliptBase(std::string name_) : super(name_) {}

protected:
  void fillOperators()
  {
    // ===== create matrix operator =====
    Operator *matrixOperator = new Operator(getFeSpace());
55
    matrixOperator->addTerm(new Simple_SOT);
Praetorius, Simon's avatar
Praetorius, Simon committed
56
57
58
59
60
61
    prob->addMatrixOperator(matrixOperator, 0, 0);


    // ===== create rhs operator =====
    int degree = getFeSpace()->getBasisFcts()->getDegree();
    Operator *rhsOperator = new Operator(getFeSpace());
62
    rhsOperator->addTerm(new CoordsAtQP_ZOT(new F(degree)));
Praetorius, Simon's avatar
Praetorius, Simon committed
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
    prob->addVectorOperator(rhsOperator, 0);
  }

  void fillBoundaryCondition()
  {
    // ===== add boundary conditions =====
    prob->addDirichletBC(1, 0, 0, new G);
  }
};

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

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

  AMDiS::init(argc, argv);

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


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


  // === create adapt ===
  AdaptStationary adapt("ellipt->adapt", ellipt, adaptInfo);


  // ===== start adaption loop =====
  ptime start_time= microsec_clock::local_time();
  ellipt.initTimeInterface(); // fillOperators() and fillBoundaryCondition()
  adapt.adapt();
  time_duration td= microsec_clock::local_time()-start_time;

  MSG("elapsed time= %f msec\n", td.total_milliseconds()/1000.0);

  ellipt.writeFiles(&adaptInfo, true);

  AMDiS::finalize();
}