12f86a920SJeremy L Thompson // Copyright (c) 2017-2018, Lawrence Livermore National Security, LLC. 22f86a920SJeremy L Thompson // Produced at the Lawrence Livermore National Laboratory. LLNL-CODE-734707. 32f86a920SJeremy L Thompson // All Rights reserved. See files LICENSE and NOTICE for details. 42f86a920SJeremy L Thompson // 52f86a920SJeremy L Thompson // This file is part of CEED, a collection of benchmarks, miniapps, software 62f86a920SJeremy L Thompson // libraries and APIs for efficient high-order finite element and spectral 72f86a920SJeremy L Thompson // element discretizations for exascale applications. For more information and 82f86a920SJeremy L Thompson // source code availability see http://github.com/ceed. 92f86a920SJeremy L Thompson // 102f86a920SJeremy L Thompson // The CEED research is supported by the Exascale Computing Project 17-SC-20-SC, 112f86a920SJeremy L Thompson // a collaborative effort of two U.S. Department of Energy organizations (Office 122f86a920SJeremy L Thompson // of Science and the National Nuclear Security Administration) responsible for 132f86a920SJeremy L Thompson // the planning and preparation of a capable exascale ecosystem, including 142f86a920SJeremy L Thompson // software, applications, hardware, advanced system engineering and early 152f86a920SJeremy L Thompson // testbed platforms, in support of the nation's exascale computing imperative. 162f86a920SJeremy L Thompson 173d576824SJeremy L Thompson #include <ceed.h> 183d576824SJeremy L Thompson #include <ceed-backend.h> 192f86a920SJeremy L Thompson #include "ceed-ref.h" 202f86a920SJeremy L Thompson 21f10650afSjeremylt //------------------------------------------------------------------------------ 22f10650afSjeremylt // Tensor Contract Apply 23f10650afSjeremylt //------------------------------------------------------------------------------ 242f86a920SJeremy L Thompson int CeedTensorContractApply_Ref(CeedTensorContract contract, CeedInt A, 252f86a920SJeremy L Thompson CeedInt B, CeedInt C, CeedInt J, 262f86a920SJeremy L Thompson const CeedScalar *restrict t, 272f86a920SJeremy L Thompson CeedTransposeMode tmode, const CeedInt Add, 282f86a920SJeremy L Thompson const CeedScalar *restrict u, 292f86a920SJeremy L Thompson CeedScalar *restrict v) { 302f86a920SJeremy L Thompson CeedInt tstride0 = B, tstride1 = 1; 312f86a920SJeremy L Thompson if (tmode == CEED_TRANSPOSE) { 322f86a920SJeremy L Thompson tstride0 = 1; tstride1 = J; 332f86a920SJeremy L Thompson } 342f86a920SJeremy L Thompson 352f86a920SJeremy L Thompson if (!Add) 362f86a920SJeremy L Thompson for (CeedInt q=0; q<A*J*C; q++) 372f86a920SJeremy L Thompson v[q] = (CeedScalar) 0.0; 382f86a920SJeremy L Thompson 392f86a920SJeremy L Thompson for (CeedInt a=0; a<A; a++) 402f86a920SJeremy L Thompson for (CeedInt b=0; b<B; b++) 412f86a920SJeremy L Thompson for (CeedInt j=0; j<J; j++) { 422f86a920SJeremy L Thompson CeedScalar tq = t[j*tstride0 + b*tstride1]; 432f86a920SJeremy L Thompson for (CeedInt c=0; c<C; c++) 442f86a920SJeremy L Thompson v[(a*J+j)*C+c] += tq * u[(a*B+b)*C+c]; 452f86a920SJeremy L Thompson } 46*e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 472f86a920SJeremy L Thompson } 482f86a920SJeremy L Thompson 49f10650afSjeremylt //------------------------------------------------------------------------------ 50f10650afSjeremylt // Tensor Contract Destroy 51f10650afSjeremylt //------------------------------------------------------------------------------ 522f86a920SJeremy L Thompson static int CeedTensorContractDestroy_Ref(CeedTensorContract contract) { 53*e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 542f86a920SJeremy L Thompson } 552f86a920SJeremy L Thompson 56f10650afSjeremylt //------------------------------------------------------------------------------ 57f10650afSjeremylt // Tensor Contract Create 58f10650afSjeremylt //------------------------------------------------------------------------------ 59c71e1dcdSjeremylt int CeedTensorContractCreate_Ref(CeedBasis basis, CeedTensorContract contract) { 602f86a920SJeremy L Thompson int ierr; 612f86a920SJeremy L Thompson Ceed ceed; 62*e15f9bd0SJeremy L Thompson ierr = CeedTensorContractGetCeed(contract, &ceed); CeedChkBackend(ierr); 632f86a920SJeremy L Thompson 642f86a920SJeremy L Thompson ierr = CeedSetBackendFunction(ceed, "TensorContract", contract, "Apply", 65*e15f9bd0SJeremy L Thompson CeedTensorContractApply_Ref); CeedChkBackend(ierr); 662f86a920SJeremy L Thompson ierr = CeedSetBackendFunction(ceed, "TensorContract", contract, "Destroy", 67*e15f9bd0SJeremy L Thompson CeedTensorContractDestroy_Ref); CeedChkBackend(ierr); 682f86a920SJeremy L Thompson 69*e15f9bd0SJeremy L Thompson return CEED_ERROR_SUCCESS; 702f86a920SJeremy L Thompson } 71f10650afSjeremylt //------------------------------------------------------------------------------ 72