1 /// @file 2 /// Test Collocated Grad calculated matches basis with Lobatto points 3 /// \test Test Collocated Grad calculated matches basis with Lobatto points 4 #include <ceed.h> 5 #include <ceed/backend.h> 6 #include <math.h> 7 8 int main(int argc, char **argv) { 9 Ceed ceed; 10 CeedInt p = 4; 11 CeedScalar collocated_gradient_1d[(p + 2) * (p + 2)], x_2[p + 2]; 12 const CeedScalar *gradient_1d, *q_ref; 13 CeedScalar sum = 0.0; 14 CeedBasis basis; 15 16 CeedInit(argv[1], &ceed); 17 18 // Already collocated, GetCollocatedGrad will return grad_1d 19 CeedBasisCreateTensorH1Lagrange(ceed, 1, 1, p, p, CEED_GAUSS_LOBATTO, &basis); 20 CeedBasisGetCollocatedGrad(basis, collocated_gradient_1d); 21 CeedBasisGetGrad(basis, &gradient_1d); 22 23 for (CeedInt i = 0; i < p; i++) { 24 for (CeedInt j = 0; j < p; j++) { 25 if (fabs(collocated_gradient_1d[j + p * i] - gradient_1d[j + p * i]) > 100 * CEED_EPSILON) { 26 // LCOV_EXCL_START 27 printf("Error in collocated gradient %f != %f\n", collocated_gradient_1d[j + p * i], gradient_1d[j + p * i]); 28 // LCOV_EXCL_START 29 } 30 } 31 } 32 CeedBasisDestroy(&basis); 33 34 // Q = P, not already collocated 35 CeedBasisCreateTensorH1Lagrange(ceed, 1, 1, p, p, CEED_GAUSS, &basis); 36 CeedBasisGetCollocatedGrad(basis, collocated_gradient_1d); 37 38 CeedBasisGetQRef(basis, &q_ref); 39 for (CeedInt i = 0; i < p; i++) x_2[i] = q_ref[i] * q_ref[i]; 40 41 // Verify collo_grad * x^2 = 2x for quadrature points 42 for (CeedInt i = 0; i < p; i++) { 43 sum = 0.0; 44 for (CeedInt j = 0; j < p; j++) sum += collocated_gradient_1d[j + p * i] * x_2[j]; 45 if (fabs(sum - 2 * q_ref[i]) > 100 * CEED_EPSILON) printf("Error in collocated gradient %f != %f\n", sum, 2 * q_ref[i]); 46 } 47 CeedBasisDestroy(&basis); 48 49 // Q = P + 2, not already collocated 50 CeedBasisCreateTensorH1Lagrange(ceed, 1, 1, p, p + 2, CEED_GAUSS, &basis); 51 CeedBasisGetCollocatedGrad(basis, collocated_gradient_1d); 52 53 CeedBasisGetQRef(basis, &q_ref); 54 for (CeedInt i = 0; i < p + 2; i++) x_2[i] = q_ref[i] * q_ref[i]; 55 56 // Verify collocated_gradient * x^2 = 2x for quadrature points 57 for (CeedInt i = 0; i < p + 2; i++) { 58 sum = 0.0; 59 for (CeedInt j = 0; j < p + 2; j++) sum += collocated_gradient_1d[j + (p + 2) * i] * x_2[j]; 60 if (fabs(sum - 2 * q_ref[i]) > 100 * CEED_EPSILON) printf("Error in collocated gradient %f != %f\n", sum, 2 * q_ref[i]); 61 } 62 CeedBasisDestroy(&basis); 63 64 CeedDestroy(&ceed); 65 return 0; 66 } 67