11d102b48SJeremy L Thompson // Copyright (c) 2017-2018, Lawrence Livermore National Security, LLC. 21d102b48SJeremy L Thompson // Produced at the Lawrence Livermore National Laboratory. LLNL-CODE-734707. 31d102b48SJeremy L Thompson // All Rights reserved. See files LICENSE and NOTICE for details. 41d102b48SJeremy L Thompson // 51d102b48SJeremy L Thompson // This file is part of CEED, a collection of benchmarks, miniapps, software 61d102b48SJeremy L Thompson // libraries and APIs for efficient high-order finite element and spectral 71d102b48SJeremy L Thompson // element discretizations for exascale applications. For more information and 81d102b48SJeremy L Thompson // source code availability see http://github.com/ceed. 91d102b48SJeremy L Thompson // 101d102b48SJeremy L Thompson // The CEED research is supported by the Exascale Computing Project 17-SC-20-SC, 111d102b48SJeremy L Thompson // a collaborative effort of two U.S. Department of Energy organizations (Office 121d102b48SJeremy L Thompson // of Science and the National Nuclear Security Administration) responsible for 131d102b48SJeremy L Thompson // the planning and preparation of a capable exascale ecosystem, including 141d102b48SJeremy L Thompson // software, applications, hardware, advanced system engineering and early 151d102b48SJeremy L Thompson // testbed platforms, in support of the nation's exascale computing imperative. 161d102b48SJeremy L Thompson 171d102b48SJeremy L Thompson CEED_QFUNCTION(setup)(void *ctx, const CeedInt Q, 181d102b48SJeremy L Thompson const CeedScalar *const *in, 191d102b48SJeremy L Thompson CeedScalar *const *out) { 201d102b48SJeremy L Thompson // At every quadrature point, compute qw/det(J).adj(J).adj(J)^T and store 211d102b48SJeremy L Thompson // the symmetric part of the result. 221d102b48SJeremy L Thompson 231d102b48SJeremy L Thompson // in[0] is Jacobians with shape [2, nc=2, Q] 241d102b48SJeremy L Thompson // in[1] is quadrature weights, size (Q) 251d102b48SJeremy L Thompson const CeedScalar *J = in[0], *qw = in[1]; 261d102b48SJeremy L Thompson 271d102b48SJeremy L Thompson // out[0] is qdata, size (Q) 281d102b48SJeremy L Thompson CeedScalar *qd = out[0]; 291d102b48SJeremy L Thompson 301d102b48SJeremy L Thompson // Quadrature point loop 311d102b48SJeremy L Thompson for (CeedInt i=0; i<Q; i++) { 321d102b48SJeremy L Thompson // J: 0 2 qd: 0 2 adj(J): J22 -J12 331d102b48SJeremy L Thompson // 1 3 2 1 -J21 J11 341d102b48SJeremy L Thompson const CeedScalar J11 = J[i+Q*0]; 351d102b48SJeremy L Thompson const CeedScalar J21 = J[i+Q*1]; 361d102b48SJeremy L Thompson const CeedScalar J12 = J[i+Q*2]; 371d102b48SJeremy L Thompson const CeedScalar J22 = J[i+Q*3]; 381d102b48SJeremy L Thompson const CeedScalar w = qw[i] / (J11*J22 - J21*J12); 391d102b48SJeremy L Thompson qd[i+Q*0] = w * (J12*J12 + J22*J22); 401d102b48SJeremy L Thompson qd[i+Q*2] = w * (J11*J11 + J21*J21); 411d102b48SJeremy L Thompson qd[i+Q*1] = - w * (J11*J12 + J21*J22); 421d102b48SJeremy L Thompson } 431d102b48SJeremy L Thompson 441d102b48SJeremy L Thompson return 0; 451d102b48SJeremy L Thompson } 461d102b48SJeremy L Thompson 471d102b48SJeremy L Thompson CEED_QFUNCTION(diff)(void *ctx, const CeedInt Q, const CeedScalar *const *in, 481d102b48SJeremy L Thompson CeedScalar *const *out) { 491d102b48SJeremy L Thompson // in[0] is gradient u, shape [2, nc=1, Q] 501d102b48SJeremy L Thompson // in[1] is quadrature data, size (3*Q) 511d102b48SJeremy L Thompson const CeedScalar *du = in[0], *qd = in[1]; 521d102b48SJeremy L Thompson 531d102b48SJeremy L Thompson // out[0] is output to multiply against gradient v, shape [2, nc=1, Q] 541d102b48SJeremy L Thompson CeedScalar *dv = out[0]; 551d102b48SJeremy L Thompson 561d102b48SJeremy L Thompson // Quadrature point loop 571d102b48SJeremy L Thompson for (CeedInt i=0; i<Q; i++) { 581d102b48SJeremy L Thompson const CeedScalar du0 = du[i+Q*0]; 591d102b48SJeremy L Thompson const CeedScalar du1 = du[i+Q*1]; 601d102b48SJeremy L Thompson dv[i+Q*0] = qd[i+Q*0]*du0 + qd[i+Q*2]*du1; 611d102b48SJeremy L Thompson dv[i+Q*1] = qd[i+Q*2]*du0 + qd[i+Q*1]*du1; 621d102b48SJeremy L Thompson } 631d102b48SJeremy L Thompson 641d102b48SJeremy L Thompson return 0; 651d102b48SJeremy L Thompson } 661d102b48SJeremy L Thompson 671d102b48SJeremy L Thompson CEED_QFUNCTION(diff_lin)(void *ctx, const CeedInt Q, 68*7f823360Sjeremylt const CeedScalar *const *in, CeedScalar *const *out) { 691d102b48SJeremy L Thompson // in[0] is gradient u, shape [2, nc=1, Q] 701d102b48SJeremy L Thompson // in[1] is quadrature data, size (4*Q) 711d102b48SJeremy L Thompson const CeedScalar *du = in[0], *qd = in[1]; 721d102b48SJeremy L Thompson 731d102b48SJeremy L Thompson // out[0] is output to multiply against gradient v, shape [2, nc=1, Q] 741d102b48SJeremy L Thompson CeedScalar *dv = out[0]; 751d102b48SJeremy L Thompson 761d102b48SJeremy L Thompson // Quadrature point loop 771d102b48SJeremy L Thompson for (CeedInt i=0; i<Q; i++) { 781d102b48SJeremy L Thompson const CeedScalar du0 = du[i+Q*0]; 791d102b48SJeremy L Thompson const CeedScalar du1 = du[i+Q*1]; 801d102b48SJeremy L Thompson // Linearized Qdata is provided column-major 811d102b48SJeremy L Thompson // 0 2 821d102b48SJeremy L Thompson // 1 3 831d102b48SJeremy L Thompson dv[i+Q*0] = qd[i+Q*0]*du0 + qd[i+Q*2]*du1; 841d102b48SJeremy L Thompson dv[i+Q*1] = qd[i+Q*1]*du0 + qd[i+Q*3]*du1; 851d102b48SJeremy L Thompson } 861d102b48SJeremy L Thompson 871d102b48SJeremy L Thompson return 0; 881d102b48SJeremy L Thompson } 89