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. 321617c04Sjeremylt // 43d8e8822SJeremy L Thompson // SPDX-License-Identifier: BSD-2-Clause 521617c04Sjeremylt // 63d8e8822SJeremy L Thompson // This file is part of CEED: http://github.com/ceed 721617c04Sjeremylt 849aac155SJeremy L Thompson #include <ceed.h> 9ec3da8bcSJed Brown #include <ceed/backend.h> 103d576824SJeremy L Thompson #include <math.h> 113d576824SJeremy L Thompson #include <stdbool.h> 123d576824SJeremy L Thompson #include <string.h> 132b730f8bSJeremy L Thompson 1421617c04Sjeremylt #include "ceed-ref.h" 1521617c04Sjeremylt 16f10650afSjeremylt //------------------------------------------------------------------------------ 17f10650afSjeremylt // Basis Apply 18f10650afSjeremylt //------------------------------------------------------------------------------ 192b730f8bSJeremy L Thompson static int CeedBasisApply_Ref(CeedBasis basis, CeedInt num_elem, CeedTransposeMode t_mode, CeedEvalMode eval_mode, CeedVector U, CeedVector V) { 204ce2993fSjeremylt Ceed ceed; 212b730f8bSJeremy L Thompson CeedCallBackend(CeedBasisGetCeed(basis, &ceed)); 22c4e3f59bSSebastian Grimberg CeedInt dim, num_comp, q_comp, num_nodes, num_qpts; 232b730f8bSJeremy L Thompson CeedCallBackend(CeedBasisGetDimension(basis, &dim)); 242b730f8bSJeremy L Thompson CeedCallBackend(CeedBasisGetNumComponents(basis, &num_comp)); 25c4e3f59bSSebastian Grimberg CeedCallBackend(CeedBasisGetNumQuadratureComponents(basis, eval_mode, &q_comp)); 262b730f8bSJeremy L Thompson CeedCallBackend(CeedBasisGetNumNodes(basis, &num_nodes)); 272b730f8bSJeremy L Thompson CeedCallBackend(CeedBasisGetNumQuadraturePoints(basis, &num_qpts)); 282f86a920SJeremy L Thompson CeedTensorContract contract; 292b730f8bSJeremy L Thompson CeedCallBackend(CeedBasisGetTensorContract(basis, &contract)); 30d1d35e2fSjeremylt const CeedInt add = (t_mode == CEED_TRANSPOSE); 31aedaa0e5Sjeremylt const CeedScalar *u; 32aedaa0e5Sjeremylt CeedScalar *v; 336574a04fSJeremy L Thompson if (U != CEED_VECTOR_NONE) CeedCallBackend(CeedVectorGetArrayRead(U, CEED_MEM_HOST, &u)); 346574a04fSJeremy L Thompson else CeedCheck(eval_mode == CEED_EVAL_WEIGHT, ceed, CEED_ERROR_BACKEND, "An input vector is required for this CeedEvalMode"); 352b730f8bSJeremy L Thompson CeedCallBackend(CeedVectorGetArrayWrite(V, CEED_MEM_HOST, &v)); 3621617c04Sjeremylt 378d94b059Sjeremylt // Clear v if operating in transpose 38d1d35e2fSjeremylt if (t_mode == CEED_TRANSPOSE) { 39d1d35e2fSjeremylt const CeedInt v_size = num_elem * num_comp * num_nodes; 402b730f8bSJeremy L Thompson for (CeedInt i = 0; i < v_size; i++) v[i] = (CeedScalar)0.0; 4121617c04Sjeremylt } 426402da51SJeremy L Thompson bool is_tensor_basis; 436402da51SJeremy L Thompson CeedCallBackend(CeedBasisIsTensor(basis, &is_tensor_basis)); 446402da51SJeremy L Thompson if (is_tensor_basis) { 45c4e3f59bSSebastian Grimberg // Tensor basis 46d1d35e2fSjeremylt CeedInt P_1d, Q_1d; 472b730f8bSJeremy L Thompson CeedCallBackend(CeedBasisGetNumNodes1D(basis, &P_1d)); 482b730f8bSJeremy L Thompson CeedCallBackend(CeedBasisGetNumQuadraturePoints1D(basis, &Q_1d)); 49d1d35e2fSjeremylt switch (eval_mode) { 508d94b059Sjeremylt // Interpolate to/from quadrature points 51a2b73c81Sjeremylt case CEED_EVAL_INTERP: { 52dfe03796SJeremy L Thompson CeedBasis_Ref *impl; 532b730f8bSJeremy L Thompson CeedCallBackend(CeedBasisGetData(basis, &impl)); 548c1105f8SJeremy L Thompson if (impl->has_collo_interp) { 55d1d35e2fSjeremylt memcpy(v, u, num_elem * num_comp * num_nodes * sizeof(u[0])); 56dfe03796SJeremy L Thompson } else { 57d1d35e2fSjeremylt CeedInt P = P_1d, Q = Q_1d; 58d1d35e2fSjeremylt if (t_mode == CEED_TRANSPOSE) { 592b730f8bSJeremy L Thompson P = Q_1d; 602b730f8bSJeremy L Thompson Q = P_1d; 6121617c04Sjeremylt } 62d1d35e2fSjeremylt CeedInt pre = num_comp * CeedIntPow(P, dim - 1), post = num_elem; 63d1d35e2fSjeremylt CeedScalar tmp[2][num_elem * num_comp * Q * CeedIntPow(P > Q ? P : Q, dim - 1)]; 64d1d35e2fSjeremylt const CeedScalar *interp_1d; 652b730f8bSJeremy L Thompson CeedCallBackend(CeedBasisGetInterp1D(basis, &interp_1d)); 6621617c04Sjeremylt for (CeedInt d = 0; d < dim; d++) { 672b730f8bSJeremy L Thompson CeedCallBackend(CeedTensorContractApply(contract, pre, P, post, Q, interp_1d, t_mode, add && (d == dim - 1), d == 0 ? u : tmp[d % 2], 682b730f8bSJeremy L Thompson d == dim - 1 ? v : tmp[(d + 1) % 2])); 6921617c04Sjeremylt pre /= P; 7021617c04Sjeremylt post *= Q; 7121617c04Sjeremylt } 72dfe03796SJeremy L Thompson } 73a2b73c81Sjeremylt } break; 748d94b059Sjeremylt // Evaluate the gradient to/from quadrature points 75a2b73c81Sjeremylt case CEED_EVAL_GRAD: { 7621617c04Sjeremylt // In CEED_NOTRANSPOSE mode: 77d1d35e2fSjeremylt // u has shape [dim, num_comp, P^dim, num_elem], row-major layout 78d1d35e2fSjeremylt // v has shape [dim, num_comp, Q^dim, num_elem], row-major layout 7921617c04Sjeremylt // In CEED_TRANSPOSE mode, the sizes of u and v are switched. 80d1d35e2fSjeremylt CeedInt P = P_1d, Q = Q_1d; 81d1d35e2fSjeremylt if (t_mode == CEED_TRANSPOSE) { 82*1c66c397SJeremy L Thompson P = Q_1d; 83*1c66c397SJeremy L Thompson Q = Q_1d; 8421617c04Sjeremylt } 8584a01de5SJeremy L Thompson CeedBasis_Ref *impl; 862b730f8bSJeremy L Thompson CeedCallBackend(CeedBasisGetData(basis, &impl)); 87d1d35e2fSjeremylt CeedInt pre = num_comp * CeedIntPow(P, dim - 1), post = num_elem; 88d1d35e2fSjeremylt const CeedScalar *interp_1d; 892b730f8bSJeremy L Thompson CeedCallBackend(CeedBasisGetInterp1D(basis, &interp_1d)); 908c1105f8SJeremy L Thompson if (impl->collo_grad_1d) { 91d1d35e2fSjeremylt CeedScalar tmp[2][num_elem * num_comp * Q * CeedIntPow(P > Q ? P : Q, dim - 1)]; 92d1d35e2fSjeremylt CeedScalar interp[num_elem * num_comp * Q * CeedIntPow(P > Q ? P : Q, dim - 1)]; 9384a01de5SJeremy L Thompson // Interpolate to quadrature points (NoTranspose) 9484a01de5SJeremy L Thompson // or Grad to quadrature points (Transpose) 9521617c04Sjeremylt for (CeedInt d = 0; d < dim; d++) { 962b730f8bSJeremy L Thompson CeedCallBackend(CeedTensorContractApply(contract, pre, P, post, Q, (t_mode == CEED_NOTRANSPOSE ? interp_1d : impl->collo_grad_1d), t_mode, 972b730f8bSJeremy L Thompson add && (d > 0), 982b730f8bSJeremy L Thompson (t_mode == CEED_NOTRANSPOSE ? (d == 0 ? u : tmp[d % 2]) : u + d * num_qpts * num_comp * num_elem), 992b730f8bSJeremy L Thompson (t_mode == CEED_NOTRANSPOSE ? (d == dim - 1 ? interp : tmp[(d + 1) % 2]) : interp))); 10021617c04Sjeremylt pre /= P; 10121617c04Sjeremylt post *= Q; 10221617c04Sjeremylt } 10384a01de5SJeremy L Thompson // Grad to quadrature points (NoTranspose) 1048795c945Sjeremylt // or Interpolate to nodes (Transpose) 105d1d35e2fSjeremylt P = Q_1d, Q = Q_1d; 106d1d35e2fSjeremylt if (t_mode == CEED_TRANSPOSE) { 107*1c66c397SJeremy L Thompson P = Q_1d; 108*1c66c397SJeremy L Thompson Q = P_1d; 10984a01de5SJeremy L Thompson } 110d1d35e2fSjeremylt pre = num_comp * CeedIntPow(P, dim - 1), post = num_elem; 11184a01de5SJeremy L Thompson for (CeedInt d = 0; d < dim; d++) { 1122b730f8bSJeremy L Thompson CeedCallBackend(CeedTensorContractApply( 1132b730f8bSJeremy L Thompson contract, pre, P, post, Q, (t_mode == CEED_NOTRANSPOSE ? impl->collo_grad_1d : interp_1d), t_mode, add && (d == dim - 1), 1142b730f8bSJeremy L Thompson (t_mode == CEED_NOTRANSPOSE ? interp : (d == 0 ? interp : tmp[d % 2])), 1152b730f8bSJeremy L Thompson (t_mode == CEED_NOTRANSPOSE ? v + d * num_qpts * num_comp * num_elem : (d == dim - 1 ? v : tmp[(d + 1) % 2])))); 11684a01de5SJeremy L Thompson pre /= P; 11784a01de5SJeremy L Thompson post *= Q; 11821617c04Sjeremylt } 1198c1105f8SJeremy L Thompson } else if (impl->has_collo_interp) { // Qpts collocated with nodes 120d1d35e2fSjeremylt const CeedScalar *grad_1d; 1212b730f8bSJeremy L Thompson CeedCallBackend(CeedBasisGetGrad1D(basis, &grad_1d)); 122dfe03796SJeremy L Thompson 123dfe03796SJeremy L Thompson // Dim contractions, identity in other directions 124d1d35e2fSjeremylt CeedInt pre = num_comp * CeedIntPow(P, dim - 1), post = num_elem; 125c6158135Sjeremylt for (CeedInt d = 0; d < dim; d++) { 1262b730f8bSJeremy L Thompson CeedCallBackend(CeedTensorContractApply(contract, pre, P, post, Q, grad_1d, t_mode, add && (d > 0), 1272b730f8bSJeremy L Thompson t_mode == CEED_NOTRANSPOSE ? u : u + d * num_comp * num_qpts * num_elem, 1282b730f8bSJeremy L Thompson t_mode == CEED_TRANSPOSE ? v : v + d * num_comp * num_qpts * num_elem)); 129c6158135Sjeremylt pre /= P; 130c6158135Sjeremylt post *= Q; 131dfe03796SJeremy L Thompson } 132a7bd39daSjeremylt } else { // Underintegration, P > Q 133d1d35e2fSjeremylt const CeedScalar *grad_1d; 1342b730f8bSJeremy L Thompson CeedCallBackend(CeedBasisGetGrad1D(basis, &grad_1d)); 135a7bd39daSjeremylt 136d1d35e2fSjeremylt if (t_mode == CEED_TRANSPOSE) { 137*1c66c397SJeremy L Thompson P = Q_1d; 138*1c66c397SJeremy L Thompson Q = P_1d; 139a7bd39daSjeremylt } 140d1d35e2fSjeremylt CeedScalar tmp[2][num_elem * num_comp * Q * CeedIntPow(P > Q ? P : Q, dim - 1)]; 141a7bd39daSjeremylt 142a7bd39daSjeremylt // Dim**2 contractions, apply grad when pass == dim 143a7bd39daSjeremylt for (CeedInt p = 0; p < dim; p++) { 144d1d35e2fSjeremylt CeedInt pre = num_comp * CeedIntPow(P, dim - 1), post = num_elem; 145a7bd39daSjeremylt for (CeedInt d = 0; d < dim; d++) { 1462b730f8bSJeremy L Thompson CeedCallBackend(CeedTensorContractApply( 1472b730f8bSJeremy L Thompson contract, pre, P, post, Q, (p == d) ? grad_1d : interp_1d, t_mode, add && (d == dim - 1), 1482b730f8bSJeremy L Thompson (d == 0 ? (t_mode == CEED_NOTRANSPOSE ? u : u + p * num_comp * num_qpts * num_elem) : tmp[d % 2]), 1492b730f8bSJeremy L Thompson (d == dim - 1 ? (t_mode == CEED_TRANSPOSE ? v : v + p * num_comp * num_qpts * num_elem) : tmp[(d + 1) % 2]))); 150a7bd39daSjeremylt pre /= P; 151a7bd39daSjeremylt post *= Q; 152a7bd39daSjeremylt } 153a7bd39daSjeremylt } 154a7bd39daSjeremylt } 155a2b73c81Sjeremylt } break; 1568d94b059Sjeremylt // Retrieve interpolation weights 157a2b73c81Sjeremylt case CEED_EVAL_WEIGHT: { 1586574a04fSJeremy L Thompson CeedCheck(t_mode == CEED_NOTRANSPOSE, ceed, CEED_ERROR_BACKEND, "CEED_EVAL_WEIGHT incompatible with CEED_TRANSPOSE"); 159d1d35e2fSjeremylt CeedInt Q = Q_1d; 160d1d35e2fSjeremylt const CeedScalar *q_weight_1d; 1612b730f8bSJeremy L Thompson CeedCallBackend(CeedBasisGetQWeights(basis, &q_weight_1d)); 16221617c04Sjeremylt for (CeedInt d = 0; d < dim; d++) { 163b5cf12eeSjeremylt CeedInt pre = CeedIntPow(Q, dim - d - 1), post = CeedIntPow(Q, d); 1642b730f8bSJeremy L Thompson for (CeedInt i = 0; i < pre; i++) { 1652b730f8bSJeremy L Thompson for (CeedInt j = 0; j < Q; j++) { 16684a01de5SJeremy L Thompson for (CeedInt k = 0; k < post; k++) { 1672b730f8bSJeremy L Thompson CeedScalar w = q_weight_1d[j] * (d == 0 ? 1 : v[((i * Q + j) * post + k) * num_elem]); 1682b730f8bSJeremy L Thompson for (CeedInt e = 0; e < num_elem; e++) v[((i * Q + j) * post + k) * num_elem + e] = w; 1692b730f8bSJeremy L Thompson } 1702b730f8bSJeremy L Thompson } 17184a01de5SJeremy L Thompson } 17221617c04Sjeremylt } 173a2b73c81Sjeremylt } break; 174c042f62fSJeremy L Thompson // LCOV_EXCL_START 1758d94b059Sjeremylt // Evaluate the divergence to/from the quadrature points 176a2b73c81Sjeremylt case CEED_EVAL_DIV: 177e15f9bd0SJeremy L Thompson return CeedError(ceed, CEED_ERROR_BACKEND, "CEED_EVAL_DIV not supported"); 1788d94b059Sjeremylt // Evaluate the curl to/from the quadrature points 179a2b73c81Sjeremylt case CEED_EVAL_CURL: 180e15f9bd0SJeremy L Thompson return CeedError(ceed, CEED_ERROR_BACKEND, "CEED_EVAL_CURL not supported"); 1818d94b059Sjeremylt // Take no action, BasisApply should not have been called 182a2b73c81Sjeremylt case CEED_EVAL_NONE: 1832b730f8bSJeremy L Thompson return CeedError(ceed, CEED_ERROR_BACKEND, "CEED_EVAL_NONE does not make sense in this context"); 184c042f62fSJeremy L Thompson // LCOV_EXCL_STOP 18521617c04Sjeremylt } 186a8de75f0Sjeremylt } else { 187a8de75f0Sjeremylt // Non-tensor basis 188c4e3f59bSSebastian Grimberg CeedInt P = num_nodes, Q = num_qpts; 189d1d35e2fSjeremylt switch (eval_mode) { 19084a01de5SJeremy L Thompson // Interpolate to/from quadrature points 191a8de75f0Sjeremylt case CEED_EVAL_INTERP: { 1926c58de82SJeremy L Thompson const CeedScalar *interp; 1932b730f8bSJeremy L Thompson CeedCallBackend(CeedBasisGetInterp(basis, &interp)); 194c4e3f59bSSebastian Grimberg CeedCallBackend(CeedTensorContractStridedApply(contract, num_comp, P, num_elem, q_comp, Q, interp, t_mode, add, u, v)); 1952b730f8bSJeremy L Thompson } break; 19684a01de5SJeremy L Thompson // Evaluate the gradient to/from quadrature points 197a8de75f0Sjeremylt case CEED_EVAL_GRAD: { 1986c58de82SJeremy L Thompson const CeedScalar *grad; 1992b730f8bSJeremy L Thompson CeedCallBackend(CeedBasisGetGrad(basis, &grad)); 200c4e3f59bSSebastian Grimberg CeedCallBackend(CeedTensorContractStridedApply(contract, num_comp, P, num_elem, q_comp, Q, grad, t_mode, add, u, v)); 201c4e3f59bSSebastian Grimberg } break; 202c4e3f59bSSebastian Grimberg // Evaluate the divergence to/from the quadrature points 203c4e3f59bSSebastian Grimberg case CEED_EVAL_DIV: { 204c4e3f59bSSebastian Grimberg const CeedScalar *div; 205c4e3f59bSSebastian Grimberg CeedCallBackend(CeedBasisGetDiv(basis, &div)); 206c4e3f59bSSebastian Grimberg CeedCallBackend(CeedTensorContractStridedApply(contract, num_comp, P, num_elem, q_comp, Q, div, t_mode, add, u, v)); 207c4e3f59bSSebastian Grimberg } break; 208c4e3f59bSSebastian Grimberg // Evaluate the curl to/from the quadrature points 209c4e3f59bSSebastian Grimberg case CEED_EVAL_CURL: { 210c4e3f59bSSebastian Grimberg const CeedScalar *curl; 211c4e3f59bSSebastian Grimberg CeedCallBackend(CeedBasisGetCurl(basis, &curl)); 212c4e3f59bSSebastian Grimberg CeedCallBackend(CeedTensorContractStridedApply(contract, num_comp, P, num_elem, q_comp, Q, curl, t_mode, add, u, v)); 2132b730f8bSJeremy L Thompson } break; 21484a01de5SJeremy L Thompson // Retrieve interpolation weights 215a8de75f0Sjeremylt case CEED_EVAL_WEIGHT: { 2166574a04fSJeremy L Thompson CeedCheck(t_mode == CEED_NOTRANSPOSE, ceed, CEED_ERROR_BACKEND, "CEED_EVAL_WEIGHT incompatible with CEED_TRANSPOSE"); 217d1d35e2fSjeremylt const CeedScalar *q_weight; 2182b730f8bSJeremy L Thompson CeedCallBackend(CeedBasisGetQWeights(basis, &q_weight)); 2192b730f8bSJeremy L Thompson for (CeedInt i = 0; i < num_qpts; i++) { 2202b730f8bSJeremy L Thompson for (CeedInt e = 0; e < num_elem; e++) v[i * num_elem + e] = q_weight[i]; 2212b730f8bSJeremy L Thompson } 222a8de75f0Sjeremylt } break; 22350c301a5SRezgar Shakeri // LCOV_EXCL_START 22484a01de5SJeremy L Thompson // Take no action, BasisApply should not have been called 225a8de75f0Sjeremylt case CEED_EVAL_NONE: 2262b730f8bSJeremy L Thompson return CeedError(ceed, CEED_ERROR_BACKEND, "CEED_EVAL_NONE does not make sense in this context"); 227c042f62fSJeremy L Thompson // LCOV_EXCL_STOP 228a8de75f0Sjeremylt } 229a8de75f0Sjeremylt } 230a7b7f929Sjeremylt if (U != CEED_VECTOR_NONE) { 2312b730f8bSJeremy L Thompson CeedCallBackend(CeedVectorRestoreArrayRead(U, &u)); 232aedaa0e5Sjeremylt } 2332b730f8bSJeremy L Thompson CeedCallBackend(CeedVectorRestoreArray(V, &v)); 23402f1ab5cSSebastian Grimberg 235e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 23621617c04Sjeremylt } 23721617c04Sjeremylt 238f10650afSjeremylt //------------------------------------------------------------------------------ 239b2165e7aSSebastian Grimberg // Basis Destroy Tensor 240b2165e7aSSebastian Grimberg //------------------------------------------------------------------------------ 241b2165e7aSSebastian Grimberg static int CeedBasisDestroyTensor_Ref(CeedBasis basis) { 242b2165e7aSSebastian Grimberg CeedBasis_Ref *impl; 243b2165e7aSSebastian Grimberg CeedCallBackend(CeedBasisGetData(basis, &impl)); 244b2165e7aSSebastian Grimberg CeedCallBackend(CeedFree(&impl->collo_grad_1d)); 245b2165e7aSSebastian Grimberg CeedCallBackend(CeedFree(&impl)); 246b2165e7aSSebastian Grimberg 247b2165e7aSSebastian Grimberg return CEED_ERROR_SUCCESS; 248b2165e7aSSebastian Grimberg } 249b2165e7aSSebastian Grimberg 250b2165e7aSSebastian Grimberg //------------------------------------------------------------------------------ 251b2165e7aSSebastian Grimberg // Basis Create Tensor 252b2165e7aSSebastian Grimberg //------------------------------------------------------------------------------ 253b2165e7aSSebastian Grimberg int CeedBasisCreateTensorH1_Ref(CeedInt dim, CeedInt P_1d, CeedInt Q_1d, const CeedScalar *interp_1d, const CeedScalar *grad_1d, 254b2165e7aSSebastian Grimberg const CeedScalar *q_ref_1d, const CeedScalar *q_weight_1d, CeedBasis basis) { 255b2165e7aSSebastian Grimberg Ceed ceed; 256b2165e7aSSebastian Grimberg CeedCallBackend(CeedBasisGetCeed(basis, &ceed)); 257b2165e7aSSebastian Grimberg CeedBasis_Ref *impl; 258b2165e7aSSebastian Grimberg CeedCallBackend(CeedCalloc(1, &impl)); 259b2165e7aSSebastian Grimberg // Check for collocated interp 260b2165e7aSSebastian Grimberg if (Q_1d == P_1d) { 261b2165e7aSSebastian Grimberg bool collocated = 1; 262b2165e7aSSebastian Grimberg for (CeedInt i = 0; i < P_1d; i++) { 263b2165e7aSSebastian Grimberg collocated = collocated && (fabs(interp_1d[i + P_1d * i] - 1.0) < 1e-14); 264b2165e7aSSebastian Grimberg for (CeedInt j = 0; j < P_1d; j++) { 265b2165e7aSSebastian Grimberg if (j != i) collocated = collocated && (fabs(interp_1d[j + P_1d * i]) < 1e-14); 266b2165e7aSSebastian Grimberg } 267b2165e7aSSebastian Grimberg } 268b2165e7aSSebastian Grimberg impl->has_collo_interp = collocated; 269b2165e7aSSebastian Grimberg } 270b2165e7aSSebastian Grimberg // Calculate collocated grad 271b2165e7aSSebastian Grimberg if (Q_1d >= P_1d && !impl->has_collo_interp) { 272b2165e7aSSebastian Grimberg CeedCallBackend(CeedMalloc(Q_1d * Q_1d, &impl->collo_grad_1d)); 273b2165e7aSSebastian Grimberg CeedCallBackend(CeedBasisGetCollocatedGrad(basis, impl->collo_grad_1d)); 274b2165e7aSSebastian Grimberg } 275b2165e7aSSebastian Grimberg CeedCallBackend(CeedBasisSetData(basis, impl)); 276b2165e7aSSebastian Grimberg 277b2165e7aSSebastian Grimberg Ceed parent; 278b2165e7aSSebastian Grimberg CeedCallBackend(CeedGetParent(ceed, &parent)); 279b2165e7aSSebastian Grimberg CeedTensorContract contract; 280b2165e7aSSebastian Grimberg CeedCallBackend(CeedTensorContractCreate(parent, basis, &contract)); 281b2165e7aSSebastian Grimberg CeedCallBackend(CeedBasisSetTensorContract(basis, contract)); 282b2165e7aSSebastian Grimberg 283b2165e7aSSebastian Grimberg CeedCallBackend(CeedSetBackendFunction(ceed, "Basis", basis, "Apply", CeedBasisApply_Ref)); 284b2165e7aSSebastian Grimberg CeedCallBackend(CeedSetBackendFunction(ceed, "Basis", basis, "Destroy", CeedBasisDestroyTensor_Ref)); 285b2165e7aSSebastian Grimberg 286b2165e7aSSebastian Grimberg return CEED_ERROR_SUCCESS; 287b2165e7aSSebastian Grimberg } 288b2165e7aSSebastian Grimberg 289b2165e7aSSebastian Grimberg //------------------------------------------------------------------------------ 29050c301a5SRezgar Shakeri // Basis Create Non-Tensor H^1 291f10650afSjeremylt //------------------------------------------------------------------------------ 2922b730f8bSJeremy L Thompson int CeedBasisCreateH1_Ref(CeedElemTopology topo, CeedInt dim, CeedInt num_nodes, CeedInt num_qpts, const CeedScalar *interp, const CeedScalar *grad, 2932b730f8bSJeremy L Thompson const CeedScalar *q_ref, const CeedScalar *q_weight, CeedBasis basis) { 294f10650afSjeremylt Ceed ceed; 2952b730f8bSJeremy L Thompson CeedCallBackend(CeedBasisGetCeed(basis, &ceed)); 296f10650afSjeremylt 297f10650afSjeremylt Ceed parent; 2982b730f8bSJeremy L Thompson CeedCallBackend(CeedGetParent(ceed, &parent)); 299f10650afSjeremylt CeedTensorContract contract; 3002b730f8bSJeremy L Thompson CeedCallBackend(CeedTensorContractCreate(parent, basis, &contract)); 3012b730f8bSJeremy L Thompson CeedCallBackend(CeedBasisSetTensorContract(basis, contract)); 302f10650afSjeremylt 3032b730f8bSJeremy L Thompson CeedCallBackend(CeedSetBackendFunction(ceed, "Basis", basis, "Apply", CeedBasisApply_Ref)); 304f10650afSjeremylt 305e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 306f10650afSjeremylt } 307f10650afSjeremylt 308f10650afSjeremylt //------------------------------------------------------------------------------ 30950c301a5SRezgar Shakeri // Basis Create Non-Tensor H(div) 31050c301a5SRezgar Shakeri //------------------------------------------------------------------------------ 3112b730f8bSJeremy L Thompson int CeedBasisCreateHdiv_Ref(CeedElemTopology topo, CeedInt dim, CeedInt num_nodes, CeedInt num_qpts, const CeedScalar *interp, const CeedScalar *div, 3122b730f8bSJeremy L Thompson const CeedScalar *q_ref, const CeedScalar *q_weight, CeedBasis basis) { 31350c301a5SRezgar Shakeri Ceed ceed; 3142b730f8bSJeremy L Thompson CeedCallBackend(CeedBasisGetCeed(basis, &ceed)); 31550c301a5SRezgar Shakeri 31650c301a5SRezgar Shakeri Ceed parent; 3172b730f8bSJeremy L Thompson CeedCallBackend(CeedGetParent(ceed, &parent)); 31850c301a5SRezgar Shakeri CeedTensorContract contract; 3192b730f8bSJeremy L Thompson CeedCallBackend(CeedTensorContractCreate(parent, basis, &contract)); 3202b730f8bSJeremy L Thompson CeedCallBackend(CeedBasisSetTensorContract(basis, contract)); 32150c301a5SRezgar Shakeri 3222b730f8bSJeremy L Thompson CeedCallBackend(CeedSetBackendFunction(ceed, "Basis", basis, "Apply", CeedBasisApply_Ref)); 32350c301a5SRezgar Shakeri 32450c301a5SRezgar Shakeri return CEED_ERROR_SUCCESS; 32550c301a5SRezgar Shakeri } 32650c301a5SRezgar Shakeri 32750c301a5SRezgar Shakeri //------------------------------------------------------------------------------ 328c4e3f59bSSebastian Grimberg // Basis Create Non-Tensor H(curl) 329c4e3f59bSSebastian Grimberg //------------------------------------------------------------------------------ 330c4e3f59bSSebastian Grimberg int CeedBasisCreateHcurl_Ref(CeedElemTopology topo, CeedInt dim, CeedInt num_nodes, CeedInt num_qpts, const CeedScalar *interp, 331c4e3f59bSSebastian Grimberg const CeedScalar *curl, const CeedScalar *q_ref, const CeedScalar *q_weight, CeedBasis basis) { 332c4e3f59bSSebastian Grimberg Ceed ceed; 333c4e3f59bSSebastian Grimberg CeedCallBackend(CeedBasisGetCeed(basis, &ceed)); 334c4e3f59bSSebastian Grimberg 335c4e3f59bSSebastian Grimberg Ceed parent; 336c4e3f59bSSebastian Grimberg CeedCallBackend(CeedGetParent(ceed, &parent)); 337c4e3f59bSSebastian Grimberg CeedTensorContract contract; 338c4e3f59bSSebastian Grimberg CeedCallBackend(CeedTensorContractCreate(parent, basis, &contract)); 339c4e3f59bSSebastian Grimberg CeedCallBackend(CeedBasisSetTensorContract(basis, contract)); 340c4e3f59bSSebastian Grimberg 341c4e3f59bSSebastian Grimberg CeedCallBackend(CeedSetBackendFunction(ceed, "Basis", basis, "Apply", CeedBasisApply_Ref)); 342c4e3f59bSSebastian Grimberg 343c4e3f59bSSebastian Grimberg return CEED_ERROR_SUCCESS; 344c4e3f59bSSebastian Grimberg } 345c4e3f59bSSebastian Grimberg 346c4e3f59bSSebastian Grimberg //------------------------------------------------------------------------------ 347