\doxysection{Local\+\_\+\+Kernels.\+h}
\hypertarget{_local___kernels_8h_source}{}\label{_local___kernels_8h_source}\index{src/Local\_Kernels.h@{src/Local\_Kernels.h}}

\begin{DoxyCode}{0}
\DoxyCodeLine{00001\ }
\DoxyCodeLine{00011\ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ T>}
\DoxyCodeLine{00012\ \textcolor{keywordtype}{int}\ sgn(T\ val)\ \{}
\DoxyCodeLine{00013\ \ \ \ \ \textcolor{keywordflow}{return}\ (T(0)\ <\ val)\ -\/\ (val\ <\ T(0));}
\DoxyCodeLine{00014\ \}}
\DoxyCodeLine{00015\ }
\DoxyCodeLine{00035\ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ T>}
\DoxyCodeLine{00036\ \textcolor{keywordtype}{void}\ sample\_CLL(T*\ vel\_in,\ T*\ vel\_refl,\ T*\ GSI\_parameters,\ T*\ Gas\_parameters,\ T*\ Surface\_parameters)\ \{}
\DoxyCodeLine{00037\ \ \ \ \ }
\DoxyCodeLine{00038\ \ \ \ \ \textcolor{comment}{//\ Retrieve\ GSI\ and\ surface\ parameters}}
\DoxyCodeLine{00039\ \ \ \ \ T\ alpha\_n\ =\ GSI\_parameters[0];\ \textcolor{comment}{//\ Normal\ accommodation\ coefficient}}
\DoxyCodeLine{00040\ \ \ \ \ T\ sigma\_t\ =\ GSI\_parameters[1];\ \textcolor{comment}{//\ Tangential\ momentum\ accommodation\ coefficient}}
\DoxyCodeLine{00041\ \ \ \ \ T\ alpha\_t\ =\ sigma\_t\ *\ (2\ -\/\ sigma\_t);\ \textcolor{comment}{//\ Tangential\ accommodation\ coefficient}}
\DoxyCodeLine{00042\ \ \ \ \ T\ T\_W\ =\ Surface\_parameters[0];\ \textcolor{comment}{//\ Wall\ temperature}}
\DoxyCodeLine{00043\ }
\DoxyCodeLine{00044\ \ \ \ \ \textcolor{comment}{//\ Random\ number\ generator\ setup}}
\DoxyCodeLine{00045\ \ \ \ \ std::random\_device\ rd;}
\DoxyCodeLine{00046\ \ \ \ \ std::seed\_seq\ fullSeed\{rd(),\ rd(),\ rd(),\ rd(),\ rd(),\ rd(),\ rd(),\ rd(),\ rd(),\ rd()\};}
\DoxyCodeLine{00047\ \ \ \ \ std::mt19937\ rng(fullSeed);\ \textcolor{comment}{//\ Random\ number\ generator}}
\DoxyCodeLine{00048\ \ \ \ \ std::uniform\_real\_distribution<T>\ uniformDist(0.0f,\ 1.0f);\ \textcolor{comment}{//\ Uniform\ distribution\ in\ [0,\ 1]}}
\DoxyCodeLine{00049\ }
\DoxyCodeLine{00050\ \ \ \ \ \textcolor{comment}{//\ Calculate\ velocity\ scale\ based\ on\ gas\ properties\ and\ surface\ temperature}}
\DoxyCodeLine{00051\ \ \ \ \ T\ vel\_wall\ =\ sqrt(2.0\ *\ R\_gas\ /\ Gas\_parameters[2]\ *\ T\_W);}
\DoxyCodeLine{00052\ }
\DoxyCodeLine{00053\ \ \ \ \ \textcolor{comment}{//\ Generate\ random\ numbers\ for\ sampling}}
\DoxyCodeLine{00054\ \ \ \ \ T\ x1\ =\ uniformDist(rng),\ x2\ =\ uniformDist(rng),\ x3\ =\ uniformDist(rng),\ }
\DoxyCodeLine{00055\ \ \ \ \ \ \ x4\ =\ uniformDist(rng),\ x5\ =\ uniformDist(rng),\ x6\ =\ uniformDist(rng);}
\DoxyCodeLine{00056\ }
\DoxyCodeLine{00057\ \ \ \ \ \textcolor{comment}{//\ Calculate\ reflection\ parameters}}
\DoxyCodeLine{00058\ \ \ \ \ T\ r1\ =\ sqrt(-\/alpha\_n\ *\ log(x1));}
\DoxyCodeLine{00059\ \ \ \ \ T\ r3\ =\ sqrt(-\/alpha\_t\ *\ log(x3));}
\DoxyCodeLine{00060\ \ \ \ \ T\ r5\ =\ sqrt(-\/alpha\_t\ *\ log(x5));}
\DoxyCodeLine{00061\ \ \ \ \ T\ theta2\ =\ 2.0\ *\ M\_PI\ *\ x2;}
\DoxyCodeLine{00062\ \ \ \ \ T\ theta4\ =\ 2.0\ *\ M\_PI\ *\ x4;}
\DoxyCodeLine{00063\ \ \ \ \ T\ theta6\ =\ 2.0\ *\ M\_PI\ *\ x6;}
\DoxyCodeLine{00064\ }
\DoxyCodeLine{00065\ \ \ \ \ \textcolor{comment}{//\ Compute\ the\ magnitude\ of\ the\ input\ velocity\ components}}
\DoxyCodeLine{00066\ \ \ \ \ T\ vel\_norm\_m\ =\ fabs(vel\_in[2]\ /\ vel\_wall)\ *\ sqrt(1\ -\/\ alpha\_n);}
\DoxyCodeLine{00067\ \ \ \ \ T\ vel\_tan1\_m\ =\ vel\_in[0]\ /\ vel\_wall\ *\ sqrt(1\ -\/\ alpha\_t);}
\DoxyCodeLine{00068\ }
\DoxyCodeLine{00069\ \ \ \ \ \textcolor{comment}{//\ Reflect\ the\ velocity\ in\ normal\ and\ tangential\ directions}}
\DoxyCodeLine{00070\ \ \ \ \ vel\_refl[2]\ =\ vel\_wall\ *\ sqrt(r1\ *\ r1\ +\ vel\_norm\_m\ *\ vel\_norm\_m\ +\ 2\ *\ r1\ *\ vel\_norm\_m\ *\ cos(theta2));\ \textcolor{comment}{//\ Normal\ component}}
\DoxyCodeLine{00071\ \ \ \ \ vel\_refl[0]\ =\ vel\_wall\ *\ (vel\_tan1\_m\ +\ r3\ *\ cos(theta4));\ \textcolor{comment}{//\ Tangential\ component\ 1}}
\DoxyCodeLine{00072\ \ \ \ \ vel\_refl[1]\ =\ vel\_wall\ *\ (r5\ *\ cos(theta6));\ \textcolor{comment}{//\ Tangential\ component\ 2}}
\DoxyCodeLine{00073\ \}}
\DoxyCodeLine{00074\ }
\DoxyCodeLine{00095\ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ T>}
\DoxyCodeLine{00096\ \textcolor{keywordtype}{void}\ sample\_DRIA(T*\ vel\_in,\ T*\ vel\_refl,\ T*\ GSI\_parameters,\ T*\ Gas\_parameters,\ T*\ Surface\_parameters)\ \{}
\DoxyCodeLine{00097\ }
\DoxyCodeLine{00098\ \ \ \ \ \textcolor{comment}{//\ Compute\ the\ magnitude\ of\ the\ input\ velocity}}
\DoxyCodeLine{00099\ \ \ \ \ T\ vel\_in\_norm\ =\ sqrt(vel\_in[0]\ *\ vel\_in[0]\ +\ vel\_in[1]\ *\ vel\_in[1]\ +\ vel\_in[2]\ *\ vel\_in[2]);}
\DoxyCodeLine{00100\ }
\DoxyCodeLine{00101\ \ \ \ \ \textcolor{comment}{//\ Retrieve\ GSI\ and\ surface\ parameters}}
\DoxyCodeLine{00102\ \ \ \ \ T\ alpha\ =\ GSI\_parameters[0];\ \textcolor{comment}{//\ Accommodation\ coefficient}}
\DoxyCodeLine{00103\ \ \ \ \ T\ T\_W\ =\ Surface\_parameters[0];\ \textcolor{comment}{//\ Wall\ temperature}}
\DoxyCodeLine{00104\ \ \ \ \ T\ T\_G\ =\ Gas\_parameters[0];\ \textcolor{comment}{//\ Gas\ temperature}}
\DoxyCodeLine{00105\ \ \ \ \ T\ gas\_speed\ =\ Gas\_parameters[3];\ \textcolor{comment}{//\ Gas\ speed}}
\DoxyCodeLine{00106\ }
\DoxyCodeLine{00107\ \ \ \ \ \textcolor{comment}{//\ Compute\ characteristic\ gas\ temperature\ based\ on\ speed}}
\DoxyCodeLine{00108\ \ \ \ \ T\ T\_K\ =\ gas\_speed\ *\ gas\_speed\ *\ Gas\_parameters[2]\ /\ 3.0\ /\ R\_gas;}
\DoxyCodeLine{00109\ }
\DoxyCodeLine{00110\ \ \ \ \ \textcolor{comment}{//\ Random\ number\ generator\ setup}}
\DoxyCodeLine{00111\ \ \ \ \ std::random\_device\ rd;}
\DoxyCodeLine{00112\ \ \ \ \ std::seed\_seq\ fullSeed\{rd(),\ rd(),\ rd(),\ rd(),\ rd(),\ rd(),\ rd(),\ rd(),\ rd(),\ rd()\};}
\DoxyCodeLine{00113\ \ \ \ \ std::mt19937\ rng(fullSeed);\ \textcolor{comment}{//\ Random\ number\ generator}}
\DoxyCodeLine{00114\ \ \ \ \ std::uniform\_real\_distribution<T>\ uniformDist(0.0f,\ 1.0f);\ \textcolor{comment}{//\ Uniform\ distribution\ in\ [0,\ 1]}}
\DoxyCodeLine{00115\ \ \ \ \ std::normal\_distribution<T>\ normDist(0.0f,\ 1.0f);\ \textcolor{comment}{//\ Normal\ distribution\ for\ random\ velocities}}
\DoxyCodeLine{00116\ }
\DoxyCodeLine{00117\ \ \ \ \ \textcolor{comment}{//\ Compute\ reflected\ temperature\ based\ on\ accommodation\ coefficient}}
\DoxyCodeLine{00118\ \ \ \ \ T\ T\_R\ =\ (1.0\ -\/\ alpha)\ *\ T\_K\ +\ alpha\ *\ T\_W;}
\DoxyCodeLine{00119\ }
\DoxyCodeLine{00120\ \ \ \ \ \textcolor{comment}{//\ Calculate\ velocity\ scale\ based\ on\ gas\ properties\ and\ reflected\ temperature}}
\DoxyCodeLine{00121\ \ \ \ \ T\ vel\_wall\ =\ sqrt(2.0\ *\ R\_gas\ /\ Gas\_parameters[2]\ *\ T\_R);}
\DoxyCodeLine{00122\ }
\DoxyCodeLine{00123\ \ \ \ \ \textcolor{comment}{//\ Generate\ random\ numbers\ for\ sampling}}
\DoxyCodeLine{00124\ \ \ \ \ T\ x1\ =\ uniformDist(rng),\ x2\ =\ uniformDist(rng),\ x3\ =\ uniformDist(rng),\ }
\DoxyCodeLine{00125\ \ \ \ \ \ \ x4\ =\ uniformDist(rng),\ x5\ =\ uniformDist(rng),\ x6\ =\ uniformDist(rng);}
\DoxyCodeLine{00126\ }
\DoxyCodeLine{00127\ \ \ \ \ \textcolor{comment}{//\ Calculate\ reflection\ parameters}}
\DoxyCodeLine{00128\ \ \ \ \ T\ r1\ =\ sqrt(-\/log(x1));}
\DoxyCodeLine{00129\ \ \ \ \ T\ r3\ =\ sqrt(-\/log(x3));}
\DoxyCodeLine{00130\ \ \ \ \ T\ r5\ =\ sqrt(-\/log(x5));}
\DoxyCodeLine{00131\ \ \ \ \ T\ theta2\ =\ 2.0\ *\ M\_PI\ *\ x2;}
\DoxyCodeLine{00132\ \ \ \ \ T\ theta4\ =\ 2.0\ *\ M\_PI\ *\ x4;}
\DoxyCodeLine{00133\ \ \ \ \ T\ theta6\ =\ 2.0\ *\ M\_PI\ *\ x6;}
\DoxyCodeLine{00134\ }
\DoxyCodeLine{00135\ \ \ \ \ \textcolor{comment}{//\ Reflect\ the\ velocity\ in\ normal\ and\ tangential\ directions}}
\DoxyCodeLine{00136\ \ \ \ \ vel\_refl[2]\ =\ vel\_wall\ *\ r1;\ \textcolor{comment}{//\ Normal\ component}}
\DoxyCodeLine{00137\ \ \ \ \ vel\_refl[0]\ =\ sqrt(R\_gas\ *\ T\_R\ /\ Gas\_parameters[2])\ *\ normDist(rng);\ \textcolor{comment}{//\ Tangential\ component\ 1}}
\DoxyCodeLine{00138\ \ \ \ \ vel\_refl[1]\ =\ sqrt(R\_gas\ *\ T\_R\ /\ Gas\_parameters[2])\ *\ normDist(rng);\ \textcolor{comment}{//\ Tangential\ component\ 2}}
\DoxyCodeLine{00139\ \}}

\end{DoxyCode}
