|
1 | | -""" |
2 | | -Process simulation tools for NeqSim. |
| 1 | +"""Process simulation tools for NeqSim. |
3 | 2 |
|
4 | 3 | This module provides Python wrapper functions for creating and running |
5 | 4 | process simulations using the NeqSim Java library. It includes equipment |
6 | 5 | like compressors, pumps, heat exchangers, separators, and more. |
7 | 6 |
|
8 | | -Example usage in Google Colab: |
| 7 | +Two Approaches for Process Simulation |
| 8 | +===================================== |
| 9 | +
|
| 10 | +NeqSim Python offers two ways to build process simulations: |
| 11 | +
|
| 12 | +1. **Python Wrappers (Recommended for beginners)** |
| 13 | + Uses simple Python functions with a global process. Best for quick |
| 14 | + prototyping, Jupyter notebooks, and learning. |
| 15 | +
|
| 16 | +2. **Direct Java Access (Full control)** |
| 17 | + Uses the jneqsim module to access NeqSim Java classes directly. |
| 18 | + Best for production code, multiple processes, and advanced features. |
| 19 | +
|
| 20 | +Approach 1: Python Wrappers (Global Process) |
| 21 | +-------------------------------------------- |
| 22 | +Simple functions that automatically add equipment to a global process. |
| 23 | +Use clearProcess() to reset, runProcess() to execute. |
| 24 | +
|
9 | 25 | >>> from neqsim.thermo import fluid |
10 | 26 | >>> from neqsim.process import stream, compressor, runProcess, clearProcess |
11 | 27 | >>> |
12 | 28 | >>> clearProcess() |
13 | 29 | >>> my_fluid = fluid('srk') |
14 | 30 | >>> my_fluid.addComponent('methane', 1.0) |
| 31 | + >>> my_fluid.setTemperature(30.0, 'C') |
| 32 | + >>> my_fluid.setPressure(10.0, 'bara') |
| 33 | + >>> my_fluid.setTotalFlowRate(1.0, 'MSm3/day') |
| 34 | + >>> |
15 | 35 | >>> inlet = stream('inlet', my_fluid) |
16 | | - >>> inlet.setPressure(10.0, 'bara') |
17 | 36 | >>> comp = compressor('compressor1', inlet, pres=50.0) |
18 | 37 | >>> runProcess() |
19 | 38 | >>> print(f"Power: {comp.getPower()/1e6:.2f} MW") |
| 39 | +
|
| 40 | +Pros: |
| 41 | + - Concise, readable code |
| 42 | + - Tab completion and docstrings in IDE |
| 43 | + - No Java knowledge required |
| 44 | + - Great for learning and prototyping |
| 45 | +
|
| 46 | +Cons: |
| 47 | + - Global state limits to one process at a time |
| 48 | + - Not all Java features may be exposed |
| 49 | + - Less control over process execution |
| 50 | +
|
| 51 | +Approach 2: Direct Java Access (Explicit Process) |
| 52 | +-------------------------------------------------- |
| 53 | +Create and manage ProcessSystem objects explicitly using jneqsim. |
| 54 | +
|
| 55 | + >>> from neqsim import jneqsim |
| 56 | + >>> from neqsim.thermo import fluid |
| 57 | + >>> |
| 58 | + >>> # Create fluid |
| 59 | + >>> my_fluid = fluid('srk') |
| 60 | + >>> my_fluid.addComponent('methane', 1.0) |
| 61 | + >>> my_fluid.setTemperature(30.0, 'C') |
| 62 | + >>> my_fluid.setPressure(10.0, 'bara') |
| 63 | + >>> my_fluid.setTotalFlowRate(1.0, 'MSm3/day') |
| 64 | + >>> |
| 65 | + >>> # Create equipment using Java classes |
| 66 | + >>> inlet = jneqsim.process.equipment.stream.Stream('inlet', my_fluid) |
| 67 | + >>> comp = jneqsim.process.equipment.compressor.Compressor('compressor1', inlet) |
| 68 | + >>> comp.setOutletPressure(50.0) |
| 69 | + >>> |
| 70 | + >>> # Create and run process explicitly |
| 71 | + >>> process = jneqsim.process.processmodel.ProcessSystem() |
| 72 | + >>> process.add(inlet) |
| 73 | + >>> process.add(comp) |
| 74 | + >>> process.run() |
| 75 | + >>> print(f"Power: {comp.getPower()/1e6:.2f} MW") |
| 76 | +
|
| 77 | +Pros: |
| 78 | + - Full access to all NeqSim Java features |
| 79 | + - Multiple independent processes possible |
| 80 | + - Explicit control over process construction |
| 81 | + - Better for production code and testing |
| 82 | +
|
| 83 | +Cons: |
| 84 | + - More verbose code |
| 85 | + - Requires understanding of Java class structure |
| 86 | + - Less IDE support (though stubs help) |
| 87 | +
|
| 88 | +Choosing an Approach |
| 89 | +-------------------- |
| 90 | +Use **Python wrappers** when: |
| 91 | + - Learning NeqSim or thermodynamics |
| 92 | + - Quick calculations in Jupyter notebooks |
| 93 | + - Single process simulations |
| 94 | + - Prototyping process designs |
| 95 | +
|
| 96 | +Use **direct Java access** when: |
| 97 | + - Building production applications |
| 98 | + - Running multiple processes in parallel |
| 99 | + - Need features not exposed by wrappers |
| 100 | + - Writing automated tests |
| 101 | + - Configuration-driven process construction |
| 102 | +
|
| 103 | +Hybrid Approach |
| 104 | +--------------- |
| 105 | +You can mix both approaches. Create equipment with wrappers, then access |
| 106 | +Java methods directly: |
| 107 | +
|
| 108 | + >>> from neqsim.process import stream, compressor, runProcess, clearProcess |
| 109 | + >>> from neqsim.thermo import fluid |
| 110 | + >>> |
| 111 | + >>> clearProcess() |
| 112 | + >>> my_fluid = fluid('srk') |
| 113 | + >>> my_fluid.addComponent('methane', 1.0) |
| 114 | + >>> inlet = stream('inlet', my_fluid) |
| 115 | + >>> comp = compressor('comp1', inlet, pres=50.0) |
| 116 | + >>> |
| 117 | + >>> # Access Java methods not exposed by wrapper |
| 118 | + >>> comp.setPolytropicEfficiency(0.78) |
| 119 | + >>> comp.setUsePolytropicCalc(True) |
| 120 | + >>> |
| 121 | + >>> runProcess() |
| 122 | +
|
| 123 | +Available Equipment |
| 124 | +------------------- |
| 125 | +Streams: stream, virtualstream, neqstream, energystream |
| 126 | +Separation: separator, separator3phase, gasscrubber, filters |
| 127 | +Compression: compressor, pump, expander |
| 128 | +Heat Transfer: heater, cooler, heatExchanger |
| 129 | +Valves: valve, safety_valve |
| 130 | +Mixing/Splitting: mixer, phasemixer, splitter, compsplitter, staticmixer |
| 131 | +Pipelines: pipe, pipeline, beggs_brill_pipe, wellflow |
| 132 | +Columns: distillationColumn, simpleTEGAbsorber, waterStripperColumn |
| 133 | +Control: calculator, setpoint, adjuster, flowrateadjuster, setter, flowsetter |
| 134 | +Special: ejector, flare, flarestack, recycle, saturator, GORfitter |
| 135 | +Storage: tank, simplereservoir, manifold |
| 136 | +Measurement: waterDewPointAnalyser, hydrateEquilibriumTemperatureAnalyser |
| 137 | +Power: windturbine, solarpanel, batterystorage, fuelcell, electrolyzer, co2electrolyzer |
20 | 138 | """ |
21 | 139 | from __future__ import annotations |
22 | 140 |
|
|
0 commit comments