diff --git a/tutorials/02-language-features/05-datasources/00-datasources.lca b/tutorials/02-language-features/05-datasources/00-datasources.lca new file mode 100644 index 00000000..4df1702c --- /dev/null +++ b/tutorials/02-language-features/05-datasources/00-datasources.lca @@ -0,0 +1,29 @@ +/* + A datasource is assumed to provide a sequence of records. + For now, only the local CSV file source is supported. +*/ + +datasource inventory { + /* + The location is relative to the path chosen when invoking the cli. + */ + location = "data/inventory.csv" + + /* + The schema is defined using default values. Note that the unit of + the default value will be the one chosen for the entire column. + */ + schema { + quantity = 1 p + ram_size = 16 GB + storage_size = 1 TB + amortization_period = 5 year + power = 400 W + ram_allocation = 75 percent + storage_allocation = 25 percent + + // embodied impact + GWP = 0 kg_CO2_Eq + WU = 0 m3 + } +} diff --git a/tutorials/02-language-features/05-datasources/01-lookup.lca b/tutorials/02-language-features/05-datasources/01-lookup.lca new file mode 100644 index 00000000..659353b5 --- /dev/null +++ b/tutorials/02-language-features/05-datasources/01-lookup.lca @@ -0,0 +1,42 @@ +/* + Lookup primitive +*/ + +process my_lookup { + products { + 1 p material + } + variables { + /* + The lookup primitive fetches exactly one record matching + the given condition. Here, the chosen row is the one whose + value in the column 'id' equals the value "small". + + If no record or more than one record is found, an error + is thrown. + */ + row = lookup inventory match id = "small" + + /* + Individual entries of the record are accessed using + the dot syntax. Their dimensions is specified by + the data source schema. + */ + + quantity = row.quantity + GWP = row.GWP + } + + impacts { + quantity * GWP GWP + } +} + +test my_lookup { + given { + 1 p material from my_lookup + } + assert { + GWP between 38 p * 2800 kg_CO2_Eq and 38 p * 2900 kg_CO2_Eq + } +} diff --git a/tutorials/02-language-features/05-datasources/main.lca b/tutorials/02-language-features/05-datasources/02-for-each.lca similarity index 71% rename from tutorials/02-language-features/05-datasources/main.lca rename to tutorials/02-language-features/05-datasources/02-for-each.lca index b1cf492b..deb39922 100644 --- a/tutorials/02-language-features/05-datasources/main.lca +++ b/tutorials/02-language-features/05-datasources/02-for-each.lca @@ -1,29 +1,3 @@ -/* - A datasource is assumed to provide a sequence of records. - For now, only the local CSV file source is supported. -*/ -datasource inventory { - location = "inventory.csv" - - /* - The schema is defined using default values. Note that the unit of - the default value will be the one chosen for the entire column. - */ - schema { - quantity = 1 p - ram_size = 16 GB - storage_size = 1 TB - amortization_period = 5 year - power = 400 W - ram_allocation = 75 percent - storage_allocation = 25 percent - - // embodied impact - GWP = 0 kg_CO2_Eq - WU = 0 m3 - } -} - /* Block 'for_each' */ @@ -78,7 +52,7 @@ process pool_server { inputs { for_each row from inventory { // record variable can be fed to the process invoked. - row .quantity server from server(row = row) + row.quantity server from server(row = row) } } } diff --git a/tutorials/02-language-features/05-datasources/inventory.csv b/tutorials/02-language-features/05-datasources/data/inventory.csv similarity index 100% rename from tutorials/02-language-features/05-datasources/inventory.csv rename to tutorials/02-language-features/05-datasources/data/inventory.csv diff --git a/tutorials/03-advanced/01-relational-modeling/datasources.lca b/tutorials/03-advanced/01-relational-modeling/00-datasources.lca similarity index 100% rename from tutorials/03-advanced/01-relational-modeling/datasources.lca rename to tutorials/03-advanced/01-relational-modeling/00-datasources.lca diff --git a/tutorials/03-advanced/01-relational-modeling/01-main.lca b/tutorials/03-advanced/01-relational-modeling/01-main.lca new file mode 100644 index 00000000..116777c5 --- /dev/null +++ b/tutorials/03-advanced/01-relational-modeling/01-main.lca @@ -0,0 +1,59 @@ +process datacenter { + params { + id = "dc-zone-01" + } + variables { + dc = lookup datacenters match id = id + total = dc.reserved_power * dc.amortization_period + } + products { + total energy + } + inputs { + // include electricity from the relevant geographic zone + total electricity from electricity_mix(geo = dc.geo) + + // include all components belonging to the given datacenter + for_each row from datacenter_components match datacenter_id = dc .id { + + // pass the component parameters + 1 p component from datacenter_component(dc_component = row) + } + } +} + +process datacenter_component { + params { + dc_component from datacenter_components + } + products { + 1 p component + } + impacts { + dc_component.GWP GWP + } +} + +process electricity_mix { + params { + geo = "GLO" + } + variables { + mix = lookup electricity_mixes match geo = geo + } + products { + 1 kWh electricity + } + impacts { + mix.GWP GWP + } +} + +test datacenter { + given { + 1 kWh energy from datacenter(id = "dc-zone-01") + } + assert { + GWP between 70 g_CO2_Eq and 75 g_CO2_Eq + } +} diff --git a/tutorials/03-advanced/01-relational-modeling/main.lca b/tutorials/03-advanced/01-relational-modeling/main.lca deleted file mode 100644 index 2caa1c66..00000000 --- a/tutorials/03-advanced/01-relational-modeling/main.lca +++ /dev/null @@ -1,59 +0,0 @@ -process main { - params { - id = "dc-zone-01" - } - products { - 1 p main - } - inputs { - for_each dc from datacenters match id = id { - 1 kWh energy from datacenter(dc = dc) - } - } -} - -process datacenter { - params { - dc from datacenters - } - variables { - total = dc.reserved_power * dc.amortization_period - } - products { - total energy - } - inputs { - for_each row from datacenter_components match datacenter_id = dc .id { - 1 p component from datacenter_component(dc_component = row) - } - - for_each mix from electricity_mixes match geo = dc .geo { - total electricity from electricity_mix(mix = mix) - } - } -} - -process datacenter_component { - params { - dc_component from datacenter_components - } - products { - 1 p component - } - impacts { - dc_component .GWP GWP - } -} - -process electricity_mix { - params { - mix from electricity_mixes - } - products { - 1 kWh electricity - } - impacts { - mix.GWP GWP - } -} - diff --git a/tutorials/03-advanced/01-relational-modeling/units.lca b/tutorials/03-advanced/01-relational-modeling/units.lca index cc39f6a0..703c3229 100644 --- a/tutorials/03-advanced/01-relational-modeling/units.lca +++ b/tutorials/03-advanced/01-relational-modeling/units.lca @@ -1,3 +1,8 @@ +unit g_CO2_Eq { + symbol = "g_CO2_Eq" + alias_for = 1e-3 kg_CO2_Eq +} + unit ton_CO2_Eq { symbol = "ton_CO2_Eq" alias_for = 1000 kg_CO2_Eq diff --git a/tutorials/03-advanced/02-circular-footprint-formula/01-main.lca b/tutorials/03-advanced/02-circular-footprint-formula/01-main.lca index 9bc48f3b..a92e0c1b 100644 --- a/tutorials/03-advanced/02-circular-footprint-formula/01-main.lca +++ b/tutorials/03-advanced/02-circular-footprint-formula/01-main.lca @@ -12,3 +12,11 @@ process cff { } } +test cff { + given { + 1 kg material from cff + } + assert { + GWP between 1.38 kg_CO2_Eq and 1.4 kg_CO2_Eq + } +} diff --git a/tutorials/03-advanced/02-circular-footprint-formula/03-end_of_life.lca b/tutorials/03-advanced/02-circular-footprint-formula/03-end_of_life.lca index 355103a3..883ba03f 100644 --- a/tutorials/03-advanced/02-circular-footprint-formula/03-end_of_life.lca +++ b/tutorials/03-advanced/02-circular-footprint-formula/03-end_of_life.lca @@ -9,23 +9,23 @@ process end_of_life { variables { mat_params = lookup material_params match id = id - ErecyclingEol_id = mat_params .ErecyclingEol_id - EstarV_id = mat_params .EstarV_id - Eer_id = mat_params .Eer_id - Ed_id = mat_params .Ed_id + ErecyclingEol_id = mat_params.ErecyclingEol_id + EstarV_id = mat_params.EstarV_id + Eer_id = mat_params.Eer_id + Ed_id = mat_params.Ed_id A = mat_params.A B = mat_params.B Q_out = mat_params.Q_out R2_data = lookup R2_data match ( geo = geo, id = id ) - R2 = R2_data .R2 + R2 = R2_data.R2 - R3 = mat_params .R3 + R3 = mat_params.R3 - LHV = mat_params .LHV - Xer_heat = mat_params .Xer_heat - Xer_elec = mat_params .Xer_elec + LHV = mat_params.LHV + Xer_heat = mat_params.Xer_heat + Xer_elec = mat_params.Xer_elec } inputs { diff --git a/tutorials/run.sh b/tutorials/run.sh index 970cbe0d..a8c15bbd 100755 --- a/tutorials/run.sh +++ b/tutorials/run.sh @@ -23,16 +23,19 @@ fi lcaac test -p $TUTORIALS_PATH/01-basics/01-getting-started lcaac test -p $TUTORIALS_PATH/01-basics/02-biosphere lcaac test -p $TUTORIALS_PATH/01-basics/03-impacts + lcaac test -p $TUTORIALS_PATH/02-language-features/01-parametrized-process lcaac test -p $TUTORIALS_PATH/02-language-features/02-variables lcaac test -p $TUTORIALS_PATH/02-language-features/03-units lcaac test -p $TUTORIALS_PATH/02-language-features/04-labels lcaac test -p $TUTORIALS_PATH/02-language-features/05-datasources +lcaac test -p $TUTORIALS_PATH/03-advanced/01-relational-modeling +lcaac test -p $TUTORIALS_PATH/03-advanced/02-circular-footprint-formula + # Check custom dimensions tutorial set -euo - # The following assessment is expected to fail. if lcaac assess -p $TUTORIALS_PATH/02-language-features/03-units customer; then exit 0 -fi +fi 2> /dev/null