ProcessModel#
- class ProcessModel(*, simulate=True, scenario=None, load=True, save=None, **kwargs)[source]#
ProcessModel objects allow us to write code for many related configurations with ease. It streamlines the process of creating a model, including:
Defining scenarios to compare.
Creating the thermodynamic property package.
Forming the system from unit operations.
Setting up the evaluation model.
Additionally, all objects created within the process model (e.g., chemicals, streams, units, systems) can be easily accessed as attributes.
The first step is to inherit from the ProcessModel abstract class. An abstract class has missing (or “abstract”) attributes/methods which the user must define to complete the class. The user must define a Scenario dataclass, and as_scenario, create_thermo, create_system, create_model methods for the process model to initialize its key components.
It may help to look at how ProcessModel objects are created (approximately):
def __new__(cls, simulate=None, scenario=None, load=True, save=True, **kwargs): if scenario is None: self.scenario = cls.Scenario(**kwargs) else: # The Scenario object can be initialized through the `as_scenario` class method. self.scenario = cls.as_scenario(scenario) # No need to recreate a process model for repeated scenarios. if load and scenario in cls.cache: return cls.cache[scenario] self = super().__new__() # The thermodynamic property package is given by the `create_thermo` method. self.load_thermo(self.create_thermo()) # If no system is returned by the `create_system` method, a new system is created from flowsheet units. self.flowsheet = bst.Flowsheet() system = self.create_system() if system is None: system = self.flowsheet.create_system() # This saves the system as self.system and all units/streams as attributes by ID. # For example, Stream('feedstock') will be stored as self.feestock. self.load_system(system) # A Model object is loaded from the `create_model` method. # The model will be stored as self.model and all parameters and indicators as attributes by function name. # For example: # # @model.indicator # def MSP(): return self.tea.solve_price(self.product) # # ^ This becomes self.MSP. self.load_model(self.create_model()) if simulate: self.system.simulate() if save: self.cache[scenario] = self return self
-
Scenario:
type
# class-attribute Class which defines arguments to the process model using the layout of a python dataclass: https://docs.python.org/3/library/dataclasses.html
- default_scenario = AbstractMethod#
This method allows the process model to default the scenario. It should return a Scenario object.
- as_scenario = AbstractClassMethod#
This method allows the process model to interpret objects (e.g., strings, numbers) as a Scenario.
- initialize = AbstractMethod#
This method should return a model object. The model will be saved as a self.model attribute. All parameters and indicators of the model object will also be saved as attributes by their function names.
- create_thermo = AbstractMethod#
This method should return a chemicals or thermo object. BioSTEAM will automatically set it as the thermodynmic property package.
- create_system = AbstractMethod#
This method should create unit operations and connect them. It can return a system object, optionally. Otherwise, BioSTEAM will take care of creating the system from the units and saves it as the self.system attribute. All streams and unit operations are also saved as attributes by their ID.
- create_model = AbstractMethod#
This method should return a model object. The model will be saved as a self.model attribute. All parameters and indicators of the model object will also be saved as attributes by their function names.