173d26085Sjeremylt /// @file
2ac5aa7bcSJeremy L Thompson /// Test creation, use, and destruction of a multi-component element restriction
3ac5aa7bcSJeremy L Thompson /// \test Test creation, use, and destruction of a multi-component element restriction
473d26085Sjeremylt #include <ceed.h>
5ec3da8bcSJed Brown #include <ceed/backend.h>
649aac155SJeremy L Thompson #include <stdio.h>
773d26085Sjeremylt
main(int argc,char ** argv)873d26085Sjeremylt int main(int argc, char **argv) {
973d26085Sjeremylt Ceed ceed;
1073d26085Sjeremylt CeedVector x, y;
11d1d35e2fSjeremylt CeedInt num_elem = 3;
12d1d35e2fSjeremylt CeedInt ind[2 * num_elem];
13*33c56a19SJeremy L Thompson CeedInt e_layout[3];
144fee36f0SJeremy L Thompson CeedScalar x_array[2 * (num_elem + 1)];
154fee36f0SJeremy L Thompson CeedElemRestriction elem_restriction;
1673d26085Sjeremylt
1773d26085Sjeremylt CeedInit(argv[1], &ceed);
1873d26085Sjeremylt
1973d26085Sjeremylt // Setup
20d1d35e2fSjeremylt CeedVectorCreate(ceed, 2 * (num_elem + 1), &x);
21d1d35e2fSjeremylt for (CeedInt i = 0; i < num_elem + 1; i++) {
224fee36f0SJeremy L Thompson x_array[i] = 10 + i;
234fee36f0SJeremy L Thompson x_array[i + num_elem + 1] = 20 + i;
2473d26085Sjeremylt }
254fee36f0SJeremy L Thompson CeedVectorSetArray(x, CEED_MEM_HOST, CEED_USE_POINTER, x_array);
264fee36f0SJeremy L Thompson CeedVectorCreate(ceed, 2 * (num_elem * 2), &y);
2773d26085Sjeremylt
28d1d35e2fSjeremylt for (CeedInt i = 0; i < num_elem; i++) {
2973d26085Sjeremylt ind[2 * i + 0] = i;
3073d26085Sjeremylt ind[2 * i + 1] = i + 1;
3173d26085Sjeremylt }
324fee36f0SJeremy L Thompson CeedElemRestrictionCreate(ceed, num_elem, 2, 2, num_elem + 1, 2 * (num_elem + 1), CEED_MEM_HOST, CEED_USE_POINTER, ind, &elem_restriction);
3373d26085Sjeremylt
3473d26085Sjeremylt // Restrict
354fee36f0SJeremy L Thompson CeedElemRestrictionApply(elem_restriction, CEED_NOTRANSPOSE, x, y, CEED_REQUEST_IMMEDIATE);
3673d26085Sjeremylt
3773d26085Sjeremylt // Check
384fee36f0SJeremy L Thompson {
394fee36f0SJeremy L Thompson const CeedScalar *y_array;
404fee36f0SJeremy L Thompson
414fee36f0SJeremy L Thompson CeedVectorGetArrayRead(y, CEED_MEM_HOST, &y_array);
42*33c56a19SJeremy L Thompson CeedElemRestrictionGetELayout(elem_restriction, e_layout);
432b730f8bSJeremy L Thompson for (CeedInt i = 0; i < 2; i++) { // Node
442b730f8bSJeremy L Thompson for (CeedInt j = 0; j < 2; j++) { // Component
452b730f8bSJeremy L Thompson for (CeedInt k = 0; k < num_elem; k++) { // Element
46*33c56a19SJeremy L Thompson if (y_array[i * e_layout[0] + j * e_layout[1] + k * e_layout[2]] != x_array[ind[i + k * 2] + j * (num_elem + 1)]) {
47a2546046Sjeremylt // LCOV_EXCL_START
482b730f8bSJeremy L Thompson printf("Error in restricted array y[%" CeedInt_FMT "][%" CeedInt_FMT "][%" CeedInt_FMT "] = %f != %f\n", i, j, k,
49*33c56a19SJeremy L Thompson (CeedScalar)y_array[i * e_layout[0] + j * e_layout[1] + k * e_layout[2]], x_array[ind[i + k * 2] + j * (num_elem + 1)]);
50de996c55Sjeremylt // LCOV_EXCL_STOP
512b730f8bSJeremy L Thompson }
522b730f8bSJeremy L Thompson }
532b730f8bSJeremy L Thompson }
542b730f8bSJeremy L Thompson }
554fee36f0SJeremy L Thompson CeedVectorRestoreArrayRead(y, &y_array);
564fee36f0SJeremy L Thompson }
5773d26085Sjeremylt
5873d26085Sjeremylt CeedVectorDestroy(&x);
5973d26085Sjeremylt CeedVectorDestroy(&y);
604fee36f0SJeremy L Thompson CeedElemRestrictionDestroy(&elem_restriction);
6173d26085Sjeremylt CeedDestroy(&ceed);
6273d26085Sjeremylt return 0;
6373d26085Sjeremylt }
64