Skip to content

Commit c74fa7d

Browse files
Add tests
1 parent 7a8cd28 commit c74fa7d

16 files changed

+325
-77
lines changed

tests/README.md

+10-7
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,25 @@ This page provides a brief description of the tests for the libCEED library.
44

55
The tests are organized by API object, and some tests are further organized, as required.
66

7-
0. Ceed Tests
7+
0. Ceed Tests
88
1. CeedVector Tests
99
1.0. CeedVector general tests
10-
1.1. CeedVector error tests
11-
2. CeedElemRestriction Tests
10+
1.1. CeedVector error tests
11+
2. CeedElemRestriction Tests
1212
3. CeedBasis Tests
1313
3.0. CeedBasis utility tests
1414
3.1. CeedBasis tensor basis tests
15-
3.2. CeedBasis simplex basis tests
15+
3.2. CeedBasis simplex basis tests
16+
3.3. CeedBasis non-tensor H(div) basis tests
17+
3.4. CeedBasis non-tensor H(curl) basis tests
1618
4. CeedQFunction Tests
1719
4.0. CeedQFunction user code tests
18-
4.1. CeedQFunction gallery code tests
20+
4.1. CeedQFunction gallery code tests
1921
5. CeedOperator Tests
2022
5.0. CeedOperator with tensor bases tests
2123
5.1. CeedOperator with simplex bases tests
2224
5.2. CeedOperator with operator composition tests
23-
5.3. CeedOperator and CeedQFunction assembly tests
25+
5.3. CeedOperator diagonal and CeedQFunction assembly tests
2426
5.4. CeedOperator element inverse tests
25-
5.5. CeedOperator multigrid level tests
27+
5.5. CeedOperator multigrid level tests
28+
5.6. CeedOperator full assembly tests

tests/output/t340-basis.out

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
CeedBasis (H(curl) space on a triangle element): dim=2 P=8 Q=4
2+
qref: 0.33333333 0.20000000 0.20000000 0.60000000 0.33333333 0.20000000 0.60000000 0.20000000
3+
qweight: -0.26041667 0.26041667 0.28125000 0.26041667
4+
interp[0]: -0.22222222 0.44444444 0.22222222 -0.44444444 -0.22222222 -0.22222222 2.66666667 0.00000000
5+
interp[1]: 0.08000000 0.48000000 0.56000000 -0.48000000 1.04000000 -0.72000000 2.24000000 -0.64000000
6+
interp[2]: 0.24000000 -0.48000000 -0.24000000 0.48000000 -0.56000000 -0.56000000 2.88000000 0.00000000
7+
interp[3]: -0.56000000 0.48000000 -0.08000000 -0.48000000 -0.72000000 1.04000000 1.60000000 0.64000000
8+
interp[4]: -0.44444444 0.22222222 -0.22222222 -0.22222222 0.22222222 -0.44444444 0.00000000 2.66666667
9+
interp[5]: -0.48000000 -0.08000000 1.04000000 -0.72000000 0.56000000 -0.48000000 -0.64000000 2.24000000
10+
interp[6]: -0.48000000 0.56000000 -0.72000000 1.04000000 -0.08000000 -0.48000000 0.64000000 1.60000000
11+
interp[7]: 0.48000000 -0.24000000 -0.56000000 -0.56000000 -0.24000000 0.48000000 0.00000000 2.88000000
12+
curl[0]: 2.00000000 2.00000000 -2.00000000 -2.00000000 2.00000000 2.00000000 0.00000000 0.00000000
13+
curl[1]: -1.20000000 -1.20000000 -8.40000000 1.20000000 8.40000000 -1.20000000 -9.60000000 9.60000000
14+
curl[2]: -1.20000000 8.40000000 1.20000000 -8.40000000 -1.20000000 -1.20000000 9.60000000 9.60000000
15+
curl[3]: 8.40000000 -1.20000000 1.20000000 1.20000000 -1.20000000 8.40000000 0.00000000 -19.20000000

tests/t320-basis.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/// @file
2-
/// Test creation and destruction of a 2D Simplex non-tensor H1 basis
3-
/// \test Test creation and destruction of a 2D Simplex non-tensor H1 basis
2+
/// Test creation and destruction of a 2D Simplex non-tensor H^1 basis
3+
/// \test Test creation and destruction of a 2D Simplex non-tensor H^1 basis
44
#include "t320-basis.h"
55

66
#include <ceed.h>

tests/t321-basis.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/// @file
2-
/// Test interpolation with a 2D Simplex non-tensor H1 basis
3-
/// \test Test interpolation with a 2D Simplex non-tensor H1 basis
2+
/// Test interpolation with a 2D Simplex non-tensor H^1 basis
3+
/// \test Test interpolation with a 2D Simplex non-tensor H^1 basis
44
#include <ceed.h>
55
#include <math.h>
66
#include <stdio.h>

tests/t322-basis.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/// @file
2-
/// Test integration with a 2D Simplex non-tensor H1 basis
3-
/// \test Test integration with a 2D Simplex non-tensor H1 basis
2+
/// Test integration with a 2D Simplex non-tensor H^1 basis
3+
/// \test Test integration with a 2D Simplex non-tensor H^1 basis
44
#include <ceed.h>
55
#include <math.h>
66
#include <stdio.h>

tests/t323-basis.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/// @file
2-
/// Test grad with a 2D Simplex non-tensor H1 basis
3-
/// \test Test grad with a 2D Simplex non-tensor H1 basis
2+
/// Test grad with a 2D Simplex non-tensor H^1 basis
3+
/// \test Test grad with a 2D Simplex non-tensor H^1 basis
44
#include <ceed.h>
55
#include <math.h>
66
#include <stdio.h>

tests/t324-basis.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/// @file
2-
/// Test grad transpose with a 2D Simplex non-tensor H1 basis
3-
/// \test Test grad transpose with a 2D Simplex non-tensor H1 basis
2+
/// Test grad transpose with a 2D Simplex non-tensor H^1 basis
3+
/// \test Test grad transpose with a 2D Simplex non-tensor H^1 basis
44
#include <ceed.h>
55
#include <math.h>
66
#include <stdio.h>

tests/t325-basis.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/// @file
2-
/// Test grad transpose with a 2D Simplex non-tensor H1 basis
3-
/// \test Test grad transpose with a 2D Simplex non-tensor H1 basis
2+
/// Test grad transpose with a 2D Simplex non-tensor H^1 basis
3+
/// \test Test grad transpose with a 2D Simplex non-tensor H^1 basis
44
#include <ceed.h>
55
#include <math.h>
66
#include <stdio.h>

tests/t330-basis.c

+5-12
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,25 @@
11
/// @file
2-
/// Test creation and destruction of a 2D Quad non-tensor Hdiv basis
3-
/// \test Test creation and destruction of a 2D Quad non-tensor Hdiv basis
2+
/// Test creation and destruction of a 2D Quad non-tensor H(div) basis
3+
/// \test Test creation and destruction of a 2D Quad non-tensor H(div) basis
44
#include "t330-basis.h"
55

66
#include <ceed.h>
77
#include <stdio.h>
88

99
int main(int argc, char **argv) {
1010
Ceed ceed;
11-
const CeedInt q = 3, dim = 2, num_qpts = q * q, elem_nodes = 4;
12-
CeedInt num_comp = 1;
13-
CeedInt p = dim * elem_nodes; // DoF per element, DoF are vector in H(div)
11+
const CeedInt p = 8, q = 3, dim = 2, num_qpts = q * q;
1412
CeedBasis basis;
1513
CeedScalar q_ref[dim * num_qpts], q_weights[num_qpts];
1614
CeedScalar interp[dim * p * num_qpts], div[p * num_qpts];
1715

1816
CeedInit(argv[1], &ceed);
1917

2018
// Test skipped if using single precision
21-
if (CEED_SCALAR_TYPE == CEED_SCALAR_FP32)
22-
// LCOV_EXCL_START
23-
return CeedError(ceed, CEED_ERROR_UNSUPPORTED, "Test not implemented in single precision");
24-
// LCOV_EXCL_STOP
19+
if (CEED_SCALAR_TYPE == CEED_SCALAR_FP32) return CeedError(ceed, CEED_ERROR_UNSUPPORTED, "Test not implemented in single precision");
2520

2621
BuildHdivQuadrilateral(q, q_ref, q_weights, interp, div, CEED_GAUSS);
27-
CeedBasisCreateHdiv(ceed, CEED_TOPOLOGY_QUAD, num_comp, p, num_qpts, interp, div, q_ref, q_weights, &basis);
28-
// interp[0]--.interp[num_qpts-1] ==> basis in x-direction
29-
// interp[num_qpts]--.interp[dim*num_qpts-1] ==> basis in y-direction
22+
CeedBasisCreateHdiv(ceed, CEED_TOPOLOGY_QUAD, 1, p, num_qpts, interp, div, q_ref, q_weights, &basis);
3023
CeedBasisView(basis, stdout);
3124

3225
CeedBasisDestroy(&basis);

tests/t330-basis.h

+5-4
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
#include <ceed.h>
99

10-
// Hdiv basis for quadrilateral linear BDM element in 2D
11-
// Local numbering is as follow (each edge has 2 vector DoF)
10+
// H(div) basis for quadrilateral linear BDM element in 2D
11+
// Local numbering is as follows (each edge has 2 vector dof)
1212
// b4 b5
1313
// 2---------3
1414
// b7| |b3
@@ -40,6 +40,7 @@ int BuildNodalHdivQuadrilateral(CeedScalar *x, CeedScalar *Bx, CeedScalar *By) {
4040
By[7] = 0.125 + -0.125 * y_hat * y_hat;
4141
return 0;
4242
}
43+
4344
static void BuildHdivQuadrilateral(CeedInt q, CeedScalar *q_ref, CeedScalar *q_weights, CeedScalar *interp, CeedScalar *div, CeedQuadMode quad_mode) {
4445
// Get 1D quadrature on [-1,1]
4546
CeedScalar q_ref_1d[q], q_weight_1d[q];
@@ -56,10 +57,10 @@ static void BuildHdivQuadrilateral(CeedInt q, CeedScalar *q_ref, CeedScalar *q_w
5657

5758
// Divergence operator; Divergence of nodal basis for ref element
5859
CeedScalar D[8] = {0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25};
59-
// Loop over quadrature points
6060
CeedScalar Bx[8], By[8];
6161
CeedScalar X[2];
6262

63+
// Loop over quadrature points
6364
for (CeedInt i = 0; i < q; i++) {
6465
for (CeedInt j = 0; j < q; j++) {
6566
CeedInt k1 = q * i + j;
@@ -76,4 +77,4 @@ static void BuildHdivQuadrilateral(CeedInt q, CeedScalar *q_ref, CeedScalar *q_w
7677
}
7778
}
7879
}
79-
}
80+
}

tests/t331-basis.c

+15-26
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/// @file
2-
/// Test GetInterp and BasisApply for a 2D Quad non-tensor H(div) basis
3-
/// \test Test GetInterp and BasisApply for a 2D Quad non-tensor H(div) basis
2+
/// Test interpolation with a 2D Quad non-tensor H(div) basis
3+
/// \test Test interpolation with a 2D Quad non-tensor H(div) basis
44
#include <ceed.h>
55
#include <math.h>
66
#include <stdio.h>
@@ -9,58 +9,47 @@
99

1010
int main(int argc, char **argv) {
1111
Ceed ceed;
12-
const CeedInt num_nodes = 4, q = 3, dim = 2, num_qpts = q * q;
13-
CeedInt num_comp = 1; // one vector component
14-
CeedInt p = dim * num_nodes; // DoF per element
12+
CeedVector u, v;
13+
const CeedInt p = 8, q = 3, dim = 2, num_qpts = q * q;
1514
CeedBasis basis;
1615
CeedScalar q_ref[dim * num_qpts], q_weights[num_qpts];
17-
CeedScalar div[p * num_qpts], interp[p * dim * num_qpts];
18-
CeedVector u, v;
16+
CeedScalar interp[dim * p * num_qpts], div[p * num_qpts];
1917

2018
CeedInit(argv[1], &ceed);
2119

2220
BuildHdivQuadrilateral(q, q_ref, q_weights, interp, div, CEED_GAUSS);
23-
CeedBasisCreateHdiv(ceed, CEED_TOPOLOGY_QUAD, num_comp, p, num_qpts, interp, div, q_ref, q_weights, &basis);
21+
CeedBasisCreateHdiv(ceed, CEED_TOPOLOGY_QUAD, 1, p, num_qpts, interp, div, q_ref, q_weights, &basis);
2422

25-
// Test GetInterp for H(div)
23+
// Test interpolation for H(div)
2624
{
27-
const CeedScalar *interp_2;
28-
CeedBasisGetInterp(basis, &interp_2);
29-
for (CeedInt i = 0; i < p * dim * num_qpts; i++) {
30-
if (fabs(interp[i] - interp_2[i]) > 100. * CEED_EPSILON) {
31-
// LCOV_EXCL_START
32-
printf("%f != %f\n", interp[i], interp_2[i]);
33-
// LCOV_EXCL_STOP
34-
}
25+
const CeedScalar *interp_in_basis;
26+
27+
CeedBasisGetInterp(basis, &interp_in_basis);
28+
for (CeedInt i = 0; i < dim * p * num_qpts; i++) {
29+
if (fabs(interp[i] - interp_in_basis[i]) > 100. * CEED_EPSILON) printf("%f != %f\n", interp[i], interp_in_basis[i]);
3530
}
3631
}
3732

3833
CeedVectorCreate(ceed, p, &u);
3934
CeedVectorSetValue(u, 1.0);
40-
CeedVectorCreate(ceed, num_qpts * dim, &v);
41-
CeedVectorSetValue(v, 0.);
35+
CeedVectorCreate(ceed, dim * num_qpts, &v);
36+
CeedVectorSetValue(v, 0.0);
4237

43-
// BasisApply for H(div): CEED_EVAL_INTERP, NOTRANSPOSE case
4438
CeedBasisApply(basis, 1, CEED_NOTRANSPOSE, CEED_EVAL_INTERP, u, v);
4539

4640
{
4741
const CeedScalar *v_array;
4842

4943
CeedVectorGetArrayRead(v, CEED_MEM_HOST, &v_array);
5044
for (CeedInt i = 0; i < dim * num_qpts; i++) {
51-
if (fabs(q_ref[i] - v_array[i]) > 100. * CEED_EPSILON) {
52-
// LCOV_EXCL_START
53-
printf("%f != %f\n", q_ref[i], v_array[i]);
54-
// LCOV_EXCL_STOP
55-
}
45+
if (fabs(q_ref[i] - v_array[i]) > 100. * CEED_EPSILON) printf("%f != %f\n", q_ref[i], v_array[i]);
5646
}
5747
CeedVectorRestoreArrayRead(v, &v_array);
5848
}
5949

6050
CeedVectorSetValue(v, 1.0);
6151
CeedVectorSetValue(u, 0.0);
6252

63-
// BasisApply for Hdiv: CEED_EVAL_INTERP, TRANSPOSE case
6453
CeedBasisApply(basis, 1, CEED_TRANSPOSE, CEED_EVAL_INTERP, v, u);
6554

6655
{

tests/t332-basis.c

+12-16
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/// @file
2-
/// Test GetDiv and BasisApply for a 2D Quad non-tensor H(div) basis
3-
/// \test Test GetDiv and BasisApply for a 2D Quad non-tensor H(div) basis
2+
/// Test div with a 2D Quad non-tensor H(div) basis
3+
/// \test Test div with a 2D Quad non-tensor H(div) basis
44
#include <ceed.h>
55
#include <math.h>
66
#include <stdio.h>
@@ -9,35 +9,32 @@
99

1010
int main(int argc, char **argv) {
1111
Ceed ceed;
12-
const CeedInt num_nodes = 4, q = 3, dim = 2, num_qpts = q * q;
13-
CeedInt num_comp = 1; // one vector component
14-
CeedInt p = dim * num_nodes; // DoF per element
12+
CeedVector u, v;
13+
const CeedInt p = 8, q = 3, dim = 2, num_qpts = q * q;
1514
CeedBasis basis;
1615
CeedScalar q_ref[dim * num_qpts], q_weights[num_qpts];
17-
CeedScalar div[p * num_qpts], interp[p * dim * num_qpts];
18-
CeedVector u, v;
16+
CeedScalar interp[dim * p * num_qpts], div[p * num_qpts];
1917

2018
CeedInit(argv[1], &ceed);
2119

2220
BuildHdivQuadrilateral(q, q_ref, q_weights, interp, div, CEED_GAUSS);
23-
CeedBasisCreateHdiv(ceed, CEED_TOPOLOGY_QUAD, num_comp, p, num_qpts, interp, div, q_ref, q_weights, &basis);
21+
CeedBasisCreateHdiv(ceed, CEED_TOPOLOGY_QUAD, 1, p, num_qpts, interp, div, q_ref, q_weights, &basis);
2422

25-
// Test GetDiv
23+
// Test div for H(div)
2624
{
27-
const CeedScalar *div_2;
25+
const CeedScalar *div_in_basis;
2826

29-
CeedBasisGetDiv(basis, &div_2);
27+
CeedBasisGetDiv(basis, &div_in_basis);
3028
for (CeedInt i = 0; i < p * num_qpts; i++) {
31-
if (fabs(div[i] - div_2[i]) > 100. * CEED_EPSILON) printf("%f != %f\n", div[i], div_2[i]);
29+
if (fabs(div[i] - div_in_basis[i]) > 100. * CEED_EPSILON) printf("%f != %f\n", div[i], div_in_basis[i]);
3230
}
3331
}
3432

3533
CeedVectorCreate(ceed, p, &u);
36-
CeedVectorSetValue(u, 1);
34+
CeedVectorSetValue(u, 1.0);
3735
CeedVectorCreate(ceed, num_qpts, &v);
38-
CeedVectorSetValue(v, 0);
36+
CeedVectorSetValue(v, 0.0);
3937

40-
// BasisApply for H(div): CEED_EVAL_DIV, NOTRANSPOSE case
4138
CeedBasisApply(basis, 1, CEED_NOTRANSPOSE, CEED_EVAL_DIV, u, v);
4239

4340
{
@@ -53,7 +50,6 @@ int main(int argc, char **argv) {
5350
CeedVectorSetValue(v, 1.0);
5451
CeedVectorSetValue(u, 0.0);
5552

56-
// BasisApply for H(div): CEED_EVAL_DIV, TRANSPOSE case
5753
CeedBasisApply(basis, 1, CEED_TRANSPOSE, CEED_EVAL_DIV, v, u);
5854

5955
{

tests/t340-basis.c

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/// @file
2+
/// Test creation and destruction of a 2D Simplex non-tensor H(curl) basis
3+
/// \test Test creation and distruction of a 2D Simplex non-tensor H(curl) basis
4+
#include "t340-basis.h"
5+
6+
#include <ceed.h>
7+
8+
int main(int argc, char **argv) {
9+
Ceed ceed;
10+
const CeedInt p = 8, q = 4, dim = 2;
11+
CeedBasis basis;
12+
CeedScalar q_ref[dim * q], q_weight[q];
13+
CeedScalar interp[dim * p * q], curl[p * q];
14+
15+
CeedInit(argv[1], &ceed);
16+
17+
// Test skipped if using single precision
18+
if (CEED_SCALAR_TYPE == CEED_SCALAR_FP32) return CeedError(ceed, CEED_ERROR_UNSUPPORTED, "Test not implemented in single precision");
19+
20+
BuildHcurl2DSimplex(q_ref, q_weight, interp, curl);
21+
CeedBasisCreateHcurl(ceed, CEED_TOPOLOGY_TRIANGLE, 1, p, q, interp, curl, q_ref, q_weight, &basis);
22+
CeedBasisView(basis, stdout);
23+
24+
CeedBasisDestroy(&basis);
25+
CeedDestroy(&ceed);
26+
return 0;
27+
}

0 commit comments

Comments
 (0)