1 /// @file 2 /// Test viewing of mass matrix operator 3 /// \test Test viewing of mass matrix operator 4 #include <ceed.h> 5 #include <stdlib.h> 6 #include <math.h> 7 8 #include "t500-operator.h" 9 10 int main(int argc, char **argv) { 11 Ceed ceed; 12 CeedInterlaceMode imode = CEED_NONINTERLACED; 13 CeedElemRestriction Erestrictx, Erestrictu, Erestrictxi, Erestrictui; 14 CeedBasis bx, bu; 15 CeedQFunction qf_setup, qf_mass; 16 CeedOperator op_setup, op_mass; 17 CeedVector qdata; 18 CeedInt nelem = 15, P = 5, Q = 8; 19 CeedInt Nx = nelem+1, Nu = nelem*(P-1)+1; 20 CeedInt indx[nelem*2], indu[nelem*P]; 21 22 CeedInit(argv[1], &ceed); 23 24 for (CeedInt i=0; i<nelem; i++) { 25 indx[2*i+0] = i; 26 indx[2*i+1] = i+1; 27 } 28 // Restrictions 29 CeedElemRestrictionCreate(ceed, imode, nelem, 2, Nx, 1, CEED_MEM_HOST, 30 CEED_USE_POINTER, indx, &Erestrictx); 31 CeedElemRestrictionCreateIdentity(ceed, imode, nelem, 2, nelem*2, 1, 32 &Erestrictxi); 33 34 for (CeedInt i=0; i<nelem; i++) { 35 for (CeedInt j=0; j<P; j++) { 36 indu[P*i+j] = i*(P-1) + j; 37 } 38 } 39 CeedElemRestrictionCreate(ceed, imode, nelem, P, Nu, 2, CEED_MEM_HOST, 40 CEED_USE_POINTER, indu, &Erestrictu); 41 CeedElemRestrictionCreateIdentity(ceed, imode, nelem, Q, Q*nelem, 1, 42 &Erestrictui); 43 44 // Bases 45 CeedBasisCreateTensorH1Lagrange(ceed, 1, 1, 2, Q, CEED_GAUSS, &bx); 46 CeedBasisCreateTensorH1Lagrange(ceed, 1, 2, P, Q, CEED_GAUSS, &bu); 47 48 // QFunctions 49 CeedQFunctionCreateInterior(ceed, 1, setup, setup_loc, &qf_setup); 50 CeedQFunctionAddInput(qf_setup, "_weight", 1, CEED_EVAL_WEIGHT); 51 CeedQFunctionAddInput(qf_setup, "dx", 1*1, CEED_EVAL_GRAD); 52 CeedQFunctionAddOutput(qf_setup, "rho", 1, CEED_EVAL_NONE); 53 54 CeedQFunctionCreateInterior(ceed, 1, mass, mass_loc, &qf_mass); 55 CeedQFunctionAddInput(qf_mass, "rho", 1, CEED_EVAL_NONE); 56 CeedQFunctionAddInput(qf_mass, "u", 2, CEED_EVAL_INTERP); 57 CeedQFunctionAddOutput(qf_mass, "v", 2, CEED_EVAL_INTERP); 58 59 // Operators 60 CeedOperatorCreate(ceed, qf_setup, CEED_QFUNCTION_NONE, CEED_QFUNCTION_NONE, 61 &op_setup); 62 63 CeedOperatorCreate(ceed, qf_mass, CEED_QFUNCTION_NONE, CEED_QFUNCTION_NONE, 64 &op_mass); 65 66 CeedVectorCreate(ceed, nelem*Q, &qdata); 67 68 CeedOperatorSetField(op_setup, "_weight", Erestrictxi, bx, CEED_VECTOR_NONE); 69 CeedOperatorSetField(op_setup, "dx", Erestrictx, bx, CEED_VECTOR_ACTIVE); 70 CeedOperatorSetField(op_setup, "rho", Erestrictui, CEED_BASIS_COLLOCATED, 71 CEED_VECTOR_ACTIVE); 72 73 CeedOperatorSetField(op_mass, "rho", Erestrictui, CEED_BASIS_COLLOCATED, 74 qdata); 75 CeedOperatorSetField(op_mass, "u", Erestrictu, bu, CEED_VECTOR_ACTIVE); 76 CeedOperatorSetField(op_mass, "v", Erestrictu, bu, CEED_VECTOR_ACTIVE); 77 78 CeedOperatorView(op_setup, stdout); 79 CeedOperatorView(op_mass, stdout); 80 81 CeedQFunctionDestroy(&qf_setup); 82 CeedQFunctionDestroy(&qf_mass); 83 CeedOperatorDestroy(&op_setup); 84 CeedOperatorDestroy(&op_mass); 85 CeedElemRestrictionDestroy(&Erestrictu); 86 CeedElemRestrictionDestroy(&Erestrictx); 87 CeedElemRestrictionDestroy(&Erestrictui); 88 CeedElemRestrictionDestroy(&Erestrictxi); 89 CeedBasisDestroy(&bu); 90 CeedBasisDestroy(&bx); 91 CeedVectorDestroy(&qdata); 92 CeedDestroy(&ceed); 93 return 0; 94 } 95