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]; 16d1d35e2fSjeremylt CeedScalar a[num_comp * (num_elem + 1)]; 170acb07cdSJeremy L Thompson const CeedScalar *xx, *yy; 180acb07cdSJeremy L Thompson CeedInt layout[3]; 1957c64913Sjeremylt CeedElemRestriction r; 2057c64913Sjeremylt 2157c64913Sjeremylt CeedInit(argv[1], &ceed); 22288c0443SJeremy L Thompson 230acb07cdSJeremy L Thompson CeedVectorCreate(ceed, num_comp * (num_elem + 1), &x); 240acb07cdSJeremy L Thompson for (CeedInt i = 0; i < num_elem + 1; i++) { 25d1d35e2fSjeremylt a[i + 0 * (num_elem + 1)] = 10 + i; 26d1d35e2fSjeremylt a[i + 1 * (num_elem + 1)] = 20 + i; 27d1d35e2fSjeremylt a[i + 2 * (num_elem + 1)] = 30 + i; 2857c64913Sjeremylt } 2957c64913Sjeremylt CeedVectorSetArray(x, CEED_MEM_HOST, CEED_USE_POINTER, a); 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 } 35*2b730f8bSJeremy L Thompson CeedElemRestrictionCreateBlocked(ceed, num_elem, elem_size, blk_size, num_comp, num_elem + 1, num_comp * (num_elem + 1), CEED_MEM_HOST, 36d979a051Sjeremylt CEED_USE_POINTER, ind, &r); 370acb07cdSJeremy L Thompson CeedVectorCreate(ceed, num_comp * num_blk * blk_size * elem_size, &y); 3857c64913Sjeremylt 3957c64913Sjeremylt // NoTranspose 40a8d32208Sjeremylt CeedElemRestrictionApply(r, CEED_NOTRANSPOSE, x, y, CEED_REQUEST_IMMEDIATE); 410acb07cdSJeremy L Thompson CeedVectorGetArrayRead(y, CEED_MEM_HOST, &yy); 420acb07cdSJeremy L Thompson CeedElemRestrictionGetELayout(r, &layout); 43*2b730f8bSJeremy L Thompson for (CeedInt i = 0; i < elem_size; i++) { // Node 44*2b730f8bSJeremy L Thompson for (CeedInt j = 0; j < num_comp; j++) { // Component 450acb07cdSJeremy L Thompson for (CeedInt k = 0; k < num_elem; k++) { // Element 460acb07cdSJeremy L Thompson CeedInt block = k / blk_size; 470acb07cdSJeremy L Thompson CeedInt elem = k % blk_size; 48*2b730f8bSJeremy L Thompson CeedInt index = (i * blk_size + elem) * layout[0] + j * layout[1] * blk_size + block * layout[2] * blk_size; 49*2b730f8bSJeremy L Thompson if (yy[index] != a[ind[k * elem_size + i] + j * (num_elem + 1)]) { 500acb07cdSJeremy L Thompson // LCOV_EXCL_START 51*2b730f8bSJeremy L Thompson printf("Error in restricted array y[%" CeedInt_FMT "][%" CeedInt_FMT "][%" CeedInt_FMT "] = %f\n", i, j, k, (double)yy[index]); 520acb07cdSJeremy L Thompson // LCOV_EXCL_STOP 530acb07cdSJeremy L Thompson } 54*2b730f8bSJeremy L Thompson } 55*2b730f8bSJeremy L Thompson } 56*2b730f8bSJeremy L Thompson } 570acb07cdSJeremy L Thompson CeedVectorRestoreArrayRead(y, &yy); 5857c64913Sjeremylt 5957c64913Sjeremylt // Transpose 600acb07cdSJeremy L Thompson CeedVectorSetValue(x, 0); 61a8d32208Sjeremylt CeedElemRestrictionApply(r, CEED_TRANSPOSE, y, x, CEED_REQUEST_IMMEDIATE); 620acb07cdSJeremy L Thompson CeedVectorGetArrayRead(x, CEED_MEM_HOST, &xx); 630acb07cdSJeremy L Thompson for (CeedInt i = 0; i < num_elem + 1; i++) { 640acb07cdSJeremy L Thompson for (CeedInt j = 0; j < num_comp; j++) { 65*2b730f8bSJeremy L Thompson if (xx[i + j * (num_elem + 1)] != ((j + 1) * 10 + i) * (i > 0 && i < num_elem ? 2.0 : 1.0)) { 660acb07cdSJeremy L Thompson // LCOV_EXCL_START 67*2b730f8bSJeremy L Thompson printf("Error in restricted array x[%" CeedInt_FMT "][%" CeedInt_FMT "] = %f\n", j, i, (double)xx[i + j * (num_elem + 1)]); 680acb07cdSJeremy L Thompson // LCOV_EXCL_STOP 690acb07cdSJeremy L Thompson } 700acb07cdSJeremy L Thompson } 71*2b730f8bSJeremy L Thompson } 720acb07cdSJeremy L Thompson CeedVectorRestoreArrayRead(x, &xx); 7357c64913Sjeremylt 7457c64913Sjeremylt CeedVectorDestroy(&x); 7557c64913Sjeremylt CeedVectorDestroy(&y); 7657c64913Sjeremylt CeedElemRestrictionDestroy(&r); 7757c64913Sjeremylt CeedDestroy(&ceed); 7857c64913Sjeremylt return 0; 7957c64913Sjeremylt } 80