1 /// @file 2 /// Test creation, action, and destruction for identity operator 3 /// \test Test creation, action, and destruction for identity operator 4 #include <ceed.h> 5 #include <math.h> 6 #include <stdlib.h> 7 8 int main(int argc, char **argv) { 9 Ceed ceed; 10 CeedElemRestriction elem_restr_u, elem_restr_u_i; 11 CeedBasis basis_u; 12 CeedQFunction qf_identity; 13 CeedOperator op_identity; 14 CeedVector U, V; 15 const CeedScalar *hv; 16 CeedInt num_elem = 15, P = 5, Q = 8; 17 CeedInt elem_size = P, num_nodes = num_elem * (P - 1) + 1; 18 CeedInt ind_u[num_elem * P]; 19 20 CeedInit(argv[1], &ceed); 21 22 // Restrictions 23 for (CeedInt i = 0; i < num_elem; i++) { 24 for (CeedInt j = 0; j < P; j++) { 25 ind_u[P * i + j] = i * (P - 1) + j; 26 } 27 } 28 CeedElemRestrictionCreate(ceed, num_elem, elem_size, 1, 1, num_nodes, CEED_MEM_HOST, CEED_USE_POINTER, ind_u, &elem_restr_u); 29 CeedInt strides_u_i[3] = {1, P, P}; 30 CeedElemRestrictionCreateStrided(ceed, num_elem, elem_size, 1, elem_size * num_elem, strides_u_i, &elem_restr_u_i); 31 32 // Bases 33 CeedBasisCreateTensorH1Lagrange(ceed, 1, 1, P, Q, CEED_GAUSS, &basis_u); 34 35 // QFunction 36 CeedQFunctionCreateIdentity(ceed, 1, CEED_EVAL_NONE, CEED_EVAL_NONE, &qf_identity); 37 38 // Operators 39 CeedOperatorCreate(ceed, qf_identity, CEED_QFUNCTION_NONE, CEED_QFUNCTION_NONE, &op_identity); 40 CeedOperatorSetField(op_identity, "input", elem_restr_u, CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE); 41 CeedOperatorSetField(op_identity, "output", elem_restr_u_i, CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE); 42 CeedOperatorSetNumQuadraturePoints(op_identity, elem_size); 43 44 CeedVectorCreate(ceed, num_nodes, &U); 45 CeedVectorSetValue(U, 3.0); 46 CeedVectorCreate(ceed, elem_size * num_elem, &V); 47 CeedOperatorApply(op_identity, U, V, CEED_REQUEST_IMMEDIATE); 48 49 // Check output 50 CeedVectorGetArrayRead(V, CEED_MEM_HOST, &hv); 51 for (CeedInt i = 0; i < elem_size * num_elem; i++) { 52 if (fabs(hv[i] - 3.) > 1e-14) printf("[%" CeedInt_FMT "] Computed Value: %f != True Value: 1.0\n", i, hv[i]); 53 } 54 CeedVectorRestoreArrayRead(V, &hv); 55 56 CeedQFunctionDestroy(&qf_identity); 57 CeedOperatorDestroy(&op_identity); 58 CeedElemRestrictionDestroy(&elem_restr_u); 59 CeedElemRestrictionDestroy(&elem_restr_u_i); 60 CeedBasisDestroy(&basis_u); 61 CeedVectorDestroy(&U); 62 CeedVectorDestroy(&V); 63 CeedDestroy(&ceed); 64 return 0; 65 } 66