1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
// Copyright (C) 2024, NTNU
// Author: Jarle Vinje Kramer <jarlekramer@gmail.com; jarle.a.kramer@ntnu.no>
// License: GPL v3.0 (see separate file LICENSE or https://www.gnu.org/licenses/gpl-3.0.html)
use super::*;
use crate::line_force_model::LineForceModel;
/// This code block contains the logic to update the wake structure
impl DynamicWake {
/// Function that updates the wake data before the solver executes a new time step. The main job
/// is to ensure that geometry of the wake and the strength behind the first panels is correct.
///
/// # Steps that are performed in this function
/// Since the last time step, the line force model might have moved, and the wake points have
/// streamed downstream. That means that the following must happen:
/// - Synchronize the geometry for the first points in the wake to the geometry of the line
/// force model.
/// - Stream the old wake points downstream.
/// - Shift the strength of the panels downstream.
///
/// # Arguments
/// * `time_step` - The current value of the time step
/// * `line_force_model` - The line force model that the wake is based on
/// * `wake_points_freestream` - The freestream velocity at the points in the wake for the
/// current time step
pub fn update_before_solving(
&mut self,
time_step: Float,
line_force_model: &LineForceModel,
felt_span_points_freestream: &[SpatialVector]
) {
self.update_wake_points_before_solving(
time_step,
line_force_model,
felt_span_points_freestream
);
self.update_panel_data();
self.stream_strength_values_downstream();
}
/// Update the wake geometry and strength based on the final solution at a time step.
///
/// This will:
/// 1) stream the wake points downstream
/// 2) stream the strength downstream
pub fn update_after_solving(
&mut self,
new_circulation_strength: &[Float],
wake_points_freestream: &[SpatialVector],
) {
self.update_wing_strength(new_circulation_strength);
self.update_velocity_at_points(wake_points_freestream);
self.number_of_time_steps_completed += 1;
}
/// Update the wake points by streaming them downstream.
///
/// The first and second "rows" - meaning the wing geometries and the first row of wake points -
/// are treated as special cases. The rest are moved based on the euler method
pub fn update_wake_points_before_solving(
&mut self,
time_step: Float,
line_force_model: &LineForceModel,
felt_span_points_freestream: &[SpatialVector]
) {
self.synchronize_first_points_to_wing_geometry(line_force_model);
self.stream_free_wake_points_based_on_stored_velocity(time_step);
if self.settings.shape_damping_factor > 0.0 {
self.move_first_free_wake_points_with_damping(line_force_model, felt_span_points_freestream);
} else {
self.move_first_free_wake_points_no_damping(line_force_model, felt_span_points_freestream);
}
self.move_last_wake_points(felt_span_points_freestream);
}
/// Takes a line force vector as input, that might have a different position and orientation
/// than the previous time step, and updates the first points in the wake to match the new
/// geometry.
///
/// # Argument
/// * `line_force_model` - The line force model that the wake is based on
pub fn synchronize_first_points_to_wing_geometry(
&mut self,
line_force_model: &LineForceModel
) {
let nr_span_points = line_force_model.span_points_global.len();
for i in 0..nr_span_points {
self.points[i] = line_force_model.span_points_global[i];
}
}
/// Recalculates the panel data based on the current geometry of the wake.
pub fn update_panel_data(&mut self) {
for i in 0..self.indices.nr_panels() {
let (stream_index, span_index) = self.indices.reverse_panel_index(i);
let panel_points = self.panel_points(stream_index, span_index);
self.panels[i] = Panel::new(
panel_points,
self.potential_theory_settings.far_field_ratio,
self.panels_viscous_core_length[i]
);
}
}
/// Computes the velocity at all the wake points.
///
/// The velocity is calculated as the sum of the freestream velocity and the induced velocity.
/// However, if the settings contains and end-index for the induced velocities, the induced
/// velocities can be neglected for the last panels. This is useful for speeding up simulations.
///
/// # Argument
/// * `wake_points_freestream` - A vector containing the freestream velocity at the wake points
pub fn update_velocity_at_points(&mut self, wake_points_freestream: &[SpatialVector]) {
for i in 0..self.points.len() {
self.velocity_at_points[i] = wake_points_freestream[i];
}
let end_index = self.settings.end_index_induced_velocities_on_wake.min(
self.points.len()
);
if end_index > 0 && self.number_of_time_steps_completed > 2 {
let u_i_calc: Vec<SpatialVector> = self.induced_velocities(&self.points[0..end_index]);
for i in 0..end_index {
self.velocity_at_points[i] += u_i_calc[i];
}
}
}
/// Update the strength of the wake panels closest to the wing geometry.
///
/// This is the same as updating the circulation strength on the first panels in the wake.
pub fn update_wing_strength(&mut self, new_circulation_strength: &[Float]) {
for i in 0..new_circulation_strength.len() {
self.strengths[i] = new_circulation_strength[i];
}
}
fn first_free_wake_points_direction(
&self,
line_force_model: &LineForceModel,
felt_span_points_freestream: &[SpatialVector]
) -> Vec<SpatialVector> {
let nr_first_wake_points = self.indices.nr_points_along_span;
let mut direction_vectors: Vec<SpatialVector> = Vec::with_capacity(nr_first_wake_points);
match self.settings.first_wake_points_direction {
FirstWakePointsDirection::Chord => {
for i in 0..nr_first_wake_points{
direction_vectors.push(
line_force_model.chord_vectors_global_at_span_points[i].normalize()
)
}
},
FirstWakePointsDirection::Freestream => {
for i in 0..nr_first_wake_points {
direction_vectors.push(
felt_span_points_freestream[i].normalize()
)
}
},
FirstWakePointsDirection::ActualVelocity => {
if self.number_of_time_steps_completed > 2 {
for i in 0..nr_first_wake_points {
let local_velocity = 0.5 * (
self.velocity_at_points[i] +
self.velocity_at_points[nr_first_wake_points + i]
);
direction_vectors.push(
local_velocity.normalize()
)
}
} else {
for i in 0..nr_first_wake_points {
direction_vectors.push(
felt_span_points_freestream[i].normalize()
)
}
}
}
}
direction_vectors
}
/// Moves the first wake points after the wing geometry itself.
///
/// In general, the principle is that the first free wake points are moved from the wing
/// geometry and then *either* in the direction of the chord vector or the velocity vector.
fn move_first_free_wake_points_no_damping(
&mut self,
line_force_model: &LineForceModel,
felt_span_points_freestream: &[SpatialVector]
) {
let direction_vectors = self.first_free_wake_points_direction(
line_force_model,
felt_span_points_freestream
);
let first_panel_length = self.representative_chord_length * self.settings.first_panel_relative_length;
for i in 0..self.indices.nr_points_along_span {
let estimated_new_wake_point = self.points[i] + direction_vectors[i] * first_panel_length;
self.points[i + self.indices.nr_points_along_span] = estimated_new_wake_point;
}
}
/// Moves the first wake points after the wing geometry itself.
///
/// In general, the principle is that the first free wake points are moved from the wing
/// geometry and then *either* in the direction of the chord vector or the velocity vector.
fn move_first_free_wake_points_with_damping(
&mut self,
line_force_model: &LineForceModel,
felt_span_points_freestream: &[SpatialVector]
) {
let old_start_index = self.indices.nr_points_along_span;
let old_end_index = 2 * self.indices.nr_points_along_span;
let old_wake_points = self.points[old_start_index..old_end_index].to_vec();
let direction_vectors = self.first_free_wake_points_direction(
line_force_model,
felt_span_points_freestream
);
let first_panel_length = self.representative_chord_length * self.settings.first_panel_relative_length;
for i in 0..self.indices.nr_points_along_span {
let estimated_new_wake_point = self.points[i] + direction_vectors[i] * first_panel_length;
self.points[i + self.indices.nr_points_along_span] =
old_wake_points[i] * self.settings.shape_damping_factor +
estimated_new_wake_point * (1.0 - self.settings.shape_damping_factor);
}
}
/// Moves the last points in the wake.
///
/// The length of the last panel is determined based on the `last_panel_relative_length`
/// parameter in the settings, plus the chord length. The direction of the last panel is taken
/// to be the same as the direction between the previous two points in the wake.
///
/// # Arguments
/// * `line_force_model_data` - The line force model data that the should use for the update
pub fn move_last_wake_points(
&mut self,
felt_span_points_freestream: &[SpatialVector],
) {
let nr_points = self.points.len();
let nr_points_along_span = self.indices.nr_points_along_span;
let multi_panel_wake = self.indices.nr_panels_per_line_element > 1;
let start_index_last = nr_points - nr_points_along_span;
let start_index_previous = start_index_last - nr_points_along_span;
let change_directions: Vec<SpatialVector> = if multi_panel_wake {
(0..self.indices.nr_points_along_span).map(|i| {
let previous_point = self.points[start_index_previous + i];
let second_previous_point = self.points[start_index_previous - nr_points_along_span + i];
(previous_point - second_previous_point).normalize()
}).collect()
} else {
felt_span_points_freestream.iter()
.map(|v| v.normalize())
.collect()
};
for i in 0..self.indices.nr_points_along_span {
let change_vector = self.settings.last_panel_relative_length * self.representative_chord_length * change_directions[i];
self.points[start_index_last + i] = self.points[start_index_previous + i] + change_vector;
}
}
/// Stream all free wake points based on the Euler method.
fn stream_free_wake_points_based_on_stored_velocity(&mut self, time_step: Float) {
for i_stream in (2..self.indices.nr_points_per_line_element).rev() {
for i_span in 0..self.indices.nr_points_along_span {
let previous_flat_index = self.indices.point_index(i_stream - 1, i_span);
let current_flat_index = self.indices.point_index(i_stream, i_span);
let previous_wake_point = self.points[previous_flat_index];
let previous_velocity = self.velocity_at_points[previous_flat_index];
let integrated_point = previous_wake_point + time_step * previous_velocity;
if self.settings.shape_damping_factor > 0.0 {
let current_wake_point = self.points[current_flat_index];
self.points[current_flat_index] = current_wake_point * self.settings.shape_damping_factor +
integrated_point * (1.0 - self.settings.shape_damping_factor);
} else {
self.points[current_flat_index] = integrated_point;
}
}
}
}
/// Shifts the strength of the panels downstream.
pub fn stream_strength_values_downstream(&mut self) {
for i_stream in (1..self.indices.nr_panels_per_line_element).rev() {
for i_span in 0..self.indices.nr_panels_along_span {
let current_index = self.indices.panel_index(i_stream, i_span);
let previous_index = self.indices.panel_index(i_stream - 1, i_span);
self.strengths[current_index] = self.strengths[previous_index];
}
}
}
}