14411cf47Sjeremylt /// @file 252bfb9bbSJeremy L Thompson /// Test Collocated Grad calculated matches basis with Lobatto points 352bfb9bbSJeremy L Thompson /// \test Test Collocated Grad calculated matches basis with Lobatto points 457c64913Sjeremylt #include <ceed.h> 5ec3da8bcSJed Brown #include <ceed/backend.h> 657c64913Sjeremylt #include <math.h> 757c64913Sjeremylt 857c64913Sjeremylt int main(int argc, char **argv) { 957c64913Sjeremylt Ceed ceed; 10*4fee36f0SJeremy L Thompson CeedInt p = 4; 11*4fee36f0SJeremy L Thompson CeedScalar collocated_gradient_1d[(p + 2) * (p + 2)], x_2[p + 2]; 12*4fee36f0SJeremy L Thompson const CeedScalar *gradient_1d, *q_ref; 139ac7b42eSJeremy L Thompson CeedScalar sum = 0.0; 14*4fee36f0SJeremy L Thompson CeedBasis basis; 1557c64913Sjeremylt 1657c64913Sjeremylt CeedInit(argv[1], &ceed); 17aedaa0e5Sjeremylt 18d1d35e2fSjeremylt // Already collocated, GetCollocatedGrad will return grad_1d 19*4fee36f0SJeremy L Thompson CeedBasisCreateTensorH1Lagrange(ceed, 1, 1, p, p, CEED_GAUSS_LOBATTO, &basis); 20*4fee36f0SJeremy L Thompson CeedBasisGetCollocatedGrad(basis, collocated_gradient_1d); 21*4fee36f0SJeremy L Thompson CeedBasisGetGrad(basis, &gradient_1d); 22aedaa0e5Sjeremylt 23*4fee36f0SJeremy L Thompson for (CeedInt i = 0; i < p; i++) { 24*4fee36f0SJeremy L Thompson for (CeedInt j = 0; j < p; j++) { 25*4fee36f0SJeremy L Thompson if (fabs(collocated_gradient_1d[j + p * i] - gradient_1d[j + p * i]) > 100 * CEED_EPSILON) { 269ac7b42eSJeremy L Thompson // LCOV_EXCL_START 27*4fee36f0SJeremy L Thompson printf("Error in collocated gradient %f != %f\n", collocated_gradient_1d[j + p * i], gradient_1d[j + p * i]); 289ac7b42eSJeremy L Thompson // LCOV_EXCL_START 292b730f8bSJeremy L Thompson } 302b730f8bSJeremy L Thompson } 312b730f8bSJeremy L Thompson } 32*4fee36f0SJeremy L Thompson CeedBasisDestroy(&basis); 3357c64913Sjeremylt 3452bfb9bbSJeremy L Thompson // Q = P, not already collocated 35*4fee36f0SJeremy L Thompson CeedBasisCreateTensorH1Lagrange(ceed, 1, 1, p, p, CEED_GAUSS, &basis); 36*4fee36f0SJeremy L Thompson CeedBasisGetCollocatedGrad(basis, collocated_gradient_1d); 3752bfb9bbSJeremy L Thompson 38*4fee36f0SJeremy L Thompson CeedBasisGetQRef(basis, &q_ref); 39*4fee36f0SJeremy L Thompson for (CeedInt i = 0; i < p; i++) x_2[i] = q_ref[i] * q_ref[i]; 409ac7b42eSJeremy L Thompson 419ac7b42eSJeremy L Thompson // Verify collo_grad * x^2 = 2x for quadrature points 42*4fee36f0SJeremy L Thompson for (CeedInt i = 0; i < p; i++) { 439ac7b42eSJeremy L Thompson sum = 0.0; 44*4fee36f0SJeremy L Thompson for (CeedInt j = 0; j < p; j++) sum += collocated_gradient_1d[j + p * i] * x_2[j]; 452b730f8bSJeremy L Thompson if (fabs(sum - 2 * q_ref[i]) > 100 * CEED_EPSILON) printf("Error in collocated gradient %f != %f\n", sum, 2 * q_ref[i]); 4652bfb9bbSJeremy L Thompson } 47*4fee36f0SJeremy L Thompson CeedBasisDestroy(&basis); 4852bfb9bbSJeremy L Thompson 4952bfb9bbSJeremy L Thompson // Q = P + 2, not already collocated 50*4fee36f0SJeremy L Thompson CeedBasisCreateTensorH1Lagrange(ceed, 1, 1, p, p + 2, CEED_GAUSS, &basis); 51*4fee36f0SJeremy L Thompson CeedBasisGetCollocatedGrad(basis, collocated_gradient_1d); 5252bfb9bbSJeremy L Thompson 53*4fee36f0SJeremy L Thompson CeedBasisGetQRef(basis, &q_ref); 54*4fee36f0SJeremy L Thompson for (CeedInt i = 0; i < p + 2; i++) x_2[i] = q_ref[i] * q_ref[i]; 559ac7b42eSJeremy L Thompson 56*4fee36f0SJeremy L Thompson // Verify collocated_gradient * x^2 = 2x for quadrature points 57*4fee36f0SJeremy L Thompson for (CeedInt i = 0; i < p + 2; i++) { 589ac7b42eSJeremy L Thompson sum = 0.0; 59*4fee36f0SJeremy L Thompson for (CeedInt j = 0; j < p + 2; j++) sum += collocated_gradient_1d[j + (p + 2) * i] * x_2[j]; 602b730f8bSJeremy L Thompson if (fabs(sum - 2 * q_ref[i]) > 100 * CEED_EPSILON) printf("Error in collocated gradient %f != %f\n", sum, 2 * q_ref[i]); 6152bfb9bbSJeremy L Thompson } 62*4fee36f0SJeremy L Thompson CeedBasisDestroy(&basis); 6352bfb9bbSJeremy L Thompson 6457c64913Sjeremylt CeedDestroy(&ceed); 6557c64913Sjeremylt return 0; 6657c64913Sjeremylt } 67