1*3f919cbcSJeremy L Thompson /// @file
2*3f919cbcSJeremy L Thompson /// Test FLOP estimation for mass matrix operator at points
3*3f919cbcSJeremy L Thompson /// \test Test FLOP estimation for mass matrix operator at points
4*3f919cbcSJeremy L Thompson #include "t595-operator.h"
5*3f919cbcSJeremy L Thompson
6*3f919cbcSJeremy L Thompson #include <ceed.h>
7*3f919cbcSJeremy L Thompson #include <math.h>
8*3f919cbcSJeremy L Thompson #include <stdio.h>
9*3f919cbcSJeremy L Thompson #include <stdlib.h>
10*3f919cbcSJeremy L Thompson
main(int argc,char ** argv)11*3f919cbcSJeremy L Thompson int main(int argc, char **argv) {
12*3f919cbcSJeremy L Thompson Ceed ceed;
13*3f919cbcSJeremy L Thompson CeedInt num_elem_1d = 3, num_elem = num_elem_1d * num_elem_1d, dim = 2, p = 3, q = 5;
14*3f919cbcSJeremy L Thompson CeedInt num_nodes = (num_elem_1d * (p - 1) + 1) * (num_elem_1d * (p - 1) + 1), num_points_per_elem = 4, num_points = num_elem * num_points_per_elem;
15*3f919cbcSJeremy L Thompson CeedSize flop_estimate = 0;
16*3f919cbcSJeremy L Thompson CeedVector x_points, q_data;
17*3f919cbcSJeremy L Thompson CeedElemRestriction elem_restriction_x_points, elem_restriction_q_data, elem_restriction_u;
18*3f919cbcSJeremy L Thompson CeedBasis basis_x, basis_u;
19*3f919cbcSJeremy L Thompson CeedQFunction qf_mass;
20*3f919cbcSJeremy L Thompson CeedOperator op_mass;
21*3f919cbcSJeremy L Thompson bool is_at_points;
22*3f919cbcSJeremy L Thompson
23*3f919cbcSJeremy L Thompson CeedInit(argv[1], &ceed);
24*3f919cbcSJeremy L Thompson
25*3f919cbcSJeremy L Thompson // Point reference coordinates
26*3f919cbcSJeremy L Thompson CeedVectorCreate(ceed, dim * num_points, &x_points);
27*3f919cbcSJeremy L Thompson {
28*3f919cbcSJeremy L Thompson CeedScalar x_array[dim * num_points];
29*3f919cbcSJeremy L Thompson
30*3f919cbcSJeremy L Thompson for (CeedInt e = 0; e < num_elem; e++) {
31*3f919cbcSJeremy L Thompson for (CeedInt d = 0; d < dim; d++) {
32*3f919cbcSJeremy L Thompson x_array[num_points_per_elem * (e * dim + d) + 0] = 0.25;
33*3f919cbcSJeremy L Thompson x_array[num_points_per_elem * (e * dim + d) + 1] = d == 0 ? -0.25 : 0.25;
34*3f919cbcSJeremy L Thompson x_array[num_points_per_elem * (e * dim + d) + 2] = d == 0 ? 0.25 : -0.25;
35*3f919cbcSJeremy L Thompson x_array[num_points_per_elem * (e * dim + d) + 3] = 0.25;
36*3f919cbcSJeremy L Thompson }
37*3f919cbcSJeremy L Thompson }
38*3f919cbcSJeremy L Thompson CeedVectorSetArray(x_points, CEED_MEM_HOST, CEED_COPY_VALUES, x_array);
39*3f919cbcSJeremy L Thompson }
40*3f919cbcSJeremy L Thompson {
41*3f919cbcSJeremy L Thompson CeedInt ind_x[num_elem + 1 + num_points];
42*3f919cbcSJeremy L Thompson
43*3f919cbcSJeremy L Thompson for (CeedInt i = 0; i <= num_elem; i++) ind_x[i] = num_elem + 1 + i * num_points_per_elem;
44*3f919cbcSJeremy L Thompson for (CeedInt i = 0; i < num_points; i++) ind_x[num_elem + 1 + i] = i;
45*3f919cbcSJeremy L Thompson CeedElemRestrictionCreateAtPoints(ceed, num_elem, num_points, dim, num_points * dim, CEED_MEM_HOST, CEED_COPY_VALUES, ind_x,
46*3f919cbcSJeremy L Thompson &elem_restriction_x_points);
47*3f919cbcSJeremy L Thompson CeedElemRestrictionCreateAtPoints(ceed, num_elem, num_points, 1, num_points, CEED_MEM_HOST, CEED_COPY_VALUES, ind_x, &elem_restriction_q_data);
48*3f919cbcSJeremy L Thompson }
49*3f919cbcSJeremy L Thompson
50*3f919cbcSJeremy L Thompson // Q data
51*3f919cbcSJeremy L Thompson CeedVectorCreate(ceed, num_points, &q_data);
52*3f919cbcSJeremy L Thompson
53*3f919cbcSJeremy L Thompson CeedBasisCreateTensorH1Lagrange(ceed, dim, dim, 2, q, CEED_GAUSS, &basis_x);
54*3f919cbcSJeremy L Thompson
55*3f919cbcSJeremy L Thompson // Cell solution
56*3f919cbcSJeremy L Thompson {
57*3f919cbcSJeremy L Thompson CeedInt ind_u[num_elem * p * p];
58*3f919cbcSJeremy L Thompson
59*3f919cbcSJeremy L Thompson for (CeedInt e = 0; e < num_elem; e++) {
60*3f919cbcSJeremy L Thompson CeedInt elem_xy[2] = {1, 1}, n_d[2] = {0, 0};
61*3f919cbcSJeremy L Thompson
62*3f919cbcSJeremy L Thompson for (CeedInt d = 0; d < dim; d++) n_d[d] = num_elem_1d * (p - 1) + 1;
63*3f919cbcSJeremy L Thompson {
64*3f919cbcSJeremy L Thompson CeedInt r_e = e;
65*3f919cbcSJeremy L Thompson
66*3f919cbcSJeremy L Thompson for (CeedInt d = 0; d < dim; d++) {
67*3f919cbcSJeremy L Thompson elem_xy[d] = r_e % num_elem_1d;
68*3f919cbcSJeremy L Thompson r_e /= num_elem_1d;
69*3f919cbcSJeremy L Thompson }
70*3f919cbcSJeremy L Thompson }
71*3f919cbcSJeremy L Thompson CeedInt num_nodes_in_elem = p * p, *elem_nodes = ind_u + e * num_nodes_in_elem;
72*3f919cbcSJeremy L Thompson
73*3f919cbcSJeremy L Thompson for (CeedInt n = 0; n < num_nodes_in_elem; n++) {
74*3f919cbcSJeremy L Thompson CeedInt g_node = 0, g_node_stride = 1, r_node = n;
75*3f919cbcSJeremy L Thompson
76*3f919cbcSJeremy L Thompson for (CeedInt d = 0; d < dim; d++) {
77*3f919cbcSJeremy L Thompson g_node += (elem_xy[d] * (p - 1) + r_node % p) * g_node_stride;
78*3f919cbcSJeremy L Thompson g_node_stride *= n_d[d];
79*3f919cbcSJeremy L Thompson r_node /= p;
80*3f919cbcSJeremy L Thompson }
81*3f919cbcSJeremy L Thompson elem_nodes[n] = g_node;
82*3f919cbcSJeremy L Thompson }
83*3f919cbcSJeremy L Thompson }
84*3f919cbcSJeremy L Thompson CeedElemRestrictionCreate(ceed, num_elem, p * p, 1, 1, num_nodes, CEED_MEM_HOST, CEED_COPY_VALUES, ind_u, &elem_restriction_u);
85*3f919cbcSJeremy L Thompson }
86*3f919cbcSJeremy L Thompson CeedBasisCreateTensorH1Lagrange(ceed, dim, 1, p, q, CEED_GAUSS, &basis_u);
87*3f919cbcSJeremy L Thompson
88*3f919cbcSJeremy L Thompson // Mass operator
89*3f919cbcSJeremy L Thompson CeedQFunctionCreateInterior(ceed, 1, mass, mass_loc, &qf_mass);
90*3f919cbcSJeremy L Thompson CeedQFunctionAddInput(qf_mass, "u", 1, CEED_EVAL_INTERP);
91*3f919cbcSJeremy L Thompson CeedQFunctionAddInput(qf_mass, "rho", 1, CEED_EVAL_NONE);
92*3f919cbcSJeremy L Thompson CeedQFunctionAddOutput(qf_mass, "v", 1, CEED_EVAL_INTERP);
93*3f919cbcSJeremy L Thompson
94*3f919cbcSJeremy L Thompson CeedOperatorCreateAtPoints(ceed, qf_mass, CEED_QFUNCTION_NONE, CEED_QFUNCTION_NONE, &op_mass);
95*3f919cbcSJeremy L Thompson CeedOperatorSetField(op_mass, "u", elem_restriction_u, basis_u, CEED_VECTOR_ACTIVE);
96*3f919cbcSJeremy L Thompson CeedOperatorSetField(op_mass, "rho", elem_restriction_q_data, CEED_BASIS_NONE, q_data);
97*3f919cbcSJeremy L Thompson CeedOperatorSetField(op_mass, "v", elem_restriction_u, basis_u, CEED_VECTOR_ACTIVE);
98*3f919cbcSJeremy L Thompson CeedOperatorAtPointsSetPoints(op_mass, elem_restriction_x_points, x_points);
99*3f919cbcSJeremy L Thompson
100*3f919cbcSJeremy L Thompson CeedOperatorIsAtPoints(op_mass, &is_at_points);
101*3f919cbcSJeremy L Thompson if (!is_at_points) printf("Error: Operator should be at points\n");
102*3f919cbcSJeremy L Thompson
103*3f919cbcSJeremy L Thompson // Estimate FLOPs
104*3f919cbcSJeremy L Thompson CeedQFunctionSetUserFlopsEstimate(qf_mass, 1);
105*3f919cbcSJeremy L Thompson CeedOperatorGetFlopsEstimate(op_mass, &flop_estimate);
106*3f919cbcSJeremy L Thompson
107*3f919cbcSJeremy L Thompson // Check output
108*3f919cbcSJeremy L Thompson if (flop_estimate != 16317) {
109*3f919cbcSJeremy L Thompson // LCOV_EXCL_START
110*3f919cbcSJeremy L Thompson printf("Incorrect FLOP estimate computed, %ld != 16317\n", flop_estimate);
111*3f919cbcSJeremy L Thompson // LCOV_EXCL_STOP
112*3f919cbcSJeremy L Thompson }
113*3f919cbcSJeremy L Thompson
114*3f919cbcSJeremy L Thompson CeedVectorDestroy(&x_points);
115*3f919cbcSJeremy L Thompson CeedVectorDestroy(&q_data);
116*3f919cbcSJeremy L Thompson CeedElemRestrictionDestroy(&elem_restriction_x_points);
117*3f919cbcSJeremy L Thompson CeedElemRestrictionDestroy(&elem_restriction_q_data);
118*3f919cbcSJeremy L Thompson CeedElemRestrictionDestroy(&elem_restriction_u);
119*3f919cbcSJeremy L Thompson CeedBasisDestroy(&basis_x);
120*3f919cbcSJeremy L Thompson CeedBasisDestroy(&basis_u);
121*3f919cbcSJeremy L Thompson CeedQFunctionDestroy(&qf_mass);
122*3f919cbcSJeremy L Thompson CeedOperatorDestroy(&op_mass);
123*3f919cbcSJeremy L Thompson CeedDestroy(&ceed);
124*3f919cbcSJeremy L Thompson return 0;
125*3f919cbcSJeremy L Thompson }
126