LESSON 13: Creating local Submodels and using a Submodel in a Model


== Now that you have initial knowledges of Submodels on Dinamica EGO, we would like to demonstrate and explain how to create a Submodel and next we will learn how to use this Submodel created in a Model.

For this, using the model developed in the previous exercise, we will answer the following question: How is the productivity for each crop along the analyzed period?


Let's go! Select the functors of the Model that should be included in the Submodel:



With this selection active, Click on Edit tab and next on the Create a Submodel to convert all selected functor into a local Submodel:



In the Submodel Editor Window, insert a Submodel name (Calc Most Productive year) and define the input and output ports to this Submodel.



Now, our Submodel has been created:



We can use this Submodel in an independent model. For demonstrate this, grab a “Load Table Functor” and place it on the sketch. Double click the Load Table Functor and open the IBGE_crop_information_complete.csv file.

Grab a “Reorder Table Column” and place it on the sketch to switch the order of the year and crop key columns. Connect the Load Table to Reorder Table Column. In the Functor Editor window insert the index of the column to be moved (“1”) and the new column index, similarly to previous exercise.



Now, let's insert our previously created Submodel. First, click on the Submodels tab and from the library window grab a “Calc Most Productive year” Submodel and place it on the sketch. We want to calculate the most productive year for each crop; thus, we will use this Submodel 3 times, i.e. for the crops 1, 2 and 3.



Now you need to save the results to a file. Grab three “Save Table” functors, place it on the sketch and connect to each Submodel (For the three crops). Open Save Map Functors, browse to the Guidebook Dinamica_4/Models/Set_2/basics/6_submodel and write the name files (most_productive_year_for_crop_1.csv, most_productive_year_for_crop_2.csv, and most_productive_year_for_crop_3.csv).

The final model will look like this:





Mark the eye button at the top of “Save Table” to view the results hereafter.

Save and run the model!

Now, click on eye button of “Save Table” to see the result. These functors outputs are tables that looks like this:



What does this result say about the productivity for each crop along the analyzed period?
We can infer that 2009 was the most productive year for Crop 1 along the analyzed period, with a productivity of 80.25549 tons/ha. For the Crop 2, 2015 was the most productive year, with a productivity of 3.535804 tons/ha and 2011 was the most productive year for Crop 3, with a productivity of 3.121386 tons/ha.

Congratulations! You have successfully completed this lesson! Now let’s move to the next ones!