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 <string.h> 182f86a920SJeremy L Thompson #include "ceed-ref.h" 192f86a920SJeremy L Thompson 202f86a920SJeremy L Thompson int CeedTensorContractApply_Ref(CeedTensorContract contract, CeedInt A, 212f86a920SJeremy L Thompson CeedInt B, CeedInt C, CeedInt J, 222f86a920SJeremy L Thompson const CeedScalar *restrict t, 232f86a920SJeremy L Thompson CeedTransposeMode tmode, const CeedInt Add, 242f86a920SJeremy L Thompson const CeedScalar *restrict u, 252f86a920SJeremy L Thompson CeedScalar *restrict v) { 262f86a920SJeremy L Thompson CeedInt tstride0 = B, tstride1 = 1; 272f86a920SJeremy L Thompson if (tmode == CEED_TRANSPOSE) { 282f86a920SJeremy L Thompson tstride0 = 1; tstride1 = J; 292f86a920SJeremy L Thompson } 302f86a920SJeremy L Thompson 312f86a920SJeremy L Thompson if (!Add) 322f86a920SJeremy L Thompson for (CeedInt q=0; q<A*J*C; q++) 332f86a920SJeremy L Thompson v[q] = (CeedScalar) 0.0; 342f86a920SJeremy L Thompson 352f86a920SJeremy L Thompson for (CeedInt a=0; a<A; a++) 362f86a920SJeremy L Thompson for (CeedInt b=0; b<B; b++) 372f86a920SJeremy L Thompson for (CeedInt j=0; j<J; j++) { 382f86a920SJeremy L Thompson CeedScalar tq = t[j*tstride0 + b*tstride1]; 392f86a920SJeremy L Thompson for (CeedInt c=0; c<C; c++) 402f86a920SJeremy L Thompson v[(a*J+j)*C+c] += tq * u[(a*B+b)*C+c]; 412f86a920SJeremy L Thompson } 422f86a920SJeremy L Thompson return 0; 432f86a920SJeremy L Thompson } 442f86a920SJeremy L Thompson 452f86a920SJeremy L Thompson static int CeedTensorContractDestroy_Ref(CeedTensorContract contract) { 462f86a920SJeremy L Thompson return 0; 472f86a920SJeremy L Thompson } 482f86a920SJeremy L Thompson 49*c71e1dcdSjeremylt int CeedTensorContractCreate_Ref(CeedBasis basis, CeedTensorContract contract) { 502f86a920SJeremy L Thompson int ierr; 512f86a920SJeremy L Thompson Ceed ceed; 522f86a920SJeremy L Thompson ierr = CeedTensorContractGetCeed(contract, &ceed); CeedChk(ierr); 532f86a920SJeremy L Thompson 542f86a920SJeremy L Thompson ierr = CeedSetBackendFunction(ceed, "TensorContract", contract, "Apply", 552f86a920SJeremy L Thompson CeedTensorContractApply_Ref); CeedChk(ierr); 562f86a920SJeremy L Thompson ierr = CeedSetBackendFunction(ceed, "TensorContract", contract, "Destroy", 572f86a920SJeremy L Thompson CeedTensorContractDestroy_Ref); CeedChk(ierr); 582f86a920SJeremy L Thompson 592f86a920SJeremy L Thompson return 0; 602f86a920SJeremy L Thompson } 61