| 1 |
// SPDX-FileCopyrightText: Copyright © DUNE Project contributors, see file LICENSE.md in module root |
| 2 |
// SPDX-License-Identifier: LGPL-2.1-or-later |
| 3 |
#include "config.h" |
| 4 |
|
| 5 |
#include <cstdio> |
| 6 |
|
| 7 |
#include <dune/common/parallel/mpihelper.hh> |
| 8 |
#include <dune/common/test/testsuite.hh> |
| 9 |
|
| 10 |
#include <dune/uggrid/initug.h> |
| 11 |
|
| 12 |
#include "evm.h" |
| 13 |
#include "gm.h" |
| 14 |
#include "rm.h" |
| 15 |
|
| 16 |
USING_UGDIM_NAMESPACE |
| 17 |
USING_UG_NAMESPACE |
| 18 |
|
| 19 |
static bool CheckVolumes(REFRULE const *Rule) |
| 20 |
{ |
| 21 |
bool pass = true; |
| 22 |
|
| 23 |
DOUBLE_VECTOR coords [MAX_CORNERS_OF_ELEM+MAX_NEW_CORNERS_DIM]; |
| 24 |
DOUBLE_VECTOR coord; |
| 25 |
DOUBLE_VECTOR p[MAX_CORNERS_OF_ELEM]; |
| 26 |
|
| 27 |
/* this function work only for TETRAHEDRA!!! */ |
| 28 |
int tag = TETRAHEDRON; |
| 29 |
|
| 30 |
/* reset coords */ |
| 31 |
for (int i=0; i<MAX_CORNERS_OF_ELEM+MAX_NEW_CORNERS_DIM; i++) |
| 32 |
V3_CLEAR(coords[i]) |
| 33 |
|
| 34 |
/* compute coordinates of corners */ |
| 35 |
int j = 0; |
| 36 |
for (int i=0; i<CORNERS_OF_TAG(tag); i++,j++) |
| 37 |
V3_COPY(LOCAL_COORD_OF_TAG(tag,i),coords[j]) |
| 38 |
|
| 39 |
/* compute coordinates of midnodes */ |
| 40 |
for (int i=0; i<EDGES_OF_TAG(tag); i++,j++) |
| 41 |
{ |
| 42 |
V3_CLEAR(coord) |
| 43 |
for (int k=0; k<CORNERS_OF_EDGE; k++) |
| 44 |
{ |
| 45 |
V3_ADD(LOCAL_COORD_OF_TAG(tag,CORNER_OF_EDGE_TAG(tag,i,k)),coord,coord) |
| 46 |
} |
| 47 |
V3_SCALE(1.0/CORNERS_OF_EDGE,coord) |
| 48 |
V3_COPY(coord,coords[j]); |
| 49 |
} |
| 50 |
|
| 51 |
/* compute coordinates of sidenodes */ |
| 52 |
for (int i=0; i<SIDES_OF_TAG(tag); i++,j++) |
| 53 |
{ |
| 54 |
V3_CLEAR(coord) |
| 55 |
for (int k=0; k<CORNERS_OF_SIDE_TAG(tag,i); k++) |
| 56 |
V3_ADD(LOCAL_COORD_OF_TAG(tag,CORNER_OF_SIDE_TAG(tag,i,k)),coord,coord) |
| 57 |
V3_SCALE(1.0/CORNERS_OF_SIDE_TAG(tag,i),coord) |
| 58 |
V3_COPY(coord,coords[j]); |
| 59 |
} |
| 60 |
|
| 61 |
/* compute coordinates of center node */ |
| 62 |
V3_CLEAR(coord) |
| 63 |
for (int i=0; i<CORNERS_OF_TAG(tag); i++) |
| 64 |
{ |
| 65 |
V3_ADD(LOCAL_COORD_OF_TAG(tag,i),coord,coord) |
| 66 |
} |
| 67 |
V3_SCALE(1.0/CORNERS_OF_TAG(tag),coord) |
| 68 |
V3_COPY(coord,coords[j]); |
| 69 |
|
| 70 |
for (int i=0; i<MAX_CORNERS_OF_ELEM+MAX_NEW_CORNERS_DIM; i++) |
| 71 |
{ |
| 72 |
printf("CheckVolumes(): i=%d x=%.8f y=%.8f z=%.8f\n", |
| 73 |
i,coords[i][0],coords[i][1],coords[i][2]); |
| 74 |
} |
| 75 |
|
| 76 |
/* check the son volumes being really greater than zero */ |
| 77 |
double sum=0.0; |
| 78 |
for (int i=0; i<NSONS_OF_RULE(Rule); i++) |
| 79 |
{ |
| 80 |
for (int k=1; k<4; k++) |
| 81 |
{ |
| 82 |
V3_SUBTRACT(coords[SON_CORNER_OF_RULE(Rule,i,k)],coords[SON_CORNER_OF_RULE(Rule,i,0)],p[k]) |
| 83 |
} |
| 84 |
|
| 85 |
double sp; |
| 86 |
// triple product of son |
| 87 |
V3_VECTOR_PRODUCT(p[1],p[2],p[0]) |
| 88 |
V3_SCALAR_PRODUCT(p[0],p[3],sp) |
| 89 |
|
| 90 |
if (sp<=0.0) |
| 91 |
{ |
| 92 |
printf("negative volume=%f for son=%d rule=%d\n",sp,i,MARK_OF_RULE(Rule)); |
| 93 |
pass = false; |
| 94 |
} |
| 95 |
sum += sp; |
| 96 |
|
| 97 |
} |
| 98 |
|
| 99 |
// check if volume of sons add up to volume of original tetrahedra |
| 100 |
// 6*Volume_original == sum over 6*volume_sons |
| 101 |
// exception for first rule |
| 102 |
if( sum != 1.0 && Rule->mark != 0) |
| 103 |
{ |
| 104 |
printf("Rule %d :sum over sons = %f != 1\n",Rule->mark,sum); |
| 105 |
pass = false; |
| 106 |
} |
| 107 |
|
| 108 |
return pass; |
| 109 |
} |
| 110 |
|
| 111 |
int main(int argc, char** argv) |
| 112 |
{ |
| 113 |
Dune::MPIHelper::instance(argc, argv); |
| 114 |
InitUg(&argc, &argv); |
| 115 |
|
| 116 |
bool pass = true; |
| 117 |
|
| 118 |
std::printf("Testing %d refinement rules for the tetrahedron...\n", MaxRules[TETRAHEDRON]); |
| 119 |
REFRULE* rules = RefRules[TETRAHEDRON]; |
| 120 |
for (int i = 0; i < MaxRules[TETRAHEDRON]; ++i) |
| 121 |
pass = pass && CheckVolumes(rules + i); |
| 122 |
|
| 123 |
ExitUg(); |
| 124 |
|
| 125 |
return pass ? 0 : 1; |
| 126 |
} |