Skip to content

Simulation Engine API Reference ​

Overview ​

The simulation engine provides core calculation capabilities for wastewater treatment process modeling. It supports hydraulic calculations, mass balance, and process performance analysis across multiple flow conditions.

Core Interfaces ​

StreamData ​

Represents flow and quality data at a connection point between process units.

Properties ​

PropertyTypeRequiredDescription
flownumberYesFlow rate in m³/d (default/current flow)
dwfnumberNoDry Weather Flow in m³/d - base design condition
peakFlownumberNoPeak flow from network in m³/d
flowConditionsFlowConditionSetNoComplete flow conditions set for all scenarios
tssnumberNoTotal suspended solids in mg/L
codnumberNoChemical oxygen demand in mg/L
tknnumberNoTotal Kjeldahl nitrogen in mg/L
tpnumberNoTotal phosphorus in mg/L
nh4numberNoAmmonia nitrogen in mg/L
no2numberNoNitrite nitrogen in mg/L (for two-step nitrification)
no3numberNoNitrate nitrogen in mg/L
donumberNoDissolved oxygen in mg/L
percentDSnumberNoPercent dry solids (%) - for sludge streams

Example ​

typescript
const influent: StreamData = {
  flow: 50000,
  dwf: 50000,
  tss: 250,
  cod: 500,
  tkn: 45,
  nh4: 30,
  tp: 8,
  do: 0.5
};

const effluentQuality: StreamData = {
  flow: 49500,
  tss: 10,
  cod: 40,
  tkn: 5,
  nh4: 1,
  no3: 8,
  tp: 0.5,
  do: 6.5
};

const sludgeStream: StreamData = {
  flow: 500,
  tss: 12000,
  percentDS: 1.2  // 1.2% dry solids
};
  • FlowConditionSet - Multi-condition flow scenarios
  • CalculationEdge - Uses StreamData for edge flow

FlowConditionSet ​

Complete flow condition set for a stream, containing all 6 standard design conditions.

Properties ​

PropertyTypeDescription
dwfnumberDry Weather Flow - base design condition (m³/d)
avgFlownumberAverage daily flow (m³/d)
maxDailynumberMaximum daily flow - peak day (m³/d)
minInstantnumberMinimum instantaneous flow (L/s)
maxInstantnumberMaximum instantaneous flow (L/s)
peakNetworknumberPeak flow from network model (L/s)

Example ​

typescript
const flowConditions: FlowConditionSet = {
  dwf: 50000,        // 50,000 m³/d base flow
  avgFlow: 60000,    // 60,000 m³/d annual average
  maxDaily: 90000,   // 90,000 m³/d peak day
  minInstant: 289,   // 289 L/s minimum
  maxInstant: 1736,  // 1,736 L/s maximum (3×DWF)
  peakNetwork: 2315  // 2,315 L/s from network model
};

// Apply to stream
const stream: StreamData = {
  flow: 50000,
  flowConditions: flowConditions,
  tss: 250,
  cod: 500
};
  • FlowConditionType - Individual condition type enumeration
  • FlowConditionMetadata - Display metadata for conditions

FlowConditionType ​

Enumeration of flow condition types for wastewater treatment design.

Values ​

ValueDescription
'DWF'Dry Weather Flow - base design condition
'avgFlow'Average daily flow
'maxDaily'Maximum daily flow (peak day)
'minInstant'Minimum instantaneous flow
'maxInstant'Maximum instantaneous flow (3×DWF typical)
'peakNetwork'Peak flow from network hydraulic model

Example ​

typescript
function getFlowValue(
  conditions: FlowConditionSet,
  type: FlowConditionType
): number {
  switch (type) {
    case 'DWF':
      return conditions.dwf;
    case 'avgFlow':
      return conditions.avgFlow;
    case 'maxDaily':
      return conditions.maxDaily;
    case 'minInstant':
      return conditions.minInstant;
    case 'maxInstant':
      return conditions.maxInstant;
    case 'peakNetwork':
      return conditions.peakNetwork;
  }
}

CalculationMode ​

Calculation mode for process units controlling whether basic fixed-efficiency or advanced mechanistic models are used.

Values ​

ValueDescription
'basic'Fixed-efficiency calculations (default, backward compatible)
'advanced'Mechanistic calculations using biokinetic models (ASM1, ASM2d, etc.)

Example ​

typescript
const unitParameters: ProcessUnitParameters = {
  calculationMode: 'advanced',
  volume: 5000,
  doSetpoint: 2.0,
  temperature: 15
};

BasicCalculationResult ​

Result of basic hydraulic calculations for the process flow network.

Properties ​

PropertyTypeDescription
flowsMap<string, number>Edge ID → flow rate (m³/d)
volumesMap<string, number>Node ID → volume (m³)
hrtMap<string, number>Node ID → hydraulic retention time (hours)
massLoadsMap<string, number>Edge ID → mass load (kg/d) for TSS
inletFlowsMap<string, number>Node ID → inlet flow rate (m³/d)
outletFlowsMap<string, number>Node ID → outlet flow rate (m³/d)
timestampDateCalculation timestamp
successbooleanWhether calculation completed successfully
errorsstring[]Error messages if any
warningsstring[]Warning messages if any

Example ​

typescript
interface CalculationEngine {
  calculate(graph: CalculationGraph): BasicCalculationResult;
}

const result = engine.calculate(graph);

if (result.success) {
  console.log(`Flow at edge E1: ${result.flows.get('E1')} m³/d`);
  console.log(`HRT at node N1: ${result.hrt.get('N1')} hours`);
  console.log(`TSS load at edge E2: ${result.massLoads.get('E2')} kg/d`);
} else {
  console.error('Calculation failed:', result.errors);
}

if (result.warnings.length > 0) {
  console.warn('Warnings:', result.warnings);
}

CalculationGraph ​

Complete calculation graph for the wastewater treatment plant.

Properties ​

PropertyTypeDescription
nodesMap<string, CalculationNode>All nodes in the graph by ID
edgesMap<string, CalculationEdge>All edges in the graph by ID
calculationOrderstring[]Topologically sorted node IDs for calculation order
hasCyclesbooleanWhether the graph contains cycles (recycle streams)
tearStreamsstring[]IDs of edges that are tear streams for recycle convergence

Example ​

typescript
// Build calculation graph
const graph: CalculationGraph = {
  nodes: new Map([
    ['N1', influentNode],
    ['N2', primaryNode],
    ['N3', aerationNode],
    ['N4', clarifierNode]
  ]),
  edges: new Map([
    ['E1', { id: 'E1', sourceId: 'N1', targetId: 'N2', streamData: { flow: 50000 } }],
    ['E2', { id: 'E2', sourceId: 'N2', targetId: 'N3', streamData: { flow: 50000 } }],
    ['E3', { id: 'E3', sourceId: 'N3', targetId: 'N4', streamData: { flow: 50000 } }]
  ]),
  calculationOrder: ['N1', 'N2', 'N3', 'N4'],
  hasCycles: false,
  tearStreams: []
};

// Process in topological order
for (const nodeId of graph.calculationOrder) {
  const node = graph.nodes.get(nodeId);
  // Perform calculations...
}
  • CalculationNode - Node structure
  • CalculationEdge - Edge structure

CalculationNode ​

Node in the calculation graph representing a process unit.

Properties ​

PropertyTypeDescription
idstringUnique node ID
namestringDisplay name
unitTypeProcessUnitTypeProcess unit type
parametersProcessUnitParametersUnit parameters
upstreamNodesstring[]IDs of upstream nodes
downstreamNodesstring[]IDs of downstream nodes
inletStreamDataundefined
outletsStreamData[]Outlet stream data (multiple for splitters)
displayValuesDisplayValue[]Display values for UI

Example ​

typescript
const aerationNode: CalculationNode = {
  id: 'aeration-1',
  name: 'Aeration Tank',
  unitType: 'aerobicZone',
  parameters: {
    volume: 5000,
    doSetpoint: 2.0,
    temperature: 15
  },
  upstreamNodes: ['primary-1'],
  downstreamNodes: ['clarifier-1'],
  inlet: {
    flow: 50000,
    tss: 150,
    cod: 300
  },
  outlets: [{
    flow: 50000,
    tss: 3000,  // MLSS
    do: 2.0
  }],
  displayValues: [
    { label: 'Volume', value: 5000, unit: 'm³', position: 'top' },
    { label: 'DO', value: 2.0, unit: 'mg/L', position: 'inside' }
  ]
};

CalculationEdge ​

Edge in the calculation graph representing a process connection.

Properties ​

PropertyTypeDescription
idstringUnique edge ID
sourceIdstringSource node ID
targetIdstringTarget node ID
sourceHandlestringundefined
targetHandlestringundefined
streamDataStreamDataStream data flowing through this edge
labelstringundefined

Example ​

typescript
const rasEdge: CalculationEdge = {
  id: 'edge-ras',
  sourceId: 'clarifier-1',
  targetId: 'aeration-1',
  sourceHandle: 'underflow',
  targetHandle: 'recycle',
  streamData: {
    flow: 50000,  // 1:1 RAS ratio
    tss: 12000,   // RAS solids
    do: 0.5
  },
  label: 'RAS'
};

DisplayValue ​

Display value to show on canvas nodes/edges for visual feedback.

Properties ​

PropertyTypeDescription
labelstringShort label for the value
valuestring | numberFormatted value string or number
unitstringUnit of measurement
positionstringundefined
colorstringundefined

Example ​

typescript
const displayValues: DisplayValue[] = [
  {
    label: 'Flow',
    value: 50000,
    unit: 'm³/d',
    position: 'top'
  },
  {
    label: 'DO',
    value: 2.0,
    unit: 'mg/L',
    position: 'inside',
    color: '#00ff00'
  },
  {
    label: 'MLSS',
    value: 3000,
    unit: 'mg/L',
    position: 'bottom'
  }
];

ProcessUnitParameters ​

Configuration parameters extracted from node data for calculations.

See Process Units API for complete documentation of all parameters.


Equipment Configuration Types ​

EquipmentStatus ​

Equipment status in the project indicating project scope.

Values ​

ValueDescription
'existing'Equipment already installed and operational
'new'Equipment to be installed as part of project
'to-be-removed'Equipment to be demolished/removed
'future'Equipment for future phases

ProcessUnitConfig ​

Extended process unit configuration supporting quantity, duty/standby, and status.

Properties ​

PropertyTypeDescription
quantitynumberNumber of parallel identical units (e.g., 3 for "3 PSTs")
dutyConfigDutyStandbyConfigundefined
statusEquipmentStatusEquipment status in project
puNumberstringundefined
puRangestringundefined
puNumberOverridestringundefined

Example ​

typescript
const pumpConfig: ProcessUnitConfig = {
  quantity: 3,
  dutyConfig: {
    duty: 2,
    standby: 1,
    label: '2D+1S'
  },
  status: 'new',
  puNumber: 'PU5',
  puRange: 'PU5-PU7'
};

DutyStandbyConfig ​

Duty/standby configuration for parallel units.

Properties ​

PropertyTypeDescription
dutynumberNumber of duty units (normally operating)
standbynumberNumber of standby units (backup)
assistnumberundefined
labelstringundefined

Example ​

typescript
const config: DutyStandbyConfig = {
  duty: 2,
  standby: 1,
  label: '2D+1S'
};

// With assist pump
const configWithAssist: DutyStandbyConfig = {
  duty: 2,
  standby: 1,
  assist: 1,
  label: '2D+1S+1A'
};

Implementation Notes ​

Flow Calculations ​

  1. Multi-condition Support: StreamData supports multiple flow conditions for comprehensive design analysis
  2. Default Flow: The flow property is the primary/active flow condition
  3. Optional Conditions: Individual flow conditions (dwf, peakFlow) or complete FlowConditionSet can be provided

Calculation Order ​

  1. Topological Sort: Nodes are calculated in topological order from the calculationOrder array
  2. Recycle Handling: Graphs with cycles use tear streams for iterative convergence
  3. Convergence: Recycle loops iterate until mass balance closes within tolerance

Units Consistency ​

All calculations use consistent SI units:

  • Flow: m³/d (daily) or L/s (instantaneous)
  • Concentration: mg/L
  • Mass: kg/d
  • Volume: m³
  • Time: hours (HRT), days (SRT)

Error Handling ​

Calculations return success/failure status with:

  • success: boolean indicating overall success
  • errors: array of error messages for failures
  • warnings: array of warning messages for non-critical issues