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 
57 namespace Intrepid2 {
58 namespace Experimental {
59 
60 template<typename SpT>
61 template<typename BasisType,
62 typename ortValueType, class ...ortProperties>
63 void
64 ProjectionTools<SpT>::getHGradEvaluationPoints(typename BasisType::scalarViewType evaluationPoints,
65  typename BasisType::scalarViewType extDerivEvaluationPoints,
66  const Kokkos::DynRankView<ortValueType, ortProperties...> orts,
67  const BasisType* cellBasis,
68  ProjectionStruct<SpT, typename BasisType::scalarType> * projStruct,
69  const EvalPointsType evalPointType) {
70  typedef typename BasisType::scalarType scalarType;
71  typedef Kokkos::DynRankView<scalarType,SpT> scalarViewType;
72  typedef Kokkos::pair<ordinal_type,ordinal_type> range_type;
73  const auto cellTopo = cellBasis->getBaseCellTopology();
74  ordinal_type dim = cellTopo.getDimension();
75  ordinal_type numCells = evaluationPoints.extent(0);
76  const ordinal_type edgeDim = 1;
77  const ordinal_type faceDim = 2;
78 
79  ordinal_type numVertices = (cellBasis->getDofCount(0, 0) > 0) ? cellTopo.getVertexCount() : 0;
80  ordinal_type numEdges = (cellBasis->getDofCount(1, 0) > 0) ? cellTopo.getEdgeCount() : 0;
81  ordinal_type numFaces = (cellBasis->getDofCount(2, 0) > 0) ? cellTopo.getFaceCount() : 0;
82 
83  Kokkos::View<ordinal_type*> eOrt("eOrt", numEdges), fOrt("fOrt", numFaces);
84 
85  if(numVertices>0) {
86  //TODO: use lattice to retrieve vertex coordinates.
87  scalarViewType dofCoords("dofCoords", cellBasis->getCardinality(), dim);
88  cellBasis->getDofCoords(dofCoords);
89  for(ordinal_type iv=0; iv<numVertices; ++iv) {
90  ordinal_type idof = cellBasis->getDofOrdinal(0, iv, 0);
91  for(ordinal_type d=0; d<dim; d++)
92  for(ordinal_type ic=0; ic<numCells; ++ic)
93  evaluationPoints(ic,iv,d) = dofCoords(idof,d);
94  }
95  }
96 
97  for(ordinal_type ie=0; ie<numEdges; ++ie) {
98  range_type edgeGradPointsRange;
99  scalarViewType cubPoints;
100  if(evalPointType == TARGET) {
101  edgeGradPointsRange = projStruct->getTargetDerivPointsRange(edgeDim, ie);
102  cubPoints = projStruct->getTargetDerivEvalPoints(edgeDim, ie);
103  }
104  else {
105  edgeGradPointsRange = projStruct->getBasisDerivPointsRange(edgeDim, ie);
106  cubPoints = projStruct->getBasisDerivEvalPoints(edgeDim, ie);
107  }
108 
109  scalarViewType orientedTargetCubPoints("orientedTargetCubPoints", cubPoints.extent(0),edgeDim);
110 
111  const auto topoKey = projStruct->getTopologyKey(edgeDim,ie);
112 
113  for(ordinal_type ic=0; ic<numCells; ++ic) {
114  orts(ic).getEdgeOrientation(eOrt.data(), numEdges);
115  ordinal_type ort = eOrt(ie);
116  Impl::OrientationTools::mapToModifiedReference(orientedTargetCubPoints,cubPoints,topoKey,ort);
117  CellTools<SpT>::mapToReferenceSubcell(Kokkos::subview(extDerivEvaluationPoints,ic,edgeGradPointsRange,Kokkos::ALL()), orientedTargetCubPoints, edgeDim, ie, cellBasis->getBaseCellTopology());
118  }
119  }
120 
121 
122  for(ordinal_type iface=0; iface<numFaces; ++iface) {
123 
124  scalarViewType gradCubPoints;
125  range_type faceGradPointsRange;
126  if(evalPointType == TARGET) {
127  gradCubPoints = projStruct->getTargetDerivEvalPoints(faceDim, iface);
128  faceGradPointsRange = projStruct->getTargetDerivPointsRange(faceDim, iface);
129  } else {
130  gradCubPoints = projStruct->getBasisDerivEvalPoints(faceDim, iface);
131  faceGradPointsRange = projStruct->getBasisDerivPointsRange(faceDim, iface);
132  }
133 
134  scalarViewType faceGradCubPoints("faceGradCubPoints", gradCubPoints.extent(0), faceDim);
135 
136  const auto topoKey = projStruct->getTopologyKey(faceDim,iface);
137  for(ordinal_type ic=0; ic<numCells; ++ic) {
138 
139  orts(ic).getFaceOrientation(fOrt.data(), numFaces);
140 
141  ordinal_type ort = fOrt(iface);
142  Impl::OrientationTools::mapToModifiedReference(faceGradCubPoints,gradCubPoints,topoKey,ort);
143  CellTools<SpT>::mapToReferenceSubcell(Kokkos::subview(extDerivEvaluationPoints, ic, faceGradPointsRange, Kokkos::ALL()), faceGradCubPoints, faceDim, iface, cellBasis->getBaseCellTopology());
144  }
145  }
146 
147  if(cellBasis->getDofCount(dim,0)>0) {
148  range_type cellGradPointsRange;
149  scalarViewType gradCubPoints;
150  if(evalPointType == TARGET) {
151  gradCubPoints = projStruct->getTargetDerivEvalPoints(dim, 0);
152  cellGradPointsRange = projStruct->getTargetDerivPointsRange(dim, 0);
153  } else {
154  gradCubPoints = projStruct->getBasisDerivEvalPoints(dim, 0);
155  cellGradPointsRange = projStruct->getBasisDerivPointsRange(dim, 0);
156  }
157  RealSpaceTools<SpT>::clone(Kokkos::subview(extDerivEvaluationPoints, Kokkos::ALL(), cellGradPointsRange, Kokkos::ALL()), gradCubPoints);
158  }
159 }
160 
161 
162 template<typename SpT>
163 template<typename basisCoeffsValueType, class ...basisCoeffsProperties,
164 typename funValsValueType, class ...funValsProperties,
165 typename BasisType,
166 typename ortValueType,class ...ortProperties>
167 void
168 ProjectionTools<SpT>::getHGradBasisCoeffs(Kokkos::DynRankView<basisCoeffsValueType,basisCoeffsProperties...> basisCoeffs,
169  const Kokkos::DynRankView<funValsValueType,funValsProperties...> targetAtEvalPoints,
170  const Kokkos::DynRankView<funValsValueType,funValsProperties...> targetGradAtGradEvalPoints,
171  const typename BasisType::scalarViewType evaluationPoints,
172  const typename BasisType::scalarViewType extDerivEvaluationPoints,
173  const Kokkos::DynRankView<ortValueType, ortProperties...> orts,
174  const BasisType* cellBasis,
175  ProjectionStruct<SpT, typename BasisType::scalarType> * projStruct){
176 
177  typedef typename Kokkos::Impl::is_space<SpT>::host_mirror_space::execution_space host_space_type;
178  typedef typename BasisType::scalarType scalarType;
179  typedef Kokkos::DynRankView<scalarType,SpT> scalarViewType;
180  typedef Kokkos::pair<ordinal_type,ordinal_type> range_type;
181  const auto cellTopo = cellBasis->getBaseCellTopology();
182  ordinal_type dim = cellTopo.getDimension();
183  ordinal_type numTotalEvaluationPoints(targetAtEvalPoints.extent(1)),
184  numTotalGradEvaluationPoints(targetGradAtGradEvalPoints.extent(1));
185  ordinal_type basisCardinality = cellBasis->getCardinality();
186  ordinal_type numCells = targetAtEvalPoints.extent(0);
187  const ordinal_type edgeDim = 1;
188  const ordinal_type faceDim = 2;
189 
190  ordinal_type numVertices = (cellBasis->getDofCount(0, 0) > 0) ? cellTopo.getVertexCount() : 0;
191  ordinal_type numEdges = (cellBasis->getDofCount(1, 0) > 0) ? cellTopo.getEdgeCount() : 0;
192  ordinal_type numFaces = (cellBasis->getDofCount(2, 0) > 0) ? cellTopo.getFaceCount() : 0;
193 
194  Kokkos::View<ordinal_type*> eOrt("eOrt", numEdges);
195  Kokkos::View<ordinal_type*> fOrt("fOrt", numFaces);
196  scalarViewType refEdgeTan("refEdgeTan", dim);
197  scalarViewType refFaceTangents("refFaceTangents", dim, 2);
198  auto refFaceTanU = Kokkos::subview(refFaceTangents, Kokkos::ALL, 0);
199  auto refFaceTanV = Kokkos::subview(refFaceTangents, Kokkos::ALL, 1);
200 
201  ordinal_type numVertexDofs = numVertices;
202 
203  ordinal_type numEdgeDofs(0);
204  for(ordinal_type ie=0; ie<numEdges; ++ie)
205  numEdgeDofs += cellBasis->getDofCount(edgeDim,ie);
206 
207  ordinal_type numFaceDofs(0);
208  for(ordinal_type iface=0; iface<numFaces; ++iface)
209  numFaceDofs += cellBasis->getDofCount(faceDim,iface);
210 
211  Kokkos::View<ordinal_type*> computedDofs("computedDofs",numVertexDofs+numEdgeDofs+numFaceDofs);
212 
213  ordinal_type computedDofsCount = 0;
214 
215  ordinal_type numTotalCubPoints = projStruct->getNumBasisEvalPoints(),
216  numTotalGradCubPoints = projStruct->getNumBasisDerivEvalPoints();
217  scalarViewType cubPoints("cubPoints",numCells,numTotalCubPoints, dim);
218  scalarViewType gradCubPoints("gradCubPoints",numCells,numTotalGradCubPoints, dim);
219  getHGradEvaluationPoints(cubPoints, gradCubPoints, orts, cellBasis, projStruct, BASIS);
220 
221  scalarViewType basisAtCubPoints("basisAtCubPoints",numCells,basisCardinality, numTotalCubPoints);
222  scalarViewType basisAtTargetCubPoints("basisAtTargetCubPoints",numCells,basisCardinality, numTotalEvaluationPoints);
223  {
224  scalarViewType nonOrientedBasisAtCubPoints("nonOrientedBasisAtCubPoints",numCells,basisCardinality, numTotalCubPoints);
225  scalarViewType nonOrientedBasisAtTargetCubPoints("nonOrientedBasisAtTargetCubPoints",numCells,basisCardinality, numTotalEvaluationPoints);
226 
227  for(ordinal_type ic=0; ic<numCells; ++ic) {
228  cellBasis->getValues(Kokkos::subview(nonOrientedBasisAtTargetCubPoints,ic,Kokkos::ALL(),Kokkos::ALL()), Kokkos::subview(evaluationPoints, ic, Kokkos::ALL(), Kokkos::ALL()));
229  cellBasis->getValues(Kokkos::subview(nonOrientedBasisAtCubPoints,ic,Kokkos::ALL(),Kokkos::ALL()), Kokkos::subview(cubPoints, ic, Kokkos::ALL(), Kokkos::ALL()));
230  }
231 
232  OrientationTools<SpT>::modifyBasisByOrientation(basisAtCubPoints, nonOrientedBasisAtCubPoints, orts, cellBasis);
233  OrientationTools<SpT>::modifyBasisByOrientation(basisAtTargetCubPoints, nonOrientedBasisAtTargetCubPoints, orts, cellBasis);
234  }
235 
236  scalarViewType basisGradAtGradCubPoints;
237  scalarViewType basisGradAtTargetGradCubPoints;
238  if(numTotalGradEvaluationPoints>0) {
239  scalarViewType nonOrientedBasisGradAtTargetGradCubPoints, nonOrientedBasisGradAtGradCubPoints;
240 
241  basisGradAtGradCubPoints = scalarViewType ("basisGradAtGradCubPoints",numCells,basisCardinality, numTotalGradCubPoints, dim);
242  nonOrientedBasisGradAtGradCubPoints = scalarViewType ("nonOrientedBasisGradAtGradCubPoints",numCells,basisCardinality, numTotalGradCubPoints, dim);
243  basisGradAtTargetGradCubPoints = scalarViewType("basisGradAtTargetGradCubPoints",numCells,basisCardinality, numTotalGradEvaluationPoints, dim);
244  nonOrientedBasisGradAtTargetGradCubPoints = scalarViewType("nonOrientedBasisGradAtTargetGradCubPoints",numCells,basisCardinality, numTotalGradEvaluationPoints, dim);
245 
246  for(ordinal_type ic=0; ic<numCells; ++ic) {
247  cellBasis->getValues(Kokkos::subview(nonOrientedBasisGradAtGradCubPoints,ic,Kokkos::ALL(),Kokkos::ALL(),Kokkos::ALL()), Kokkos::subview(gradCubPoints, ic, Kokkos::ALL(), Kokkos::ALL()),OPERATOR_GRAD);
248  cellBasis->getValues(Kokkos::subview(nonOrientedBasisGradAtTargetGradCubPoints,ic,Kokkos::ALL(),Kokkos::ALL(),Kokkos::ALL()), Kokkos::subview(extDerivEvaluationPoints, ic, Kokkos::ALL(), Kokkos::ALL()),OPERATOR_GRAD);
249  }
250 
251  OrientationTools<SpT>::modifyBasisByOrientation(basisGradAtGradCubPoints, nonOrientedBasisGradAtGradCubPoints, orts, cellBasis);
252  OrientationTools<SpT>::modifyBasisByOrientation(basisGradAtTargetGradCubPoints, nonOrientedBasisGradAtTargetGradCubPoints, orts, cellBasis);
253  }
254 
255  for(ordinal_type iv=0; iv<numVertices; ++iv) {
256  ordinal_type idof = cellBasis->getDofOrdinal(0, iv, 0);
257  computedDofs(computedDofsCount++) = idof;
258  for(ordinal_type ic=0; ic<numCells; ++ic)
259  basisCoeffs(ic,idof) = targetAtEvalPoints(ic,iv);
260  }
261 
262  for(ordinal_type ie=0; ie<numEdges; ++ie) {
263 
264  ordinal_type edgeCardinality = cellBasis->getDofCount(edgeDim,ie);
265  ordinal_type numCubPoints = projStruct->getNumBasisDerivEvalPoints(edgeDim, ie);
266  ordinal_type numTargetCubPoints = projStruct->getNumTargetDerivEvalPoints(edgeDim, ie);
267 
268  CellTools<SpT>::getReferenceEdgeTangent(refEdgeTan, ie, cellBasis->getBaseCellTopology());
269 
270  scalarViewType edgeBasisAtCubPoints("tanBasisAtElemCubPoints",numCells,edgeCardinality, numCubPoints);
271  scalarViewType edgeTargetAtTargetCubPoints("tanBasisAtTargetCubPoints",numCells, numTargetCubPoints);
272  scalarViewType weightedBasisAtElemCubPoints("weightedTanBasisAtElemCubPoints",numCells,edgeCardinality, numCubPoints);
273  scalarViewType weightedBasisAtTargetCubPoints("weightedTanBasisAtTargetCubPoints",numCells,edgeCardinality, numTargetCubPoints);
274  scalarViewType mComputedProjection("mComputedProjection", numCells, numCubPoints);
275 
276  scalarViewType targetEvalWeights = projStruct->getTargetDerivEvalWeights(edgeDim, ie);
277  scalarViewType basisEvalWeights = projStruct->getBasisDerivEvalWeights(edgeDim, ie);
278 
279  //Note: we are not considering the jacobian of the orientation map since it is simply a scalar term for the integrals and it does not affect the projection
280  ordinal_type offsetBasis = projStruct->getBasisDerivPointsRange(edgeDim, ie).first;
281  ordinal_type offsetTarget = projStruct->getTargetDerivPointsRange(edgeDim, ie).first;
282  for(ordinal_type j=0; j <edgeCardinality; ++j) {
283  ordinal_type jdof = cellBasis->getDofOrdinal(edgeDim, ie, j);
284  for(ordinal_type ic=0; ic<numCells; ++ic) {
285  for(ordinal_type iq=0; iq <numCubPoints; ++iq) {
286  for(ordinal_type d=0; d <dim; ++d)
287  edgeBasisAtCubPoints(ic,j,iq) += basisGradAtGradCubPoints(ic,jdof,offsetBasis+iq,d)*refEdgeTan(d);
288  weightedBasisAtElemCubPoints(ic,j,iq) = edgeBasisAtCubPoints(ic,j,iq)*basisEvalWeights(iq);
289  }
290  for(ordinal_type iq=0; iq <numTargetCubPoints; ++iq) {
291  for(ordinal_type d=0; d <dim; ++d)
292  weightedBasisAtTargetCubPoints(ic,j,iq) += basisGradAtTargetGradCubPoints(ic,jdof,offsetTarget+iq,d)*refEdgeTan(d)*targetEvalWeights(iq);
293  }
294  }
295  }
296 
297  for(ordinal_type ic=0; ic<numCells; ++ic)
298  for(ordinal_type iq=0; iq <numTargetCubPoints; ++iq)
299  for(ordinal_type d=0; d <dim; ++d)
300  edgeTargetAtTargetCubPoints(ic,iq) += targetGradAtGradEvalPoints(ic,offsetTarget+iq,d)*refEdgeTan(d);
301 
302  for(ordinal_type j=0; j <numVertexDofs; ++j) {
303  ordinal_type jdof = computedDofs(j);
304  for(ordinal_type ic=0; ic<numCells; ++ic)
305  for(ordinal_type iq=0; iq <numCubPoints; ++iq)
306  for(ordinal_type d=0; d <dim; ++d)
307  mComputedProjection(ic,iq) -= basisCoeffs(ic,jdof)*basisGradAtGradCubPoints(ic,jdof,offsetBasis+iq,d)*refEdgeTan(d);
308  }
309 
310 
311  scalarViewType edgeMassMat_("edgeMassMat_", numCells, edgeCardinality, edgeCardinality),
312  edgeRhsMat_("rhsMat_", numCells, edgeCardinality);
313 
314  scalarViewType cubWeights_("cubWeights_", numCells, 1, basisEvalWeights.extent(0)), targetEvalWeights_("targetEvalWeights", numCells, 1, targetEvalWeights.extent(0));
315  RealSpaceTools<SpT>::clone(cubWeights_, basisEvalWeights);
316  RealSpaceTools<SpT>::clone(targetEvalWeights_, targetEvalWeights);
317 
318  FunctionSpaceTools<SpT >::integrate(edgeMassMat_, edgeBasisAtCubPoints, weightedBasisAtElemCubPoints);
319  FunctionSpaceTools<SpT >::integrate(edgeRhsMat_, edgeTargetAtTargetCubPoints, weightedBasisAtTargetCubPoints);
320  FunctionSpaceTools<SpT >::integrate(edgeRhsMat_, mComputedProjection, weightedBasisAtElemCubPoints,true);
321 
322 
323  Kokkos::View<funValsValueType**,Kokkos::LayoutLeft,host_space_type> edgeMassMat("edgeMassMat", edgeCardinality,edgeCardinality);
324  Kokkos::View<funValsValueType**,Kokkos::LayoutLeft,host_space_type> edgeRhsMat("edgeRhsMat",edgeCardinality, 1);
325 
326  Teuchos::LAPACK<ordinal_type,funValsValueType> lapack;
327  ordinal_type info = 0;
328  for(ordinal_type ic=0; ic<numCells; ++ic) {
329  for(ordinal_type i=0; i<edgeCardinality; ++i) {
330  edgeRhsMat(i,0) = edgeRhsMat_(ic,i);
331  for(ordinal_type j=0; j<edgeCardinality; ++j)
332  edgeMassMat(i,j) = edgeMassMat_(ic,i,j);
333  }
334 
335  lapack.POSV('U', edgeCardinality, 1,
336  edgeMassMat.data(),
337  edgeMassMat.stride_1(),
338  edgeRhsMat.data(),
339  edgeRhsMat.stride_1(),
340  &info);
341 
342  if (info) {
343  std::stringstream ss;
344  ss << ">>> ERROR (Intrepid::ProjectionTools::getBasisCoeffs): "
345  << "LAPACK return with error code: "
346  << info;
347  INTREPID2_TEST_FOR_EXCEPTION( true, std::runtime_error, ss.str().c_str() );
348  }
349 
350  for(ordinal_type i=0; i<edgeCardinality; ++i){
351  ordinal_type edge_dof = cellBasis->getDofOrdinal(edgeDim, ie, i);
352  basisCoeffs(ic,edge_dof) = edgeRhsMat(i,0);
353  }
354  }
355  for(ordinal_type i=0; i<edgeCardinality; ++i)
356  computedDofs(computedDofsCount++) = cellBasis->getDofOrdinal(edgeDim, ie, i);
357  }
358 
359  scalarViewType ortJacobian("ortJacobian", faceDim, faceDim);
360 
361  for(ordinal_type iface=0; iface<numFaces; ++iface) {
362 
363 
364  const auto topoKey = projStruct->getTopologyKey(faceDim,iface);
365 
366 
367  ordinal_type faceCardinality = cellBasis->getDofCount(faceDim,iface);
368 
369  ordinal_type numTargetGradCubPoints = projStruct->getNumTargetDerivEvalPoints(faceDim, iface);
370  ordinal_type numGradCubPoints = projStruct->getNumBasisDerivEvalPoints(faceDim, iface);
371 
372  CellTools<SpT>::getReferenceFaceTangents(refFaceTanU, refFaceTanV,iface, cellTopo);
373 
374  scalarViewType faceBasisGradAtGradCubPoints("normaBasisGradAtGradCubPoints",numCells,faceCardinality, numGradCubPoints,faceDim);
375  scalarViewType wBasisGradAtGradCubPoints("weightedNormalBasisGradAtGradCubPoints",numCells,faceCardinality, numGradCubPoints,faceDim);
376 
377  scalarViewType faceBasisGradAtTargetGradCubPoints("normalBasisGradAtTargetGradCubPoints",numCells,faceCardinality, numTargetGradCubPoints,faceDim);
378  scalarViewType wBasisGradBasisAtTargetGradCubPoints("weightedNormalBasisGradAtTargetGradCubPoints",numCells,faceCardinality, numTargetGradCubPoints,faceDim);
379 
380  scalarViewType targetGradAtTargetGradCubPoints("targetGradAtTargetGradCubPoints",numCells, numTargetGradCubPoints,faceDim);
381  scalarViewType mComputedProjectionGrad("mNormalComputedProjection", numCells,numGradCubPoints,faceDim);
382 
383  ordinal_type offsetBasisGrad = projStruct->getBasisDerivPointsRange(faceDim, iface).first;
384  ordinal_type offsetTargetGrad = projStruct->getTargetDerivPointsRange(faceDim, iface).first;
385  scalarViewType targetGradCubWeights = projStruct->getTargetDerivEvalWeights(faceDim, iface);
386  scalarViewType gradCubWeights = projStruct->getBasisDerivEvalWeights(faceDim, iface);
387 
388  //Note: we are not considering the jacobian of the orientation map since it is simply a scalar term for the integrals and it does not affect the projection
389  for(ordinal_type ic=0; ic<numCells; ++ic) {
390 
391  orts(ic).getFaceOrientation(fOrt.data(), numFaces);
392 
393  ordinal_type ort = fOrt(iface);
394  Impl::OrientationTools::getJacobianOfOrientationMap(ortJacobian, topoKey, ort);
395  for(ordinal_type j=0; j <faceCardinality; ++j) {
396  ordinal_type jdof = cellBasis->getDofOrdinal(faceDim, iface, j);
397  for(ordinal_type itan=0; itan <faceDim; ++itan) {
398  for(ordinal_type iq=0; iq <numGradCubPoints; ++iq) {
399  for(ordinal_type d=0; d <dim; ++d)
400  for(ordinal_type jtan=0; jtan <faceDim; ++jtan)
401  faceBasisGradAtGradCubPoints(ic,j,iq,itan) += refFaceTangents(d, jtan)*ortJacobian(jtan,itan)*basisGradAtGradCubPoints(ic,jdof,offsetBasisGrad+iq,d);
402  wBasisGradAtGradCubPoints(ic,j,iq,itan) = faceBasisGradAtGradCubPoints(ic,j,iq,itan) * gradCubWeights(iq);
403  }
404  for(ordinal_type iq=0; iq <numTargetGradCubPoints; ++iq) {
405  for(ordinal_type d=0; d <dim; ++d)
406  for(ordinal_type jtan=0; jtan <faceDim; ++jtan)
407  faceBasisGradAtTargetGradCubPoints(ic,j,iq,itan) += refFaceTangents(d, jtan)*ortJacobian(jtan,itan)*basisGradAtTargetGradCubPoints(ic,jdof,offsetTargetGrad+iq,d);
408  wBasisGradBasisAtTargetGradCubPoints(ic,j,iq,itan) = faceBasisGradAtTargetGradCubPoints(ic,j,iq,itan) * targetGradCubWeights(iq);
409  }
410  }
411  }
412 
413  for(ordinal_type d=0; d <dim; ++d)
414  for(ordinal_type itan=0; itan <faceDim; ++itan)
415  for(ordinal_type iq=0; iq <numTargetGradCubPoints; ++iq)
416  for(ordinal_type jtan=0; jtan <faceDim; ++jtan)
417  targetGradAtTargetGradCubPoints(ic,iq,itan) += refFaceTangents(d, jtan)*ortJacobian(jtan,itan)*targetGradAtGradEvalPoints(ic,offsetTargetGrad+iq,d);
418 
419  for(ordinal_type j=0; j <numVertexDofs+numEdgeDofs; ++j) {
420  ordinal_type jdof = computedDofs(j);
421  for(ordinal_type iq=0; iq <numGradCubPoints; ++iq)
422  for(ordinal_type d=0; d <dim; ++d)
423  for(ordinal_type itan=0; itan <faceDim; ++itan)
424  for(ordinal_type jtan=0; jtan <faceDim; ++jtan)
425  mComputedProjectionGrad(ic,iq,itan) -= basisCoeffs(ic,jdof)*refFaceTangents(d, jtan)*ortJacobian(jtan,itan)*basisGradAtGradCubPoints(ic,jdof,offsetBasisGrad+iq,d);
426  }
427  }
428 
429  scalarViewType faceMassMat_("faceMassMat_", numCells, faceCardinality, faceCardinality),
430  faceRhsMat_("rhsMat_", numCells, faceCardinality);
431 
432  FunctionSpaceTools<SpT >::integrate(faceMassMat_, faceBasisGradAtGradCubPoints, wBasisGradAtGradCubPoints);
433 
434  FunctionSpaceTools<SpT >::integrate(faceRhsMat_, targetGradAtTargetGradCubPoints, wBasisGradBasisAtTargetGradCubPoints);
435  FunctionSpaceTools<SpT >::integrate(faceRhsMat_, mComputedProjectionGrad, wBasisGradAtGradCubPoints,true);
436 
437  Kokkos::View<funValsValueType**,Kokkos::LayoutLeft,host_space_type> faceMassMat("faceMassMat", faceCardinality,faceCardinality);
438  Kokkos::View<funValsValueType**,Kokkos::LayoutLeft,host_space_type> faceRhsMat("faceRhsMat",faceCardinality, 1);
439 
440  Teuchos::LAPACK<ordinal_type,funValsValueType> lapack;
441  ordinal_type info = 0;
442  for(ordinal_type ic=0; ic<numCells; ++ic) {
443 
444  for(ordinal_type i=0; i<faceCardinality; ++i) {
445  faceRhsMat(i,0) = faceRhsMat_(ic,i);
446  for(ordinal_type j=0; j<faceCardinality; ++j)
447  faceMassMat(i,j) = faceMassMat_(ic,i,j);
448  }
449 
450  lapack.POSV('U', faceCardinality, 1,
451  faceMassMat.data(),
452  faceMassMat.stride_1(),
453  faceRhsMat.data(),
454  faceRhsMat.stride_1(),
455  &info);
456 
457  if (info) {
458  std::stringstream ss;
459  ss << ">>> ERROR (Intrepid::ProjectionTools::getBasisCoeffs): "
460  << "LAPACK return with error code: "
461  << info;
462  INTREPID2_TEST_FOR_EXCEPTION( true, std::runtime_error, ss.str().c_str() );
463  }
464 
465  for(ordinal_type i=0; i<faceCardinality; ++i){
466  ordinal_type face_dof = cellBasis->getDofOrdinal(faceDim, iface, i);
467  basisCoeffs(ic,face_dof) = faceRhsMat(i,0);
468  }
469  }
470 
471  for(ordinal_type i=0; i<faceCardinality; ++i)
472  computedDofs(computedDofsCount++) = cellBasis->getDofOrdinal(faceDim, iface, i);
473  }
474 
475  ordinal_type numElemDofs = cellBasis->getDofCount(dim,0);
476  if(numElemDofs>0) {
477 
478  range_type cellGradPointsRange = projStruct->getTargetDerivPointsRange(dim, 0);
479 
480  ordinal_type numTargetGradCubPoints = projStruct->getNumTargetDerivEvalPoints(dim,0);
481  ordinal_type numGradCubPoints = projStruct->getNumBasisDerivEvalPoints(dim,0);
482 
483  scalarViewType internalBasisGradAtGradCubPoints("internalBasisGradAtCubPoints",numCells,numElemDofs, numGradCubPoints, dim);
484  scalarViewType internalBasisGradAtTargetGradCubPoints("weightedBasisGradAtGradCubPoints",numCells,numElemDofs, numTargetGradCubPoints,dim);
485  scalarViewType mComputedProjectionGrad("mComputedProjectionGrad", numCells, numGradCubPoints, dim);
486 
487  scalarViewType targetGradCubWeights = projStruct->getTargetDerivEvalWeights(dim, 0);
488  scalarViewType cubGradWeights = projStruct->getBasisDerivEvalWeights(dim, 0);
489  ordinal_type offsetBasisGrad = projStruct->getBasisDerivPointsRange(dim, 0).first;
490  ordinal_type offsetTargetGrad = projStruct->getTargetDerivPointsRange(dim, 0).first;
491 
492 
493  scalarViewType wBasisGradAtGradCubPoints("weightedBasisGradAtGradCubPoints",numCells,numElemDofs, numGradCubPoints,dim);
494  scalarViewType wBasisGradBasisAtTargetGradCubPoints("weightedBasisGradAtTargetGradCubPoints",numCells,numElemDofs, numTargetGradCubPoints,dim);
495  for(ordinal_type j=0; j <numElemDofs; ++j) {
496  ordinal_type idof = cellBasis->getDofOrdinal(dim, 0, j);
497  for(ordinal_type ic=0; ic<numCells; ++ic) {
498  for(ordinal_type d=0; d <dim; ++d) {
499  for(ordinal_type iq=0; iq <numGradCubPoints; ++iq) {
500  internalBasisGradAtGradCubPoints(ic,j,iq,d) = basisGradAtGradCubPoints(ic,idof,offsetBasisGrad+iq,d);
501  wBasisGradAtGradCubPoints(ic,j,iq,d) = internalBasisGradAtGradCubPoints(ic,j,iq,d) * cubGradWeights(iq);
502  }
503  for(ordinal_type iq=0; iq <numTargetGradCubPoints; ++iq) {
504  internalBasisGradAtTargetGradCubPoints(ic,j,iq,d) = basisGradAtTargetGradCubPoints(ic,idof,offsetTargetGrad+iq,d);
505  wBasisGradBasisAtTargetGradCubPoints(ic,j,iq,d )= internalBasisGradAtTargetGradCubPoints(ic,j,iq,d) * targetGradCubWeights(iq);
506  }
507  }
508  }
509  }
510 
511  for(ordinal_type j=0; j <numVertexDofs+numEdgeDofs+numFaceDofs; ++j) {
512  ordinal_type jdof = computedDofs(j);
513  for(ordinal_type iq=0; iq <numGradCubPoints; ++iq)
514  for(ordinal_type ic=0; ic<numCells; ++ic) {
515  for(ordinal_type d=0; d <dim; ++d) {
516  mComputedProjectionGrad(ic,iq,d) -= basisCoeffs(ic,jdof)*basisGradAtGradCubPoints(ic,jdof,offsetBasisGrad+iq,d);
517  }
518  }
519  }
520 
521 
522  scalarViewType cellMassMat_("cellMassMat_", numCells, numElemDofs, numElemDofs),
523  cellRhsMat_("rhsMat_", numCells, numElemDofs);
524 
525  FunctionSpaceTools<SpT >::integrate(cellMassMat_, internalBasisGradAtGradCubPoints, wBasisGradAtGradCubPoints);
526  FunctionSpaceTools<SpT >::integrate(cellRhsMat_, Kokkos::subview(targetGradAtGradEvalPoints,Kokkos::ALL(),cellGradPointsRange,Kokkos::ALL()), wBasisGradBasisAtTargetGradCubPoints);
527  FunctionSpaceTools<SpT >::integrate(cellRhsMat_, mComputedProjectionGrad, wBasisGradAtGradCubPoints, true);
528 
529  Kokkos::View<funValsValueType**,Kokkos::LayoutLeft,host_space_type> cellMassMat("cellMassMat", numElemDofs,numElemDofs);
530  Kokkos::View<funValsValueType**,Kokkos::LayoutLeft,host_space_type> cellRhsMat("cellRhsMat",numElemDofs, 1);
531 
532  Teuchos::LAPACK<ordinal_type,funValsValueType> lapack;
533  ordinal_type info = 0;
534  for(ordinal_type ic=0; ic<numCells; ++ic) {
535  for(ordinal_type i=0; i<numElemDofs; ++i) {
536  cellRhsMat(i,0) = cellRhsMat_(ic,i);
537  for(ordinal_type j=0; j<numElemDofs; ++j)
538  cellMassMat(i,j) = cellMassMat_(ic,i,j);
539  }
540 
541  lapack.POSV('U', numElemDofs, 1,
542  cellMassMat.data(),
543  cellMassMat.stride_1(),
544  cellRhsMat.data(),
545  cellRhsMat.stride_1(),
546  &info);
547 
548  for(ordinal_type i=0; i<numElemDofs; ++i){
549  ordinal_type idof = cellBasis->getDofOrdinal(dim, 0, i);
550  basisCoeffs(ic,idof) = cellRhsMat(i,0);
551  }
552 
553  if (info) {
554  std::stringstream ss;
555  ss << ">>> ERROR (Intrepid::ProjectionTools::getBasisCoeffs): "
556  << "LAPACK return with error code: "
557  << info;
558  INTREPID2_TEST_FOR_EXCEPTION( true, std::runtime_error, ss.str().c_str() );
559  }
560  }
561  }
562 }
563 }
564 }
565 
566 #endif
567 
static void getReferenceEdgeTangent(Kokkos::DynRankView< refEdgeTangentValueType, refEdgeTangentProperties...> 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 abstract base class Intrepid2::DefaultCubatureFactory.
static void getJacobianOfOrientationMap(JacobianViewType jacobian, const shards::CellTopology cellTopo, const ordinal_type cellOrt)
Computes jacobian of the parameterization maps of 1- and 2-subcells with orientation.
static void getHGradBasisCoeffs(Kokkos::DynRankView< basisCoeffsValueType, basisCoeffsProperties...> basisCoeffs, const Kokkos::DynRankView< funValsValueType, funValsProperties...> targetAtEvalPoints, const Kokkos::DynRankView< funValsValueType, funValsProperties...> targetGradAtGradEvalPoints, const typename BasisType::scalarViewType evaluationPoints, const typename BasisType::scalarViewType gradEvalPoints, const Kokkos::DynRankView< ortValueType, ortProperties...> cellOrientations, const BasisType *cellBasis, ProjectionStruct< ExecSpaceType, typename BasisType::scalarType > *projStruct)
Computes the basis coefficients of the HGrad projection of the target function.
static void modifyBasisByOrientation(Kokkos::DynRankView< outputValueType, outputProperties...> output, const Kokkos::DynRankView< inputValueType, inputProperties...> input, const Kokkos::DynRankView< ortValueType, ortProperties...> orts, const BasisPtrType basis)
Modify basis due to orientation.
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...
static void mapToReferenceSubcell(Kokkos::DynRankView< refSubcellPointValueType, refSubcellPointProperties...> refSubcellPoints, const Kokkos::DynRankView< paramPointValueType, paramPointProperties...> paramPoints, const ordinal_type subcellDim, const ordinal_type subcellOrd, const shards::CellTopology parentCell)
Computes parameterization maps of 1- and 2-subcells of reference cells.
Header file for the Intrepid2::FunctionSpaceTools class.
static void clone(Kokkos::DynRankView< outputValueType, outputProperties...> output, const Kokkos::DynRankView< inputValueType, inputProperties...> input)
Clone input array.
static void getHGradEvaluationPoints(typename BasisType::scalarViewType evaluationPoints, typename BasisType::scalarViewType gradEvalPoints, const Kokkos::DynRankView< ortValueType, ortProperties...> cellOrientations, const BasisType *cellBasis, ProjectionStruct< ExecSpaceType, typename BasisType::scalarType > *projStruct, const EvalPointsType evalPointType=TARGET)
Computes evaluation points for HGrad projection.
Header file for Intrepid2::ArrayTools class providing utilities for array operations.
static void getReferenceFaceTangents(Kokkos::DynRankView< refFaceTanUValueType, refFaceTanUProperties...> refFaceTanU, Kokkos::DynRankView< refFaceTanVValueType, refFaceTanVProperties...> refFaceTanV, const ordinal_type faceOrd, const shards::CellTopology parentCell)
Computes pairs of constant tangent vectors to faces of a 3D reference cells.
static void mapToModifiedReference(outPointViewType outPoints, const refPointViewType refPoints, const shards::CellTopology cellTopo, const ordinal_type cellOrt=0)
Computes modified parameterization maps of 1- and 2-subcells with orientation.