14411cf47Sjeremylt /// @file 24411cf47Sjeremylt /// Test creation, use, and destruction of a blocked element restriction with multiple components in the lvector 34411cf47Sjeremylt /// \test Test creation, use, and destruction of a blocked element restriction with multiple components in the lvector 457c64913Sjeremylt #include <ceed.h> 50acb07cdSJeremy L Thompson #include <ceed/backend.h> 657c64913Sjeremylt 757c64913Sjeremylt int main(int argc, char **argv) { 857c64913Sjeremylt Ceed ceed; 957c64913Sjeremylt CeedVector x, y; 10d1d35e2fSjeremylt CeedInt num_elem = 8; 110acb07cdSJeremy L Thompson CeedInt elem_size = 2; 120acb07cdSJeremy L Thompson CeedInt num_blk = 2; 13d1d35e2fSjeremylt CeedInt blk_size = 5; 14d1d35e2fSjeremylt CeedInt num_comp = 3; 150acb07cdSJeremy L Thompson CeedInt ind[elem_size * num_elem]; 16*4fee36f0SJeremy L Thompson CeedScalar x_array[num_comp * (num_elem + 1)]; 170acb07cdSJeremy L Thompson CeedInt layout[3]; 18*4fee36f0SJeremy L Thompson CeedElemRestriction elem_restriction; 1957c64913Sjeremylt 2057c64913Sjeremylt CeedInit(argv[1], &ceed); 21288c0443SJeremy L Thompson 220acb07cdSJeremy L Thompson CeedVectorCreate(ceed, num_comp * (num_elem + 1), &x); 230acb07cdSJeremy L Thompson for (CeedInt i = 0; i < num_elem + 1; i++) { 24*4fee36f0SJeremy L Thompson x_array[i + 0 * (num_elem + 1)] = 10 + i; 25*4fee36f0SJeremy L Thompson x_array[i + 1 * (num_elem + 1)] = 20 + i; 26*4fee36f0SJeremy L Thompson x_array[i + 2 * (num_elem + 1)] = 30 + i; 2757c64913Sjeremylt } 28*4fee36f0SJeremy L Thompson CeedVectorSetArray(x, CEED_MEM_HOST, CEED_USE_POINTER, x_array); 29*4fee36f0SJeremy L Thompson CeedVectorCreate(ceed, num_comp * num_blk * blk_size * elem_size, &y); 300acb07cdSJeremy L Thompson 31d1d35e2fSjeremylt for (CeedInt i = 0; i < num_elem; i++) { 3257c64913Sjeremylt ind[2 * i + 0] = i; 3357c64913Sjeremylt ind[2 * i + 1] = i + 1; 3457c64913Sjeremylt } 352b730f8bSJeremy L Thompson CeedElemRestrictionCreateBlocked(ceed, num_elem, elem_size, blk_size, num_comp, num_elem + 1, num_comp * (num_elem + 1), CEED_MEM_HOST, 36*4fee36f0SJeremy L Thompson CEED_USE_POINTER, ind, &elem_restriction); 3757c64913Sjeremylt 3857c64913Sjeremylt // NoTranspose 39*4fee36f0SJeremy L Thompson CeedElemRestrictionApply(elem_restriction, CEED_NOTRANSPOSE, x, y, CEED_REQUEST_IMMEDIATE); 40*4fee36f0SJeremy L Thompson { 41*4fee36f0SJeremy L Thompson const CeedScalar *y_array; 42*4fee36f0SJeremy L Thompson 43*4fee36f0SJeremy L Thompson CeedVectorGetArrayRead(y, CEED_MEM_HOST, &y_array); 44*4fee36f0SJeremy L Thompson CeedElemRestrictionGetELayout(elem_restriction, &layout); 452b730f8bSJeremy L Thompson for (CeedInt i = 0; i < elem_size; i++) { // Node 462b730f8bSJeremy L Thompson for (CeedInt j = 0; j < num_comp; j++) { // Component 470acb07cdSJeremy L Thompson for (CeedInt k = 0; k < num_elem; k++) { // Element 480acb07cdSJeremy L Thompson CeedInt block = k / blk_size; 490acb07cdSJeremy L Thompson CeedInt elem = k % blk_size; 502b730f8bSJeremy L Thompson CeedInt index = (i * blk_size + elem) * layout[0] + j * layout[1] * blk_size + block * layout[2] * blk_size; 51*4fee36f0SJeremy L Thompson if (y_array[index] != x_array[ind[k * elem_size + i] + j * (num_elem + 1)]) { 520acb07cdSJeremy L Thompson // LCOV_EXCL_START 53*4fee36f0SJeremy L Thompson printf("Error in restricted array y[%" CeedInt_FMT "][%" CeedInt_FMT "][%" CeedInt_FMT "] = %f\n", i, j, k, (double)y_array[index]); 540acb07cdSJeremy L Thompson // LCOV_EXCL_STOP 550acb07cdSJeremy L Thompson } 562b730f8bSJeremy L Thompson } 572b730f8bSJeremy L Thompson } 582b730f8bSJeremy L Thompson } 59*4fee36f0SJeremy L Thompson CeedVectorRestoreArrayRead(y, &y_array); 60*4fee36f0SJeremy L Thompson } 6157c64913Sjeremylt 6257c64913Sjeremylt // Transpose 630acb07cdSJeremy L Thompson CeedVectorSetValue(x, 0); 64*4fee36f0SJeremy L Thompson CeedElemRestrictionApply(elem_restriction, CEED_TRANSPOSE, y, x, CEED_REQUEST_IMMEDIATE); 65*4fee36f0SJeremy L Thompson { 66*4fee36f0SJeremy L Thompson const CeedScalar *x_array; 67*4fee36f0SJeremy L Thompson 68*4fee36f0SJeremy L Thompson CeedVectorGetArrayRead(x, CEED_MEM_HOST, &x_array); 690acb07cdSJeremy L Thompson for (CeedInt i = 0; i < num_elem + 1; i++) { 700acb07cdSJeremy L Thompson for (CeedInt j = 0; j < num_comp; j++) { 71*4fee36f0SJeremy L Thompson if (x_array[i + j * (num_elem + 1)] != ((j + 1) * 10 + i) * (i > 0 && i < num_elem ? 2.0 : 1.0)) { 720acb07cdSJeremy L Thompson // LCOV_EXCL_START 73*4fee36f0SJeremy L Thompson printf("Error in restricted array x[%" CeedInt_FMT "][%" CeedInt_FMT "] = %f\n", j, i, (double)x_array[i + j * (num_elem + 1)]); 740acb07cdSJeremy L Thompson // LCOV_EXCL_STOP 750acb07cdSJeremy L Thompson } 760acb07cdSJeremy L Thompson } 772b730f8bSJeremy L Thompson } 78*4fee36f0SJeremy L Thompson CeedVectorRestoreArrayRead(x, &x_array); 79*4fee36f0SJeremy L Thompson } 8057c64913Sjeremylt 8157c64913Sjeremylt CeedVectorDestroy(&x); 8257c64913Sjeremylt CeedVectorDestroy(&y); 83*4fee36f0SJeremy L Thompson CeedElemRestrictionDestroy(&elem_restriction); 8457c64913Sjeremylt CeedDestroy(&ceed); 8557c64913Sjeremylt return 0; 8657c64913Sjeremylt } 87