parametric.cc 4.81 KB
Newer Older
1
2
3
4
5
6
7
8
9
#include "AMDiS.h"

using namespace std;
using namespace AMDiS;

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

10
/// RHS function
11
12
13
class F : public AbstractFunction<double, WorldVector<double> >
{
public:
14
  F(int degree) : AbstractFunction<double, WorldVector<double> >(degree) {}
15

16
17
18
  /// Implementation of AbstractFunction::operator().
  double operator()(const WorldVector<double>& x) const 
  {
19
20
    return -2.0 * x[0];
  }
21
22
23
24
25
26
27
28
29
30
};

/** \brief
 * Implementation of a scalar problem. In \ref buildBeforeCoarsen() parametric
 * coordinates for the vertices are filled in a DOFVector. This DOFVector is
 * used in \ref parametric to parametrize elements while mesh traversal. 
 */
class ParametricSphere : public ProblemScal 
{
public:
31
  /// constructor
32
33
34
  ParametricSphere(const char *name) 
    : ProblemScal(name),
      parametric(NULL)
35
  {}
36

37
38
39
40
41
42
43
  /// destructor
  ~ParametricSphere() 
  {
    for (int i = 0; i < Global::getGeo(WORLD); i++)
      delete parametricCoords[i];

    delete parametric;
44
45
  }

46
  /// initialization of the base class and creation of \ref parametric.
47
48
49
50
51
52
53
54
55
  void initialize(Flag initFlag,
		  ProblemScal *adoptProblem = NULL,
		  Flag adoptFlag = INIT_NOTHING)
  {
    ProblemScal::initialize(initFlag, adoptProblem, adoptFlag);

    // ===== create projection =====
    WorldVector<double> ballCenter;
    ballCenter.set(0.0);
56
    new BallProject(1, 
57
58
59
60
61
		    VOLUME_PROJECTION, 
		    ballCenter, 
		    1.0);

    // ===== create coords vector =====
Thomas Witkowski's avatar
Thomas Witkowski committed
62
    for (int i = 0; i < Global::getGeo(WORLD); i++)
63
      parametricCoords[i] = new DOFVector<double>(this->getFeSpace(), 
64
65
66
						  "parametric coords");

    // ===== create parametric object =====
67
    parametric = new ParametricFirstOrder(&parametricCoords);
68
69
70
71
72
73
74
75
76
77
78

    // ===== enable parametric traverse =====
    this->getMesh()->setParametric(parametric);
  };

  /** \brief
   * Implementation of ProblemStatBase::buildBeforeCoarsen().
   */
  void buildBeforeCoarsen(AdaptInfo *adaptInfo, Flag flag) {
    FUNCNAME("ParametricSphere::buildAfterCoarsen()");
    MSG("calculation of parametric coordinates\n");
79
    int preDOFs = this->getFeSpace()->getAdmin()->getNumberOfPreDOFs(VERTEX);
80
81
82
83
84
85
86
87
88
89
90
91
92
    int dim = this->getMesh()->getDim();
    int dow = Global::getGeo(WORLD);
    WorldVector<double> vertexCoords;
    const DegreeOfFreedom **dof;
    DegreeOfFreedom vertexIndex;

    // ===== disable parametric traverse =====
    this->getMesh()->setParametric(NULL);

    TraverseStack stack;
    ElInfo *elInfo = NULL;
    elInfo = stack.traverseFirst(this->getMesh(), -1, 
				 Mesh::CALL_LEAF_EL | Mesh::FILL_COORDS);
93
    while (elInfo) {
94
      dof = elInfo->getElement()->getDOF();
95
      for (int i = 0; i < dim + 1; i++) {
96
97
	vertexCoords = elInfo->getCoord(i);
	Projection::getProjection(1)->project(vertexCoords);
98
	for (int j = 0; j < dow; j++)
99
100
101
102
103
104
105
106
	  (*(parametricCoords[j]))[dof[i][preDOFs]] = vertexCoords[j];
      }
      elInfo = stack.traverseNext(elInfo);
    }
    

    // ===== enable parametric traverse =====
    this->getMesh()->setParametric(parametric);
107
  }
108
109

protected:
110
  /// DOFVector storing parametric coordinates.
111
112
  WorldVector<DOFVector<double>*> parametricCoords;

113
  /// Parametrizes vertex coordinates while mesh traversal.
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
  ParametricFirstOrder *parametric;
};

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

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

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

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

  // ===== create and init the scalar problem ===== 
  ParametricSphere parametric("parametric");
  parametric.initialize(INIT_ALL);

  // === create adapt info ===
136
  AdaptInfo *adaptInfo = new AdaptInfo("parametric->adapt", 1);
137
138

  // === create adapt ===
139
  AdaptStationary *adapt = new AdaptStationary("parametric->adapt",
140
141
142
143
144
					       &parametric,
					       adaptInfo);
  
  // ===== create matrix operator =====
  Operator matrixOperator(Operator::MATRIX_OPERATOR,
145
			  parametric.getFeSpace());
146
  matrixOperator.addSecondOrderTerm(new Laplace_SOT);
147
148
149
150
  parametric.addMatrixOperator(&matrixOperator);

  // ===== create rhs operator =====
  Operator rhsOperator(Operator::VECTOR_OPERATOR,
151
		       parametric.getFeSpace());
152

153
  int degree = parametric.getFeSpace()->getBasisFcts()->getDegree();
154

155
  rhsOperator.addZeroOrderTerm(new CoordsAtQP_ZOT(new F(degree)));
156
157
158
159
160
161
162
163
164
165
166
  parametric.addVectorOperator(&rhsOperator);

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

  parametric.writeFiles(adaptInfo, true);

  return 0;
}