xref: /libCEED/tests/t320-basis.h (revision bdee0278611904727ee35fcc2d0d7c3bf83db4c4)
1 // Copyright (c) 2017-2026, Lawrence Livermore National Security, LLC and other CEED contributors.
2 // All Rights Reserved. See the top-level LICENSE and NOTICE files for details.
3 //
4 // SPDX-License-Identifier: BSD-2-Clause
5 //
6 // This file is part of CEED:  http://github.com/ceed
7 
8 #include <ceed.h>
9 
10 static void Build2DSimplex(CeedScalar *q_ref, CeedScalar *q_weight, CeedScalar *interp, CeedScalar *grad) {
11   CeedInt P = 6, Q = 4;
12 
13   q_ref[0]    = 0.2;
14   q_ref[1]    = 0.6;
15   q_ref[2]    = 1. / 3.;
16   q_ref[3]    = 0.2;
17   q_ref[4]    = 0.2;
18   q_ref[5]    = 0.2;
19   q_ref[6]    = 1. / 3.;
20   q_ref[7]    = 0.6;
21   q_weight[0] = 25. / 96.;
22   q_weight[1] = 25. / 96.;
23   q_weight[2] = -27. / 96.;
24   q_weight[3] = 25. / 96.;
25 
26   // Loop over quadrature points
27   for (int i = 0; i < Q; i++) {
28     CeedScalar x1 = q_ref[0 * Q + i], x2 = q_ref[1 * Q + i];
29     // Interp
30     interp[i * P + 0] = 2. * (x1 + x2 - 1.) * (x1 + x2 - 1. / 2.);
31     interp[i * P + 1] = -4. * x1 * (x1 + x2 - 1.);
32     interp[i * P + 2] = 2. * x1 * (x1 - 1. / 2.);
33     interp[i * P + 3] = -4. * x2 * (x1 + x2 - 1.);
34     interp[i * P + 4] = 4. * x1 * x2;
35     interp[i * P + 5] = 2. * x2 * (x2 - 1. / 2.);
36     // Grad
37     grad[(i + 0) * P + 0] = 2. * (1. * (x1 + x2 - 1. / 2.) + (x1 + x2 - 1.) * 1.);
38     grad[(i + Q) * P + 0] = 2. * (1. * (x1 + x2 - 1. / 2.) + (x1 + x2 - 1.) * 1.);
39     grad[(i + 0) * P + 1] = -4. * (1. * (x1 + x2 - 1.) + x1 * 1.);
40     grad[(i + Q) * P + 1] = -4. * (x1 * 1.);
41     grad[(i + 0) * P + 2] = 2. * (1. * (x1 - 1. / 2.) + x1 * 1.);
42     grad[(i + Q) * P + 2] = 2. * 0.;
43     grad[(i + 0) * P + 3] = -4. * (x2 * 1.);
44     grad[(i + Q) * P + 3] = -4. * (1. * (x1 + x2 - 1.) + x2 * 1.);
45     grad[(i + 0) * P + 4] = 4. * (1. * x2);
46     grad[(i + Q) * P + 4] = 4. * (x1 * 1.);
47     grad[(i + 0) * P + 5] = 2. * 0.;
48     grad[(i + Q) * P + 5] = 2. * (1. * (x2 - 1. / 2.) + x2 * 1.);
49   }
50 }
51