Intrepid2
Intrepid2_ProjectionToolsDefHGRAD.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ************************************************************************
3 //
4 // Intrepid2 Package
5 // Copyright (2007) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Kyungjoo Kim (kyukim@sandia.gov), or
38 // Mauro Perego (mperego@sandia.gov)
39 //
40 // ************************************************************************
41 // @HEADER
42 
49 #ifndef __INTREPID2_PROJECTIONTOOLSDEFHGRAD_HPP__
50 #define __INTREPID2_PROJECTIONTOOLSDEFHGRAD_HPP__
51 
53 #include "Intrepid2_ArrayTools.hpp"
55 
56 #include "Intrepid2_TestUtils.hpp"
57 
58 namespace Intrepid2 {
59 
60 namespace FunctorsProjectionTools {
61 
62 template<typename ViewType1, typename ViewType2, typename ViewType3,
63 typename ViewType4, typename ViewType5>
65  ViewType1 basisCoeffs_;
66  const ViewType2 tagToOrdinal_;
67  const ViewType3 targetEPointsRange_;
68  const ViewType4 targetAtTargetEPoints_;
69  const ViewType5 basisAtTargetEPoints_;
70  ordinal_type numVertices_;
71 
72 
73  ComputeBasisCoeffsOnVertices_HGRAD(ViewType1 basisCoeffs, ViewType2 tagToOrdinal, ViewType3 targetEPointsRange,
74  ViewType4 targetAtTargetEPoints, ViewType5 basisAtTargetEPoints, ordinal_type numVertices) :
75  basisCoeffs_(basisCoeffs), tagToOrdinal_(tagToOrdinal), targetEPointsRange_(targetEPointsRange),
76  targetAtTargetEPoints_(targetAtTargetEPoints), basisAtTargetEPoints_(basisAtTargetEPoints), numVertices_(numVertices) {}
77 
78  void
79  KOKKOS_INLINE_FUNCTION
80  operator()(const ordinal_type ic) const {
81 
82 
83  for(ordinal_type iv=0; iv<numVertices_; ++iv) {
84  ordinal_type idof = tagToOrdinal_(0, iv, 0);
85  ordinal_type pt = targetEPointsRange_(0,iv).first;
86  //the value of the basis at the vertex might be different than 1; HGrad basis, so the function is scalar
87  basisCoeffs_(ic,idof) = targetAtTargetEPoints_(ic,pt)/basisAtTargetEPoints_(idof,pt,0);
88  }
89  }
90 };
91 
92 template<typename ViewType1, typename ViewType2, typename ViewType3,
93 typename ViewType4, typename ViewType5>
95  const ViewType1 basisCoeffs_;
96  const ViewType1 negPartialProjGrad_;
97  const ViewType1 basisTanAtEPoints_;
98  const ViewType1 basisGradAtBasisGradEPoints_;
99  const ViewType2 basisGradEWeights_;
100  const ViewType1 wBasisAtBasisGradEPoints_;
101  const ViewType2 targetGradEWeights_;
102  const ViewType1 basisGradAtTargetGradEPoints_;
103  const ViewType1 wBasisAtTargetGradEPoints_;
104  const ViewType3 computedDofs_;
105  const ViewType4 tagToOrdinal_;
106  const ViewType1 targetGradTanAtTargetGradEPoints_;
107  const ViewType5 targetGradAtTargetGradEPoints_;
108  const ViewType1 refEdgeTan_;
109  ordinal_type edgeCardinality_;
110  ordinal_type offsetBasis_;
111  ordinal_type offsetTarget_;
112  ordinal_type numVertexDofs_;
113  ordinal_type edgeDim_;
114  ordinal_type dim_;
115  ordinal_type iedge_;
116 
117  ComputeBasisCoeffsOnEdges_HGRAD(const ViewType1 basisCoeffs, ViewType1 negPartialProjGrad, const ViewType1 basisTanAtEPoints,
118  const ViewType1 basisGradAtBasisGradEPoints, const ViewType2 basisGradEWeights, const ViewType1 wBasisAtBasisGradEPoints, const ViewType2 targetGradEWeights,
119  const ViewType1 basisGradAtTargetGradEPoints, const ViewType1 wBasisAtTargetGradEPoints, const ViewType3 computedDofs, const ViewType4 tagToOrdinal,
120  const ViewType1 targetGradTanAtTargetGradEPoints, const ViewType5 targetGradAtTargetGradEPoints, const ViewType1 refEdgeTan,
121  ordinal_type edgeCardinality, ordinal_type offsetBasis,
122  ordinal_type offsetTarget, ordinal_type numVertexDofs, ordinal_type edgeDim, ordinal_type dim, ordinal_type iedge) :
123  basisCoeffs_(basisCoeffs), negPartialProjGrad_(negPartialProjGrad), basisTanAtEPoints_(basisTanAtEPoints),
124  basisGradAtBasisGradEPoints_(basisGradAtBasisGradEPoints), basisGradEWeights_(basisGradEWeights), wBasisAtBasisGradEPoints_(wBasisAtBasisGradEPoints), targetGradEWeights_(targetGradEWeights),
125  basisGradAtTargetGradEPoints_(basisGradAtTargetGradEPoints), wBasisAtTargetGradEPoints_(wBasisAtTargetGradEPoints),
126  computedDofs_(computedDofs), tagToOrdinal_(tagToOrdinal), targetGradTanAtTargetGradEPoints_(targetGradTanAtTargetGradEPoints),
127  targetGradAtTargetGradEPoints_(targetGradAtTargetGradEPoints), refEdgeTan_(refEdgeTan),
128  edgeCardinality_(edgeCardinality), offsetBasis_(offsetBasis),
129  offsetTarget_(offsetTarget), numVertexDofs_(numVertexDofs), edgeDim_(edgeDim), dim_(dim), iedge_(iedge)
130  {}
131 
132  void
133  KOKKOS_INLINE_FUNCTION
134  operator()(const ordinal_type ic) const {
135 
136  ordinal_type numBasisGradEPoints = basisGradEWeights_.extent(0);
137  ordinal_type numTargetGradEPoints = targetGradEWeights_.extent(0);
138 
139  //this loop could be moved outside of cell loop
140  for(ordinal_type j=0; j <edgeCardinality_; ++j) {
141  ordinal_type jdof = tagToOrdinal_(edgeDim_, iedge_, j);
142 
143  for(ordinal_type iq=0; iq <numBasisGradEPoints; ++iq) {
144  typename ViewType1::value_type tmp =0;
145  for(ordinal_type d=0; d <dim_; ++d)
146  tmp += basisGradAtBasisGradEPoints_(jdof,offsetBasis_+iq,d)*refEdgeTan_(d);
147  basisTanAtEPoints_(0,j,iq) = tmp;
148  wBasisAtBasisGradEPoints_(ic,j,iq) = tmp*basisGradEWeights_(iq);
149  }
150  for(ordinal_type iq=0; iq <numTargetGradEPoints; ++iq) {
151  for(ordinal_type d=0; d <dim_; ++d)
152  wBasisAtTargetGradEPoints_(ic,j,iq) += basisGradAtTargetGradEPoints_(jdof,offsetTarget_+iq,d)*refEdgeTan_(d)*targetGradEWeights_(iq);
153  }
154  }
155 
156  for(ordinal_type iq=0; iq <numTargetGradEPoints; ++iq)
157  for(ordinal_type d=0; d <dim_; ++d)
158  targetGradTanAtTargetGradEPoints_(ic,iq) += targetGradAtTargetGradEPoints_(ic,offsetTarget_+iq,d)*refEdgeTan_(d);
159 
160  for(ordinal_type j=0; j <numVertexDofs_; ++j) {
161  ordinal_type jdof = computedDofs_(j);
162  for(ordinal_type iq=0; iq <numBasisGradEPoints; ++iq)
163  for(ordinal_type d=0; d <dim_; ++d)
164  negPartialProjGrad_(ic,iq) -= basisCoeffs_(ic,jdof)*basisGradAtBasisGradEPoints_(jdof,offsetBasis_+iq,d)*refEdgeTan_(d);
165  }
166  }
167 };
168 
169 template<typename ViewType1, typename ViewType2, typename ViewType3,
170 typename ViewType4, typename ViewType5>
172  const ViewType1 basisCoeffs_;
173  const ViewType1 negPartialProjGrad_;
174  const ViewType1 faceBasisGradAtGradEPoints_;
175  const ViewType1 basisGradAtBasisGradEPoints_;
176  const ViewType2 basisGradEWeights_;
177  const ViewType1 wBasisGradAtGradEPoints_;
178  const ViewType2 targetGradEWeights_;
179  const ViewType1 basisGradAtTargetGradEPoints_;
180  const ViewType1 wBasisGradBasisAtTargetGradEPoints_;
181  const ViewType3 computedDofs_;
182  const ViewType4 tagToOrdinal_;
183  const ViewType1 targetGradTanAtTargetGradEPoints_;
184  const ViewType5 targetGradAtTargetGradEPoints_;
185  const ViewType1 refFaceNormal_;
186  ordinal_type faceCardinality_;
187  ordinal_type offsetBasisGrad_;
188  ordinal_type offsetTargetGrad_;
189  ordinal_type numVertexEdgeDofs_;
190  ordinal_type numFaces_;
191  ordinal_type faceDim_;
192  ordinal_type dim_;
193  ordinal_type iface_;
194 
195  ComputeBasisCoeffsOnFaces_HGRAD(const ViewType1 basisCoeffs, ViewType1 negPartialProjGrad, const ViewType1 faceBasisGradAtGradEPoints,
196  const ViewType1 basisGradAtBasisGradEPoints, const ViewType2 basisGradEWeights, const ViewType1 wBasisGradAtGradEPoints, const ViewType2 targetGradEWeights,
197  const ViewType1 basisGradAtTargetGradEPoints, const ViewType1 wBasisGradBasisAtTargetGradEPoints, const ViewType3 computedDofs, const ViewType4 tagToOrdinal,
198  const ViewType1 targetGradTanAtTargetGradEPoints, const ViewType5 targetGradAtTargetGradEPoints,
199  const ViewType1 refFaceNormal, ordinal_type faceCardinality, ordinal_type offsetBasisGrad,
200  ordinal_type offsetTargetGrad, ordinal_type numVertexEdgeDofs, ordinal_type numFaces, ordinal_type faceDim,
201  ordinal_type dim, ordinal_type iface) :
202  basisCoeffs_(basisCoeffs), negPartialProjGrad_(negPartialProjGrad), faceBasisGradAtGradEPoints_(faceBasisGradAtGradEPoints),
203  basisGradAtBasisGradEPoints_(basisGradAtBasisGradEPoints), basisGradEWeights_(basisGradEWeights), wBasisGradAtGradEPoints_(wBasisGradAtGradEPoints),
204  targetGradEWeights_(targetGradEWeights),
205  basisGradAtTargetGradEPoints_(basisGradAtTargetGradEPoints), wBasisGradBasisAtTargetGradEPoints_(wBasisGradBasisAtTargetGradEPoints),
206  computedDofs_(computedDofs), tagToOrdinal_(tagToOrdinal), targetGradTanAtTargetGradEPoints_(targetGradTanAtTargetGradEPoints),
207  targetGradAtTargetGradEPoints_(targetGradAtTargetGradEPoints), refFaceNormal_(refFaceNormal),
208  faceCardinality_(faceCardinality), offsetBasisGrad_(offsetBasisGrad),
209  offsetTargetGrad_(offsetTargetGrad), numVertexEdgeDofs_(numVertexEdgeDofs), numFaces_(numFaces),
210  faceDim_(faceDim), dim_(dim), iface_(iface)
211  {}
212 
213  void
214  KOKKOS_INLINE_FUNCTION
215  operator()(const ordinal_type ic) const {
216 
217  ordinal_type numBasisGradEPoints = basisGradEWeights_.extent(0);
218  ordinal_type numTargetGradEPoints = targetGradEWeights_.extent(0);
219 
220  //normal
221  typename ViewType2::value_type n[3] = {refFaceNormal_(0), refFaceNormal_(1), refFaceNormal_(2)};
222 
223  for(ordinal_type j=0; j <faceCardinality_; ++j) {
224  ordinal_type jdof = tagToOrdinal_(faceDim_, iface_, j);
225  for(ordinal_type d=0; d <dim_; ++d) {
226  ordinal_type dp1 = (d+1) % dim_;
227  ordinal_type dp2 = (d+2) % dim_;
228  for(ordinal_type iq=0; iq <numBasisGradEPoints; ++iq) {
229  faceBasisGradAtGradEPoints_(0,j,iq,d) = basisGradAtBasisGradEPoints_(jdof,offsetBasisGrad_+iq,dp1)*n[dp2] - basisGradAtBasisGradEPoints_(jdof,offsetBasisGrad_+iq,dp2)*n[dp1];
230  wBasisGradAtGradEPoints_(ic,j,iq,d) = faceBasisGradAtGradEPoints_(0,j,iq,d) * basisGradEWeights_(iq);
231  }
232  for(ordinal_type iq=0; iq <numTargetGradEPoints; ++iq) {
233  wBasisGradBasisAtTargetGradEPoints_(ic,j,iq,d) = (basisGradAtTargetGradEPoints_(jdof,offsetTargetGrad_+iq,dp1)*n[dp2] - basisGradAtTargetGradEPoints_(jdof,offsetTargetGrad_+iq,dp2)*n[dp1]) * targetGradEWeights_(iq);
234  }
235  }
236  }
237 
238  for(ordinal_type d=0; d <dim_; ++d) {
239  ordinal_type dp1 = (d+1) % dim_;
240  ordinal_type dp2 = (d+2) % dim_;
241  for(ordinal_type iq=0; iq <numTargetGradEPoints; ++iq)
242  targetGradTanAtTargetGradEPoints_(ic,iq,d) = targetGradAtTargetGradEPoints_(ic,offsetTargetGrad_+iq,dp1)*n[dp2] - targetGradAtTargetGradEPoints_(ic,offsetTargetGrad_+iq,dp2)*n[dp1];
243  }
244 
245  for(ordinal_type j=0; j <numVertexEdgeDofs_; ++j) {
246  ordinal_type jdof = computedDofs_(j);
247  for(ordinal_type d=0; d <dim_; ++d) {
248  ordinal_type dp1 = (d+1) % dim_;
249  ordinal_type dp2 = (d+2) % dim_;
250  for(ordinal_type iq=0; iq <numBasisGradEPoints; ++iq)
251  negPartialProjGrad_(ic,iq,d) -= (basisGradAtBasisGradEPoints_(jdof,offsetBasisGrad_+iq,dp1)*n[dp2] - basisGradAtBasisGradEPoints_(jdof,offsetBasisGrad_+iq,dp2)*n[dp1]) * basisCoeffs_(ic,jdof);
252  }
253  }
254  }
255 };
256 
257 
258 template<typename ViewType1, typename ViewType2, typename ViewType3,
259 typename ViewType4>
261  const ViewType1 basisCoeffs_;
262  const ViewType1 negPartialProjGrad_;
263  const ViewType1 cellBasisGradAtGradEPoints_;
264  const ViewType1 basisGradAtBasisGradEPoints_;
265  const ViewType2 basisGradEWeights_;
266  const ViewType1 wBasisGradAtGradEPoints_;
267  const ViewType2 targetGradEWeights_;
268  const ViewType1 basisGradAtTargetGradEPoints_;
269  const ViewType1 wBasisGradBasisAtTargetGradEPoints_;
270  const ViewType3 computedDofs_;
271  const ViewType4 elemDof_;
272  ordinal_type dim_;
273  ordinal_type numElemDofs_;
274  ordinal_type offsetBasisGrad_;
275  ordinal_type offsetTargetGrad_;
276  ordinal_type numVertexEdgeFaceDofs_;
277 
278  ComputeBasisCoeffsOnCells_HGRAD(const ViewType1 basisCoeffs, ViewType1 negPartialProjGrad, const ViewType1 cellBasisGradAtGradEPoints,
279  const ViewType1 basisGradAtBasisGradEPoints, const ViewType2 basisGradEWeights, const ViewType1 wBasisGradAtGradEPoints, const ViewType2 targetGradEWeights,
280  const ViewType1 basisGradAtTargetGradEPoints, const ViewType1 wBasisGradBasisAtTargetGradEPoints, const ViewType3 computedDofs, const ViewType4 elemDof,
281  ordinal_type dim, ordinal_type numElemDofs, ordinal_type offsetBasisGrad, ordinal_type offsetTargetGrad, ordinal_type numVertexEdgeFaceDofs) :
282  basisCoeffs_(basisCoeffs), negPartialProjGrad_(negPartialProjGrad), cellBasisGradAtGradEPoints_(cellBasisGradAtGradEPoints),
283  basisGradAtBasisGradEPoints_(basisGradAtBasisGradEPoints), basisGradEWeights_(basisGradEWeights), wBasisGradAtGradEPoints_(wBasisGradAtGradEPoints), targetGradEWeights_(targetGradEWeights),
284  basisGradAtTargetGradEPoints_(basisGradAtTargetGradEPoints), wBasisGradBasisAtTargetGradEPoints_(wBasisGradBasisAtTargetGradEPoints),
285  computedDofs_(computedDofs), elemDof_(elemDof), dim_(dim), numElemDofs_(numElemDofs), offsetBasisGrad_(offsetBasisGrad),
286  offsetTargetGrad_(offsetTargetGrad), numVertexEdgeFaceDofs_(numVertexEdgeFaceDofs) {}
287 
288  void
289  KOKKOS_INLINE_FUNCTION
290  operator()(const ordinal_type ic) const {
291  ordinal_type numBasisGradEPoints = basisGradEWeights_.extent(0);
292  ordinal_type numTargetGradEPoints = targetGradEWeights_.extent(0);
293  for(ordinal_type j=0; j <numElemDofs_; ++j) {
294  ordinal_type idof = elemDof_(j);
295  for(ordinal_type d=0; d <dim_; ++d) {
296  for(ordinal_type iq=0; iq <numBasisGradEPoints; ++iq) {
297  cellBasisGradAtGradEPoints_(0,j,iq,d) = basisGradAtBasisGradEPoints_(idof,offsetBasisGrad_+iq,d);
298  wBasisGradAtGradEPoints_(ic,j,iq,d) = cellBasisGradAtGradEPoints_(0,j,iq,d) * basisGradEWeights_(iq);
299  }
300  for(ordinal_type iq=0; iq <numTargetGradEPoints; ++iq) {
301  wBasisGradBasisAtTargetGradEPoints_(ic,j,iq,d )= basisGradAtTargetGradEPoints_(idof,offsetTargetGrad_+iq,d) * targetGradEWeights_(iq);
302  }
303  }
304  }
305  for(ordinal_type j=0; j <numVertexEdgeFaceDofs_; ++j) {
306  ordinal_type jdof = computedDofs_(j);
307  for(ordinal_type iq=0; iq <numBasisGradEPoints; ++iq)
308  for(ordinal_type d=0; d <dim_; ++d) {
309  negPartialProjGrad_(ic,iq,d) -= basisCoeffs_(ic,jdof)*basisGradAtBasisGradEPoints_(jdof,offsetBasisGrad_+iq,d);
310  }
311  }
312  }
313 };
314 
315 } // FunctorsProjectionTools namespace
316 
317 
318 template<typename DeviceType>
319 template<class BasisCoeffsViewType, class TargetValueViewType, class TargetGradViewType, class BasisType, class OrientationViewType>
320 void
321 ProjectionTools<DeviceType>::getHGradBasisCoeffs(BasisCoeffsViewType basisCoeffs,
322  const TargetValueViewType targetAtTargetEPoints,
323  const TargetGradViewType targetGradAtTargetGradEPoints,
324  const OrientationViewType orts,
325  const BasisType* cellBasis,
327 {
328  using funValsValueType = typename TargetValueViewType::value_type;
329  static_assert(std::is_same<funValsValueType,typename TargetGradViewType::value_type>::value,
330  "targetGradAtTargetGradEPoints and targetAtTargetEPoints must agree on their value type" );
331 
332  typedef typename BasisType::scalarType scalarType;
333  typedef Kokkos::DynRankView<scalarType,DeviceType> ScalarViewType;
334  typedef Kokkos::pair<ordinal_type,ordinal_type> range_type;
335  const auto cellTopo = cellBasis->getBaseCellTopology();
336  ordinal_type dim = cellTopo.getDimension();
337  ordinal_type basisCardinality = cellBasis->getCardinality();
338  ordinal_type numCells = targetAtTargetEPoints.extent(0);
339  const ordinal_type edgeDim = 1;
340  const ordinal_type faceDim = 2;
341 
342  ordinal_type numVertices = (cellBasis->getDofCount(0, 0) > 0) ? cellTopo.getVertexCount() : 0;
343  ordinal_type numEdges = (cellBasis->getDofCount(1, 0) > 0) ? cellTopo.getEdgeCount() : 0;
344  ordinal_type numFaces = (cellBasis->getDofCount(2, 0) > 0) ? cellTopo.getFaceCount() : 0;
345 
346  ScalarViewType refEdgeTan("refTan", dim);
347  ScalarViewType refFaceNormal("refNormal", dim);
348 
349  ordinal_type numVertexDofs = numVertices;
350 
351  ordinal_type numEdgeDofs(0);
352  for(ordinal_type ie=0; ie<numEdges; ++ie)
353  numEdgeDofs += cellBasis->getDofCount(edgeDim,ie);
354 
355  ordinal_type numFaceDofs(0);
356  for(ordinal_type iface=0; iface<numFaces; ++iface)
357  numFaceDofs += cellBasis->getDofCount(faceDim,iface);
358 
359  Kokkos::View<ordinal_type*, DeviceType> computedDofs("computedDofs",numVertexDofs+numEdgeDofs+numFaceDofs);
360 
361  ordinal_type numTotalBasisGradEPoints = projStruct->getNumBasisDerivEvalPoints();
362  auto basisGradEPoints = projStruct->getAllDerivEvalPoints(EvalPointsType::BASIS);
363 
364  ordinal_type numTotalTargetEPoints = projStruct->getNumTargetEvalPoints(), numTotalTargetGradEPoints = projStruct->getNumTargetDerivEvalPoints();
365  auto targetEPoints = projStruct->getAllEvalPoints(EvalPointsType::TARGET);
366  auto targetGradEPoints = projStruct->getAllDerivEvalPoints(EvalPointsType::TARGET);
367 
368 
369  ScalarViewType basisAtTargetEPoints("basisAtTargetEPoints",basisCardinality, numTotalTargetEPoints);
370  cellBasis->getValues(basisAtTargetEPoints, targetEPoints);
371 
372  ScalarViewType basisGradAtBasisGradEPoints;
373  ScalarViewType basisGradAtTargetGradEPoints;
374  if(numTotalBasisGradEPoints>0) {
375  basisGradAtBasisGradEPoints = ScalarViewType ("basisGradAtBasisGradEPoints",basisCardinality, numTotalBasisGradEPoints, dim);
376  basisGradAtTargetGradEPoints = ScalarViewType("basisGradAtTargetGradEPoints",basisCardinality, numTotalTargetGradEPoints, dim);
377 
378  cellBasis->getValues(basisGradAtBasisGradEPoints, basisGradEPoints, OPERATOR_GRAD);
379  cellBasis->getValues(basisGradAtTargetGradEPoints, targetGradEPoints, OPERATOR_GRAD);
380  }
381 
382  auto targetEPointsRange = Kokkos::create_mirror_view_and_copy(MemSpaceType(), projStruct->getTargetPointsRange());
383  auto targetGradEPointsRange = projStruct->getTargetDerivPointsRange();
384  auto basisGradEPointsRange = projStruct->getBasisDerivPointsRange();
385 
386  auto tagToOrdinal = Kokkos::create_mirror_view_and_copy(MemSpaceType(), cellBasis->getAllDofOrdinal());
387 
388  typename RefSubcellParametrization<DeviceType>::ConstViewType subcellParamFace;
389  if(numFaces>0)
390  subcellParamFace = RefSubcellParametrization<DeviceType>::get(faceDim, cellBasis->getBaseCellTopology().getKey());
391 
392 
393  Kokkos::parallel_for("Compute Dofs ", Kokkos::RangePolicy<ExecSpaceType, int> (0, numVertices),
394  KOKKOS_LAMBDA (const size_t iv) {
395  computedDofs(iv) = tagToOrdinal(0, iv, 0);
396  });
397  ordinal_type computedDofsCount = numVertices;
398 
399  ScalarViewType refBasisCoeffs("refBasisCoeffs", basisCoeffs.extent(0), basisCoeffs.extent(1));
400 
401  const Kokkos::RangePolicy<ExecSpaceType> policy(0, numCells);
402  using functorType = FunctorsProjectionTools::ComputeBasisCoeffsOnVertices_HGRAD<ScalarViewType, decltype(tagToOrdinal), decltype(targetEPointsRange),
403  decltype(targetAtTargetEPoints), decltype(basisAtTargetEPoints)>;
404  Kokkos::parallel_for(policy, functorType(refBasisCoeffs, tagToOrdinal, targetEPointsRange,
405  targetAtTargetEPoints, basisAtTargetEPoints, numVertices));
406 
407  for(ordinal_type ie=0; ie<numEdges; ++ie) {
408 
409  ordinal_type edgeCardinality = cellBasis->getDofCount(edgeDim,ie);
410  ordinal_type offsetBasis = basisGradEPointsRange(edgeDim, ie).first;
411  ordinal_type offsetTarget = targetGradEPointsRange(edgeDim, ie).first;
412  ordinal_type numBasisGradEPoints = range_size(basisGradEPointsRange(edgeDim, ie));
413  ordinal_type numTargetGradEPoints = range_size(targetGradEPointsRange(edgeDim, ie));
414  auto basisGradEWeights = Kokkos::create_mirror_view_and_copy(MemSpaceType(),projStruct->getBasisDerivEvalWeights(edgeDim,ie));
415  auto targetGradEWeights = Kokkos::create_mirror_view_and_copy(MemSpaceType(),projStruct->getTargetDerivEvalWeights(edgeDim,ie));
416 
417  CellTools<DeviceType>::getReferenceEdgeTangent(refEdgeTan, ie, cellTopo);
418 
419  ScalarViewType basisTanAtEPoints("basisTanAtEPoints",1,edgeCardinality, numBasisGradEPoints);
420  ScalarViewType targetGradTanAtTargetGradEPoints("tanBasisAtTargetGradEPoints",numCells, numTargetGradEPoints);
421  ScalarViewType wBasisAtBasisGradEPoints("wTanBasisAtBasisGradEPoints",numCells,edgeCardinality, numBasisGradEPoints);
422  ScalarViewType wBasisAtTargetGradEPoints("wTanBasisAtTargetGradEPoints",numCells,edgeCardinality, numTargetGradEPoints);
423  ScalarViewType negPartialProjGrad("negPartialProjGrad", numCells, numBasisGradEPoints);
424 
425  using functorTypeEdge = FunctorsProjectionTools::ComputeBasisCoeffsOnEdges_HGRAD<ScalarViewType, decltype(basisGradEWeights),
426  decltype(computedDofs), decltype(tagToOrdinal), decltype(targetGradAtTargetGradEPoints)>;
427 
428  Kokkos::parallel_for(policy, functorTypeEdge(refBasisCoeffs, negPartialProjGrad, basisTanAtEPoints,
429  basisGradAtBasisGradEPoints, basisGradEWeights, wBasisAtBasisGradEPoints, targetGradEWeights,
430  basisGradAtTargetGradEPoints, wBasisAtTargetGradEPoints, computedDofs, tagToOrdinal,
431  targetGradTanAtTargetGradEPoints, targetGradAtTargetGradEPoints, refEdgeTan,
432  edgeCardinality, offsetBasis,
433  offsetTarget, numVertexDofs, edgeDim, dim, ie));
434 
435  ScalarViewType edgeMassMat_("edgeMassMat_", 1, edgeCardinality, edgeCardinality),
436  edgeRhsMat_("rhsMat_", numCells, edgeCardinality);
437 
438  FunctionSpaceTools<DeviceType >::integrate(edgeMassMat_, basisTanAtEPoints, Kokkos::subview(wBasisAtBasisGradEPoints, std::make_pair(0,1), Kokkos::ALL(), Kokkos::ALL()) );
439  FunctionSpaceTools<DeviceType >::integrate(edgeRhsMat_, targetGradTanAtTargetGradEPoints, wBasisAtTargetGradEPoints);
440  FunctionSpaceTools<DeviceType >::integrate(edgeRhsMat_, negPartialProjGrad, wBasisAtBasisGradEPoints,true);
441 
442  typedef Kokkos::DynRankView<scalarType, Kokkos::LayoutRight, DeviceType> WorkArrayViewType;
443  ScalarViewType t_("t",numCells, edgeCardinality);
444  WorkArrayViewType w_("w",numCells, edgeCardinality);
445 
446  auto edgeDofs = Kokkos::subview(tagToOrdinal, edgeDim, ie, Kokkos::ALL());
447 
448  ElemSystem edgeSystem("edgeSystem", true);
449  edgeSystem.solve(refBasisCoeffs, edgeMassMat_, edgeRhsMat_, t_, w_, edgeDofs, edgeCardinality);
450 
451  Kokkos::parallel_for("Compute Dofs ", Kokkos::RangePolicy<ExecSpaceType, int> (0, edgeCardinality),
452  KOKKOS_LAMBDA (const size_t i) {
453  computedDofs(computedDofsCount+i) = tagToOrdinal(edgeDim, ie, i);
454  });
455  computedDofsCount += edgeCardinality;
456 
457  }
458 
459  for(ordinal_type iface=0; iface<numFaces; ++iface) {
460 
461  ordinal_type faceCardinality = cellBasis->getDofCount(faceDim,iface);
462 
463  ordinal_type numGradEPoints = range_size(basisGradEPointsRange(faceDim, iface));
464  ordinal_type numTargetGradEPoints = range_size(targetGradEPointsRange(faceDim, iface));
465  ordinal_type offsetBasisGrad = basisGradEPointsRange(faceDim, iface).first;
466  ordinal_type offsetTargetGrad = targetGradEPointsRange(faceDim, iface).first;
467  auto basisGradEWeights = Kokkos::create_mirror_view_and_copy(MemSpaceType(),projStruct->getBasisDerivEvalWeights(faceDim,iface));
468  auto targetGradEWeights = Kokkos::create_mirror_view_and_copy(MemSpaceType(),projStruct->getTargetDerivEvalWeights(faceDim,iface));
469 
470  CellTools<DeviceType>::getReferenceFaceNormal(refFaceNormal, iface, cellTopo);
471 
472  ScalarViewType faceBasisGradAtGradEPoints("faceBasisGradAtGradEPoints",1,faceCardinality, numGradEPoints,dim);
473  ScalarViewType wBasisGradAtGradEPoints("wNormalBasisGradAtGradEPoints",numCells,faceCardinality, numGradEPoints,dim);
474  ScalarViewType wBasisGradBasisAtTargetGradEPoints("wNormalBasisGradAtTargetGradEPoints",numCells,faceCardinality, numTargetGradEPoints,dim);
475  ScalarViewType targetGradTanAtTargetGradEPoints("targetGradTanAtTargetGradEPoints",numCells, numTargetGradEPoints,dim);
476  ScalarViewType negPartialProjGrad("mNormalComputedProjection", numCells,numGradEPoints,dim);
477 
478  using functorTypeFace_HGRAD = FunctorsProjectionTools::ComputeBasisCoeffsOnFaces_HGRAD<ScalarViewType, decltype(basisGradEWeights),
479  decltype(computedDofs), decltype(tagToOrdinal), decltype(targetGradAtTargetGradEPoints)>;
480 
481  Kokkos::parallel_for(policy, functorTypeFace_HGRAD(refBasisCoeffs, negPartialProjGrad, faceBasisGradAtGradEPoints,
482  basisGradAtBasisGradEPoints, basisGradEWeights, wBasisGradAtGradEPoints, targetGradEWeights,
483  basisGradAtTargetGradEPoints,wBasisGradBasisAtTargetGradEPoints, computedDofs, tagToOrdinal,
484  targetGradTanAtTargetGradEPoints,targetGradAtTargetGradEPoints,
485  refFaceNormal, faceCardinality, offsetBasisGrad,
486  offsetTargetGrad, numVertexDofs+numEdgeDofs, numFaces, faceDim,
487  dim, iface));
488 
489  ScalarViewType faceMassMat_("faceMassMat_", 1, faceCardinality, faceCardinality),
490  faceRhsMat_("rhsMat_", numCells, faceCardinality);
491 
492  FunctionSpaceTools<DeviceType >::integrate(faceMassMat_, faceBasisGradAtGradEPoints, Kokkos::subview(wBasisGradAtGradEPoints, std::make_pair(0,1), Kokkos::ALL(), Kokkos::ALL(), Kokkos::ALL()) );
493  FunctionSpaceTools<DeviceType >::integrate(faceRhsMat_, targetGradTanAtTargetGradEPoints, wBasisGradBasisAtTargetGradEPoints);
494  FunctionSpaceTools<DeviceType >::integrate(faceRhsMat_, negPartialProjGrad, wBasisGradAtGradEPoints,true);
495 
496  typedef Kokkos::DynRankView<scalarType, Kokkos::LayoutRight, DeviceType> WorkArrayViewType;
497  ScalarViewType t_("t",numCells, faceCardinality);
498  WorkArrayViewType w_("w",numCells, faceCardinality);
499 
500  auto faceDofs = Kokkos::subview(tagToOrdinal, faceDim, iface, Kokkos::ALL());
501 
502  ElemSystem faceSystem("faceSystem", true);
503  faceSystem.solve(refBasisCoeffs, faceMassMat_, faceRhsMat_, t_, w_, faceDofs, faceCardinality);
504 
505  Kokkos::parallel_for("Compute Face Dofs ", Kokkos::RangePolicy<ExecSpaceType, int> (0, faceCardinality),
506  KOKKOS_LAMBDA (const size_t i) {
507  computedDofs(computedDofsCount+i) = tagToOrdinal(faceDim, iface, i);
508  });
509  computedDofsCount += faceCardinality;
510  }
511 
512  ordinal_type numElemDofs = cellBasis->getDofCount(dim,0);
513  if(numElemDofs>0) {
514 
515  range_type cellTargetGradEPointsRange = targetGradEPointsRange(dim, 0);
516  ordinal_type numTargetGradEPoints = range_size(cellTargetGradEPointsRange);
517  ordinal_type numGradEPoints = range_size(basisGradEPointsRange(dim, 0));
518  ordinal_type offsetBasisGrad = basisGradEPointsRange(dim, 0).first;
519  ordinal_type offsetTargetGrad = cellTargetGradEPointsRange.first;
520  auto targetGradEWeights = Kokkos::create_mirror_view_and_copy(MemSpaceType(),projStruct->getTargetDerivEvalWeights(dim,0));
521  auto basisGradEWeights = Kokkos::create_mirror_view_and_copy(MemSpaceType(),projStruct->getBasisDerivEvalWeights(dim,0));
522 
523  ScalarViewType cellBasisGradAtGradEPoints("internalBasisGradAtEPoints",1,numElemDofs, numGradEPoints, dim);
524  ScalarViewType negPartialProjGrad("negPartialProjGrad", numCells, numGradEPoints, dim);
525  ScalarViewType wBasisGradAtGradEPoints("wBasisGradAtGradEPoints",numCells,numElemDofs, numGradEPoints,dim);
526  ScalarViewType wBasisGradBasisAtTargetGradEPoints("wBasisGradAtTargetGradEPoints",numCells,numElemDofs, numTargetGradEPoints,dim);
527 
528  auto elemDof = Kokkos::subview(tagToOrdinal, dim, 0, Kokkos::ALL());
530  Kokkos::parallel_for(policy, functorTypeCell_HGRAD(refBasisCoeffs, negPartialProjGrad, cellBasisGradAtGradEPoints,
531  basisGradAtBasisGradEPoints, basisGradEWeights, wBasisGradAtGradEPoints, targetGradEWeights,
532  basisGradAtTargetGradEPoints, wBasisGradBasisAtTargetGradEPoints, computedDofs, elemDof,
533  dim, numElemDofs, offsetBasisGrad, offsetTargetGrad, numVertexDofs+numEdgeDofs+numFaceDofs));
534  ScalarViewType cellMassMat_("cellMassMat_", 1, numElemDofs, numElemDofs),
535  cellRhsMat_("rhsMat_", numCells, numElemDofs);
536 
537  FunctionSpaceTools<DeviceType >::integrate(cellMassMat_, cellBasisGradAtGradEPoints, Kokkos::subview(wBasisGradAtGradEPoints, std::make_pair(0,1), Kokkos::ALL(), Kokkos::ALL(), Kokkos::ALL()) );
538  FunctionSpaceTools<DeviceType >::integrate(cellRhsMat_, Kokkos::subview(targetGradAtTargetGradEPoints,Kokkos::ALL(),cellTargetGradEPointsRange,Kokkos::ALL()), wBasisGradBasisAtTargetGradEPoints);
539  FunctionSpaceTools<DeviceType >::integrate(cellRhsMat_, negPartialProjGrad, wBasisGradAtGradEPoints, true);
540 
541  typedef Kokkos::DynRankView<scalarType, Kokkos::LayoutRight, DeviceType> WorkArrayViewType;
542  ScalarViewType t_("t",numCells, numElemDofs);
543  WorkArrayViewType w_("w",numCells, numElemDofs);
544 
545  auto cellDofs = Kokkos::subview(tagToOrdinal, dim, 0, Kokkos::ALL());
546  ElemSystem cellSystem("cellSystem", true);
547  cellSystem.solve(refBasisCoeffs, cellMassMat_, cellRhsMat_, t_, w_, cellDofs, numElemDofs);
548  }
549 
550  OrientationTools<DeviceType>::modifyBasisByOrientationInverse(basisCoeffs, refBasisCoeffs, orts, cellBasis, true);
551 
552 }
553 
554 } // Intrepid2 namespace
555 
556 #endif
557 
static void getHGradBasisCoeffs(BasisCoeffsViewType basisCoeffs, const TargetValueViewType targetAtEvalPoints, const TargetGradViewType targetGradAtGradEvalPoints, const OrientationViewType cellOrientations, const BasisType *cellBasis, ProjectionStruct< DeviceType, typename BasisType::scalarType > *projStruct)
Computes the basis coefficients of the HGrad projection of the target function.
Header file for the abstract base class Intrepid2::DefaultCubatureFactory.
ordinal_type getNumBasisDerivEvalPoints()
Returns number of evaluation points for basis derivatives.
const range_tag getTargetDerivPointsRange() const
Returns the range tag of the target function derivative evaluation points on subcells.
static ConstViewType get(const ordinal_type subcellDim, const unsigned parentCellKey)
Returns a Kokkos view with the coefficients of the parametrization maps for the edges or faces of a r...
host_view_type getTargetDerivEvalWeights(const ordinal_type subCellDim, const ordinal_type subCellId)
Returns the function derivatives evaluation weights on a subcell.
void solve(ViewType1 basisCoeffs, ViewType2 elemMat, ViewType2 elemRhs, ViewType2 tau, ViewType3 w, const ViewType4 elemDof, ordinal_type n, ordinal_type m=0)
Solve the system and returns the basis coefficients solve the system either using Kokkos Kernel QR or...
static void getReferenceEdgeTangent(RefEdgeTangentViewType refEdgeTangent, const ordinal_type edgeOrd, const shards::CellTopology parentCell)
Computes constant tangent vectors to edges of 2D or 3D reference cells.
Header file for the Intrepid2::FunctionSpaceTools class.
view_type getAllDerivEvalPoints(EvalPointsType type=TARGET) const
Returns all the evaluation points for basis/target derivatives in the cell.
view_type getAllEvalPoints(EvalPointsType type=TARGET) const
Returns the basis/target evaluation points in the cell.
static void getReferenceFaceNormal(RefFaceNormalViewType refFaceNormal, const ordinal_type faceOrd, const shards::CellTopology parentCell)
Computes constant normal vectors to faces of 3D reference cell.
ordinal_type getNumTargetEvalPoints()
Returns number of points where to evaluate the target function.
const range_tag getBasisDerivPointsRange() const
Returns the range tag of the derivative evaluation points on subcell.
Header file for Intrepid2::ArrayTools class providing utilities for array operations.
static void integrate(Kokkos::DynRankView< outputValueValueType, outputValueProperties...> outputValues, const Kokkos::DynRankView< leftValueValueType, leftValueProperties...> leftValues, const Kokkos::DynRankView< rightValueValueType, rightValueProperties...> rightValues, const bool sumInto=false)
Contracts leftValues and rightValues arrays on the point and possibly space dimensions and stores the...
const range_tag getTargetPointsRange() const
Returns the range of the target function evaluation points on subcells.
host_view_type getBasisDerivEvalWeights(const ordinal_type subCellDim, const ordinal_type subCellId)
Returns the basis derivatives evaluation weights on a subcell.
Utility methods for Intrepid2 unit tests.
ordinal_type getNumTargetDerivEvalPoints()
Returns number of points where to evaluate the derivatives of the target function.
Class to solve a square system A x = b on each cell A is expected to be saddle a point (KKT) matrix o...
An helper class to compute the evaluation points and weights needed for performing projections...
static void modifyBasisByOrientationInverse(Kokkos::DynRankView< outputValueType, outputProperties...> output, const Kokkos::DynRankView< inputValueType, inputProperties...> input, const OrientationViewType orts, const BasisType *basis, const bool transpose=false)
Modify basis due to orientation, applying the inverse of the operator applied in modifyBasisByOrienta...