xref: /libCEED/tests/t405-qfunction.h (revision c9c2c07970382857cc7b4a28d359710237b91a3e)
13d8e8822SJeremy L Thompson // Copyright (c) 2017-2022, Lawrence Livermore National Security, LLC and other CEED contributors.
23d8e8822SJeremy L Thompson // All Rights Reserved. See the top-level LICENSE and NOTICE files for details.
377841947SLeila Ghaffari //
43d8e8822SJeremy L Thompson // SPDX-License-Identifier: BSD-2-Clause
577841947SLeila Ghaffari //
63d8e8822SJeremy L Thompson // This file is part of CEED:  http://github.com/ceed
777841947SLeila Ghaffari 
8*c9c2c079SJeremy L Thompson #include <ceed.h>
9*c9c2c079SJeremy L Thompson 
1077841947SLeila Ghaffari CEED_QFUNCTION(setup)(void *ctx, const CeedInt Q,
1177841947SLeila Ghaffari                       const CeedScalar *const *in,
1277841947SLeila Ghaffari                       CeedScalar *const *out) {
1377841947SLeila Ghaffari   const CeedScalar *w = in[0];
1477841947SLeila Ghaffari   CeedScalar *q_data = out[0];
1577841947SLeila Ghaffari   for (CeedInt i=0; i<Q; i++) {
1677841947SLeila Ghaffari     q_data[i] = w[i];
1777841947SLeila Ghaffari   }
1877841947SLeila Ghaffari   return 0;
1977841947SLeila Ghaffari }
2077841947SLeila Ghaffari 
2177841947SLeila Ghaffari CEED_QFUNCTION_HELPER CeedScalar times_two(CeedScalar x) {
2277841947SLeila Ghaffari   return 2 * x;
2377841947SLeila Ghaffari }
2477841947SLeila Ghaffari 
2577841947SLeila Ghaffari CEED_QFUNCTION(mass)(void *ctx, const CeedInt Q, const CeedScalar *const *in,
2677841947SLeila Ghaffari                      CeedScalar *const *out) {
2777841947SLeila Ghaffari   const CeedScalar *q_data = in[0], *u = in[1];
2877841947SLeila Ghaffari   CeedScalar *v = out[0];
2977841947SLeila Ghaffari   for (CeedInt i=0; i<Q; i++) {
3077841947SLeila Ghaffari     v[i] = q_data[i] * times_two(u[i]);
3177841947SLeila Ghaffari   }
3277841947SLeila Ghaffari   return 0;
3377841947SLeila Ghaffari }
34