1*b7ec98d8SJeremy L Thompson // Copyright (c) 2017-2018, Lawrence Livermore National Security, LLC. 2*b7ec98d8SJeremy L Thompson // Produced at the Lawrence Livermore National Laboratory. LLNL-CODE-734707. 3*b7ec98d8SJeremy L Thompson // All Rights reserved. See files LICENSE and NOTICE for details. 4*b7ec98d8SJeremy L Thompson // 5*b7ec98d8SJeremy L Thompson // This file is part of CEED, a collection of benchmarks, miniapps, software 6*b7ec98d8SJeremy L Thompson // libraries and APIs for efficient high-order finite element and spectral 7*b7ec98d8SJeremy L Thompson // element discretizations for exascale applications. For more information and 8*b7ec98d8SJeremy L Thompson // source code availability see http://github.com/ceed. 9*b7ec98d8SJeremy L Thompson // 10*b7ec98d8SJeremy L Thompson // The CEED research is supported by the Exascale Computing Project 17-SC-20-SC, 11*b7ec98d8SJeremy L Thompson // a collaborative effort of two U.S. Department of Energy organizations (Office 12*b7ec98d8SJeremy L Thompson // of Science and the National Nuclear Security Administration) responsible for 13*b7ec98d8SJeremy L Thompson // the planning and preparation of a capable exascale ecosystem, including 14*b7ec98d8SJeremy L Thompson // software, applications, hardware, advanced system engineering and early 15*b7ec98d8SJeremy L Thompson // testbed platforms, in support of the nation's exascale computing imperative. 16*b7ec98d8SJeremy L Thompson 17*b7ec98d8SJeremy L Thompson CEED_QFUNCTION(setup_mass)(void *ctx, const CeedInt Q, 18*b7ec98d8SJeremy L Thompson const CeedScalar *const *in, 19*b7ec98d8SJeremy L Thompson CeedScalar *const *out) { 20*b7ec98d8SJeremy L Thompson const CeedScalar *J = in[0], *weight = in[1]; 21*b7ec98d8SJeremy L Thompson CeedScalar *rho = out[0]; 22*b7ec98d8SJeremy L Thompson for (CeedInt i=0; i<Q; i++) { 23*b7ec98d8SJeremy L Thompson rho[i] = weight[i] * (J[i+Q*0]*J[i+Q*3] - J[i+Q*1]*J[i+Q*2]); 24*b7ec98d8SJeremy L Thompson } 25*b7ec98d8SJeremy L Thompson return 0; 26*b7ec98d8SJeremy L Thompson } 27*b7ec98d8SJeremy L Thompson 28*b7ec98d8SJeremy L Thompson CEED_QFUNCTION(setup_diff)(void *ctx, const CeedInt Q, 29*b7ec98d8SJeremy L Thompson const CeedScalar *const *in, 30*b7ec98d8SJeremy L Thompson CeedScalar *const *out) { 31*b7ec98d8SJeremy L Thompson // At every quadrature point, compute qw/det(J).adj(J).adj(J)^T and store 32*b7ec98d8SJeremy L Thompson // the symmetric part of the result. 33*b7ec98d8SJeremy L Thompson 34*b7ec98d8SJeremy L Thompson // in[0] is Jacobians with shape [2, nc=2, Q] 35*b7ec98d8SJeremy L Thompson // in[1] is quadrature weights, size (Q) 36*b7ec98d8SJeremy L Thompson const CeedScalar *J = in[0], *qw = in[1]; 37*b7ec98d8SJeremy L Thompson 38*b7ec98d8SJeremy L Thompson // out[0] is qdata, size (Q) 39*b7ec98d8SJeremy L Thompson CeedScalar *qd = out[0]; 40*b7ec98d8SJeremy L Thompson 41*b7ec98d8SJeremy L Thompson // Quadrature point loop 42*b7ec98d8SJeremy L Thompson for (CeedInt i=0; i<Q; i++) { 43*b7ec98d8SJeremy L Thompson // J: 0 2 qd: 0 2 adj(J): J22 -J12 44*b7ec98d8SJeremy L Thompson // 1 3 2 1 -J21 J11 45*b7ec98d8SJeremy L Thompson const CeedScalar J11 = J[i+Q*0]; 46*b7ec98d8SJeremy L Thompson const CeedScalar J21 = J[i+Q*1]; 47*b7ec98d8SJeremy L Thompson const CeedScalar J12 = J[i+Q*2]; 48*b7ec98d8SJeremy L Thompson const CeedScalar J22 = J[i+Q*3]; 49*b7ec98d8SJeremy L Thompson const CeedScalar w = qw[i] / (J11*J22 - J21*J12); 50*b7ec98d8SJeremy L Thompson qd[i+Q*0] = w * (J12*J12 + J22*J22); 51*b7ec98d8SJeremy L Thompson qd[i+Q*1] = w * (J11*J11 + J21*J21); 52*b7ec98d8SJeremy L Thompson qd[i+Q*2] = - w * (J11*J12 + J21*J22); 53*b7ec98d8SJeremy L Thompson } 54*b7ec98d8SJeremy L Thompson 55*b7ec98d8SJeremy L Thompson return 0; 56*b7ec98d8SJeremy L Thompson } 57*b7ec98d8SJeremy L Thompson 58*b7ec98d8SJeremy L Thompson CEED_QFUNCTION(apply)(void *ctx, const CeedInt Q, const CeedScalar *const *in, 59*b7ec98d8SJeremy L Thompson CeedScalar *const *out) { 60*b7ec98d8SJeremy L Thompson // in[0] is gradient u, shape [2, nc=1, Q] 61*b7ec98d8SJeremy L Thompson // in[1] is mass quadrature data, size (Q) 62*b7ec98d8SJeremy L Thompson // in[2] is Poisson quadrature data, size (Q) 63*b7ec98d8SJeremy L Thompson // in[3] is u, size (Q) 64*b7ec98d8SJeremy L Thompson const CeedScalar *du = in[0], *qd_mass = in[1], *qd_diff = in[2], *u = in[3]; 65*b7ec98d8SJeremy L Thompson 66*b7ec98d8SJeremy L Thompson // out[0] is output to multiply against v, size (Q) 67*b7ec98d8SJeremy L Thompson // out[1] is output to multiply against gradient v, shape [2, nc=1, Q] 68*b7ec98d8SJeremy L Thompson CeedScalar *v = out[0], *dv = out[1]; 69*b7ec98d8SJeremy L Thompson 70*b7ec98d8SJeremy L Thompson // Quadrature point loop 71*b7ec98d8SJeremy L Thompson for (CeedInt i=0; i<Q; i++) { 72*b7ec98d8SJeremy L Thompson // Mass 73*b7ec98d8SJeremy L Thompson v[i] = qd_mass[i]*u[i]; 74*b7ec98d8SJeremy L Thompson // Diff 75*b7ec98d8SJeremy L Thompson const CeedScalar du0 = du[i+Q*0]; 76*b7ec98d8SJeremy L Thompson const CeedScalar du1 = du[i+Q*1]; 77*b7ec98d8SJeremy L Thompson dv[i+Q*0] = qd_diff[i+Q*0]*du0 + qd_diff[i+Q*2]*du1; 78*b7ec98d8SJeremy L Thompson dv[i+Q*1] = qd_diff[i+Q*2]*du0 + qd_diff[i+Q*1]*du1; 79*b7ec98d8SJeremy L Thompson } 80*b7ec98d8SJeremy L Thompson 81*b7ec98d8SJeremy L Thompson return 0; 82*b7ec98d8SJeremy L Thompson } 83