-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreateReducer.m
More file actions
58 lines (47 loc) · 1.39 KB
/
createReducer.m
File metadata and controls
58 lines (47 loc) · 1.39 KB
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
function createReducer
soundSpeed = C.soundSpeed;
gravity = C.gravity;
viscosity = C.viscosity;
height = C.height;
slope = C.slope;
density = C.density;
time_step = C.timeStep;
g = gravity;
c = soundSpeed;
r = density;
% d = diameter;
dt = time_step;
s = sin(slope);
gs = g * s;
rc = r * c;
%% символы
% n
% / | \
% l--0--r
% |
% p
syms v_n v_l v_0 v_r v_p p_n p_l p_0 p_r h_0 h_n u d
dp = p_n - p_0;
dv = v_n - v_0;
dh = h_n - h_0;
v = [v_l v_0 v_r];
p = [p_l p_0 p_r];
h = h_0;
Re = @(velocity) abs(velocity) * d / viscosity;
% debug
lambda = @(velocity) .3164 / Re(velocity)^.25 * 2e3;
head = @(pressure) pressure ./ gravity ./ density + height;
p2 = @(v) v * abs(v);
%% уравнения
A = p_n + rc * v_n == p_l + rc * v_l - ( lambda((v_l + 0) / 2) * p2(v_l) / 2 / d + gs ) * rc * dt;
B = p_n - rc * v_n == p_r - rc * v_r + ( lambda((0 + v_r) / 2) * p2(v_r) / 2 / d + gs ) * rc * dt;
%% экспорт
unknowns = [p_n v_n];
outputs = {'p_n' 'v_n'};
% AB
solve([A B], unknowns);
matlabFunction(simplify(ans.p_n), simplify(ans.v_n), 'Vars', {p_l p_r v_l v_r d}, 'Outputs', outputs, 'File', '+reducers/AB');
% A
matlabFunction(simplify(solve(A, p_n)), 'Vars', {p_l v_l v_0 v_n d}, 'Outputs', {'p'}, 'File', '+reducers/A');
% B
matlabFunction(simplify(solve(B, p_n)), 'Vars', {p_r v_0 v_r v_n d}, 'Outputs', {'p'}, 'File', '+reducers/B');