173d26085Sjeremylt /// @file 273d26085Sjeremylt /// Test creation, transpose use, and destruction of a multicomponent element restriction 373d26085Sjeremylt /// \test Test creation, transpose use, and destruction of a 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; 1049fd234cSJeremy L Thompson CeedInt ne = 5; 1173d26085Sjeremylt CeedInt ind[2*ne]; 1249fd234cSJeremy L Thompson CeedInt layout[3]; 1349fd234cSJeremy L Thompson CeedScalar mult; 1473d26085Sjeremylt CeedScalar a[2*(ne*2)]; 1573d26085Sjeremylt const CeedScalar *yy; 1673d26085Sjeremylt CeedElemRestriction r; 1773d26085Sjeremylt 1873d26085Sjeremylt CeedInit(argv[1], &ceed); 1973d26085Sjeremylt 2073d26085Sjeremylt // Setup 2173d26085Sjeremylt CeedVectorCreate(ceed, 2*(ne*2), &x); 2273d26085Sjeremylt 2373d26085Sjeremylt for (CeedInt i=0; i<ne; i++) { 2473d26085Sjeremylt ind[2*i+0] = i; 2573d26085Sjeremylt ind[2*i+1] = i+1; 2673d26085Sjeremylt } 27d979a051Sjeremylt CeedElemRestrictionCreate(ceed, ne, 2, 2, ne+1, 2*(ne+1), CEED_MEM_HOST, 28288c0443SJeremy L Thompson CEED_USE_POINTER, ind, &r); 2973d26085Sjeremylt CeedVectorCreate(ceed, 2*(ne+1), &y); 3073d26085Sjeremylt CeedVectorSetValue(y, 0); // Allocates array 3173d26085Sjeremylt 3249fd234cSJeremy L Thompson // Set x data in backend E-layout 3349fd234cSJeremy L Thompson CeedElemRestrictionGetELayout(r, &layout); 3449fd234cSJeremy L Thompson for (CeedInt i=0; i<2; i++) // Node 3549fd234cSJeremy L Thompson for (CeedInt j=0; j<2; j++) // Component 3649fd234cSJeremy L Thompson for (CeedInt k=0; k<ne; k++) // Element 3749fd234cSJeremy L Thompson a[i*layout[0] + j*layout[1] + k*layout[2]] = 10*j+(2*k+i+1)/2; 3849fd234cSJeremy L Thompson CeedVectorSetArray(x, CEED_MEM_HOST, CEED_USE_POINTER, a); 3949fd234cSJeremy L Thompson 4073d26085Sjeremylt // Restrict 41a8d32208Sjeremylt CeedElemRestrictionApply(r, CEED_TRANSPOSE, x, y, CEED_REQUEST_IMMEDIATE); 4273d26085Sjeremylt 4373d26085Sjeremylt // Check 4473d26085Sjeremylt CeedVectorGetArrayRead(y, CEED_MEM_HOST, &yy); 4573d26085Sjeremylt for (CeedInt i=0; i<ne+1; i++) { 4673d26085Sjeremylt mult = i>0&&i<ne ? 2 : 1; 4749fd234cSJeremy L Thompson if (yy[i] != i*mult) 48a2546046Sjeremylt // LCOV_EXCL_START 4973d26085Sjeremylt printf("Error in restricted array y[%d] = %f != %f\n", 5049fd234cSJeremy L Thompson i, (double)yy[i], i*mult); 51de996c55Sjeremylt // LCOV_EXCL_STOP 5249fd234cSJeremy L Thompson if (yy[i+ne+1] != (10+i)*mult) 53a2546046Sjeremylt // LCOV_EXCL_START 5473d26085Sjeremylt printf("Error in restricted array y[%d] = %f != %f\n", 5549fd234cSJeremy L Thompson i+ne+1, (double)yy[i+ne+1], (10.+i)*mult); 56de996c55Sjeremylt // LCOV_EXCL_STOP 5773d26085Sjeremylt } 5873d26085Sjeremylt 5973d26085Sjeremylt CeedVectorRestoreArrayRead(y, &yy); 6073d26085Sjeremylt CeedVectorDestroy(&x); 6173d26085Sjeremylt CeedVectorDestroy(&y); 6273d26085Sjeremylt CeedElemRestrictionDestroy(&r); 6373d26085Sjeremylt CeedDestroy(&ceed); 6473d26085Sjeremylt return 0; 6573d26085Sjeremylt } 66