Skip to content

Commit d20a13b

Browse files
committed
docs: document two approaches for process simulation
Added comprehensive documentation explaining: - Python wrappers (global process) for beginners/notebooks - Direct jneqsim Java access for production/advanced use - Hybrid approach combining both methods - Pros and cons of each approach - Complete equipment list by category Updated README.md with: - Process Simulation section with code examples - Comparison table for choosing an approach
1 parent efa42a6 commit d20a13b

File tree

2 files changed

+192
-4
lines changed

2 files changed

+192
-4
lines changed

README.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,76 @@ pip install neqsim
2020

2121
See the [NeqSim Python Wiki](https://github.com/equinor/neqsim-python/wiki) for how to use NeqSim Python via Python or in Jupyter notebooks. Also see [examples of use of NeqSim for Gas Processing in Colab](https://colab.research.google.com/github/EvenSol/NeqSim-Colab/blob/master/notebooks/examples_of_NeqSim_in_Colab.ipynb#scrollTo=kHt6u-utpvYf). Learn and ask questions in [Discussions for use and development of NeqSim](https://github.com/equinor/neqsim/discussions).
2222

23+
## Process Simulation
24+
25+
NeqSim Python provides two ways to build process simulations:
26+
27+
### 1. Python Wrappers (Recommended for beginners)
28+
29+
Simple functions with a global process - great for notebooks and prototyping:
30+
31+
```python
32+
from neqsim.thermo import fluid
33+
from neqsim.process import stream, compressor, separator, runProcess, clearProcess
34+
35+
clearProcess()
36+
feed = fluid('srk')
37+
feed.addComponent('methane', 0.9)
38+
feed.addComponent('ethane', 0.1)
39+
feed.setTemperature(30.0, 'C')
40+
feed.setPressure(50.0, 'bara')
41+
feed.setTotalFlowRate(10.0, 'MSm3/day')
42+
43+
inlet = stream('inlet', feed)
44+
sep = separator('separator', inlet)
45+
comp = compressor('compressor', sep.getGasOutStream(), pres=100.0)
46+
runProcess()
47+
48+
print(f"Compressor power: {comp.getPower()/1e6:.2f} MW")
49+
```
50+
51+
### 2. Direct Java Access (Full control)
52+
53+
Explicit process management using jneqsim - best for production code:
54+
55+
```python
56+
from neqsim import jneqsim
57+
from neqsim.thermo import fluid
58+
59+
feed = fluid('srk')
60+
feed.addComponent('methane', 0.9)
61+
feed.addComponent('ethane', 0.1)
62+
feed.setTemperature(30.0, 'C')
63+
feed.setPressure(50.0, 'bara')
64+
65+
# Create equipment using Java classes
66+
inlet = jneqsim.process.equipment.stream.Stream('inlet', feed)
67+
sep = jneqsim.process.equipment.separator.Separator('separator', inlet)
68+
comp = jneqsim.process.equipment.compressor.Compressor('compressor', sep.getGasOutStream())
69+
comp.setOutletPressure(100.0)
70+
71+
# Create and run process explicitly
72+
process = jneqsim.process.processmodel.ProcessSystem()
73+
process.add(inlet)
74+
process.add(sep)
75+
process.add(comp)
76+
process.run()
77+
78+
print(f"Compressor power: {comp.getPower()/1e6:.2f} MW")
79+
```
80+
81+
### Choosing an Approach
82+
83+
| Use Case | Recommended Approach |
84+
|----------|---------------------|
85+
| Learning & prototyping | Python wrappers |
86+
| Jupyter notebooks | Python wrappers |
87+
| Production applications | Direct Java access |
88+
| Multiple parallel processes | Direct Java access |
89+
| Advanced Java features | Direct Java access |
90+
91+
See the [examples folder](https://github.com/equinor/neqsim-python/tree/master/examples) for more process simulation examples.
92+
2393
### Prerequisites
2494

2595
Java version 8 or higher ([Java JDK](https://adoptium.net/)) needs to be installed. The Python package [JPype](https://github.com/jpype-project/jpype) is used to connect Python and Java. Read the [installation requirements for Jpype](https://jpype.readthedocs.io/en/latest/install.html). Be aware that mixing 64 bit Python with 32 bit Java and vice versa crashes on import of the jpype module. The needed Python packages are listed in the [NeqSim Python dependencies page](https://github.com/equinor/neqsim-python/network/dependencies).

src/neqsim/process/processTools.py

Lines changed: 122 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,140 @@
1-
"""
2-
Process simulation tools for NeqSim.
1+
"""Process simulation tools for NeqSim.
32
43
This module provides Python wrapper functions for creating and running
54
process simulations using the NeqSim Java library. It includes equipment
65
like compressors, pumps, heat exchangers, separators, and more.
76
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+
925
>>> from neqsim.thermo import fluid
1026
>>> from neqsim.process import stream, compressor, runProcess, clearProcess
1127
>>>
1228
>>> clearProcess()
1329
>>> my_fluid = fluid('srk')
1430
>>> 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+
>>>
1535
>>> inlet = stream('inlet', my_fluid)
16-
>>> inlet.setPressure(10.0, 'bara')
1736
>>> comp = compressor('compressor1', inlet, pres=50.0)
1837
>>> runProcess()
1938
>>> 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
20138
"""
21139
from __future__ import annotations
22140

0 commit comments

Comments
 (0)