Panzer  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Panzer_ProjectToFaces_impl.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Panzer: A partial differential equation assembly
5 // engine for strongly coupled complex multiphysics systems
6 // Copyright (2011) Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact Roger P. Pawlowski (rppawlo@sandia.gov) and
39 // Eric C. Cyr (eccyr@sandia.gov)
40 // ***********************************************************************
41 // @HEADER
42 
43 #ifndef PANZER_PROJECT_TO_FACES_IMPL_HPP
44 #define PANZER_PROJECT_TO_FACES_IMPL_HPP
45 
46 #include "Teuchos_Assert.hpp"
47 #include "Phalanx_DataLayout.hpp"
48 
49 #include "Intrepid2_Cubature.hpp"
50 #include "Intrepid2_DefaultCubatureFactory.hpp"
51 #include "Intrepid2_FunctionSpaceTools.hpp"
52 #include "Intrepid2_Kernels.hpp"
53 #include "Intrepid2_CellTools.hpp"
54 #include "Intrepid2_OrientationTools.hpp"
55 
57 #include "Panzer_PureBasis.hpp"
60 #include "Kokkos_ViewFactory.hpp"
61 
62 #include "Teuchos_FancyOStream.hpp"
63 
64 #include <cstring>
65 
66 template<typename EvalT,typename Traits>
69 {
70  dof_name_ = (p.get< std::string >("DOF Name"));
71 
72  if(p.isType< Teuchos::RCP<PureBasis> >("Basis"))
73  basis_ = p.get< Teuchos::RCP<PureBasis> >("Basis");
74  else
75  basis_ = p.get< Teuchos::RCP<const PureBasis> >("Basis");
76 
77  Teuchos::RCP<PHX::DataLayout> basis_layout = basis_->functional;
78  Teuchos::RCP<PHX::DataLayout> vector_layout = basis_->functional_grad;
79 
80  // some sanity checks
81  TEUCHOS_ASSERT(basis_->isVectorBasis());
82 
83  result_ = PHX::MDField<ScalarT,Cell,BASIS>(dof_name_,basis_layout);
84  this->addEvaluatedField(result_);
85 
86  normals_ = PHX::MDField<const ScalarT,Cell,BASIS,Dim>(dof_name_+"_Normals",vector_layout);
87  this->addDependentField(normals_);
88 
89  vector_values_ = PHX::MDField<const ScalarT,Cell,BASIS,Dim>(dof_name_+"_Vector",vector_layout);
90  this->addDependentField(vector_values_);
91 
92  this->setName("Project To Faces");
93 }
94 
95 // **********************************************************************
96 template<typename EvalT,typename Traits>
99  PHX::FieldManager<Traits>& /* fm */)
100 {
101  num_faces_ = result_.extent(1);
102  num_dim_ = vector_values_.extent(2);
103 
104  TEUCHOS_ASSERT(result_.extent(1) == normals_.extent(1));
105  TEUCHOS_ASSERT(vector_values_.extent(2) == normals_.extent(2));
106 }
107 
108 // **********************************************************************
109 template<typename EvalT,typename Traits>
112 {
113 
114  // Restricting HDiv field, multiplied by the normal to the faces, into HVol on the faces.
115  // This code assumes affine mapping and the projection into 1 quadrature point for each face,
116  // which is identified with the face. This makes sense only for low order bases, for which
117  // HVol is constant
118 
119  //TODO: make this work w/ high order basis
120  const int intDegree = basis_->order();
121  TEUCHOS_ASSERT(intDegree == 1);
122 
123  auto result = result_.get_static_view();
124  auto vector_values = vector_values_.get_static_view();
125  auto normals = normals_.get_static_view();
126  auto num_faces = num_faces_;
127  auto num_dim = num_dim_;
128 
129  auto policy = panzer::HP::inst().teamPolicy<ScalarT,PHX::exec_space>(workset.num_cells);
130  Kokkos::parallel_for("panzer::ProjectToFaces",policy,KOKKOS_LAMBDA(const Kokkos::TeamPolicy<PHX::exec_space>::member_type& team) {
131  const auto cell = team.league_rank();
132  Kokkos::parallel_for(Kokkos::TeamThreadRange(team,0,num_faces),[&] (const int p) {
133  result(cell,p) = ScalarT(0.0);
134  for (int dim = 0; dim < num_dim; ++dim)
135  result(cell,p) += vector_values(cell,p,dim) * normals(cell,p,dim);
136  });
137  });
138 }
139 
140 
141 #endif
int num_cells
DEPRECATED - use: numCells()
void evaluateFields(typename Traits::EvalData d)
T & get(const std::string &name, T def_value)
Kokkos::TeamPolicy< TeamPolicyProperties...> teamPolicy(const int &league_size)
Returns a TeamPolicy for hierarchic parallelism.
void postRegistrationSetup(typename Traits::SetupData d, PHX::FieldManager< Traits > &vm)
PHX::MDField< ScalarT, panzer::Cell, panzer::IP > result
A field that will be used to build up the result of the integral we&#39;re performing.
ProjectToFaces(const Teuchos::ParameterList &p)
KOKKOS_FORCEINLINE_FUNCTION array_type get_static_view()
bool isType(const std::string &name) const
static HP & inst()
Private ctor.
#define TEUCHOS_ASSERT(assertion_test)