MFEM v4.7.0
Finite element discretization library
Loading...
Searching...
No Matches
tmop_pa_w2_c0.cpp
Go to the documentation of this file.
1// Copyright (c) 2010-2024, 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 "../tmop.hpp"
13#include "tmop_pa.hpp"
14#include "../linearform.hpp"
17
18namespace mfem
19{
20
22 const real_t lim_normal,
23 const Vector &lim_dist,
24 const Vector &c0_,
25 const int NE,
26 const DenseTensor &j_,
27 const Array<real_t> &w_,
28 const Array<real_t> &b_,
29 const Array<real_t> &bld_,
30 const Vector &x0_,
31 const Vector &x1_,
32 const Vector &ones,
33 Vector &energy,
34 const bool exp_lim,
35 const int d1d,
36 const int q1d)
37{
38 const bool const_c0 = c0_.Size() == 1;
39
40 constexpr int DIM = 2;
41 constexpr int NBZ = 1;
42
43 const int D1D = T_D1D ? T_D1D : d1d;
44 const int Q1D = T_Q1D ? T_Q1D : q1d;
45
46 const auto C0 = const_c0 ?
47 Reshape(c0_.Read(), 1, 1, 1) :
48 Reshape(c0_.Read(), Q1D, Q1D, NE);
49 const auto LD = Reshape(lim_dist.Read(), D1D, D1D, NE);
50 const auto J = Reshape(j_.Read(), DIM, DIM, Q1D, Q1D, NE);
51 const auto b = Reshape(b_.Read(), Q1D, D1D);
52 const auto bld = Reshape(bld_.Read(), Q1D, D1D);
53 const auto W = Reshape(w_.Read(), Q1D, Q1D);
54 const auto X0 = Reshape(x0_.Read(), D1D, D1D, DIM, NE);
55 const auto X1 = Reshape(x1_.Read(), D1D, D1D, DIM, NE);
56
57 auto E = Reshape(energy.Write(), Q1D, Q1D, NE);
58
59 mfem::forall_2D_batch(NE, Q1D, Q1D, NBZ, [=] MFEM_HOST_DEVICE (int e)
60 {
61 const int D1D = T_D1D ? T_D1D : d1d;
62 const int Q1D = T_Q1D ? T_Q1D : q1d;
63 constexpr int NBZ = 1;
64 constexpr int MQ1 = T_Q1D ? T_Q1D : T_MAX;
65 constexpr int MD1 = T_D1D ? T_D1D : T_MAX;
66
67 MFEM_SHARED real_t B[MQ1*MD1];
68 MFEM_SHARED real_t BLD[MQ1*MD1];
69
70 MFEM_SHARED real_t XY[NBZ][MD1*MD1];
71 MFEM_SHARED real_t DQ[NBZ][MD1*MQ1];
72 MFEM_SHARED real_t QQ[NBZ][MQ1*MQ1];
73
74 MFEM_SHARED real_t XY0[2][NBZ][MD1*MD1];
75 MFEM_SHARED real_t DQ0[2][NBZ][MD1*MQ1];
76 MFEM_SHARED real_t QQ0[2][NBZ][MQ1*MQ1];
77
78 MFEM_SHARED real_t XY1[2][NBZ][MD1*MD1];
79 MFEM_SHARED real_t DQ1[2][NBZ][MD1*MQ1];
80 MFEM_SHARED real_t QQ1[2][NBZ][MQ1*MQ1];
81
82 kernels::internal::LoadX<MD1,NBZ>(e,D1D,LD,XY);
83 kernels::internal::LoadX<MD1,NBZ>(e,D1D,X0,XY0);
84 kernels::internal::LoadX<MD1,NBZ>(e,D1D,X1,XY1);
85
86 kernels::internal::LoadB<MD1,MQ1>(D1D,Q1D,b,B);
87 kernels::internal::LoadB<MD1,MQ1>(D1D,Q1D,bld,BLD);
88
89 kernels::internal::EvalX<MD1,MQ1,NBZ>(D1D,Q1D,BLD,XY,DQ);
90 kernels::internal::EvalY<MD1,MQ1,NBZ>(D1D,Q1D,BLD,DQ,QQ);
91
92 kernels::internal::EvalX<MD1,MQ1,NBZ>(D1D,Q1D,B,XY0,DQ0);
93 kernels::internal::EvalY<MD1,MQ1,NBZ>(D1D,Q1D,B,DQ0,QQ0);
94
95 kernels::internal::EvalX<MD1,MQ1,NBZ>(D1D,Q1D,B,XY1,DQ1);
96 kernels::internal::EvalY<MD1,MQ1,NBZ>(D1D,Q1D,B,DQ1,QQ1);
97
98 MFEM_FOREACH_THREAD(qy,y,Q1D)
99 {
100 MFEM_FOREACH_THREAD(qx,x,Q1D)
101 {
102 real_t ld, p0[2], p1[2];
103 const real_t *Jtr = &J(0,0,qx,qy,e);
104 const real_t detJtr = kernels::Det<2>(Jtr);
105 const real_t weight = W(qx,qy) * detJtr;
106 const real_t coeff0 = const_c0 ? C0(0,0,0) : C0(qx,qy,e);
107 kernels::internal::PullEval<MQ1,NBZ>(Q1D,qx,qy,QQ,ld);
108 kernels::internal::PullEval<MQ1,NBZ>(Q1D,qx,qy,QQ0,p0);
109 kernels::internal::PullEval<MQ1,NBZ>(Q1D,qx,qy,QQ1,p1);
110 const real_t dist = ld; // GetValues, default comp set to 0
111 real_t id2 = 0.0;
112 real_t dsq = 0.0;
113 if (!exp_lim)
114 {
115 id2 = 0.5 / (dist*dist);
116 dsq = kernels::DistanceSquared<2>(p1,p0) * id2;
117 E(qx,qy,e) = weight * lim_normal * dsq * coeff0;
118 }
119 else
120 {
121 id2 = 1.0 / (dist*dist);
122 dsq = kernels::DistanceSquared<2>(p1,p0) * id2;
123 E(qx,qy,e) = weight * lim_normal * exp(10.0*(dsq-1.0)) * coeff0;
124 }
125 }
126 }
127 });
128 return energy * ones;
129}
130
132{
133 const int N = PA.ne;
134 const int D1D = PA.maps->ndof;
135 const int Q1D = PA.maps->nqpt;
136 const int id = (D1D << 4 ) | Q1D;
137 const real_t ln = lim_normal;
138 const Vector &LD = PA.LD;
139 const DenseTensor &J = PA.Jtr;
140 const Array<real_t> &W = PA.ir->GetWeights();
141 const Array<real_t> &B = PA.maps->B;
142 const Array<real_t> &BLD = PA.maps_lim->B;
143 MFEM_VERIFY(PA.maps_lim->ndof == D1D, "");
144 MFEM_VERIFY(PA.maps_lim->nqpt == Q1D, "");
145 const Vector &X0 = PA.X0;
146 const Vector &C0 = PA.C0;
147 const Vector &O = PA.O;
148 Vector &E = PA.E;
149
150 auto el = dynamic_cast<TMOP_ExponentialLimiter *>(lim_func);
151 const bool exp_lim = (el) ? true : false;
152
153 MFEM_LAUNCH_TMOP_KERNEL(EnergyPA_C0_2D,id,ln,LD,C0,N,J,W,B,BLD,X0,X,O,E,
154 exp_lim);
155}
156
157} // namespace mfem
const T * Read(bool on_dev=true) const
Shortcut for mfem::Read(a.GetMemory(), a.Size(), on_dev).
Definition array.hpp:317
Rank 3 tensor (array of matrices)
const real_t * Read(bool on_dev=true) const
Shortcut for mfem::Read( GetMemory(), TotalSize(), on_dev).
Exponential limiter function in TMOP_Integrator.
Definition tmop.hpp:1224
real_t GetLocalStateEnergyPA_C0_2D(const Vector &) const
TMOP_LimiterFunction * lim_func
Definition tmop.hpp:1765
struct mfem::TMOP_Integrator::@23 PA
Vector data type.
Definition vector.hpp:80
virtual const real_t * Read(bool on_dev=true) const
Shortcut for mfem::Read(vec.GetMemory(), vec.Size(), on_dev).
Definition vector.hpp:474
int Size() const
Returns the size of the vector.
Definition vector.hpp:218
virtual real_t * Write(bool on_dev=true)
Shortcut for mfem::Write(vec.GetMemory(), vec.Size(), on_dev).
Definition vector.hpp:482
real_t b
Definition lissajous.cpp:42
constexpr int DIM
MFEM_HOST_DEVICE real_t DistanceSquared(const real_t *x, const real_t *y)
Compute the square of the Euclidean distance to another vector.
Definition kernels.hpp:40
MFEM_HOST_DEVICE T Det(const T *data)
Compute the determinant of a square matrix of size dim with given data.
Definition kernels.hpp:237
MFEM_REGISTER_TMOP_KERNELS(void, DatcSize, const int NE, const int ncomp, const int sizeidx, const real_t input_min_size, const DenseMatrix &w_, const Array< real_t > &b_, const Vector &x_, const Vector &nc_reduce, DenseTensor &j_, const int d1d, const int q1d)
MFEM_HOST_DEVICE DeviceTensor< sizeof...(Dims), T > Reshape(T *ptr, Dims... dims)
Wrap a pointer as a DeviceTensor with automatically deduced template parameters.
Definition dtensor.hpp:131
void forall_2D_batch(int N, int X, int Y, int BZ, lambda &&body)
Definition forall.hpp:769
float real_t
Definition config.hpp:43