<jupyter_start><jupyter_text>Cornstover biorefinery **In this example, uncertainty analysis is performed around reaction conversions in the cornstover biorefinery.**  Cornstover biorefinery layout The cornstover biorefinery modeled in BioSTEAM is divided into 8 areas: feedstock handling, pretreatment and conditioning, enzyme production, recovery, wastewater treatment, storage, boiler and turbo-generator system, and utilities (Figure 4). In contrast to the original report by Humbird et. al., enzyme is not produced on-site. Instead, the cellulase mixture is bought at 0.507 USD⋅kg-1 at a protein concentration of 0.10 kg⋅liter-1. ![Cornstover areas](Cornstover_areas.png "Cornstover areas") Begin by loading the biorefinery:<jupyter_code>import biosteam as bst
from biosteam import find
from biosteam.biorefineries.cornstover import system<jupyter_output><empty_output><jupyter_text>By convention, the complete system is the name of the flowsheet with "_sys" at the end:<jupyter_code>cornstover_sys = find.system.cornstover_sys
cornstover_sys
# Here is the TEA object
cornstover_tea = cornstover_sys.TEA
cornstover_tea<jupyter_output><empty_output><jupyter_text>Navigate by looking at the diagram:<jupyter_code>find.diagram('thorough') # Alternatively, you could save a report of the system to explore the biorefinery<jupyter_output><empty_output><jupyter_text>Note that all unit operations are numbered by their respective area, for example the pretreatment reactor `R201` is in area 200.<jupyter_code>R201 = find.unit.R201
R201<jupyter_output><empty_output><jupyter_text>The `reactions` attribute of the PretreatmentReactorSystem object is a ParallelReaction object with all stoichiometric reaction taking place:<jupyter_code>find.unit.R201.reactions<jupyter_output><empty_output><jupyter_text>You can access reaction items and change conversions:<jupyter_code>glucose_conversion_rxn = R201.reactions[0]
glucose_conversion_rxn
print(glucose_conversion_rxn.X)
glucose_conversion_rxn.X = 0.10
print(glucose_conversion_rxn.X)<jupyter_output><empty_output><jupyter_text>We can create a Model object to begin our uncertainty analysis:<jupyter_code># Define MESP function
ethanol_density_kggal = 2.98668849 # kg/gal
ethanol = find.stream.ethanol
get_MESP = lambda: cornstover_tea.solve_price(ethanol) * ethanol_density_kggal # -> USD/gal

# Define MESP metric
metric_MESP = bst.Metric('MESP', get_MESP, 'USD/gal')

# Initialize model
cornstover_model = bst.Model(system=find.system.cornstover_sys,
                             metrics=(metric_MESP,))

cornstover_model # The model begins with no parameters<jupyter_output><empty_output><jupyter_text>Now add parameters concerning reactions:<jupyter_code>from chaospy import distributions as D

# Parameter distribution
conversion = D.Triangle(0.05, 0.10, 0.15)

# Parameter decorator
param = cornstover_model.parameter 

# Create and add paramter
@param(element=R201, kind='coupled', distribution=conversion)
def set_conversion(glucose_conversion):
    glucose_conversion_rxn.X = glucose_conversion

cornstover_model
xylose_conversion_rxn = R201.reactions[8]

@param(element=R201, kind='coupled', distribution=D.Triangle(0.85, 0.90, 0.95))
def set_conversion(xylose_conversion):
    xylose_conversion_rxn.X = xylose_conversion
    
cornstover_model<jupyter_output><empty_output><jupyter_text>Check your distributions:<jupyter_code>dist_dict = cornstover_model.get_distribution_summary()
dist_dict['Triangle']<jupyter_output><empty_output><jupyter_text>Once all parameters have been added, Monte Carlo can be performed:<jupyter_code>N_samples = 100
rule = 'L' # Latin hypercube sampling
samples = cornstover_model.sample(N_samples, rule)
cornstover_model.load_samples(samples)
cornstover_model.evaluate()
cornstover_model.table<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup