Peano
Loading...
Searching...
No Matches
DGUtilsTest.cpp
Go to the documentation of this file.
1#include "DGUtilsTest.h"
2#include "TestUtils.h"
3#include "../DGUtils.h"
4
6
7
8/*
9 * We use precomputed values for lagrange polynomials as basis function
10 * on Gauss-Legendre nodes
11 */
13 TestCase ("exahype2::dg::tests::DGUtilsTest") {
14}
15
16
18 testMethod( testGetIndex );
19 testMethod( testComputeGradientOnConstantSolution );
20 testMethod( testEvaluatePolynomialOrder1 );
21 testMethod( testEvaluatePolynomialOrder2 );
22}
23
24
26 const int order = 1;
27
29
30 #if Dimensions==2
31 dummyEvent.setX( {0.4,0.6} );
32 dummyEvent.setH( {0.2,0.2} );
33 double Q0[] = {1.2,1.2,1.2,1.2};
34 tarch::la::Vector<Dimensions,double> xCentre = {0.5,0.7};
36 #else
37 dummyEvent.setX( {0.4,0.6,0.8} );
38 dummyEvent.setH( {0.2,0.2,0.2} );
39 double Q0[] = {1.2,1.2,1.2,1.2,1.2,1.2,1.2,1.2};
40 tarch::la::Vector<Dimensions,double> xCentre = {0.5,0.7,0.9};
42 #endif
43
44 peano4::datamanagement::CellMarker cellMarker(dummyEvent);
45
46 double result;
48 cellMarker,
49 order,
51 1,
52 Q0,
53 xLeftBottom,
54 0
55 );
56 validateNumericalEqualsWithParams1( result, 1.2, cellMarker.toString() );
57
59 cellMarker,
60 order,
62 1,
63 Q0,
64 xCentre,
65 0
66 );
67 validateNumericalEqualsWithParams1( result, 1.2, cellMarker.toString() );
68}
69
70
72 const int order = 2;
73
75
76 #if Dimensions==2
77 dummyEvent.setX( {0.4,0.6} );
78 dummyEvent.setH( {0.2,0.2} );
79 double Q0[] = { 1.2, 1.2, 1.2,
80 1.2, 1.2, 1.2,
81 1.2, 1.2, 1.2 };
82 tarch::la::Vector<Dimensions,double> xCentre = {0.5,0.7};
84 #else
85 dummyEvent.setX( {0.4,0.6,0.8} );
86 dummyEvent.setH( {0.2,0.2,0.2} );
87 double Q0[] = { 1.2, 1.2, 1.2,
88 1.2, 1.2, 1.2,
89 1.2, 1.2, 1.2,
90 1.2, 1.2, 1.2,
91 1.2, 1.2, 1.2,
92 1.2, 1.2, 1.2,
93 1.2, 1.2, 1.2,
94 1.2, 1.2, 1.2,
95 1.2, 1.2, 1.2 };
96 tarch::la::Vector<Dimensions,double> xCentre = {0.5,0.7,0.9};
98 #endif
99
100 peano4::datamanagement::CellMarker cellMarker(dummyEvent);
101
102 double result;
104 cellMarker,
105 order,
107 1,
108 Q0,
109 xLeftBottom,
110 0
111 );
112 validateNumericalEqualsWithParams1( result, 1.2, cellMarker.toString() );
113
115 cellMarker,
116 order,
118 1,
119 Q0,
120 xCentre,
121 0
122 );
123 validateNumericalEqualsWithParams1( result, 1.2, cellMarker.toString() );
124}
125
126
128 const int order = 3;
129 const int nodesPerAxis = order+1;
130 const int nodesPerCell = getNodesPerCell(nodesPerAxis);
131
132 validateEquals(nodesPerCell, std::pow(nodesPerAxis,Dimensions));
133
134 tarch::la::Vector<Dimensions,int> strides = getStrides(nodesPerAxis);
135 validateEquals(strides[Dimensions-1], std::pow(nodesPerAxis,Dimensions-1));
136
137 tarch::la::Vector<Dimensions,int> firstIndex = getIndex(0, strides);
138 for(int i=0; i<Dimensions; i++){
139 validateEquals(firstIndex[i], 0);
140 }
141
142 tarch::la::Vector<Dimensions,int> lastIndex = getIndex(nodesPerCell-1, strides);
143 for(int i=0; i<Dimensions; i++){
144 validateEquals(lastIndex[i], nodesPerAxis-1);
145 }
146}
147
148
150 #if Dimensions==2
151 const int order = 3;
152 const int nodesPerAxis = order+1;
153 const int nodesPerCell = getNodesPerCell(nodesPerAxis);
154
155 // 1 unknown, 1 auxiliary variable
156 double cellQin[2*nodesPerCell];
157 double gradientValues[2*Dimensions];
158 for(int i=0; i<2*nodesPerCell; i++){
159 cellQin[i] = 1.0;
160 }
161
162 for(int node=0; node<nodesPerCell; node++){
164 cellQin,
166 10, //invDx
167 nodesPerAxis,
168 2, //strideQ
169 node,
170 gradientValues
171 );
172 for(int var=0; var<Dimensions; var++){
173 validateNumericalEquals(gradientValues[var], 0.0);
174 }
175 }
176 #endif
177}
#define testMethod(name)
Run a test method and check for errors.
Definition TestMacros.h:24
#define validateNumericalEquals(actualValue, validValue)
Definition TestMacros.h:428
#define validateNumericalEqualsWithParams1(actualValue, validValue, param0)
Definition TestMacros.h:486
#define validateEquals(actualValue, validValue)
Definition TestMacros.h:299
void run() override
This routine is triggered by the TestCaseCollection.
constexpr double QuadratureNodes1dP2[]
Definition TestUtils.h:18
constexpr double QuadratureNodes1dP1[]
Definition TestUtils.h:17
constexpr double DerivativeOperatorLagrangeP3[]
Definition TestUtils.h:20
tarch::la::Vector< Dimensions, int > getStrides(int nodesPerAxis)
Definition DGUtils.cpp:47
void computeGradient(const double *__restrict__ const QCell, const double *__restrict__ const derivativeOperator, const double invDx, const int nodesPerAxis, const int strideQ, const int scalarIndex, double *__restrict__ gradQ)
Definition DGUtils.cpp:110
tarch::la::Vector< Dimensions, int > getIndex(int node, tarch::la::Vector< Dimensions, int > strides)
Definition DGUtils.cpp:55
int getNodesPerCell(int nodesPerAxis)
The number of nodes in a cell is basically the input to the power of d.
Definition DGUtils.cpp:39
QStoreType evaluatePolynomial(const peano4::datamanagement::CellMarker &marker, int order, const double *__restrict__ QuadratureNodes1d, int unknownsPerDoF, const QStoreType *__restrict__ Q, const tarch::la::Vector< Dimensions, double > &x, int unknown)
Evaluate the DG polynomial.
Definition DGUtils.cpph:3
void setX(const tarch::la::Vector< Dimensions, double > &value)
void setH(const tarch::la::Vector< Dimensions, double > &value)
Simple vector class.
Definition Vector.h:150