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> 6*49aac155SJeremy L Thompson #include <stdio.h> 72b730f8bSJeremy L Thompson #include <stdlib.h> 82ebaca42Sjeremylt 92ebaca42Sjeremylt #include "t500-operator.h" 102ebaca42Sjeremylt 112ebaca42Sjeremylt int main(int argc, char **argv) { 122ebaca42Sjeremylt Ceed ceed; 134fee36f0SJeremy L Thompson CeedElemRestriction elem_restriction_x, elem_restriction_u, elem_restriction_q_data; 144fee36f0SJeremy L Thompson CeedBasis basis_x, basis_u; 152ebaca42Sjeremylt CeedQFunction qf_setup, qf_mass; 162ebaca42Sjeremylt CeedOperator op_setup, op_mass; 17d1d35e2fSjeremylt CeedVector q_data; 184fee36f0SJeremy L Thompson CeedInt num_elem = 15, p = 5, q = 8; 194fee36f0SJeremy L Thompson CeedInt num_nodes_x = num_elem + 1, num_nodes_u = num_elem * (p - 1) + 1; 204fee36f0SJeremy L Thompson CeedInt ind_x[num_elem * 2], ind_u[num_elem * p]; 212ebaca42Sjeremylt 222ebaca42Sjeremylt CeedInit(argv[1], &ceed); 232ebaca42Sjeremylt 244fee36f0SJeremy L Thompson CeedVectorCreate(ceed, num_elem * q, &q_data); 254fee36f0SJeremy L Thompson 264fee36f0SJeremy L Thompson // Restrictions 27d1d35e2fSjeremylt for (CeedInt i = 0; i < num_elem; i++) { 28d1d35e2fSjeremylt ind_x[2 * i + 0] = i; 29d1d35e2fSjeremylt ind_x[2 * i + 1] = i + 1; 302ebaca42Sjeremylt } 314fee36f0SJeremy L Thompson CeedElemRestrictionCreate(ceed, num_elem, 2, 1, 1, num_nodes_x, CEED_MEM_HOST, CEED_USE_POINTER, ind_x, &elem_restriction_x); 3215910d16Sjeremylt 33d1d35e2fSjeremylt for (CeedInt i = 0; i < num_elem; i++) { 344fee36f0SJeremy L Thompson for (CeedInt j = 0; j < p; j++) { 354fee36f0SJeremy L Thompson ind_u[p * i + j] = 2 * (i * (p - 1) + j); 362ebaca42Sjeremylt } 372ebaca42Sjeremylt } 384fee36f0SJeremy L Thompson CeedElemRestrictionCreate(ceed, num_elem, p, 2, 1, 2 * num_nodes_u, CEED_MEM_HOST, CEED_USE_POINTER, ind_u, &elem_restriction_u); 394fee36f0SJeremy L Thompson 404fee36f0SJeremy L Thompson CeedInt strides_q_data[3] = {1, q, q}; 414fee36f0SJeremy L Thompson CeedElemRestrictionCreateStrided(ceed, num_elem, q, 1, q * num_elem, strides_q_data, &elem_restriction_q_data); 422ebaca42Sjeremylt 432ebaca42Sjeremylt // Bases 444fee36f0SJeremy L Thompson CeedBasisCreateTensorH1Lagrange(ceed, 1, 1, 2, q, CEED_GAUSS, &basis_x); 454fee36f0SJeremy L Thompson CeedBasisCreateTensorH1Lagrange(ceed, 1, 2, p, q, CEED_GAUSS, &basis_u); 462ebaca42Sjeremylt 472ebaca42Sjeremylt // QFunctions 482ebaca42Sjeremylt CeedQFunctionCreateInterior(ceed, 1, setup, setup_loc, &qf_setup); 49a61c78d6SJeremy L Thompson CeedQFunctionAddInput(qf_setup, "weight", 1, CEED_EVAL_WEIGHT); 502ebaca42Sjeremylt CeedQFunctionAddInput(qf_setup, "dx", 1 * 1, CEED_EVAL_GRAD); 512ebaca42Sjeremylt CeedQFunctionAddOutput(qf_setup, "rho", 1, CEED_EVAL_NONE); 522ebaca42Sjeremylt 532ebaca42Sjeremylt CeedQFunctionCreateInterior(ceed, 1, mass, mass_loc, &qf_mass); 542ebaca42Sjeremylt CeedQFunctionAddInput(qf_mass, "rho", 1, CEED_EVAL_NONE); 552ebaca42Sjeremylt CeedQFunctionAddInput(qf_mass, "u", 2, CEED_EVAL_INTERP); 562ebaca42Sjeremylt CeedQFunctionAddOutput(qf_mass, "v", 2, CEED_EVAL_INTERP); 572ebaca42Sjeremylt 582ebaca42Sjeremylt // Operators 592b730f8bSJeremy L Thompson CeedOperatorCreate(ceed, qf_setup, CEED_QFUNCTION_NONE, CEED_QFUNCTION_NONE, &op_setup); 604fee36f0SJeremy L Thompson CeedOperatorSetField(op_setup, "weight", CEED_ELEMRESTRICTION_NONE, basis_x, CEED_VECTOR_NONE); 614fee36f0SJeremy L Thompson CeedOperatorSetField(op_setup, "dx", elem_restriction_x, basis_x, CEED_VECTOR_ACTIVE); 624fee36f0SJeremy L Thompson CeedOperatorSetField(op_setup, "rho", elem_restriction_q_data, CEED_BASIS_COLLOCATED, CEED_VECTOR_ACTIVE); 632ebaca42Sjeremylt 642b730f8bSJeremy L Thompson CeedOperatorCreate(ceed, qf_mass, CEED_QFUNCTION_NONE, CEED_QFUNCTION_NONE, &op_mass); 654fee36f0SJeremy L Thompson CeedOperatorSetField(op_mass, "rho", elem_restriction_q_data, CEED_BASIS_COLLOCATED, q_data); 664fee36f0SJeremy L Thompson CeedOperatorSetField(op_mass, "u", elem_restriction_u, basis_u, CEED_VECTOR_ACTIVE); 674fee36f0SJeremy L Thompson CeedOperatorSetField(op_mass, "v", elem_restriction_u, basis_u, CEED_VECTOR_ACTIVE); 682ebaca42Sjeremylt 692ebaca42Sjeremylt CeedOperatorView(op_setup, stdout); 702ebaca42Sjeremylt CeedOperatorView(op_mass, stdout); 712ebaca42Sjeremylt 724fee36f0SJeremy L Thompson CeedVectorDestroy(&q_data); 734fee36f0SJeremy L Thompson CeedElemRestrictionDestroy(&elem_restriction_u); 744fee36f0SJeremy L Thompson CeedElemRestrictionDestroy(&elem_restriction_x); 754fee36f0SJeremy L Thompson CeedElemRestrictionDestroy(&elem_restriction_q_data); 764fee36f0SJeremy L Thompson CeedBasisDestroy(&basis_u); 774fee36f0SJeremy L Thompson CeedBasisDestroy(&basis_x); 782ebaca42Sjeremylt CeedQFunctionDestroy(&qf_setup); 792ebaca42Sjeremylt CeedQFunctionDestroy(&qf_mass); 802ebaca42Sjeremylt CeedOperatorDestroy(&op_setup); 812ebaca42Sjeremylt CeedOperatorDestroy(&op_mass); 822ebaca42Sjeremylt CeedDestroy(&ceed); 832ebaca42Sjeremylt return 0; 842ebaca42Sjeremylt } 85