GSI_Toolbox 1.0.0
A toolbox for Gas-Surface Interaction simulations
Loading...
Searching...
No Matches
Local_Kernels.h
1
11template <typename T>
12int sgn(T val) {
13 return (T(0) < val) - (val < T(0));
14}
15
35template <typename T>
36void sample_CLL(T* vel_in, T* vel_refl, T* GSI_parameters, T* Gas_parameters, T* Surface_parameters) {
37
38 // Retrieve GSI and surface parameters
39 T alpha_n = GSI_parameters[0]; // Normal accommodation coefficient
40 T sigma_t = GSI_parameters[1]; // Tangential momentum accommodation coefficient
41 T alpha_t = sigma_t * (2 - sigma_t); // Tangential accommodation coefficient
42 T T_W = Surface_parameters[0]; // Wall temperature
43
44 // Random number generator setup
45 std::random_device rd;
46 std::seed_seq fullSeed{rd(), rd(), rd(), rd(), rd(), rd(), rd(), rd(), rd(), rd()};
47 std::mt19937 rng(fullSeed); // Random number generator
48 std::uniform_real_distribution<T> uniformDist(0.0f, 1.0f); // Uniform distribution in [0, 1]
49
50 // Calculate velocity scale based on gas properties and surface temperature
51 T vel_wall = sqrt(2.0 * R_gas / Gas_parameters[2] * T_W);
52
53 // Generate random numbers for sampling
54 T x1 = uniformDist(rng), x2 = uniformDist(rng), x3 = uniformDist(rng),
55 x4 = uniformDist(rng), x5 = uniformDist(rng), x6 = uniformDist(rng);
56
57 // Calculate reflection parameters
58 T r1 = sqrt(-alpha_n * log(x1));
59 T r3 = sqrt(-alpha_t * log(x3));
60 T r5 = sqrt(-alpha_t * log(x5));
61 T theta2 = 2.0 * M_PI * x2;
62 T theta4 = 2.0 * M_PI * x4;
63 T theta6 = 2.0 * M_PI * x6;
64
65 // Compute the magnitude of the input velocity components
66 T vel_norm_m = fabs(vel_in[2] / vel_wall) * sqrt(1 - alpha_n);
67 T vel_tan1_m = vel_in[0] / vel_wall * sqrt(1 - alpha_t);
68
69 // Reflect the velocity in normal and tangential directions
70 vel_refl[2] = vel_wall * sqrt(r1 * r1 + vel_norm_m * vel_norm_m + 2 * r1 * vel_norm_m * cos(theta2)); // Normal component
71 vel_refl[0] = vel_wall * (vel_tan1_m + r3 * cos(theta4)); // Tangential component 1
72 vel_refl[1] = vel_wall * (r5 * cos(theta6)); // Tangential component 2
73}
74
95template <typename T>
96void sample_DRIA(T* vel_in, T* vel_refl, T* GSI_parameters, T* Gas_parameters, T* Surface_parameters) {
97
98 // Compute the magnitude of the input velocity
99 T vel_in_norm = sqrt(vel_in[0] * vel_in[0] + vel_in[1] * vel_in[1] + vel_in[2] * vel_in[2]);
100
101 // Retrieve GSI and surface parameters
102 T alpha = GSI_parameters[0]; // Accommodation coefficient
103 T T_W = Surface_parameters[0]; // Wall temperature
104 T T_G = Gas_parameters[0]; // Gas temperature
105 T gas_speed = Gas_parameters[3]; // Gas speed
106
107 // Compute characteristic gas temperature based on speed
108 T T_K = gas_speed * gas_speed * Gas_parameters[2] / 3.0 / R_gas;
109
110 // Random number generator setup
111 std::random_device rd;
112 std::seed_seq fullSeed{rd(), rd(), rd(), rd(), rd(), rd(), rd(), rd(), rd(), rd()};
113 std::mt19937 rng(fullSeed); // Random number generator
114 std::uniform_real_distribution<T> uniformDist(0.0f, 1.0f); // Uniform distribution in [0, 1]
115 std::normal_distribution<T> normDist(0.0f, 1.0f); // Normal distribution for random velocities
116
117 // Compute reflected temperature based on accommodation coefficient
118 T T_R = (1.0 - alpha) * T_K + alpha * T_W;
119
120 // Calculate velocity scale based on gas properties and reflected temperature
121 T vel_wall = sqrt(2.0 * R_gas / Gas_parameters[2] * T_R);
122
123 // Generate random numbers for sampling
124 T x1 = uniformDist(rng), x2 = uniformDist(rng), x3 = uniformDist(rng),
125 x4 = uniformDist(rng), x5 = uniformDist(rng), x6 = uniformDist(rng);
126
127 // Calculate reflection parameters
128 T r1 = sqrt(-log(x1));
129 T r3 = sqrt(-log(x3));
130 T r5 = sqrt(-log(x5));
131 T theta2 = 2.0 * M_PI * x2;
132 T theta4 = 2.0 * M_PI * x4;
133 T theta6 = 2.0 * M_PI * x6;
134
135 // Reflect the velocity in normal and tangential directions
136 vel_refl[2] = vel_wall * r1; // Normal component
137 vel_refl[0] = sqrt(R_gas * T_R / Gas_parameters[2]) * normDist(rng); // Tangential component 1
138 vel_refl[1] = sqrt(R_gas * T_R / Gas_parameters[2]) * normDist(rng); // Tangential component 2
139}