|
550 | 550 | "fluid1.initPhysicalProperties()\n", |
551 | 551 | "print(\"thermal conductivity \", fluid1.getPhase(\"oil\").getThermalConductivity('W/mK'))" |
552 | 552 | ] |
| 553 | + }, |
| 554 | + { |
| 555 | + "cell_type": "markdown", |
| 556 | + "metadata": {}, |
| 557 | + "source": [ |
| 558 | + "## Create Process from YAML Configuration\n", |
| 559 | + "\n", |
| 560 | + "The `create_process_from_config()` function allows you to build complete process simulations from YAML files. This is ideal for:\n", |
| 561 | + "- Separating process configuration from code\n", |
| 562 | + "- Version-controlling process designs\n", |
| 563 | + "- Quickly modifying process parameters" |
| 564 | + ] |
| 565 | + }, |
| 566 | + { |
| 567 | + "cell_type": "code", |
| 568 | + "execution_count": null, |
| 569 | + "metadata": {}, |
| 570 | + "outputs": [], |
| 571 | + "source": [ |
| 572 | + "# Example: Create a process from a YAML configuration string\n", |
| 573 | + "# (In practice, you'd typically load this from a file)\n", |
| 574 | + "\n", |
| 575 | + "yaml_config = \"\"\"\n", |
| 576 | + "name: Gas Compression Example\n", |
| 577 | + "\n", |
| 578 | + "fluids:\n", |
| 579 | + " natural_gas:\n", |
| 580 | + " model: srk\n", |
| 581 | + " temperature: 303.15\n", |
| 582 | + " pressure: 10.0\n", |
| 583 | + " components:\n", |
| 584 | + " - name: methane\n", |
| 585 | + " moles: 0.90\n", |
| 586 | + " - name: ethane\n", |
| 587 | + " moles: 0.05\n", |
| 588 | + " - name: propane\n", |
| 589 | + " moles: 0.03\n", |
| 590 | + " - name: n-butane\n", |
| 591 | + " moles: 0.02\n", |
| 592 | + "\n", |
| 593 | + "equipment:\n", |
| 594 | + " - type: stream\n", |
| 595 | + " name: inlet\n", |
| 596 | + " fluid: natural_gas\n", |
| 597 | + " temperature: 303.15\n", |
| 598 | + " pressure: 10.0\n", |
| 599 | + " flow_rate: 5.0\n", |
| 600 | + " flow_unit: MSm3/day\n", |
| 601 | + "\n", |
| 602 | + " - type: separator\n", |
| 603 | + " name: inlet_sep\n", |
| 604 | + " inlet: inlet\n", |
| 605 | + "\n", |
| 606 | + " - type: compressor\n", |
| 607 | + " name: comp1\n", |
| 608 | + " inlet: inlet_sep.gas\n", |
| 609 | + " pressure: 50.0\n", |
| 610 | + "\n", |
| 611 | + " - type: cooler\n", |
| 612 | + " name: cooler1\n", |
| 613 | + " inlet: comp1\n", |
| 614 | + " temperature: 303.15\n", |
| 615 | + "\n", |
| 616 | + " - type: splitter\n", |
| 617 | + " name: splitter1\n", |
| 618 | + " inlet: cooler1\n", |
| 619 | + " split_factors: [0.8, 0.2]\n", |
| 620 | + "\"\"\"\n", |
| 621 | + "\n", |
| 622 | + "# Parse YAML and create process\n", |
| 623 | + "import yaml\n", |
| 624 | + "from neqsim.process import create_process_from_config\n", |
| 625 | + "\n", |
| 626 | + "config = yaml.safe_load(yaml_config)\n", |
| 627 | + "process = create_process_from_config(config)\n", |
| 628 | + "\n", |
| 629 | + "# Display results\n", |
| 630 | + "print(\"=== Process Results ===\")\n", |
| 631 | + "print(f\"Compressor power: {process.get('comp1').getPower()/1e6:.2f} MW\")\n", |
| 632 | + "print(f\"Cooler duty: {process.get('cooler1').getDuty()/1e6:.2f} MW\")\n", |
| 633 | + "\n", |
| 634 | + "# Get results as DataFrame\n", |
| 635 | + "df = process.results_dataframe()\n", |
| 636 | + "print(\"\\n=== Stream Summary ===\")\n", |
| 637 | + "print(df.head(10))" |
| 638 | + ] |
| 639 | + }, |
| 640 | + { |
| 641 | + "cell_type": "code", |
| 642 | + "execution_count": null, |
| 643 | + "metadata": {}, |
| 644 | + "outputs": [], |
| 645 | + "source": [ |
| 646 | + "# Example: Create fluid from configuration\n", |
| 647 | + "from neqsim.process import create_fluid_from_config\n", |
| 648 | + "from neqsim.thermo import TPflash, dataFrame\n", |
| 649 | + "\n", |
| 650 | + "# Create a custom fluid from config\n", |
| 651 | + "fluid_config = {\n", |
| 652 | + " 'model': 'cpa', # Use CPA for polar components\n", |
| 653 | + " 'temperature': 298.15,\n", |
| 654 | + " 'pressure': 1.0,\n", |
| 655 | + " 'components': [\n", |
| 656 | + " {'name': 'methane', 'moles': 0.80},\n", |
| 657 | + " {'name': 'CO2', 'moles': 0.10},\n", |
| 658 | + " {'name': 'water', 'moles': 0.05},\n", |
| 659 | + " {'name': 'MEG', 'moles': 0.05}\n", |
| 660 | + " ],\n", |
| 661 | + " 'multiphase': True\n", |
| 662 | + "}\n", |
| 663 | + "\n", |
| 664 | + "fluid = create_fluid_from_config(fluid_config)\n", |
| 665 | + "fluid.setTemperature(300.0)\n", |
| 666 | + "fluid.setPressure(50.0)\n", |
| 667 | + "TPflash(fluid)\n", |
| 668 | + "\n", |
| 669 | + "print(\"=== Fluid Properties ===\")\n", |
| 670 | + "print(dataFrame(fluid))" |
| 671 | + ] |
553 | 672 | } |
554 | 673 | ], |
555 | 674 | "metadata": { |
|
568 | 687 | "name": "python", |
569 | 688 | "nbconvert_exporter": "python", |
570 | 689 | "pygments_lexer": "ipython3", |
571 | | - "version": "3.10.16" |
| 690 | + "version": "3.11.6" |
572 | 691 | } |
573 | 692 | }, |
574 | 693 | "nbformat": 4, |
|
0 commit comments