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_sanitation_components

qsdsan.utils.create_example_sanitation_components(set_thermo=True)

Load a set of pre-constructed components for sanitation-unit documentation.

These are the excreta/nutrient components used by the sanitation SanUnit examples (e.g., Excretion, PitLatrine, Trucking); they are not part of the default set returned by qsdsan.Components.load_default().

Parameters:

set_thermo (bool) – Whether to set the returned components as the thermodynamic property package (i.e., call qsdsan.set_thermo()).

Returns:

  • A qsdsan.CompiledComponents object with the components

  • NH3 (measured as N), NonNH3, P, K, Mg, Ca, H2O, OtherSS, N2O, CH4,

  • Tissue, WoodAsh, Struvite, HAP, MagnesiumHydroxide, and LPG. The last four

  • are needed by some units (e.g., struvite recovery in

  • UDDT/SepticTank,

  • LPG combustion in SludgePasteurization).

Examples

>>> from qsdsan.utils import create_example_sanitation_components
>>> cmps = create_example_sanitation_components()
>>> cmps.IDs
('NH3', 'NonNH3', 'P', 'K', 'Mg', 'Ca', 'H2O', 'OtherSS', 'N2O', 'CH4', 'Tissue', 'WoodAsh', 'Struvite', 'HAP', 'MagnesiumHydroxide', 'LPG')

create_example_wwt_components

qsdsan.utils.create_example_wwt_components(set_thermo=True)

Load a minimal set of pre-constructed components for wastewater-treatment unit documentation.

These are the lumped COD-based components used by the wastewater-treatment SanUnit examples (e.g., ActivatedSludgeProcess, BeltThickener, CombinedHeatPower). The active_biomass, inert_biomass, and substrates component groups expected by several of those units are defined here.

Parameters:

set_thermo (bool) – Whether to set the returned components as the thermodynamic property package (i.e., call qsdsan.set_thermo()).

Returns:

  • A qsdsan.CompiledComponents object with X (biomass), X_inert

  • (inert biomass), Substrate, and CH4, plus the default combustion components

  • (O2, CO2, H2O, N2, P4O10, SO2).

Examples

>>> from qsdsan.utils import create_example_wwt_components
>>> cmps = create_example_wwt_components()
>>> cmps.IDs
('X', 'X_inert', 'Substrate', 'CH4', 'O2', 'CO2', 'H2O', 'N2', 'P4O10', 'SO2')
>>> [c.ID for c in cmps.substrates]
['Substrate']

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_treatment_systems

qsdsan.utils.create_example_treatment_systems(components=None, set_thermo=True)

Build the aerobic and anaerobic wastewater treatment systems used in the TEA and LCA tutorials, for documentation purpose.

Two single-unit systems treat the same municipal wastewater (4,000 m3/d, COD ~430 mg/L):

  • aer_sys: an aerobic activated-sludge plant (spends electricity on aeration, produces waste sludge); and

  • ana_sys: an anaerobic plant (recovers biogas, but needs heating and a little alkalinity).

Both plants share an installed capital and a sludge-disposal cost (declared on a common abstract base class), so they are a compact but realistic substrate for techno-economic and life cycle analyses. The sizing, energy, and cost figures follow Metcalf & Eddy, Wastewater Engineering (5th ed.); they are order-of-magnitude teaching values, not a design basis.

Parameters:
  • components (obj) – If given, will call qsdsan.set_thermo(components)(); otherwise a small set of components is created. Must include “H2O”, “O2”, “CO2”, “NH3”, “CH4”, “NaHCO3”, “Substrate”, and “Biomass”.

  • set_thermo (bool) – Whether to set the thermo property package to the components used here (ignored when components is None, in which case it is always set).

Returns:

  • aer_sys (qsdsan.System) – The aerobic treatment system (unit aer).

  • ana_sys (qsdsan.System) – The anaerobic treatment system (unit ana).

Examples

>>> from qsdsan.utils import create_example_treatment_systems
>>> aer_sys, ana_sys = create_example_treatment_systems()
>>> aer_sys.simulate()
>>> ana_sys.simulate()
>>> ([u.ID for u in aer_sys.units], [u.ID for u in ana_sys.units])
(['aer'], ['ana'])
>>> aer_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: [TEA] Total capital expenditure (USD)>,
 <Metric: [TEA] Net present value (USD)>)