0% found this document useful (0 votes)
144 views11 pages

Pipe Network Assignment: Computation in Engineering I

This document describes a pipe network assignment which involves developing a C++ application to calculate flows in a pipe network. The key aspects are: 1. The pipe network consists of nodes and tubes between nodes. Nodes have coordinates and a flow value, tubes have a diameter and connect two nodes. 2. An algorithm is provided to set up a permeability matrix from the tube properties, set up a load vector from the node flows, impose a boundary condition, solve the resulting linear system to obtain head values at nodes, and calculate flows in each tube from the heads. 3. The input file format is defined which specifies the network topology in three sections - number of nodes/tubes, node properties, and tube

Uploaded by

Dương Nguyễn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
144 views11 pages

Pipe Network Assignment: Computation in Engineering I

This document describes a pipe network assignment which involves developing a C++ application to calculate flows in a pipe network. The key aspects are: 1. The pipe network consists of nodes and tubes between nodes. Nodes have coordinates and a flow value, tubes have a diameter and connect two nodes. 2. An algorithm is provided to set up a permeability matrix from the tube properties, set up a load vector from the node flows, impose a boundary condition, solve the resulting linear system to obtain head values at nodes, and calculate flows in each tube from the heads. 3. The input file format is defined which specifies the network topology in three sections - number of nodes/tubes, node properties, and tube

Uploaded by

Dương Nguyễn
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Chair for Computation in Engineering

Technical University of Munich

Pipe network assignment


A village in Bavaria plans to build a new water supply network. Your task is to develop a C++ console
application, which calculates the flows in the tubes of such a network. The pipe network consists of
nodes and tubes between the nodes.
50m³/s
1 2
1 2 3
A pipe network consists of
3 500m • Nodes: A node is defined by its
5
6 two spatial coordinates, a global
4 7
4 5 id, and a flow value 𝑄 (inflow:
8 10 𝑄 < 0, outflow: 𝑄 > 0)
500m
50m³/s • Tubes: A tube has a diameter
6 7 8 and lies between two nodes
9 11
150m³/s
500m 500m 1000m

Computation in Engineering I 1
Chair for Computation in Engineering
Technical University of Munich

Pipe network assignment


1. Write a shared library that allows to
• read input data for nodes and tubes from a file, see section input file
• use this data to set up a class structure given in the section class structure
• compute the resulting fluxes according to sections physical problem, example and algorithm
• output the results either on screen or in an output file
2. Add a unit test executable for your library and add the tests (pipenetwork_test.cpp) uploaded
in Moodle. You will have to provide the catch2 header for the tests to compile (see e.g. exercise 4)
3. Write a driver executable that uses your library to print the fluxes in a pipe network given in sec-
tion input file. Store the data in a text file pipedata.txt and read that file from your driver.
You are also given a simple linear algebra library on Moodle that allows you to perform computations
with vectors and matrices.
The assignment is due to January 26th, 2022. There will be short individual online interviews via
zoom. The details though Moodle.
Computation in Engineering I 2
Chair for Computation in Engineering
Technical University of Munich

Pipe network assignment: Physical problem


The underlying physical problem is explained by terial. For laminar flow:
considering the example of a single tube: 64 𝑢⋅𝑑
𝜆= , 𝑅𝑒 = ,
Δℎ Re 𝜈
ℎ𝑎 where 𝜈 = 10−6 for water. With
ℎ𝑏
𝑞 4⋅𝑞
𝑢= = 2 ,
𝑞 𝐴 𝑑 𝜋
we get
The loss of hydraulic head in the tube depends
𝜋 ⋅ 𝑔 ⋅ 𝑑4 𝜋 ⋅ 𝑔 ⋅ 𝑑4
on the velocity 𝑢 of the flow: 𝑞= Δℎ = ℎ − ℎ𝑏 ,
128 ⋅ 𝜈 ⋅ 𝑙 128 ⋅ 𝜈 ⋅ 𝑙 𝑎
𝑑 𝑢2
Δℎ = 𝜆 , or simply 𝑞 = 𝐵 ℎ𝑎 − ℎ𝑏 , where
𝑙 2𝑔
where 𝑙 is the length of the tube, 𝑑 the diameter 𝜋 ⋅ 𝑔 ⋅ 𝑑4
𝐵=
and 𝑔 = 9.81 the acceleration due to gravity. The 128 ⋅ 𝜈 ⋅ 𝑙
factor 𝜆 describes the roughness of the tube ma- represents the permeability of the tube.
Computation in Engineering I 3
Chair for Computation in Engineering
Technical University of Munich

Pipe network assignment: Example


To demonstrate the procedure calculating the zero in every node (note: outflow is positive):
flow distribution in a pipe network, consider 𝑞1 − 𝑞3 − 𝑄1 = 0
the following example: −𝑞1 + 𝑞2 + 𝑄2 = 0
ℎ1 −𝑞2 + 𝑞3 = 0
ℎ2 𝑄2
which gives:
𝑄1
𝑞1 𝐵1 ℎ1 − ℎ2 − 𝐵3 ℎ3 − ℎ1 − 𝑄1 = 0
2
−𝐵1 ℎ1 − ℎ2 + 𝐵2 ℎ2 − ℎ3 + 𝑄2 = 0
1
ℎ3 −𝐵2 ℎ2 − ℎ3 + 𝐵3 ℎ3 − ℎ1 =0
𝑞2
𝑞3 or 𝐁𝐡 = 𝐐 in matrix form:
3 ℎ1
𝐵1 + 𝐵3 −𝐵1 −𝐵3 −𝑄1
−𝐵1 𝐵1 + 𝐵2 −𝐵2 ℎ2 = −𝑄2
The system must fulfill the condition that the
−𝐵3 −𝐵2 𝐵2 + 𝐵3 ℎ3 −0
sum of the inflow and the outflow has to be
Computation in Engineering I 4
Chair for Computation in Engineering
Technical University of Munich

Pipe network assignment: Example


The matrix 𝐁 represents the global permeabil- This can be enforced, for example, by setting the
ity matrix and 𝐐 the load vector. The elements off-diagonal entries 𝐾𝑖1 and 𝐾1𝑖 of the coefficient
in the solution vector 𝐡 are the values of the matrix and the entry 𝑄𝑖 of the right hand side vector
head at the nodes. to 0, while setting the diagonal entry 𝐾11 to 1.
The resulting equation system is singular, i.e. Now we have the following equation system:
it has no unique solution. This is due to the
1 0 0 ℎ1 −0
fact that all formulas are based on the
0 𝐵1 + 𝐵2 −𝐵2 ℎ2 = −𝑄2
difference in hydraulic head between two
0 −𝐵2 𝐵2 + 𝐵3 ℎ3 −0
nodes, but an absolute height of the system is
not specified. Therefore, we have to include Just like in finite elements there are other methods
such a boundary condition by defining the to impose Dirichlet boundary conditions, however,
absolute height of one node (e.g. ℎ1 ≔ 0). the presented method is sufficient.

Computation in Engineering I 5
Chair for Computation in Engineering
Technical University of Munich

Pipe network assignment: Algorithm


The following pseudo code sketches the algorithm to compute the fluxes of the pipe network (Note,
that indices start from 0 here):
Create zero-initialized permeability matrix B 1. Set up permeability matrix
∀ tubes i:
➢ get id1 and id2 of the two bounding nodes
➢ compute permeability factor B_i
➢ assemble B_i into the B matrix:
• B(id1, id1) += B_i
• B(id2, id2) += B_i
• B(id1, id2) -= B_i
• B(id2, id1) -= B_i

create load vector Q 2. Set up load vector


∀ nodes i:
Q[i] = -Q_in[i] (the given (in-/out) flow value)
Computation in Engineering I 6
Chair for Computation in Engineering
Technical University of Munich

Pipe network assignment: Algorithm


for i = 1 ... number nodes: 3. Impose boundary condition
➢ B(i, 0) = 0
➢ B(0, i) = 0
B(0,0) = 1
Q(0) = 0

solve linear equation system to get head vector h 4. Solve linear system

create zero-initialized vector of fluxes q 5. Postprocess fluxes


∀ tubes i:
➢ extract the entries h1 and h2 at the ids of the
two bounding nodes from h
➢ compute permeability factor B_i
➢ q[i] = B_i * (h1 - h2)

return q
Computation in Engineering I 7
Chair for Computation in Engineering
Technical University of Munich

Pipe network assignment: Input file


8
The input file containing the network data is divided into three parts: 11
0 0 -50
1. Number of nodes 1000 0 -50
Number of tubes 2000 0 0
0 500 0
2. Node data: Each line contains one node as x-coordinate, y- 500 500 0
coordinate and the inflow/outflow separated by a whitespace. 0 1000 -50
1000 1000 0
3. Tube data: Each line contains one tube defined by start and end
2000 1000 150
node ids and its diameter 0 1 0.5
The input file is saved as text file. 1 2 0.5
0 3 0.5
3 4 0.5
The example on the right side has 8 nodes and 11 tubes with inflow at 4 1 0.5
1 7 0.5
the nodes 0, 1 and 5 and outflow at the node 7. All tubes have the 2 7 0.5
same diameter of 0.5 meters. 3 5 0.5
5 6 0.5
4 6 0.5
6 7 0.5
Computation in Engineering I 8
Chair for Computation in Engineering
Technical University of Munich

Pipe network assignment: Input file


The following code shows how to read a file with the name input.txt whose first entry is an integer
number specifying the number of following floating point numbers.
std::ifstream infile( "input.txt" );

int numberOfValues;
infile >> numberOfValues;

std::vector<double> data;
data.reserve( numberOfValues );

for( int i = 0; i < numberOfValues; ++i )


{
double value;
infile >> value;

data.push_back( value );
}
Computation in Engineering I 9
Chair for Computation in Engineering
Technical University of Munich

Pipe network assignment: Class structure


PipeNetwork
PipeNetwork( filename : const std::string& )
computeFluxes( ) const : std::vector<double>
...

* *
Node Tube
Node( x : double, y : double, Tube( node1 : Node*, node2 : Node*,
flow : double, id : int ) diameter : double )
2
x( ) const : double length( ) const : double
y( ) const : double permeability( ) const : double
flow( ) const : double node1( ) const : const Node*
id( ) const : int node2( ) const : const Node*
... ...
Computation in Engineering I 10
Chair for Computation in Engineering
Technical University of Munich

Pipe network assignment: Code


• Set up a new source project using CMake. Your source project shall not contain project files of
any kind other than the CMakeLists.txt files. The process of creating a build project from your
source code can be part of the interview.
• Use a separate pair of header and source files for each class you introduce and choose the same
name as the class. For example: PipeNetwork.hpp, PipeNetwork.cpp, Node.hpp, Node.cpp,
Tube.hpp and Tube.cpp
• Embed your library code into the (nested) namespaces cie and pipenetwork
• Choose the member variables according to ownership model shown in the UML diagram on the
previous page. You may add additional members.
• Make all member variables private
• Don’t modify the unit tests, you can, however, add additional tests for code you write. Make sure
that you set up your test files such that exactly one file defines CATCH_CONFIG_MAIN.
• Pay attention to the const qualifiers in the UML diagram, most member functions are const and
some return values
Computation in Engineering I 11

You might also like