Skip to content

Model Selection Architecture ​

Basic and Advanced calculation modes for process units

Overview ​

ErgoPlanner supports two calculation modes for process units:

ModeDescriptionUse Case
BasicFixed-efficiency calculations using empirical removal ratesQuick estimates, preliminary design, simple plants
AdvancedMechanistic calculations using biokinetic models (ASM1, ASM2d, ASM3, ADM1)Detailed design, optimization, research

Calculation Mode Selection ​

Per-Node Mode Selection ​

Each process unit can have its own calculation mode. The mode is stored as part of the node parameters:

typescript
interface ProcessUnitParameters {
  // ... other parameters
  calculationMode?: 'basic' | 'advanced';
}

Default Behavior ​

  • New nodes default to 'basic' mode for backward compatibility
  • Templates can specify default modes per unit type
  • Mode changes preserve parameter values for seamless switching

Using the Mode Toggle ​

In the Properties Panel ​

  1. Select a process unit on the canvas
  2. In the Properties Panel, locate the Mode toggle (below the unit type)
  3. Click Basic or Advanced to switch modes
  4. Additional parameters appear in Advanced mode

Visual Indicators ​

  • Basic mode: Standard parameter view
  • Advanced mode: Extended parameters with kinetic coefficients

ModelModeService API ​

The ModelModeService manages calculation mode state:

typescript
import { getModelModeService } from '@/flow/services/simulation/modelMode';

const service = getModelModeService();

// Get current mode (returns 'basic' for unknown nodes)
const mode = service.getCalculationMode('node-id');

// Set calculation mode
service.setCalculationMode('node-id', 'advanced');

// Check if unit type supports advanced mode
const supported = service.supportsAdvancedMode('CSTR');

// Subscribe to mode changes
const unsubscribe = service.subscribe((event) => {
  console.log(`Mode changed: ${event.oldMode} -> ${event.newMode}`);
});

Parameter Preservation ​

When switching from Advanced to Basic mode, advanced parameters are cached:

typescript
// Before switching to basic, preserve advanced params
service.preserveAdvancedParams('node-id', currentParams);
service.setCalculationMode('node-id', 'basic');

// Later, when switching back to advanced
service.setCalculationMode('node-id', 'advanced');
const restored = service.restoreAdvancedParams('node-id');

Implementing Advanced Process Unit Models ​

To add advanced mode support to a process unit, implement IAdvancedProcessUnit:

typescript
import { IAdvancedProcessUnit } from '@/flow/services/simulation/plugins';

class AdvancedCSTRModel implements IAdvancedProcessUnit {
  // Basic mode parameters shown in UI
  basicModeParameters = ['volume', 'mlss', 'srt'];

  // Additional advanced parameters
  advancedParameterSchema = {
    type: 'object',
    properties: {
      muMax: { type: 'number', title: 'Max growth rate (1/d)' },
      Ks: { type: 'number', title: 'Half-saturation (mg/L)' },
      Yh: { type: 'number', title: 'Heterotrophic yield' },
    }
  };

  advancedDefaultParameters = {
    muMax: 6.0,
    Ks: 20,
    Yh: 0.67,
  };

  calculateAdvancedOutputs(inputs, params) {
    // Implement ASM1/ASM2d/ASM3 calculations
    return outputs;
  }
}

Template Configuration ​

Templates can specify default calculation modes:

typescript
// In templateParameterService.ts
const TEMPLATE_DEFAULT_MODES = {
  'mle-basic': {
    defaultMode: 'basic' as const,
    nodeOverrides: {}
  },
  'mle-advanced': {
    defaultMode: 'advanced' as const,
    nodeOverrides: {
      'cstr-1': 'advanced',
      'clarifier-1': 'basic', // Clarifiers stay basic
    }
  }
};

Supported Process Units ​

Advanced Mode Support ​

Unit TypeBasicAdvancedBiokinetic Models
CSTRYesYesASM1, ASM2d, ASM3
PFRYesYesASM1, ASM3
SBRYesYesASM1, ASM2d
MBBRYesYesASM3
MBRYesYesASM1, ASM2d
DigesterYesYesADM1
Primary ClarifierYesYesStokes/Camp
Secondary ClarifierYesYesTakács
ThickenerYesNo-
DAFYesNo-

Best Practices ​

  1. Start with Basic mode for initial design
  2. Switch to Advanced when optimizing or validating
  3. Use consistent modes across connected units
  4. Save templates with appropriate default modes

Technical Reference ​

Files ​

FilePurpose
engine/types.tsCalculationMode type definition
plugins/IAdvancedProcessUnit.tsAdvanced model interface
modelMode/modelModeService.tsMode management service
templates/templateParameterService.tsTemplate defaults