CFE_NormAndErrorFcts.cc 30.3 KB
Newer Older
1
#include <vector>
2
#include "CFE_NormAndErrorFcts.h"
3
4
5
6
#include "Mesh.h"
#include "Traverse.h"
#include "SubElInfo.h"

7
namespace AMDiS {
8

9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
  double CFE_NormAndErrorFcts::L2_err_abs = 0.0;
  double CFE_NormAndErrorFcts::L2_u_norm = 0.0;
  double CFE_NormAndErrorFcts::H1_err_abs = 0.0;
  double CFE_NormAndErrorFcts::H1_u_norm = 0.0;

  double
  ElementL1Norm_Analyt::calcElNorm(ElInfo *elInfo, 
				   const double &det,
				   const double &fac)
  {
    double val = 0.0;
    const WorldVector<double> *worldCoordsAtQP;

    for (int iq = 0; iq < nQPts; ++iq) {
      worldCoordsAtQP = elInfo->coordToWorld(q->getLambda(iq), NULL);
      val += q->getWeight(iq) * fabs((*f)(*worldCoordsAtQP));
    }
    double nrm = det * val;
27

28
    return nrm;
29
30
  }

31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
  double
  ElementL2Norm_Analyt::calcElNorm(ElInfo *elInfo, 
				   const double &det,
				   const double &fac)
  {
    double val = 0.0;
    const WorldVector<double> *worldCoordsAtQP;

    for (int iq = 0; iq < nQPts; ++iq) {
      worldCoordsAtQP = elInfo->coordToWorld(q->getLambda(iq), NULL);
      val += q->getWeight(iq) * sqr((*f)(*worldCoordsAtQP));
    }
    double nrm = det * val;

    return nrm;
  }
47

48
49
50
51
52
53
54
55
56
57
58
  double
  ElementH1Norm_Analyt::calcElNorm(ElInfo *elInfo, 
				   const double &det,
				   const double &fac)
  {
    double val = 0.0;
    double norm_grd2;
    const WorldVector<double> *worldCoordsAtQP;

    for (int iq = 0; iq < nQPts; ++iq) {
      worldCoordsAtQP = elInfo->coordToWorld(q->getLambda(iq), NULL);
59
    
60
61
62
      norm_grd2 = 0.0;
      for (int j = 0; j < dim; j++)
	norm_grd2 += sqr(((*grd)(*worldCoordsAtQP))[j]);
63
    
64
65
66
67
68
      val += q->getWeight(iq) * norm_grd2;
    }
    double nrm = det * val;

    return nrm;
69
70
  }

71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
  double
  ElementL1Norm_DOF::calcElNorm(ElInfo *elInfo, 
				const double &det,
				const double &fac)
  {
    double val = 0.0;
    const double *dofAtQPs = dofVec->getVecAtQPs(elInfo,
						 q,
						 NULL,
						 NULL); 

    for (int iq = 0; iq < nQPts; ++iq) {
      val += q->getWeight(iq) * fabs(dofAtQPs[iq]);
    }
    double nrm = det * val;
86

87
    return nrm;
88
89
  }

90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
  double
  ElementL2Norm_DOF::calcElNorm(ElInfo *elInfo, 
				const double &det,
				const double &fac)
  {
    double val = 0.0;
    const double *dofAtQPs = dofVec->getVecAtQPs(elInfo,
						 q,
						 NULL,
						 NULL); 

    for (int iq = 0; iq < nQPts; ++iq) {
      val += q->getWeight(iq) * sqr(dofAtQPs[iq]);
    }
    double nrm = det * val;
105

106
    return nrm;
107
108
  }

109
110
111
112
113
114
115
116
117
118
119
120
121
  double
  ElementH1Norm_DOF::calcElNorm(ElInfo *elInfo, 
				const double &det,
				const double &fac)
  {
    double val = 0.0;
    double norm_grd2;
    const WorldVector<double> *grdDofAtQPs = dofVec->getGrdAtQPs(elInfo, 
								 q, 
								 NULL, 
								 NULL);

    for (int iq = 0; iq < nQPts; ++iq) {
122
    
123
124
125
      norm_grd2 = 0.0;
      for (int j = 0; j < dim; ++j)
	norm_grd2 += sqr(grdDofAtQPs[iq][j]);
126
    
127
128
129
      val += q->getWeight(iq) * norm_grd2;
    }
    double nrm = det * val;
130

131
132
    return nrm;
  }
133

134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
  double
  ElementL2Err::calcElNorm(ElInfo *elInfo, 
			   const double &det, 
			   const double &fac)
  {
    double val = 0.0;
    double val_nrm = 0.0;
    const double *uhAtQPs = uh->getVecAtQPs(elInfo,
					    q,
					    NULL,
					    NULL); 
    const WorldVector<double> *worldCoordsAtQP;

    for (int iq = 0; iq < nQPts; ++iq) {
      worldCoordsAtQP = elInfo->coordToWorld(q->getLambda(iq), NULL);
      val += q->getWeight(iq) * sqr((*u)(*worldCoordsAtQP) - uhAtQPs[iq]);
150
    
151
152
153
      if (relErr) 
	val_nrm += q->getWeight(iq) * sqr((*u)(*worldCoordsAtQP));
    }
154

155
    double err = det * val;
156

157
158
    if (relErr)
      nrmU += fac * det * val_nrm;
159

160
161
    return err;
  }
162

163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
  double
  ElementH1Err::calcElNorm(ElInfo *elInfo, 
			   const double &det,
			   const double &fac)
  {
    double val = 0.0;
    double val_nrm = 0.0;
    double norm_err_grd2;
    double norm_grd2;
    const WorldVector<double> *grdUhAtQPs = uh->getGrdAtQPs(elInfo,
							    q,
							    NULL,
							    NULL); 
    const WorldVector<double> *worldCoordsAtQP;

    for (int iq = 0; iq < nQPts; ++iq) {

      worldCoordsAtQP = elInfo->coordToWorld(q->getLambda(iq), NULL);

      norm_err_grd2 = 0.0;
      for (int j = 0; j < dim; ++j)
	norm_err_grd2 += 
	  sqr(((*grdu)(*worldCoordsAtQP))[j] - grdUhAtQPs[iq][j]);
186
    
187
      val += q->getWeight(iq) * norm_err_grd2;
188
    
189
190
191
192
      if (relErr) {
	norm_grd2 = 0.0;
	for (int j = 0; j < dim; ++j)
	  norm_grd2 += sqr(((*grdu)(*worldCoordsAtQP))[j]);
193
      
194
195
	val_nrm += q->getWeight(iq) * norm_grd2;
      }
196
    }
197
    double err = det * val;
198
  
199
200
    if (relErr) 
      nrmGrdU += fac * det * val_nrm;
201
  
202
    return err;
203
204
  }

205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
  double
  CFE_NormAndErrorFcts::Norm_IntNoBound(ElementNorm *elNorm,
					ElementLevelSet *elLS,
					Flag fillFlag,
					int deg, 
					Quadrature *q)
  {
    FUNCNAME("CFE_NormAndErrorFcts::Norm_IntNoBound()");

    int dim = elLS->getDim();
    Mesh *mesh = elLS->getMesh();
    double nrm = 0.0;
    int elStatus;

    // ===== Get quadratures. =====
    if (!q) {
      q = Quadrature::provideQuadrature(dim, deg);
    }
    elNorm->setQuadrature(q);
224
225


226
227
    // ===== Traverse mesh and calculate integral on each element. =====
    TraverseStack stack;
228

229
    ElInfo *elInfo = stack.traverseFirst(mesh, -1, fillFlag);
230

231
    while(elInfo) {
232

233
234
      // Check whether current element is cut by the zero level set.
      elStatus = elLS->createElementLevelSet(elInfo);
235

236
      if (elStatus == ElementLevelSet::LEVEL_SET_INTERIOR) {
237

238
239
240
	// -------------------------------------------------------------------
	//  Element is in the domain with negative level set function values.
	// -------------------------------------------------------------------
241

242
	elLS->setLevelSetDomain(ElementLevelSet::LEVEL_SET_INTERIOR);
243

244
245
	nrm += elNorm->calcElNorm(elInfo, fabs(elInfo->getDet()));
      }
246

247
      elInfo = stack.traverseNext(elInfo);
248

249
    }  // end of: mesh traverse
250

251
    return nrm;
252
253
  }

254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
  double
  CFE_NormAndErrorFcts::Norm_IntBound(ElementNorm *elNorm,
				      ElementLevelSet *elLS,
				      Flag fillFlag,
				      int deg, 
				      Quadrature *q)
  {
    FUNCNAME("CFE_NormAndErrorFcts::Norm_IntBound()");

    int dim = elLS->getDim();
    Mesh *mesh = elLS->getMesh();
    double nrm = 0.0;
    double el_norm;
    VectorOfFixVecs<DimVec<double> > *intersecPts;
    int numIntersecPts;
    SubPolytope *subPolytope;
    ScalableQuadrature *scalQuad;
    int nScalQPts;
    int elStatus;

    // ===== Get quadratures. =====
    if (!q) {
      q = Quadrature::provideQuadrature(dim, deg);
    }
    scalQuad = NEW ScalableQuadrature(q);
    nScalQPts = scalQuad->getNumPoints();
280
281


282
283
    // ===== Traverse mesh and calculate integral on each element. =====
    TraverseStack stack;
284

285
    ElInfo *elInfo = stack.traverseFirst(mesh, -1, fillFlag);
286

287
288
    while(elInfo) {
      el_norm = 0.0;
289

290
291
      // Check whether current element is cut by the zero level set.
      elStatus = elLS->createElementLevelSet(elInfo);
292

293
      if (elStatus == ElementLevelSet::LEVEL_SET_BOUNDARY) {
294

295
296
297
	// -------------------------------------------------------------------
	//  Element is cut by the zero level set.
	// -------------------------------------------------------------------
298

299
300
301
	// Calculate norm on subpolyope.
	intersecPts = elLS->getElIntersecPoints();
	numIntersecPts = elLS->getNumElIntersecPoints();
302

303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
	// -----------------------------------------------------------------
	//  Subelement may be inside the domain with negative level set
	//  function value as well as inside the domain with positive
	//  function value.
	//
	//  Whether a subelement is in the domain with negative or positive
	//  level set function values is checked by the level set function
	//  value of the first vertex of the subelement. (The subelements 
	//  are created in such a way that this vertex always is a vertex 
	//  of the element and not an intersection point. Thus the level set 
	//  function value of this vertex really is unequal to zero.)

	subPolytope = NEW SubPolytope(elInfo, 
				      intersecPts, 
				      numIntersecPts, 
				      0);
319

320
321
	elLS->setLevelSetDomain(
				elLS->getVertexPos(subPolytope->getSubElement(0)->getLambda(0)));
322

323
324
325
326
	el_norm = calcSubPolNorm(elInfo,
				 subPolytope,
				 elNorm,
				 scalQuad);
327

328
329
330
331
332
	// Calculate integral on the other element part.
	if (elLS->getLevelSetDomain() == ElementLevelSet::LEVEL_SET_EXTERIOR) 
	  elLS->setLevelSetDomain(ElementLevelSet::LEVEL_SET_INTERIOR);
	else 
	  elLS->setLevelSetDomain(ElementLevelSet::LEVEL_SET_EXTERIOR);
333

334
335
	elNorm->setQuadrature(q);
	el_norm += elNorm->calcElNorm(elInfo, fabs(elInfo->getDet()));
336

337
338
339
340
341
	el_norm -= calcSubPolNorm(elInfo,
				  subPolytope,
				  elNorm,
				  scalQuad,
				  -1.0);
342

343
	nrm += el_norm;
344
    
345
346
347
348
	// Free data.
	DELETE subPolytope;
      }
      else if (elStatus == ElementLevelSet::LEVEL_SET_INTERIOR) {
349

350
351
352
	// -------------------------------------------------------------------
	//  Element is in the domain with negative level set function values.
	// -------------------------------------------------------------------
353

354
	elLS->setLevelSetDomain(ElementLevelSet::LEVEL_SET_INTERIOR);
355

356
357
358
	elNorm->setQuadrature(q);
	nrm += elNorm->calcElNorm(elInfo, fabs(elInfo->getDet()));
      }
359

360
      elInfo = stack.traverseNext(elInfo);
361

362
    }  // end of: mesh traverse
363

364
    DELETE scalQuad;
365

366
    return nrm;
367
368
  }

369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
  double
  CFE_NormAndErrorFcts::Norm_Int(ElementNorm *elNorm,
				 ElementLevelSet *elLS,
				 Flag fillFlag,
				 int deg, 
				 Quadrature *q)
  {
    FUNCNAME("CFE_NormAndErrorFcts::Norm_Int()");

    int dim = elLS->getDim();
    Mesh *mesh = elLS->getMesh();
    double nrm = 0.0;
    double el_norm;
    VectorOfFixVecs<DimVec<double> > *intersecPts;
    int numIntersecPts;
    int vertex_interior;
    SubPolytope *subPolytope;
    ScalableQuadrature *scalQuad;
    int nScalQPts;
    int elStatus;

    // ===== Get quadratures. =====
    if (!q) {
      q = Quadrature::provideQuadrature(dim, deg);
    }
    scalQuad = NEW ScalableQuadrature(q);
    nScalQPts = scalQuad->getNumPoints();
396
397


398
399
    // ===== Traverse mesh and calculate integral on each element. =====
    TraverseStack stack;
400

401
    ElInfo *elInfo = stack.traverseFirst(mesh, -1, fillFlag);
402

403
404
    while(elInfo) {
      el_norm = 0.0;
405

406
407
      // Check whether current element is cut by the zero level set.
      elStatus = elLS->createElementLevelSet(elInfo);
408

409
      if (elStatus == ElementLevelSet::LEVEL_SET_BOUNDARY) {
410

411
412
413
	// -------------------------------------------------------------------
	//  Element is cut by the zero level set.
	// -------------------------------------------------------------------
414

415
416
417
	// Create subelements.
	intersecPts = elLS->getElIntersecPoints();
	numIntersecPts = elLS->getNumElIntersecPoints();
418

419
420
421
422
423
	if (dim == 1 || (dim == 3 && numIntersecPts == 4)) {

	  // -----------------------------------------------------------------
	  //  Subelement(s) are inside the domain with negative level set
	  //  function value.
424

425
426
427
428
429
430
	  // Get vertex with negative level set function value.
	  for (int i=0; i<=dim; ++i) {
	    if (elLS->getElVertLevelSetVec(i) < 0) {
	      vertex_interior = i;
	      break;
	    }
431
	  }
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460

	  subPolytope = NEW SubPolytope(elInfo, 
					intersecPts, 
					numIntersecPts, 
					vertex_interior);

	  elLS->setLevelSetDomain(ElementLevelSet::LEVEL_SET_INTERIOR);
	}
	else {

	  // -----------------------------------------------------------------
	  //  Subelement may be inside the domain with negative level set
	  //  function value as well as inside the domain with positive
	  //  function value.
	  //
	  //  Whether a subelement is in the domain with negative or positive
	  //  level set function values is checked by the level set function
	  //  value of the first vertex of the subelement. (The subelements 
	  //  are created in such a way that this vertex always is a vertex 
	  //  of the element and not an intersection point. Thus the level set 
	  //  function value of this vertex really is unequal to zero.)

	  subPolytope = NEW SubPolytope(elInfo, 
					intersecPts, 
					numIntersecPts, 
					0);

	  elLS->setLevelSetDomain(
				  elLS->getVertexPos(subPolytope->getSubElement(0)->getLambda(0)));
461
462
	}

463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
	// Calculate norm on subpolytope.
	if (elLS->getLevelSetDomain() == ElementLevelSet::LEVEL_SET_INTERIOR)
	  el_norm = calcSubPolNorm(elInfo,
				   subPolytope,
				   elNorm,
				   scalQuad);
	else 
	  el_norm = calcSubPolNorm(elInfo,
				   subPolytope,
				   elNorm,
				   scalQuad,
				   -1.0);

	// -------------------------------------------------------------------
	// In case the subelement is in the domain with positive level set
	// function values:
	// Calculate the integral on the element part with negative
	// level set function values by substracting the integral on the
	// subelement from the integral on the complete element.
	if (elLS->getLevelSetDomain() == ElementLevelSet::LEVEL_SET_EXTERIOR) {

	  elLS->setLevelSetDomain(ElementLevelSet::LEVEL_SET_INTERIOR);

	  elNorm->setQuadrature(q);
	  el_norm *= -1.0;
	  el_norm += elNorm->calcElNorm(elInfo, fabs(elInfo->getDet()));
	}

	// Free data.
	DELETE subPolytope;
      }
      else if (elStatus == ElementLevelSet::LEVEL_SET_INTERIOR) {

	// -------------------------------------------------------------------
	//  Element is in the domain with negative level set function values.
	// -------------------------------------------------------------------
499
500

	elLS->setLevelSetDomain(ElementLevelSet::LEVEL_SET_INTERIOR);
501
502
503

	elNorm->setQuadrature(q);
	el_norm = elNorm->calcElNorm(elInfo, fabs(elInfo->getDet()));
504
      }
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563

      nrm += el_norm;
      elInfo = stack.traverseNext(elInfo);

    }  // end of: mesh traverse

    DELETE scalQuad;

    return nrm;
  }

  double
  CFE_NormAndErrorFcts::Norm_Bound(ElementNorm *elNorm,
				   ElementLevelSet *elLS,
				   Flag fillFlag,
				   int deg, 
				   Quadrature *q)
  {
    FUNCNAME("CFE_NormAndErrorFcts::Norm_Bound()");

    int dim = elLS->getDim();
    Mesh *mesh = elLS->getMesh();
    double nrm = 0.0;
    double el_norm;
    VectorOfFixVecs<DimVec<double> > *intersecPts;
    int numIntersecPts;
    SubPolytope *subPolytope;
    ScalableQuadrature *scalQuad;
    int nScalQPts;
    int elStatus;

    // ===== Get quadratures. =====
    if (!q) {
      q = Quadrature::provideQuadrature(dim, deg);
    }
    scalQuad = NEW ScalableQuadrature(q);
    nScalQPts = scalQuad->getNumPoints();


    // ===== Traverse mesh and calculate integral on each element. =====
    TraverseStack stack;

    ElInfo *elInfo = stack.traverseFirst(mesh, -1, fillFlag);

    while(elInfo) {
      el_norm = 0.0;

      // Check whether current element is cut by the zero level set.
      elStatus = elLS->createElementLevelSet(elInfo);

      if (elStatus == ElementLevelSet::LEVEL_SET_BOUNDARY) {

	// -------------------------------------------------------------------
	//  Element is cut by the zero level set.
	// -------------------------------------------------------------------

	// Calculate norm on subpolyope.
	intersecPts = elLS->getElIntersecPoints();
	numIntersecPts = elLS->getNumElIntersecPoints();
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582

	// -----------------------------------------------------------------
	//  Subelement may be inside the domain with negative level set
	//  function value as well as inside the domain with positive
	//  function value.
	//
	//  Whether a subelement is in the domain with negative or positive
	//  level set function values is checked by the level set function
	//  value of the first vertex of the subelement. (The subelements 
	//  are created in such a way that this vertex always is a vertex 
	//  of the element and not an intersection point. Thus the level set 
	//  function value of this vertex really is unequal to zero.)

	subPolytope = NEW SubPolytope(elInfo, 
				      intersecPts, 
				      numIntersecPts, 
				      0);

	elLS->setLevelSetDomain(
583
				elLS->getVertexPos(subPolytope->getSubElement(0)->getLambda(0)));
584
585
586
587
588
589

	el_norm = calcSubPolNorm(elInfo,
				 subPolytope,
				 elNorm,
				 scalQuad);

590
591
592
593
594
	// Calculate integral on the other element part.
	if (elLS->getLevelSetDomain() == ElementLevelSet::LEVEL_SET_EXTERIOR) 
	  elLS->setLevelSetDomain(ElementLevelSet::LEVEL_SET_INTERIOR);
	else 
	  elLS->setLevelSetDomain(ElementLevelSet::LEVEL_SET_EXTERIOR);
595
596
597
598

	elNorm->setQuadrature(q);
	el_norm += elNorm->calcElNorm(elInfo, fabs(elInfo->getDet()));

599
600
601
602
603
	el_norm -= calcSubPolNorm(elInfo,
				  subPolytope,
				  elNorm,
				  scalQuad,
				  -1.0);
604

605
606
607
608
609
	nrm += el_norm;
    
	// Free data.
	DELETE subPolytope;
      }
610

611
      elInfo = stack.traverseNext(elInfo);
612

613
    }  // end of: mesh traverse
614

615
    DELETE scalQuad;
616

617
    return nrm;
618
619
  }

620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
  double
  CFE_NormAndErrorFcts::Norm_Complete(ElementNorm *elNorm,
				      ElementLevelSet *elLS,
				      Flag fillFlag,
				      int deg, 
				      Quadrature *q)
  {
    FUNCNAME("CFE_NormAndErrorFcts::Norm_Complete()");

    int dim = elLS->getDim();
    Mesh *mesh = elLS->getMesh();
    double nrm = 0.0;
    double el_norm;
    VectorOfFixVecs<DimVec<double> > *intersecPts;
    int numIntersecPts;
    SubPolytope *subPolytope;
    ScalableQuadrature *scalQuad;
    int nScalQPts;
    int elStatus;

    // ===== Get quadratures. =====
    if (!q) {
      q = Quadrature::provideQuadrature(dim, deg);
643
    }
644
645
    scalQuad = NEW ScalableQuadrature(q);
    nScalQPts = scalQuad->getNumPoints();
646
647


648
649
    // ===== Traverse mesh and calculate integral on each element. =====
    TraverseStack stack;
650

651
    ElInfo *elInfo = stack.traverseFirst(mesh, -1, fillFlag);
652

653
654
    while(elInfo) {
      el_norm = 0.0;
655

656
657
      // Check whether current element is cut by the zero level set.
      elStatus = elLS->createElementLevelSet(elInfo);
658

659
      if (elStatus == ElementLevelSet::LEVEL_SET_BOUNDARY) {
660

661
662
663
	// -------------------------------------------------------------------
	//  Element is cut by the zero level set.
	// -------------------------------------------------------------------
664

665
666
667
	// Calculate norm on subpolyope.
	intersecPts = elLS->getElIntersecPoints();
	numIntersecPts = elLS->getNumElIntersecPoints();
668

669
670
671
672
673
674
675
676
677
678
679
	// -----------------------------------------------------------------
	//  Subelement may be inside the domain with negative level set
	//  function value as well as inside the domain with positive
	//  function value.
	//
	//  Whether a subelement is in the domain with negative or positive
	//  level set function values is checked by the level set function
	//  value of the first vertex of the subelement. (The subelements 
	//  are created in such a way that this vertex always is a vertex 
	//  of the element and not an intersection point. Thus the level set 
	//  function value of this vertex really is unequal to zero.)
680

681
682
683
684
	subPolytope = NEW SubPolytope(elInfo, 
				      intersecPts, 
				      numIntersecPts, 
				      0);
685

686
687
	elLS->setLevelSetDomain(
				elLS->getVertexPos(subPolytope->getSubElement(0)->getLambda(0)));
688

689
690
691
692
	el_norm = calcSubPolNorm(elInfo,
				 subPolytope,
				 elNorm,
				 scalQuad);
693

694
695
696
697
698
	// Calculate integral on the other element part.
	if (elLS->getLevelSetDomain() == ElementLevelSet::LEVEL_SET_EXTERIOR) 
	  elLS->setLevelSetDomain(ElementLevelSet::LEVEL_SET_INTERIOR);
	else 
	  elLS->setLevelSetDomain(ElementLevelSet::LEVEL_SET_EXTERIOR);
699

700
701
	elNorm->setQuadrature(q);
	el_norm += elNorm->calcElNorm(elInfo, fabs(elInfo->getDet()));
702

703
704
705
706
707
	el_norm -= calcSubPolNorm(elInfo,
				  subPolytope,
				  elNorm,
				  scalQuad,
				  -1.0);
708

709
	nrm += el_norm;
710
    
711
712
713
714
	// Free data.
	DELETE subPolytope;
      }
      else {
715

716
717
718
719
	// -------------------------------------------------------------------
	//  Element is either completely in the domain with negative 
	//  or positive level set function values.
	// -------------------------------------------------------------------
720

721
	elLS->setLevelSetDomain(elStatus);
722

723
724
725
	elNorm->setQuadrature(q);
	nrm += elNorm->calcElNorm(elInfo, fabs(elInfo->getDet()));
      }
726

727
      elInfo = stack.traverseNext(elInfo);
728

729
    }  // end of: mesh traverse
730

731
    DELETE scalQuad;
732

733
    return nrm;
734
735
  }

736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
  double 
  CFE_NormAndErrorFcts::L1Norm_Analyt(
				      AbstractFunction<double, WorldVector<double> > *f, 
				      ElementLevelSet *elLS,
				      int domainFlag, 
				      int deg, 
				      Quadrature *q)
  {
    FUNCNAME("CFE_NormAndErrorFcts::L1Norm_Analyt");

    ElementL1Norm_Analyt *elNorm = NEW ElementL1Norm_Analyt(q, f);
    int dim = elLS->getDim();

    TEST_EXIT(dim == Global::getGeo(WORLD))
      ("doesn't work for dimension of problem != dimension of world!\n");

    Flag fillFlag = Mesh::CALL_LEAF_EL | 
      Mesh::FILL_COORDS |
      Mesh::FILL_DET;

    double nrm = 0.0;
    switch(domainFlag) {
    case -3: nrm = Norm_IntNoBound(elNorm, elLS, fillFlag, deg, q);
      break;
    case -2: nrm = Norm_IntBound(elNorm, elLS, fillFlag, deg, q);
      break;
    case -1: nrm = Norm_Int(elNorm, elLS, fillFlag, deg, q);
      break;
    case 0: nrm = Norm_Bound(elNorm, elLS, fillFlag, deg, q);
      break;
    case 1: nrm = Norm_Complete(elNorm, elLS, fillFlag, deg, q);
      break;
    default: ERROR_EXIT("illegal flag !\n");
      break;
    }
771

772
    DELETE elNorm;
773

774
    return nrm;  
775
776
  }

777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
  double 
  CFE_NormAndErrorFcts::L2NormSquare_Analyt(
					    AbstractFunction<double, WorldVector<double> > *f, 
					    ElementLevelSet *elLS,
					    int domainFlag, 
					    int deg, 
					    Quadrature *q)
  {
    FUNCNAME("CFE_NormAndErrorFcts::L2NormSquare_Analyt");

    ElementL2Norm_Analyt *elNorm = NEW ElementL2Norm_Analyt(q, f);
    int dim = elLS->getDim();

    TEST_EXIT(dim == Global::getGeo(WORLD))
      ("doesn't work for dimension of problem != dimension of world!\n");

    Flag fillFlag = Mesh::CALL_LEAF_EL | 
      Mesh::FILL_COORDS |
      Mesh::FILL_DET;

    double nrm = 0.0;
    switch(domainFlag) {
    case -3: nrm = Norm_IntNoBound(elNorm, elLS, fillFlag, deg, q);
      break;
    case -2: nrm = Norm_IntBound(elNorm, elLS, fillFlag, deg, q);
      break;
    case -1: nrm = Norm_Int(elNorm, elLS, fillFlag, deg, q);
      break;
    case 0: nrm = Norm_Bound(elNorm, elLS, fillFlag, deg, q);
      break;
    case 1: nrm = Norm_Complete(elNorm, elLS, fillFlag, deg, q);
      break;
    default: ERROR_EXIT("illegal flag !\n");
      break;
    }
812

813
    DELETE elNorm;
814

815
816
    return nrm;  
  }
817

818
819
820
821
822
823
824
825
826
  double 
  CFE_NormAndErrorFcts::L2Norm_Analyt(
				      AbstractFunction<double, WorldVector<double> > *f, 
				      ElementLevelSet *elLS,
				      int domainFlag, 
				      int deg, 
				      Quadrature *q)
  {
    return sqrt(L2NormSquare_Analyt(f, elLS, domainFlag, deg, q));
827
828
  }

829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
  double 
  CFE_NormAndErrorFcts::H1NormSquare_Analyt(
					    AbstractFunction<WorldVector<double>, WorldVector<double> > *grd, 
					    ElementLevelSet *elLS,
					    int domainFlag, 
					    int deg, 
					    Quadrature *q)
  {
    FUNCNAME("CFE_NormAndErrorFcts::H1NormSquare_Analyt");

    int dim = elLS->getDim();
    ElementH1Norm_Analyt *elNorm = NEW ElementH1Norm_Analyt(q, grd, dim);

    TEST_EXIT(dim == Global::getGeo(WORLD))
      ("doesn't work for dimension of problem != dimension of world!\n");

    Flag fillFlag = Mesh::CALL_LEAF_EL | 
      Mesh::FILL_COORDS |
      Mesh::FILL_DET;

    double nrm = 0.0;
    switch(domainFlag) {
    case -3: nrm = Norm_IntNoBound(elNorm, elLS, fillFlag, deg, q);
      break;
    case -2: nrm = Norm_IntBound(elNorm, elLS, fillFlag, deg, q);
      break;
    case -1: nrm = Norm_Int(elNorm, elLS, fillFlag, deg, q);
      break;
    case 0: nrm = Norm_Bound(elNorm, elLS, fillFlag, deg, q);
      break;
    case 1: nrm = Norm_Complete(elNorm, elLS, fillFlag, deg, q);
      break;
    default: ERROR_EXIT("illegal flag !\n");
      break;
    }
864

865
    DELETE elNorm;
866

867
868
    return nrm;  
  }
869

870
871
872
873
874
875
876
877
878
  double 
  CFE_NormAndErrorFcts::H1Norm_Analyt(
				      AbstractFunction<WorldVector<double>, WorldVector<double> > *grd, 
				      ElementLevelSet *elLS,
				      int domainFlag, 
				      int deg, 
				      Quadrature *q)
  {
    return sqrt(H1NormSquare_Analyt(grd, elLS, domainFlag, deg, q));
879
880
  }

881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
  double 
  CFE_NormAndErrorFcts::L1Norm_DOF(DOFVector<double> *dof, 
				   ElementLevelSet *elLS,
				   int domainFlag, 
				   int deg, 
				   Quadrature *q)
  {
    FUNCNAME("CFE_NormAndErrorFcts::L1Norm_DOF");

    ElementL1Norm_DOF *elNorm = NEW ElementL1Norm_DOF(q, dof);
    int dim = elLS->getDim();

    TEST_EXIT(dim == Global::getGeo(WORLD))
      ("doesn't work for dimension of problem != dimension of world!\n");

    Flag fillFlag = Mesh::CALL_LEAF_EL | 
      Mesh::FILL_COORDS |
      Mesh::FILL_DET;

    double nrm = 0.0;
    switch(domainFlag) {
    case -3: nrm = Norm_IntNoBound(elNorm, elLS, fillFlag, deg, q);
      break;
    case -2: nrm = Norm_IntBound(elNorm, elLS, fillFlag, deg, q);
      break;
    case -1: nrm = Norm_Int(elNorm, elLS, fillFlag, deg, q);
      break;
    case 0: nrm = Norm_Bound(elNorm, elLS, fillFlag, deg, q);
      break;
    case 1: nrm = Norm_Complete(elNorm, elLS, fillFlag, deg, q);
      break;
    default: ERROR_EXIT("illegal flag !\n");
      break;
    }
915

916
    DELETE elNorm;
917

918
    return nrm;  
919
920
  }

921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
  double 
  CFE_NormAndErrorFcts::L2NormSquare_DOF(DOFVector<double> *dof, 
					 ElementLevelSet *elLS,
					 int domainFlag, 
					 int deg, 
					 Quadrature *q)
  {
    FUNCNAME("CFE_NormAndErrorFcts::L2NormSquare_DOF");

    ElementL2Norm_DOF *elNorm = NEW ElementL2Norm_DOF(q, dof);
    int dim = elLS->getDim();

    TEST_EXIT(dim == Global::getGeo(WORLD))
      ("doesn't work for dimension of problem != dimension of world!\n");

    Flag fillFlag = Mesh::CALL_LEAF_EL | 
      Mesh::FILL_COORDS |
      Mesh::FILL_DET;

    double nrm = 0.0;
    switch(domainFlag) {
    case -3: nrm = Norm_IntNoBound(elNorm, elLS, fillFlag, deg, q);
      break;
    case -2: nrm = Norm_IntBound(elNorm, elLS, fillFlag, deg, q);
      break;
    case -1: nrm = Norm_Int(elNorm, elLS, fillFlag, deg, q);
      break;
    case 0: nrm = Norm_Bound(elNorm, elLS, fillFlag, deg, q);
      break;
    case 1: nrm = Norm_Complete(elNorm, elLS, fillFlag, deg, q);
      break;
    default: ERROR_EXIT("illegal flag !\n");
      break;
    }
955

956
    DELETE elNorm;
957

958
959
    return nrm;  
  }
960

961
962
963
964
965
966
967
968
  double 
  CFE_NormAndErrorFcts::L2Norm_DOF(DOFVector<double> *dof, 
				   ElementLevelSet *elLS,
				   int domainFlag, 
				   int deg, 
				   Quadrature *q)
  {
    return sqrt(L2NormSquare_DOF(dof, elLS, domainFlag, deg, q));
969
970
  }

971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
  double 
  CFE_NormAndErrorFcts::H1NormSquare_DOF(DOFVector<double> *dof, 
					 ElementLevelSet *elLS,
					 int domainFlag, 
					 int deg, 
					 Quadrature *q)
  {
    FUNCNAME("CFE_NormAndErrorFcts::H1NormSquare_DOF");

    int dim = elLS->getDim();
    ElementH1Norm_DOF *elNorm = NEW ElementH1Norm_DOF(q, dof, dim);

    TEST_EXIT(dim == Global::getGeo(WORLD))
      ("doesn't work for dimension of problem != dimension of world!\n");

    Flag fillFlag = Mesh::CALL_LEAF_EL | 
      Mesh::FILL_COORDS |
      Mesh::FILL_DET | 
      Mesh::FILL_GRD_LAMBDA;

    double nrm = 0.0;
    switch(domainFlag) {
    case -3: nrm = Norm_IntNoBound(elNorm, elLS, fillFlag, deg, q);
      break;
    case -2: nrm = Norm_IntBound(elNorm, elLS, fillFlag, deg, q);
      break;
    case -1: nrm = Norm_Int(elNorm, elLS, fillFlag, deg, q);
      break;
    case 0: nrm = Norm_Bound(elNorm, elLS, fillFlag, deg, q);
      break;