improving the solution method in wanda
TRANSCRIPT
Improving the Solution Method in Wanda
Leonard Huijzer
Delft University of Technology, The Netherlands
March 6, 2018
Water Hammer
2
Water Hammer
2
Water Hammer
2
Structure
1 Model
2 Current Situation
(a) Robustness(b) Performance(c) Maintainability
3 Research Approach
(a) Robustness(b) Performance(c) Maintainability
4 Summary and Approach
5 Planning
3
Model – Steady State Flow
Liquid module quantities:
• Energy head: H = pρg + z
• Volumetric flow rate: Q = Av
Example: Small System (incompressible, viscous)
4
Model – Steady State Flow
Example: Small System (incompressible, viscous)
H1 = c1QA + Q1 − Q2 = 0
QA = 0HA = H1
HA = H2
H2 − H3 =λL
8A/O
Q2|Q2|A2g
Q2 = Q3
HB = H3
HB = H4
QB = 0QB + Q3 + Q4 = 0
H4 = c2
4
Model – Steady State Flow
Apply Newton-Raphson method:
f(u(k+1)) ≈ f(u(k)) + J(u(k))�u(k+1) − u(k)
�= 0
where u(k) = [Q(k)1 H
(k)1 . . . Q
(k)n H
(k)n ]� and J(u(k)) is the Jacobian
5
Model – Steady State FlowApply Newton-Raphson method:
Example: Small System
0 1 0 0 0 0 0 0 0 0 0 01 0 1 0 −1 0 0 0 0 0 0 00 0 1 0 0 0 0 0 0 0 0 00 1 0 −1 0 0 0 0 0 0 0 00 0 0 −1 0 1 0 0 0 0 0 00 0 0 0 −c3 1 0 −1 0 0 0 00 0 0 0 1 0 −1 0 0 0 0 00 0 0 0 0 0 0 1 0 −1 0 00 0 0 0 0 0 0 0 0 −1 0 10 0 0 0 0 0 0 0 1 0 0 00 0 0 0 0 0 1 0 1 0 1 00 0 0 0 0 0 0 0 0 0 0 1
Q1
H1
QA
HA
Q2
H2
Q3
H3
QB
HB
Q4
H4
=
c10000c400000c2
5
Model – Transient FlowViscous , compressible in pipes
∂v
∂t+ g
∂H
∂x+
λ
8A/Ov |v | = 0
∂H
∂t+
c2
g
∂v
∂x= 0
c = pressure wave speedSolution method:
1 Solve internal pipe points atΔt/2
2 Solve internal pipe points atΔt
3 Solve rest of system + pipeboundaries at Δt usingNewton-Raphson
6
Model – Transient Flow
Example: Sewage System
7
Current Situation – Robustness
Example: Steady Flow H
Now:
H2 − H3 =λL
8A/O
Q2|Q2|A2g
has an infinite number of solutions. Fix: Prescribe H on A or B .
8
Current Situation – Robustness
Example: Transient Flow H
Component phases can cause trouble.Fix: Take H from previous time-step.
9
Current Situation – Robustness
Example: Steady State Q
H1 = c1H1 = HA
QA + Q1 + Q2 = 0QA = 0H2 = HA
H2 = c2
Fix??Can also happen in transient flow simulations.Furthermore, if c1 �= c2 then contradiction!
10
Current Situation – Performance
What are we working with?
(a) Drinking water (b) Noord-Holland 1
11
Current Situation – Performance
What are we working with?
(a) Drinking water (b) Noord-Holland 1
Small (but many), asymmetric, sparse and banded� LU-decomposition
11
Current Situation – PerformanceCurrent solution method
1 Determine component ordering2 For each time step
(a) If phase change: detect if and where H is undetermined; apply fix(b) Solve internal pipe points(c) Solve system using Newton-Raphson � IMSL matrix solver
Matrix: solve using LU-decomposition with Markowitz pivoting:Select pivot which minimises fill-in
(a) 2D Laplacian (b) L (c) U
12
Current Situation – Maintainability
Some systems are unsolvable:
• Underdetermined
• Contradictory
Lead to singular matrices
Why is this a problem?:
• International Mathematics and Statistics Library (IMSL) matrixsolver crashes or loops
• Limited troubleshooting
• Paid license
13
Research Goals
• Robustness: prevent or handle singular matrices
• Performance: no concessions
• Maintainability: open source library with permissive license
Goal:Find and implement numerical library which satisfies these requirements
14
Research Approach – RobustnessGoal: prevent singular matrices• Physical model• Structurally singular systems
Definition
Let M ∈ Rn×n. M is called structurally singular if every N ∈ Rn×n,with Nij = 0 whenever Mij = 0, is singular.
H1 = c1H1 = HA
QA + Q1 + Q2 = 0QA = 0H2 = HA
H2 = c2
15
Research Approach – Robustness
Let the matrix M ∈ R6×6 bedefined by
Mij =
�1, if variable j in equation i0, otherwise
H1 = c1H1 = HA
QA + Q1 + Q2 = 0QA = 0H2 = HA
H2 = c2
M =
1 0 0 0 0 01 0 1 0 0 00 1 0 1 0 10 0 0 1 0 00 0 1 0 1 00 0 0 0 1 0
15
Research Approach – Robustness
6
5
4
3
2
1
Q2
H2
QA
HA
Q1
H1
H1 = c1H1 = HA
QA + Q1 + Q2 = 0QA = 0H2 = HA
H2 = c2
M =
1 0 0 0 0 01 0 1 0 0 00 1 0 1 0 10 0 0 1 0 00 0 1 0 1 00 0 0 0 1 0
15
Research Approach – Robustness
Goal: detect ’singular’ matricesDeterminant not useful in finite precision.
Definition: Condition Number
Let M ∈ Rn×n. The condition number of M is defined as
κ(M) = �M� · �M−1�
Use estimation techniques.
16
Research Approach – Robustness
Goal: detect ’singular’ matricesDeterminant not useful in finite precision.
Singular Value Decomposition
Let M ∈ Rn×n. The SVD is given by
M = UΣV�
where Σ = diag(σ1,σ2, . . . ,σn) and σ1 ≥ σ2 ≥ · · · ≥ σn ≥ 0.
Note that: κ2(M) =σmax
σminAlternatives: QR-decomposition, . . .
16
Research Approach – Performance
Test cases
(a) Noord-Holland 1 (b) Noord-Holland 2
17
Research Approach – Performance
Test cases
H-detect IMSL solver Matrix build Miscellaneous0
0.05
0.1
0.15
0.2
0.25
0.3
0.35
0.4
Perc
enta
ge o
f tim
e
Total time: 68s
(a) Noord-Holland 1
H-detect IMSL solver Matrix build Miscellaneous0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
Perc
enta
ge o
f tim
e
Total time: 1654s
(b) Noord-Holland 2
17
Research Approach – PerformancePerformance improvements:• Fill-in reduction by component ordering; now Breadth-First Search
18
Research Approach – PerformancePerformance improvements:• Fill-in reduction by component ordering; now Breadth-First Search• Fill-in reduction via matrix reordering: e.g., Cuthill-McKee
18
Research Approach – Performance
Performance improvements:
• Fill-in reduction by component ordering; now Breadth-First Search
• Fill-in reduction via matrix reordering: e.g., Cuthill-McKee
• Fill-in reduction via pivoting: e.g., Markowitz
At each step minimise
(r(k)i − 1)(c
(k)j − 1)
where r(k)i = nnz(M(k)(i , :)) and c
(k)j = nnz(M(k)(:, j))
18
Research Approach – Performance
Performance improvements:
• Fill-in reduction by component ordering; now Breadth-First Search
• Fill-in reduction via matrix reordering: e.g., Cuthill-McKee
• Fill-in reduction via pivoting: e.g., Markowitz
• (LU-decomposition + condition number estimation vs.SVD,QR ,. . . )
18
Research Approach – Performance
Other potential improvements:
• Newton-Raphson alternatives: Quasi-Newton, Picard iteration
• Algorithm that detects undetermined nodes
19
Research Approach – Maintainability
Requirements:
• Open source
• Permissive license
• (Free)
Candidates:
• Linear Algebra Package (LAPACK)
• PLASMA, MAGMA
• Multi-frontal Massively Parallel Solver (MUMPS)
Which offers best performance?
20
Summary and ApproachSummary:• The Wanda model: steady and transient flow• Current situation: robustness, performance, maintainability
Approach:1 Prevent singular matrices:
• detect structural singularities• physical model
2 Matrix solver performance vs. other routines3 Implement LAPACK
• condition number estimation• rank-revealing decomposition• Matrix reordering• Evaluate performance
4 If necessary, implement PLASMA, MAGMA, MUMPS5 Other improvements
• Algorithm which detects undetermined nodes• Newton-Raphson alternatives• . . .
21
Planning
1 March: Detect structural singularities, matrix solver performancevs. other routines (using test cases)
2 April: Replace IMSL by LAPACK, detect singular matrices,improve matrix ordering
3 May: Condition number estimation, rank-revealingdecompositions, evaluate performance and robustness
4 June: Test PLASMA, MAGMA, MUMPS
5 July: Report draft, other improvements
6 August: Finish report, presentation
22
Improving the Solution Method in Wanda
Leonard Huijzer
Delft University of Technology, The Netherlands
March 6, 2018
Bibliography
Anderson, E., Z. Bai, C. Bischof, S. Blackford, J. Demmel, J. Dongarra, J. Du Croz,A. Greenbaum, S. Hammarling, A. McKenney, and D. Sorensen (1999). LAPACK Users’Guide. Third. Philadelphia, PA: Society for Industrial and Applied Mathematics.
Golub, G. and C. Van Loan (1996). Matrix Computations. Johns Hopkins Studies in theMathematical Sciences. Johns Hopkins University Press. isbn: 9780801854149.
Hydrodynamica van Leidingsystemem (2015). Deltares.
IMSL Fortran Math Library (2014). RogueWave Software.
Multifrontal Massively Parallel Solver. User’s Guide (2016).
WANDA 4.5 User Manual (2017). Deltares.
Wylie, E. and V. Streeter (1978). Fluid transients. Advanced book program v. 1977.McGraw-Hill International Book Co.
24