Intrepid2
Intrepid2_ProjectionToolsDefHVOL.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_PROJECTIONTOOLSDEFHVOL_HPP__
50 #define __INTREPID2_PROJECTIONTOOLSDEFHVOL_HPP__
51 
53 #include "Intrepid2_ArrayTools.hpp"
55 
56 
57 namespace Intrepid2 {
58 
59 template<typename DeviceType>
60 template<typename basisCoeffsValueType, class ...basisCoeffsProperties,
61 typename funValsValueType, class ...funValsProperties,
62 typename BasisType,
63 typename ortValueType,class ...ortProperties>
64 void
65 ProjectionTools<DeviceType>::getHVolBasisCoeffs(Kokkos::DynRankView<basisCoeffsValueType,basisCoeffsProperties...> basisCoeffs,
66  const Kokkos::DynRankView<funValsValueType,funValsProperties...> targetAtTargetEPoints,
67  const Kokkos::DynRankView<ortValueType, ortProperties...> orts,
68  const BasisType* cellBasis,
69  ProjectionStruct<DeviceType, typename BasisType::scalarType> * projStruct){
70 
71  typedef typename BasisType::scalarType scalarType;
72  typedef Kokkos::DynRankView<scalarType,DeviceType> ScalarViewType;
73  ordinal_type dim = cellBasis->getBaseCellTopology().getDimension();
74 
75  ordinal_type basisCardinality = cellBasis->getCardinality();
76 
77  ordinal_type numCells = targetAtTargetEPoints.extent(0);
78 
79  auto refTargetEWeights = projStruct->getTargetEvalWeights(dim,0);
80  auto targetEPointsRange = projStruct->getTargetPointsRange();
81 
82  auto refBasisEWeights = projStruct->getBasisEvalWeights(dim,0);
83  auto basisEPointsRange = projStruct->getBasisPointsRange();
84 
85  ordinal_type numTargetEPoints = range_size(targetEPointsRange(dim,0));
86  ordinal_type numBasisEPoints = range_size(basisEPointsRange(dim,0));
87 
88  ScalarViewType basisAtBasisEPoints("basisAtBasisEPoints", 1, basisCardinality, numBasisEPoints);
89  ScalarViewType basisAtTargetEPoints("basisAtTargetEPoints", basisCardinality, numTargetEPoints);
90 
91  auto basisEPoints = projStruct->getAllEvalPoints(EvalPointsType::BASIS);
92  auto targetEPoints = projStruct->getAllEvalPoints(EvalPointsType::TARGET);
93 
94  cellBasis->getValues(Kokkos::subview(basisAtBasisEPoints, 0, Kokkos::ALL(), Kokkos::ALL()), basisEPoints);
95  cellBasis->getValues(basisAtTargetEPoints, targetEPoints);
96 
97  ScalarViewType weightedBasisAtTargetEPoints("weightedBasisAtTargetEPoints_",numCells, basisCardinality, numTargetEPoints);
98  ScalarViewType weightedBasisAtBasisEPoints("weightedBasisAtBasisEPoints", 1, basisCardinality, numBasisEPoints);
99 
100  auto tagToOrdinal = Kokkos::create_mirror_view_and_copy(MemSpaceType(), cellBasis->getAllDofOrdinal());
101  auto cellDofs = Kokkos::subview(tagToOrdinal, dim, 0, Kokkos::ALL());
102 
103  ScalarViewType
104  massMat0("massMat0", 1, basisCardinality, basisCardinality),
105  massMat("massMat", numCells, basisCardinality, basisCardinality),
106  rhsMat("rhsMat", numCells, basisCardinality );
107 
108  ordinal_type offsetBasis = basisEPointsRange(dim,0).first;
109  ordinal_type offsetTarget = targetEPointsRange(dim,0).first;
110 
111  using HostSpaceType = Kokkos::DefaultHostExecutionSpace;
112  auto hWeightedBasisAtBasisEPoints = Kokkos::create_mirror_view(weightedBasisAtBasisEPoints);
113  auto hWeightedBasisAtTargetEPoints = Kokkos::create_mirror_view(weightedBasisAtTargetEPoints);
114  auto hBasisAtBasisEPoints = Kokkos::create_mirror_view_and_copy(HostSpaceType(), basisAtBasisEPoints);
115  auto hBasisAtTargetEPoints = Kokkos::create_mirror_view_and_copy(HostSpaceType(), basisAtTargetEPoints);
116 
117  for(ordinal_type j=0; j <basisCardinality; ++j) {
118  ordinal_type idof = cellBasis->getDofOrdinal(dim, 0, j);
119  for(ordinal_type iq=0; iq <ordinal_type(refBasisEWeights.extent(0)); ++iq)
120  hWeightedBasisAtBasisEPoints(0,j,iq) = hBasisAtBasisEPoints(0,idof,offsetBasis+iq) * refBasisEWeights(iq);
121  for(ordinal_type iq=0; iq <ordinal_type(refTargetEWeights.extent(0)); ++iq)
122  hWeightedBasisAtTargetEPoints(0,j,iq) = hBasisAtTargetEPoints(idof,offsetTarget+iq)* refTargetEWeights(iq);
123  }
124  Kokkos::deep_copy(weightedBasisAtBasisEPoints,hWeightedBasisAtBasisEPoints);
125  Kokkos::deep_copy(weightedBasisAtTargetEPoints,hWeightedBasisAtTargetEPoints);
126  FunctionSpaceTools<DeviceType >::integrate(massMat0, basisAtBasisEPoints, weightedBasisAtBasisEPoints);
127  RealSpaceTools<DeviceType>::clone(massMat, Kokkos::subview(massMat0,0,Kokkos::ALL(), Kokkos::ALL()));
128  RealSpaceTools<DeviceType>::clone(weightedBasisAtTargetEPoints, Kokkos::subview(weightedBasisAtTargetEPoints,0,Kokkos::ALL(), Kokkos::ALL()));
129  FunctionSpaceTools<DeviceType >::integrate(rhsMat, targetAtTargetEPoints, weightedBasisAtTargetEPoints);
130 
131  typedef Kokkos::DynRankView<scalarType, Kokkos::LayoutRight, DeviceType> WorkArrayViewType;
132  ScalarViewType t_("t",numCells, basisCardinality);
133  WorkArrayViewType w_("w",numCells,basisCardinality);
134 
135  ElemSystem cellSystem("cellSystem", true);
136  cellSystem.solve(basisCoeffs, massMat, rhsMat, t_, w_, cellDofs, basisCardinality);
137 }
138 
139 } // Intrepid2 namespace
140 
141 #endif
142 
Header file for the abstract base class Intrepid2::DefaultCubatureFactory.
static void clone(Kokkos::DynRankView< outputValueType, outputProperties...> output, const Kokkos::DynRankView< inputValueType, inputProperties...> input)
Clone input array.
Header file for the Intrepid2::FunctionSpaceTools class.
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...
static void getHVolBasisCoeffs(Kokkos::DynRankView< basisCoeffsValueType, basisCoeffsProperties...> basisCoeffs, const Kokkos::DynRankView< funValsValueType, funValsProperties...> targetAtEvalPoints, [[maybe_unused]] const Kokkos::DynRankView< ortValueType, ortProperties...> cellOrientations, const BasisType *cellBasis, ProjectionStruct< DeviceType, typename BasisType::scalarType > *projStruct)
Computes the basis coefficients of the HVol projection of the target function.