ElInfo2d.cc 17.9 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include "ElInfo2d.h"
#include "BasisFunction.h"
#include "Element.h"
#include "Line.h"
#include "Triangle.h"
#include "Tetrahedron.h"
#include "FiniteElemSpace.h"
#include "Flag.h"
#include "MacroElement.h"
#include "Mesh.h"
#include "Global.h"
#include "FixVec.h"
#include "DOFVector.h"

namespace AMDiS {

17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
  double ElInfo2d::mat_d1_val[3][3] = {{1.0, 0.0, 0.0}, 
				       {0.0, 1.0, 0.0}, 
				       {0.0, 0.0, 1.0}};
  mtl::dense2D<double> ElInfo2d::mat_d1(mat_d1_val);

  double ElInfo2d::mat_d1_left_val[3][3] = {{0.0, 1.0, 0.5}, 
					    {0.0, 0.0, 0.5},
					    {1.0, 0.0, 0.0}};
  mtl::dense2D<double> ElInfo2d::mat_d1_left(mat_d1_left_val);

  double ElInfo2d::mat_d1_right_val[3][3] = {{0.0, 0.0, 0.5}, 
					     {1.0, 0.0, 0.5},
					     {0.0, 1.0, 0.0}};
  mtl::dense2D<double> ElInfo2d::mat_d1_right(mat_d1_right_val);

32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
  ElInfo2d::ElInfo2d(Mesh *aMesh) 
    : ElInfo(aMesh) 
  {
    e1 = NEW WorldVector<double>;
    e2 = NEW WorldVector<double>;
    normal = NEW WorldVector<double>;
  }

  ElInfo2d::~ElInfo2d()
  {
    DELETE e1;
    DELETE e2;
    DELETE normal;
  }

47
48
  void ElInfo2d::fillMacroInfo(const MacroElement * mel)
  {
49
50
    FUNCNAME("ElInfo::fillMacroInfo()");
 
51
    macroElement_ = const_cast<MacroElement*>(mel);
52
53
    element_ = const_cast<Element*>(mel->getElement());
    parent_ = NULL;
54
    level = 0;
55
56
57
58

    if (fillFlag_.isSet(Mesh::FILL_COORDS) || 
	fillFlag_.isSet(Mesh::FILL_DET)    ||
	fillFlag_.isSet(Mesh::FILL_GRD_LAMBDA)) {
59
60
61

      int vertices = mesh_->getGeo(VERTEX);
      for (int i = 0; i < vertices; i++) {
62
63
64
65
66
67
	coord_[i] = mel->coord[i];
      }
    }

    int neighbours = mesh_->getGeo(NEIGH);

68
69
70
71
    if (fillFlag_.isSet(Mesh::FILL_OPP_COORDS) || 
	fillFlag_.isSet(Mesh::FILL_NEIGH)) {

      bool fill_opp_coords = (fillFlag_.isSet(Mesh::FILL_OPP_COORDS));
72
    
73
74
75
76
      for (int i = 0; i < neighbours; i++) {
	MacroElement *macroNeighbour = mel->getNeighbour(i);

	if (macroNeighbour) {
Thomas Witkowski's avatar
Thomas Witkowski committed
77
	  neighbour_[i] = macroNeighbour->getElement();	  
78
79
80
81
82
83
84
85
86
87
88
89
90
	  Element *nb = const_cast<Element*>(neighbour_[i]);

	  int edgeNo = oppVertex_[i] = mel->getOppVertex(i);
	  if (nb->getFirstChild() && (edgeNo != 2)) {   // make nb nearest el.
	    if (edgeNo == 0) {
	      nb = neighbour_[i] = nb->getSecondChild();
	    } else {
	      nb = neighbour_[i] = nb->getFirstChild();
	    }

	    oppVertex_[i] = 2;

	    if (fill_opp_coords) {
91
	      if (nb->isNewCoordSet()) {
92
93
94
95
96
97
98
99
100
101
102
103
104
		oppCoord_[i] = *(nb->getNewCoord());
	      } else {
		oppCoord_[i] = (macroNeighbour->coord[0] + macroNeighbour->coord[1]) * 0.5;
	      }	    	      
	      
	      switch (i) {
	      case 0:
		if (*(macroNeighbour->getElement()->getDOF(2)) == *(element_->getDOF(2))) {
		  neighbourCoord_[i][0] = macroNeighbour->coord[2];
		  neighbourCoord_[i][1] = macroNeighbour->coord[0];
		} else if (*(macroNeighbour->getElement()->getDOF(2)) == *(element_->getDOF(1))) {
		  neighbourCoord_[i][0] = macroNeighbour->coord[1];
		  neighbourCoord_[i][1] = macroNeighbour->coord[2];
105
		} else {
Thomas Witkowski's avatar
Thomas Witkowski committed
106
		  ERROR_EXIT("Should not happen!\n");
107
		}
108
109
110
111
112
113
114
115
116
117
118
119
	
		neighbourCoord_[i][2] = oppCoord_[i];
		break;
		
	      case 1:
		if (*(macroNeighbour->getElement()->getDOF(2)) == *(element_->getDOF(2))) {
		  neighbourCoord_[i][0] = macroNeighbour->coord[1];
		  neighbourCoord_[i][1] = macroNeighbour->coord[2];
		} else if (*(macroNeighbour->getElement()->getDOF(2)) == *(element_->getDOF(0))) {
		  neighbourCoord_[i][0] = macroNeighbour->coord[2];
		  neighbourCoord_[i][1] = macroNeighbour->coord[0];
		} else {
Thomas Witkowski's avatar
Thomas Witkowski committed
120
		  ERROR_EXIT("Should not happen!\n");
121
122
123
124
125
		}
		
		neighbourCoord_[i][2] = oppCoord_[i];
		break;
		
Thomas Witkowski's avatar
Thomas Witkowski committed
126
127
128
129
130
131
132
133
134
135
136
137
	      case 2:
		if (*(macroNeighbour->getElement()->getDOF(2)) == *(element_->getDOF(0))) {
		  neighbourCoord_[i][0] = macroNeighbour->coord[2];
		  neighbourCoord_[i][1] = macroNeighbour->coord[1];
		} else if (*(macroNeighbour->getElement()->getDOF(2)) == *(element_->getDOF(1))) {
		  neighbourCoord_[i][0] = macroNeighbour->coord[0];
		  neighbourCoord_[i][1] = macroNeighbour->coord[2];		 
		} else {
		  ERROR_EXIT("Should not happen!\n");
		}
		break;

138
	      default:
Thomas Witkowski's avatar
Thomas Witkowski committed
139
		std::cout << "------------- Error --------------" << std::endl;
Thomas Witkowski's avatar
Thomas Witkowski committed
140
141
		std::cout << "  Neighbour counter = " << i << "\n";
		std::cout << "  Element index     = " << element_->getIndex() << "\n\n";
Thomas Witkowski's avatar
Thomas Witkowski committed
142
143
144
145
146
147
148
149
150
151
152
		for (int j = 0; j < neighbours; j++) {
		  if (mel->getNeighbour(j)) {
		    std::cout << "  Neighbour " << j << ": " 
			      << mel->getNeighbour(j)->getElement()->getIndex() 
			      << std::endl;
		  } else {
		    std::cout << "  Neighbour " << j << ": not existing" << std::endl;
		  }
		  std::cout << "  OppVertex " << j << ": " << static_cast<int>(mel->getOppVertex(j)) << std::endl;
		  std::cout << std::endl;
		}
153
154
		ERROR_EXIT("should not happen!\n");
		break;
155
156
157
	      }
	    }
	  } else {
158
159
160
161
162
	    if (fill_opp_coords) {
	      oppCoord_[i] = macroNeighbour->coord[edgeNo];

	      neighbourCoord_[i] = macroNeighbour->coord;	      
	    }
163
	  }
164
165
166
	} else {
	  neighbour_[i] = NULL;
        }
167
      }
168
    }
169
    
170
171
    if (fillFlag_.isSet(Mesh::FILL_BOUND)) {   
      for (int i = 0; i < element_->getGeo(BOUNDARY); i++) {
172
173
174
	boundary_[i] = mel->getBoundary(i);
      }

175
      for (int i = 0; i < element_->getGeo(PROJECTION); i++) {
176
177
178
179
180
181
182
183
184
185
	projection_[i] = mel->getProjection(i);
      }
    }
  }


  /****************************************************************************/
  /*   fill ElInfo structure for one child of an element   		    */
  /****************************************************************************/

186
  void ElInfo2d::fillElInfo(int ichild, const ElInfo *elInfoOld)
187
  {
188
    FUNCNAME("ElInfo::fillElInfo()");
189

190
    Element *elem = elInfoOld->element_;
191
192
    Element *nb;

193
    Flag fill_flag = elInfoOld->fillFlag_;
194

195
196
197
198
199
    TEST_EXIT_DBG(elem->getFirstChild())("no children?\n");
    element_ = const_cast<Element*>((ichild == 0) ? 
				    elem->getFirstChild() : 
				    elem->getSecondChild());
    TEST_EXIT_DBG(element_)("missing child %d?\n", ichild);
200

201
    macroElement_  = elInfoOld->macroElement_;
202
    fillFlag_ = fill_flag;
203
    parent_ = elem;
204
    level = elInfoOld->level + 1;
205
    iChild = ichild;
206
207
208

    if (fillFlag_.isSet(Mesh::FILL_COORDS) || 
	fillFlag_.isSet(Mesh::FILL_DET)    ||
209
210
	fillFlag_.isSet(Mesh::FILL_GRD_LAMBDA)) {
      
211
      if (elem->isNewCoordSet()) {
212
213
	coord_[2] = *(elem->getNewCoord());
      } else {
214
	coord_[2].setMidpoint(elInfoOld->coord_[0], elInfoOld->coord_[1]);
215
216
217
      }
      
      if (ichild == 0) {
218
219
	coord_[0] = elInfoOld->coord_[2];
	coord_[1] = elInfoOld->coord_[0];
220
      } else {
221
222
	coord_[0] = elInfoOld->coord_[1];
	coord_[1] = elInfoOld->coord_[2];
223
224
225
226
227
228
229
230
231
232
      }
    }

    bool fill_opp_coords = (fill_flag.isSet(Mesh::FILL_OPP_COORDS));

    if (fill_flag.isSet(Mesh::FILL_NEIGH) || fill_opp_coords) {     
      if (ichild == 0) {
	// Calculation of the neighbour 2, its oppCoords and the
	// cooresponding oppVertex.

233
234
	neighbour_[2] = elInfoOld->neighbour_[1];
	oppVertex_[2] = elInfoOld->oppVertex_[1];
235
236
	
	if (neighbour_[2] && fill_opp_coords) {
237
238
	  oppCoord_[2] = elInfoOld->oppCoord_[1];
	  neighbourCoord_[2] = elInfoOld->neighbourCoord_[1];
239
	}
240
241
242
243
244
245
246
247
248
249
250
251
252
	
	
	// Calculation of the neighbour 1, its oppCoords and the
	// cooresponding oppVertex.
	
	if (elem->getFirstChild()  &&  
	    elem->getSecondChild()->getFirstChild()  &&  
	    elem->getSecondChild()->getFirstChild()) {
	  
	  neighbour_[1] = elem->getSecondChild()->getSecondChild();
	  oppVertex_[1] = 2;
	  
	  if (fill_opp_coords) {
253
            if (elem->getSecondChild()->isNewCoordSet()) {
254
255
	      oppCoord_[1] = *(elem->getSecondChild()->getNewCoord());
	    } else {      
256
257
	      oppCoord_[1].setMidpoint(elInfoOld->coord_[1], 
				       elInfoOld->coord_[2]);
258
	    }
259

260
261
262
	    neighbourCoord_[1][0] = coord_[0];
	    neighbourCoord_[1][1] = coord_[2];
	    neighbourCoord_[1][2] = oppCoord_[1];  
263
264
	  }
	} else {
265
266
267
268
	  neighbour_[1] = elem->getSecondChild();
	  oppVertex_[1] = 0;

	  if (fill_opp_coords) {
269
	    oppCoord_[1] = elInfoOld->coord_[1];
270

271
272
	    neighbourCoord_[1][0] = elInfoOld->coord_[1];
	    neighbourCoord_[1][1] = elInfoOld->coord_[2];
273
	    neighbourCoord_[1][2] = coord_[2];
274
275
276
277
	  }
	}


278
279
280
	// Calculation of the neighbour 0, its oppCoords and the
	// cooresponding oppVertex.
	
281
	nb = elInfoOld->neighbour_[2];
282
	if (nb) {
283
	  TEST(elInfoOld->oppVertex_[2] == 2)("invalid neighbour\n"); 
284
285
	  TEST_EXIT_DBG(nb->getFirstChild())("missing first child?\n");
	  TEST_EXIT_DBG(nb->getSecondChild())("missing second child?\n");
286
287
288
289
290
291
	 
	  nb = nb->getSecondChild();

	  if (nb->getFirstChild()) {
	    oppVertex_[0] = 2;

292
	    if (fill_opp_coords) {
293
	      if (nb->isNewCoordSet()) {
294
295
		oppCoord_[0] = *(nb->getNewCoord());
	      } else {
296
297
		oppCoord_[0].setMidpoint(elInfoOld->neighbourCoord_[2][1],
					 elInfoOld->neighbourCoord_[2][2]);
298
	      }
299

300
301
302
	      neighbourCoord_[0][0].setMidpoint(elInfoOld->neighbourCoord_[2][0],
						elInfoOld->neighbourCoord_[2][1]);
	      neighbourCoord_[0][1] = elInfoOld->neighbourCoord_[2][1];
303
304
305
306
307
308
309
	      neighbourCoord_[0][2] = oppCoord_[0];
	    }	   
 
	    nb = nb->getFirstChild();
	  } else {
	    oppVertex_[0] = 1;

310
	    if (fill_opp_coords) {
311
	      oppCoord_[0] = elInfoOld->oppCoord_[2];    
312

313
314
315
316
	      neighbourCoord_[0][0] = elInfoOld->neighbourCoord_[2][0];
	      neighbourCoord_[0][1] = elInfoOld->neighbourCoord_[2][2];
	      neighbourCoord_[0][2].setMidpoint(elInfoOld->neighbourCoord_[2][0],
						elInfoOld->neighbourCoord_[2][1]);
317
318
	    }
	  }
319
320
321
322
323
324
325
	}
	
	neighbour_[0] = nb;
      } else {   /* ichild == 1 */
	// Calculation of the neighbour 2, its oppCoords and the
	// cooresponding oppVertex.

326
327
	neighbour_[2] = elInfoOld->neighbour_[0];
	oppVertex_[2] = elInfoOld->oppVertex_[0];
328
329

	if (neighbour_[2] && fill_opp_coords) {
330
331
	  oppCoord_[2] = elInfoOld->oppCoord_[0];
	  neighbourCoord_[2] = elInfoOld->neighbourCoord_[0];
332
333
334
335
336
337
338
339
340
341
342
	}
	

	// Calculation of the neighbour 0, its oppCoords and the
	// cooresponding oppVertex.

	if (elem->getFirstChild()->getFirstChild()) {
	  neighbour_[0] = elem->getFirstChild()->getFirstChild();
	  oppVertex_[0] = 2;

	  if (fill_opp_coords) {
343
            if (elem->getFirstChild()->isNewCoordSet()) {
344
	      oppCoord_[0] = *(elem->getFirstChild()->getNewCoord());
345
	    } else {
346
347
	      oppCoord_[0].setMidpoint(elInfoOld->coord_[0], 
				       elInfoOld->coord_[2]);
348
	    }
349
350
351
352

	    neighbourCoord_[0][0] = coord_[2];
	    neighbourCoord_[0][1] = coord_[1];
	    neighbourCoord_[0][2] = oppCoord_[0];
353
	  }
354
355
356
357
358
	} else {
	  neighbour_[0] = elem->getFirstChild();
	  oppVertex_[0] = 1;

	  if (fill_opp_coords) {
359
	    oppCoord_[0] = elInfoOld->coord_[0];
360

361
362
	    neighbourCoord_[0][0] = elInfoOld->coord_[2];
	    neighbourCoord_[0][1] = elInfoOld->coord_[0];
363
	    neighbourCoord_[0][2] = coord_[2];
364
	  }
365
366
367
368
369
	}

	// Calculation of the neighbour 1, its oppCoords and the
	// cooresponding oppVertex.

370
	nb = elInfoOld->neighbour_[2];
371
	if (nb) {
372
	  TEST(elInfoOld->oppVertex_[2] == 2)("invalid neighbour\n"); 
373
374
375
376
377
	  TEST((nb = nb->getFirstChild()))("missing child?\n");

	  if (nb->getFirstChild()) {
	    oppVertex_[1] = 2;

378
	    if (fill_opp_coords) {
379
	      if (nb->isNewCoordSet()) {
380
		oppCoord_[1] = *(nb->getNewCoord());
381
	      } else {
382
383
		oppCoord_[1].setMidpoint(elInfoOld->neighbourCoord_[2][0],
					 elInfoOld->neighbourCoord_[2][2]);
384
	      }
385

386
387
388
	      neighbourCoord_[1][0] = elInfoOld->neighbourCoord_[2][0];
	      neighbourCoord_[1][1].setMidpoint(elInfoOld->neighbourCoord_[2][0],
						elInfoOld->neighbourCoord_[2][1]);
389
	      neighbourCoord_[1][2] = oppCoord_[1];
390
	    }
391
392
	    nb = nb->getSecondChild();

393
	  } else {
394
395
	    oppVertex_[1] = 0;

396
	    if (fill_opp_coords) {
397
	      oppCoord_[1] = elInfoOld->oppCoord_[2];
398

399
400
401
402
	      neighbourCoord_[1][0] = elInfoOld->neighbourCoord_[2][2];	      
	      neighbourCoord_[1][1] = elInfoOld->neighbourCoord_[2][0];
	      neighbourCoord_[1][2].setMidpoint(elInfoOld->neighbourCoord_[2][0],
						elInfoOld->neighbourCoord_[2][1]);
403
404
405
	    }
	  }
	}
406
407
408
409
410
	neighbour_[1] = nb;
      } // if (ichild == 0) {} else
    } // if (fill_flag.isSet(Mesh::FILL_NEIGH) || fillFlag_.isSet(Mesh::FILL_OPP_COORDS))
    

411
    if (fill_flag.isSet(Mesh::FILL_BOUND)) {
412
413
      if (elInfoOld->getBoundary(2)) {
	boundary_[5] = elInfoOld->getBoundary(2);
414
      } else {
415
	boundary_[5] = INTERIOR;
416
      }
417

418
      if (ichild == 0) {
419
420
421
	boundary_[3] = elInfoOld->getBoundary(5);
	boundary_[4] = elInfoOld->getBoundary(3);
	boundary_[0] = elInfoOld->getBoundary(2);
422
	boundary_[1] = INTERIOR;
423
	boundary_[2] = elInfoOld->getBoundary(1);
424
      } else {
425
426
	boundary_[3] = elInfoOld->getBoundary(4);
	boundary_[4] = elInfoOld->getBoundary(5);
427
	boundary_[0] = INTERIOR;
428
429
	boundary_[1] = elInfoOld->getBoundary(2);
	boundary_[2] = elInfoOld->getBoundary(0);
430
431
      }

432
433
      if (elInfoOld->getProjection(0) && 
	  elInfoOld->getProjection(0)->getType() == VOLUME_PROJECTION) {
434
	
435
	projection_[0] = elInfoOld->getProjection(0);
436
437
      } else { // boundary projection
	if (ichild == 0) {
438
	  projection_[0] = elInfoOld->getProjection(2);
439
	  projection_[1] = NULL;
440
	  projection_[2] = elInfoOld->getProjection(1);
441
442
	} else {
	  projection_[0] = NULL;
443
444
	  projection_[1] = elInfoOld->getProjection(2);
	  projection_[2] = elInfoOld->getProjection(0);
445
446
447
448
449
	}
      }
    }
  }

Thomas Witkowski's avatar
Thomas Witkowski committed
450
  double ElInfo2d::calcGrdLambda(DimVec<WorldVector<double> >& grd_lam)
451
  {
452
    FUNCNAME("ElInfo2d::calcGrdLambda()");
453
454

    testFlag(Mesh::FILL_COORDS);
455
456
  
    double adet = 0.0;
457
458
    int dim = mesh_->getDim();

Thomas Witkowski's avatar
Thomas Witkowski committed
459
    for (int i = 0; i < dimOfWorld; i++) {
460
461
      (*e1)[i] = coord_[1][i] - coord_[0][i];
      (*e2)[i] = coord_[2][i] - coord_[0][i];
462
463
    }

Thomas Witkowski's avatar
Thomas Witkowski committed
464
    if (dimOfWorld == 2) {
465
      double sdet = (*e1)[0] * (*e2)[1] - (*e1)[1] * (*e2)[0];
466
467
468
469
      adet = abs(sdet);

      if (adet < 1.0E-25) {
	MSG("abs(det) = %f\n", adet);
470
	for (int i = 0; i <= dim; i++)
Thomas Witkowski's avatar
Thomas Witkowski committed
471
	  for (int j = 0; j < dimOfWorld; j++)
472
	    grd_lam[i][j] = 0.0;
473
474
      } else {
	double det1 = 1.0 / sdet;
475
476
477
478
479

	grd_lam[1][0] = (*e2)[1] * det1;  // a11: (a_ij) = A^{-T}
	grd_lam[1][1] = -(*e2)[0] * det1; // a21
	grd_lam[2][0] = -(*e1)[1] * det1; // a12
	grd_lam[2][1] = (*e1)[0] * det1;  // a22
480
481
	grd_lam[0][0] = - grd_lam[1][0] - grd_lam[2][0];
	grd_lam[0][1] = - grd_lam[1][1] - grd_lam[2][1];
482
      }
483
484
    } else {  
      vectorProduct(*e1, *e2, *normal);
485

486
      adet = norm(normal);
487
488
489

      if (adet < 1.0E-15) {
	MSG("abs(det) = %lf\n", adet);
490
	for (int i = 0; i <= dim; i++)
Thomas Witkowski's avatar
Thomas Witkowski committed
491
	  for (int j = 0; j < dimOfWorld; j++)
492
493
	    grd_lam[i][j] = 0.0;
      } else {
494
495
	vectorProduct(*e2, *normal, grd_lam[1]);
	vectorProduct(*normal, *e1, grd_lam[2]);
496
      
497
	double adet2 = 1.0 / (adet * adet);
498

Thomas Witkowski's avatar
Thomas Witkowski committed
499
	for (int i = 0; i < dimOfWorld; i++) {
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
	  grd_lam[1][i] *= adet2;
	  grd_lam[2][i] *= adet2;
	}

	grd_lam[0][0] = - grd_lam[1][0] - grd_lam[2][0];
	grd_lam[0][1] = - grd_lam[1][1] - grd_lam[2][1];
	grd_lam[0][2] = - grd_lam[1][2] - grd_lam[2][2];
      }
    }

    return adet;
  }

  const int ElInfo2d::worldToCoord(const WorldVector<double>& xy,
				   DimVec<double>* lambda) const
  {
516
    FUNCNAME("ElInfo::worldToCoord()");
517

518
    TEST_EXIT_DBG(lambda)("lambda must not be NULL\n");
519

520
521
522
523
    DimVec<WorldVector<double> > edge(mesh_->getDim(), NO_INIT);
    WorldVector<double> x; 
    static DimVec<double> vec(mesh_->getDim(), NO_INIT);

524
525
    int dim = mesh_->getDim();

526
527
    for (int j = 0; j < dimOfWorld; j++) {
      double x0 = coord_[dim][j];
528
      x[j] = xy[j] - x0;
529
      for (int i = 0; i < dim; i++)
530
531
532
	edge[i][j] = coord_[i][j] - x0;
    }
  
533
534
535
    double det  = edge[0][0] * edge[1][1] - edge[0][1] * edge[1][0]; 
    double det0 =       x[0] * edge[1][1] -       x[1] * edge[1][0]; 
    double det1 = edge[0][0] * x[1]       - edge[0][1] * x[0]; 
536
537
538

    if (abs(det) < DBL_TOL) {
      ERROR("det = %le; abort\n", det);
539
540
      for (int i = 0; i <= dim; i++) 
	(*lambda)[i] = 1.0/dim;
541
542
543
544
545
546
547
548
549
      return 0;
    }

    (*lambda)[0] = det0 / det;
    (*lambda)[1] = det1 / det;
    (*lambda)[2] = 1.0 - (*lambda)[0] - (*lambda)[1];

    int k = -1;
    double lmin = 0.0;
550
    for (int i = 0; i <= dim; i++) {
551
552
553
554
555
556
557
558
559
560
561
562
      if ((*lambda)[i] < -1.E-5) {
	if ((*lambda)[i] < lmin) {
	  k = i;
	  lmin = (*lambda)[i];
	}
      }
    }

    return k;
  }


Thomas Witkowski's avatar
Thomas Witkowski committed
563
  double ElInfo2d::getNormal(int side, WorldVector<double> &normal)
564
  {
565
    FUNCNAME("ElInfo::getNormal()");
566

567
568
    int i0 = (side + 1) % 3;
    int i1 = (side + 2) % 3;
569

Thomas Witkowski's avatar
Thomas Witkowski committed
570
    if (dimOfWorld == 2){
571
572
573
574
575
      normal[0] = coord_[i1][1] - coord_[i0][1];
      normal[1] = coord_[i0][0] - coord_[i1][0];
    } else { // dow == 3
      WorldVector<double> e0, e1,e2, elementNormal;

576
577
578
579
580
581
      e0 = coord_[i1]; 
      e0 -= coord_[i0];
      e1 = coord_[i1]; 
      e1 -= coord_[side];
      e2 = coord_[i0]; 
      e2 -= coord_[side];
582
583
584
585
586

      vectorProduct(e1, e2, elementNormal);
      vectorProduct(elementNormal, e0, normal);
    }

587
    double det = norm(&normal);
588

589
    TEST_EXIT_DBG(det > 1.e-30)("det = 0 on face %d\n", side);
590
591
592

    normal *= 1.0 / det;
    
Thomas Witkowski's avatar
Thomas Witkowski committed
593
    return det;
594
595
596
597
598
599
600
  }

  /****************************************************************************/
  /*  calculate the normal of the element for dim of world = dim + 1          */
  /*  return the absulute value of the determinant from the                   */
  /*  transformation to the reference element                                 */
  /****************************************************************************/
Thomas Witkowski's avatar
Thomas Witkowski committed
601
  double ElInfo2d::getElementNormal(WorldVector<double> &elementNormal) const
602
  {
603
    FUNCNAME("ElInfo::getElementNormal()");
604

Thomas Witkowski's avatar
Thomas Witkowski committed
605
606
    TEST_EXIT_DBG(dimOfWorld == 3)
      (" element normal only well defined for  DIM_OF_WORLD = DIM + 1 !!");
607

608
609
    WorldVector<double> e0 = coord_[1] - coord_[0];
    WorldVector<double> e1 = coord_[2] - coord_[0];
610
611
612

    vectorProduct(e0, e1, elementNormal);

613
    double det = norm(&elementNormal);
614

615
    TEST_EXIT_DBG(det > 1.e-30)("det = 0");
616
617
618

    elementNormal *= 1.0 / det;
    
Thomas Witkowski's avatar
Thomas Witkowski committed
619
    return det;
620
  }
621

622
  void ElInfo2d::getRefSimplexCoords(const BasisFunction *basisFcts,
623
				     mtl::dense2D<double>& coords) const
624
  {
625
    TEST_EXIT(basisFcts->getDegree() == 1)("Wrong basis function degree!\n");
626

627
    coords = mat_d1;
628
629
  }

630
631
  void ElInfo2d::getSubElementCoords(const BasisFunction *basisFcts,
				     int iChild,
632
				     mtl::dense2D<double>& coords) const
633
  {
634
635
636
637
638
639
640
641
642
643
644
645
646
647
    FUNCNAME("ElInfo1d::getSubElementCoords()");

    switch (basisFcts->getDegree()) {
    case 1:
      if (iChild == 0)
	coords *= mat_d1_left;
      else
	coords *= mat_d1_right;

      break;
    case 2:
      break;
    default:
      ERROR_EXIT("Not yet implemented!\n");
648
649
650
    }
  }

651
}