Panzer  Version of the Day
Panzer_GatherNormals_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_GATHER_NORMALS_IMPL_HPP
44 #define PANZER_GATHER_NORMALS_IMPL_HPP
45 
46 #include "Teuchos_Assert.hpp"
47 #include "Phalanx_DataLayout.hpp"
48 
49 #include "Panzer_PureBasis.hpp"
51 #include "Kokkos_ViewFactory.hpp"
52 
53 #include "Teuchos_FancyOStream.hpp"
54 
55 template<typename EvalT,typename Traits>
58  const Teuchos::ParameterList& p)
59 {
60  dof_name = (p.get< std::string >("DOF Name"));
61 
62  if(p.isType< Teuchos::RCP<PureBasis> >("Basis"))
63  basis = p.get< Teuchos::RCP<PureBasis> >("Basis");
64  else
65  basis = p.get< Teuchos::RCP<const PureBasis> >("Basis");
66 
67  pointRule = p.get<Teuchos::RCP<const PointRule> >("Point Rule");
68 
70  Teuchos::RCP<PHX::DataLayout> vector_layout_vector = basis->functional_grad;
71 
72  // some sanity checks
74 
75  // setup the orientation field
76  std::string orientationFieldName = basis->name() + " Orientation";
77  dof_orientation = PHX::MDField<ScalarT,Cell,NODE>(orientationFieldName,basis_layout);
78 
79  // setup all basis fields that are required
81 
82  // setup all fields to be evaluated and constructed
84 
85  // the field manager will allocate all of these field
86  this->addDependentField(dof_orientation);
87  this->addDependentField(pointValues.jac);
88 
89  gatherFieldNormals = PHX::MDField<ScalarT,Cell,NODE,Dim>(dof_name+"_Normals",vector_layout_vector);
90  this->addEvaluatedField(gatherFieldNormals);
91 
92  this->setName("Gather Normals");
93 }
94 
95 // **********************************************************************
96 template<typename EvalT,typename Traits>
100 {
101  // setup the field data object
102  this->utils.setFieldData(gatherFieldNormals,fm);
103  this->utils.setFieldData(dof_orientation,fm);
104  this->utils.setFieldData(pointValues.jac,fm);
105 
106  faceNormal = Kokkos::createDynRankView(gatherFieldNormals.get_static_view(),
107  "faceNormal",
108  gatherFieldNormals.dimension(0),
109  gatherFieldNormals.dimension(1),
110  gatherFieldNormals.dimension(2));
111 }
112 
113 // **********************************************************************
114 template<typename EvalT,typename Traits>
117 {
118 
119  if(workset.num_cells<=0)
120  return;
121 
122  const shards::CellTopology & parentCell = *basis->getCellTopology();
123  int cellDim = parentCell.getDimension();
124  int numFaces = gatherFieldNormals.dimension(1);
125 
126  // Collect the tangents for the element faces in reference space.
127  // These are scaled such that U x V returns a unit normal,
128  // **contrary to the Intrepid documentation**.
129  Kokkos::DynRankView<ScalarT,PHX::Device> refFaceTanU = Kokkos::createDynRankView(gatherFieldNormals.get_static_view(),"refFaceTanU",numFaces,cellDim);
130  Kokkos::DynRankView<ScalarT,PHX::Device> refFaceTanV = Kokkos::createDynRankView(gatherFieldNormals.get_static_view(),"refFaceTanV",numFaces,cellDim);
131  for(int i=0;i<numFaces;i++) {
132  Kokkos::DynRankView<double,PHX::Device> refTanU = Kokkos::DynRankView<double,PHX::Device>("refTanU",cellDim);
133  Kokkos::DynRankView<double,PHX::Device> refTanV = Kokkos::DynRankView<double,PHX::Device>("refTanV",cellDim);
134  Intrepid2::CellTools<double>::getReferenceFaceTangents(refTanU, refTanV, i, parentCell);
135  for(int d=0;d<cellDim;d++) {
136  refFaceTanU(i,d) = refTanU(d);
137  refFaceTanV(i,d) = refTanV(d);
138  }
139  }
140 
141  // The conversion to physical space must be done by converting each face tangent,
142  // then computing the normal: see Intrepid2_CellToolsDef.hpp.
143  // This code duplicates Intrepid2::getPhysicalFaceNormals to avoid converting local
144  // data structures to and from Intrepid data structures.
145  // Note that the magnitude of the normal is related to the area of the physical face.
146  for(index_t c=0;c<workset.num_cells;c++) {
147  for(int f = 0; f < numFaces; f++) {
148 
149  std::vector<double> faceTanU(3);
150  std::vector<double> faceTanV(3);
151  for(int i = 0; i < cellDim; i++) {
152  faceTanU[i] = Sacado::ScalarValue<ScalarT>::eval(pointValues.jac(c,f,i,0)*refFaceTanU(f,0))
153  + Sacado::ScalarValue<ScalarT>::eval(pointValues.jac(c,f,i,1)*refFaceTanU(f,1))
154  + Sacado::ScalarValue<ScalarT>::eval(pointValues.jac(c,f,i,2)*refFaceTanU(f,2));
155  faceTanV[i] = Sacado::ScalarValue<ScalarT>::eval(pointValues.jac(c,f,i,0)*refFaceTanV(f,0))
156  + Sacado::ScalarValue<ScalarT>::eval(pointValues.jac(c,f,i,1)*refFaceTanV(f,1))
157  + Sacado::ScalarValue<ScalarT>::eval(pointValues.jac(c,f,i,2)*refFaceTanV(f,2));
158  }
159 
160  // normal = TanU x TanV
161  gatherFieldNormals(c,f,0) = (faceTanU[1]*faceTanV[2] - faceTanU[2]*faceTanV[1])*dof_orientation(c,f);
162  gatherFieldNormals(c,f,1) = (faceTanU[2]*faceTanV[0] - faceTanU[0]*faceTanV[2])*dof_orientation(c,f);
163  gatherFieldNormals(c,f,2) = (faceTanU[0]*faceTanV[1] - faceTanU[1]*faceTanV[0])*dof_orientation(c,f);
164 
165  }
166  }
167 
168 }
169 
170 #endif
std::string name() const
A unique key that is the combination of the basis type and basis order.
T & get(const std::string &name, T def_value)
PointValues2< ScalarT, PHX::MDField > pointValues
Interpolates basis DOF values to IP DOF values.
bool isVectorBasis() const
Kokkos::DynRankView< typename InputArray::value_type, PHX::Device > createDynRankView(const InputArray &a, const std::string &name, const DimensionPack... dims)
Wrapper to simplify Panzer use of Sacado ViewFactory.
PHX::MDField< const ScalarT, Cell, BASIS > dof_orientation
Teuchos::RCP< const panzer::PointRule > pointRule
Teuchos::RCP< PHX::DataLayout > functional_grad
<Cell,Basis,Dim>
bool isType(const std::string &name) const
void evaluateFields(typename Traits::EvalData d)
Teuchos::RCP< const shards::CellTopology > getCellTopology() const
Teuchos::RCP< const panzer::PureBasis > basis
Interpolates basis DOF values to IP DOF values.
Array< Scalar, Cell, IP, Dim, Dim, void, void, void, void > jac
void setupArrays(const Teuchos::RCP< const panzer::PointRule > &pr, const ArrayFactory &af)
Sizes/allocates memory for arrays.
const std::string & getName() const
#define TEUCHOS_ASSERT(assertion_test)
Teuchos::RCP< PHX::DataLayout > functional
<Cell,Basis> or <Cell,Basis>
void postRegistrationSetup(typename Traits::SetupData d, PHX::FieldManager< Traits > &vm)
Kokkos::DynRankView< ScalarT, PHX::Device > faceNormal