xref: /libCEED/tests/t566-operator.h (revision c9c2c07970382857cc7b4a28d359710237b91a3e)
1b8edc0e7SJeremy L Thompson // Copyright (c) 2017-2022, Lawrence Livermore National Security, LLC and other CEED contributors.
2b8edc0e7SJeremy L Thompson // All Rights Reserved. See the top-level LICENSE and NOTICE files for details.
3b8edc0e7SJeremy L Thompson //
4b8edc0e7SJeremy L Thompson // SPDX-License-Identifier: BSD-2-Clause
5b8edc0e7SJeremy L Thompson //
6b8edc0e7SJeremy L Thompson // This file is part of CEED:  http://github.com/ceed
7b8edc0e7SJeremy L Thompson 
8*c9c2c079SJeremy L Thompson #include <ceed.h>
9*c9c2c079SJeremy L Thompson 
10b8edc0e7SJeremy L Thompson CEED_QFUNCTION(setup)(void *ctx, const CeedInt Q,
11b8edc0e7SJeremy L Thompson                       const CeedScalar *const *in,
12b8edc0e7SJeremy L Thompson                       CeedScalar *const *out) {
13b8edc0e7SJeremy L Thompson   const CeedScalar *weight = in[0], *J = in[1];
14b8edc0e7SJeremy L Thompson   CeedScalar *rho = out[0];
15b8edc0e7SJeremy L Thompson   for (CeedInt i=0; i<Q; i++) {
16b8edc0e7SJeremy L Thompson     rho[i] = weight[i] * (J[i+Q*0]*J[i+Q*3] - J[i+Q*1]*J[i+Q*2]);
17b8edc0e7SJeremy L Thompson   }
18b8edc0e7SJeremy L Thompson   return 0;
19b8edc0e7SJeremy L Thompson }
20b8edc0e7SJeremy L Thompson 
21b8edc0e7SJeremy L Thompson CEED_QFUNCTION(mass)(void *ctx, const CeedInt Q, const CeedScalar *const *in,
22b8edc0e7SJeremy L Thompson                      CeedScalar *const *out) {
2310a06a06SJeremy L Thompson   // *INDENT-OFF*
2410a06a06SJeremy L Thompson   const CeedScalar (*q_data)             = (const CeedScalar(*))in[0],
2510a06a06SJeremy L Thompson                         (*u)[CEED_Q_VLA] = (const CeedScalar(*)[CEED_Q_VLA])in[1];
2610a06a06SJeremy L Thompson   CeedScalar            (*v)[CEED_Q_VLA] = (CeedScalar(*)[CEED_Q_VLA])out[0];
2710a06a06SJeremy L Thompson   // *INDENT-ON*
28b8edc0e7SJeremy L Thompson 
2910a06a06SJeremy L Thompson   const CeedScalar num_comp = 2;
30b8edc0e7SJeremy L Thompson   const CeedScalar scale[2][2] = {
31b8edc0e7SJeremy L Thompson     {1.0, 2.0},
32b8edc0e7SJeremy L Thompson     {3.0, 4.0},
33b8edc0e7SJeremy L Thompson   };
34b8edc0e7SJeremy L Thompson 
35b8edc0e7SJeremy L Thompson   for (CeedInt i = 0; i < Q; i++) {
3610a06a06SJeremy L Thompson     for (CeedInt c_out = 0; c_out < num_comp; c_out++) {
3710a06a06SJeremy L Thompson       v[c_out][i] = 0.0;
3810a06a06SJeremy L Thompson       for (CeedInt c_in = 0; c_in < num_comp; c_in++) {
3910a06a06SJeremy L Thompson         v[c_out][i] += q_data[i] * u[c_in][i] * scale[c_in][c_out];
40b8edc0e7SJeremy L Thompson       }
41b8edc0e7SJeremy L Thompson     }
42b8edc0e7SJeremy L Thompson   }
43b8edc0e7SJeremy L Thompson   return 0;
44b8edc0e7SJeremy L Thompson }
45