Class SpreadsheetBlock

All Implemented Interfaces:
Serializable, Runnable, ProcessEquipmentInterface, ProcessElementInterface, SimulationInterface, NamedInterface

public class SpreadsheetBlock extends ProcessEquipmentBaseClass
Inline spreadsheet / calculator block for embedding custom calculations directly in a flowsheet. Similar to UniSim's spreadsheet, this block lets users define named import cells that pull values from process streams or equipment, named formula cells that perform arithmetic on those values, and export cells that push computed results back into the process.

Usage example:

SpreadsheetBlock sheet = new SpreadsheetBlock("Energy Calc");
sheet.addStreamImportCell("T_in", feed, s -> s.getTemperature("C"));
sheet.addStreamImportCell("T_out", product, s -> s.getTemperature("C"));
sheet.addStreamImportCell("mdot", feed, s -> s.getFlowRate("kg/hr"));
sheet.addFormulaCell("deltaT", cells -> cells.get("T_out") - cells.get("T_in"));
sheet.addFormulaCell("duty_kW",
    cells -> cells.get("mdot") * 4.18 * cells.get("deltaT") / 3600.0);
sheet.addExportCell("duty_kW", cooler, (eq, val) -> ((Cooler) eq).setEnergyInput(val));
Version:
1.0
Author:
ESOL
See Also:
  • Field Details

  • Constructor Details

    • SpreadsheetBlock

      public SpreadsheetBlock(String name)
      Constructor for SpreadsheetBlock.
      Parameters:
      name - a String name for this spreadsheet block
  • Method Details

    • addStreamImportCell

      public void addStreamImportCell(String cellName, StreamInterface stream, Function<StreamInterface, Double> reader)
      Add an import cell that reads a value from a stream each time the block runs.
      Parameters:
      cellName - unique name for this cell (e.g. "T_inlet")
      stream - the source stream to read from
      reader - function that extracts a double value from the stream
    • addImportCell

      public void addImportCell(String cellName, ProcessEquipmentInterface equipment, Function<ProcessEquipmentInterface, Double> reader)
      Add an import cell that reads a value from any process equipment each time the block runs.
      Parameters:
      cellName - unique name for this cell
      equipment - the source equipment to read from
      reader - function that extracts a double value from the equipment
    • addConstantCell

      public void addConstantCell(String cellName, double value)
      Add a constant cell with a fixed value.
      Parameters:
      cellName - unique name for this cell
      value - the constant value
    • addFormulaCell

      public void addFormulaCell(String cellName, Function<Map<String,Double>, Double> formula)
      Add a formula cell that computes a value from the current cell values. Formula cells can reference any previously defined cell (import, constant, or earlier formula cells).
      Parameters:
      cellName - unique name for this cell
      formula - function that takes the map of current cell values and returns the computed value
    • addExportCell

      public void addExportCell(String cellName, ProcessEquipmentInterface target, SpreadsheetBlock.ExportWriter writer)
      Add an export target that pushes a computed cell value back into process equipment after calculation.
      Parameters:
      cellName - the cell whose value to export
      target - the equipment to receive the value
      writer - biconsumer that applies the value to the equipment
    • getCellValue

      public double getCellValue(String cellName)
      Get the current computed value of a cell.
      Parameters:
      cellName - the cell name
      Returns:
      the current value, or Double.NaN if not yet computed
    • getAllCellValues

      public Map<String,Double> getAllCellValues()
      Get all current cell values as an unmodifiable map.
      Returns:
      map of cell name to computed value
    • getCellNames

      public List<String> getCellNames()
      Get the names of all defined cells in order.
      Returns:
      list of cell names
    • run

      public void run(UUID id)

      In this method all thermodynamic and unit operations will be calculated in a steady state calculation.

      Parameters:
      id - UUID