12ebaca42Sjeremylt /// @file 22ebaca42Sjeremylt /// Test viewing of mass matrix operator 32ebaca42Sjeremylt /// \test Test viewing of mass matrix operator 42ebaca42Sjeremylt #include <ceed.h> 52ebaca42Sjeremylt #include <math.h> 62b730f8bSJeremy L Thompson #include <stdlib.h> 72ebaca42Sjeremylt 82ebaca42Sjeremylt #include "t500-operator.h" 92ebaca42Sjeremylt 102ebaca42Sjeremylt int main(int argc, char **argv) { 112ebaca42Sjeremylt Ceed ceed; 12*4fee36f0SJeremy L Thompson CeedElemRestriction elem_restriction_x, elem_restriction_u, elem_restriction_q_data; 13*4fee36f0SJeremy L Thompson CeedBasis basis_x, basis_u; 142ebaca42Sjeremylt CeedQFunction qf_setup, qf_mass; 152ebaca42Sjeremylt CeedOperator op_setup, op_mass; 16d1d35e2fSjeremylt CeedVector q_data; 17*4fee36f0SJeremy L Thompson CeedInt num_elem = 15, p = 5, q = 8; 18*4fee36f0SJeremy L Thompson CeedInt num_nodes_x = num_elem + 1, num_nodes_u = num_elem * (p - 1) + 1; 19*4fee36f0SJeremy L Thompson CeedInt ind_x[num_elem * 2], ind_u[num_elem * p]; 202ebaca42Sjeremylt 212ebaca42Sjeremylt CeedInit(argv[1], &ceed); 222ebaca42Sjeremylt 23*4fee36f0SJeremy L Thompson CeedVectorCreate(ceed, num_elem * q, &q_data); 24*4fee36f0SJeremy L Thompson 25*4fee36f0SJeremy L Thompson // Restrictions 26d1d35e2fSjeremylt for (CeedInt i = 0; i < num_elem; i++) { 27d1d35e2fSjeremylt ind_x[2 * i + 0] = i; 28d1d35e2fSjeremylt ind_x[2 * i + 1] = i + 1; 292ebaca42Sjeremylt } 30*4fee36f0SJeremy L Thompson CeedElemRestrictionCreate(ceed, num_elem, 2, 1, 1, num_nodes_x, CEED_MEM_HOST, CEED_USE_POINTER, ind_x, &elem_restriction_x); 3115910d16Sjeremylt 32d1d35e2fSjeremylt for (CeedInt i = 0; i < num_elem; i++) { 33*4fee36f0SJeremy L Thompson for (CeedInt j = 0; j < p; j++) { 34*4fee36f0SJeremy L Thompson ind_u[p * i + j] = 2 * (i * (p - 1) + j); 352ebaca42Sjeremylt } 362ebaca42Sjeremylt } 37*4fee36f0SJeremy L Thompson CeedElemRestrictionCreate(ceed, num_elem, p, 2, 1, 2 * num_nodes_u, CEED_MEM_HOST, CEED_USE_POINTER, ind_u, &elem_restriction_u); 38*4fee36f0SJeremy L Thompson 39*4fee36f0SJeremy L Thompson CeedInt strides_q_data[3] = {1, q, q}; 40*4fee36f0SJeremy L Thompson CeedElemRestrictionCreateStrided(ceed, num_elem, q, 1, q * num_elem, strides_q_data, &elem_restriction_q_data); 412ebaca42Sjeremylt 422ebaca42Sjeremylt // Bases 43*4fee36f0SJeremy L Thompson CeedBasisCreateTensorH1Lagrange(ceed, 1, 1, 2, q, CEED_GAUSS, &basis_x); 44*4fee36f0SJeremy L Thompson CeedBasisCreateTensorH1Lagrange(ceed, 1, 2, p, q, CEED_GAUSS, &basis_u); 452ebaca42Sjeremylt 462ebaca42Sjeremylt // QFunctions 472ebaca42Sjeremylt CeedQFunctionCreateInterior(ceed, 1, setup, setup_loc, &qf_setup); 48a61c78d6SJeremy L Thompson CeedQFunctionAddInput(qf_setup, "weight", 1, CEED_EVAL_WEIGHT); 492ebaca42Sjeremylt CeedQFunctionAddInput(qf_setup, "dx", 1 * 1, CEED_EVAL_GRAD); 502ebaca42Sjeremylt CeedQFunctionAddOutput(qf_setup, "rho", 1, CEED_EVAL_NONE); 512ebaca42Sjeremylt 522ebaca42Sjeremylt CeedQFunctionCreateInterior(ceed, 1, mass, mass_loc, &qf_mass); 532ebaca42Sjeremylt CeedQFunctionAddInput(qf_mass, "rho", 1, CEED_EVAL_NONE); 542ebaca42Sjeremylt CeedQFunctionAddInput(qf_mass, "u", 2, CEED_EVAL_INTERP); 552ebaca42Sjeremylt CeedQFunctionAddOutput(qf_mass, "v", 2, CEED_EVAL_INTERP); 562ebaca42Sjeremylt 572ebaca42Sjeremylt // Operators 582b730f8bSJeremy L Thompson CeedOperatorCreate(ceed, qf_setup, CEED_QFUNCTION_NONE, CEED_QFUNCTION_NONE, &op_setup); 59*4fee36f0SJeremy L Thompson CeedOperatorSetField(op_setup, "weight", CEED_ELEMRESTRICTION_NONE, basis_x, CEED_VECTOR_NONE); 60*4fee36f0SJeremy L Thompson CeedOperatorSetField(op_setup, "dx", elem_restriction_x, basis_x, CEED_VECTOR_ACTIVE); 61*4fee36f0SJeremy L Thompson CeedOperatorSetField(op_setup, "rho", elem_restriction_q_data, CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE); 622ebaca42Sjeremylt 632b730f8bSJeremy L Thompson CeedOperatorCreate(ceed, qf_mass, CEED_QFUNCTION_NONE, CEED_QFUNCTION_NONE, &op_mass); 64*4fee36f0SJeremy L Thompson CeedOperatorSetField(op_mass, "rho", elem_restriction_q_data, CEED_BASIS_COLLOCATED, q_data); 65*4fee36f0SJeremy L Thompson CeedOperatorSetField(op_mass, "u", elem_restriction_u, basis_u, CEED_VECTOR_ACTIVE); 66*4fee36f0SJeremy L Thompson CeedOperatorSetField(op_mass, "v", elem_restriction_u, basis_u, CEED_VECTOR_ACTIVE); 672ebaca42Sjeremylt 682ebaca42Sjeremylt CeedOperatorView(op_setup, stdout); 692ebaca42Sjeremylt CeedOperatorView(op_mass, stdout); 702ebaca42Sjeremylt 71*4fee36f0SJeremy L Thompson CeedVectorDestroy(&q_data); 72*4fee36f0SJeremy L Thompson CeedElemRestrictionDestroy(&elem_restriction_u); 73*4fee36f0SJeremy L Thompson CeedElemRestrictionDestroy(&elem_restriction_x); 74*4fee36f0SJeremy L Thompson CeedElemRestrictionDestroy(&elem_restriction_q_data); 75*4fee36f0SJeremy L Thompson CeedBasisDestroy(&basis_u); 76*4fee36f0SJeremy L Thompson CeedBasisDestroy(&basis_x); 772ebaca42Sjeremylt CeedQFunctionDestroy(&qf_setup); 782ebaca42Sjeremylt CeedQFunctionDestroy(&qf_mass); 792ebaca42Sjeremylt CeedOperatorDestroy(&op_setup); 802ebaca42Sjeremylt CeedOperatorDestroy(&op_mass); 812ebaca42Sjeremylt CeedDestroy(&ceed); 822ebaca42Sjeremylt return 0; 832ebaca42Sjeremylt } 84