Grow the Simulation
In this tutorial, we grow our simulation through code, exploring how we might be able to save time by interacting with our simulations through this alternative interface.Contents
Motivation
In the previous tutorial, we revealed that we have been writing code all along. That said, there are some features of the engine which can only be accessed by writing code through the "Editor" tab such as probabilistic simulation. Sometimes, it may also be easier or faster to express your ideas through code than by building it up through the dialog boxes. All that in mind, we will now make some edits through code.
New Application
Create a new "dom refrig" application for domestic refrigeration. First, have it use "HFC-134a" with the following properties:
- Initial charge 0.25 kg / unit for domestic manufacture
- Initial charge 0.1 kg / unit for domestic manufacture
- Assume emissions 1000 tCO2e / kg
- A starting domestic manufacture level of 250 mt in year 1
- A starting import of 50 mt in year 1
- Increase manufacture by + 5% each year (the plus sign is optional)
- Increase import by + 4% each year
- 2% retired each year and 5% recharged each year with 0.05 kg / unit recharge
Next, create "R-600a" with the following properties:
- Initial charge 0.1 kg / unit for domestic manufacture
- Initial charge 0.1 kg / unit for domestic manufacture
- Assume emissions 50 tCO2e / kg
- 2% retired each year and 5% recharged each year
- A starting domestic manufacture level of 5 mt in year 1
- Increase sales by 5% each year
- A starting import of 2 mt in year 1
- 0.01 kg / unit recharge
Be sure to click "run" to execute again when you are done. Here is what that code may look like right before end default:
define application "Dom Refrig" uses substance "HFC-134a" initial charge with 0.25 kg / unit for manufacture initial charge with 0.1 kg / unit for import equals 1000 tCO2e / kg set manufacture to 250 mt during year 1 set import to 50 mt during year 1 change manufacture by 5 % each year change import by 4 % each year retire 2 % each year recharge 5 % each year with 0.5 kg / unit end substance uses substance "R-600a" initial charge with 0.1 kg / unit for manufacture initial charge with 0.1 kg / unit for import equals 50 tCO2e / kg set manufacture to 5 mt during year 1 set import to 5 mt during year 1 retire 2 % each year recharge 5 % each year with 0.01 kg / unit end substance end application end default
New Policies
Next, let's make some policies. Create the following for domestic refrigeration:
- Recover 30% with 100% reuse during years 2 to 20.
- Replace 15 mt each year of all sales with R-600a during years 2 to 20.
Once again, be sure to click "run" to execute again. Here is what that code may look like (right before start simulations):
start policy "Dom Recycling" modify application "Dom Refrig" modify substance "HFC-134a" recover 30 % with 100 % reuse during years 2 to onwards end substance end application end policy start policy "Dom Replace" modify application "Dom Refrig" modify substance "HFC-134a" replace 15 mt of sales with "R-600a" during years 2 to 20 end substance end application end policy start simulations
New Simulations
Finally, let's modify our simulations so that recycle and replacement have these new policies for domestic refrigeration. Note that policies are case sensitive. Here's what that might look like:
start simulations simulate "Business as Usual" from years 1 to 20 simulate "Recycle" using "Com Recycling" then "Dom Recyling" from years 1 to 20 simulate "Replacement" using "Com Replace" then "Dom Replace" from years 1 to 20 simulate "Permitting" using "Com Permit" from years 1 to 20 simulate "Combined" using "Com Recycling" then "Com Replace" then "Com Permit" then "Dom Recyling" then "Dom Replace" from years 1 to 20 end simulations
One last time, be sure to click run.
Conclusion
Sometimes it is easier to use code to express your idea. However, many simulations can be built either in the designer or code editor. Let's continue our journey by looking closer at the visualization tools available in the next tutorial.