Documentation Examples

This modules contain several quick functions for demonstration (e.g., quickly create a qsdsan.Model to show the functions in the qsdsan.stats module).

create_example_components

qsdsan.utils.create_example_components(set_thermo=True)

Load pre-constructed components for documentation purpose.

Returns:

  • A qsdsan.CompiledComponents object with components including

  • H2O (alias Water), CO2, N2O, NaCl, H2SO4, CH4 (alias Methane), Methanol, and Ethanol.

Examples

>>> from qsdsan.utils import create_example_components
>>> cmps = create_example_components()
>>> cmps.show()
CompiledComponents([H2O, CO2, N2O, NaCl, H2SO4, CH4, Methanol, Ethanol])

create_example_system

qsdsan.utils.create_example_system(components=None)

Load a pre-constructed system for documentation purpose.

Returns:

  • A qsdsan.System object including a mix tank, a pump, a heat exchanger,

  • and various mixer/splitters.

Parameters:

components (obj) – If given, will call qsdsan.set_thermo(components)() to set components used in system simulation. The provided components must have “Water”, “NaCl”, “Methanol”, and “Ethanol” components, which are used in the construction of the system.

Examples

>>> from qsdsan.utils import create_example_system
>>> # Components from `create_example_components` will be loaded if no components are set/given
>>> sys = create_example_system()
>>> sys.path
(<MixTank: M1>,
 <Pump: P1>,
 <HXutility: H1>,
 <ComponentSplitter: S1>,
 <Mixer: M2>,
 <Splitter: S2>)
>>> sys.diagram() 

create_example_model

qsdsan.utils.create_example_model(evaluate=False, N=100, rule='L', seed=554, **sample_kwargs)

Load a pre-constructed system model for documentation purpose.

Parameters:
  • evaluate (bool) – Whether to evaluate the model (i.e., simulate the system and get metrics).

  • N (int) – Sample size, will be ignored if evaluate is set to False.

  • rule (str) – Sampling rule, will be ignored if evaluate is set to False.

  • seed (int) – Random seed for sample consistency, will be ignored if evaluate is set to False.

  • sample_kwargs (dict) – Additional keyword arguments that will be passed to model.sample()

Returns:

cmps – If given, will call qsdsan.set_thermo(cmps)() to set components used in system simulation. The provided cmps must have “Water”, “NaCl”, “Methanol”, and “Ethanol” components, which are used in the construction of the system.

Return type:

obj

Examples

>>> from qsdsan.utils import create_example_model
>>> model = create_example_model(N=100, rule='L', seed=554, evaluate=False)
>>> model.system.path
(<MixTank: M1>,
 <Pump: P1>,
 <HXutility: H1>,
 <ComponentSplitter: S1>,
 <Mixer: M2>,
 <Splitter: S2>)
>>> model.parameters 
(<Parameter: [Stream-salt water] Salt flow rate (kg/hr)>,
 <Parameter: [Stream-salt water] Salt solution price (USD/kg)>,
 <Parameter: [Mix tank-M1] Mix tank retention time (hr)>,
 <Parameter: [Mix tank-M1] Mix tank mixer power usage (kW/m3)>,
 <Parameter: [Pump-P1] Pump design head (kPa)>,
 <Parameter: [HXutility-H1] Heat exchanger temperature (K)>)
>>> model.metrics 
(<Metric: [System] Total heating duty (kJ/yr)>,
 <Metric: [System] Total electricity consumption (kWh/yr)>,
 <Metric: [Simple TEA] Total capital expenditure (USD)>,
 <Metric: [Simple TEA] Net present value (USD)>)