1 /// @file 2 /// Test integration with a 2D Simplex non-tensor H1 basis 3 /// \test Test integration with a 2D Simplex non-tensor H1 basis 4 #include <ceed.h> 5 #include <math.h> 6 #include "t320-basis.h" 7 8 double feval(double x1, double x2) { 9 return x1*x1 + x2*x2 + x1*x2 + 1; 10 } 11 12 int main(int argc, char **argv) { 13 Ceed ceed; 14 CeedVector In, Out, Weights; 15 const CeedInt P = 6, Q = 4, dim = 2; 16 CeedBasis b; 17 CeedScalar qref[dim*Q], qweight[Q]; 18 CeedScalar interp[P*Q], grad[dim*P*Q]; 19 CeedScalar xr[] = {0., 0.5, 1., 0., 0.5, 0., 0., 0., 0., 0.5, 0.5, 1.}; 20 const CeedScalar *out, *weights; 21 CeedScalar in[P], sum; 22 23 buildmats(qref, qweight, interp, grad); 24 25 CeedInit(argv[1], &ceed); 26 27 CeedBasisCreateH1(ceed, CEED_TRIANGLE, 1, P, Q, interp, grad, qref, 28 qweight, &b); 29 30 // Interpolate function to quadrature points 31 for (int i=0; i<P; i++) 32 in[i] = feval(xr[0*P+i], xr[1*P+i]); 33 34 CeedVectorCreate(ceed, P, &In); 35 CeedVectorSetArray(In, CEED_MEM_HOST, CEED_USE_POINTER, in); 36 CeedVectorCreate(ceed, Q, &Out); 37 CeedVectorSetValue(Out, 0); 38 CeedVectorCreate(ceed, Q, &Weights); 39 CeedVectorSetValue(Weights, 0); 40 41 CeedBasisApply(b, 1, CEED_NOTRANSPOSE, CEED_EVAL_INTERP, In, Out); 42 CeedBasisApply(b, 1, CEED_NOTRANSPOSE, CEED_EVAL_WEIGHT, 43 CEED_VECTOR_NONE, Weights); 44 45 // Check values at quadrature points 46 CeedVectorGetArrayRead(Out, CEED_MEM_HOST, &out); 47 CeedVectorGetArrayRead(Weights, CEED_MEM_HOST, &weights); 48 sum = 0; 49 for (int i=0; i<Q; i++) 50 sum += out[i]*weights[i]; 51 if (fabs(sum - 17./24.) > 1e-10) 52 printf("%f != %f\n", sum, 17./24.); 53 CeedVectorRestoreArrayRead(Out, &out); 54 CeedVectorRestoreArrayRead(Weights, &weights); 55 56 CeedVectorDestroy(&In); 57 CeedVectorDestroy(&Out); 58 CeedVectorDestroy(&Weights); 59 CeedBasisDestroy(&b); 60 CeedDestroy(&ceed); 61 return 0; 62 } 63