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>
749aac155SJeremy L Thompson #include <stdio.h>
857c64913Sjeremylt
main(int argc,char ** argv)957c64913Sjeremylt int main(int argc, char **argv) {
1057c64913Sjeremylt Ceed ceed;
114fee36f0SJeremy L Thompson CeedInt p = 4;
124fee36f0SJeremy L Thompson CeedScalar collocated_gradient_1d[(p + 2) * (p + 2)], x_2[p + 2];
134fee36f0SJeremy L Thompson const CeedScalar *gradient_1d, *q_ref;
149ac7b42eSJeremy L Thompson CeedScalar sum = 0.0;
154fee36f0SJeremy L Thompson CeedBasis basis;
1657c64913Sjeremylt
1757c64913Sjeremylt CeedInit(argv[1], &ceed);
18aedaa0e5Sjeremylt
19d1d35e2fSjeremylt // Already collocated, GetCollocatedGrad will return grad_1d
204fee36f0SJeremy L Thompson CeedBasisCreateTensorH1Lagrange(ceed, 1, 1, p, p, CEED_GAUSS_LOBATTO, &basis);
214fee36f0SJeremy L Thompson CeedBasisGetCollocatedGrad(basis, collocated_gradient_1d);
224fee36f0SJeremy L Thompson CeedBasisGetGrad(basis, &gradient_1d);
23aedaa0e5Sjeremylt
244fee36f0SJeremy L Thompson for (CeedInt i = 0; i < p; i++) {
254fee36f0SJeremy L Thompson for (CeedInt j = 0; j < p; j++) {
264fee36f0SJeremy L Thompson if (fabs(collocated_gradient_1d[j + p * i] - gradient_1d[j + p * i]) > 100 * CEED_EPSILON) {
279ac7b42eSJeremy L Thompson // LCOV_EXCL_START
284fee36f0SJeremy L Thompson printf("Error in collocated gradient %f != %f\n", collocated_gradient_1d[j + p * i], gradient_1d[j + p * i]);
29*378c2ab0SJeremy L Thompson // LCOV_EXCL_STOP
302b730f8bSJeremy L Thompson }
312b730f8bSJeremy L Thompson }
322b730f8bSJeremy L Thompson }
334fee36f0SJeremy L Thompson CeedBasisDestroy(&basis);
3457c64913Sjeremylt
3552bfb9bbSJeremy L Thompson // Q = P, not already collocated
364fee36f0SJeremy L Thompson CeedBasisCreateTensorH1Lagrange(ceed, 1, 1, p, p, CEED_GAUSS, &basis);
374fee36f0SJeremy L Thompson CeedBasisGetCollocatedGrad(basis, collocated_gradient_1d);
3852bfb9bbSJeremy L Thompson
394fee36f0SJeremy L Thompson CeedBasisGetQRef(basis, &q_ref);
404fee36f0SJeremy L Thompson for (CeedInt i = 0; i < p; i++) x_2[i] = q_ref[i] * q_ref[i];
419ac7b42eSJeremy L Thompson
429ac7b42eSJeremy L Thompson // Verify collo_grad * x^2 = 2x for quadrature points
434fee36f0SJeremy L Thompson for (CeedInt i = 0; i < p; i++) {
449ac7b42eSJeremy L Thompson sum = 0.0;
454fee36f0SJeremy L Thompson for (CeedInt j = 0; j < p; j++) sum += collocated_gradient_1d[j + p * i] * x_2[j];
462b730f8bSJeremy 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]);
4752bfb9bbSJeremy L Thompson }
484fee36f0SJeremy L Thompson CeedBasisDestroy(&basis);
4952bfb9bbSJeremy L Thompson
5052bfb9bbSJeremy L Thompson // Q = P + 2, not already collocated
514fee36f0SJeremy L Thompson CeedBasisCreateTensorH1Lagrange(ceed, 1, 1, p, p + 2, CEED_GAUSS, &basis);
524fee36f0SJeremy L Thompson CeedBasisGetCollocatedGrad(basis, collocated_gradient_1d);
5352bfb9bbSJeremy L Thompson
544fee36f0SJeremy L Thompson CeedBasisGetQRef(basis, &q_ref);
554fee36f0SJeremy L Thompson for (CeedInt i = 0; i < p + 2; i++) x_2[i] = q_ref[i] * q_ref[i];
569ac7b42eSJeremy L Thompson
574fee36f0SJeremy L Thompson // Verify collocated_gradient * x^2 = 2x for quadrature points
584fee36f0SJeremy L Thompson for (CeedInt i = 0; i < p + 2; i++) {
599ac7b42eSJeremy L Thompson sum = 0.0;
604fee36f0SJeremy L Thompson for (CeedInt j = 0; j < p + 2; j++) sum += collocated_gradient_1d[j + (p + 2) * i] * x_2[j];
612b730f8bSJeremy 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]);
6252bfb9bbSJeremy L Thompson }
634fee36f0SJeremy L Thompson CeedBasisDestroy(&basis);
6452bfb9bbSJeremy L Thompson
6557c64913Sjeremylt CeedDestroy(&ceed);
6657c64913Sjeremylt return 0;
6757c64913Sjeremylt }
68