LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
LevelDependentFluidStationaryMean.m
1% res = LevelDependentFluidStationaryMean (masses, iniF, KF, cloF, iniB, KB, cloB, T)
2% Calculates the stationary mean fluid level of first order and second order
3% level dependent (multi-regime) fluid models, from the matrix-exponential
4% building blocks returned by SecondOrderLevelDependentFluidSolve.
5%
6% * masses: list of point-mass vectors (K+1 vectors located at levels
7% T(1)=0, T(2), ..., T(K+1)=top threshold)
8% * iniF, KF, cloF: initial vector, matrix exponent and closing matrix for
9% the forward direction for each regime (a list of size K)
10% * iniB, KB, cloB: initial vector, matrix exponent and closing matrix for
11% the backward direction for each regime (a list of size K)
12% * T: vector of regime thresholds (length K)
13%
14% res is the scalar mean fluid level E[X].
15%
16% Note: the level-dependent stationary density in regime k over the interval
17% [T(k),T(k+1)] is
18% pi_k(x) = iniF{k}*expm(KF{k}*(x-T(k)))*cloF{k}
19% + iniB{k}*expm(KB{k}*(T(k+1)-x))*cloB{k}
20% and E[X] is obtained in closed form by integrating x*pi_k(x) over each
21% regime plus the contribution T(j)*sum(masses{j}) of the point masses.
22function res = LevelDependentFluidStationaryMean (masses, iniF, KF, cloF, iniB, KB, cloB, T)
23
24 K = length(T);
25 T = [0 T];
26 N = length(masses{1});
27 h = ones(N,1);
28
29 % integrals of a matrix exponential over [0,L] via nilpotent block
30 % augmentation (robust even if M is singular, i.e. has a zero eigenvalue):
31 % J0 = int_0^L expm(M u) du, J1 = int_0^L u*expm(M u) du
32 function [J0, J1] = expIntMoments(M, L)
33 n = size(M,1);
34 Zn = zeros(n);
35 In = eye(n);
36 A = [M, In, Zn; Zn, Zn, In; Zn, Zn, Zn];
37 W = expm(A*L);
38 J0 = W(1:n, n+1:2*n);
39 W13 = W(1:n, 2*n+1:3*n);
40 J1 = L*J0 - W13;
41 end
42
43 res = 0;
44 % contribution of the point masses (located at levels T(1..K+1))
45 for j=1:K+1
46 res = res + T(j) * sum(masses{j});
47 end
48 % contribution of the continuous density in each regime
49 for k=1:K
50 Tk = T(k+1) - T(k);
51 [J0F, J1F] = expIntMoments(KF{k}, Tk);
52 [J0B, J1B] = expIntMoments(KB{k}, Tk);
53 res = res + iniF{k} * (T(k)*J0F + J1F) * cloF{k} * h;
54 res = res + iniB{k} * (T(k+1)*J0B - J1B) * cloB{k} * h;
55 end
56end
Definition Station.m:245