MFEM v4.10.0
Finite element discretization library
Loading...
Searching...
No Matches
interpolate_local_1.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 InterpolateLocal1DKernel(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 nfields,
45 double *gll1D,
46 double *lagcoeff,
47 const int pN = 0)
48{
49 const int MD1 = T_D1D ? T_D1D : DofQuadLimits::MAX_D1D;
50 const int D1D = T_D1D ? T_D1D : pN;
51 const int p_Nq = D1D;
52 MFEM_VERIFY(MD1 <= DofQuadLimits::MAX_D1D,
53 "Increase Max allowable polynomial order.");
54 MFEM_VERIFY(pN<=DofQuadLimits::MAX_D1D,
55 "Increase Max allowable polynomial order.");
56 MFEM_VERIFY(D1D != 0, "Polynomial order not specified.");
57 // for each point of the npt points, create a thread block of size dof1Dsol
58 mfem::forall_2D(npt, D1D, 1, [=] MFEM_HOST_DEVICE (int i)
59 {
60 MFEM_SHARED double wtr[MD1];
61 MFEM_SHARED double sums[MD1];
62
63 // Evaluate basis functions at the reference space coordinates
64 MFEM_FOREACH_THREAD(j,x,D1D)
65 {
66 lagrange_eval(wtr, r[i], j, p_Nq, gll1D, lagcoeff);
67 }
68 MFEM_SYNC_THREAD;
69
70 for (int fld=0; fld<nfields; ++fld)
71 {
72 // If using GetNodalValues, ordering is NDOFS x NEL x VDIM and the
73 // offset would be `el[i] * p_Nq + fld * gf_offset`.
74 // R->Mult produces element vectors in NDOFS x VDIM x NEL layout.
75 const int elemOffset = el[i]*nfields*p_Nq + fld*p_Nq;
76 MFEM_FOREACH_THREAD(j,x,D1D)
77 {
78 sums[j] = wtr[j] * gf_in[elemOffset + j];
79 }
80 MFEM_SYNC_THREAD;
81
82 MFEM_FOREACH_THREAD(j,x,1)
83 {
84 double sumv = 0.0;
85 // sum the contributions of each lagrange polynomial
86 for (int jj=0; jj<D1D; ++jj)
87 {
88 sumv += sums[jj];
89 }
90 int_out[fld*npt + i] = sumv;
91 }
92 MFEM_SYNC_THREAD;
93 }
94 });
95}
96
98 Array<int> &gsl_elem_dev_l,
99 Vector &gsl_ref_l,
100 Vector &field_out,
101 int npt,
102 int ncomp,
103 int dof1Dsol )
104{
105 MFEM_VERIFY(dim == 1, "Kernel for edges only.");
106 if (npt == 0) { return; }
107 bool use_dev = field_in.UseDevice();
108 auto pfin = field_in.Read(use_dev);
109 auto pgsl = gsl_elem_dev_l.ReadWrite(use_dev);
110 auto pgslr = gsl_ref_l.ReadWrite(use_dev);
111 auto pfout = field_out.Write(use_dev);
112 auto pgll = DEV.gll1d_sol.ReadWrite(use_dev);
113 auto plcf = DEV.lagcoeff_sol.ReadWrite(use_dev);
114 switch (dof1Dsol)
115 {
116 case 2:
117 InterpolateLocal1DKernel<2>(pfin, pgsl, pgslr, pfout,
118 npt, ncomp, pgll, plcf);
119 break;
120 case 3:
121 InterpolateLocal1DKernel<3>(pfin, pgsl, pgslr, pfout,
122 npt, ncomp, pgll, plcf);
123 break;
124 case 4:
125 InterpolateLocal1DKernel<4>(pfin, pgsl, pgslr, pfout,
126 npt, ncomp, pgll, plcf);
127 break;
128 case 5:
129 InterpolateLocal1DKernel<5>(pfin, pgsl, pgslr, pfout,
130 npt, ncomp, pgll, plcf);
131 break;
132 default:
133 InterpolateLocal1DKernel(pfin, pgsl, pgslr, pfout,
134 npt, ncomp, pgll, plcf, dof1Dsol);
135 break;
136 }
137}
138#undef CODE_INTERNAL
139#undef CODE_BORDER
140#undef CODE_NOT_FOUND
141#else
142void FindPointsGSLIB::InterpolateLocal1(const Vector &field_in,
143 Array<int> &gsl_elem_dev_l,
144 Vector &gsl_ref_l,
145 Vector &field_out,
146 int npt, int ncomp,
147 int dof1Dsol) {};
148#endif
149
150} // namespace mfem
151
152#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 InterpolateLocal1(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 1D.
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