15aed82e4SJeremy L Thompson // Copyright (c) 2017-2024, Lawrence Livermore National Security, LLC and other CEED contributors. 23d8e8822SJeremy L Thompson // All Rights Reserved. See the top-level LICENSE and NOTICE files for details. 3cb32e2e7SValeria Barra // 43d8e8822SJeremy L Thompson // SPDX-License-Identifier: BSD-2-Clause 5cb32e2e7SValeria Barra // 63d8e8822SJeremy L Thompson // This file is part of CEED: http://github.com/ceed 7cb32e2e7SValeria Barra 8cb32e2e7SValeria Barra /// @file 9cb32e2e7SValeria Barra /// libCEED QFunctions for mass operator example using PETSc 10cb32e2e7SValeria Barra 11*c0b5abf0SJeremy L Thompson #include <ceed/types.h> 12*c0b5abf0SJeremy L Thompson #ifndef CEED_RUNNING_JIT_PASS 13cb32e2e7SValeria Barra #include <math.h> 14*c0b5abf0SJeremy L Thompson #endif 15cb32e2e7SValeria Barra 16e83e87a5Sjeremylt // ----------------------------------------------------------------------------- 17ea61e9acSJeremy L Thompson // This QFunction sets up the geometric factors required to apply the mass operator 18ed264d09SValeria Barra // 199b072555Sjeremylt // The quadrature data is stored in the array q_data. 20ed264d09SValeria Barra // 21ea61e9acSJeremy L Thompson // We require the determinant of the Jacobian to properly compute integrals of the form: int( u v ) 22ed264d09SValeria Barra // 239b072555Sjeremylt // Qdata: det_J * w 24ed264d09SValeria Barra // 25cb32e2e7SValeria Barra // ----------------------------------------------------------------------------- 262b730f8bSJeremy L Thompson CEED_QFUNCTION(SetupMassGeo)(void *ctx, const CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 27d4d45553Srezgarshakeri // Inputs 28d4d45553Srezgarshakeri const CeedScalar(*J)[3][CEED_Q_VLA] = (const CeedScalar(*)[3][CEED_Q_VLA])in[1]; 29d4d45553Srezgarshakeri const CeedScalar(*w) = in[2]; // Note: *X = in[0] 30d4d45553Srezgarshakeri // Outputs 319b072555Sjeremylt CeedScalar *q_data = out[0]; 32cb32e2e7SValeria Barra 33d4d45553Srezgarshakeri const CeedInt dim = 3; 34cb32e2e7SValeria Barra // Quadrature Point Loop 352b730f8bSJeremy L Thompson CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) { 36d4d45553Srezgarshakeri // Setup 37d4d45553Srezgarshakeri CeedScalar A[3][3]; 38d4d45553Srezgarshakeri for (CeedInt j = 0; j < dim; j++) { 39d4d45553Srezgarshakeri for (CeedInt k = 0; k < dim; k++) { 40d4d45553Srezgarshakeri // Equivalent code with no mod operations: 41d4d45553Srezgarshakeri // A[k][j] = J[k+1][j+1]*J[k+2][j+2] - J[k+1][j+2]*J[k+2][j+1] 42d4d45553Srezgarshakeri A[k][j] = J[(k + 1) % dim][(j + 1) % dim][i] * J[(k + 2) % dim][(j + 2) % dim][i] - 43d4d45553Srezgarshakeri J[(k + 1) % dim][(j + 2) % dim][i] * J[(k + 2) % dim][(j + 1) % dim][i]; 44d4d45553Srezgarshakeri } 45d4d45553Srezgarshakeri } 46d4d45553Srezgarshakeri const CeedScalar detJ = J[0][0][i] * A[0][0] + J[0][1][i] * A[0][1] + J[0][2][i] * A[0][2]; 47d4d45553Srezgarshakeri q_data[i] = detJ * w[i]; 48cb32e2e7SValeria Barra } // End of Quadrature Point Loop 49cb32e2e7SValeria Barra return 0; 50cb32e2e7SValeria Barra } 51cb32e2e7SValeria Barra 52e83e87a5Sjeremylt // ----------------------------------------------------------------------------- 53ed264d09SValeria Barra // This QFunction sets up the rhs and true solution for the problem 54cb32e2e7SValeria Barra // ----------------------------------------------------------------------------- 552b730f8bSJeremy L Thompson CEED_QFUNCTION(SetupMassRhs)(void *ctx, const CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 56e83e87a5Sjeremylt const CeedScalar *x = in[0], *w = in[1]; 57cb32e2e7SValeria Barra CeedScalar *true_soln = out[0], *rhs = out[1]; 58cb32e2e7SValeria Barra 59cb32e2e7SValeria Barra // Quadrature Point Loop 602b730f8bSJeremy L Thompson CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) { 61cb32e2e7SValeria Barra true_soln[i] = sqrt(x[i] * x[i] + x[i + Q] * x[i + Q] + x[i + 2 * Q] * x[i + 2 * Q]); 62e83e87a5Sjeremylt rhs[i] = w[i] * true_soln[i]; 63cb32e2e7SValeria Barra } // End of Quadrature Point Loop 64cb32e2e7SValeria Barra return 0; 65cb32e2e7SValeria Barra } 66cb32e2e7SValeria Barra 67e83e87a5Sjeremylt // ----------------------------------------------------------------------------- 68ed264d09SValeria Barra // This QFunction applies the mass operator for a scalar field. 69ed264d09SValeria Barra // 70ed264d09SValeria Barra // Inputs: 71ed264d09SValeria Barra // u - Input vector at quadrature points 729b072555Sjeremylt // q_data - Geometric factors 73ed264d09SValeria Barra // 74ed264d09SValeria Barra // Output: 75ed264d09SValeria Barra // v - Output vector (test functions) at quadrature points 76cb32e2e7SValeria Barra // ----------------------------------------------------------------------------- 772b730f8bSJeremy L Thompson CEED_QFUNCTION(Mass)(void *ctx, const CeedInt Q, const CeedScalar *const *in, CeedScalar *const *out) { 789b072555Sjeremylt const CeedScalar *u = in[0], *q_data = in[1]; 79cb32e2e7SValeria Barra CeedScalar *v = out[0]; 80cb32e2e7SValeria Barra 81cb32e2e7SValeria Barra // Quadrature Point Loop 822b730f8bSJeremy L Thompson CeedPragmaSIMD for (CeedInt i = 0; i < Q; i++) v[i] = q_data[i] * u[i]; 83cb32e2e7SValeria Barra 84cb32e2e7SValeria Barra return 0; 85cb32e2e7SValeria Barra } 86cb32e2e7SValeria Barra // ----------------------------------------------------------------------------- 87