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 172f86a920SJeremy L Thompson #include "ceed-ref.h" 182f86a920SJeremy L Thompson 19*f10650afSjeremylt //------------------------------------------------------------------------------ 20*f10650afSjeremylt // Tensor Contract Apply 21*f10650afSjeremylt //------------------------------------------------------------------------------ 222f86a920SJeremy L Thompson int CeedTensorContractApply_Ref(CeedTensorContract contract, CeedInt A, 232f86a920SJeremy L Thompson CeedInt B, CeedInt C, CeedInt J, 242f86a920SJeremy L Thompson const CeedScalar *restrict t, 252f86a920SJeremy L Thompson CeedTransposeMode tmode, const CeedInt Add, 262f86a920SJeremy L Thompson const CeedScalar *restrict u, 272f86a920SJeremy L Thompson CeedScalar *restrict v) { 282f86a920SJeremy L Thompson CeedInt tstride0 = B, tstride1 = 1; 292f86a920SJeremy L Thompson if (tmode == CEED_TRANSPOSE) { 302f86a920SJeremy L Thompson tstride0 = 1; tstride1 = J; 312f86a920SJeremy L Thompson } 322f86a920SJeremy L Thompson 332f86a920SJeremy L Thompson if (!Add) 342f86a920SJeremy L Thompson for (CeedInt q=0; q<A*J*C; q++) 352f86a920SJeremy L Thompson v[q] = (CeedScalar) 0.0; 362f86a920SJeremy L Thompson 372f86a920SJeremy L Thompson for (CeedInt a=0; a<A; a++) 382f86a920SJeremy L Thompson for (CeedInt b=0; b<B; b++) 392f86a920SJeremy L Thompson for (CeedInt j=0; j<J; j++) { 402f86a920SJeremy L Thompson CeedScalar tq = t[j*tstride0 + b*tstride1]; 412f86a920SJeremy L Thompson for (CeedInt c=0; c<C; c++) 422f86a920SJeremy L Thompson v[(a*J+j)*C+c] += tq * u[(a*B+b)*C+c]; 432f86a920SJeremy L Thompson } 442f86a920SJeremy L Thompson return 0; 452f86a920SJeremy L Thompson } 462f86a920SJeremy L Thompson 47*f10650afSjeremylt //------------------------------------------------------------------------------ 48*f10650afSjeremylt // Tensor Contract Destroy 49*f10650afSjeremylt //------------------------------------------------------------------------------ 502f86a920SJeremy L Thompson static int CeedTensorContractDestroy_Ref(CeedTensorContract contract) { 512f86a920SJeremy L Thompson return 0; 522f86a920SJeremy L Thompson } 532f86a920SJeremy L Thompson 54*f10650afSjeremylt //------------------------------------------------------------------------------ 55*f10650afSjeremylt // Tensor Contract Create 56*f10650afSjeremylt //------------------------------------------------------------------------------ 57c71e1dcdSjeremylt int CeedTensorContractCreate_Ref(CeedBasis basis, CeedTensorContract contract) { 582f86a920SJeremy L Thompson int ierr; 592f86a920SJeremy L Thompson Ceed ceed; 602f86a920SJeremy L Thompson ierr = CeedTensorContractGetCeed(contract, &ceed); CeedChk(ierr); 612f86a920SJeremy L Thompson 622f86a920SJeremy L Thompson ierr = CeedSetBackendFunction(ceed, "TensorContract", contract, "Apply", 632f86a920SJeremy L Thompson CeedTensorContractApply_Ref); CeedChk(ierr); 642f86a920SJeremy L Thompson ierr = CeedSetBackendFunction(ceed, "TensorContract", contract, "Destroy", 652f86a920SJeremy L Thompson CeedTensorContractDestroy_Ref); CeedChk(ierr); 662f86a920SJeremy L Thompson 672f86a920SJeremy L Thompson return 0; 682f86a920SJeremy L Thompson } 69*f10650afSjeremylt //------------------------------------------------------------------------------ 70