1b249f0c7SJeremy L Thompson /// @file 2b249f0c7SJeremy L Thompson /// Test creation, evaluation, and destruction for vector mass QFunction by name 3b249f0c7SJeremy L Thompson /// \test Test creation, evaluation, and destruction for vector mass QFunction by name 4b249f0c7SJeremy L Thompson #include <ceed.h> 5b249f0c7SJeremy L Thompson #include <math.h> 6b249f0c7SJeremy L Thompson #include <string.h> 7b249f0c7SJeremy L Thompson 8b249f0c7SJeremy L Thompson int main(int argc, char **argv) { 9b249f0c7SJeremy L Thompson Ceed ceed; 10b249f0c7SJeremy L Thompson CeedVector in[16], out[16]; 11*4fee36f0SJeremy L Thompson CeedVector q_data, dx, w, u, v; 12b249f0c7SJeremy L Thompson CeedQFunction qf_setup, qf_mass; 13*4fee36f0SJeremy L Thompson CeedInt q = 8; 14b249f0c7SJeremy L Thompson const CeedInt num_comp = 3; 15b249f0c7SJeremy L Thompson 16b249f0c7SJeremy L Thompson CeedInit(argv[1], &ceed); 17b249f0c7SJeremy L Thompson 18b249f0c7SJeremy L Thompson for (CeedInt dim = 2; dim <= 3; dim++) { 19*4fee36f0SJeremy L Thompson CeedInt num_qpts = CeedIntPow(q, dim); 20b249f0c7SJeremy L Thompson 21*4fee36f0SJeremy L Thompson CeedVectorCreate(ceed, num_qpts * dim * dim, &dx); 22*4fee36f0SJeremy L Thompson CeedVectorCreate(ceed, num_qpts, &w); 23*4fee36f0SJeremy L Thompson CeedVectorCreate(ceed, num_qpts * num_comp, &u); 24*4fee36f0SJeremy L Thompson { 25*4fee36f0SJeremy L Thompson CeedScalar dx_array[num_qpts * dim * dim], w_array[num_qpts], u_array[num_qpts * num_comp]; 26b249f0c7SJeremy L Thompson 27b249f0c7SJeremy L Thompson for (CeedInt i = 0; i < num_qpts; i++) { 28*4fee36f0SJeremy L Thompson w_array[i] = 1.0 / num_qpts; 29b249f0c7SJeremy L Thompson } 30b249f0c7SJeremy L Thompson for (CeedInt d = 0; d < dim; d++) { 31b249f0c7SJeremy L Thompson for (CeedInt g = 0; g < dim; g++) { 32b249f0c7SJeremy L Thompson for (CeedInt i = 0; i < num_qpts; i++) { 33*4fee36f0SJeremy L Thompson dx_array[i + (g * dim + d) * num_qpts] = d == g; 34b249f0c7SJeremy L Thompson } 35b249f0c7SJeremy L Thompson } 36b249f0c7SJeremy L Thompson } 37b249f0c7SJeremy L Thompson for (CeedInt c = 0; c < num_comp; c++) { 38b249f0c7SJeremy L Thompson for (CeedInt i = 0; i < num_qpts; i++) { 39*4fee36f0SJeremy L Thompson u_array[i + c * num_qpts] = c + 1; 40b249f0c7SJeremy L Thompson } 41b249f0c7SJeremy L Thompson } 42*4fee36f0SJeremy L Thompson CeedVectorSetArray(dx, CEED_MEM_HOST, CEED_COPY_VALUES, dx_array); 43*4fee36f0SJeremy L Thompson CeedVectorSetArray(w, CEED_MEM_HOST, CEED_COPY_VALUES, w_array); 44*4fee36f0SJeremy L Thompson CeedVectorSetArray(u, CEED_MEM_HOST, CEED_COPY_VALUES, u_array); 45*4fee36f0SJeremy L Thompson } 46*4fee36f0SJeremy L Thompson CeedVectorCreate(ceed, num_qpts, &q_data); 47*4fee36f0SJeremy L Thompson CeedVectorSetValue(q_data, 0.0); 48*4fee36f0SJeremy L Thompson CeedVectorCreate(ceed, num_qpts * num_comp, &v); 49*4fee36f0SJeremy L Thompson CeedVectorSetValue(v, 0.0); 50b249f0c7SJeremy L Thompson 51*4fee36f0SJeremy L Thompson char name[13] = ""; 52*4fee36f0SJeremy L Thompson snprintf(name, sizeof name, "Mass%" CeedInt_FMT "DBuild", dim); 53*4fee36f0SJeremy L Thompson CeedQFunctionCreateInteriorByName(ceed, name, &qf_setup); 54b249f0c7SJeremy L Thompson { 55*4fee36f0SJeremy L Thompson in[0] = dx; 56*4fee36f0SJeremy L Thompson in[1] = w; 57*4fee36f0SJeremy L Thompson out[0] = q_data; 58b249f0c7SJeremy L Thompson CeedQFunctionApply(qf_setup, num_qpts, in, out); 59b249f0c7SJeremy L Thompson } 60*4fee36f0SJeremy L Thompson 61*4fee36f0SJeremy L Thompson CeedQFunctionCreateInteriorByName(ceed, "Vector3MassApply", &qf_mass); 62b249f0c7SJeremy L Thompson { 63*4fee36f0SJeremy L Thompson in[0] = u; 64*4fee36f0SJeremy L Thompson in[1] = q_data; 65*4fee36f0SJeremy L Thompson out[0] = v; 66b249f0c7SJeremy L Thompson CeedQFunctionApply(qf_mass, num_qpts, in, out); 67b249f0c7SJeremy L Thompson } 68b249f0c7SJeremy L Thompson 69*4fee36f0SJeremy L Thompson // Verify results 70*4fee36f0SJeremy L Thompson { 71*4fee36f0SJeremy L Thompson const CeedScalar *v_array; 72*4fee36f0SJeremy L Thompson 73*4fee36f0SJeremy L Thompson CeedVectorGetArrayRead(v, CEED_MEM_HOST, &v_array); 74b249f0c7SJeremy L Thompson for (CeedInt c = 0; c < num_comp; c++) { 75b249f0c7SJeremy L Thompson CeedScalar sum = 0; 76*4fee36f0SJeremy L Thompson for (CeedInt i = 0; i < num_qpts; i++) sum += v_array[i + c * num_qpts]; 772b730f8bSJeremy L Thompson if (fabs(sum - (c + 1)) > 10 * CEED_EPSILON) { 78b249f0c7SJeremy L Thompson // LCOV_EXCL_START 792b730f8bSJeremy L Thompson printf("%" CeedInt_FMT "D volume error in component %" CeedInt_FMT ": %f != %f\n", dim, c, sum, (c + 1.0)); 80b249f0c7SJeremy L Thompson // LCOV_EXCL_STOP 81b249f0c7SJeremy L Thompson } 822b730f8bSJeremy L Thompson } 83*4fee36f0SJeremy L Thompson CeedVectorRestoreArrayRead(v, &v_array); 84*4fee36f0SJeremy L Thompson } 85b249f0c7SJeremy L Thompson 86*4fee36f0SJeremy L Thompson CeedVectorDestroy(&dx); 87*4fee36f0SJeremy L Thompson CeedVectorDestroy(&w); 88*4fee36f0SJeremy L Thompson CeedVectorDestroy(&u); 89*4fee36f0SJeremy L Thompson CeedVectorDestroy(&v); 90*4fee36f0SJeremy L Thompson CeedVectorDestroy(&q_data); 91b249f0c7SJeremy L Thompson CeedQFunctionDestroy(&qf_setup); 92b249f0c7SJeremy L Thompson CeedQFunctionDestroy(&qf_mass); 93b249f0c7SJeremy L Thompson } 94b249f0c7SJeremy L Thompson 95b249f0c7SJeremy L Thompson CeedDestroy(&ceed); 96b249f0c7SJeremy L Thompson return 0; 97b249f0c7SJeremy L Thompson } 98