{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Minimal Example pandapipes\n",
"\n",
"## Creating a low pressure gas network\n",
"\n",
"We consider the following simple 3-junction example network with an ideal valve as a minimal example:\n",
"\n",
"\n",
"\n",
"The above network can be created in pandapipes as follows:"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import pandapipes as pp\n",
"\n",
"#create empty net\n",
"net = pp.create_empty_network(fluid=\"lgas\")\n",
"\n",
"# create junction\n",
"j1 = pp.create_junction(net, pn_bar=1.05, tfluid_k=293.15, name=\"Junction 1\")\n",
"j2 = pp.create_junction(net, pn_bar=1.05, tfluid_k=293.15, name=\"Junction 2\") \n",
"j3 = pp.create_junction(net, pn_bar=1.05, tfluid_k=293.15, name=\"Junction 3\") \n",
"\n",
"# create junction elements\n",
"ext_grid = pp.create_ext_grid(net, junction=j1, p_bar=1.1, t_k=293.15, name=\"Grid Connection\")\n",
"sink = pp.create_sink(net, junction=j3, mdot_kg_per_s=0.045, name=\"Sink\")\n",
"\n",
"# create branch element\n",
"pipe = pp.create_pipe_from_parameters(net, from_junction=j1, to_junction=j2, length_km=0.1, diameter_m=0.05, name=\"Pipe 1\")\n",
"valve = pp.create_valve(net, from_junction=j2, to_junction=j3, diameter_m=0.05, opened=True, name=\"Valve 1\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Note that the fluid used here is lgas. You can find 5 predefined fluids in pandapipes:\n",
" - lgas\n",
" - hgas\n",
" - hydrogen\n",
" - water\n",
" - air\n",
"\n",
"And that the predefined valve element is an ideal valve. "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Data Structure\n",
"\n",
"Each dataframe in a pandapipes net object contains the information about one pandapipes element, such as pipe, sink, valve etc."
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": " name pn_bar tfluid_k height_m in_service type\n0 Junction 1 1.05 293.15 0.0 True junction\n1 Junction 2 1.05 293.15 0.0 True junction\n2 Junction 3 1.05 293.15 0.0 True junction",
"text/html": "
\n\n
\n \n \n | \n name | \n pn_bar | \n tfluid_k | \n height_m | \n in_service | \n type | \n
\n \n \n \n 0 | \n Junction 1 | \n 1.05 | \n 293.15 | \n 0.0 | \n True | \n junction | \n
\n \n 1 | \n Junction 2 | \n 1.05 | \n 293.15 | \n 0.0 | \n True | \n junction | \n
\n \n 2 | \n Junction 3 | \n 1.05 | \n 293.15 | \n 0.0 | \n True | \n junction | \n
\n \n
\n
"
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"net.junction"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": " name from_junction to_junction std_type length_km diameter_m k_mm \\\n0 Pipe 1 0 1 None 0.1 0.05 1.0 \n\n loss_coefficient alpha_w_per_m2k text_k qext_w sections in_service \\\n0 0.0 0.0 293.0 0.0 1 True \n\n type \n0 pipe ",
"text/html": "\n\n
\n \n \n | \n name | \n from_junction | \n to_junction | \n std_type | \n length_km | \n diameter_m | \n k_mm | \n loss_coefficient | \n alpha_w_per_m2k | \n text_k | \n qext_w | \n sections | \n in_service | \n type | \n
\n \n \n \n 0 | \n Pipe 1 | \n 0 | \n 1 | \n None | \n 0.1 | \n 0.05 | \n 1.0 | \n 0.0 | \n 0.0 | \n 293.0 | \n 0.0 | \n 1 | \n True | \n pipe | \n
\n \n
\n
"
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"net.pipe"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": " name junction p_bar t_k in_service type\n0 Grid Connection 0 1.1 293.15 True pt",
"text/html": "\n\n
\n \n \n | \n name | \n junction | \n p_bar | \n t_k | \n in_service | \n type | \n
\n \n \n \n 0 | \n Grid Connection | \n 0 | \n 1.1 | \n 293.15 | \n True | \n pt | \n
\n \n
\n
"
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"net.ext_grid"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Pipe Flow\n",
"\n",
"We now run a pipe flow:\n"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"hp.pandapipes.pipeflow - INFO: niter 0\n",
"hp.pandapipes.pipeflow - INFO: niter 1\n",
"hp.pandapipes.pipeflow - INFO: niter 2\n",
"hp.pandapipes.pipeflow - INFO: niter 3\n",
"hp.pandapipes.pipeflow - INFO: ---------------------------------------------------------------------------------\n",
"hp.pandapipes.pipeflow - INFO: Calculation completed. Preparing results...\n",
"hp.pandapipes.pipeflow - INFO: Converged after 4 iterations.\n",
"hp.pandapipes.pipeflow - INFO: Norm of residual: 1.6351116571833302e-08\n",
"hp.pandapipes.pipeflow - INFO: tol_p: 0.0001\n",
"hp.pandapipes.pipeflow - INFO: tol_v: 0.0001\n"
]
}
],
"source": [
"pp.pipeflow(net)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"And check out at the results for junctions and pipes:"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": " p_bar t_k\n0 1.100000 293.15\n1 0.913916 293.15\n2 0.913916 293.15",
"text/html": "\n\n
\n \n \n | \n p_bar | \n t_k | \n
\n \n \n \n 0 | \n 1.100000 | \n 293.15 | \n
\n \n 1 | \n 0.913916 | \n 293.15 | \n
\n \n 2 | \n 0.913916 | \n 293.15 | \n
\n \n
\n
"
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"net.res_junction"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"They're is no pressure loss between junction 2 and junction 3 because of the ideal valve."
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": " v_from_m_per_s v_to_m_per_s v_mean_m_per_s p_from_bar p_to_bar \\\n0 15.766074 17.295535 16.483877 1.1 0.913916 \n\n t_from_k t_to_k mdot_from_kg_per_s mdot_to_kg_per_s vdot_norm_m3_per_s \\\n0 293.15 293.15 0.045 -0.045 0.06044 \n\n reynolds lambda normfactor_from normfactor_to \n0 96710.314701 0.049222 0.512189 0.561877 ",
"text/html": "\n\n
\n \n \n | \n v_from_m_per_s | \n v_to_m_per_s | \n v_mean_m_per_s | \n p_from_bar | \n p_to_bar | \n t_from_k | \n t_to_k | \n mdot_from_kg_per_s | \n mdot_to_kg_per_s | \n vdot_norm_m3_per_s | \n reynolds | \n lambda | \n normfactor_from | \n normfactor_to | \n
\n \n \n \n 0 | \n 15.766074 | \n 17.295535 | \n 16.483877 | \n 1.1 | \n 0.913916 | \n 293.15 | \n 293.15 | \n 0.045 | \n -0.045 | \n 0.06044 | \n 96710.314701 | \n 0.049222 | \n 0.512189 | \n 0.561877 | \n
\n \n
\n
"
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"net.res_pipe"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Closed valve\n",
"\n",
"We now close the valve between junction 2 and junction 3:"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"# Problem can not run pipeflow if valve closed\n",
"net.valve.opened = False"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The closed valve cuts the sink from the external grid:\n",
"\n",
""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This can be verified by running a power flow and inspecting the results. The pressure and temperature at junction 2 is given as NaN:"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"scrolled": true
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"hp.pandapipes.pipeflow_setup - INFO: Setting the following nodes out of service for hydraulics calculation in connectivity check:\n",
"In table junction: [2]\n",
"hp.pandapipes.pipeflow - INFO: niter 0\n",
"hp.pandapipes.pipeflow - INFO: niter 1\n",
"hp.pandapipes.pipeflow - INFO: ---------------------------------------------------------------------------------\n",
"hp.pandapipes.pipeflow - INFO: Calculation completed. Preparing results...\n",
"hp.pandapipes.pipeflow - INFO: Converged after 2 iterations.\n",
"hp.pandapipes.pipeflow - INFO: Norm of residual: 6.635561679383765e-07\n",
"hp.pandapipes.pipeflow - INFO: tol_p: 0.0001\n",
"hp.pandapipes.pipeflow - INFO: tol_v: 0.0001\n"
]
},
{
"data": {
"text/plain": " p_bar t_k\n0 1.1 293.15\n1 1.1 293.15\n2 NaN NaN",
"text/html": "\n\n
\n \n \n | \n p_bar | \n t_k | \n
\n \n \n \n 0 | \n 1.1 | \n 293.15 | \n
\n \n 1 | \n 1.1 | \n 293.15 | \n
\n \n 2 | \n NaN | \n NaN | \n
\n \n
\n
"
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"pp.pipeflow(net)\n",
"net.res_junction"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Also the results from the pipe show that the mass flow is almost zero and the speed of the mass flow is zero. "
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": " v_from_m_per_s v_to_m_per_s v_mean_m_per_s p_from_bar p_to_bar \\\n0 0.0 0.0 0.0 1.1 1.1 \n\n t_from_k t_to_k mdot_from_kg_per_s mdot_to_kg_per_s vdot_norm_m3_per_s \\\n0 293.15 293.15 0.0 -0.0 0.0 \n\n reynolds lambda normfactor_from normfactor_to \n0 0.0 0.04856 0.512189 0.512189 ",
"text/html": "\n\n
\n \n \n | \n v_from_m_per_s | \n v_to_m_per_s | \n v_mean_m_per_s | \n p_from_bar | \n p_to_bar | \n t_from_k | \n t_to_k | \n mdot_from_kg_per_s | \n mdot_to_kg_per_s | \n vdot_norm_m3_per_s | \n reynolds | \n lambda | \n normfactor_from | \n normfactor_to | \n
\n \n \n \n 0 | \n 0.0 | \n 0.0 | \n 0.0 | \n 1.1 | \n 1.1 | \n 293.15 | \n 293.15 | \n 0.0 | \n -0.0 | \n 0.0 | \n 0.0 | \n 0.04856 | \n 0.512189 | \n 0.512189 | \n
\n \n
\n
"
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"net.res_pipe"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.4"
}
},
"nbformat": 4,
"nbformat_minor": 2
}