Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 120 additions & 1 deletion examples/jupyter/examplesInPython.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,125 @@
"fluid1.initPhysicalProperties()\n",
"print(\"thermal conductivity \", fluid1.getPhase(\"oil\").getThermalConductivity('W/mK'))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Create Process from YAML Configuration\n",
"\n",
"The `create_process_from_config()` function allows you to build complete process simulations from YAML files. This is ideal for:\n",
"- Separating process configuration from code\n",
"- Version-controlling process designs\n",
"- Quickly modifying process parameters"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Example: Create a process from a YAML configuration string\n",
"# (In practice, you'd typically load this from a file)\n",
"\n",
"yaml_config = \"\"\"\n",
"name: Gas Compression Example\n",
"\n",
"fluids:\n",
" natural_gas:\n",
" model: srk\n",
" temperature: 303.15\n",
" pressure: 10.0\n",
" components:\n",
" - name: methane\n",
" moles: 0.90\n",
" - name: ethane\n",
" moles: 0.05\n",
" - name: propane\n",
" moles: 0.03\n",
" - name: n-butane\n",
" moles: 0.02\n",
"\n",
"equipment:\n",
" - type: stream\n",
" name: inlet\n",
" fluid: natural_gas\n",
" temperature: 303.15\n",
" pressure: 10.0\n",
" flow_rate: 5.0\n",
" flow_unit: MSm3/day\n",
"\n",
" - type: separator\n",
" name: inlet_sep\n",
" inlet: inlet\n",
"\n",
" - type: compressor\n",
" name: comp1\n",
" inlet: inlet_sep.gas\n",
" pressure: 50.0\n",
"\n",
" - type: cooler\n",
" name: cooler1\n",
" inlet: comp1\n",
" temperature: 303.15\n",
"\n",
" - type: splitter\n",
" name: splitter1\n",
" inlet: cooler1\n",
" split_factors: [0.8, 0.2]\n",
"\"\"\"\n",
"\n",
"# Parse YAML and create process\n",
"import yaml\n",
"from neqsim.process import create_process_from_config\n",
"\n",
"config = yaml.safe_load(yaml_config)\n",
"process = create_process_from_config(config)\n",
"\n",
"# Display results\n",
"print(\"=== Process Results ===\")\n",
"print(f\"Compressor power: {process.get('comp1').getPower()/1e6:.2f} MW\")\n",
"print(f\"Cooler duty: {process.get('cooler1').getDuty()/1e6:.2f} MW\")\n",
"\n",
"# Get results as DataFrame\n",
"df = process.results_dataframe()\n",
"print(\"\\n=== Stream Summary ===\")\n",
"print(df.head(10))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Example: Create fluid from configuration\n",
"from neqsim.process import create_fluid_from_config\n",
"from neqsim.thermo import TPflash, dataFrame\n",
"\n",
"# Create a custom fluid from config\n",
"fluid_config = {\n",
" 'model': 'cpa', # Use CPA for polar components\n",
" 'temperature': 298.15,\n",
" 'pressure': 1.0,\n",
" 'components': [\n",
" {'name': 'methane', 'moles': 0.80},\n",
" {'name': 'CO2', 'moles': 0.10},\n",
" {'name': 'water', 'moles': 0.05},\n",
" {'name': 'MEG', 'moles': 0.05}\n",
" ],\n",
" 'multiphase': True\n",
"}\n",
"\n",
"fluid = create_fluid_from_config(fluid_config)\n",
"fluid.setTemperature(300.0)\n",
"fluid.setPressure(50.0)\n",
"TPflash(fluid)\n",
"\n",
"print(\"=== Fluid Properties ===\")\n",
"print(dataFrame(fluid))"
]
}
],
"metadata": {
Expand All @@ -568,7 +687,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.16"
"version": "3.11.6"
}
},
"nbformat": 4,
Expand Down
Loading