xref: /libCEED/tests/t201-elemrestriction.c (revision 7509a596beda7c1d002d2274a17375b09541fdb6)
14411cf47Sjeremylt /// @file
2*7509a596Sjeremylt /// Test creation, use, and destruction of a strided element restriction
3*7509a596Sjeremylt /// \test Test creation, use, and destruction of a strided element restriction
457c64913Sjeremylt #include <ceed.h>
557c64913Sjeremylt 
657c64913Sjeremylt int main(int argc, char **argv) {
757c64913Sjeremylt   Ceed ceed;
857c64913Sjeremylt   CeedVector x, y;
957c64913Sjeremylt   CeedInt ne = 3;
1057c64913Sjeremylt   CeedScalar a[ne*2];
1157c64913Sjeremylt   const CeedScalar *yy;
12*7509a596Sjeremylt   CeedInt strides[3] = {1, 2, 2};
1357c64913Sjeremylt   CeedElemRestriction r;
1457c64913Sjeremylt 
1557c64913Sjeremylt   CeedInit(argv[1], &ceed);
16288c0443SJeremy L Thompson 
1757c64913Sjeremylt   CeedVectorCreate(ceed, ne*2, &x);
18288c0443SJeremy L Thompson   for (CeedInt i=0; i<ne*2; i++)
19288c0443SJeremy L Thompson     a[i] = 10 + i;
2057c64913Sjeremylt   CeedVectorSetArray(x, CEED_MEM_HOST, CEED_USE_POINTER, a);
2157c64913Sjeremylt 
22*7509a596Sjeremylt   CeedElemRestrictionCreateStrided(ceed, ne, 2, ne*2, 1, strides, &r);
2357c64913Sjeremylt   CeedVectorCreate(ceed, ne*2, &y);
2473d26085Sjeremylt   CeedVectorSetValue(y, 0); // Allocates array
25a8d32208Sjeremylt   CeedElemRestrictionApply(r, CEED_NOTRANSPOSE, x, y, CEED_REQUEST_IMMEDIATE);
26288c0443SJeremy L Thompson 
2757c64913Sjeremylt   CeedVectorGetArrayRead(y, CEED_MEM_HOST, &yy);
28a2546046Sjeremylt   for (CeedInt i=0; i<ne*2; i++)
2957c64913Sjeremylt     if (yy[i] != 10+i)
30a2546046Sjeremylt       // LCOV_EXCL_START
31d863ab9bSjeremylt       printf("Error in restricted array y[%d] = %f",
3257c64913Sjeremylt              i, (double)yy[i]);
33de996c55Sjeremylt   // LCOV_EXCL_STOP
3457c64913Sjeremylt   CeedVectorRestoreArrayRead(y, &yy);
35a2546046Sjeremylt 
3657c64913Sjeremylt   CeedVectorDestroy(&x);
3757c64913Sjeremylt   CeedVectorDestroy(&y);
3857c64913Sjeremylt   CeedElemRestrictionDestroy(&r);
3957c64913Sjeremylt   CeedDestroy(&ceed);
4057c64913Sjeremylt   return 0;
4157c64913Sjeremylt }
42