Parametrized Processes
In the previous chapter, you have seen how to define processes. In this section, you will learn how to add parameters to your processes, so as to write parametrized processes: processes that modify their behavior depending on a given input.
Simple first example
To declare a process using parameters, you use a params
(short for parameters) block:
process bake {
params {
salt_amount = 30 g
}
products {
1 kg bread
}
inputs {
1 kg flour
salt_amount salt
}
}
The above declaration will define a process that produces bread with salt_amount
of salt, with a
default value of 30 grams. When the bread
of this process is used as input somewhere else, if
you do not specify a value for salt_amount
, the default value will be used. This is in particular
the case if you directly run the inventory analysis for a process with parameters:
Item | Quantity | Unit | flour [kg] | salt [g] |
---|---|---|---|---|
bread from bake {salt_amount = 30 g} | 1 | kg | 1.0 | 30.0 |
If you want to change the value that salt_amount
takes when making a reference to process bake
,
you can do so by writing the value like so:
process produce_sandwich {
products {
5 u sandwich
}
inputs {
1 kg bread from bake (salt_amount = 20 g)
}
Upon running inventory analysis on the produce_sandwich
process, we can see that the requested
amount of salt has been taken into account:
Item | Quantity | Unit | flour [kg] | salt [g] |
---|---|---|---|---|
sandwich from produce_sandwich | 1 | u | 0.2 | 4.0 |
We can now re-use our bake
process for a zero-salt diet sandwich, without having to re-write or
copy/paste anything:
process produce_nosalt_sandwich {
products {
5 u sandwich
}
inputs {
1 kg bread from bake (salt_amount = 0 g)
}
}
From which we can obtain, as expected:
Item | Quantity | Unit | flour [kg] | salt [g] |
---|---|---|---|---|
sandwich from produce_sandwich | 1 | u | 0.2 | 0.0 |
A real-world example: electricity market process
One of the real-world applications of using parameters with processes is to define market processes, which can then be re-used with the appropriate parameters depending on the usage context. Here, we will showcase an electricity production market process based on energy mix parameters.
Base production processes
First, we define the base production processes for fossil, hydro- and wind production (assuming the substances used in resources and emissions are already defined, for clarity). Those three processes produce different types of electricity, require different resources and have different emissions.
process electricity_fossil_production {
products {
1 kWh electricity_fossil
}
inputs {
1E-12 p energy_plant
}
emissions {
1.2 kg carbon_dioxide_fossil( compartment = "air" )
}
resources {
1.2 MJ hard_coal( compartment = "ground", sub_compartment = "non-renewable" )
}
}
process electricity_hydro_production {
products {
1 kWh electricity_hydro
}
inputs {
1E-12 p energy_plant
}
resources {
3.8 MJ energy_hydro ( compartment = "water", sub_compartment = "renewable" )
}
}
process electricity_wind_production {
products {
1 kWh electricity_wind
}
inputs {
1E-12 p energy_plant
}
resources {
3.8 MJ energy_wind( compartment = "air", sub_compartment = "renewable" )
}
}
Market process
However, once produced, electricity is electricity and we do not want to write down once and for all the electricity-mix a factory uses, as this can evolve over time. Let us define a market process that mixes all three electricity types into one, with parameters defining the different proportions:
process electricity_production {
params {
from_hydro = 20 percent
from_wind = 10 percent
}
products {
1 kWh electricity
}
inputs {
from_hydro * 1 kWh electricity_hydro
from_wind * 1 kWh electricity_wind
( 100 percent - from_hydro - from_wind ) * 1 kWh electricity_fossil
}
}
When electricity
from this process is used elsewhere, the default values of 20% of hydro-produced
electricity, 10% of wind-produced electricity and 70% fossil-produced electricity will be used.
Using the market
We can then re-use the market process in different contexts, without having to redefine anything in the chain of emissions or resource usage:
// Renewable-only energy mix
process green_factory {
products {
1 p a_product
}
inputs {
10 kWh electricity from electricity_production ( from_hydro = 80 percent, from_wind = 20 percent)
}
}
// Default energy mix
process normal_factory {
products {
1 p a_product
}
inputs {
10 kWh electricity
}
}
And the results in the inventory analysis show, as expected, different results for each factory:
Item | Quantity | Unit | energy_plant [p] | [Resource] energy_hydro [MJ] | [Resource] energy_wind [MJ] | [Resource] hard_coal [MJ] | [Emission] carbon_dioxyde_fossil (air) [kg ] |
---|---|---|---|---|---|---|---|
a_product from green_factory{} | 1 | p | 1.0E-11 | -30.4 | -7.6 | 0.0 | 0.0 |
a_product from normal_factory{} | 1 | p | 1.0E-11 | -7.6 | -3.8 | -8.4 | 8.4 |
Notice that to guarantee that the mix always sums to 100%, we have defined the proportion of fossil-produced electricity in the market process using a formula : as long as dimensional analysis is consistent, you can write arbitrary mathematical expressions where quantities are expected.