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
30template <typename Scalar>
31KOKKOS_INLINE_FUNCTION
32void
33convertNormalToRotationMatrix(const Scalar normal[3], Scalar transverse[3], Scalar binormal[3])
34{
35 using T = Scalar;
36
37 const T n = sqrt(normal[0]*normal[0]+normal[1]*normal[1]+normal[2]*normal[2]);
38
39 // If this fails then the geometry for this cell is probably undefined
40 if(n > 0.){
41 // Make sure transverse is not parallel to normal within some margin of error
42 transverse[0]=0.;transverse[1]=1.;transverse[2]=0.;
43 if(Kokkos::fabs(normal[0]*transverse[0]+normal[1]*transverse[1])>0.9){
44 transverse[0]=1.;transverse[1]=0.;
45 }
46
47 const T nt = normal[0]*transverse[0]+normal[1]*transverse[1]+normal[2]*transverse[2];
48
49 // Note normal has unit length
50 const T mult = nt/(n*n); // = nt
51
52 // Remove normal projection from transverse
53 for(int dim=0;dim<3;++dim){
54 transverse[dim] = transverse[dim] - mult * normal[dim];
55 }
56
57 const T t = sqrt(transverse[0]*transverse[0]+transverse[1]*transverse[1]+transverse[2]*transverse[2]);
58 KOKKOS_ASSERT(t != 0.);
59 for(int dim=0;dim<3;++dim){
60 transverse[dim] /= t;
61 }
62
63 // We assume a right handed system such that b = n \times t
64 binormal[0] = (normal[1] * transverse[2] - normal[2] * transverse[1]);
65 binormal[1] = (normal[2] * transverse[0] - normal[0] * transverse[2]);
66 binormal[2] = (normal[0] * transverse[1] - normal[1] * transverse[0]);
67
68 // Normalize binormal
69 const T b = sqrt(binormal[0]*binormal[0]+binormal[1]*binormal[1]+binormal[2]*binormal[2]);
70 for(int dim=0;dim<3;++dim){
71 binormal[dim] /= b;
72 }
73 } else {
74 transverse[0] = 0.;
75 transverse[1] = 0.;
76 transverse[2] = 0.;
77 binormal[0] = 0.;
78 binormal[1] = 0.;
79 binormal[2] = 0.;
80 }
81}
82
83}
84
85#endif
KOKKOS_INLINE_FUNCTION void convertNormalToRotationMatrix(const Scalar normal[3], Scalar transverse[3], Scalar binormal[3])
Builds an orthonormal (transverse, binormal) pair completing a right-handed rotation matrix for the g...