Skip to content

Commit 87c0459

Browse files
Add tests
1 parent 59d8d48 commit 87c0459

16 files changed

+305
-67
lines changed

tests/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ The tests are organized by API object, and some tests are further organized, as
1313
3.0. CeedBasis utility tests
1414
3.1. CeedBasis tensor basis tests
1515
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
1820
4.1. CeedQFunction gallery code 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 distruction 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 distruction 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 interpolaton with a 2D Simplex non-tensor H1 basis
2+
/// Test interpolation with a 2D Simplex non-tensor H^1 basis
3+
/// \test Test interpolaton with a 2D Simplex non-tensor H^1 basis
44
#include <ceed.h>
55
#include <math.h>
66

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

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

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 transposewith 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

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 transposewith a 2D Simplex non-tensor H1 basis
2+
/// Test grad transpose with a 2D Simplex non-tensor H^1 basis
3+
/// \test Test grad transposewith a 2D Simplex non-tensor H^1 basis
44
#include <ceed.h>
55
#include <math.h>
66

tests/t330-basis.c

+6-11
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,26 @@
11
/// @file
2-
/// Test creation and destruction of a 2D Quad non-tensor Hdiv basis
3-
/// \test Test creation and distruction 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 distruction of a 2D Quad non-tensor H(div) basis
44
#include "t330-basis.h"
55

66
#include <ceed.h>
77

88
int main(int argc, char **argv) {
99
Ceed ceed;
1010
const CeedInt Q = 3, dim = 2, num_qpts = Q * Q, elem_nodes = 4;
11-
CeedInt num_comp = 1;
12-
CeedInt P = dim * elem_nodes; // dof per element! dof is vector in H(div)
11+
const CeedInt P = dim * elem_nodes;
1312
CeedBasis b;
1413
CeedScalar q_ref[dim * num_qpts], q_weights[num_qpts];
1514
CeedScalar interp[dim * P * num_qpts], div[P * num_qpts];
1615

1716
CeedInit(argv[1], &ceed);
1817

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

2521
HdivBasisQuad(Q, q_ref, q_weights, interp, div, CEED_GAUSS);
26-
CeedBasisCreateHdiv(ceed, CEED_TOPOLOGY_QUAD, num_comp, P, num_qpts, interp, div, q_ref, q_weights, &b);
27-
// interp[0]--.interp[num_qpts-1] ==> basis in x-direction
28-
// interp[num_qpts]--.interp[dim*num_qpts-1] ==> basis in y-direction
22+
23+
CeedBasisCreateHdiv(ceed, CEED_TOPOLOGY_QUAD, 1, P, num_qpts, interp, div, q_ref, q_weights, &b);
2924
CeedBasisView(b, stdout);
3025

3126
CeedBasisDestroy(&b);

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 BDMelement 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 NodalHdivBasisQuad(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 HdivBasisQuad(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 HdivBasisQuad(CeedInt Q, CeedScalar *q_ref, CeedScalar *q_weights, C
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 HdivBasisQuad(CeedInt Q, CeedScalar *q_ref, CeedScalar *q_weights, C
7677
}
7778
}
7879
}
79-
}
80+
}

tests/t331-basis.c

+18-26
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,54 @@
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

77
#include "t330-basis.h"
88

99
int main(int argc, char **argv) {
1010
Ceed ceed;
11-
const CeedInt num_nodes = 4, Q = 3, dim = 2, num_qpts = Q * Q;
12-
CeedInt num_comp = 1; // one vector componenet
13-
CeedInt P = dim * num_nodes; // dof per element!
11+
const CeedInt Q = 3, dim = 2, num_qpts = Q * Q, elem_nodes = 4;
12+
const CeedInt P = dim * elem_nodes;
1413
CeedBasis b;
1514
CeedScalar q_ref[dim * num_qpts], q_weights[num_qpts];
16-
CeedScalar div[P * num_qpts], interp[P * dim * num_qpts];
15+
CeedScalar interp[dim * P * num_qpts], div[P * num_qpts];
1716
CeedVector X, Y;
18-
const CeedScalar *y, *x;
17+
const CeedScalar *y, *x, *interp2;
18+
CeedScalar sum;
1919

2020
CeedInit(argv[1], &ceed);
2121

2222
HdivBasisQuad(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, &b);
2423

25-
// Test GetInterp for H(div)
26-
const CeedScalar *interp2;
24+
CeedBasisCreateHdiv(ceed, CEED_TOPOLOGY_QUAD, 1, P, num_qpts, interp, div, q_ref, q_weights, &b);
25+
26+
// Test interpolation for H(div)
2727
CeedBasisGetInterp(b, &interp2);
28-
for (CeedInt i = 0; i < P * dim * num_qpts; i++) {
29-
if (fabs(interp[i] - interp2[i]) > 100. * CEED_EPSILON) {
30-
// LCOV_EXCL_START
31-
printf("%f != %f\n", interp[i], interp2[i]);
32-
// LCOV_EXCL_STOP
33-
}
28+
for (CeedInt i = 0; i < dim * P * num_qpts; i++) {
29+
if (fabs(interp[i] - interp2[i]) > 100. * CEED_EPSILON) printf("%f != %f\n", interp[i], interp2[i]);
3430
}
3531

3632
CeedVectorCreate(ceed, P, &X);
3733
CeedVectorSetValue(X, 1.0);
38-
CeedVectorCreate(ceed, num_qpts * dim, &Y);
39-
CeedVectorSetValue(Y, 0.);
40-
// BasisApply for H(div): CEED_EVAL_INTERP, NOTRANSPOSE case
34+
CeedVectorCreate(ceed, dim * num_qpts, &Y);
35+
CeedVectorSetValue(Y, 0.0);
36+
4137
CeedBasisApply(b, 1, CEED_NOTRANSPOSE, CEED_EVAL_INTERP, X, Y);
4238

4339
CeedVectorGetArrayRead(Y, CEED_MEM_HOST, &y);
4440
for (CeedInt i = 0; i < dim * num_qpts; i++) {
45-
if (fabs(q_ref[i] - y[i]) > 100. * CEED_EPSILON) {
46-
// LCOV_EXCL_START
47-
printf("%f != %f\n", q_ref[i], y[i]);
48-
// LCOV_EXCL_STOP
49-
}
41+
if (fabs(q_ref[i] - y[i]) > 100. * CEED_EPSILON) printf("%f != %f\n", q_ref[i], y[i]);
5042
}
5143
CeedVectorRestoreArrayRead(Y, &y);
5244

5345
CeedVectorSetValue(Y, 1.0);
5446
CeedVectorSetValue(X, 0.0);
55-
// BasisApply for Hdiv: CEED_EVAL_INTERP, TRANSPOSE case
47+
5648
CeedBasisApply(b, 1, CEED_TRANSPOSE, CEED_EVAL_INTERP, Y, X);
5749

5850
CeedVectorGetArrayRead(X, CEED_MEM_HOST, &x);
59-
CeedScalar sum = 0.;
51+
sum = 0.;
6052
for (CeedInt i = 0; i < P; i++) {
6153
sum += x[i];
6254
}

tests/t332-basis.c

+15-14
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,38 @@
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

77
#include "t330-basis.h"
88

99
int main(int argc, char **argv) {
1010
Ceed ceed;
11-
const CeedInt num_nodes = 4, Q = 3, dim = 2, num_qpts = Q * Q;
12-
CeedInt num_comp = 1; // one vector componenet
13-
CeedInt P = dim * num_nodes; // dof per element!
11+
const CeedInt Q = 3, dim = 2, num_qpts = Q * Q, elem_nodes = 4;
12+
const CeedInt P = dim * elem_nodes;
1413
CeedBasis b;
1514
CeedScalar q_ref[dim * num_qpts], q_weights[num_qpts];
16-
CeedScalar div[P * num_qpts], interp[P * dim * num_qpts];
15+
CeedScalar interp[dim * P * num_qpts], div[P * num_qpts];
1716
CeedVector X, Y;
18-
const CeedScalar *y, *x;
17+
const CeedScalar *y, *x, *div2;
1918

2019
CeedInit(argv[1], &ceed);
2120

2221
HdivBasisQuad(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, &b);
24-
// Test GetDiv
25-
const CeedScalar *div2;
22+
23+
CeedBasisCreateHdiv(ceed, CEED_TOPOLOGY_QUAD, 1, P, num_qpts, interp, div, q_ref, q_weights, &b);
24+
25+
// Test div for H(div)
2626
CeedBasisGetDiv(b, &div2);
2727
for (CeedInt i = 0; i < P * num_qpts; i++) {
2828
if (fabs(div[i] - div2[i]) > 100. * CEED_EPSILON) printf("%f != %f\n", div[i], div2[i]);
2929
}
30+
3031
CeedVectorCreate(ceed, P, &X);
31-
CeedVectorSetValue(X, 1);
32+
CeedVectorSetValue(X, 1.0);
3233
CeedVectorCreate(ceed, num_qpts, &Y);
33-
CeedVectorSetValue(Y, 0);
34-
// BasisApply for H(div): CEED_EVAL_DIV, NOTRANSPOSE case
34+
CeedVectorSetValue(Y, 0.0);
35+
3536
CeedBasisApply(b, 1, CEED_NOTRANSPOSE, CEED_EVAL_DIV, X, Y);
3637

3738
CeedVectorGetArrayRead(Y, CEED_MEM_HOST, &y);
@@ -42,7 +43,7 @@ int main(int argc, char **argv) {
4243

4344
CeedVectorSetValue(Y, 1.0);
4445
CeedVectorSetValue(X, 0.0);
45-
// BasisApply for H(div): CEED_EVAL_DIV, TRANSPOSE case
46+
4647
CeedBasisApply(b, 1, CEED_TRANSPOSE, CEED_EVAL_DIV, Y, X);
4748

4849
CeedVectorGetArrayRead(X, CEED_MEM_HOST, &x);

tests/t340-basis.c

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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 b;
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+
buildmats(q_ref, q_weight, interp, curl);
21+
22+
CeedBasisCreateHcurl(ceed, CEED_TOPOLOGY_TRIANGLE, 1, P, Q, interp, curl, q_ref, q_weight, &b);
23+
CeedBasisView(b, stdout);
24+
25+
CeedBasisDestroy(&b);
26+
CeedDestroy(&ceed);
27+
return 0;
28+
}

tests/t340-basis.h

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Copyright (c) 2017-2022, Lawrence Livermore National Security, LLC and other CEED contributors.
2+
// All Rights Reserved. See the top-level LICENSE and NOTICE files for details.
3+
//
4+
// SPDX-License-Identifier: BSD-2-Clause
5+
//
6+
// This file is part of CEED: http://github.com/ceed
7+
8+
#include <ceed.h>
9+
10+
// H(curl) basis for order 2 Nédélec (first kind) triangle element in 2D
11+
// See: https://defelement.com/elements/examples/triangle-N1curl-2.html
12+
static void buildmats(CeedScalar *q_ref, CeedScalar *q_weight, CeedScalar *interp, CeedScalar *curl) {
13+
CeedInt P = 8, Q = 4;
14+
15+
q_ref[0] = 1. / 3.;
16+
q_ref[4] = 1. / 3.;
17+
q_ref[1] = 0.2;
18+
q_ref[5] = 0.2;
19+
q_ref[2] = 0.2;
20+
q_ref[6] = 0.6;
21+
q_ref[3] = 0.6;
22+
q_ref[7] = 0.2;
23+
q_weight[0] = -25. / 96.;
24+
q_weight[1] = 25. / 96.;
25+
q_weight[2] = 27. / 96.;
26+
q_weight[3] = 25. / 96.;
27+
28+
// Loop over quadrature points
29+
for (int i = 0; i < Q; i++) {
30+
CeedScalar x1 = q_ref[0 * Q + i], x2 = q_ref[1 * Q + i];
31+
// Interp
32+
interp[(i + 0) * P + 0] = 2. * x2 * (1. - 4. * x1);
33+
interp[(i + Q) * P + 0] = 4. * x1 * (2. * x1 - 1.);
34+
interp[(i + 0) * P + 1] = 4. * x2 * (1. - 2. * x2);
35+
interp[(i + Q) * P + 1] = 2. * x1 * (4. * x2 - 1.);
36+
interp[(i + 0) * P + 2] = 2. * x2 * (-4. * x1 - 4. * x2 + 3.);
37+
interp[(i + Q) * P + 2] = 8. * x1 * x1 + 8. * x1 * x2 - 12. * x1 - 6. * x2 + 4.;
38+
interp[(i + 0) * P + 3] = 4. * x2 * (2. * x2 - 1.);
39+
interp[(i + Q) * P + 3] = -8. * x1 * x2 + 2. * x1 + 6. * x2 - 2.;
40+
interp[(i + 0) * P + 4] = 8. * x1 * x2 - 6. * x1 + 8. * x2 * x2 - 12. * x2 + 4.;
41+
interp[(i + Q) * P + 4] = 2. * x1 * (-4. * x1 - 4. * x2 + 3.);
42+
interp[(i + 0) * P + 5] = -8. * x1 * x2 + 6. * x1 + 2. * x2 - 2.;
43+
interp[(i + Q) * P + 5] = 4. * x1 * (2. * x1 - 1.);
44+
interp[(i + 0) * P + 6] = 8. * x2 * (-x1 - 2. * x2 + 2.);
45+
interp[(i + Q) * P + 6] = 8. * x1 * (x1 + 2. * x2 - 1.);
46+
interp[(i + 0) * P + 7] = 8. * x2 * (2. * x1 + x2 - 1.);
47+
interp[(i + Q) * P + 7] = 8. * x1 * (-2. * x1 - x2 + 2.);
48+
// Curl
49+
curl[i * P + 0] = 24. * x1 - 6.;
50+
curl[i * P + 1] = 24. * x2 - 6.;
51+
curl[i * P + 2] = 24. * x1 + 24. * x2 - 18.;
52+
curl[i * P + 3] = -24. * x2 + 6.;
53+
curl[i * P + 4] = -24. * x1 - 24. * x2 + 18.;
54+
curl[i * P + 5] = 24. * x1 - 6.;
55+
curl[i * P + 6] = 24. * x1 + 48. * x2 - 24.;
56+
curl[i * P + 7] = -48. * x1 - 24. * x1 + 24.;
57+
}
58+
}

0 commit comments

Comments
 (0)