Skip to content

Commit 6c4d651

Browse files
authored
add validation (#1809)
* add validation * update * update * update * update * update * v3.2.1
1 parent 66bde2e commit 6c4d651

File tree

31 files changed

+3553
-30
lines changed

31 files changed

+3553
-30
lines changed

docs/integration/ai_validation_framework.md

Lines changed: 111 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,107 @@ ValidationResult post = contract.checkPostconditions(system);
7777
- `SeparatorContract` - Validates Separator equipment
7878
- `ProcessSystemContract` - Validates ProcessSystem
7979

80-
### 4. AIIntegrationHelper
80+
### 4. Equipment-Level Validation
81+
82+
All process equipment classes implement `validateSetup()` to check equipment-specific configuration:
83+
84+
```java
85+
// Validate individual equipment
86+
Separator separator = new Separator("V-100");
87+
ValidationResult result = separator.validateSetup();
88+
89+
if (!result.isValid()) {
90+
System.out.println("Configuration issues:");
91+
result.getErrors().forEach(System.out::println);
92+
}
93+
```
94+
95+
**Equipment Validation Checks:**
96+
97+
| Equipment | Validations |
98+
|-----------|-------------|
99+
| **Stream** | Fluid set, temperature > 0 K |
100+
| **Separator** | Inlet stream connected |
101+
| **Mixer** | At least one inlet stream added |
102+
| **Splitter** | Inlet stream connected, split fractions sum to 1.0 |
103+
| **Tank** | Has fluid or input stream connected |
104+
| **DistillationColumn** | Feed streams connected, condenser/reboiler configured |
105+
| **Recycle** | Inlet and outlet streams set, tolerance > 0 |
106+
| **Adjuster** | Target and adjustment variables set, tolerance > 0 |
107+
| **TwoPortEquipment** | Inlet stream connected |
108+
109+
### 5. ProcessSystem Validation
110+
111+
ProcessSystem provides aggregate validation across all equipment:
112+
113+
```java
114+
ProcessSystem process = new ProcessSystem();
115+
process.add(feed);
116+
process.add(separator);
117+
process.add(compressor);
118+
119+
// Quick check before running
120+
if (process.isReadyToRun()) {
121+
process.run();
122+
} else {
123+
// Get combined validation result
124+
ValidationResult result = process.validateSetup();
125+
System.out.println(result.getReport());
126+
}
127+
128+
// Get per-equipment validation
129+
Map<String, ValidationResult> allResults = process.validateAll();
130+
for (Map.Entry<String, ValidationResult> entry : allResults.entrySet()) {
131+
if (!entry.getValue().isValid()) {
132+
System.out.println(entry.getKey() + ": " + entry.getValue().getErrors());
133+
}
134+
}
135+
```
136+
137+
**ProcessSystem Validation Methods:**
138+
139+
| Method | Returns | Description |
140+
|--------|---------|-------------|
141+
| `validateSetup()` | `ValidationResult` | Combined result for all equipment |
142+
| `validateAll()` | `Map<String, ValidationResult>` | Per-equipment results |
143+
| `isReadyToRun()` | `boolean` | True if no CRITICAL errors |
144+
145+
### 5b. ProcessModel Validation
146+
147+
ProcessModel provides aggregate validation across all contained ProcessSystems:
148+
149+
```java
150+
ProcessModel model = new ProcessModel();
151+
model.add("GasProcessing", gasProcess);
152+
model.add("OilProcessing", oilProcess);
153+
154+
// Quick check before running
155+
if (model.isReadyToRun()) {
156+
model.run();
157+
} else {
158+
// Get formatted validation report
159+
System.out.println(model.getValidationReport());
160+
}
161+
162+
// Get per-process validation
163+
Map<String, ValidationResult> allResults = model.validateAll();
164+
for (Map.Entry<String, ValidationResult> entry : allResults.entrySet()) {
165+
if (!entry.getValue().isValid()) {
166+
System.out.println(entry.getKey() + ": " + entry.getValue().getErrors());
167+
}
168+
}
169+
```
170+
171+
**ProcessModel Validation Methods:**
172+
173+
| Method | Returns | Description |
174+
|--------|---------|-------------|
175+
| `validateSetup()` | `ValidationResult` | Combined result for all processes |
176+
| `validateAll()` | `Map<String, ValidationResult>` | Per-process results |
177+
| `isReadyToRun()` | `boolean` | True if no CRITICAL errors |
178+
| `getValidationReport()` | `String` | Human-readable formatted report |
179+
180+
### 6. AIIntegrationHelper
81181

82182
Unified entry point connecting validation with RL/ML infrastructure:
83183

@@ -97,7 +197,7 @@ String docs = helper.getAPIDocumentation();
97197
RLEnvironment env = helper.createRLEnvironment();
98198
```
99199

100-
### 5. AI Annotations
200+
### 7. AI Annotations
101201

102202
Annotations for exposing methods to AI agents:
103203

@@ -115,7 +215,7 @@ public void addComponent(
115215
) { ... }
116216
```
117217

118-
### 6. AISchemaDiscovery
218+
### 8. AISchemaDiscovery
119219

120220
Discovers annotated methods via reflection:
121221

@@ -240,16 +340,18 @@ All components have comprehensive unit tests:
240340
| ModuleContractTest | 14 | Contract implementations |
241341
| AISchemaDiscoveryTest | 13 | Annotation discovery |
242342
| AIIntegrationHelperTest | 15 | Integration helper |
343+
| EquipmentValidationTest | 41 | Equipment and ProcessModel validateSetup() methods |
243344

244345
Run tests:
245346
```bash
246-
./mvnw test -Dtest="ValidationResultTest,SimulationValidatorTest,ModuleContractTest,AISchemaDiscoveryTest,AIIntegrationHelperTest"
347+
./mvnw test -Dtest="ValidationResultTest,SimulationValidatorTest,ModuleContractTest,AISchemaDiscoveryTest,AIIntegrationHelperTest,EquipmentValidationTest"
247348
```
248349

249350
## Future Enhancements
250351

251-
1. **Apply @AIExposable annotations** to core NeqSim methods (addComponent, setMixingRule, TPflash, etc.)
252-
2. **MPC validation contracts** for ProcessLinkedMPC
253-
3. **Surrogate model validation** integration with SurrogateModelRegistry
254-
4. **Real-time validation** during simulation stepping
255-
5. **Custom validation rules** via pluggable validators
352+
1. ~~**Standardize validateSetup()** across all ProcessEquipmentBaseClass subclasses~~ ✅ Implemented
353+
2. **Apply @AIExposable annotations** to core NeqSim methods (addComponent, setMixingRule, TPflash, etc.)
354+
3. **MPC validation contracts** for ProcessLinkedMPC
355+
4. **Surrogate model validation** integration with SurrogateModelRegistry
356+
5. **Real-time validation** during simulation stepping
357+
6. **Custom validation rules** via pluggable validators

docs/process/equipment/distillation.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Documentation for distillation column equipment in NeqSim process simulation.
66
- [Overview](#overview)
77
- [Column Types](#column-types)
88
- [Configuration](#configuration)
9+
- [Builder Pattern](#builder-pattern)
910
- [Solver Options](#solver-options)
1011
- [Usage Examples](#usage-examples)
1112

@@ -42,6 +43,58 @@ Stream bottoms = column.getLiquidOutStream();
4243

4344
---
4445

46+
## Builder Pattern
47+
48+
For complex column configurations, use the fluent Builder API:
49+
50+
```java
51+
import neqsim.process.equipment.distillation.DistillationColumn;
52+
import neqsim.process.equipment.distillation.DistillationColumn.SolverType;
53+
54+
// Build column with fluent API
55+
DistillationColumn column = DistillationColumn.builder("Deethanizer")
56+
.numberOfTrays(15)
57+
.withCondenserAndReboiler()
58+
.topPressure(25.0, "bara")
59+
.bottomPressure(26.0, "bara")
60+
.temperatureTolerance(0.001)
61+
.massBalanceTolerance(0.01)
62+
.maxIterations(100)
63+
.solverType(SolverType.INSIDE_OUT)
64+
.internalDiameter(2.5)
65+
.addFeedStream(feedStream, 8)
66+
.build();
67+
68+
column.run();
69+
```
70+
71+
### Builder Methods
72+
73+
| Method | Description |
74+
|--------|-------------|
75+
| `numberOfTrays(int)` | Set number of simple trays (excluding condenser/reboiler) |
76+
| `withCondenser()` | Add condenser at top |
77+
| `withReboiler()` | Add reboiler at bottom |
78+
| `withCondenserAndReboiler()` | Add both |
79+
| `topPressure(double, String)` | Set top pressure with unit |
80+
| `bottomPressure(double, String)` | Set bottom pressure with unit |
81+
| `pressure(double, String)` | Set same pressure top and bottom |
82+
| `temperatureTolerance(double)` | Convergence tolerance for temperature |
83+
| `massBalanceTolerance(double)` | Convergence tolerance for mass balance |
84+
| `tolerance(double)` | Set all tolerances at once |
85+
| `maxIterations(int)` | Maximum solver iterations |
86+
| `solverType(SolverType)` | Set solver algorithm |
87+
| `directSubstitution()` | Use direct substitution solver |
88+
| `dampedSubstitution()` | Use damped substitution solver |
89+
| `insideOut()` | Use inside-out solver |
90+
| `relaxationFactor(double)` | Damping factor for solver |
91+
| `internalDiameter(double)` | Column internal diameter (meters) |
92+
| `multiPhaseCheck(boolean)` | Enable/disable multi-phase check |
93+
| `addFeedStream(Stream, int)` | Add feed stream to specified tray |
94+
| `build()` | Build the configured column |
95+
96+
---
97+
4598
## Column Configuration
4699

47100
### Number of Trays

docs/process/processmodel/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ This folder contains documentation for process system and flowsheet management i
77
| Document | Description |
88
|----------|-------------|
99
| [ProcessSystem](process_system.md) | Main process system class and execution strategies |
10+
| [ProcessModel](process_model.md) | Multi-process coordination and management |
1011
| [ProcessModule](process_module.md) | Modular process units |
1112
| [Graph-Based Simulation](graph_simulation.md) | Graph-based execution and optimization |
1213
| [PFD Diagram Export](diagram_export.md) | Professional process flow diagram generation |

0 commit comments

Comments
 (0)