xref: /libCEED/tests/t205-elemrestriction.c (revision ec3da8bcb94d9f0073544b37b5081a06981a86f7)
173d26085Sjeremylt /// @file
273d26085Sjeremylt /// Test creation, use, and destruction of an interlaced multicomponent element restriction
373d26085Sjeremylt /// \test Test creation, use, and destruction of an interlaced multicomponent element restriction
473d26085Sjeremylt #include <ceed.h>
5*ec3da8bcSJed Brown #include <ceed/backend.h>
673d26085Sjeremylt 
773d26085Sjeremylt int main(int argc, char **argv) {
873d26085Sjeremylt   Ceed ceed;
973d26085Sjeremylt   CeedVector x, y;
1073d26085Sjeremylt   CeedInt ne = 3;
1173d26085Sjeremylt   CeedInt ind[2*ne];
1249fd234cSJeremy L Thompson   CeedInt layout[3];
1373d26085Sjeremylt   CeedScalar a[2*(ne+1)];
1473d26085Sjeremylt   const CeedScalar *yy;
1573d26085Sjeremylt   CeedElemRestriction r;
1673d26085Sjeremylt 
1773d26085Sjeremylt   CeedInit(argv[1], &ceed);
1873d26085Sjeremylt 
1973d26085Sjeremylt   // Setup
2073d26085Sjeremylt   CeedVectorCreate(ceed, 2*(ne+1), &x);
2173d26085Sjeremylt   for (CeedInt i=0; i<ne+1; i++) {
2273d26085Sjeremylt     a[2*i] = 10 + i;
2373d26085Sjeremylt     a[2*i+1] = 20 + i;
2473d26085Sjeremylt   }
2573d26085Sjeremylt   CeedVectorSetArray(x, CEED_MEM_HOST, CEED_USE_POINTER, a);
2673d26085Sjeremylt 
2773d26085Sjeremylt   for (CeedInt i=0; i<ne; i++) {
28d979a051Sjeremylt     ind[2*i+0] = 2*i;
29d979a051Sjeremylt     ind[2*i+1] = 2*(i+1);
3073d26085Sjeremylt   }
31d979a051Sjeremylt   CeedElemRestrictionCreate(ceed, ne, 2, 2, 1, 2*(ne+1), CEED_MEM_HOST,
32288c0443SJeremy L Thompson                             CEED_USE_POINTER, ind, &r);
3373d26085Sjeremylt   CeedVectorCreate(ceed, 2*(ne*2), &y);
3473d26085Sjeremylt   CeedVectorSetValue(y, 0); // Allocates array
3573d26085Sjeremylt 
3673d26085Sjeremylt   // Restrict
37a8d32208Sjeremylt   CeedElemRestrictionApply(r, CEED_NOTRANSPOSE, x, y, CEED_REQUEST_IMMEDIATE);
3873d26085Sjeremylt 
3973d26085Sjeremylt   // Check
4073d26085Sjeremylt   CeedVectorGetArrayRead(y, CEED_MEM_HOST, &yy);
4149fd234cSJeremy L Thompson   CeedElemRestrictionGetELayout(r, &layout);
4249fd234cSJeremy L Thompson   for (CeedInt i=0; i<2; i++)       // Node
4349fd234cSJeremy L Thompson     for (CeedInt j=0; j<2; j++)     // Component
4449fd234cSJeremy L Thompson       for (CeedInt k=0; k<ne; k++)  // Element
4549fd234cSJeremy L Thompson         if (yy[i*layout[0]+j*layout[1]+k*layout[2]] != a[ind[i+k*2]+j])
46a2546046Sjeremylt           // LCOV_EXCL_START
4749fd234cSJeremy L Thompson           printf("Error in restricted array y[%d][%d][%d] = %f != %f\n",
4849fd234cSJeremy L Thompson                  i, j, k, (double)yy[i*layout[0]+j*layout[1]+k*layout[2]],
4949fd234cSJeremy L Thompson                  a[ind[i+k*2]+j*(ne+1)]);
50de996c55Sjeremylt   // LCOV_EXCL_STOP
5173d26085Sjeremylt 
5273d26085Sjeremylt   CeedVectorRestoreArrayRead(y, &yy);
5373d26085Sjeremylt   CeedVectorDestroy(&x);
5473d26085Sjeremylt   CeedVectorDestroy(&y);
5573d26085Sjeremylt   CeedElemRestrictionDestroy(&r);
5673d26085Sjeremylt   CeedDestroy(&ceed);
5773d26085Sjeremylt   return 0;
5873d26085Sjeremylt }
59