nonlin.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
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
#include "AMDiS.h"

using namespace AMDiS;
using namespace std;

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

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

  G()
    : AbstractFunction<double, WorldVector<double> >()
  {}

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


/// 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 + pow(ux, 4.0);
  }
};


class NonlinFctLeft : public AbstractFunction<double, double> 
{
public:
  NonlinFctLeft()
    : AbstractFunction<double, double>()
  {}

  double operator()(const double& u) const
  {
    return 4.0 * u * u * u;
  }
};


class NonlinFctRight : public AbstractFunction<double, double> 
{
public:
  NonlinFctRight()
    : AbstractFunction<double, double>()
  {}

  double operator()(const double& u) const
  {
    return -(u * u * u * u);
  }
};

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

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

80
  AMDiS::init(argc, argv);
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95

  // ===== create and init the scalar problem ===== 
  ProblemNonLin nonlin("nonlin");
  nonlin.initialize(INIT_ALL);

  // === create adapt info ===
  AdaptInfo adaptInfo("nonlin->adapt");


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

  
  // === create matrix operators ===
  Operator mat01(nonlin.getFeSpace());
96
  mat01.addTerm(new Simple_SOT());
97
98
99
  nonlin.addMatrixOperator(mat01, 0, 0);

  Operator mat02(nonlin.getFeSpace());
100
  mat02.addTerm(new VecAtQP_ZOT(nonlin.getSolution(0), new NonlinFctLeft()));
101
102
103
104
105
  nonlin.addMatrixOperator(mat02, 0, 0);

  // === create rhs operators ===
  Operator vec01(nonlin.getFeSpace());
  vec01.setUhOld(nonlin.getSolution(0));
106
  vec01.addTerm(new Simple_SOT(-1.0));
107
108
109
  nonlin.addVectorOperator(vec01, 0);
  
  Operator vec02(nonlin.getFeSpace());
110
  vec02.addTerm(new VecAtQP_ZOT(nonlin.getSolution(0), new NonlinFctRight()));
111
112
113
  nonlin.addVectorOperator(vec02, 0);
  
  Operator vec03(nonlin.getFeSpace());
114
  vec03.addTerm(new CoordsAtQP_ZOT(new F(nonlin.getFeSpace()->getBasisFcts()->getDegree())));
115
116
117
118
119
120
121
122
123
  nonlin.addVectorOperator(vec03, 0);

  // ===== add boundary conditions =====
  nonlin.addDirichletBC(1, 0, 0, new G);

  // ===== start adaption loop =====
  adapt.adapt();

  nonlin.writeFiles(adaptInfo, true);
124
125

  AMDiS::finalize();
126
}