{
"cells": [
{
"cell_type": "markdown",
"id": "c2edd2df-8144-4d8c-8ff5-816b6b5ace01",
"metadata": {},
"source": [
"# Thermal circuit to state-space\n",
"\n",
"This notebook is a go through complete example of obtaining a state-space representation from the bilding described by walls ans thermal circuits. The steps are:\n",
"\n",
"- in a folder, describe the walls (wall type and wall data), the thermal circuits and give the assembling matrix or lists;\n",
"- from walls and thermal circuits obtain the set of disassembled circuits (function `bldg2TCd()`);\n",
"- assemble the set of disassembled thermal circuits (function `assemble_TCd_matrix()`);\n",
"- transform the thermal circuit into state-space representation (function `tc2ss()`)."
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "2e98a935-1ae9-43b3-ae9c-fd0ebd8a8b94",
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import pandas as pd\n",
"import pd_dm4bem"
]
},
{
"cell_type": "markdown",
"id": "ca4b9d26-f049-4fb9-9677-0a38f273a8f4",
"metadata": {},
"source": [
"## Assembling and converting the thermal circuits to state-space\n",
"Consider the disassembled thermal circuits shown in Figure 1 that we want to assemble as shown in Figure 2 and then obtain the state-space representation.\n",
"\n",
"\n",
"> Figure 1. Four disassembled thermal circuits: wall_out, TC0, TC1, TC2, TC3.\n",
"\n",
"\n",
"> Figure 2. The assembling of the four circuits from Figure 1.\n",
"\n",
"The steps to obtain a state-space model from thermal circuits described in a folder are:\n",
"1. Obtain the disassambled set of thermal circuits from data given in a folder."
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "c14c351d-26a7-427f-ada1-3c9c005c98e1",
"metadata": {},
"outputs": [],
"source": [
"# Disassembled thermal circuits\n",
"folder_path = \"bldg\"\n",
"TCd = pd_dm4bem.bldg2TCd(folder_path,\n",
" TC_auto_number=True)\n",
"\n",
"# For non auto-numbering of thermal circuits TC\n",
"# TCd = pd_dm4bem.bldg2TCd(folder_path, TC_auto_number=False)"
]
},
{
"cell_type": "markdown",
"id": "8b44d99a-4e20-4889-a7ab-b7b19b36a8b8",
"metadata": {},
"source": [
"2. Assemble the set of thermal circuits"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "f8aedb97-b69d-4f99-bfbf-3655bf43c1e0",
"metadata": {},
"outputs": [],
"source": [
"# Assembled thermal circuit:\n",
"\n",
"# from 'assembly_matrix.csv'\n",
"ass_mat = pd.read_csv(folder_path + '/assembly_matrix.csv')\n",
"TCm = pd_dm4bem.assemble_TCd_matrix(TCd, ass_mat)\n",
"\n",
"# from 'assembly_lists.csv'\n",
"ass_lists = pd.read_csv(folder_path + '/assembly_lists.csv')\n",
"ass_mat = pd_dm4bem.assemble_lists2matrix(ass_lists)\n",
"TCl = pd_dm4bem.assemble_TCd_matrix(TCd, ass_mat)"
]
},
{
"cell_type": "markdown",
"id": "89b404fe-b3d4-435e-aee0-094353267438",
"metadata": {},
"source": [
"3. Transform the thermal circuit into state-space representation."
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "6852db7e-2d7f-4968-83cd-3f65aae01804",
"metadata": {},
"outputs": [],
"source": [
"# State-space from TC\n",
"[As, Bs, Cs, Ds, us] = pd_dm4bem.tc2ss(TCl)"
]
},
{
"cell_type": "markdown",
"id": "edbdfaa8-f9d8-4b1d-b0bc-a857fd76c210",
"metadata": {},
"source": [
"The [state-space representation](https://en.m.wikipedia.org/wiki/State-space_representation) is characterized by the matrices __A__ (state), __B__ (input), __C__ (ouput) and __D__ (feedthrough) and by the input vector __u__. Note the use of 's' (from state-space) in the names of As, Bs, Cs, Ds us in order to avoid confusion with the notation for differential-algebraic equations (A, G, C, b, f)."
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "cfafee92-73c6-49d7-ad30-795bdc3bfd17",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" c1_θ0 | \n",
" c2_θ0 | \n",
" ow0_θ1 | \n",
" ow0_θ3 | \n",
"
\n",
" \n",
" \n",
" \n",
" | c1_θ0 | \n",
" -0.000240 | \n",
" 0.000085 | \n",
" 0.000000 | \n",
" 0.000002 | \n",
"
\n",
" \n",
" | c2_θ0 | \n",
" 0.002857 | \n",
" -0.003925 | \n",
" 0.000000 | \n",
" 0.000790 | \n",
"
\n",
" \n",
" | ow0_θ1 | \n",
" 0.000000 | \n",
" 0.000000 | \n",
" -0.000024 | \n",
" 0.000002 | \n",
"
\n",
" \n",
" | ow0_θ3 | \n",
" 0.000011 | \n",
" 0.000107 | \n",
" 0.000121 | \n",
" -0.000239 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" c1_θ0 c2_θ0 ow0_θ1 ow0_θ3\n",
"c1_θ0 -0.000240 0.000085 0.000000 0.000002\n",
"c2_θ0 0.002857 -0.003925 0.000000 0.000790\n",
"ow0_θ1 0.000000 0.000000 -0.000024 0.000002\n",
"ow0_θ3 0.000011 0.000107 0.000121 -0.000239"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"As"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "d9bda09a-62df-4344-a508-571068f239ea",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" c1_q0 | \n",
" c2_q0 | \n",
" c3_q0 | \n",
" ow0_q0 | \n",
" c1_θ0 | \n",
" c2_θ0 | \n",
" ow0_θ0 | \n",
" ow0_θ4 | \n",
"
\n",
" \n",
" \n",
" \n",
" | c1_θ0 | \n",
" 0.000152 | \n",
" 0.000000 | \n",
" 0.0 | \n",
" 0.000000 | \n",
" 9.182736e-07 | \n",
" 0.000000 | \n",
" 0.000000e+00 | \n",
" 8.022399e-08 | \n",
"
\n",
" \n",
" | c2_θ0 | \n",
" 0.000000 | \n",
" 0.000278 | \n",
" 0.0 | \n",
" 0.000000 | \n",
" 0.000000e+00 | \n",
" 0.000031 | \n",
" 0.000000e+00 | \n",
" 2.600003e-05 | \n",
"
\n",
" \n",
" | ow0_θ1 | \n",
" 0.000000 | \n",
" 0.000000 | \n",
" 0.0 | \n",
" 0.000022 | \n",
" 0.000000e+00 | \n",
" 0.000000 | \n",
" 1.970654e-08 | \n",
" 0.000000e+00 | \n",
"
\n",
" \n",
" | ow0_θ3 | \n",
" 0.000000 | \n",
" 0.000000 | \n",
" 0.0 | \n",
" 0.000000 | \n",
" 0.000000e+00 | \n",
" 0.000000 | \n",
" 0.000000e+00 | \n",
" 2.931595e-07 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" c1_q0 c2_q0 c3_q0 ow0_q0 c1_θ0 c2_θ0 \\\n",
"c1_θ0 0.000152 0.000000 0.0 0.000000 9.182736e-07 0.000000 \n",
"c2_θ0 0.000000 0.000278 0.0 0.000000 0.000000e+00 0.000031 \n",
"ow0_θ1 0.000000 0.000000 0.0 0.000022 0.000000e+00 0.000000 \n",
"ow0_θ3 0.000000 0.000000 0.0 0.000000 0.000000e+00 0.000000 \n",
"\n",
" ow0_θ0 ow0_θ4 \n",
"c1_θ0 0.000000e+00 8.022399e-08 \n",
"c2_θ0 0.000000e+00 2.600003e-05 \n",
"ow0_θ1 1.970654e-08 0.000000e+00 \n",
"ow0_θ3 0.000000e+00 2.931595e-07 "
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Bs"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "7341354f-44d3-4b95-af47-71965e829d08",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" c1_θ0 | \n",
" c2_θ0 | \n",
" ow0_θ1 | \n",
" ow0_θ3 | \n",
"
\n",
" \n",
" \n",
" \n",
" | c2_θ0 | \n",
" 0.0 | \n",
" 1.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" c1_θ0 c2_θ0 ow0_θ1 ow0_θ3\n",
"c2_θ0 0.0 1.0 0.0 0.0"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Cs"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "3c26b78b-0799-470b-bfb2-8024aea59a78",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" c1_q0 | \n",
" c2_q0 | \n",
" c3_q0 | \n",
" ow0_q0 | \n",
" c1_θ0 | \n",
" c2_θ0 | \n",
" ow0_θ0 | \n",
" ow0_θ4 | \n",
"
\n",
" \n",
" \n",
" \n",
" | c2_θ0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" c1_q0 c2_q0 c3_q0 ow0_q0 c1_θ0 c2_θ0 ow0_θ0 ow0_θ4\n",
"c2_θ0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Ds"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "372c6332-5526-488e-81e6-fa3450d829cd",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" u | \n",
"
\n",
" \n",
" \n",
" \n",
" | c1_q0 | \n",
" To | \n",
"
\n",
" \n",
" | c2_q0 | \n",
" To | \n",
"
\n",
" \n",
" | c3_q0 | \n",
" Ti_sp | \n",
"
\n",
" \n",
" | ow0_q0 | \n",
" To | \n",
"
\n",
" \n",
" | c1_θ0 | \n",
" Φa | \n",
"
\n",
" \n",
" | c2_θ0 | \n",
" Qa | \n",
"
\n",
" \n",
" | ow0_θ0 | \n",
" Φo | \n",
"
\n",
" \n",
" | ow0_θ4 | \n",
" Φi | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" u\n",
"c1_q0 To\n",
"c2_q0 To\n",
"c3_q0 Ti_sp\n",
"ow0_q0 To\n",
"c1_θ0 Φa\n",
"c2_θ0 Qa\n",
"ow0_θ0 Φo\n",
"ow0_θ4 Φi"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"pd.DataFrame({'u': us})"
]
},
{
"cell_type": "markdown",
"id": "b432e1de-b9a7-49c7-8292-2a28421e0547",
"metadata": {},
"source": [
"The state-space representation allows us to do the eigenvalues analysis and to find the maximum time step."
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "945f3c38-b2ad-4a1a-bbbc-27b68eec2550",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Time constants:\n",
"['249.30 s', '4093.21 s', '6729.13 s', '44033.06 s']\n",
"\n",
"2 x Time constants:\n",
"['498.60 s', '8186.41 s', '13458.25 s', '88066.12 s']\n",
"\n",
"Maximum time step: 498.60 s = 8.31 min\n"
]
}
],
"source": [
"λ = np.linalg.eig(As)[0] # eigenvalues of matrix As\n",
"λ = np.sort(λ)\n",
"\n",
"print('Time constants:') \n",
"print([f'{T:.2f} s' for T in -1 / λ])\n",
"\n",
"print('\\n2 x Time constants:') \n",
"print([f'{T:.2f} s' for T in -2 / λ])\n",
"\n",
"dtmax = 2 * min(-1. / λ)\n",
"print(f'\\nMaximum time step: {dtmax:.2f} s = {dtmax / 60:.2f} min')"
]
},
{
"cell_type": "markdown",
"id": "8b8687e7-41a5-4b22-950e-e9b643cfee22",
"metadata": {
"tags": []
},
"source": [
"## Comparing the results\n",
"\n",
"The model used in this notebook is similar to that used in `03CubicBuilding.ipynb`. The notations in the two models are different (see Figure 2 and Figure 3).\n",
"\n",
"\n",
"> Figure 3. Thermal circuit for the cubic building used in `03CubicBuilding.ipynb`\n",
"\n",
"The correspondences between the notations in the two models (i.e., this notebook and `03CubicBuilding.ipynb`) is shown in Tables 1, 2, and 3.\n",
"\n",
"> Table 1. Correspondence between states (i.e., temperature nodes with capacities) in Figures 2 and 3.\n",
"\n",
"|Fig. 2|ow0_θ1|ow0_θ3|c2_θ0|c1_θ0|\n",
"|------|------|------|-----|-----|\n",
"|Fig. 3| θ1 | θ3 | θ6 | θ7 | \n",
"\n",
"> Table 2. Correspondence between temperature sources in Figures 2 and 3.\n",
"\n",
"|Fig. 2|ow0_q0|c1_q0|c2_q0|c3_q0|\n",
"|------|------|-----|-----|-----|\n",
"|Fig. 3|q0 |q8 |q10 |q11 |\n",
"\n",
"\n",
"> Table 3. Correspondence between flow sources in Figures 2 and 3.\n",
"\n",
"|Fig. 2|ow0_θ0|ow0_θ4|c2_θ0|c1_θ0|\n",
"|------|------|------|-----|-----|\n",
"|Fig. 3|θ0 |θ4 |θ6 |θ7 |\n"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "66d3bf52-ed99-4410-8709-e04915e10f9c",
"metadata": {},
"outputs": [],
"source": [
"θ_order = ['ow0_θ1', 'ow0_θ3', 'c2_θ0', 'c1_θ0']\n",
"uT_order = ['ow0_q0', 'c1_q0', 'c2_q0', 'c3_q0']\n",
"uQ_order = ['ow0_θ0', 'ow0_θ4', 'c2_θ0', 'c1_θ0']\n",
"u_order = uT_order + uQ_order\n",
"y_order = ['c2_θ0'] "
]
},
{
"cell_type": "markdown",
"id": "db3c9f78-990e-455d-9dcb-0b26ab1e9501",
"metadata": {},
"source": [
"By reindexing the matrices of the state-space model, it becomes easier to compare the results from this notebook and `03CubicBuilding.ipynb`."
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "c144c7f9-d8ff-4cb4-ab88-31f968c9b85b",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" ow0_θ1 | \n",
" ow0_θ3 | \n",
" c2_θ0 | \n",
" c1_θ0 | \n",
"
\n",
" \n",
" \n",
" \n",
" | ow0_θ1 | \n",
" -0.000024 | \n",
" 0.000002 | \n",
" 0.000000 | \n",
" 0.000000 | \n",
"
\n",
" \n",
" | ow0_θ3 | \n",
" 0.000121 | \n",
" -0.000239 | \n",
" 0.000107 | \n",
" 0.000011 | \n",
"
\n",
" \n",
" | c2_θ0 | \n",
" 0.000000 | \n",
" 0.000790 | \n",
" -0.003925 | \n",
" 0.002857 | \n",
"
\n",
" \n",
" | c1_θ0 | \n",
" 0.000000 | \n",
" 0.000002 | \n",
" 0.000085 | \n",
" -0.000240 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" ow0_θ1 ow0_θ3 c2_θ0 c1_θ0\n",
"ow0_θ1 -0.000024 0.000002 0.000000 0.000000\n",
"ow0_θ3 0.000121 -0.000239 0.000107 0.000011\n",
"c2_θ0 0.000000 0.000790 -0.003925 0.002857\n",
"c1_θ0 0.000000 0.000002 0.000085 -0.000240"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"As.reindex(index=θ_order, columns=θ_order)"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "b46bebd4-adb6-47c0-be44-92594993dfaf",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" ow0_q0 | \n",
" c1_q0 | \n",
" c2_q0 | \n",
" c3_q0 | \n",
" ow0_θ0 | \n",
" ow0_θ4 | \n",
" c2_θ0 | \n",
" c1_θ0 | \n",
"
\n",
" \n",
" \n",
" \n",
" | ow0_θ1 | \n",
" 0.000022 | \n",
" 0.000000 | \n",
" 0.000000 | \n",
" 0.0 | \n",
" 1.970654e-08 | \n",
" 0.000000e+00 | \n",
" 0.000000 | \n",
" 0.000000e+00 | \n",
"
\n",
" \n",
" | ow0_θ3 | \n",
" 0.000000 | \n",
" 0.000000 | \n",
" 0.000000 | \n",
" 0.0 | \n",
" 0.000000e+00 | \n",
" 2.931595e-07 | \n",
" 0.000000 | \n",
" 0.000000e+00 | \n",
"
\n",
" \n",
" | c2_θ0 | \n",
" 0.000000 | \n",
" 0.000000 | \n",
" 0.000278 | \n",
" 0.0 | \n",
" 0.000000e+00 | \n",
" 2.600003e-05 | \n",
" 0.000031 | \n",
" 0.000000e+00 | \n",
"
\n",
" \n",
" | c1_θ0 | \n",
" 0.000000 | \n",
" 0.000152 | \n",
" 0.000000 | \n",
" 0.0 | \n",
" 0.000000e+00 | \n",
" 8.022399e-08 | \n",
" 0.000000 | \n",
" 9.182736e-07 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" ow0_q0 c1_q0 c2_q0 c3_q0 ow0_θ0 ow0_θ4 \\\n",
"ow0_θ1 0.000022 0.000000 0.000000 0.0 1.970654e-08 0.000000e+00 \n",
"ow0_θ3 0.000000 0.000000 0.000000 0.0 0.000000e+00 2.931595e-07 \n",
"c2_θ0 0.000000 0.000000 0.000278 0.0 0.000000e+00 2.600003e-05 \n",
"c1_θ0 0.000000 0.000152 0.000000 0.0 0.000000e+00 8.022399e-08 \n",
"\n",
" c2_θ0 c1_θ0 \n",
"ow0_θ1 0.000000 0.000000e+00 \n",
"ow0_θ3 0.000000 0.000000e+00 \n",
"c2_θ0 0.000031 0.000000e+00 \n",
"c1_θ0 0.000000 9.182736e-07 "
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Bs.reindex(index=θ_order, columns=u_order)"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "6824c922-6800-49bc-837e-f238beee7c9e",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" ow0_θ1 | \n",
" ow0_θ3 | \n",
" c2_θ0 | \n",
" c1_θ0 | \n",
"
\n",
" \n",
" \n",
" \n",
" | c2_θ0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 1.0 | \n",
" 0.0 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" ow0_θ1 ow0_θ3 c2_θ0 c1_θ0\n",
"c2_θ0 0.0 0.0 1.0 0.0"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Cs.reindex(index=y_order, columns=θ_order)"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "b02d331a-65f7-4678-acc9-ae0537adfc72",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" ow0_q0 | \n",
" c1_q0 | \n",
" c2_q0 | \n",
" c3_q0 | \n",
" ow0_θ0 | \n",
" ow0_θ4 | \n",
" c2_θ0 | \n",
" c1_θ0 | \n",
"
\n",
" \n",
" \n",
" \n",
" | c2_θ0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
" 0.0 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" ow0_q0 c1_q0 c2_q0 c3_q0 ow0_θ0 ow0_θ4 c2_θ0 c1_θ0\n",
"c2_θ0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Ds.reindex(index=y_order, columns=u_order)"
]
},
{
"cell_type": "markdown",
"id": "3d311895-ab92-497a-b1dc-db71d2d7a5f6",
"metadata": {},
"source": [
"## Types of notation\n",
"\n",
"The notation used for the nodes and flow can be symbols or numbers (in the case of autonumbering).\n",
"\n",
"The data used in the next examples is extracted from the paper:\n",
"> [Ghiaus, C. (2013)](https://hal.science/hal-03605823/document). Causality issue in the heat balance method for calculating the design heating and cooling load. Energy, 50, 292-301."
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "a5664eb3-207f-4c1c-bca8-a9f2f7ccd80f",
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"import pd_dm4bem"
]
},
{
"cell_type": "markdown",
"id": "68dbd826-c50c-48d8-98d6-ddcbfbf459e9",
"metadata": {
"tags": []
},
"source": [
"### Thermal circuit file to state-space\n",
"\n",
"#### File describing the thermal circuit with symbols\n",
"\n",
"Let's consider a thermal circuit that uses symbols for numbering the temperature nodes and the oriented flow branches (Figure 1). \n",
"\n",
"\n",
"> Figure 1. Thermal circuit with symbols.\n",
"\n",
"The thermal circuit from Figure 1 is defined in the file `./TC_tc2ss/TC_tc2ss_sym.csv`. In this case, symbols are used for the nodes and the branches."
]
},
{
"cell_type": "code",
"execution_count": 17,
"id": "b51a704f-7177-4c5d-834d-cce04594c60c",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" A | \n",
" θso | \n",
" θw | \n",
" θsi | \n",
" θa | \n",
" G | \n",
" b | \n",
"
\n",
" \n",
" \n",
" \n",
" | 0 | \n",
" qw0 | \n",
" -1 | \n",
" 1.0 | \n",
" NaN | \n",
" NaN | \n",
" 2.9 | \n",
" NaN | \n",
"
\n",
" \n",
" | 1 | \n",
" qw1 | \n",
" NaN | \n",
" -1.0 | \n",
" 1 | \n",
" NaN | \n",
" 2.9 | \n",
" NaN | \n",
"
\n",
" \n",
" | 2 | \n",
" qv | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" 1 | \n",
" 38.3 | \n",
" Tov | \n",
"
\n",
" \n",
" | 3 | \n",
" qco | \n",
" 1 | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" 250.0 | \n",
" Tow | \n",
"
\n",
" \n",
" | 4 | \n",
" qci | \n",
" NaN | \n",
" NaN | \n",
" -1 | \n",
" 1 | \n",
" 125.0 | \n",
" NaN | \n",
"
\n",
" \n",
" | 5 | \n",
" C | \n",
" NaN | \n",
" 4000000.0 | \n",
" NaN | \n",
" 8.2E+04 | \n",
" NaN | \n",
" NaN | \n",
"
\n",
" \n",
" | 6 | \n",
" f | \n",
" Qo | \n",
" NaN | \n",
" Qi | \n",
" Qg | \n",
" NaN | \n",
" NaN | \n",
"
\n",
" \n",
" | 7 | \n",
" y | \n",
" NaN | \n",
" NaN | \n",
" 1 | \n",
" 1 | \n",
" NaN | \n",
" NaN | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" A θso θw θsi θa G b\n",
"0 qw0 -1 1.0 NaN NaN 2.9 NaN\n",
"1 qw1 NaN -1.0 1 NaN 2.9 NaN\n",
"2 qv NaN NaN NaN 1 38.3 Tov\n",
"3 qco 1 NaN NaN NaN 250.0 Tow\n",
"4 qci NaN NaN -1 1 125.0 NaN\n",
"5 C NaN 4000000.0 NaN 8.2E+04 NaN NaN\n",
"6 f Qo NaN Qi Qg NaN NaN\n",
"7 y NaN NaN 1 1 NaN NaN"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"pd.read_csv('./TC_tc2ss/TC_tc2ss_sym.csv')"
]
},
{
"cell_type": "markdown",
"id": "5a68800e-83c7-4daa-aacc-d48231f7bffa",
"metadata": {
"tags": []
},
"source": [
"#### Auto-numbering\n",
"\n",
"The nodes and the oriented branches can be auto-numbered. The names of the nodes and branches are composed by the name of the circuit and θ0, θ1, ... , for nodes and q0, q1, ... for branches, e.g., a_θ1 stands for temperature node θ1 of circuit a."
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "5849fd64-0a51-40f2-ab62-d4d0a7d167db",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" a_θ1 | \n",
" a_θ3 | \n",
"
\n",
" \n",
" \n",
" \n",
" | a_θ1 | \n",
" -0.000001 | \n",
" 7.085614e-07 | \n",
"
\n",
" \n",
" | a_θ3 | \n",
" 0.000035 | \n",
" -5.016371e-04 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" a_θ1 a_θ3\n",
"a_θ1 -0.000001 7.085614e-07\n",
"a_θ3 0.000035 -5.016371e-04"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"TC_file = \"TC_tc2ss/TC_tc2ss_sym.csv\"\n",
"TC = pd_dm4bem.file2TC(TC_file, name=\"a\",\n",
" auto_number=True)\n",
"[Asa, Bsa, Csa, Dsa, ua] = pd_dm4bem.tc2ss(TC)\n",
"Asa"
]
},
{
"cell_type": "markdown",
"id": "80ace660-f1ee-400a-9c34-42b2cba5e841",
"metadata": {},
"source": [
"#### Symbols\n",
"Alternatively, the nodes and the branches can keep the names given in the `TC` file (the default value of `auto_number`is `False`)."
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "d76a6a32-4ba7-4ad7-afc0-2128e02fada4",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" s_θw | \n",
" s_θa | \n",
"
\n",
" \n",
" \n",
" \n",
" | s_θw | \n",
" -0.000001 | \n",
" 7.085614e-07 | \n",
"
\n",
" \n",
" | s_θa | \n",
" 0.000035 | \n",
" -5.016371e-04 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" s_θw s_θa\n",
"s_θw -0.000001 7.085614e-07\n",
"s_θa 0.000035 -5.016371e-04"
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"TC_file = \"TC_tc2ss/TC_tc2ss_sym.csv\"\n",
"TC = pd_dm4bem.file2TC(TC_file, name=\"s\")\n",
"[Ass, Bss, Css, Dss, us] = pd_dm4bem.tc2ss(TC)\n",
"Ass"
]
},
{
"cell_type": "markdown",
"id": "444ab174-467e-4b0d-9cec-51ecd1dbdae8",
"metadata": {},
"source": [
"Note that the order of symbols corespond to the order given in the description file `./TC_tc2ss/TC_tc2ss_num.csv`not to the alphabetical order."
]
},
{
"cell_type": "markdown",
"id": "81cde545-813a-4f7c-af24-1b5d101c4d10",
"metadata": {
"tags": []
},
"source": [
"### File describing the thermal circuit with numbers\n",
"\n",
"Instead of using symbols, the thermal circuit can be numbered (Figure 2).\n",
"\n",
"\n",
"> Figure 2. Numbered thermal circuit\n",
"\n",
"The thermal circuit from Figure 1 is defined in the file `./TC_tc2ss/TC_tc2ss_num.csv`. In this case, the nodes and the branches are numbered. "
]
},
{
"cell_type": "code",
"execution_count": 20,
"id": "c3934823-30b8-4fc8-bf3a-83dd0f09cbcb",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" A | \n",
" θ0 | \n",
" θ1 | \n",
" θ2 | \n",
" θ3 | \n",
" G | \n",
" b | \n",
"
\n",
" \n",
" \n",
" \n",
" | 0 | \n",
" q0 | \n",
" NaN | \n",
" NaN | \n",
" 1 | \n",
" NaN | \n",
" 38.3 | \n",
" Tov | \n",
"
\n",
" \n",
" | 1 | \n",
" q1 | \n",
" 1 | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
" 250.0 | \n",
" Tow | \n",
"
\n",
" \n",
" | 2 | \n",
" q2 | \n",
" -1 | \n",
" NaN | \n",
" NaN | \n",
" 1.0 | \n",
" 2.9 | \n",
" NaN | \n",
"
\n",
" \n",
" | 3 | \n",
" q3 | \n",
" NaN | \n",
" 1 | \n",
" NaN | \n",
" -1.0 | \n",
" 2.9 | \n",
" NaN | \n",
"
\n",
" \n",
" | 4 | \n",
" q4 | \n",
" NaN | \n",
" -1 | \n",
" 1 | \n",
" NaN | \n",
" 125.0 | \n",
" NaN | \n",
"
\n",
" \n",
" | 5 | \n",
" C | \n",
" NaN | \n",
" NaN | \n",
" 8.2E+04 | \n",
" 4000000.0 | \n",
" NaN | \n",
" NaN | \n",
"
\n",
" \n",
" | 6 | \n",
" f | \n",
" Qo | \n",
" Qi | \n",
" Qg | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
"
\n",
" \n",
" | 7 | \n",
" y | \n",
" NaN | \n",
" 1 | \n",
" 1 | \n",
" NaN | \n",
" NaN | \n",
" NaN | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" A θ0 θ1 θ2 θ3 G b\n",
"0 q0 NaN NaN 1 NaN 38.3 Tov\n",
"1 q1 1 NaN NaN NaN 250.0 Tow\n",
"2 q2 -1 NaN NaN 1.0 2.9 NaN\n",
"3 q3 NaN 1 NaN -1.0 2.9 NaN\n",
"4 q4 NaN -1 1 NaN 125.0 NaN\n",
"5 C NaN NaN 8.2E+04 4000000.0 NaN NaN\n",
"6 f Qo Qi Qg NaN NaN NaN\n",
"7 y NaN 1 1 NaN NaN NaN"
]
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"pd.read_csv('./TC_tc2ss/TC_tc2ss_num.csv')"
]
},
{
"cell_type": "code",
"execution_count": 21,
"id": "3007e13b-20d4-4e8e-a1a7-db2e38ff13f8",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" n_θ2 | \n",
" n_θ3 | \n",
"
\n",
" \n",
" \n",
" \n",
" | n_θ2 | \n",
" -5.016371e-04 | \n",
" 0.000035 | \n",
"
\n",
" \n",
" | n_θ3 | \n",
" 7.085614e-07 | \n",
" -0.000001 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" n_θ2 n_θ3\n",
"n_θ2 -5.016371e-04 0.000035\n",
"n_θ3 7.085614e-07 -0.000001"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"TC_file = \"TC_tc2ss/TC_tc2ss_num.csv\"\n",
"TC = pd_dm4bem.file2TC(TC_file, name=\"n\")\n",
"[Asn, Bsn, Csn, Dsn, un] = pd_dm4bem.tc2ss(TC)\n",
"Asn"
]
},
{
"cell_type": "markdown",
"id": "fe0e0e7b-df22-47eb-8919-81339c20fe99",
"metadata": {},
"source": [
"Note that the values of the state-space representations are the same but the order is different. The order is given by the `.cvs` files that define the thermal circuit."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2a8a60b9-259c-40cb-9399-e6a149e26b70",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.9.7"
},
"toc-autonumbering": true
},
"nbformat": 4,
"nbformat_minor": 5
}