16e15d496SJeremy L Thompson /// @file 26e15d496SJeremy L Thompson /// Test FLOP estimation for composite mass matrix operator 36e15d496SJeremy L Thompson /// \test Test FLOP estimation for composite mass matrix operator 46e15d496SJeremy L Thompson #include <ceed.h> 56e15d496SJeremy L Thompson #include <math.h> 62b730f8bSJeremy L Thompson #include <stdlib.h> 72b730f8bSJeremy L Thompson 86e15d496SJeremy L Thompson #include "t320-basis.h" 96e15d496SJeremy L Thompson 10*4fee36f0SJeremy L Thompson /* The mesh comprises of two rows of 3 quadrilaterals followed by one row 116e15d496SJeremy L Thompson of 6 triangles: 126e15d496SJeremy L Thompson _ _ _ 136e15d496SJeremy L Thompson |_|_|_| 146e15d496SJeremy L Thompson |_|_|_| 156e15d496SJeremy L Thompson |/|/|/| 166e15d496SJeremy L Thompson 176e15d496SJeremy L Thompson */ 186e15d496SJeremy L Thompson 196e15d496SJeremy L Thompson int main(int argc, char **argv) { 206e15d496SJeremy L Thompson Ceed ceed; 219d36ca50SJeremy L Thompson CeedSize flop_estimate; 22*4fee36f0SJeremy L Thompson CeedElemRestriction elem_restriction_x_tet, elem_restriction_u_tet, elem_restriction_q_data_tet, elem_restriction_x_hex, elem_restriction_u_hex, 23*4fee36f0SJeremy L Thompson elem_restriction_q_data_hex; 242b730f8bSJeremy L Thompson CeedBasis basis_x_tet, basis_u_tet, basis_x_hex, basis_u_hex; 256e15d496SJeremy L Thompson CeedQFunction qf_mass; 266e15d496SJeremy L Thompson CeedOperator op_mass_tet, op_mass_hex, op_mass; 276e15d496SJeremy L Thompson CeedVector q_data_tet, q_data_hex; 28*4fee36f0SJeremy 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; 292b730f8bSJeremy L Thompson CeedInt n_x = 3, n_y = 3, n_x_tet = 3, n_y_tet = 1, n_x_hex = 3; 306e15d496SJeremy L Thompson CeedInt row, col, offset; 31*4fee36f0SJeremy L Thompson CeedInt num_dofs = (n_x * 2 + 1) * (n_y * 2 + 1), num_qpts_tet = num_elem_tet * q_tet, num_qpts_hex = num_elem_hex * q_hex * q_hex; 32*4fee36f0SJeremy L Thompson CeedInt ind_x_tet[num_elem_tet * p_tet], ind_x_hex[num_elem_hex * p_hex * p_hex]; 33*4fee36f0SJeremy L Thompson CeedScalar q_ref[dim * q_tet], q_weight[q_tet]; 34*4fee36f0SJeremy L Thompson CeedScalar interp[p_tet * q_tet], grad[dim * p_tet * q_tet]; 356e15d496SJeremy L Thompson 366e15d496SJeremy L Thompson CeedInit(argv[1], &ceed); 376e15d496SJeremy L Thompson 386e15d496SJeremy L Thompson // Qdata Vectors 396e15d496SJeremy L Thompson CeedVectorCreate(ceed, num_qpts_tet, &q_data_tet); 406e15d496SJeremy L Thompson CeedVectorCreate(ceed, num_qpts_hex, &q_data_hex); 416e15d496SJeremy L Thompson 426e15d496SJeremy L Thompson // Set up Tet Elements 43*4fee36f0SJeremy L Thompson // -- Restrictions 446e15d496SJeremy L Thompson for (CeedInt i = 0; i < num_elem_tet / 2; i++) { 456e15d496SJeremy L Thompson col = i % n_x_tet; 466e15d496SJeremy L Thompson row = i / n_x_tet; 476e15d496SJeremy L Thompson offset = col * 2 + row * (n_x_tet * 2 + 1) * 2; 486e15d496SJeremy L Thompson 49*4fee36f0SJeremy L Thompson ind_x_tet[i * 2 * p_tet + 0] = 2 + offset; 50*4fee36f0SJeremy L Thompson ind_x_tet[i * 2 * p_tet + 1] = 9 + offset; 51*4fee36f0SJeremy L Thompson ind_x_tet[i * 2 * p_tet + 2] = 16 + offset; 52*4fee36f0SJeremy L Thompson ind_x_tet[i * 2 * p_tet + 3] = 1 + offset; 53*4fee36f0SJeremy L Thompson ind_x_tet[i * 2 * p_tet + 4] = 8 + offset; 54*4fee36f0SJeremy L Thompson ind_x_tet[i * 2 * p_tet + 5] = 0 + offset; 556e15d496SJeremy L Thompson 56*4fee36f0SJeremy L Thompson ind_x_tet[i * 2 * p_tet + 6] = 14 + offset; 57*4fee36f0SJeremy L Thompson ind_x_tet[i * 2 * p_tet + 7] = 7 + offset; 58*4fee36f0SJeremy L Thompson ind_x_tet[i * 2 * p_tet + 8] = 0 + offset; 59*4fee36f0SJeremy L Thompson ind_x_tet[i * 2 * p_tet + 9] = 15 + offset; 60*4fee36f0SJeremy L Thompson ind_x_tet[i * 2 * p_tet + 10] = 8 + offset; 61*4fee36f0SJeremy L Thompson ind_x_tet[i * 2 * p_tet + 11] = 16 + offset; 626e15d496SJeremy L Thompson } 63*4fee36f0SJeremy L Thompson CeedElemRestrictionCreate(ceed, num_elem_tet, p_tet, dim, num_dofs, dim * num_dofs, CEED_MEM_HOST, CEED_USE_POINTER, ind_x_tet, 64*4fee36f0SJeremy L Thompson &elem_restriction_x_tet); 65*4fee36f0SJeremy 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); 666e15d496SJeremy L Thompson 67*4fee36f0SJeremy L Thompson CeedInt strides_q_data_tet[3] = {1, q_tet, q_tet}; 68*4fee36f0SJeremy L Thompson CeedElemRestrictionCreateStrided(ceed, num_elem_tet, q_tet, 1, num_qpts_tet, strides_q_data_tet, &elem_restriction_q_data_tet); 696e15d496SJeremy L Thompson 706e15d496SJeremy L Thompson // -- Bases 71*4fee36f0SJeremy L Thompson Build2DSimplex(q_ref, q_weight, interp, grad); 72*4fee36f0SJeremy L Thompson CeedBasisCreateH1(ceed, CEED_TOPOLOGY_TRIANGLE, dim, p_tet, q_tet, interp, grad, q_ref, q_weight, &basis_x_tet); 736e15d496SJeremy L Thompson 74*4fee36f0SJeremy L Thompson Build2DSimplex(q_ref, q_weight, interp, grad); 75*4fee36f0SJeremy L Thompson CeedBasisCreateH1(ceed, CEED_TOPOLOGY_TRIANGLE, 1, p_tet, q_tet, interp, grad, q_ref, q_weight, &basis_u_tet); 766e15d496SJeremy L Thompson 776e15d496SJeremy L Thompson // -- QFunction 786e15d496SJeremy L Thompson CeedQFunctionCreateInteriorByName(ceed, "MassApply", &qf_mass); 796e15d496SJeremy L Thompson 806e15d496SJeremy L Thompson // -- Operators 816e15d496SJeremy L Thompson // ---- Mass Tet 822b730f8bSJeremy L Thompson CeedOperatorCreate(ceed, qf_mass, CEED_QFUNCTION_NONE, CEED_QFUNCTION_NONE, &op_mass_tet); 83*4fee36f0SJeremy L Thompson CeedOperatorSetField(op_mass_tet, "u", elem_restriction_u_tet, basis_u_tet, CEED_VECTOR_ACTIVE); 84*4fee36f0SJeremy L Thompson CeedOperatorSetField(op_mass_tet, "qdata", elem_restriction_q_data_tet, CEED_BASIS_COLLOCATED, q_data_tet); 85*4fee36f0SJeremy L Thompson CeedOperatorSetField(op_mass_tet, "v", elem_restriction_u_tet, basis_u_tet, CEED_VECTOR_ACTIVE); 866e15d496SJeremy L Thompson 876e15d496SJeremy L Thompson // Set up Hex Elements 88*4fee36f0SJeremy L Thompson // -- Restrictions 896e15d496SJeremy L Thompson for (CeedInt i = 0; i < num_elem_hex; i++) { 906e15d496SJeremy L Thompson col = i % n_x_hex; 916e15d496SJeremy L Thompson row = i / n_x_hex; 926e15d496SJeremy L Thompson offset = (n_x_tet * 2 + 1) * (n_y_tet * 2) * (1 + row) + col * 2; 93*4fee36f0SJeremy L Thompson for (CeedInt j = 0; j < p_hex; j++) { 94*4fee36f0SJeremy L Thompson for (CeedInt k = 0; k < p_hex; k++) ind_x_hex[p_hex * (p_hex * i + k) + j] = offset + k * (n_x_hex * 2 + 1) + j; 952b730f8bSJeremy L Thompson } 966e15d496SJeremy L Thompson } 97*4fee36f0SJeremy 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, 98*4fee36f0SJeremy L Thompson &elem_restriction_x_hex); 99*4fee36f0SJeremy 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); 1006e15d496SJeremy L Thompson 101*4fee36f0SJeremy L Thompson CeedInt strides_q_data_hex[3] = {1, q_hex * q_hex, q_hex * q_hex}; 102*4fee36f0SJeremy L Thompson CeedElemRestrictionCreateStrided(ceed, num_elem_hex, q_hex * q_hex, 1, num_qpts_hex, strides_q_data_hex, &elem_restriction_q_data_hex); 1036e15d496SJeremy L Thompson 1046e15d496SJeremy L Thompson // -- Bases 105*4fee36f0SJeremy L Thompson CeedBasisCreateTensorH1Lagrange(ceed, dim, dim, p_hex, q_hex, CEED_GAUSS, &basis_x_hex); 106*4fee36f0SJeremy L Thompson CeedBasisCreateTensorH1Lagrange(ceed, dim, 1, p_hex, q_hex, CEED_GAUSS, &basis_u_hex); 1076e15d496SJeremy L Thompson 1086e15d496SJeremy L Thompson // -- Operators 1092b730f8bSJeremy L Thompson CeedOperatorCreate(ceed, qf_mass, CEED_QFUNCTION_NONE, CEED_QFUNCTION_NONE, &op_mass_hex); 110*4fee36f0SJeremy L Thompson CeedOperatorSetField(op_mass_hex, "u", elem_restriction_u_hex, basis_u_hex, CEED_VECTOR_ACTIVE); 111*4fee36f0SJeremy L Thompson CeedOperatorSetField(op_mass_hex, "qdata", elem_restriction_q_data_hex, CEED_BASIS_COLLOCATED, q_data_hex); 112*4fee36f0SJeremy L Thompson CeedOperatorSetField(op_mass_hex, "v", elem_restriction_u_hex, basis_u_hex, CEED_VECTOR_ACTIVE); 1136e15d496SJeremy L Thompson 1146e15d496SJeremy L Thompson // Set up Composite Operator 1156e15d496SJeremy L Thompson // -- Create 1166e15d496SJeremy L Thompson CeedCompositeOperatorCreate(ceed, &op_mass); 1176e15d496SJeremy L Thompson // -- Add SubOperators 1186e15d496SJeremy L Thompson CeedCompositeOperatorAddSub(op_mass, op_mass_tet); 1196e15d496SJeremy L Thompson CeedCompositeOperatorAddSub(op_mass, op_mass_hex); 1206e15d496SJeremy L Thompson 1216e15d496SJeremy L Thompson // Estimate FLOPs 1226e15d496SJeremy L Thompson CeedQFunctionSetUserFlopsEstimate(qf_mass, 1); 1236e15d496SJeremy L Thompson CeedOperatorGetFlopsEstimate(op_mass, &flop_estimate); 1246e15d496SJeremy L Thompson 1256e15d496SJeremy L Thompson // Check output 1262b730f8bSJeremy L Thompson if (flop_estimate != 3042) printf("Incorrect FLOP estimate computed, %ld != 3042\n", flop_estimate); 1276e15d496SJeremy L Thompson 1286e15d496SJeremy L Thompson // Cleanup 129*4fee36f0SJeremy L Thompson CeedVectorDestroy(&q_data_tet); 130*4fee36f0SJeremy L Thompson CeedVectorDestroy(&q_data_hex); 131*4fee36f0SJeremy L Thompson CeedElemRestrictionDestroy(&elem_restriction_u_tet); 132*4fee36f0SJeremy L Thompson CeedElemRestrictionDestroy(&elem_restriction_x_tet); 133*4fee36f0SJeremy L Thompson CeedElemRestrictionDestroy(&elem_restriction_q_data_tet); 134*4fee36f0SJeremy L Thompson CeedElemRestrictionDestroy(&elem_restriction_u_hex); 135*4fee36f0SJeremy L Thompson CeedElemRestrictionDestroy(&elem_restriction_x_hex); 136*4fee36f0SJeremy L Thompson CeedElemRestrictionDestroy(&elem_restriction_q_data_hex); 1376e15d496SJeremy L Thompson CeedBasisDestroy(&basis_u_tet); 1386e15d496SJeremy L Thompson CeedBasisDestroy(&basis_x_tet); 1396e15d496SJeremy L Thompson CeedBasisDestroy(&basis_u_hex); 1406e15d496SJeremy L Thompson CeedBasisDestroy(&basis_x_hex); 141*4fee36f0SJeremy L Thompson CeedQFunctionDestroy(&qf_mass); 142*4fee36f0SJeremy L Thompson CeedOperatorDestroy(&op_mass_tet); 143*4fee36f0SJeremy L Thompson CeedOperatorDestroy(&op_mass_hex); 144*4fee36f0SJeremy L Thompson CeedOperatorDestroy(&op_mass); 1456e15d496SJeremy L Thompson CeedDestroy(&ceed); 1466e15d496SJeremy L Thompson return 0; 1476e15d496SJeremy L Thompson } 148