14411cf47Sjeremylt /// @file
2ac5aa7bcSJeremy L Thompson /// Test creation, use, and destruction of a blocked element restriction with multiple components in the l-vector
3ac5aa7bcSJeremy L Thompson /// \test Test creation, use, and destruction of a blocked element restriction with multiple components in the l-vector
457c64913Sjeremylt #include <ceed.h>
50acb07cdSJeremy L Thompson #include <ceed/backend.h>
649aac155SJeremy L Thompson #include <stdio.h>
757c64913Sjeremylt
main(int argc,char ** argv)857c64913Sjeremylt int main(int argc, char **argv) {
957c64913Sjeremylt Ceed ceed;
1057c64913Sjeremylt CeedVector x, y;
11d1d35e2fSjeremylt CeedInt num_elem = 8;
120acb07cdSJeremy L Thompson CeedInt elem_size = 2;
130acb07cdSJeremy L Thompson CeedInt num_blk = 2;
14d1d35e2fSjeremylt CeedInt blk_size = 5;
15d1d35e2fSjeremylt CeedInt num_comp = 3;
160acb07cdSJeremy L Thompson CeedInt ind[elem_size * num_elem];
174fee36f0SJeremy L Thompson CeedScalar x_array[num_comp * (num_elem + 1)];
18*33c56a19SJeremy L Thompson CeedInt e_layout[3];
194fee36f0SJeremy L Thompson CeedElemRestriction elem_restriction;
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++) {
254fee36f0SJeremy L Thompson x_array[i + 0 * (num_elem + 1)] = 10 + i;
264fee36f0SJeremy L Thompson x_array[i + 1 * (num_elem + 1)] = 20 + i;
274fee36f0SJeremy L Thompson x_array[i + 2 * (num_elem + 1)] = 30 + i;
2857c64913Sjeremylt }
294fee36f0SJeremy L Thompson CeedVectorSetArray(x, CEED_MEM_HOST, CEED_USE_POINTER, x_array);
304fee36f0SJeremy L Thompson CeedVectorCreate(ceed, num_comp * num_blk * blk_size * elem_size, &y);
310acb07cdSJeremy L Thompson
32d1d35e2fSjeremylt for (CeedInt i = 0; i < num_elem; i++) {
3357c64913Sjeremylt ind[2 * i + 0] = i;
3457c64913Sjeremylt ind[2 * i + 1] = i + 1;
3557c64913Sjeremylt }
362b730f8bSJeremy L Thompson CeedElemRestrictionCreateBlocked(ceed, num_elem, elem_size, blk_size, num_comp, num_elem + 1, num_comp * (num_elem + 1), CEED_MEM_HOST,
374fee36f0SJeremy L Thompson CEED_USE_POINTER, ind, &elem_restriction);
3857c64913Sjeremylt
3957c64913Sjeremylt // NoTranspose
404fee36f0SJeremy L Thompson CeedElemRestrictionApply(elem_restriction, CEED_NOTRANSPOSE, x, y, CEED_REQUEST_IMMEDIATE);
414fee36f0SJeremy L Thompson {
424fee36f0SJeremy L Thompson const CeedScalar *y_array;
434fee36f0SJeremy L Thompson
444fee36f0SJeremy L Thompson CeedVectorGetArrayRead(y, CEED_MEM_HOST, &y_array);
45*33c56a19SJeremy L Thompson CeedElemRestrictionGetELayout(elem_restriction, e_layout);
462b730f8bSJeremy L Thompson for (CeedInt i = 0; i < elem_size; i++) { // Node
472b730f8bSJeremy L Thompson for (CeedInt j = 0; j < num_comp; j++) { // Component
480acb07cdSJeremy L Thompson for (CeedInt k = 0; k < num_elem; k++) { // Element
490acb07cdSJeremy L Thompson CeedInt block = k / blk_size;
500acb07cdSJeremy L Thompson CeedInt elem = k % blk_size;
51*33c56a19SJeremy L Thompson CeedInt index = (i * blk_size + elem) * e_layout[0] + j * e_layout[1] * blk_size + block * e_layout[2] * blk_size;
524fee36f0SJeremy L Thompson if (y_array[index] != x_array[ind[k * elem_size + i] + j * (num_elem + 1)]) {
530acb07cdSJeremy L Thompson // LCOV_EXCL_START
544fee36f0SJeremy L Thompson printf("Error in restricted array y[%" CeedInt_FMT "][%" CeedInt_FMT "][%" CeedInt_FMT "] = %f\n", i, j, k, (double)y_array[index]);
550acb07cdSJeremy L Thompson // LCOV_EXCL_STOP
560acb07cdSJeremy L Thompson }
572b730f8bSJeremy L Thompson }
582b730f8bSJeremy L Thompson }
592b730f8bSJeremy L Thompson }
604fee36f0SJeremy L Thompson CeedVectorRestoreArrayRead(y, &y_array);
614fee36f0SJeremy L Thompson }
6257c64913Sjeremylt
6357c64913Sjeremylt // Transpose
640acb07cdSJeremy L Thompson CeedVectorSetValue(x, 0);
654fee36f0SJeremy L Thompson CeedElemRestrictionApply(elem_restriction, CEED_TRANSPOSE, y, x, CEED_REQUEST_IMMEDIATE);
664fee36f0SJeremy L Thompson {
674fee36f0SJeremy L Thompson const CeedScalar *x_array;
684fee36f0SJeremy L Thompson
694fee36f0SJeremy L Thompson CeedVectorGetArrayRead(x, CEED_MEM_HOST, &x_array);
700acb07cdSJeremy L Thompson for (CeedInt i = 0; i < num_elem + 1; i++) {
710acb07cdSJeremy L Thompson for (CeedInt j = 0; j < num_comp; j++) {
724fee36f0SJeremy L Thompson if (x_array[i + j * (num_elem + 1)] != ((j + 1) * 10 + i) * (i > 0 && i < num_elem ? 2.0 : 1.0)) {
730acb07cdSJeremy L Thompson // LCOV_EXCL_START
744fee36f0SJeremy L Thompson printf("Error in restricted array x[%" CeedInt_FMT "][%" CeedInt_FMT "] = %f\n", j, i, (double)x_array[i + j * (num_elem + 1)]);
750acb07cdSJeremy L Thompson // LCOV_EXCL_STOP
760acb07cdSJeremy L Thompson }
770acb07cdSJeremy L Thompson }
782b730f8bSJeremy L Thompson }
794fee36f0SJeremy L Thompson CeedVectorRestoreArrayRead(x, &x_array);
804fee36f0SJeremy L Thompson }
8157c64913Sjeremylt
8257c64913Sjeremylt CeedVectorDestroy(&x);
8357c64913Sjeremylt CeedVectorDestroy(&y);
844fee36f0SJeremy L Thompson CeedElemRestrictionDestroy(&elem_restriction);
8557c64913Sjeremylt CeedDestroy(&ceed);
8657c64913Sjeremylt return 0;
8757c64913Sjeremylt }
88