1 /// @file 2 /// Test creation, use, and destruction of a blocked element restriction with multiple components in the lvector, and libCEED owns ind pointer 3 /// \test Test creation, use, and destruction of a blocked element restriction with multiple components in the lvector, and libCEED owns ind pointer 4 #include <stdlib.h> 5 #include <ceed.h> 6 7 int main(int argc, char **argv) { 8 Ceed ceed; 9 CeedVector x, y; 10 CeedInt num_elem = 8; 11 CeedInt blk_size = 5; 12 CeedInt num_comp = 3; 13 CeedInt *ind = malloc(sizeof(CeedInt)*2*num_elem); 14 CeedScalar a[num_comp*(num_elem+1)]; 15 CeedElemRestriction r; 16 17 CeedInit(argv[1], &ceed); 18 19 CeedVectorCreate(ceed, (num_elem+1)*num_comp, &x); 20 for (CeedInt i=0; i<(num_elem+1); i++) { 21 a[i+0*(num_elem+1)] = 10 + i; 22 a[i+1*(num_elem+1)] = 20 + i; 23 a[i+2*(num_elem+1)] = 30 + i; 24 } 25 CeedVectorSetArray(x, CEED_MEM_HOST, CEED_USE_POINTER, a); 26 CeedVectorView(x, "%12.8f", stdout); 27 for (CeedInt i=0; i<num_elem; i++) { 28 ind[2*i+0] = i; 29 ind[2*i+1] = i+1; 30 } 31 CeedElemRestrictionCreateBlocked(ceed, num_elem, 2, blk_size, num_comp, 32 num_elem+1, 33 num_comp*(num_elem+1), CEED_MEM_HOST, 34 CEED_OWN_POINTER, ind, &r); 35 CeedVectorCreate(ceed, 2*blk_size*2*num_comp, &y); 36 CeedVectorSetValue(y, 0); // Allocates array 37 38 // NoTranspose 39 CeedElemRestrictionApply(r, CEED_NOTRANSPOSE, x, y, CEED_REQUEST_IMMEDIATE); 40 CeedVectorView(y, "%12.8f", stdout); 41 42 // Transpose 43 CeedVectorGetArray(x, CEED_MEM_HOST, (CeedScalar **)&a); 44 for (CeedInt i=0; i<(num_elem+1)*num_comp; i++) 45 a[i] = 0; 46 CeedVectorRestoreArray(x, (CeedScalar **)&a); 47 CeedElemRestrictionApply(r, CEED_TRANSPOSE, y, x, CEED_REQUEST_IMMEDIATE); 48 CeedVectorView(x, "%12.8f", stdout); 49 50 CeedVectorDestroy(&x); 51 CeedVectorDestroy(&y); 52 CeedElemRestrictionDestroy(&r); 53 CeedDestroy(&ceed); 54 return 0; 55 } 56