{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Creating a Unit"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"All unit operations are created by passing a name and both inlet and outlet streams. The parent [Unit](../API/Unit.txt) class does nothing when simulated, but is used here as a general example that applies to all Unit child classes (e.g. heat exchangers, mixers) which do implement modeling algorithms. "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Key parameters"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Initialize a Unit object with an `ID`, `ins` streams, and `outs` streams. Either an iterable of Stream objects, or a Stream object may work for `ins` and `outs`:"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Unit: U1\n",
"ins...\n",
"[0] in0 \n",
"outs...\n",
"[0] out0 \n"
]
}
],
"source": [
"from biosteam import Unit, Stream, settings, main_flowsheet\n",
"import biosteam as bst\n",
"bst.nbtutorial() # Light-mode html diagrams and filter warnings\n",
"settings.set_thermo(['Water'])\n",
"ins = Stream('in0')\n",
"outs = [Stream('out0')]\n",
"U1 = Unit(ID='U1', ins=ins, outs=outs)\n",
"U1.show(data=False) # Passing data as False returns only stream names"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You can also view a diagram to check connections:"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"tags": [
"nbval-ignore-output"
]
},
"outputs": [
{
"data": {
"text/html": [
"\n",
" \n",
" "
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"U1.diagram()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"IDs for Stream objects can also be used instead:"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Unit: U2\n",
"ins...\n",
"[0] s1 \n",
"outs...\n",
"[0] s2 \n"
]
}
],
"source": [
"U2 = Unit('U2', ins='', outs=['']) # Empty strings default unused IDs\n",
"U2.show(data=False)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Parameter defaults"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"By default, a unique `ID` is chosen, missing streams are given to `ins`, and empty streams to `outs`:"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Unit: U3\n",
"ins...\n",
"[0] missing stream \n",
"outs...\n",
"[0] s3 \n"
]
}
],
"source": [
"unit = Unit()\n",
"unit.show(data=False)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"For either `ins` or `outs`, if None is given, missing streams are initialized. If an empty iterable is given, empty streams are initialized:"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Unit: U4\n",
"ins...\n",
"[0] missing stream \n",
"outs...\n",
"[0] missing stream \n"
]
}
],
"source": [
"U4 = Unit('U4', ins=None, outs=None)\n",
"U4.show(data=False)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Unit: U5\n",
"ins...\n",
"[0] s4 \n",
"outs...\n",
"[0] s5 \n"
]
}
],
"source": [
"U5 = Unit('U5', ins=(), outs=())\n",
"U5.show(data=False)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The number of default streams is different for each Unit subclass: "
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Mixer: M1\n",
"ins...\n",
"[0] missing stream \n",
"[1] missing stream \n",
"outs...\n",
"[0] s6 \n"
]
}
],
"source": [
"from biosteam import Mixer, Splitter\n",
"Mixer().show(data=False)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Splitter: S1\n",
"ins...\n",
"[0] missing stream \n",
"outs...\n",
"[0] s7 \n",
"[1] s8 \n"
]
}
],
"source": [
"Splitter(split=0.5).show(data=False)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Notice how the starting letter for default IDs vary between unit operations. This is because default names follow the \"area naming convention\" as explained in the following section."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Area naming convention"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Default IDs for unit operations follow the area naming convention based on {letter}{area + number} where the letter depends on the unit operation as follows:\n",
"\n",
"* C: Centrifuge\n",
"* D: Distillation column\n",
"* E: Evaporator\n",
"* F: Flash tank\n",
"* H: Heat exchange\n",
"* M: Mixer\n",
"* P: Pump (including conveying belt)\n",
"* R: Reactor\n",
"* S: Splitter (including solid/liquid separator)\n",
"* T: Tank or bin for storage\n",
"* U: Other units\n",
"* J: Junction, not a physical unit (serves to adjust streams)\n",
"* PS: Process specificiation, not a physical unit (serves to adjust streams)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Continue creating unit operations following the area naming convention: "
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Mixer: M2\n",
"ins...\n",
"[0] missing stream \n",
"[1] missing stream \n",
"outs...\n",
"[0] s9 \n"
]
}
],
"source": [
"Mixer().show(data=False)"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Splitter: S2\n",
"ins...\n",
"[0] missing stream \n",
"outs...\n",
"[0] s10 \n",
"[1] s11 \n"
]
}
],
"source": [
"Splitter(split=0.5).show(data=False)"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Splitter: S3\n",
"ins...\n",
"[0] missing stream \n",
"outs...\n",
"[0] s12 \n",
"[1] s13 \n"
]
}
],
"source": [
"Splitter(split=0.5).show(data=False)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Notice how there were no name conflicts for default IDs. "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Create a mixer following the area naming convention, this time starting from nunber 101: "
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Mixer: M101\n",
"ins...\n",
"[0] missing stream \n",
"[1] missing stream \n",
"outs...\n",
"[0] s14 \n"
]
}
],
"source": [
"Mixer(100).show(data=False)"
]
}
],
"metadata": {
"celltoolbar": "Tags",
"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.11.4"
}
},
"nbformat": 4,
"nbformat_minor": 2
}