12ebaca42Sjeremylt /// @file 231e5b035Sjeremylt /// Test creation, action, and destruction for mass matrix operator 331e5b035Sjeremylt /// \test Test creation, action, and destruction for mass matrix operator 42ebaca42Sjeremylt #include <ceed.h> 52ebaca42Sjeremylt #include <math.h> 649aac155SJeremy L Thompson #include <stdio.h> 72b730f8bSJeremy L Thompson #include <stdlib.h> 82b730f8bSJeremy L Thompson 92ebaca42Sjeremylt #include "t320-basis.h" 102ebaca42Sjeremylt #include "t510-operator.h" 112ebaca42Sjeremylt 124fee36f0SJeremy L Thompson /* The mesh comprises of two rows of 3 quadrilaterals followed by one row 132ebaca42Sjeremylt of 6 triangles: 142ebaca42Sjeremylt _ _ _ 152ebaca42Sjeremylt |_|_|_| 162ebaca42Sjeremylt |_|_|_| 172ebaca42Sjeremylt |/|/|/| 182ebaca42Sjeremylt 192ebaca42Sjeremylt */ 202ebaca42Sjeremylt 212ebaca42Sjeremylt int main(int argc, char **argv) { 222ebaca42Sjeremylt Ceed ceed; 234fee36f0SJeremy L Thompson CeedElemRestriction elem_restriction_x_tet, elem_restriction_u_tet, elem_restr_qd_tet, elem_restriction_x_hex, elem_restriction_u_hex, 244fee36f0SJeremy L Thompson elem_restriction_q_data_hex; 252b730f8bSJeremy L Thompson CeedBasis basis_x_tet, basis_u_tet, basis_x_hex, basis_u_hex; 262b730f8bSJeremy L Thompson CeedQFunction qf_setup_tet, qf_mass_tet, qf_setup_hex, qf_mass_hex; 272b730f8bSJeremy L Thompson CeedOperator op_setup_tet, op_mass_tet, op_setup_hex, op_mass_hex, op_setup, op_mass; 284fee36f0SJeremy L Thompson CeedVector q_data_tet, q_data_hex, x; 294fee36f0SJeremy L Thompson CeedInt num_elem_tet = 6, p_tet = 6, q_tet = 4, num_elem_hex = 6, p_hex = 3, q_hex = 4, dim = 2; 302b730f8bSJeremy L Thompson CeedInt nx = 3, ny = 3, nx_tet = 3, ny_tet = 1, nx_hex = 3; 312ebaca42Sjeremylt CeedInt row, col, offset; 324fee36f0SJeremy L Thompson CeedInt num_dofs = (nx * 2 + 1) * (ny * 2 + 1), num_qpts_tet = num_elem_tet * q_tet, num_qpts_hex = num_elem_hex * q_hex * q_hex; 334fee36f0SJeremy L Thompson CeedInt ind_x_tet[num_elem_tet * p_tet], ind_x_hex[num_elem_hex * p_hex * p_hex]; 344fee36f0SJeremy L Thompson CeedScalar q_ref[dim * q_tet], q_weight[q_tet]; 354fee36f0SJeremy L Thompson CeedScalar interp[p_tet * q_tet], grad[dim * p_tet * q_tet]; 362ebaca42Sjeremylt 372ebaca42Sjeremylt CeedInit(argv[1], &ceed); 382ebaca42Sjeremylt 392ebaca42Sjeremylt // DoF Coordinates 404fee36f0SJeremy L Thompson CeedVectorCreate(ceed, dim * num_dofs, &x); 412ebaca42Sjeremylt 422ebaca42Sjeremylt // Qdata Vectors 43d1d35e2fSjeremylt CeedVectorCreate(ceed, num_qpts_tet, &q_data_tet); 44d1d35e2fSjeremylt CeedVectorCreate(ceed, num_qpts_hex, &q_data_hex); 452ebaca42Sjeremylt 46d1d35e2fSjeremylt // Set up _tet Elements 474fee36f0SJeremy L Thompson // -- Restrictions 484fee36f0SJeremy L Thompson for (CeedInt i = 0; i < num_elem_tet / 2; i++) { 49d1d35e2fSjeremylt col = i % nx_tet; 50d1d35e2fSjeremylt row = i / nx_tet; 51d1d35e2fSjeremylt offset = col * 2 + row * (nx_tet * 2 + 1) * 2; 522ebaca42Sjeremylt 534fee36f0SJeremy L Thompson ind_x_tet[i * 2 * p_tet + 0] = 2 + offset; 544fee36f0SJeremy L Thompson ind_x_tet[i * 2 * p_tet + 1] = 9 + offset; 554fee36f0SJeremy L Thompson ind_x_tet[i * 2 * p_tet + 2] = 16 + offset; 564fee36f0SJeremy L Thompson ind_x_tet[i * 2 * p_tet + 3] = 1 + offset; 574fee36f0SJeremy L Thompson ind_x_tet[i * 2 * p_tet + 4] = 8 + offset; 584fee36f0SJeremy L Thompson ind_x_tet[i * 2 * p_tet + 5] = 0 + offset; 592ebaca42Sjeremylt 604fee36f0SJeremy L Thompson ind_x_tet[i * 2 * p_tet + 6] = 14 + offset; 614fee36f0SJeremy L Thompson ind_x_tet[i * 2 * p_tet + 7] = 7 + offset; 624fee36f0SJeremy L Thompson ind_x_tet[i * 2 * p_tet + 8] = 0 + offset; 634fee36f0SJeremy L Thompson ind_x_tet[i * 2 * p_tet + 9] = 15 + offset; 644fee36f0SJeremy L Thompson ind_x_tet[i * 2 * p_tet + 10] = 8 + offset; 654fee36f0SJeremy L Thompson ind_x_tet[i * 2 * p_tet + 11] = 16 + offset; 662ebaca42Sjeremylt } 674fee36f0SJeremy L Thompson CeedElemRestrictionCreate(ceed, num_elem_tet, p_tet, dim, num_dofs, dim * num_dofs, CEED_MEM_HOST, CEED_USE_POINTER, ind_x_tet, 684fee36f0SJeremy L Thompson &elem_restriction_x_tet); 694fee36f0SJeremy L Thompson CeedElemRestrictionCreate(ceed, num_elem_tet, p_tet, 1, 1, num_dofs, CEED_MEM_HOST, CEED_USE_POINTER, ind_x_tet, &elem_restriction_u_tet); 702ebaca42Sjeremylt 714fee36f0SJeremy L Thompson CeedInt strides_q_data_tet[3] = {1, q_tet, q_tet}; 724fee36f0SJeremy L Thompson CeedElemRestrictionCreateStrided(ceed, num_elem_tet, q_tet, 1, num_qpts_tet, strides_q_data_tet, &elem_restr_qd_tet); 732ebaca42Sjeremylt 742ebaca42Sjeremylt // -- Bases 754fee36f0SJeremy L Thompson Build2DSimplex(q_ref, q_weight, interp, grad); 764fee36f0SJeremy L Thompson CeedBasisCreateH1(ceed, CEED_TOPOLOGY_TRIANGLE, dim, p_tet, q_tet, interp, grad, q_ref, q_weight, &basis_x_tet); 772ebaca42Sjeremylt 784fee36f0SJeremy L Thompson Build2DSimplex(q_ref, q_weight, interp, grad); 794fee36f0SJeremy L Thompson CeedBasisCreateH1(ceed, CEED_TOPOLOGY_TRIANGLE, 1, p_tet, q_tet, interp, grad, q_ref, q_weight, &basis_u_tet); 802ebaca42Sjeremylt 812ebaca42Sjeremylt // -- QFunctions 82d1d35e2fSjeremylt CeedQFunctionCreateInterior(ceed, 1, setup, setup_loc, &qf_setup_tet); 83a61c78d6SJeremy L Thompson CeedQFunctionAddInput(qf_setup_tet, "weight", 1, CEED_EVAL_WEIGHT); 84d1d35e2fSjeremylt CeedQFunctionAddInput(qf_setup_tet, "dx", dim * dim, CEED_EVAL_GRAD); 85d1d35e2fSjeremylt CeedQFunctionAddOutput(qf_setup_tet, "rho", 1, CEED_EVAL_NONE); 862ebaca42Sjeremylt 87d1d35e2fSjeremylt CeedQFunctionCreateInterior(ceed, 1, mass, mass_loc, &qf_mass_tet); 88d1d35e2fSjeremylt CeedQFunctionAddInput(qf_mass_tet, "rho", 1, CEED_EVAL_NONE); 89d1d35e2fSjeremylt CeedQFunctionAddInput(qf_mass_tet, "u", 1, CEED_EVAL_INTERP); 90d1d35e2fSjeremylt CeedQFunctionAddOutput(qf_mass_tet, "v", 1, CEED_EVAL_INTERP); 912ebaca42Sjeremylt 922ebaca42Sjeremylt // -- Operators 93d1d35e2fSjeremylt // ---- Setup _tet 942b730f8bSJeremy L Thompson CeedOperatorCreate(ceed, qf_setup_tet, CEED_QFUNCTION_NONE, CEED_QFUNCTION_NONE, &op_setup_tet); 95ea6b5821SJeremy L Thompson CeedOperatorSetName(op_setup_tet, "triangle elements"); 962b730f8bSJeremy L Thompson CeedOperatorSetField(op_setup_tet, "weight", CEED_ELEMRESTRICTION_NONE, basis_x_tet, CEED_VECTOR_NONE); 974fee36f0SJeremy L Thompson CeedOperatorSetField(op_setup_tet, "dx", elem_restriction_x_tet, basis_x_tet, CEED_VECTOR_ACTIVE); 98*356036faSJeremy L Thompson CeedOperatorSetField(op_setup_tet, "rho", elem_restr_qd_tet, CEED_BASIS_NONE, q_data_tet); 99d1d35e2fSjeremylt // ---- Mass _tet 1002b730f8bSJeremy L Thompson CeedOperatorCreate(ceed, qf_mass_tet, CEED_QFUNCTION_NONE, CEED_QFUNCTION_NONE, &op_mass_tet); 101ea6b5821SJeremy L Thompson CeedOperatorSetName(op_mass_tet, "triangle elements"); 102*356036faSJeremy L Thompson CeedOperatorSetField(op_mass_tet, "rho", elem_restr_qd_tet, CEED_BASIS_NONE, q_data_tet); 1034fee36f0SJeremy L Thompson CeedOperatorSetField(op_mass_tet, "u", elem_restriction_u_tet, basis_u_tet, CEED_VECTOR_ACTIVE); 1044fee36f0SJeremy L Thompson CeedOperatorSetField(op_mass_tet, "v", elem_restriction_u_tet, basis_u_tet, CEED_VECTOR_ACTIVE); 1052ebaca42Sjeremylt 106d1d35e2fSjeremylt // Set up _hex Elements 1074fee36f0SJeremy L Thompson // -- Restrictions 1084fee36f0SJeremy L Thompson for (CeedInt i = 0; i < num_elem_hex; i++) { 109d1d35e2fSjeremylt col = i % nx_hex; 110d1d35e2fSjeremylt row = i / nx_hex; 111d1d35e2fSjeremylt offset = (nx_tet * 2 + 1) * (ny_tet * 2) * (1 + row) + col * 2; 1124fee36f0SJeremy L Thompson for (CeedInt j = 0; j < p_hex; j++) { 1134fee36f0SJeremy L Thompson for (CeedInt k = 0; k < p_hex; k++) ind_x_hex[p_hex * (p_hex * i + k) + j] = offset + k * (nx_hex * 2 + 1) + j; 1142b730f8bSJeremy L Thompson } 1152ebaca42Sjeremylt } 1164fee36f0SJeremy L Thompson CeedElemRestrictionCreate(ceed, num_elem_hex, p_hex * p_hex, dim, num_dofs, dim * num_dofs, CEED_MEM_HOST, CEED_USE_POINTER, ind_x_hex, 1174fee36f0SJeremy L Thompson &elem_restriction_x_hex); 1184fee36f0SJeremy L Thompson CeedElemRestrictionCreate(ceed, num_elem_hex, p_hex * p_hex, 1, 1, num_dofs, CEED_MEM_HOST, CEED_USE_POINTER, ind_x_hex, &elem_restriction_u_hex); 1192ebaca42Sjeremylt 1204fee36f0SJeremy L Thompson CeedInt strides_q_data_hex[3] = {1, q_hex * q_hex, q_hex * q_hex}; 1214fee36f0SJeremy L Thompson CeedElemRestrictionCreateStrided(ceed, num_elem_hex, q_hex * q_hex, 1, num_qpts_hex, strides_q_data_hex, &elem_restriction_q_data_hex); 1222ebaca42Sjeremylt 1232ebaca42Sjeremylt // -- Bases 1244fee36f0SJeremy L Thompson CeedBasisCreateTensorH1Lagrange(ceed, dim, dim, p_hex, q_hex, CEED_GAUSS, &basis_x_hex); 1254fee36f0SJeremy L Thompson CeedBasisCreateTensorH1Lagrange(ceed, dim, 1, p_hex, q_hex, CEED_GAUSS, &basis_u_hex); 1262ebaca42Sjeremylt 1272ebaca42Sjeremylt // -- QFunctions 128d1d35e2fSjeremylt CeedQFunctionCreateInterior(ceed, 1, setup, setup_loc, &qf_setup_hex); 129a61c78d6SJeremy L Thompson CeedQFunctionAddInput(qf_setup_hex, "weight", 1, CEED_EVAL_WEIGHT); 130d1d35e2fSjeremylt CeedQFunctionAddInput(qf_setup_hex, "dx", dim * dim, CEED_EVAL_GRAD); 131d1d35e2fSjeremylt CeedQFunctionAddOutput(qf_setup_hex, "rho", 1, CEED_EVAL_NONE); 1322ebaca42Sjeremylt 133d1d35e2fSjeremylt CeedQFunctionCreateInterior(ceed, 1, mass, mass_loc, &qf_mass_hex); 134d1d35e2fSjeremylt CeedQFunctionAddInput(qf_mass_hex, "rho", 1, CEED_EVAL_NONE); 135d1d35e2fSjeremylt CeedQFunctionAddInput(qf_mass_hex, "u", 1, CEED_EVAL_INTERP); 136d1d35e2fSjeremylt CeedQFunctionAddOutput(qf_mass_hex, "v", 1, CEED_EVAL_INTERP); 1372ebaca42Sjeremylt 1382ebaca42Sjeremylt // -- Operators 1392b730f8bSJeremy L Thompson CeedOperatorCreate(ceed, qf_setup_hex, CEED_QFUNCTION_NONE, CEED_QFUNCTION_NONE, &op_setup_hex); 1404fee36f0SJeremy L Thompson CeedOperatorSetName(op_setup_hex, "quadrilateral elements"); 1412b730f8bSJeremy L Thompson CeedOperatorSetField(op_setup_hex, "weight", CEED_ELEMRESTRICTION_NONE, basis_x_hex, CEED_VECTOR_NONE); 1424fee36f0SJeremy L Thompson CeedOperatorSetField(op_setup_hex, "dx", elem_restriction_x_hex, basis_x_hex, CEED_VECTOR_ACTIVE); 143*356036faSJeremy L Thompson CeedOperatorSetField(op_setup_hex, "rho", elem_restriction_q_data_hex, CEED_BASIS_NONE, q_data_hex); 1442ebaca42Sjeremylt 1452b730f8bSJeremy L Thompson CeedOperatorCreate(ceed, qf_mass_hex, CEED_QFUNCTION_NONE, CEED_QFUNCTION_NONE, &op_mass_hex); 1464fee36f0SJeremy L Thompson CeedOperatorSetName(op_mass_hex, "quadrilateral elements"); 147*356036faSJeremy L Thompson CeedOperatorSetField(op_mass_hex, "rho", elem_restriction_q_data_hex, CEED_BASIS_NONE, q_data_hex); 1484fee36f0SJeremy L Thompson CeedOperatorSetField(op_mass_hex, "u", elem_restriction_u_hex, basis_u_hex, CEED_VECTOR_ACTIVE); 1494fee36f0SJeremy L Thompson CeedOperatorSetField(op_mass_hex, "v", elem_restriction_u_hex, basis_u_hex, CEED_VECTOR_ACTIVE); 1502ebaca42Sjeremylt 1512ebaca42Sjeremylt // Set up Composite Operators 1522ebaca42Sjeremylt // -- Create 1532ebaca42Sjeremylt CeedCompositeOperatorCreate(ceed, &op_setup); 154ea6b5821SJeremy L Thompson CeedOperatorSetName(op_setup, "setup"); 1552ebaca42Sjeremylt // -- Add SubOperators 156d1d35e2fSjeremylt CeedCompositeOperatorAddSub(op_setup, op_setup_tet); 157d1d35e2fSjeremylt CeedCompositeOperatorAddSub(op_setup, op_setup_hex); 1582ebaca42Sjeremylt 1592ebaca42Sjeremylt // -- Create 1602ebaca42Sjeremylt CeedCompositeOperatorCreate(ceed, &op_mass); 161ea6b5821SJeremy L Thompson CeedOperatorSetName(op_mass, "mass"); 1622ebaca42Sjeremylt // -- Add SubOperators 163d1d35e2fSjeremylt CeedCompositeOperatorAddSub(op_mass, op_mass_tet); 164d1d35e2fSjeremylt CeedCompositeOperatorAddSub(op_mass, op_mass_hex); 1652ebaca42Sjeremylt 1662ebaca42Sjeremylt // View 1672ebaca42Sjeremylt CeedOperatorView(op_setup, stdout); 1682ebaca42Sjeremylt CeedOperatorView(op_mass, stdout); 1692ebaca42Sjeremylt 1702ebaca42Sjeremylt // Cleanup 1714fee36f0SJeremy L Thompson CeedVectorDestroy(&x); 1724fee36f0SJeremy L Thompson CeedVectorDestroy(&q_data_tet); 1734fee36f0SJeremy L Thompson CeedVectorDestroy(&q_data_hex); 1744fee36f0SJeremy L Thompson CeedElemRestrictionDestroy(&elem_restriction_u_tet); 1754fee36f0SJeremy L Thompson CeedElemRestrictionDestroy(&elem_restriction_x_tet); 1764fee36f0SJeremy L Thompson CeedElemRestrictionDestroy(&elem_restr_qd_tet); 1774fee36f0SJeremy L Thompson CeedElemRestrictionDestroy(&elem_restriction_u_hex); 1784fee36f0SJeremy L Thompson CeedElemRestrictionDestroy(&elem_restriction_x_hex); 1794fee36f0SJeremy L Thompson CeedElemRestrictionDestroy(&elem_restriction_q_data_hex); 1804fee36f0SJeremy L Thompson CeedBasisDestroy(&basis_u_tet); 1814fee36f0SJeremy L Thompson CeedBasisDestroy(&basis_x_tet); 1824fee36f0SJeremy L Thompson CeedBasisDestroy(&basis_u_hex); 1834fee36f0SJeremy L Thompson CeedBasisDestroy(&basis_x_hex); 184d1d35e2fSjeremylt CeedQFunctionDestroy(&qf_setup_tet); 185d1d35e2fSjeremylt CeedQFunctionDestroy(&qf_mass_tet); 186d1d35e2fSjeremylt CeedOperatorDestroy(&op_setup_tet); 187d1d35e2fSjeremylt CeedOperatorDestroy(&op_mass_tet); 188d1d35e2fSjeremylt CeedQFunctionDestroy(&qf_setup_hex); 189d1d35e2fSjeremylt CeedQFunctionDestroy(&qf_mass_hex); 190d1d35e2fSjeremylt CeedOperatorDestroy(&op_setup_hex); 191d1d35e2fSjeremylt CeedOperatorDestroy(&op_mass_hex); 1922ebaca42Sjeremylt CeedOperatorDestroy(&op_setup); 1932ebaca42Sjeremylt CeedOperatorDestroy(&op_mass); 1942ebaca42Sjeremylt CeedDestroy(&ceed); 1952ebaca42Sjeremylt return 0; 1962ebaca42Sjeremylt } 197