MFEM v4.10.0
Finite element discretization library
Loading...
Searching...
No Matches
interpolate_local_3.cpp
Go to the documentation of this file.
1// Copyright (c) 2010-2026, Lawrence Livermore National Security, LLC. Produced
2// at the Lawrence Livermore National Laboratory. All Rights reserved. See files
3// LICENSE and NOTICE for details. LLNL-CODE-806117.
4//
5// This file is part of the MFEM library. For more information and source code
6// availability visit https://mfem.org.
7//
8// MFEM is free software; you can redistribute it and/or modify it under the
9// terms of the BSD-3 license. We welcome feedback and contributions, see file
10// CONTRIBUTING.md for details.
11
12#include "../gslib.hpp"
15
16#ifdef MFEM_USE_GSLIB
17
18#ifdef MFEM_HAVE_GCC_PRAGMA_DIAGNOSTIC
19#pragma GCC diagnostic push
20#pragma GCC diagnostic ignored "-Wunused-function"
21#endif
22#include "gslib.h"
23#ifndef GSLIB_RELEASE_VERSION //gslib v1.0.7
24#define GSLIB_RELEASE_VERSION 10007
25#endif
26#ifdef MFEM_HAVE_GCC_PRAGMA_DIAGNOSTIC
27#pragma GCC diagnostic pop
28#endif
29namespace mfem
30{
31#if GSLIB_RELEASE_VERSION >= 10009
32#define CODE_INTERNAL 0
33#define CODE_BORDER 1
34#define CODE_NOT_FOUND 2
35
37
38template<int T_D1D = 0>
39static void InterpolateLocal3DKernel(const double *const gf_in,
40 int *const el,
41 double *const r,
42 double *const int_out,
43 const int npt,
44 const int ncomp,
45 double *gll1D,
46 double *lagcoeff,
47 const int pN = 0)
48{
49 const int Nfields = ncomp;
50 const int MD1 = T_D1D ? T_D1D : DofQuadLimits::MAX_D1D;
51 const int D1D = T_D1D ? T_D1D : pN;
52 const int p_Np = D1D*D1D*D1D;
53 MFEM_VERIFY(MD1 <= DofQuadLimits::MAX_D1D,
54 "Increase Max allowable polynomial order.");
55 MFEM_VERIFY(D1D != 0, "Polynomial order not specified.");
56#define MAXC(a, b) (((a) > (b)) ? (a) : (b))
57 const int nThreadsy = MAXC(D1D, 3);
58 mfem::forall_2D(npt, D1D, nThreadsy, [=] MFEM_HOST_DEVICE (int i)
59 {
60 MFEM_SHARED double wtr[3*MD1];
61 MFEM_SHARED double sums[MD1*MD1];
62
63 // Evaluate basis functions at the reference space coordinates
64 MFEM_FOREACH_THREAD(j,x,D1D)
65 {
66 MFEM_FOREACH_THREAD(k,y,3)
67 {
68 lagrange_eval(wtr + k*D1D, r[3*i+k], j, D1D, gll1D, lagcoeff);
69 }
70 }
71 MFEM_SYNC_THREAD;
72
73 for (int fld = 0; fld < Nfields; ++fld)
74 {
75 // If using GetNodalValues, ordering is NDOFS x NEL x VDIM and the
76 // offset would be `el[i] * p_Np + fld * gf_offset`.
77 // R->Mult produces element vectors in NDOFS x VDIM x NEL layout.
78 const int elemOffset = el[i] * p_Np * Nfields + fld * p_Np;
79 MFEM_FOREACH_THREAD(j,x,D1D)
80 {
81 MFEM_FOREACH_THREAD(k,y,D1D)
82 {
83 sums[j + k*D1D] = 0.0;
84 for (int l = 0; l < D1D; ++l)
85 {
86 sums[j + k*D1D] += gf_in[elemOffset + j + k*D1D + l*D1D*D1D] *
87 wtr[2*D1D+l];
88 }
89 sums[j+k*D1D] *= wtr[D1D+k]*wtr[j];
90 }
91 }
92 MFEM_SYNC_THREAD;
93
94 MFEM_FOREACH_THREAD(j,x,1)
95 {
96 MFEM_FOREACH_THREAD(k,y,1)
97 {
98 double sumv = 0.0;
99 for (int jj = 0; jj < D1D*D1D; ++jj)
100 {
101 sumv += sums[jj];
102 }
103 int_out[i + fld * npt] = sumv;
104 }
105 }
106 MFEM_SYNC_THREAD;
107 }
108 });
109}
110
112 Array<int> &gsl_elem_dev_l,
113 Vector &gsl_ref_l,
114 Vector &field_out,
115 int npt, int ncomp,
116 int dof1Dsol)
117{
118 if (npt == 0) { return; }
119 bool use_dev = field_in.UseDevice();
120 auto pfin = field_in.Read(use_dev);
121 auto pgsle = gsl_elem_dev_l.ReadWrite(use_dev);
122 auto pgslr = gsl_ref_l.ReadWrite(use_dev);
123 auto pfout = field_out.Write(use_dev);
124 auto pgll = DEV.gll1d_sol.ReadWrite(use_dev);
125 auto plcf = DEV.lagcoeff_sol.ReadWrite(use_dev);
126 switch (dof1Dsol)
127 {
128 case 2:
129 InterpolateLocal3DKernel<2>(pfin, pgsle, pgslr, pfout,
130 npt, ncomp, pgll, plcf);
131 break;
132 case 3:
133 InterpolateLocal3DKernel<3>(pfin, pgsle, pgslr, pfout,
134 npt, ncomp, pgll, plcf);
135 break;
136 case 4:
137 InterpolateLocal3DKernel<4>(pfin, pgsle, pgslr, pfout,
138 npt, ncomp, pgll, plcf);
139 break;
140 case 5:
141 InterpolateLocal3DKernel<5>(pfin, pgsle, pgslr, pfout,
142 npt, ncomp, pgll, plcf);
143 break;
144 default:
145 InterpolateLocal3DKernel(pfin, pgsle, pgslr, pfout,
146 npt, ncomp, pgll, plcf, dof1Dsol);
147 break;
148 }
149}
150
151
152#undef MAXC
153#undef CODE_INTERNAL
154#undef CODE_BORDER
155#undef CODE_NOT_FOUND
156#else
157void FindPointsGSLIB::InterpolateLocal3(const Vector &field_in,
158 Array<int> &gsl_elem_dev_l,
159 Vector &gsl_ref_l,
160 Vector &field_out,
161 int npt, int ncomp,
162 int dof1Dsol) {};
163#endif
164} // namespace mfem
165
166#endif //ifdef MFEM_USE_GSLIB
T * ReadWrite(bool on_dev=true)
Shortcut for mfem::ReadWrite(a.GetMemory(), a.Size(), on_dev).
Definition array.hpp:426
void InterpolateLocal3(const Vector &field_in, Array< int > &gsl_elem_dev_l, Vector &gsl_ref_l, Vector &field_out, int npt, int ncomp, int dof1dsol)
Interpolate on device for 3D.
struct mfem::FindPointsGSLIB::DevStruct DEV
Vector data type.
Definition vector.hpp:82
virtual const real_t * Read(bool on_dev=true) const
Shortcut for mfem::Read(vec.GetMemory(), vec.Size(), on_dev).
Definition vector.hpp:520
virtual real_t * ReadWrite(bool on_dev=true)
Shortcut for mfem::ReadWrite(vec.GetMemory(), vec.Size(), on_dev).
Definition vector.hpp:536
virtual void UseDevice(bool use_dev) const
Enable execution of Vector operations using the mfem::Device.
Definition vector.hpp:145
virtual real_t * Write(bool on_dev=true)
Shortcut for mfem::Write(vec.GetMemory(), vec.Size(), on_dev).
Definition vector.hpp:528
MFEM_HOST_DEVICE void lagrange_eval(double *p0, double x, int i, int p_Nq, double *z, double *lagrangeCoeff)
void forall_2D(int N, int X, int Y, lambda &&body)
Definition forall.hpp:1220