152bfb9bbSJeremy L Thompson /// @file 252bfb9bbSJeremy L Thompson /// Test grad with a 2D Simplex non-tensor H1 basis 352bfb9bbSJeremy L Thompson /// \test Test grad with a 2D Simplex non-tensor H1 basis 452bfb9bbSJeremy L Thompson #include <ceed.h> 552bfb9bbSJeremy L Thompson #include <math.h> 62b730f8bSJeremy L Thompson 752bfb9bbSJeremy L Thompson #include "t320-basis.h" 852bfb9bbSJeremy L Thompson 92b730f8bSJeremy L Thompson // polynomial eval helper 10*4fee36f0SJeremy L Thompson static CeedScalar Eval(CeedScalar x1, CeedScalar x2) { return x1 * x1 + x2 * x2 + x1 * x2 + 1; } 1152bfb9bbSJeremy L Thompson 122b730f8bSJeremy L Thompson // polynomial derivative helper 13*4fee36f0SJeremy L Thompson CeedScalar EvalGrad(CeedScalar x1, CeedScalar x2) { return 2 * x1 + x2; } 1452bfb9bbSJeremy L Thompson 152b730f8bSJeremy L Thompson // main test 1652bfb9bbSJeremy L Thompson int main(int argc, char **argv) { 1752bfb9bbSJeremy L Thompson Ceed ceed; 18*4fee36f0SJeremy L Thompson CeedVector u, v; 19*4fee36f0SJeremy L Thompson const CeedInt p = 6, q = 4, dim = 2; 20*4fee36f0SJeremy L Thompson CeedBasis basis; 21*4fee36f0SJeremy L Thompson CeedScalar q_ref[dim * q], q_weight[q]; 22*4fee36f0SJeremy L Thompson CeedScalar interp[p * q], grad[dim * p * q]; 23*4fee36f0SJeremy L Thompson CeedScalar x_q[] = {0.2, 0.6, 1. / 3., 0.2, 0.2, 0.2, 1. / 3., 0.6}; 24*4fee36f0SJeremy L Thompson CeedScalar x_ref[] = {0., 0.5, 1., 0., 0.5, 0., 0., 0., 0., 0.5, 0.5, 1.}; 2552bfb9bbSJeremy L Thompson 2652bfb9bbSJeremy L Thompson CeedInit(argv[1], &ceed); 2752bfb9bbSJeremy L Thompson 28*4fee36f0SJeremy L Thompson CeedVectorCreate(ceed, p, &u); 29*4fee36f0SJeremy L Thompson { 30*4fee36f0SJeremy L Thompson CeedScalar u_array[p]; 3152bfb9bbSJeremy L Thompson 3252bfb9bbSJeremy L Thompson // Interpolate function to quadrature points 33*4fee36f0SJeremy L Thompson for (int i = 0; i < p; i++) u_array[i] = Eval(x_ref[0 * p + i], x_ref[1 * p + i]); 34*4fee36f0SJeremy L Thompson CeedVectorSetArray(u, CEED_MEM_HOST, CEED_COPY_VALUES, u_array); 35*4fee36f0SJeremy L Thompson } 36*4fee36f0SJeremy L Thompson CeedVectorCreate(ceed, q * dim, &v); 37*4fee36f0SJeremy L Thompson CeedVectorSetValue(v, 0); 3852bfb9bbSJeremy L Thompson 39*4fee36f0SJeremy L Thompson Build2DSimplex(q_ref, q_weight, interp, grad); 40*4fee36f0SJeremy L Thompson CeedBasisCreateH1(ceed, CEED_TOPOLOGY_TRIANGLE, 1, p, q, interp, grad, q_ref, q_weight, &basis); 4152bfb9bbSJeremy L Thompson 42*4fee36f0SJeremy L Thompson CeedBasisApply(basis, 1, CEED_NOTRANSPOSE, CEED_EVAL_GRAD, u, v); 4352bfb9bbSJeremy L Thompson 4452bfb9bbSJeremy L Thompson // Check values at quadrature points 45*4fee36f0SJeremy L Thompson { 46*4fee36f0SJeremy L Thompson const CeedScalar *v_array; 4752bfb9bbSJeremy L Thompson 48*4fee36f0SJeremy L Thompson CeedVectorGetArrayRead(v, CEED_MEM_HOST, &v_array); 49*4fee36f0SJeremy L Thompson for (int i = 0; i < q; i++) { 50*4fee36f0SJeremy L Thompson CeedScalar dfx = EvalGrad(x_q[0 * q + i], x_q[1 * q + i]); 51*4fee36f0SJeremy L Thompson if (fabs(v_array[0 * q + i] - dfx) > 100. * CEED_EPSILON) printf("[%" CeedInt_FMT "] %f != %f\n", i, v_array[0 * q + i], dfx); 52*4fee36f0SJeremy L Thompson dfx = EvalGrad(x_q[1 * q + i], x_q[0 * q + i]); 53*4fee36f0SJeremy L Thompson if (fabs(v_array[1 * q + i] - dfx) > 100. * CEED_EPSILON) printf("[%" CeedInt_FMT "] %f != %f\n", i, v_array[1 * q + i], dfx); 54*4fee36f0SJeremy L Thompson } 55*4fee36f0SJeremy L Thompson CeedVectorRestoreArrayRead(v, &v_array); 56*4fee36f0SJeremy L Thompson } 57*4fee36f0SJeremy L Thompson 58*4fee36f0SJeremy L Thompson CeedVectorDestroy(&u); 59*4fee36f0SJeremy L Thompson CeedVectorDestroy(&v); 60*4fee36f0SJeremy L Thompson CeedBasisDestroy(&basis); 6152bfb9bbSJeremy L Thompson CeedDestroy(&ceed); 6252bfb9bbSJeremy L Thompson return 0; 6352bfb9bbSJeremy L Thompson } 64