{ "cells": [ { "cell_type": "markdown", "id": "909e3593", "metadata": {}, "source": [ "# Compressor Model Example\n", "\n", "This example demonstrates how to use the compressor component directly from the library. The compressor is modeled assuming a constant isentropic efficiency.\n", "\n", "## 1. Check the Inputs and Parameters\n", "\n", "To identify the required inputs and parameters, use the print_setup method. This will display the names of the component’s connectors, as well as the inputs and parameters needed to define the model.\n" ] }, { "cell_type": "code", "execution_count": null, "id": "6b525538", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "=== Component Setup ===\n", "\n", "Inputs:\n", " - P_su: Not set\n", " - T_su: Not set\n", " - P_ex: Not set\n", " - fluid: Not set\n", "\n", "Parameters:\n", " - eta_is: Not set\n", "======================\n" ] } ], "source": [ "# Import the compressor model with constant isentropic efficiency\n", "from labothappy.component.compressor.compressor_csteff import CompressorCstEff\n", "\n", "# Create an instance of the compressor\n", "compressor = CompressorCstEff()\n", "\n", "# Display the component’s setup: inputs, outputs, connectors, and parameters\n", "compressor.print_setup()" ] }, { "cell_type": "markdown", "id": "090a21ee", "metadata": {}, "source": [ "## 2. Fill in the Required Inputs and Parameters\n", "\n", "### Option 1: Fill Through the Connectors\n", "\n", "In this option, you will provide the necessary inputs through the connectors. As indicated by the `print_setup` method, the required inputs are:\n", "\n", "- **Supply Pressure (P_su)**\n", "- **Exhaust Pressure (P_ex)**\n", "- **Supply Temperature (T_su)**\n", "- **Fluid**\n", "\n", "These inputs are assigned through the following connectors:\n", "\n", "- **MassConnector 'su'**: Set the supply temperature (`T`), supply pressure (`P`), and fluid.\n", "- **MassConnector 'ex'**: Set the supply pressure (`P`).\n", "\n", "After filling in the inputs, you can call the `print_setup` method again to verify that all connectors, inputs, and parameters have been correctly assigned.\n" ] }, { "cell_type": "code", "execution_count": 15, "id": "fb90c041", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "=== Component Setup ===\n", "\n", "Inputs:\n", " - P_su: 319296.5575177148\n", " - T_su: 331.033964665788\n", " - P_ex: 606240.1433176235\n", " - fluid: R1233ZDE\n", "\n", "Parameters:\n", " - eta_is: Not set\n", "======================\n" ] } ], "source": [ "\"Set inputs of the model through the connectors\"\n", "compressor.su.set_fluid('R1233ZDE')\n", "\n", "# Set properties for su connector\n", "compressor.su.set_p(319296.5575177148)\n", "compressor.su.set_T(331.033964665788) # You need to set su.h appropriately\n", "\n", "# Set properties for ex connector\n", "compressor.ex.set_p(606240.1433176235)\n", "\n", "compressor.print_setup()" ] }, { "cell_type": "markdown", "id": "4ec285cd", "metadata": {}, "source": [ "### Option 2: Fill Through the Inputs\n", "\n", "In this option, you will provide the necessary inputs through directly through the dictionarry containing all of the inputs with the method 'set_inputs'." ] }, { "cell_type": "code", "execution_count": 16, "id": "2c32297b", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "=== Component Setup ===\n", "\n", "Inputs:\n", " - P_su: 319296.5575177148\n", " - T_su: 331.033964665788\n", " - P_ex: 606240.1433176235\n", " - fluid: R1233ZDE\n", "\n", "Parameters:\n", " - eta_is: Not set\n", "======================\n" ] } ], "source": [ "\"Set inputs of the model directly\"\n", "# Setting inputs\n", "compressor.set_inputs(\n", " P_su=319296.5575177148,\n", " T_su=331.033964665788,\n", " P_ex=606240.1433176235,\n", " fluid='R1233ZDE' # Make sure to include fluid information\n", ")\n", "compressor.print_setup()" ] }, { "cell_type": "markdown", "id": "7cd5fd89", "metadata": {}, "source": [ "### Set Parameters\n", "\n", "The parameters of the model are set through the method 'set_parameters'." ] }, { "cell_type": "code", "execution_count": 17, "id": "382c1c4f", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "=== Component Setup ===\n", "\n", "Inputs:\n", " - P_su: 319296.5575177148\n", " - T_su: 331.033964665788\n", " - P_ex: 606240.1433176235\n", " - fluid: R1233ZDE\n", "\n", "Parameters:\n", " - eta_is: 0.8\n", "======================\n" ] } ], "source": [ "# Setting parameters\n", "compressor.set_parameters(\n", " eta_is = 0.8\n", ")\n", "compressor.print_setup()" ] }, { "cell_type": "markdown", "id": "72bd490c", "metadata": {}, "source": [ "## 3. Solve the Model\n", "\n", "Once you have set all the necessary inputs and parameters, you can solve the model by calling the `solve` method. After solving, you can view the results by using the `print_results` method.\n", "\n", "By using these methods, you can easily solve the model and analyze the results.\n" ] }, { "cell_type": "code", "execution_count": 18, "id": "6dcbbed3", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "=== Compressor Results ===\n", "Connectors:\n", " - su: fluid=R1233ZDE, T=331.033964665788, p=319296.5575177148, h=476278.3066771153\n", " - ex: fluid=R1233ZDE, T=354.2932947565178, p=606240.1433176235, h=491635.7887210136\n", "\n", "Results:\n", " - h_ex: 491635.7887210136\n", " - T_ex: 354.2932947565178\n", "=========================\n" ] } ], "source": [ "# Solve the compressor model\n", "compressor.solve()\n", "compressor.print_results()\n" ] } ], "metadata": { "kernelspec": { "display_name": "myenv", "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.12.7" } }, "nbformat": 4, "nbformat_minor": 5 }