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; 21ad70ee2cSJeremy L Thompson bool is_tensor_basis; 22c4e3f59bSSebastian Grimberg CeedInt dim, num_comp, q_comp, num_nodes, num_qpts; 23ad70ee2cSJeremy L Thompson const CeedInt add = (t_mode == CEED_TRANSPOSE); 24ad70ee2cSJeremy L Thompson const CeedScalar *u; 25ad70ee2cSJeremy L Thompson CeedScalar *v; 26ad70ee2cSJeremy L Thompson CeedTensorContract contract; 27ad70ee2cSJeremy L Thompson CeedBasis_Ref *impl; 28ad70ee2cSJeremy L Thompson 29ad70ee2cSJeremy L Thompson CeedCallBackend(CeedBasisGetCeed(basis, &ceed)); 30ad70ee2cSJeremy L Thompson CeedCallBackend(CeedBasisGetData(basis, &impl)); 312b730f8bSJeremy L Thompson CeedCallBackend(CeedBasisGetDimension(basis, &dim)); 322b730f8bSJeremy L Thompson CeedCallBackend(CeedBasisGetNumComponents(basis, &num_comp)); 33c4e3f59bSSebastian Grimberg CeedCallBackend(CeedBasisGetNumQuadratureComponents(basis, eval_mode, &q_comp)); 342b730f8bSJeremy L Thompson CeedCallBackend(CeedBasisGetNumNodes(basis, &num_nodes)); 352b730f8bSJeremy L Thompson CeedCallBackend(CeedBasisGetNumQuadraturePoints(basis, &num_qpts)); 362b730f8bSJeremy L Thompson CeedCallBackend(CeedBasisGetTensorContract(basis, &contract)); 376574a04fSJeremy L Thompson if (U != CEED_VECTOR_NONE) CeedCallBackend(CeedVectorGetArrayRead(U, CEED_MEM_HOST, &u)); 386574a04fSJeremy L Thompson else CeedCheck(eval_mode == CEED_EVAL_WEIGHT, ceed, CEED_ERROR_BACKEND, "An input vector is required for this CeedEvalMode"); 392b730f8bSJeremy L Thompson CeedCallBackend(CeedVectorGetArrayWrite(V, CEED_MEM_HOST, &v)); 4021617c04Sjeremylt 418d94b059Sjeremylt // Clear v if operating in transpose 42d1d35e2fSjeremylt if (t_mode == CEED_TRANSPOSE) { 43d1d35e2fSjeremylt const CeedInt v_size = num_elem * num_comp * num_nodes; 44ad70ee2cSJeremy L Thompson 452b730f8bSJeremy L Thompson for (CeedInt i = 0; i < v_size; i++) v[i] = (CeedScalar)0.0; 4621617c04Sjeremylt } 47ad70ee2cSJeremy L Thompson 486402da51SJeremy L Thompson CeedCallBackend(CeedBasisIsTensor(basis, &is_tensor_basis)); 496402da51SJeremy L Thompson if (is_tensor_basis) { 50c4e3f59bSSebastian Grimberg // Tensor basis 51d1d35e2fSjeremylt CeedInt P_1d, Q_1d; 52ad70ee2cSJeremy L Thompson 532b730f8bSJeremy L Thompson CeedCallBackend(CeedBasisGetNumNodes1D(basis, &P_1d)); 542b730f8bSJeremy L Thompson CeedCallBackend(CeedBasisGetNumQuadraturePoints1D(basis, &Q_1d)); 55d1d35e2fSjeremylt switch (eval_mode) { 568d94b059Sjeremylt // Interpolate to/from quadrature points 57a2b73c81Sjeremylt case CEED_EVAL_INTERP: { 588c1105f8SJeremy L Thompson if (impl->has_collo_interp) { 59d1d35e2fSjeremylt memcpy(v, u, num_elem * num_comp * num_nodes * sizeof(u[0])); 60dfe03796SJeremy L Thompson } else { 61d1d35e2fSjeremylt CeedInt P = P_1d, Q = Q_1d; 62ad70ee2cSJeremy L Thompson 63d1d35e2fSjeremylt if (t_mode == CEED_TRANSPOSE) { 642b730f8bSJeremy L Thompson P = Q_1d; 652b730f8bSJeremy L Thompson Q = P_1d; 6621617c04Sjeremylt } 67d1d35e2fSjeremylt CeedInt pre = num_comp * CeedIntPow(P, dim - 1), post = num_elem; 68d1d35e2fSjeremylt CeedScalar tmp[2][num_elem * num_comp * Q * CeedIntPow(P > Q ? P : Q, dim - 1)]; 69d1d35e2fSjeremylt const CeedScalar *interp_1d; 70ad70ee2cSJeremy L Thompson 712b730f8bSJeremy L Thompson CeedCallBackend(CeedBasisGetInterp1D(basis, &interp_1d)); 7221617c04Sjeremylt for (CeedInt d = 0; d < dim; d++) { 732b730f8bSJeremy L Thompson CeedCallBackend(CeedTensorContractApply(contract, pre, P, post, Q, interp_1d, t_mode, add && (d == dim - 1), d == 0 ? u : tmp[d % 2], 742b730f8bSJeremy L Thompson d == dim - 1 ? v : tmp[(d + 1) % 2])); 7521617c04Sjeremylt pre /= P; 7621617c04Sjeremylt post *= Q; 7721617c04Sjeremylt } 78dfe03796SJeremy L Thompson } 79a2b73c81Sjeremylt } break; 808d94b059Sjeremylt // Evaluate the gradient to/from quadrature points 81a2b73c81Sjeremylt case CEED_EVAL_GRAD: { 8221617c04Sjeremylt // In CEED_NOTRANSPOSE mode: 83d1d35e2fSjeremylt // u has shape [dim, num_comp, P^dim, num_elem], row-major layout 84d1d35e2fSjeremylt // v has shape [dim, num_comp, Q^dim, num_elem], row-major layout 8521617c04Sjeremylt // In CEED_TRANSPOSE mode, the sizes of u and v are switched. 86d1d35e2fSjeremylt CeedInt P = P_1d, Q = Q_1d; 87ad70ee2cSJeremy L Thompson 88d1d35e2fSjeremylt if (t_mode == CEED_TRANSPOSE) { 891c66c397SJeremy L Thompson P = Q_1d; 901c66c397SJeremy L Thompson Q = Q_1d; 9121617c04Sjeremylt } 92d1d35e2fSjeremylt CeedInt pre = num_comp * CeedIntPow(P, dim - 1), post = num_elem; 93d1d35e2fSjeremylt const CeedScalar *interp_1d; 94ad70ee2cSJeremy L Thompson 952b730f8bSJeremy L Thompson CeedCallBackend(CeedBasisGetInterp1D(basis, &interp_1d)); 968c1105f8SJeremy L Thompson if (impl->collo_grad_1d) { 97d1d35e2fSjeremylt CeedScalar tmp[2][num_elem * num_comp * Q * CeedIntPow(P > Q ? P : Q, dim - 1)]; 98d1d35e2fSjeremylt CeedScalar interp[num_elem * num_comp * Q * CeedIntPow(P > Q ? P : Q, dim - 1)]; 99ad70ee2cSJeremy L Thompson 10084a01de5SJeremy L Thompson // Interpolate to quadrature points (NoTranspose) 10184a01de5SJeremy L Thompson // or Grad to quadrature points (Transpose) 10221617c04Sjeremylt for (CeedInt d = 0; d < dim; d++) { 1032b730f8bSJeremy L Thompson CeedCallBackend(CeedTensorContractApply(contract, pre, P, post, Q, (t_mode == CEED_NOTRANSPOSE ? interp_1d : impl->collo_grad_1d), t_mode, 1042b730f8bSJeremy L Thompson add && (d > 0), 1052b730f8bSJeremy L Thompson (t_mode == CEED_NOTRANSPOSE ? (d == 0 ? u : tmp[d % 2]) : u + d * num_qpts * num_comp * num_elem), 1062b730f8bSJeremy L Thompson (t_mode == CEED_NOTRANSPOSE ? (d == dim - 1 ? interp : tmp[(d + 1) % 2]) : interp))); 10721617c04Sjeremylt pre /= P; 10821617c04Sjeremylt post *= Q; 10921617c04Sjeremylt } 11084a01de5SJeremy L Thompson // Grad to quadrature points (NoTranspose) 1118795c945Sjeremylt // or Interpolate to nodes (Transpose) 112d1d35e2fSjeremylt P = Q_1d, Q = Q_1d; 113d1d35e2fSjeremylt if (t_mode == CEED_TRANSPOSE) { 1141c66c397SJeremy L Thompson P = Q_1d; 1151c66c397SJeremy L Thompson Q = P_1d; 11684a01de5SJeremy L Thompson } 117d1d35e2fSjeremylt pre = num_comp * CeedIntPow(P, dim - 1), post = num_elem; 11884a01de5SJeremy L Thompson for (CeedInt d = 0; d < dim; d++) { 1192b730f8bSJeremy L Thompson CeedCallBackend(CeedTensorContractApply( 1202b730f8bSJeremy L Thompson contract, pre, P, post, Q, (t_mode == CEED_NOTRANSPOSE ? impl->collo_grad_1d : interp_1d), t_mode, add && (d == dim - 1), 1212b730f8bSJeremy L Thompson (t_mode == CEED_NOTRANSPOSE ? interp : (d == 0 ? interp : tmp[d % 2])), 1222b730f8bSJeremy L Thompson (t_mode == CEED_NOTRANSPOSE ? v + d * num_qpts * num_comp * num_elem : (d == dim - 1 ? v : tmp[(d + 1) % 2])))); 12384a01de5SJeremy L Thompson pre /= P; 12484a01de5SJeremy L Thompson post *= Q; 12521617c04Sjeremylt } 1268c1105f8SJeremy L Thompson } else if (impl->has_collo_interp) { // Qpts collocated with nodes 127d1d35e2fSjeremylt const CeedScalar *grad_1d; 128ad70ee2cSJeremy L Thompson 1292b730f8bSJeremy L Thompson CeedCallBackend(CeedBasisGetGrad1D(basis, &grad_1d)); 130dfe03796SJeremy L Thompson 131dfe03796SJeremy L Thompson // Dim contractions, identity in other directions 132d1d35e2fSjeremylt CeedInt pre = num_comp * CeedIntPow(P, dim - 1), post = num_elem; 133ad70ee2cSJeremy L Thompson 134c6158135Sjeremylt for (CeedInt d = 0; d < dim; d++) { 1352b730f8bSJeremy L Thompson CeedCallBackend(CeedTensorContractApply(contract, pre, P, post, Q, grad_1d, t_mode, add && (d > 0), 1362b730f8bSJeremy L Thompson t_mode == CEED_NOTRANSPOSE ? u : u + d * num_comp * num_qpts * num_elem, 1372b730f8bSJeremy L Thompson t_mode == CEED_TRANSPOSE ? v : v + d * num_comp * num_qpts * num_elem)); 138c6158135Sjeremylt pre /= P; 139c6158135Sjeremylt post *= Q; 140dfe03796SJeremy L Thompson } 141a7bd39daSjeremylt } else { // Underintegration, P > Q 142d1d35e2fSjeremylt const CeedScalar *grad_1d; 143ad70ee2cSJeremy L Thompson 1442b730f8bSJeremy L Thompson CeedCallBackend(CeedBasisGetGrad1D(basis, &grad_1d)); 145a7bd39daSjeremylt 146d1d35e2fSjeremylt if (t_mode == CEED_TRANSPOSE) { 1471c66c397SJeremy L Thompson P = Q_1d; 1481c66c397SJeremy L Thompson Q = P_1d; 149a7bd39daSjeremylt } 150d1d35e2fSjeremylt CeedScalar tmp[2][num_elem * num_comp * Q * CeedIntPow(P > Q ? P : Q, dim - 1)]; 151a7bd39daSjeremylt 152a7bd39daSjeremylt // Dim**2 contractions, apply grad when pass == dim 153a7bd39daSjeremylt for (CeedInt p = 0; p < dim; p++) { 154d1d35e2fSjeremylt CeedInt pre = num_comp * CeedIntPow(P, dim - 1), post = num_elem; 155ad70ee2cSJeremy L Thompson 156a7bd39daSjeremylt for (CeedInt d = 0; d < dim; d++) { 1572b730f8bSJeremy L Thompson CeedCallBackend(CeedTensorContractApply( 1582b730f8bSJeremy L Thompson contract, pre, P, post, Q, (p == d) ? grad_1d : interp_1d, t_mode, add && (d == dim - 1), 1592b730f8bSJeremy L Thompson (d == 0 ? (t_mode == CEED_NOTRANSPOSE ? u : u + p * num_comp * num_qpts * num_elem) : tmp[d % 2]), 1602b730f8bSJeremy L Thompson (d == dim - 1 ? (t_mode == CEED_TRANSPOSE ? v : v + p * num_comp * num_qpts * num_elem) : tmp[(d + 1) % 2]))); 161a7bd39daSjeremylt pre /= P; 162a7bd39daSjeremylt post *= Q; 163a7bd39daSjeremylt } 164a7bd39daSjeremylt } 165a7bd39daSjeremylt } 166a2b73c81Sjeremylt } break; 1678d94b059Sjeremylt // Retrieve interpolation weights 168a2b73c81Sjeremylt case CEED_EVAL_WEIGHT: { 169d1d35e2fSjeremylt CeedInt Q = Q_1d; 170d1d35e2fSjeremylt const CeedScalar *q_weight_1d; 171ad70ee2cSJeremy L Thompson 172ad70ee2cSJeremy L Thompson CeedCheck(t_mode == CEED_NOTRANSPOSE, ceed, CEED_ERROR_BACKEND, "CEED_EVAL_WEIGHT incompatible with CEED_TRANSPOSE"); 1732b730f8bSJeremy L Thompson CeedCallBackend(CeedBasisGetQWeights(basis, &q_weight_1d)); 17421617c04Sjeremylt for (CeedInt d = 0; d < dim; d++) { 175b5cf12eeSjeremylt CeedInt pre = CeedIntPow(Q, dim - d - 1), post = CeedIntPow(Q, d); 176ad70ee2cSJeremy L Thompson 1772b730f8bSJeremy L Thompson for (CeedInt i = 0; i < pre; i++) { 1782b730f8bSJeremy L Thompson for (CeedInt j = 0; j < Q; j++) { 17984a01de5SJeremy L Thompson for (CeedInt k = 0; k < post; k++) { 180ad70ee2cSJeremy L Thompson const CeedScalar w = q_weight_1d[j] * (d == 0 ? 1 : v[((i * Q + j) * post + k) * num_elem]); 181ad70ee2cSJeremy L Thompson 1822b730f8bSJeremy L Thompson for (CeedInt e = 0; e < num_elem; e++) v[((i * Q + j) * post + k) * num_elem + e] = w; 1832b730f8bSJeremy L Thompson } 1842b730f8bSJeremy L Thompson } 18584a01de5SJeremy L Thompson } 18621617c04Sjeremylt } 187a2b73c81Sjeremylt } break; 188c042f62fSJeremy L Thompson // LCOV_EXCL_START 1898d94b059Sjeremylt // Evaluate the divergence to/from the quadrature points 190a2b73c81Sjeremylt case CEED_EVAL_DIV: 191e15f9bd0SJeremy L Thompson return CeedError(ceed, CEED_ERROR_BACKEND, "CEED_EVAL_DIV not supported"); 1928d94b059Sjeremylt // Evaluate the curl to/from the quadrature points 193a2b73c81Sjeremylt case CEED_EVAL_CURL: 194e15f9bd0SJeremy L Thompson return CeedError(ceed, CEED_ERROR_BACKEND, "CEED_EVAL_CURL not supported"); 1958d94b059Sjeremylt // Take no action, BasisApply should not have been called 196a2b73c81Sjeremylt case CEED_EVAL_NONE: 1972b730f8bSJeremy L Thompson return CeedError(ceed, CEED_ERROR_BACKEND, "CEED_EVAL_NONE does not make sense in this context"); 198c042f62fSJeremy L Thompson // LCOV_EXCL_STOP 19921617c04Sjeremylt } 200a8de75f0Sjeremylt } else { 201a8de75f0Sjeremylt // Non-tensor basis 202c4e3f59bSSebastian Grimberg CeedInt P = num_nodes, Q = num_qpts; 203ad70ee2cSJeremy L Thompson 204d1d35e2fSjeremylt switch (eval_mode) { 20584a01de5SJeremy L Thompson // Interpolate to/from quadrature points 206a8de75f0Sjeremylt case CEED_EVAL_INTERP: { 2076c58de82SJeremy L Thompson const CeedScalar *interp; 208ad70ee2cSJeremy L Thompson 2092b730f8bSJeremy L Thompson CeedCallBackend(CeedBasisGetInterp(basis, &interp)); 210c4e3f59bSSebastian Grimberg CeedCallBackend(CeedTensorContractStridedApply(contract, num_comp, P, num_elem, q_comp, Q, interp, t_mode, add, u, v)); 2112b730f8bSJeremy L Thompson } break; 21284a01de5SJeremy L Thompson // Evaluate the gradient to/from quadrature points 213a8de75f0Sjeremylt case CEED_EVAL_GRAD: { 2146c58de82SJeremy L Thompson const CeedScalar *grad; 215ad70ee2cSJeremy L Thompson 2162b730f8bSJeremy L Thompson CeedCallBackend(CeedBasisGetGrad(basis, &grad)); 217c4e3f59bSSebastian Grimberg CeedCallBackend(CeedTensorContractStridedApply(contract, num_comp, P, num_elem, q_comp, Q, grad, t_mode, add, u, v)); 218c4e3f59bSSebastian Grimberg } break; 219c4e3f59bSSebastian Grimberg // Evaluate the divergence to/from the quadrature points 220c4e3f59bSSebastian Grimberg case CEED_EVAL_DIV: { 221c4e3f59bSSebastian Grimberg const CeedScalar *div; 222ad70ee2cSJeremy L Thompson 223c4e3f59bSSebastian Grimberg CeedCallBackend(CeedBasisGetDiv(basis, &div)); 224c4e3f59bSSebastian Grimberg CeedCallBackend(CeedTensorContractStridedApply(contract, num_comp, P, num_elem, q_comp, Q, div, t_mode, add, u, v)); 225c4e3f59bSSebastian Grimberg } break; 226c4e3f59bSSebastian Grimberg // Evaluate the curl to/from the quadrature points 227c4e3f59bSSebastian Grimberg case CEED_EVAL_CURL: { 228c4e3f59bSSebastian Grimberg const CeedScalar *curl; 229ad70ee2cSJeremy L Thompson 230c4e3f59bSSebastian Grimberg CeedCallBackend(CeedBasisGetCurl(basis, &curl)); 231c4e3f59bSSebastian Grimberg CeedCallBackend(CeedTensorContractStridedApply(contract, num_comp, P, num_elem, q_comp, Q, curl, t_mode, add, u, v)); 2322b730f8bSJeremy L Thompson } break; 23384a01de5SJeremy L Thompson // Retrieve interpolation weights 234a8de75f0Sjeremylt case CEED_EVAL_WEIGHT: { 235d1d35e2fSjeremylt const CeedScalar *q_weight; 236ad70ee2cSJeremy L Thompson 237ad70ee2cSJeremy L Thompson CeedCheck(t_mode == CEED_NOTRANSPOSE, ceed, CEED_ERROR_BACKEND, "CEED_EVAL_WEIGHT incompatible with CEED_TRANSPOSE"); 2382b730f8bSJeremy L Thompson CeedCallBackend(CeedBasisGetQWeights(basis, &q_weight)); 2392b730f8bSJeremy L Thompson for (CeedInt i = 0; i < num_qpts; i++) { 2402b730f8bSJeremy L Thompson for (CeedInt e = 0; e < num_elem; e++) v[i * num_elem + e] = q_weight[i]; 2412b730f8bSJeremy L Thompson } 242a8de75f0Sjeremylt } break; 24350c301a5SRezgar Shakeri // LCOV_EXCL_START 24484a01de5SJeremy L Thompson // Take no action, BasisApply should not have been called 245a8de75f0Sjeremylt case CEED_EVAL_NONE: 2462b730f8bSJeremy L Thompson return CeedError(ceed, CEED_ERROR_BACKEND, "CEED_EVAL_NONE does not make sense in this context"); 247c042f62fSJeremy L Thompson // LCOV_EXCL_STOP 248a8de75f0Sjeremylt } 249a8de75f0Sjeremylt } 250a7b7f929Sjeremylt if (U != CEED_VECTOR_NONE) { 2512b730f8bSJeremy L Thompson CeedCallBackend(CeedVectorRestoreArrayRead(U, &u)); 252aedaa0e5Sjeremylt } 2532b730f8bSJeremy L Thompson CeedCallBackend(CeedVectorRestoreArray(V, &v)); 254e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 25521617c04Sjeremylt } 25621617c04Sjeremylt 257f10650afSjeremylt //------------------------------------------------------------------------------ 258b2165e7aSSebastian Grimberg // Basis Destroy Tensor 259b2165e7aSSebastian Grimberg //------------------------------------------------------------------------------ 260b2165e7aSSebastian Grimberg static int CeedBasisDestroyTensor_Ref(CeedBasis basis) { 261b2165e7aSSebastian Grimberg CeedBasis_Ref *impl; 262ad70ee2cSJeremy L Thompson 263b2165e7aSSebastian Grimberg CeedCallBackend(CeedBasisGetData(basis, &impl)); 264b2165e7aSSebastian Grimberg CeedCallBackend(CeedFree(&impl->collo_grad_1d)); 265b2165e7aSSebastian Grimberg CeedCallBackend(CeedFree(&impl)); 266b2165e7aSSebastian Grimberg return CEED_ERROR_SUCCESS; 267b2165e7aSSebastian Grimberg } 268b2165e7aSSebastian Grimberg 269b2165e7aSSebastian Grimberg //------------------------------------------------------------------------------ 270b2165e7aSSebastian Grimberg // Basis Create Tensor 271b2165e7aSSebastian Grimberg //------------------------------------------------------------------------------ 272b2165e7aSSebastian Grimberg int CeedBasisCreateTensorH1_Ref(CeedInt dim, CeedInt P_1d, CeedInt Q_1d, const CeedScalar *interp_1d, const CeedScalar *grad_1d, 273b2165e7aSSebastian Grimberg const CeedScalar *q_ref_1d, const CeedScalar *q_weight_1d, CeedBasis basis) { 274ca735530SJeremy L Thompson Ceed ceed, ceed_parent; 275b2165e7aSSebastian Grimberg CeedBasis_Ref *impl; 276ad70ee2cSJeremy L Thompson CeedTensorContract contract; 277ad70ee2cSJeremy L Thompson 278ad70ee2cSJeremy L Thompson CeedCallBackend(CeedBasisGetCeed(basis, &ceed)); 279ca735530SJeremy L Thompson CeedCallBackend(CeedGetParent(ceed, &ceed_parent)); 280ad70ee2cSJeremy L Thompson 281b2165e7aSSebastian Grimberg CeedCallBackend(CeedCalloc(1, &impl)); 282b2165e7aSSebastian Grimberg // Check for collocated interp 283b2165e7aSSebastian Grimberg if (Q_1d == P_1d) { 284ad70ee2cSJeremy L Thompson bool has_collocated = true; 285ad70ee2cSJeremy L Thompson 286b2165e7aSSebastian Grimberg for (CeedInt i = 0; i < P_1d; i++) { 287ad70ee2cSJeremy L Thompson has_collocated = has_collocated && (fabs(interp_1d[i + P_1d * i] - 1.0) < 1e-14); 288b2165e7aSSebastian Grimberg for (CeedInt j = 0; j < P_1d; j++) { 289ad70ee2cSJeremy L Thompson if (j != i) has_collocated = has_collocated && (fabs(interp_1d[j + P_1d * i]) < 1e-14); 290b2165e7aSSebastian Grimberg } 291b2165e7aSSebastian Grimberg } 292ad70ee2cSJeremy L Thompson impl->has_collo_interp = has_collocated; 293b2165e7aSSebastian Grimberg } 294b2165e7aSSebastian Grimberg // Calculate collocated grad 295b2165e7aSSebastian Grimberg if (Q_1d >= P_1d && !impl->has_collo_interp) { 296b2165e7aSSebastian Grimberg CeedCallBackend(CeedMalloc(Q_1d * Q_1d, &impl->collo_grad_1d)); 297b2165e7aSSebastian Grimberg CeedCallBackend(CeedBasisGetCollocatedGrad(basis, impl->collo_grad_1d)); 298b2165e7aSSebastian Grimberg } 299b2165e7aSSebastian Grimberg CeedCallBackend(CeedBasisSetData(basis, impl)); 300b2165e7aSSebastian Grimberg 301*a71faab1SSebastian Grimberg CeedCallBackend(CeedTensorContractCreate(ceed_parent, &contract)); 302b2165e7aSSebastian Grimberg CeedCallBackend(CeedBasisSetTensorContract(basis, contract)); 303b2165e7aSSebastian Grimberg 304b2165e7aSSebastian Grimberg CeedCallBackend(CeedSetBackendFunction(ceed, "Basis", basis, "Apply", CeedBasisApply_Ref)); 305b2165e7aSSebastian Grimberg CeedCallBackend(CeedSetBackendFunction(ceed, "Basis", basis, "Destroy", CeedBasisDestroyTensor_Ref)); 306b2165e7aSSebastian Grimberg return CEED_ERROR_SUCCESS; 307b2165e7aSSebastian Grimberg } 308b2165e7aSSebastian Grimberg 309b2165e7aSSebastian Grimberg //------------------------------------------------------------------------------ 31050c301a5SRezgar Shakeri // Basis Create Non-Tensor H^1 311f10650afSjeremylt //------------------------------------------------------------------------------ 3122b730f8bSJeremy L Thompson int CeedBasisCreateH1_Ref(CeedElemTopology topo, CeedInt dim, CeedInt num_nodes, CeedInt num_qpts, const CeedScalar *interp, const CeedScalar *grad, 3132b730f8bSJeremy L Thompson const CeedScalar *q_ref, const CeedScalar *q_weight, CeedBasis basis) { 314ca735530SJeremy L Thompson Ceed ceed, ceed_parent; 315f10650afSjeremylt CeedTensorContract contract; 316ad70ee2cSJeremy L Thompson 317ad70ee2cSJeremy L Thompson CeedCallBackend(CeedBasisGetCeed(basis, &ceed)); 318ca735530SJeremy L Thompson CeedCallBackend(CeedGetParent(ceed, &ceed_parent)); 319ad70ee2cSJeremy L Thompson 320*a71faab1SSebastian Grimberg CeedCallBackend(CeedTensorContractCreate(ceed_parent, &contract)); 3212b730f8bSJeremy L Thompson CeedCallBackend(CeedBasisSetTensorContract(basis, contract)); 322f10650afSjeremylt 3232b730f8bSJeremy L Thompson CeedCallBackend(CeedSetBackendFunction(ceed, "Basis", basis, "Apply", CeedBasisApply_Ref)); 324e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 325f10650afSjeremylt } 326f10650afSjeremylt 327f10650afSjeremylt //------------------------------------------------------------------------------ 32850c301a5SRezgar Shakeri // Basis Create Non-Tensor H(div) 32950c301a5SRezgar Shakeri //------------------------------------------------------------------------------ 3302b730f8bSJeremy L Thompson int CeedBasisCreateHdiv_Ref(CeedElemTopology topo, CeedInt dim, CeedInt num_nodes, CeedInt num_qpts, const CeedScalar *interp, const CeedScalar *div, 3312b730f8bSJeremy L Thompson const CeedScalar *q_ref, const CeedScalar *q_weight, CeedBasis basis) { 332ca735530SJeremy L Thompson Ceed ceed, ceed_parent; 33350c301a5SRezgar Shakeri CeedTensorContract contract; 334ad70ee2cSJeremy L Thompson 335ad70ee2cSJeremy L Thompson CeedCallBackend(CeedBasisGetCeed(basis, &ceed)); 336ca735530SJeremy L Thompson CeedCallBackend(CeedGetParent(ceed, &ceed_parent)); 337ad70ee2cSJeremy L Thompson 338*a71faab1SSebastian Grimberg CeedCallBackend(CeedTensorContractCreate(ceed_parent, &contract)); 3392b730f8bSJeremy L Thompson CeedCallBackend(CeedBasisSetTensorContract(basis, contract)); 34050c301a5SRezgar Shakeri 3412b730f8bSJeremy L Thompson CeedCallBackend(CeedSetBackendFunction(ceed, "Basis", basis, "Apply", CeedBasisApply_Ref)); 34250c301a5SRezgar Shakeri return CEED_ERROR_SUCCESS; 34350c301a5SRezgar Shakeri } 34450c301a5SRezgar Shakeri 34550c301a5SRezgar Shakeri //------------------------------------------------------------------------------ 346c4e3f59bSSebastian Grimberg // Basis Create Non-Tensor H(curl) 347c4e3f59bSSebastian Grimberg //------------------------------------------------------------------------------ 348c4e3f59bSSebastian Grimberg int CeedBasisCreateHcurl_Ref(CeedElemTopology topo, CeedInt dim, CeedInt num_nodes, CeedInt num_qpts, const CeedScalar *interp, 349c4e3f59bSSebastian Grimberg const CeedScalar *curl, const CeedScalar *q_ref, const CeedScalar *q_weight, CeedBasis basis) { 350ca735530SJeremy L Thompson Ceed ceed, ceed_parent; 351c4e3f59bSSebastian Grimberg CeedTensorContract contract; 352ad70ee2cSJeremy L Thompson 353ad70ee2cSJeremy L Thompson CeedCallBackend(CeedBasisGetCeed(basis, &ceed)); 354ca735530SJeremy L Thompson CeedCallBackend(CeedGetParent(ceed, &ceed_parent)); 355ad70ee2cSJeremy L Thompson 356*a71faab1SSebastian Grimberg CeedCallBackend(CeedTensorContractCreate(ceed_parent, &contract)); 357c4e3f59bSSebastian Grimberg CeedCallBackend(CeedBasisSetTensorContract(basis, contract)); 358c4e3f59bSSebastian Grimberg 359c4e3f59bSSebastian Grimberg CeedCallBackend(CeedSetBackendFunction(ceed, "Basis", basis, "Apply", CeedBasisApply_Ref)); 360c4e3f59bSSebastian Grimberg return CEED_ERROR_SUCCESS; 361c4e3f59bSSebastian Grimberg } 362c4e3f59bSSebastian Grimberg 363c4e3f59bSSebastian Grimberg //------------------------------------------------------------------------------ 364