VelocityExt.h 8 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// ============================================================================
// ==                                                                        ==
// == AMDiS - Adaptive multidimensional simulations                          ==
// ==                                                                        ==
// ==  http://www.amdis-fem.org                                              ==
// ==                                                                        ==
// ============================================================================
//
// Software License for AMDiS
//
// Copyright (c) 2010 Dresden University of Technology 
// All rights reserved.
// Authors: Simon Vey, Thomas Witkowski et al.
//
// This file is part of AMDiS
//
// See also license.opensource.txt in the distribution.




22
23
24
25
26
27
#ifndef VELOCITYEXT_H
#define VELOCITYEXT_H

#include "AdaptInfo.h"
#include "DOFVector.h"
#include "Element.h"
28
#include "io/FileWriter.h"
29
30
31
32
33
34
#include "FixVec.h"

using namespace AMDiS;

class VelocityExt
{
35
public:
36
37
  VelocityExt(int dim_)
    : dim(dim_),
38
39
40
      nVelDOFs(0),
      lamVec(dim_, dim_ + 1, NO_INIT),
      permutation(dim_, NO_INIT)
41
42
  {
    indexFace = -1;
43
  }
44
45

  virtual ~VelocityExt()
46
  {}
47

48
  /// Print velDOF to file.
49
50
51
52
  void printVelDOF(AdaptInfo *adaptInfo, int i = 0)
  {
    FUNCNAME("VelocityExt::printVelDOF()");

53
    TEST_EXIT(i < static_cast<int>(velDOF.size()))("Illegal index!\n");
54

55
    FileWriter *fileWriter = new FileWriter(
56
			     "VelocityExt->velocity output", 
57
			     (velDOF[i])->getFeSpace()->getMesh(),
58
59
60
			     const_cast<DOFVector<double> *>(velDOF[i]));
    fileWriter->writeFiles(adaptInfo, false);

61
    delete fileWriter;
62
  }
63

64
  /// Print origVelDOF to file.
65
66
67
68
  void printOrigVelDOF(AdaptInfo *adaptInfo, int i = 0)
  {
    FUNCNAME("VelocityExt::printOrigVelDOF()");

69
    TEST_EXIT(i < static_cast<int>(origVelDOF.size()))("Illegal index!\n");
70

71
    FileWriter *fileWriter = new FileWriter(
72
			     "VelocityExt->interface velocity output", 
73
			     (origVelDOF[i])->getFeSpace()->getMesh(),
74
75
76
			     const_cast<DOFVector<double> *>(origVelDOF[i]));
    fileWriter->writeFiles(adaptInfo, false);

77
    delete fileWriter;
78
  }
79

80
  /// Set velocity (one velocity vector).
81
82
83
84
85
86
87
88
89
  void setVelocity(DOFVector<double> *origVelDOF_,
		   DOFVector<double> *velDOF_)
  {
    FUNCNAME("VelocityExt::setVelocity()");

    nVelDOFs = 1;

    TEST_EXIT(origVelDOF_)("illegal velocity vector origVelDOF !\n");
    TEST_EXIT(velDOF_)("illegal velocity vector velDOF !\n");
90
    TEST_EXIT(origVelDOF_->getFeSpace() == velDOF_->getFeSpace())
91
92
93
94
95
96
97
      ("different fe spaces !\n");

    origVelDOF.clear();
    velDOF.clear();

    origVelDOF.push_back(origVelDOF_);
    velDOF.push_back(velDOF_);
98
  }
99

100
  /// Set velocity (multiple velocity vectors).
101
102
103
104
105
106
107
  void setVelocity(std::vector<DOFVector<double> *> &origVelDOF_,
		   std::vector<DOFVector<double> *> &velDOF_)
  {
    FUNCNAME("VelocityExt::setVelocity()");

    nVelDOFs = origVelDOF_.size();

108
109
    TEST_EXIT(nVelDOFs > 0)("Illegal number of velocity vectors!\n");
    TEST_EXIT(nVelDOFs == static_cast<int>(velDOF_.size()))("Different sizes!\n");
110
111
112
113

    for (int i=0; i<nVelDOFs; ++i) {
      TEST_EXIT(origVelDOF_[i])("illegal velocity vector origVelDOF !\n");
      TEST_EXIT(velDOF_[i])("illegal velocity vector velDOF !\n");
114
      TEST_EXIT((origVelDOF_[i])->getFeSpace() == (velDOF_[i])->getFeSpace())
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
	("different fe spaces !\n");
    }
      
    origVelDOF = origVelDOF_;
    velDOF = velDOF_;
  };

  /**
   * Calculates the velocity for a vertex on a boundary element.
   * lokInd gives the lokal index of the element vertices.
   * indexV is the index of the vertex(with respect to the numeration on the element),
   * for that the velocity shall be calculated.
   */
  virtual void calcVelocityBoundary(DegreeOfFreedom *lokInd, 
				    const int indexV);

  /**
   * Calculates the velocity for a vertex on a non-boundary element.
   * lokInd gives the lokal index of the element vertices.
   * indexV is the index of the vertex(with respect to the numeration on the element),
   * for that the velocity shall be calculated.
   */
  void calcVelocity(DegreeOfFreedom *lokInd, const int indexV);

  /**
   * Sets barycentric coordinates for 2D for a vertex on a boundary element.
   * l_0. l_1, l_2 are the coordinates.
   * indexV is the index of the vertex(with respect to the numeration on the element),
   * for that the coordinates shall be stored.
   */
145
146
147
148
  void setBarycentricCoords_2D_boundary(const double &l_0, 
					const double &l_1, 
					const double &l_2, 
					const int indexV);
149
150
151
152
153

  /**
   * Sets barycentric coordinates for 2D for a vertex on a non-boundary element.
   * l_0. l_1, l_2 are the coordinates.
   */
154
155
156
  void setBarycentricCoords_2D(const double &l_0, 
			       const double &l_1, 
			       const double &l_2);
157
158

  /**
159
160
   * Calculates the barycentric coordinates for 2D for a vertex on a 
   * non-boundary element.
161
   */
162
163
164
165
  void calcBarycentricCoords_2D(const double &c_delta, 
				const double &c_alpha, 
				const double &norm_zhminusyh, 
				const double &norm_xhminusyh);
166
167
168
169
170
171
172
173

  /**
   * Sets barycentric coordinates for 3D for a vertex on a boundary element
   * (in case the coordinates are already known).
   * l_0, l_1, l-2, l_3 are the coordinates.
   * indexV is the index of the vertex(with respect to the numeration on the element),
   * for that the coordinates shall be stored.
   */
174
175
176
177
178
179
180
181
182
183
184
  void setBarycentricCoords_3D_boundary(const double &l_0, 
					const double &l_1, 
					const double &l_2, 
					const double &l_3, 
					const int indexV);

  /// Calculates the barycentric coordinates for 3D for a boundary vertex.
  void calcBarycentricCoords_3D_boundary(const DimVec<double> sp1, 
					 const DimVec<double> sp2, 
					 const double lambda, 
					 int i);
185
186

  /**
187
188
189
   * Expands 3 coordinates from a face update to 4 coordinates and stores them in 
   * lamVec[index]. vertNum is the index of the element face the coordinates 
   * belong to (0, 1 or 2).
190
   */
191
  void copyAndExpandFaceCoords_3D(int vertNum, int index);
192
193
194
195
196

  /**
   * Sets barycentric coordinates for 3D for a vertex on a non-boundary element.
   * l_0, l_1, l-2, l_3 are the coordinates.
   */
197
198
199
200
  void setBarycentricCoords_3D(const double &l_0, 
			       const double &l_1, 
			       const double &l_2, 
			       const double &l_3);
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217

  /**
   * Stores the index of element face with the shortest distance to the interface so far.
   * (with respect to the order of calculation)
   */
  void setIndexFaceWithShortestDist(int indexC);

  /**
   * Sets the permutation of the vertices.
   * vertNum is the vertex number(with respect to the numeration on the element),
   * for that the update is calculated.
   * mTrav is an index for determining the way of mesh-traverse.
   * mTrav=0:level
   * mTrav=1:traverse
   */
  void setPermutation(int vertNum, int mTrav);

218
  /// Sets the permutation.
219
220
  void setPermutation(int vertNum);

221
  /// Sets the permutation of the vertices in 2D.
222
223
  void setPermutation_2D(int i_0, int i_1, int i_2);

224
  /// Sets the permutation of the vertices in 3D.
225
226
  void setPermutation_3D(int i_0, int i_1, int i_2, int i_3);

227
  /// Swaps two vertices in the permutation.
228
229
230
  void swapVertices(int i1, int i2);

 protected:
231
  /// Original velocity vector.
232
233
  std::vector<DOFVector<double> *> origVelDOF;

234
  /// Dimension of mesh.
235
236
  int dim;

237
  /// DOF vector with extended velocity.
238
239
  std::vector<DOFVector<double> *> velDOF;

240
  /// Number of velocity vectors to be extended.
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
  int nVelDOFs;

  /**
   * Vector with barycentric coordinates of points from which the velocity is extended.
   * Whole vector is needed for the calculation on the boundary elements.
   * For non-boundary elements the first place is used.
   * If the update is calculated with the element faces, the places two-dim are used.
   */
  VectorOfFixVecs<DimVec<double> > lamVec;

  /**
   * If the update is calculated with the element faces, indexFace stores the number of the element
   * face with the shortest distance to the interface.
   * Otherwise indexFace is -1;
   */
  int indexFace;

258
  /// List with the permutation of the vertices.
259
260
261
262
  DimVec<int> permutation;
};

#endif  // VELOCITYEXT_H