MFEM v4.10.0
Finite element discretization library
Loading...
Searching...
No Matches
interpolate_local_2.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 InterpolateLocal2DKernel(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;
53 MFEM_VERIFY(MD1 <= DofQuadLimits::MAX_D1D,
54 "Increase Max allowable polynomial order.");
55 MFEM_VERIFY(pN<=DofQuadLimits::MAX_D1D,
56 "Increase Max allowable polynomial order.");
57 MFEM_VERIFY(D1D != 0, "Polynomial order not specified.");
58 mfem::forall_2D(npt, D1D, D1D, [=] MFEM_HOST_DEVICE (int i)
59 {
60 MFEM_SHARED double wtr[2*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,2)
67 {
68 lagrange_eval(wtr + k*D1D, r[2*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] = gf_in[elemOffset + j + k * D1D] *
84 wtr[D1D+k] *
85 wtr[j];
86 }
87 }
88 MFEM_SYNC_THREAD;
89
90 // MFEM_FOREACH_THREAD(j,x,D1D)
91 MFEM_FOREACH_THREAD(j,x,1)
92 {
93 MFEM_FOREACH_THREAD(k,y,1)
94 {
95 double sumv = 0.0;
96 for (int jj = 0; jj < D1D*D1D; ++jj)
97 {
98 sumv += sums[jj];
99 }
100 int_out[i + fld * npt] = sumv;
101 }
102 }
103 MFEM_SYNC_THREAD;
104 }
105 });
106}
107
109 Array<int> &gsl_elem_dev_l,
110 Vector &gsl_ref_l,
111 Vector &field_out,
112 int npt, int ncomp,
113 int dof1Dsol)
114{
115 if (npt == 0) { return; }
116 bool use_dev = field_in.UseDevice();
117 auto pfin = field_in.Read(use_dev);
118 auto pgsl = gsl_elem_dev_l.ReadWrite(use_dev);
119 auto pgslr = gsl_ref_l.ReadWrite(use_dev);
120 auto pfout = field_out.Write(use_dev);
121 auto pgll = DEV.gll1d_sol.ReadWrite(use_dev);
122 auto plcf = DEV.lagcoeff_sol.ReadWrite(use_dev);
123 switch (dof1Dsol)
124 {
125 case 2:
126 InterpolateLocal2DKernel<2>(pfin, pgsl, pgslr, pfout,
127 npt, ncomp, pgll, plcf);
128 break;
129 case 3:
130 InterpolateLocal2DKernel<3>(pfin, pgsl, pgslr, pfout,
131 npt, ncomp, pgll, plcf);
132 break;
133 case 4:
134 InterpolateLocal2DKernel<4>(pfin, pgsl, pgslr, pfout,
135 npt, ncomp, pgll, plcf);
136 break;
137 case 5:
138 InterpolateLocal2DKernel<5>(pfin, pgsl, pgslr, pfout,
139 npt, ncomp, pgll, plcf);
140 break;
141 default:
142 InterpolateLocal2DKernel(pfin, pgsl, pgslr, pfout,
143 npt, ncomp, pgll, plcf, dof1Dsol);
144 break;
145 }
146}
147
148
149#undef CODE_INTERNAL
150#undef CODE_BORDER
151#undef CODE_NOT_FOUND
152#else
153void FindPointsGSLIB::InterpolateLocal2(const Vector &field_in,
154 Array<int> &gsl_elem_dev_l,
155 Vector &gsl_ref_l,
156 Vector &field_out,
157 int npt, int ncomp,
158 int dof1Dsol) {};
159#endif
160} // namespace mfem
161
162#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
struct mfem::FindPointsGSLIB::DevStruct DEV
void InterpolateLocal2(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 2D.
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