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 namespace Experimental {
59 
60 template<typename SpT>
61 template<typename BasisType,
62 typename ortValueType, class ...ortProperties>
63 void
64 ProjectionTools<SpT>::getHVolEvaluationPoints(typename BasisType::scalarViewType evaluationPoints,
65  const Kokkos::DynRankView<ortValueType, ortProperties...> /*orts*/,
66  const BasisType* cellBasis,
67  ProjectionStruct<SpT, typename BasisType::scalarType> * projStruct,
68  const EvalPointsType evalPointType) {
69  typedef typename BasisType::scalarType scalarType;
70  typedef Kokkos::DynRankView<scalarType,SpT> scalarViewType;
71  ordinal_type dim = cellBasis->getBaseCellTopology().getDimension();
72 
73  scalarViewType cubPoints;
74  if(evalPointType == TARGET) {
75  cubPoints = projStruct->getTargetEvalPoints(dim, 0);
76  } else {
77  cubPoints = projStruct->getBasisEvalPoints(dim, 0);
78  }
79  RealSpaceTools<SpT>::clone(evaluationPoints,cubPoints);
80 }
81 
82 
83 template<typename SpT>
84 template<typename basisCoeffsValueType, class ...basisCoeffsProperties,
85 typename funValsValueType, class ...funValsProperties,
86 typename BasisType,
87 typename ortValueType,class ...ortProperties>
88 void
89 ProjectionTools<SpT>::getHVolBasisCoeffs(Kokkos::DynRankView<basisCoeffsValueType,basisCoeffsProperties...> basisCoeffs,
90  const Kokkos::DynRankView<funValsValueType,funValsProperties...> targetAtEvalPoints,
91  const typename BasisType::scalarViewType evaluationPoints,
92  const Kokkos::DynRankView<ortValueType, ortProperties...> orts,
93  const BasisType* cellBasis,
94  ProjectionStruct<SpT, typename BasisType::scalarType> * projStruct){
95 
96  typedef typename Kokkos::Impl::is_space<SpT>::host_mirror_space::execution_space host_space_type;
97  typedef typename BasisType::scalarType scalarType;
98  typedef Kokkos::DynRankView<scalarType,SpT> scalarViewType;
99  ordinal_type dim = cellBasis->getBaseCellTopology().getDimension();
100 
101  ordinal_type basisCardinality = cellBasis->getCardinality();
102 
103  ordinal_type numCubPoints = projStruct->getNumBasisEvalPoints(dim, 0);
104  ordinal_type numTargetCubPoints = projStruct->getNumTargetEvalPoints(dim, 0);
105  scalarViewType cubPoints = projStruct->getBasisEvalPoints(dim, 0);
106  scalarViewType cubWeights = projStruct->getBasisEvalWeights(dim, 0);
107  scalarViewType cubTargetWeights = projStruct->getTargetEvalWeights(dim, 0);
108 
109  ordinal_type numCells = targetAtEvalPoints.extent(0);
110 
111  scalarViewType basisAtCubPoints("basisAtcubPoints", basisCardinality, numCubPoints);
112  scalarViewType basisAtcubTargetPoints("basisAtcubTargetPoints", basisCardinality, numTargetCubPoints);
113 
114  cellBasis->getValues(basisAtCubPoints, cubPoints);
115  if(evaluationPoints.rank()==3)
116  cellBasis->getValues(basisAtcubTargetPoints, Kokkos::subview(evaluationPoints,0,Kokkos::ALL(),Kokkos::ALL()));
117  else
118  cellBasis->getValues(basisAtcubTargetPoints, evaluationPoints);
119 
120 
121  scalarViewType weightedBasisAtcubTargetPoints_("weightedBasisAtcubTargetPoints_",numCells, basisCardinality, numTargetCubPoints);
122  scalarViewType cubWeights_(cubWeights.data(),1,numCubPoints);
123  scalarViewType evaluationWeights_(cubTargetWeights.data(),1,numTargetCubPoints);
124  scalarViewType basisAtcubTargetPoints_(basisAtcubTargetPoints.data(),1, basisCardinality, numTargetCubPoints);
125  scalarViewType basisAtCubPoints_(basisAtCubPoints.data(),1, basisCardinality, numCubPoints);
126  scalarViewType weightedBasisAtCubPoints("weightedBasisAtCubPoints",1,basisCardinality, numCubPoints);
127  scalarViewType weightedBasisAtcubTargetPoints("weightedBasisAtcubTargetPoints",1, basisCardinality, numTargetCubPoints);
128  ArrayTools<SpT>::scalarMultiplyDataField( weightedBasisAtCubPoints, cubWeights_, basisAtCubPoints_, false);
129  ArrayTools<SpT>::scalarMultiplyDataField( weightedBasisAtcubTargetPoints, evaluationWeights_, basisAtcubTargetPoints, false);
130  RealSpaceTools<SpT>::clone(weightedBasisAtcubTargetPoints_,Kokkos::subview(weightedBasisAtcubTargetPoints,0,Kokkos::ALL(), Kokkos::ALL()));
131 
132  Kokkos::View<funValsValueType**,Kokkos::LayoutLeft,host_space_type>
133  massMat("massMat", basisCardinality, basisCardinality),
134  rhsMat("rhsMat", basisCardinality, numCells );
135 
136  Kokkos::DynRankView<funValsValueType,Kokkos::LayoutLeft,host_space_type> massMat_(massMat.data(),1,basisCardinality,basisCardinality);
137  Kokkos::DynRankView<funValsValueType,Kokkos::LayoutLeft,host_space_type> rhsMatTrans("rhsMatTrans",numCells,basisCardinality);
138 
139  FunctionSpaceTools<SpT >::integrate(massMat_, basisAtCubPoints_, weightedBasisAtCubPoints);
140  FunctionSpaceTools<SpT >::integrate(rhsMatTrans, targetAtEvalPoints, weightedBasisAtcubTargetPoints_);
141 
142  for(ordinal_type i=0; i<basisCardinality; ++i)
143  for(ordinal_type j=0; j<numCells; ++j)
144  rhsMat(i,j) = rhsMatTrans(j,i);
145 
146  Teuchos::LAPACK<ordinal_type,funValsValueType> lapack;
147  ordinal_type info = 0;
148 
149  lapack.POSV('U', basisCardinality, numCells,
150  massMat.data(),
151  massMat.stride_1(),
152  rhsMat.data(),
153  rhsMat.stride_1(),
154  &info);
155 
156  for(ordinal_type i=0; i<basisCardinality; ++i)
157  for(ordinal_type j=0; j<numCells; ++j) {
158  basisCoeffs(j,i) = rhsMat(i,j);
159  }
160 
161  if (info) {
162  std::stringstream ss;
163  ss << ">>> ERROR (Intrepid::ProjectionTools::getBasisCoeffs): "
164  << "LAPACK return with error code: "
165  << info;
166  INTREPID2_TEST_FOR_EXCEPTION( true, std::runtime_error, ss.str().c_str() );
167  }
168 }
169 
170 
171 
172 }
173 }
174 
175 #endif
176 
static void scalarMultiplyDataField(Kokkos::DynRankView< outputFieldValueType, outputFieldProperties...> outputFields, const Kokkos::DynRankView< inputDataValueType, inputDataProperties...> inputData, const Kokkos::DynRankView< inputFieldValueType, inputFieldProperties...> inputFields, const bool reciprocal=false)
There are two use cases: (1) multiplies a rank-3, 4, or 5 container inputFields with dimensions (C...
Header file for the abstract base class Intrepid2::DefaultCubatureFactory.
static void getHVolBasisCoeffs(Kokkos::DynRankView< basisCoeffsValueType, basisCoeffsProperties...> basisCoeffs, const Kokkos::DynRankView< funValsValueType, funValsProperties...> targetAtEvalPoints, const typename BasisType::scalarViewType evaluationPoints, const Kokkos::DynRankView< ortValueType, ortProperties...> cellOrientations, const BasisType *cellBasis, ProjectionStruct< ExecSpaceType, typename BasisType::scalarType > *projStruct)
Computes the basis coefficients of the HVol projection of the target function.
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...
Header file for the Intrepid2::FunctionSpaceTools class.
static void clone(Kokkos::DynRankView< outputValueType, outputProperties...> output, const Kokkos::DynRankView< inputValueType, inputProperties...> input)
Clone input array.
Header file for Intrepid2::ArrayTools class providing utilities for array operations.
static void getHVolEvaluationPoints(typename BasisType::scalarViewType evaluationPoints, const Kokkos::DynRankView< ortValueType, ortProperties...> cellOrientations, const BasisType *cellBasis, ProjectionStruct< ExecSpaceType, typename BasisType::scalarType > *projStruct, const EvalPointsType evalPointType=TARGET)
Computes evaluation points for HVol projection.