10036de2cSjeremylt /// @file 20036de2cSjeremylt /// Test creation, use, and destruction of a blocked element restriction with multiple components in the lvector, and libCEED owns ind pointer 30036de2cSjeremylt /// \test Test creation, use, and destruction of a blocked element restriction with multiple components in the lvector, and libCEED owns ind pointer 40036de2cSjeremylt #include <ceed.h> 50acb07cdSJeremy L Thompson #include <ceed/backend.h> 6*49aac155SJeremy L Thompson #include <stdio.h> 70acb07cdSJeremy L Thompson #include <stdlib.h> 80acb07cdSJeremy L Thompson #include <string.h> 90036de2cSjeremylt 100036de2cSjeremylt int main(int argc, char **argv) { 110036de2cSjeremylt Ceed ceed; 120036de2cSjeremylt CeedVector x, y; 13d1d35e2fSjeremylt CeedInt num_elem = 8; 140acb07cdSJeremy L Thompson CeedInt elem_size = 2; 150acb07cdSJeremy L Thompson CeedInt num_blk = 2; 16d1d35e2fSjeremylt CeedInt blk_size = 5; 17d1d35e2fSjeremylt CeedInt num_comp = 3; 180acb07cdSJeremy L Thompson CeedInt ind[elem_size * num_elem]; 190acb07cdSJeremy L Thompson CeedInt *ceed_ind = malloc(sizeof(CeedInt) * elem_size * num_elem); 204fee36f0SJeremy L Thompson CeedScalar x_array[num_comp * (num_elem + 1)]; 210acb07cdSJeremy L Thompson CeedInt layout[3]; 224fee36f0SJeremy L Thompson CeedElemRestriction elem_restriction; 230036de2cSjeremylt 240036de2cSjeremylt CeedInit(argv[1], &ceed); 250036de2cSjeremylt 260acb07cdSJeremy L Thompson CeedVectorCreate(ceed, num_comp * (num_elem + 1), &x); 270acb07cdSJeremy L Thompson for (CeedInt i = 0; i < num_elem + 1; i++) { 284fee36f0SJeremy L Thompson x_array[i + 0 * (num_elem + 1)] = 10 + i; 294fee36f0SJeremy L Thompson x_array[i + 1 * (num_elem + 1)] = 20 + i; 304fee36f0SJeremy L Thompson x_array[i + 2 * (num_elem + 1)] = 30 + i; 310036de2cSjeremylt } 324fee36f0SJeremy L Thompson CeedVectorSetArray(x, CEED_MEM_HOST, CEED_USE_POINTER, x_array); 334fee36f0SJeremy L Thompson CeedVectorCreate(ceed, num_comp * num_blk * blk_size * elem_size, &y); 340acb07cdSJeremy L Thompson 35d1d35e2fSjeremylt for (CeedInt i = 0; i < num_elem; i++) { 360036de2cSjeremylt ind[2 * i + 0] = i; 370036de2cSjeremylt ind[2 * i + 1] = i + 1; 380036de2cSjeremylt } 390acb07cdSJeremy L Thompson memcpy(ceed_ind, ind, sizeof(CeedInt) * elem_size * num_elem); 402b730f8bSJeremy L Thompson CeedElemRestrictionCreateBlocked(ceed, num_elem, elem_size, blk_size, num_comp, num_elem + 1, num_comp * (num_elem + 1), CEED_MEM_HOST, 414fee36f0SJeremy L Thompson CEED_OWN_POINTER, ceed_ind, &elem_restriction); 420036de2cSjeremylt 430036de2cSjeremylt // NoTranspose 444fee36f0SJeremy L Thompson CeedElemRestrictionApply(elem_restriction, CEED_NOTRANSPOSE, x, y, CEED_REQUEST_IMMEDIATE); 454fee36f0SJeremy L Thompson { 464fee36f0SJeremy L Thompson const CeedScalar *y_array; 474fee36f0SJeremy L Thompson 484fee36f0SJeremy L Thompson CeedVectorGetArrayRead(y, CEED_MEM_HOST, &y_array); 494fee36f0SJeremy L Thompson CeedElemRestrictionGetELayout(elem_restriction, &layout); 502b730f8bSJeremy L Thompson for (CeedInt i = 0; i < elem_size; i++) { // Node 512b730f8bSJeremy L Thompson for (CeedInt j = 0; j < num_comp; j++) { // Component 520acb07cdSJeremy L Thompson for (CeedInt k = 0; k < num_elem; k++) { // Element 530acb07cdSJeremy L Thompson CeedInt block = k / blk_size; 540acb07cdSJeremy L Thompson CeedInt elem = k % blk_size; 552b730f8bSJeremy L Thompson CeedInt index = (i * blk_size + elem) * layout[0] + j * layout[1] * blk_size + block * layout[2] * blk_size; 564fee36f0SJeremy L Thompson if (y_array[index] != x_array[ind[k * elem_size + i] + j * (num_elem + 1)]) 570acb07cdSJeremy L Thompson // LCOV_EXCL_START 584fee36f0SJeremy L Thompson printf("Error in restricted array y[%" CeedInt_FMT "][%" CeedInt_FMT "][%" CeedInt_FMT "] = %f\n", i, j, k, (double)y_array[index]); 590acb07cdSJeremy L Thompson // LCOV_EXCL_STOP 600acb07cdSJeremy L Thompson } 612b730f8bSJeremy L Thompson } 622b730f8bSJeremy L Thompson } 634fee36f0SJeremy L Thompson CeedVectorRestoreArrayRead(y, &y_array); 644fee36f0SJeremy L Thompson } 650036de2cSjeremylt 660036de2cSjeremylt // Transpose 670acb07cdSJeremy L Thompson CeedVectorSetValue(x, 0); 684fee36f0SJeremy L Thompson CeedElemRestrictionApply(elem_restriction, CEED_TRANSPOSE, y, x, CEED_REQUEST_IMMEDIATE); 694fee36f0SJeremy L Thompson { 704fee36f0SJeremy L Thompson const CeedScalar *x_array; 714fee36f0SJeremy L Thompson 724fee36f0SJeremy L Thompson CeedVectorGetArrayRead(x, CEED_MEM_HOST, &x_array); 730acb07cdSJeremy L Thompson for (CeedInt i = 0; i < num_elem + 1; i++) { 740acb07cdSJeremy L Thompson for (CeedInt j = 0; j < num_comp; j++) { 754fee36f0SJeremy L Thompson if (x_array[i + j * (num_elem + 1)] != ((j + 1) * 10 + i) * (i > 0 && i < num_elem ? 2.0 : 1.0)) { 760acb07cdSJeremy L Thompson // LCOV_EXCL_START 774fee36f0SJeremy L Thompson printf("Error in restricted array x[%" CeedInt_FMT "][%" CeedInt_FMT "] = %f\n", j, i, (double)x_array[i + j * (num_elem + 1)]); 780acb07cdSJeremy L Thompson // LCOV_EXCL_STOP 790acb07cdSJeremy L Thompson } 800acb07cdSJeremy L Thompson } 812b730f8bSJeremy L Thompson } 824fee36f0SJeremy L Thompson CeedVectorRestoreArrayRead(x, &x_array); 834fee36f0SJeremy L Thompson } 840036de2cSjeremylt 850036de2cSjeremylt CeedVectorDestroy(&x); 860036de2cSjeremylt CeedVectorDestroy(&y); 874fee36f0SJeremy L Thompson CeedElemRestrictionDestroy(&elem_restriction); 880036de2cSjeremylt CeedDestroy(&ceed); 890036de2cSjeremylt return 0; 900036de2cSjeremylt } 91