Panzer Version of the Day
Loading...
Searching...
No Matches
Panzer_ConvertNormalToRotationMatrix.hpp
Go to the documentation of this file.
1// @HEADER
2// *****************************************************************************
3// Panzer: A partial differential equation assembly
4// engine for strongly coupled complex multiphysics systems
5//
6// Copyright 2011 NTESS and the Panzer contributors.
7// SPDX-License-Identifier: BSD-3-Clause
8// *****************************************************************************
9// @HEADER
10
11#ifndef PANZER_CONVERT_NORMAL_TO_ROTATION_MATRIX_HPP
12#define PANZER_CONVERT_NORMAL_TO_ROTATION_MATRIX_HPP
13
14namespace panzer {
15
16template <typename Scalar>
17KOKKOS_INLINE_FUNCTION
18void
19convertNormalToRotationMatrix(const Scalar normal[3], Scalar transverse[3], Scalar binormal[3])
20{
21 using T = Scalar;
22
23 const T n = sqrt(normal[0]*normal[0]+normal[1]*normal[1]+normal[2]*normal[2]);
24
25 // If this fails then the geometry for this cell is probably undefined
26 if(n > 0.){
27 // Make sure transverse is not parallel to normal within some margin of error
28 transverse[0]=0.;transverse[1]=1.;transverse[2]=0.;
29 if(Kokkos::fabs(normal[0]*transverse[0]+normal[1]*transverse[1])>0.9){
30 transverse[0]=1.;transverse[1]=0.;
31 }
32
33 const T nt = normal[0]*transverse[0]+normal[1]*transverse[1]+normal[2]*transverse[2];
34
35 // Note normal has unit length
36 const T mult = nt/(n*n); // = nt
37
38 // Remove normal projection from transverse
39 for(int dim=0;dim<3;++dim){
40 transverse[dim] = transverse[dim] - mult * normal[dim];
41 }
42
43 const T t = sqrt(transverse[0]*transverse[0]+transverse[1]*transverse[1]+transverse[2]*transverse[2]);
44 KOKKOS_ASSERT(t != 0.);
45 for(int dim=0;dim<3;++dim){
46 transverse[dim] /= t;
47 }
48
49 // We assume a right handed system such that b = n \times t
50 binormal[0] = (normal[1] * transverse[2] - normal[2] * transverse[1]);
51 binormal[1] = (normal[2] * transverse[0] - normal[0] * transverse[2]);
52 binormal[2] = (normal[0] * transverse[1] - normal[1] * transverse[0]);
53
54 // Normalize binormal
55 const T b = sqrt(binormal[0]*binormal[0]+binormal[1]*binormal[1]+binormal[2]*binormal[2]);
56 for(int dim=0;dim<3;++dim){
57 binormal[dim] /= b;
58 }
59 } else {
60 transverse[0] = 0.;
61 transverse[1] = 0.;
62 transverse[2] = 0.;
63 binormal[0] = 0.;
64 binormal[1] = 0.;
65 binormal[2] = 0.;
66 }
67}
68
69}
70
71#endif
KOKKOS_INLINE_FUNCTION void convertNormalToRotationMatrix(const Scalar normal[3], Scalar transverse[3], Scalar binormal[3])