Chapter 1. Crop model building and simulation in Microsoft Excel: Introducing BuildIt 1.1 Spreadsheets for mathematical modeling Mathematical modeling often incurs a steep learning curve to many agriculturists. This is partly because one of the stages in the modeling process involves computer programming, a skill many agriculturists lack. Consequently, many agriculturists struggle to translate their formulated models into a set of instructions that can be implemented by a computer system. For them, computer programming often degenerates into a tedious and distracting undertaking. This problem has been recognized even as early as three decades ago when Hillel (1977) commented that agriculturists, being novice programmers, are easily entangled in the complexities of translating their model into a computer source code. Rather than focusing on the important—and intended—task of mathematical modeling and simulation, they instead become distracted by the intricacies and mechanism of computer programming. What is required then is some special software that allows non-programmers to build their own computer models. This will enable non-programmers, agriculturists included, to accomplish their modeling tasks directly and quickly and without the distraction of having to learn a new computer language (or to master a new simulation application). There are generally four categories of software platforms to aid in model building and simulation. They are: 1) general purpose computer languages (e.g., C, C++, FORTRAN, BASIC, Pascal and Java); 2) specialized simulation applications (e.g., FST, PowerSim, Stella and ExtendSim); 3) equation solver-based applications (e.g., Maple, Mathematica and Mathlab); and 4) spreadsheet-based applications (e.g., Microsoft Excel and OpenOffice.org Calc)1. Of these four groups of software platforms, spreadsheet applications require the least level of proficiency in computer programming. It is no surprise then that spreadsheets have been advocated by several workers (e.g., Seila, 2005; Brown, 1999; Nardi and Miller, 1990) as a suitable platform, especially for non-programmers, to build and simulate their models. Spreadsheets are immensely popular and widely used because they are easy to use and versatile. Additionally, they provide the following features (adapted from Seila, 2005): 1) a large number of numerical and non-numerical functions (i.e., dedicated formulas) to do mathematical, statistical, database, date and time, financial, engineering and other types of calculations; 2) database representations and access; 3) charting and graphing; 4) display and document formatting capabilities such as layout, fonts and colors to improve presentation; and 5) scripting or programming language such as 1 FST (Fortran Simulation Translator) is available upon request from its developers (see van Kraalingen et al., 2003); Powersim is a registered trademark of Powersim Software AS; Stella is a registered trademark of isee systems; ExtendSim is a registered trademark of Imagine That Inc.; Maple is a registered trademark of Waterloo Maple Inc.; Mathematica is a registered trademark of Wolfram Research Inc.; Mathlab is a registered trademark of The MathWorks Inc.; Microsoft Excel are registered trademarks of Microsoft Corporation; OpenOffice.org Calc is a registered trademark of OpenOffice.org 1 VBA (Visual Basic for Applications) in Excel and OOoBasic (OpenOffice.org Basic) in OpenOffice.org Calc. Spreadsheets were initially conceived as electronic accounting books for financial analysis, but today, spreadsheets have progressed beyond their original intent. They have become powerful tools to manipulate, analyze and present data, and to build models for simulating various phenomena in science and engineering (Khandan, 2001). 1.2 Advantages and disadvantages of spreadsheets It is well known that spreadsheets are easy to use, versatile and powerful, but it is not so much these characteristics that qualify spreadsheets as a suitable modeling platform for non-programmers. The first key benefit of using spreadsheets in modeling is that they do not require users to be proficient in computer programming. This is achieved by the spreadsheet system providing: 1) automatic control and maintenance of the program flow; 2) a simple, straightforward modeling framework; and 3) high-level and taskspecific functions (Nardi and Miller, 1990). A spreadsheet is a group of pages, or worksheets, where each worksheet is a two-dimensional table consisting of rows and columns of cells. Each cell can contain either a constant or a calculated value, derived from a function or formula. The open tabular format of the spreadsheet provides users a simple, straightforward framework in which to build their models. As such, spreadsheet users only need to understand two basic concepts: to treat the cells as variables and the functions (or formulas) as the relationship between these variables. Users specify the way variables depend on each other via formulas or functions, and the spreadsheet system maintains these variable dependencies. So if one part of the spreadsheet changes, it triggers an update to the whole spreadsheet so that all the dependent variables are automatically recalculated to reflect their new values—giving users immediate feedback. The order in which the variables are calculated is worked out by the spreadsheet system based on the variable dependencies. Users cannot contravene this calculation sequence by giving the spreadsheet system a different calculation or action sequence to be performed. Though this might seem restrictive, it is actually this feature, among others, that makes spreadsheets appealing to non-programmers. Spreadsheets not only relieve users from having to maintain the program flow themselves, but also from having to design their own modeling framework. Flow control and framework design are both difficult programming concepts for nonprogrammers to master (Nardi and Miller, 1990; Hoc, 1989; Lewis and Olson, 1987; Soloway et al., 1983). Without automatic flow control, users will have to write their own programming code to track variable dependencies and to update all effected variables iteratively when required. And users need not design their own modeling framework because the spreadsheet already provides users with one. Spreadsheets further cater to non-programmers by providing high-level and task-specific functions, meaning that these functions can be used without users having to understand how they work or to require computer programming expertise. One commonly used function in Excel, for example, is the SUM function that, as its names implies, calculates the total of a set of given values. Spreadsheet users merely write the SUM function and specify all the cells that contain the values to be added. Without such a high-level function, users will require to write a loop to iterate through the elements in an array, summing each element and accumulating the total. Other 2 routinely used functions are such as AVERAGE (for calculating the mean of values), MIN and MAX (for determining the smallest and largest value, respectively, from a given set of values), VLOOKUP and HLOOKUP (for looking up a value from a vertically and horizontally tabulated data, respectively), IF (for conditional computations), and trigonometric functions like SIN and COS. These are only a few of the functions listed; hundreds more functions are available in Excel (as well as in other spreadsheets) to support users’ requirements. The second key benefit of using spreadsheets is its table-oriented interface. It provides a strong visual format to manipulate, organize and present data as well as a problem-solving tool (Nardi and Miller, 1990). The spreadsheet’s open tabular format allows direct access to the variables’ values. This is in contrast to traditional programming efforts which require some special and intentionally constructed mechanisms for the input and output of variables. Brown (1999) additionally noted that because the values of all variables are always updated and displayed in the table, this could help to detect the location of errors during model construction by the presence of nonsensical or questionable values. The spreadsheet’s tabular format additionally allows users to organize visually their model into subparts or modules, where each module performs a specific task to solve an overall, larger problem. This organization can be done by segmenting the large model into smaller modules by, for instance, leaving an empty row between each module or by placing each module in a separate worksheet. Formatting the module sections such as by applying different fonts, shading, style layout or colors further help in code organization. Consequently, the model’s code is distributed visually over one or more grids in such a way that makes the model more comprehensible and maintainable. Visual code organization is not merely for aesthetic reasons. The very act of laying out data, organizing and formatting the code provide an important visual feedback mechanism that helps to organize users’ thoughts and shape their problem solving process (Nardi and Miller, 1990). Spreadsheets, however, have several important limitations. Spreadsheet models can be difficult to understand when studied by others. As mentioned previously, the modeling framework provided by spreadsheets is a simple, straightforward structure, essentially consisting of variables (cells) and their linkages with each other (formulas). But as models increase in complexity, these variable linkages can grow into an intricate network of relationships. Since the spreadsheet system maintains the program flow and shields users from viewing this network of relationships, it can be difficult for other users (even for the model developers themselves) to grasp the computations as a whole. This causes difficulty not only in understanding the model but also in debugging it (that is, to locate and correct the errors in the model). Spreadsheets offer to non-programmers a modeling platform that is almost unrestrictive and freeform and with little validation checks. While this feature can be convenient for those who wish to develop their models easily and quickly, it does, however, make it easy for users to introduce errors unwittingly into their models. Errors in large spreadsheet models, in particular, can be difficult to locate and, at times, be undetected. It is well known in the business sector that the frequency of errors in their spreadsheets are alarmingly high. Rajalingham et al. (2001) reported that as much as 90% of real-world spreadsheets contained errors. Furthermore, the European Spreadsheet Risks Interest Group (www.eusprig.org) lists nearly a hundred 3 examples of newsworthy incidences where spreadsheets errors caused companies either financial losses, incorrect forecasting, or simply, embarrassment. Although spreadsheets from the business sector are often cited as examples of high occurrence of errors, we cannot disregard the possibility that spreadsheets from other disciplines (such as agriculture) are too plagued by errors. The simple modeling framework provided by the spreadsheet also makes spreadsheet models difficult to reuse and extend. Reusability and extendibility are two software engineering concepts related to ways to increase the usefulness, applicability and lifespan of software. A modeling framework that adheres to these two concepts means that, ideally, the framework is flexible and adaptable enough for algorithm modification, substitution and addition. In some ways, reusability and extendibility are analogous to the “plug-and-play” feature in modern computer systems. For instance, adding, replacing or removing a computer peripheral (such as a printer, scanner or mouse) should be a seamless operation that does not disrupt a computer system or cause it to malfunction. In a similar way, a reusable and extendible model means that one or more parts in the model can be modified easily or even substituted with other parts from another model. It also means that additional features or functions can be added to the model. All these operations can occur without having to break or redesign the existing modeling framework. There are several examples in agriculture of modeling frameworks developed with concerns of achieving reusability and extendibility (e.g., Papajorgji and Pardalos, 2006; Papajorgji et al., 2004; Hillyer et al., 2003; Caldwell and Fernandez, 1998; Acock and Reddy, 1997). Nevertheless, until today, none of them has yet to be adopted widely by agriculturists. One could speculate that these framework designs are still not sufficiently adaptable and flexible enough to cope with the unpredictable and transient requirements of agricultural models. Or it may simply be that agriculturists do not have the interest or time to learn about reusability and extendibility, both concepts of software engineering, not agriculture. Consequently, for many agriculturists, the problem that spreadsheet models are difficult to reuse and extend may actually be an unimportant concern in their work. Spreadsheets have other limitations that are particularly relevant for models with complex data structures and algorithms (Seila, 2005). A spreadsheet is a twodimensional table of cells, and while this format is adequate in most cases, it is a limitation when more elaborate data structures are required such as lists and trees. Although spreadsheets can be coerced to handle such complex data structures, the way they are achieved in spreadsheets can be inefficient and convoluted. Complex algorithms can be particularly difficult to implement in a spreadsheet. Spreadsheets lack explicit loop and conditional controls commonly found in general purpose languages. Spreadsheets actually have a conditional construct IF-THEN-ELSE but its effect is only local to the cell that contains the construct. The construct cannot be used to change the values in other cells or to transfer control to another cell or to another part of the spreadsheet. As stated earlier, spreadsheets relieve users from having to maintain the control flow themselves. While this is a convenient feature for nonprogrammers, it becomes a severe limitation when an algorithm requires users to specify explicitly the sequence of actions to be performed. Spreadsheets like Excel and OpenOffice.org Calc have their own scripting language that can be used to circumvent this problem, but they require proficiency in computer programming. But non-programmers may find this solution unappealing because their use of spreadsheets is precisely to avoid computer programming in the first place. 4 Lastly, spreadsheet models often run slower than models developed in other software platforms. This is partly because models developed in other platforms, such as in C, C++ or FORTRAN, are compiled (translated) into fast machine code that is in a format directly executable by the computer. In contrast, no such compilation occurs for spreadsheet models. The formulas in spreadsheets are instead interpreted first before execution. This slows down program execution. Dalton (2005) roughly estimated that models written in Excel could be slower by as much as five to twenty times than if they were written in C and C++ computer languages. He further reported that Excel’s text-manipulation routines are very much slower than the same routines in C and C++ by as much as over 300 times. Slow execution speeds may not be noticeable for simple spreadsheet models, but for larger, more complex models (due to their more numerous and intricate calculations), their execution speeds can be noticeably sluggish and become a significant constraint. For non-programmers, spreadsheets offer an infrastructure that appeals to them because spreadsheets allow them to build fully functioning models quickly and directly, and without the pre-requisite knowledge in any advance programming concepts and techniques. But for those with programming expertise, the limitations of spreadsheets can be significant reasons why spreadsheets are not used as their modeling platform. In some cases, spreadsheets are merely used as a quick test bed to test their modeling ideas or to develop model prototypes. Once these ideas or model prototypes have been assessed sufficiently, model development then shifts to other software platforms for completion. 1.3 How to use BuildIt BuildIt is an addin that works within Excel to support model building and simulation in Excel. It is important to realize that BuildIt is neither a crop model nor a “toolbox” of useful equations. The primary purpose of BuildIt is to overcome some limitations in Excel by providing a framework in particular for non-programmers to build their models, especially those that are large and complex and those that have iterative calculations. Crop models, for instance, are often large and complex because they comprise several interrelated components such as meteorology, water and energy balance, and plant photosynthesis and respiration. Crop models also often involve iterative calculations, where the same set of calculations are repeated over and over to simulate the dynamics of plant growth and its environmental conditions. 1.3.1 Installing BuildIt BuildIt can be obtained free from: www.agri.upm.edu.my/~chris/buildit. Download the archive file buildit.zip. The archive contains two file versions for BuildIt: one that works in Excel 2003 (buildit.xla) and another for Excel 2007 (buildit.xlam). Excel 2003 Extract the buildit.xla file and save it a folder in your computer. You can save the buildit.xla in any folder, but by default, Excel addins are saved in several locations, one of which is in the folder Documents and Settings/user name/Application Data/Microsoft/AddIns where user name is your user name for your computer. 5 To use BuildIt, you need to load it in Excel. Start up Excel, and from the main menu, choose Tools|Add-ins. You will see a dialog box, listing all available addins (Fig. 1.1). If you do not see BuildIt’s name in the list, click the Browse button to search for the file buildit.xla. Once located, click OK and the BuildIt’s name should be listed in the dialog box. Check (tick) the box next to BuildIt’s name and dismiss the dialog box by clicking the OK button. Once loaded, BuildIt will install its own menu on the main menu bar (Fig. 1.2). BuildIt is now loaded in Excel and ready for use each time you start up Excel. Fig. 1.1. Load BuildIt by ticking its checkbox and clicking the OK button. Note that the list of available addins will differ from one computer system to another. Fig. 1.2. BuildIt menu in Excel 2003 Excel 2007 Extract the buildit.xlam file and save it a folder in your computer. You can save the buildit.xlam in any folder, but by default, Excel addins are saved in several locations, one of which is in the folder Documents and Settings/user name/Application Data/Microsoft/AddIns where user name is your user name for your computer. 6 To load BuildIt in Excel2007, first click the Microsoft Office Button , and then click Excel Options. Click the Add-Ins category. In the Manage box, click Excel Add-ins, and then click Go (Fig. 1.3). To load BuildIt, select the check box next to BuildIt’s name in the Add-Ins available box (Fig. 1.1). If you do not see BuildIt’s name in the list, click the Browse button to search for the file buildit.xlam. Once located, click OK and the BuildIt’s name should be listed in the dialog box. Dismiss the dialog box by clicking OK button. Once loaded, BuildIt will install its own ribbon (Fig. 1.4). BuildIt is now loaded in Excel and ready for use each time you start up Excel. BuildIt commands Fig. 1.2 and 1.4 show that there are four commands in the BuildIt menu: 1. Reset model: Performs the operations in the Prerun section. It also sets _step to 0. 2. Do operations only: Performs the operations in the Operation section. 3. Start simulation: Runs the model. 4. About BuildIt: Displays program information. Unloading and uninstalling BuildIt BuildIt can be unloaded from Excel by merely removing the check mark from the list of available Add-Ins (Fig. 1.1). If you wish to uninstall (remove completely) BuildIt, first unload it from Excel as previously described, then simply delete the BuildIt file from your computer. Fig. 1.3. Available addins in Excel 2007 7 Fig. 1.4. BuildIt ribbon in Excel 2007 1.3.2 BuildIt’s framework and functions Fig. 1.5 shows BuildIt’s framework and program flow in Excel. When simulation begins, BuildIt checks the Option section. A section is a range of cells in the spreadsheet (workbook) that lists one or more operations to be executed by BuildIt. We create a section by defining a chosen cell with a specific name, and this cell becomes the start of that section. The Option section, for example, is created when we define the name _option to one of the worksheet cells in our workbook. At this point, you may wonder what exactly is an operation and how they are specified for BuildIt. These will be explained later, but for the moment, just know that an operation is some specific task to be performed by BuildIt in our spreadsheet. In a given section, we list the operations in the order (from top to bottom) we want them to be executed by BuildIt. So if we want operation A to be executed before B and C, we then list operation A, B then C in that order. So the Option section is one portion in your worksheet that lists all the operations you want to be done at the beginning of a simulation run. We see from Fig. 1.5 that the operations in the Option section are only done once for each simulation run. The Option section is optional; that is, if we do not define the name _option then BuildIt proceeds into the outer loop. As indicated by the dashed boxes in Fig. 1.5, there are two loops in BuildIt’s program flow: the outer and inner loops. The outer loop controls the scenario runs. Every simulation run has at least one scenario. As an example, let us take a trivial equation for a model: y mx c 8 where m is the slope of the line and c is the intercept on the y-axis. We fix c as 0 and m as 1. We wish to simulate (or calculate, in this case) the values for y for x = 0, 1, 2, 3, …, 10. This is our only scenario so BuildIt runs our simple model, calculates and outputs the results, and simulation ends. The outer loop runs once since we have only one scenario. Fig. 1.5. Framework and program flow for BuildIt Let us say that we are also interested to determine how y varies with x with m = 2 and c = 1. This is in addition to the earlier values of m = 1 and c = 0. We can of course run the model twice: once for m = 1 and c = 0 and then for m = 2 and c = 1. 9 BuildIt, however, provides the support where we can run these two scenarios (or more) in a single simulation run. We define one of the worksheet cells with the name _scenario to denote the start of the Scenario section and to instruct BuildIt that there is more than one scenario in the simulation run. In this example, BuildIt runs the model for m = 1 and c = 0 first, then for m = 2 and c = 1, giving two output listings, one for each scenario. Again, how we specify the instructions for running two or more scenarios will be discussed later. Unlike the optional names _option and _scenario, it is compulsory that we define one of the worksheet cells with the name _step. This is because BuildIt always sets the _step variable to 0 in the beginning of the outer loop (Fig. 1.5). _step can be regarded like an iteration counter for the inner loop, but before BuildIt proceeds into the inner loop, it checks for the Prerun section. This section is created when we define one of the worksheet cells with the name _prerun. Though this section is optional, it usually required to initialize any model parameters. In other words, one of the uses of the Prerun section is to instruct BuildIt which are the model parameters to be initialized and what values to give them. The inner loop forms the hub of the calculations. Together with _step, we must also define the names _stepsize and _criteria. The name _criteria states the logical condition to which to end the cyclical calculations in the inner loop. As long as _criteria is TRUE, the iteration in the inner loop continues until _criteria becomes FALSE, after which BuildIt exits into the outer loop. Two key activities occur in the inner loop. The first is model output, and the second is the execution of BuildIt operations listed in the Operation section. This section is created by defining the name _operation to one the worksheet cells. Though the Operation section is optional, this section is often crucial to allow certain calculations in the model to occur. As indicated in Fig. 1.5, there are two points for model output: one before the operations in the Operation section are executed, and another point after their executions. There are two points for model output because the values of some variables will be changed after the operations in the Operation section. Therefore, their values before and after these operations will be different. The output of model simulation results require that we define the names _read and _write. A cell defined with the name _read is where we specify which variables are to be saved in the model output and whether they should be saved before or after the operations from the Operation section are executed. Complementing _read, is _write which specifies the starting cell where the model output should be stored. Every iteration cycle in the inner loop ends by incrementing _step by _stepsize, where _stepsize is the interval between two iteration steps. The logical condition of _criteria is checked to determine if the next iteration cycle should continue or stop. When BuildIt exits into the outer loop, all operations, if any, in the Postrun section (starts with the cell defined with _postrun) are executed. In most cases, however, there is seldom a need for the Postrun section. BuildIt then checks if there is any more modeling scenarios. If there is, BuildIt changes some values or formulas as instructed in the Scenario section (recall that it is the cell defined with _scenario), _step is reset to 0 again, and as before, all the 10 model parameters will be initialized as instructed in the Prerun section. This whole process, as discussed above, repeats until all scenarios have been exhausted. Because calculations can be lengthy, BuildIt provides a feature where calculations can be aborted. Pressing the Escape key or Control-C keys will abort the simulation run. At times, these keys have to be pressed repeatedly because Excel may ignore key presses during intensive processes or calculations. Table 1.1 summarizes the names recognized by BuildIt and their brief description. All names recognized by BuildIt start with an underscore. Table 1.1. List of cell names recognized by BuildIt. Mandatory names are those that must be defined. Name Description _step Iteration step (mandatory) _stepsize Interval between each iteration step (mandatory) _criteria Condition for ending the iteration in the inner loop (mandatory) _read Location for specifying model variables that are to be saved _write Location for saving the model simulation results _operation Indicates the start of the Operation section _prerun Indicates the start of the Prerun section _postrun Indicates the start of the Postrun section _scenario Indicates the start of the Scenario section _option Indicates the start of the Model Option section The following describes BuildIt’s various operations. They are better understood when we later see how they can be used in several examples. Nonetheless, they are listed below in one place as reference. ITG operation ITG (x, func, output, lower, upper, single_integral) Integrates the function func of x over the interval [lower, upper], and the result of the integration is to be stored in the output cell. ITG for single integrations can be represented as: upper output func( x)dx lower ITG’s last argument, single_integral is either TRUE for single integrations or FALSE for multiple integrations (e.g., double or triple integrations). The argument single_integral can be omitted and will be assumed TRUE by default. INI operation INI (destination, source) 11 Copies the contents from the source cells to the cells being referred to in the destination cells. This operation is used primarily for setting initial values to variables. REP operation REP (destination, source, num_of_replacements) Copies the contents from source cells to the cells being referred to in the cells as many as num_of_replacements times. destination ACC operation ACC (x, accumulated_x, operator) Sums or multiplies a series of numbers, depending on whether operator is either + or * for addition or multiplication, respectively. If the operator is addition (+), ACC sums the numbers: accumulated_x xi i But if the operator is multiplication (*), ACC multiplies the numbers: accumulated_x xi i RUN operation RUN macro_name Executes the macro macro_name. Macros can be a simple sequence of recorded key strokes or actions to be done, or they can be quite sophisticated, requiring programming proficiency in Visual Basic for Applications (VBA). Developing macros, however, is beyond the subject of this book. BuildIt, however, supplies three utility macros: 1. ClearOutput Deletes the previous model output 2. DisableScreenUpdate Switches off the automatic screen update 3. EnableScreenUpdate Switches on the automatic screen update The first macro, ClearOutput, is useful to clear the previous model output. Model simulations are often run many times, with each run producing its own output result. Consequently, in the Output section, you may have an overlap of the latest and old model output. This macro is often used in the Option section so that before a simulation begins, the old output is cleared entirely. The following is one way to use this macro: Row 1 2 Col. J OPTION run Col. K clearoutput The Option section begins at cell J2 (defined with the name _option). Cell J2 specifies to run a macro whose name is specified in cell K2. Notice that the macro name is case-insensitive. The other two macros, DisableScreenUpdate and EnableScreenUpdate, concern the computer screen refresh. Turning off the screen update speeds up the 12 simulation run because Excel will not refresh the cells values. In other words, the computer screen appears “frozen”. Though appearing to be stalled, the simulation is still running and cells are still being updated but the computer screen does not refresh to view their new updated values. Turning on the screen update will then “unfreeze” the screen and all cells that are visible on the screen will have their correct and current values. These two macros are useful in particular for models which have intensive and lengthy calculations. DisableScreenUpdate is often used in the Option section so that the screen update is disabled before the lengthy calculations begin. Below is one way it can be specified: Row 1 2 Col. J OPTION run Col. K disablescreenupdate This macro can also be used before a lengthy operation. The screen update is disabled before a lengthy operation and reenabled after the operation completes. Consider the following entries in the Operation section (with cell J2 defined with the name _operation): Row 1 2 3 4 Col. I OPERATION off screen update lengthy REP op. on screen update Col. J Col. K Col. L Col. M run rep run disablescreenupdate =D3:H3 enablescreenupdate =D4:H4 1000 Cells J3 to M3 specify that the contents in the range of cells D4 to H4 are to be copied to cells D3 to H3 as many as 1000 times. This can be a lengthy operation because each time cells D4:H4 are copied to cells D3:H3, it triggers an update involving possibly lengthy and intensive calculations throughout the spreadsheet. Do this 1000 times and simulation speed can be very slow. To speed up the simulation run, the screen update is disabled (cells J2 and K2) before the REP operation in cells J3 to M3. When the REP operation completes, the screen update is reenabled in cells J4 and K4. You do not have to worry about forgetting to reenable the screen update after disabling it because BuildIt always ensures that the screen update is enabled before a simulation ends or even when a simulation run is aborted (such as by pressing the Esc or Control-C keys). Lastly, BuildIt supplies one custom function and it is for linear interpolation. Interpolate function This function is called interpolate and it has the following specification: interpolate (array_x, array_y, find_x) Based on an array of given (x, y) values, the interpolate function returns y corresponding to the given find_x. If no exact match is found, this function performs a linear interpolation to obtain y. It is important to remember that array_x must be sorted ascendingly (from smallest to largest value) before this function can be used reliably. Consider the following data set in Fig. 1.6 where the interpolate function is used to lookup several values. 13 Fig. 1.6. Data table to demonstrate the use of BuildIt’s interpolate function Based on the tabulated data in Fig. 1.6: interpolate(A2:A10, B2:B10, 2) returns 20 interpolate(A2:A10, B2:B10, 3) returns 35 interpolate(A2:A10, B2:B10, 20) returns #VALUE! The first case returns the exact y value of 20 because an exact match was found. The second case fails to find an exact match, so this function linear interpolates between (2, 20) and (4, 50) to give 35. The last case returns an error value because find_x lies beyond the range of array_x. Let us now consider several examples to better understand how BuildIt can be used to build models. 1.3.3 Example 1: Leaf photosynthesis As given by Goudriaan and van Laar (1994), leaf photosynthesis can be described by the following equation: AL Am kI 0 exp kL Am kI 0 exp kL (1.1) where AL is the leaf photosynthesis (that is, the assimilation rate of CO 2 by single leaves; g CO2 m-2 leaf area s-1); Am is the maximum leaf photosynthesis rate (g CO2 m-2 leaf area s-1); is the solar radiation conversion factor (g CO2 J-1); k is the canopy extinction coefficient for solar radiation (unitless); I0 is the solar irradiance above canopy (W m-2 ground area or J m-2 ground area s-1); and L is the cumulative leaf area index from the canopy top to the canopy depth being considered (m2 leaf area m-2 ground area). In this example, we wish to determine how AL varies with L, with L increasing from 0 to 10 m2 m-2. For this task, let us take Am as 1500 g CO2 m-2 s-1; k as 0.5; I0 as 200 W m-2; and as 12 g CO2 J-1. All these equation variables are treated as constants except for L which we will vary from 0 to 10 with an interval of, say, 0.5. 14 Begin by creating an Excel workbook and save it as Ex1. Rename one of the worksheets as LeafPhotosyn. This is the worksheet where we will build Eq. (1.1). Enter the following in the LeafPhotosyn worksheet: Row 7 8 9 10 11 Col A PARAMETERS Am k Io quantum Col. B Cell name 1500 0.5 200 12 B8: Am B9: k B10: Io B11: e The values of the variables are in cells B8 to B11. Cells A7 to A11 are merely labels for documentation purposes and they are optional. Nevertheless, it is good documentation practice to label or provide a brief description to all variables and calculation steps. As required, we see that Am is 1500 g CO2 m-2 s-1 (cell B8); k is 0.5 (cell B9); I0 is 200 W m-2 (cell B10); and is 12 g CO2 J-1 (cell B11). We also define the following names to these cells: Am to cell B8, k to B9, Io to B10, and e to B11. These names are convenient because they can be used in formulas rather than their cell references to which they refer. For instance, instead of writing the formula like this: =E8*E11*E9*E10*EXP(-E9*3) we can instead use their cell names to write: =Am*e*k*Io*EXP(-k*3) which makes reading and understanding the formula easier. There are two ways to define a name to a cell. As an example, let us define the name Am to cell B8. Place the active cell indicator at cell B8 in the Leaf Photosyn worksheet (Fig. 1.7), then Type Am in the Name box, and press Enter when done. Cell B8 will have the name Am. Alternatively, in Excel 2003, choose from the main menu Insert|Name|Define and in the dialog box, type Am. In Excel 2007, from the Formulas ribbon, choose Define name. In the dialog box, type Am. The name scope should be Workbook, meaning that Am is visible (that is, can be referenced by other cells) in all worksheets in the workbook. Perform these same steps to define the names k, Io and e to cells B9, B10 and B11, respectively. Now we have to enter the following in the LeafPhotosyn worksheet: Row 1 2 3 4 5 Col. A CONTROL max steps step size step criteria Col. B Cell name 10 0.5 0 =_step<=B2 B3: _stepsize B4: _step B5: _criteria It is compulsory that we define one cell with the name _step and another cell _stepsize. In this example, we define cell B3 with the name _stepsize and cell B4 _step, and their values are 0.5 and 0, respectively. While the value of _stepsize is 15 important, the value we give to _step is not (we can even leave it blank). This is because BuildIt maintains the value of _step. Before proceeding into the inner loop, BuildIt resets _step to 0, and at the end of each iteration cycle in the inner loop, _step will be incremented automatically by as much as _stepsize; that is _stepi+1 = _stepi + _stepsize where _stepi and _stepi+1 denote the value of _step at iteration no. i and the subsequent step no. i+1, respectively (Fig. 1.5). We previously set _stepsize to 0.5 so when BuildIt enters into the inner loop, _step will have, as stated earlier, the value 0, then incremented to 0.5 in the next iteration cycle, then in successive iteration cycles, incremented to 1.0, 1.5, 2.0 and so on. Fig. 1.7. One way to define the name Am to cell B8 is to move the active cell indicator to cell B8, type Am in the Name box, and press the Enter key This progressive increase of _step will continue indefinitely unless we specify a criteria to BuildIt so that it knows when to stop the iteration cycle in the inner loop. In this example, cell B5 holds the criterion to end the simulation run, and this cell is defined with the name _criteria. Like the case for _step and _stepsize, it is also compulsory that we define one cell with the name _criteria. The formula in cell B5 tells BuildIt that as long as _step<=B2 is TRUE, the iterative calculations will continue until _step<=B2 becomes FALSE. Cell B2 is the upper limit (we gave it the value 10) so when _step exceeds 10, the logical condition _step<=B2 becomes FALSE which will end the inner loop calculations and BuildIt exits back into the outer loop. 16 The purpose of having to setup the cells for _step, _stepsize and _criteria will become evident in the following cell formulas to calculate the leaf photosynthesis: Row 1 2 3 4 5 Col. D MODEL L n1 n2 AL Col. E Cell name =_step =Am*e*k*Io*EXP(-k*L) =Am+e*k*Io*EXP(-k*L) =E3/E4 E2: L Cells E3 and E4 are the intermediary variables for the numerator and denominator in Eq. (1.1), respectively. Cell E5 is the leaf photosynthetic rate at the given L (cell E2). The formula in cell E2 (L) is set equal to _step. When BuildIt starts the simulation run, _step is set to 0 and in turn, L is also 0. Using this L value, the leaf photosynthetic rate (cell E5) is next calculated. In the next iteration cycle, _step is incremented to 0.5 (L, likewise, is 0.5), and cell E5 produces the leaf photosynthetic rate. This process continues for L = 1.0, 1.5, and so on until L exceeds 10 (the upper limit which we set in cell B2). In other words, what we have done here is to determine the leaf photosynthetic rate for L = 0 to 10 with a 0.5 interval. We can of course choose a smaller or wider interval. For example, for a smaller and wider interval, we can set _stepsize (cell B3) to 0.1 and 1.0, respectively, where the former interval produces 101 points (L = 0, 0.1, 0.2,…, 10) and the latter interval only 11 points (L = 0, 1, 2,…, 10). What if we wish to determine the leaf photosynthetic rate from L = 1 to 10, instead of L = 0 to 10? In this case, we modify the formula in cell E2 from =_step to =_step+1 so that L now starts at 1.0 and will be incremented in each subsequent iteration to 1.5, 2.0, 2.5, and so on until L = 10. Calculations for L = 0 to 10 with a 0.5 interval produces 21 points, and we need to save the model results for each point. For saving the model output, we need to define one cell with the name _read and another cell with _write. The name _read tells BuildIt which variables we wish to save, and the name _write tells BuildIt where we wish to save these variables. In other words, _read can be regarded to mean “read what?” and _write as “write where?”. The following entries illustrate the use of both names: Row 1 2 3 4 5 6 Col. G to output L =L Col. H Cell name AL =E5 G3: _read model output G6: _write Cells G1, G2, H2 and G5 are merely headers to document our entries and they are optional. As before, it is recommended that we always label or provide a short 17 description for each entry in the spreadsheet for documentation purposes. The important cells are G3 (defined with the name _read) and G6 (_write). The cell defined with _read and all cells to its right will be checked by BuildIt to determine which variables are to be saved in each iteration cycle. In our example, the values referred to in cell G3 and in the cell to its right, cell H3, will be saved by BuildIt. Cell E3 contains the value for L, and cell H3 the value of the corresponding leaf photosynthetic rate. This means that BuildIt saves the values of L and AL in each iteration cycle. What if we also wish to save the numerator (n1) and denominator (n2) of Eq. (1.1) for, say, checking purposes? For this purpose, we can enter the following: Row 1 2 3 Col. G to output L =L Col. H Col. I Col. J Cell name AL =E5 n1 =E3 n2 =E4 G3: _read This means that BuildIt now saves the results referred to in cells G3 to J3. Recall that the cell defined with _read serves as a starting point for BuildIt to determine which variables are to be saved. All cells to the right of this starting cell will be checked by BuildIt. However, these cells must not be blanks. BuildIt stops checking the moment it encounters a blank cell. For example, the following entries cause BuildIt to save only the values of L, AL and one of the intermediary variables, n1: Row 1 2 3 Col. G to output L =L Col. H Col. I AL =E5 n1 =E3 Col. J Col. K Cell name n2 =E4 G3: _read Cell J3 is blank so it causes BuildIt to stop checking and ignore cell K3. If there are more entries to the right of cell K3, they too will be ignored (and not saved) by BuildIt. In other words, variables to be saved must be specified in a continuous range of cells, starting from the right of—and including—the cell defined with _read. BuildIt actually checks two rows of cells starting from the cell defined with _read. The first row is checked to determine which variables are to be saved, whereas the second row specifies if the values of these variables are to be saved before or after the operations in the Operation section are executed (Fig. 1.5). If they are to be saved before these operations, the value FALSE must be given, else their values must be TRUE. In this example, we earlier typed the following: Row 1 2 3 4 5 6 Col. G to output L =L Col. H Cell name AL =E5 G3: _read model output G6: _write The first row checked by BuildIt is G3 and H3. This row, as stated before, tells BuildIt which variables are to be saved in every iteration cycle in the inner loop (in this case, L and AL). The second row checked by BuildIt is the one below; that is, G4 and H4. Both these cells are blanks (i.e., they are given no values). If a cell is left blank, BuildIt assumes the default TRUE value, so both G4 and H4 are treated to have 18 TRUE values. This means that the values of L and AL are saved only after the operations in the Operation section are executed. But if both G4 and H4 are FALSE, their values then saved before these operations are executed. In our example, however, it actually does not matter whether G4 or H4 is TRUE or FALSE: model output remains the same. But for some variables, we may need to specify whether their values should be saved before or after the Operation section. One such a situation will be discussed later (section 1.3.6). After specifying which variables are to be saved, we need to tell BuildIt where these variables are to be saved. We define cell G6 the name _write, so cell G6 and all cells to its right and all cells below it will be used by BuildIt to store the model output. In our example, L and AL will be saved at location starting at cell G6. In the first iteration, cells G6 and H6 will contain the values of L and AL, respectively. In the next iteration, cells G7 and H7 will now store L and AL, respectively, and so on. In other words, model output is a list that grows progressively downward where the output of each iteration cycle occupies a separate row (Fig. 1.8). We have completed implementing Eq. (1.1) in Excel and we are ready to run the simulation. From the main menu, choose Start Simulation from the BuildIt menu. The model output is as shown in Fig. 1.8. From the model output list (cells G6:H26), we can draw a line scatter graph which shows an exponential decline in AL with increasing L. Fig. 1.8. Model for leaf photosynthesis: its setup and output In Fig. 1.8, note that at the end of the simulation run, _step (as well as L) is equal to 10.5 which exceeds the upper limit of 10 (cell B2), so the condition in cell B5 is FALSE, ending the simulation run. Model output begins in cells G6 and H6 and 19 moves progressively downward in every iteration cycle, ending at cells G26 and H26. From the output list, we see that L (cell G6 downwards) begins at 0 and ends at 10 with a 0.5 interval, and its corresponding calculated AL is from H6 to H26. Recall that we can press the ESC or Control-C keys to abort the simulation run. This is particularly useful for lengthy runs. Note that you may have to press these keys repeatedly to stop the simulation run. This is because Excel may ignore key presses while it is performing intensive and lengthy calculations. Eq. (1.1) is a simple equation and admittedly, it is actually unnecessary to use BuildIt to implement Eq. (1.1) in Excel. The method as shown by Brown (1999) can be used to implement such simple equations in Excel. The use of BuildIt becomes essential, however, when we attempt to implement large, complex models in Excel, as we will later see in this book. For now, we will continue examining more examples to show how we can use BuildIt in model building and simulation. 1.3.4 Example 2: Canopy photosynthesis Eq. (1.1) determines the leaf photosynthetic rate, but to determine the photosynthetic rate of the whole canopy, we need to integrate Eq. (1.1) over the whole canopy; that is LAI AT 0 LAI 0 AL dL Am kI 0 exp kL Am kI 0 exp kL (1.2) dL where AT is the canopy photosynthesis (g CO2 m-2 leaf area s-1); and LAI is the total leaf area index of the whole canopy (m2 leaf area m-2 ground area). BuildIt solves integration numerically using the 5-point Gaussian integration method. Create a new workbook and save it as Ex2. Rename one of the worksheets as CanopyPhotosyn. This is the worksheet where we will implement Eq. (1.2) and run it to determine the canopy photosynthesis rate, AT, for LAI = 0 to 10 with a 0.5 interval. As we have done in the previous example, enter the following for the Control section in the CanopyPhotosyn worksheet: Row 1 2 3 4 5 Col. A CONTROL max steps step size step criteria Col. B Cell name 10 0.5 0 =_step<=B2 B3: _stepsize B4: _step B5: _criteria The following are the entries for the equation variables (same as before): Row 7 8 9 10 11 Col A PARAMETERS Am k Io quantum Col. B Cell name 1500 0.5 200 12 B8: Am B9: k B10: Io B11: e 20 And the section which implements Eq. (1.2) is as follows: Row 1 2 3 4 5 6 7 Col. D MODEL LAI L n1 n2 AL AT Col. E Cell name =_step E2: LAI E3: L =Am*e*k*Io*EXP(-k*L) =Am+e*k*Io*EXP(-k*L) =E4/E5 It may seem confusing that there seem to be two leaf area indexes: one in cell E2 (LAI) and another in cell E3 (L). LAI is the total leaf area of the whole canopy per unit ground area, whereas L is the cumulative leaf area (per unit ground area) from the canopy top to a given canopy depth. For instance, at half the total canopy depth, L is the sum of the leaf area from the canopy top to half the total canopy depth. So as we move progressively down the canopy depth, L increases from 0 to LAI. In short, 0 L LAI. Cells E4 and E5 are the numerator and denominator of Eq. (1.2), respectively, and their ratio gives the leaf photosynthetic rate in cell E6. Note that both these cells (E4 and E5) refer to cell E3 (L), but cell E3 is blank. It is left blank because BuildIt will supply the necessary values for L during the numerical integration of Eq. (1.2). As stated earlier, BuildIt uses a 5-point Gaussian integration method. This means that five different values of L will be selected within the interval [0, LAI] by BuildIt. And for each of the selected L value (cell E3), the corresponding AL (cell E6) will be calculated. This gives a total of five different AL values, and they are summed in such a way according to the Gaussian integration method to obtain the integration result, which is stored in cell E7. To perform an integration we use BuildIt’s integration operation, ITG. As shown in Fig. 1.9, enter the following in cells J2 to P2: Row 2 Col. J Canopy photosynthesis Col. K itg Col. L =L Col. M =E6 Col. N =E7 Col. O =0 Col. P =E2 Also define the name _operation for cell K2. This name indicates to BuildIt the start of the Operation section where the list of operations are located. In our case, there is only one operation in the list and this list begins in cell K2 onwards. Cell J2 is merely for documentation purposes to describe the intention of the integration specification in cells K2 to P2. Fig. 1.9. BuildIt’s integration operation, ITG, and its specification. Note that the last argument, single_integral, is left blank in cell Q2 so it is assumed TRUE by default. The ITG operation has the following specification: 21 ITG (x, func, output, lower, upper, single_integral) which specifies that the function func of variable x is to be integrated over the interval [lower, upper], and the result of the integration is to be stored in the output cell. The last argument, single_integral, is optional and its value must either be TRUE or FALSE only. It is set to TRUE for single integrations, and FALSE for multiple integrations (e.g., double or triple integrations). A single integration means that a function of a single variable, such as func(x), is integrated: upper output func( x)dx lower A multiple integration means that a function of two or more variables, such as func(x, y) or func(x, y ,z), is integrated. Our example here, Eq. (1.2), involves a only single integration, so the single_integral must be set to TRUE. If this argument is left blank (as we have done here), the value TRUE is assumed. We will later consider another example in the next section (1.3.5) involving double integrations. To integrate Eq. (1.2), ITG’s first argument x (cell L2) is the leaf area index, L (cell E3); the argument func (cell M2) is the leaf photosynthetic function (cell E6), the argument output (cell N2) is the integration result (canopy photosynthesis) to be stored in cell E7, and the integration limits: lower (cell O2) and upper (cell P2) are 0 and LAI (cell E2), respectively (Fig. 1.9). Before we can run the model, we need to specify which variables are to be saved and where they should be displayed. For this purpose, we need to define two names, _read and _write, to cells G3 and G6, respectively, and enter the following: Row 1 2 3 4 5 6 Col. G to output LAI =LAI Col. H Cell name AT =E7 G3: _read model output G6: _write Cells G3 and H3 instruct BuildIt to save L and AT, respectively. At the end of each iteration cycle in the inner loop, BuildIt saves these values starting from cells G6 and H6 onwards. Choose Start Simulation from the BuildIt menu to start the simulation. The results are displayed in cells G6 to H26 (Fig. 1.10). From this output list, we can plot the chart which shows an increase at a decreasing rate in the canopy photosynthesis with increasing LAI. 22 Fig. 1.10. Model for canopy photosynthesis: its setup and output 1.3.5 Example 3: Daily canopy photosynthesis In the previous example, Eq. (1.1), the leaf photosynthesis function, AL, was integrated over the entire canopy, [0, LAI], to give the canopy photosynthesis function, AT or Eq. (1.2). This equation, however, only gives the canopy photosynthesis at an instantaneous moment. To determine the daily canopy photosynthesis (that is, the canopy photosynthesis for the entire day), we must integrate Eq. (1.2) over the whole day, which is equivalent to integrating the function from the time of sunrise to sunset (since there is no photosynthesis for periods before sunrise and after sunset). The daily canopy photosynthesis function, ATd, is as shown below, expressed in units g CO2 day-1: ATd 3600 LAI 1000000 tss LAI tsr 0 Am kI 0 t exp kL Am kI 0 t exp kL dL dt (1.3) where the division by 1000000 is to convert g CO2 to g CO2, multiplication by 3600 and is to convert t, tsr and tss from unit hours to seconds, and further multiplication by LAI is to convert the photosynthetic rate per unit leaf area to the photosynthetic rate for the whole canopy. In Eq. (1.3), I0(t) is the solar irradiance (J m-2 ground area s-1) at time t (hours), given by France and Thornley (1984) as I0 t t tsr sin 2 1800 tss tsr tss tsr I t ,d tsr t tss 23 (1.4) where It,d is the daily total solar irradiance (J m-2 ground area day-1); and tsr and tss are the times of sunrise and sunset, respectively (hours). In the previous two examples, we assumed that the solar irradiance was constant. In this example, however, solar irradiance is a function of time, t, where I0 varies sinusoidally with time. We now wish to determine the relationship between ATd and LAI from LAI = 0 to 10 with a 0.5 interval. We will take the same values for the equation variables as before, with the additional of some new values: let us take It,d as 10 MJ m-2 day-1, tsr as 6:00 hours, and tss as 18:00 hours. Create a new workbook and save it as Ex3. Rename one of the worksheets as DailyCanopyPhotosyn. As usual, we begin by entering the Control section in this worksheet: Row 1 2 3 4 5 Col. A CONTROL max steps step size step criteria Col. B Cell name 10 0.5 0 =_step<=B2 B3: _stepsize B4: _step B5: _criteria The equation variables are entered as: Row 7 8 9 10 11 12 13 Col A PARAMETERS Am k e Itd tsr tss Col. B Cell name 1500 0.5 12 10000000 6 18 B8: Am B9: k B10: e B11: Itd B12: tsr B13: tss Cells B8 to B10 are for the same variables as before, whereas the new variables are at B11 (daily total solar irradiance, expressed in J m-2 day-1), B12 (hour of sunrise) and B13 (hour of sunset). The section of the worksheet that implements Eq. (1.3) and (1.4) is as follows: Row 1 2 3 4 5 6 7 8 9 10 11 12 13 14 Col. D MODEL Solar radiation hour n1 n2 Io Leaf photosyn. LAI L n1 n2 AL Col. E Cell name E3: hour =Itd/(1800*(tss-tsr)) =SIN(PI()*(hour-tsr) / (tss-tsr))^2 =E4*E5 =_step E6: Io E9: LAI E10: L =Am*e*k*Io*EXP(-k*L) =Am+e*k*Io*EXP(-k*L) =E11/E12 24 Daily canopy photosyn. itg out ATd 15 16 17 =(E16*LAI*3600)/1000000 Cells E3 is the hour, t, and together with cells E4 and E5, they are used to calculate I0(t) in cell E6. Cells E9 to E13 are to calculate the leaf photosynthetic rate, AL. To perform a double integration on AL, we require two ITG statements: Row 2 3 Col. J canopy photosyn. daily canopy photosyn. Col. K itg Col. L =L Col. M =E13 Col. N =E16 Col. O =0 Col. P =LAI itg =hour =E13 =E16 =tsr =tss Col. Q FALSE Also define the name _operation to cell K2 to indicate to BuildIt that the list of operations begin here. Recall that the ITG operation has the following specification: ITG (x, func, output, lower, upper, single_integral) Cells K2 to Q2 specify that the function AL of variable L is to be integrated over the interval [0, LAI], and the result of the integration is to be stored in cell E16. The last argument, single_integral, is set to FALSE because the integration of function AL is still incomplete, and BuildIt should check the next line for further instructions on integrating this function. Consequently, cells K3 to Q3 further specify that the function AL of variable hour is to be integrated over the interval [tsr, tss], and the result of the integration is to be stored in cell E16 as well. This time, the argument single_integral is left blank (assumed TRUE by default) because the integration of function AL is now complete. Both these ITG specifications instruct BuildIt to perform a double integration on the function AL: once over the whole canopy, then over the whole day. Their operations can be summarized as LAI output AL L, t dL dt 0 tsr tss where the result of the double integration, output, is stored in cell E16. In cell E17, the formula is =(E16*LAI*3600)/1000000 so that the integration result (cell E16) is expressed in units g CO2 day-1 to finally give the daily canopy photosynthesis, ATd. The following setups the model output: Row 1 2 3 4 5 6 Col. G to output LAI =LAI Col. H Cell name Atd =E17 G3: _read model output G6: _write 25 where _read and _write are defined to cells G3 and G6, respectively. Choose Start Simulation from the BuildIt menu to start the simulation. The results are displayed in cells G6 to H26 (Fig. 1.11). From this output list, we can plot the chart which shows a near linear increase in the daily canopy photosynthesis with increasing LAI. Fig. 1.11. Model for daily canopy photosynthesis: its setup and output 1.3.6 Example 4: Prey-predator model We continue to explore BuildIt’s functionality by building the classical LotkaVolterra’s prey-predator model in Excel. In an ecosystem, there are two species: a prey and a predator. Their population are closely related to one another. For example, a large population of prey means more food is available to the predator. This encourages predation and this will increase the population of predator. Eventually predation outstrips food supply and causes a decline in the predator population. A low population of predator now encourages the rise again in the prey population. This dynamics continue in a cycle of rise and fall in both the prey and predator population. The rate of population growth over time for the prey and predator can be described as: 26 dx x xy dt (1.5) dy xy y dt (1.6) where t is the time; x and y are the population for the prey and predator, respectively; and are the growth rates of the prey and predator, respectively; and and are the death rates of the prey and predator, respectively. The prey and predator population at any one time can be determined, using Euler’s method, as xt 1 xt dx t dt (1.7) yt 1 yt dy t dt (1.8) where subscripts t and t+1 indicate the population at time step t and the subsequent time step t+1, respectively; and t is the interval between both time steps t and t+1. We will simulate the prey and predator population dynamics for 200 time steps, with a time step interval of 1. So let us begin by fixing the initial values for x and y as 50 and 15, respectively; and as 0.1 and 0.001, respectively; and and as 0.01 and 0.05, respectively. Create a new workbook and save it as Ex4. Ensure that this workbook has at least two worksheets. We will separate the model implementation and model output results by placing them in separate worksheets. This option is entirely your choice: you may still place both parts together in one worksheet as we have done in the previous examples. Here, we will place the model implementation in a worksheet named Model, and the model output results in a worksheet named Output. Recall that we wish to run our prey-predator model for 200 time steps, with a time step interval of 1, so in the Model worksheet, enter the following for the Control section: Row 1 2 3 4 5 6 Col. A CONTROL Max steps Step size Step Criteria No. subintervals Col. B Cell name 200 1 0 =(_step/_stepsize)<B2 2 B3: _stepsize B4: _step B5: _criteria What is crucially different in the Control section as compared to the previous examples is cell B6. It denotes the number of subintervals within a single time step. The purpose of dividing the interval of a single time step into, preferably, two or more subintervals is to reduce the error of prediction. Let us consider just the prey population, x. Fig. 1.12 shows that at time step t, the prey population is x(t), and the calculated population growth rate is dx(t)/dt. So in the next time step t+1, the prey population, calculated using Eq. (1.7), increases to x(t+1) (indicated by point A). Point A, however, assumes that within the time interval, t, the population growth rate remained constant, but Fig. 1.12 shows that this is 27 untrue. The rate of population growth actually decreased within this period, so the actual prey population is really at point B. If t is large, the risk increases that the predicted value may deviate far from the true value (i.e., distance between A and B is large). Fig. 1.12. The error in predicting x(t+1) can be large when the growth rate, dx(t)/dt, is assumed constant over a large time interval, t Consequently, to reduce the prediction error, we should divide the time interval into two or more subintervals so that for each subinterval we calculate the growth rates and subsequent population for both prey and predator (Fig. 1.13). Because we have two or more subintervals within t, Eq. (1.7) and (1.8) are modified to xt 1 xt t n 1 dxt i n n i 0 dt (1.9) t n 1 dyt i n yt 1 yt n i 0 dt (1.10) where n is the number of subintervals. The more subintervals we have, the more accurate our estimates are, but the trade off is calculations become more intensive and time-consuming which can be a significant problem in large, complex models. How to choose the value for n often requires some trial-and-error which involves examining the gain in prediction accuracy with increasing n. We may opt for a particular value for n when prediction accuracy can no longer be increased significantly or when simulation runs become too lengthy if a higher n is used. Generally, models with large time step intervals or with sensitive rates of change require a large n. In this example, the number of subintervals is set at two (cell B6). Increasing n to more than two did not improve the accuracy of predictions significantly, so we will maintain n as 2. 28 Fig. 1.13. The error in predicting x(t+1) reduces when the time interval, t, is divided into two (or more) subintervals We can now proceed to enter the model parameters in the Model worksheet: Row 8 9 10 11 12 13 Col. A PARAMETERS Population prey predator Growth rate prey Col. B 14 predator 0.001 15 16 Death rate prey 0.01 17 predator 0.05 Cell name 50 15 0.1 B13: prey_growth B14: pred_growth B16: prey_death B17: pred_death For the prey, its initial population is in cell B10, growth rate in cell B13, and death rate in cell B16. For the predator, its initial population is in cell B11, growth rate in cell B14, and death rate in cell B17. Cells B13, B14, B16 and B17 are further defined with their respective cell names. The following entries implements in the model in the Model worksheet: Row 1 2 3 Col. D MODEL 4 Predator Prey Col. E Col. F Col. G Cell name pop (t1) rate =prey_growth* prey_pop - prey_death * prey_pop * pred_pop =pred_growth* prey_pop * pred_pop pop (t2) =prey_pop+F3* _stepsize/B6 E3: prey_pop 29 =pred_pop+F4* _stepsize/B6 E4: pred_pop - pred_death * pred_pop Notice, however, that both cells E3 and E4 are blanks. This is because we will instruct BuildIt to initialize their values using the INI operation which has the following specification: INI (destination, source) INI specifies that the contents from source cells will be copied to the cells referred to in the destination cells. In addition, this initialization operation must be specified in the Prerun section so that before BuildIt enters the inner loop, the prey and predator population have been initialized to their given values. So in the Model worksheet, enter the following for the Prerun section: Row 8 9 10 Col. I PRERUN Initial prey pop. Initial predator pop. Col. J Col. K Col. L ini ini =prey_pop =pred_pop =B10 =B11 Ensure that cell J9 is defined with the name _prerun to indicate to BuildIt that this cell is the starting point for all prerun operations. In this example, cells B10 and B11 are the source cells, and cells E3 (prey_pop) and E4 (pred_pop) the destination cells. The first INI operation (cells J9 to L9) instructs BuildIt to copy the contents of cell B10 to E3, initializing the prey population. The second INI operation (cells J10 to L10) copies cell B11 to E4, initializing the predator population. Note that cells I8, I9 and I10 are labels for documentation purposes only. As discussed earlier, we wish to reduce the prediction errors by dividing the time step interval into two or more subintervals so that we can determine the prey and predator population at each successive subinterval. We earlier fixed the number of subintervals, n, to two (cell B6). So while cell E3 is the prey population at time step t, or xt, subsequent calculations make cell G3 the prey population at time step t+0.5, or xt+0.5. We like to somehow copy the value in cell G3 to E3 so that cell E3 is now xt+0.5, and subsequent calculations, as before, yields xt+1 in cell G3. Since we have two subintervals, we should copy cell G3 to E3 again. This gives cell E3 the value of xt+1. In other words, prior to the REP operation, cell E3 holds xt, and after the REP operation, cell E3 holds xt+1. The same development likewise occurs in cells E4 to G4 to calculate the predator population. To instruct the copying of source cells to destinations cells, we use BuildIt’s operation which has the following specification: REP REP (destination, source, num_of_replacements) which specifies that the contents from source cells will be copied to the cells referred to in the destination cells, and this copying operation will be done num_of_replacements number of times. So in the Model worksheet, enter the following: Row 1 2 Col. I OPERATION update population Col. J Col. K Col. L Col. M rep =E3:E4 =G3:G4 =B6 Ensure that cell J2 is defined with the name _operation to indicate to BuildIt the list of operations in the Operation section that must be executed in every iteration in the 30 inner loop. Here, cells E3:E4 are the destination cells and cells G3:G4 the source cells, and their copy operation occurs twice (cell B6). We have completed implementing the model in the Model worksheet. We can now specify the model output. Fig. 1.14 shows the Output worksheet, where we entered the following to specify that we wish to output the time step, prey population and predator population: Row 1 2 3 4 5 6 7 Col. A to output step =_step Col. B Col. C Cell name prey =prey_pop FALSE predator =pred_pop FALSE A3: _read model output A7: _write Cell A3 is defined with the name _read. This tells BuildIt that this cell and all cells to its right are variables to be saved. Recall that BuildIt actually checks two rows: the first row is A3 to C3, the variables to be saved, and the second row is to instruct BuildIt whether to either save the corresponding variables before or after the executions of the operations in the Operation section (Fig. 1.5). Fig. 1.14. Output listing in the Output worksheet for the prey-predator model Cell A4 is left blank (assumed TRUE by default) so _step is saved after the operations have been executed in the inner loop. Cells B4 and B5 are instead FALSE so prey_pop and pred_pop variables are saved before these operations are executed. As mentioned previously, the value in cell E3 (prey population) is different prior and after the REP operation. Consequently, we want to save the prey population before the REP operation is done (i.e., by setting cell B4 to FALSE). If we save the 31 prey population after the REP operation (i.e., by setting cell B4 to TRUE or leaving it blank), we will get a mismatch in the output sequence, where at time step t, for instance, the corresponding prey population saved is actually xt+1 (xt is not saved at all) (Fig. 1.15). Fig. 1.15. Mismatch in the output sequence due to setting the output for the prey and predator populations to TRUE (cells B4 and C4). Compare this output to Fig. 1.14. For some variables, it does not matter if we set TRUE or FALSE in their corresponding cells in the second row. The variable _step, for example, can be saved before or after the Operation section because the value of _step is not changed by the operations. To start the simulation, choose Start Simulation from the BuildIt menu. Fig. 1.14 shows a part of the model output list. Cell A7 is defined with the name _write so output begins here and spreads until to cell C206 (not shown). The output list is then used to plot a chart showing the dynamics of the prey and predator population. We see that the prey population shows greater fluctuations than the predator population. The prey population fluctuates between about 21 to 97, whereas the predator population fluctuates in a narrower range of about 6 to 16. Also note that the predator population is often below the initial population of 15, whereas the prey population can at times exceed the initial population of 50. Before we consider the next example, it is important to know that there may be a difference between having a single and multiple REP operations to copy a range of cells to their respective destinations. For instance, we earlier entered the following for the Operation section: Row 1 2 Col. I OPERATION update population Col. J Col. K Col. L Col. M rep =E3:E4 =G3:G4 =B6 32 This case copies cells G3 to E3 and G4 to E4 simultaneously. But what if we split the single REP operation into two: one operation to copy cell G3 to E3, and another for G4 to E4? That is, we enter the following: Row 1 2 3 Col. I OPERATION update prey population update predator population Col. J Col. K Col. L Col. M rep rep =E3 =E4 =G3 =G4 =B6 =B6 This second case has two REP operations: one for each copy operation. The difference between these two cases is subtle. Eq. (1.5) and (1.6) reveal that prey and predator population depend on each other; that is, cell G3 depends on E4, and G4 on E3. This interdependency means copying cell G3 to E3 and G4 to E4 must occur at the same time. In the second case, the first REP operation copies cell G3 to E3 which updates cell E3 and causes recalculations to determine the new predator population in cell G4. The old value in cell G4 is overwritten before it could be copied to cell E4. So by the time the second REP operation is executed, it is this new (but wrong) value in cell G4 that is copied to cell E4. Cell E4 has been updated with a new value which causes recalculations to give a new (but wrong) value to cell G3, and so this error proliferates throughout the simulation run where wrong values are used in calculations to produce wrong answers. 1.3.7 Example 5: Simple plant growth model In this fifth example, we will implement a simple plant growth model adapted from Thornley (1977). Fig. 1.16 shows that the assimilates produced by photosynthesis is partitioned to maintenance for the plant’s continual survival and to growth for the synthesis of new materials for the plant. The plant weight consists of two components: the storage weight and the plant structural weight. The storage weight, Ws, is supported by the addition of newly produced substrates via the photosynthesis process. A portion of the plant’s storage, kgWs, will be utilised for maintenance and growth, where of this total (kgWs), Yg of it will be utilised for growth, and the remainder (1 – Yg) for maintenance. Of the total plant structural weight, Wg, kd of it will degrade and the substrates returned to the storage, and ks of it will senesce (i.e., loss of materials due to increasing age). The rates of change in the dry weights for storage and structure components at time t (in unit hours) are thus dWs 12 kd Wg k gWs 3600 LAI AT dt 44 1000000 dWg dt k gWsYg kdWg ksWg (1.11) (1.12) As shown earlier, Eq. (1.2) gives us the canopy photosynthesis, AT, in units of g CO2 m-2 leaf area s-1 which we will convert to units g C m-2 leaf area s-1 by: AT ( g CO2 m-2 s-1 ) AT 12 (g C m-2 s-1 ) 44 1000000 Every 44 g of CO2 has 12 g of C since the atomic weight of carbon and molecular weight of carbon dioxide are 12 and 44 g, respectively. Therefore, AT g CO2 will have (12/44)AT g of C. We divide AT by 1000000 to convert the unit g C to g C. 33 Since time t is in unit hour, we need to multiply AT by 3600 (i.e., 60 s 60 mins), and further multiplication by LAI is to convert AT into units g C m-2 ground area hour-1; hence, the converted AT is now compatible with the dry weight units (which are expressed as g C per unit ground area) Fig. 1.16. A simple plant growth model (adapted from Thornley, 1977) The cumulative increase in the dry weights for storage and structure from time t1 to t2 are obtained by integrating their rates of change function over the period [t1, t2]: Ws t2 12 kd Wg k gWs 44 1000000 3600 LAI AT dt t1 12 3600 LAI kd Wg k g Ws t 44 1000000 t2 (1.13) AT dt t1 t2 k gWsYg kd Wg ksWg dt Wg t1 (1.14) k g Ws Yg kd Wg ksW t where t is the time interval (t2 - t1), and kg ks and Yg are taken as constants. Calculations are straightforward with the exception of the integration of the canopy photosynthesis AT. From Eq. (1.2), canopy photosynthesis is LAI AT 0 LAI AL dL 0 Am kI 0 exp kL Am kI 0 exp kL dL 34 where solar irradiance, I0, is not a constant but varies with time t according to Eq. (1.4) as I0 t t tsr sin 2 1800 tss tsr tss tsr I t ,d tsr t tss where It,d is the daily total solar irradiance (J m-2 ground area day-1); and tsr and tss are the times of sunrise and sunset, respectively (hour). In this example, we will determine the daily increment in the total dry weights of Ws and Wg, with t1 = 0 and t2 = 24. The values for the rest of the parameters are as listed in Table 1.2. Since there is no photosynthesis for periods before sunrise and after sunset, integration of canopy photosynthesis over the whole day is equivalent to its integration over the period between sunrise and sunset so Eq. (1.13) becomes 12 3600 LAI Ws kd Wg k g Ws t 44 1000000 tss AT dt (1.15) tsr Consequently, the dry weights for storage and structure can be determined by: Ws,t 1 Ws,t Ws (1.16) Wg ,t 1 Wg , t Wg (1.17) where subscripts t and t+1 denote the dry weight at time t and the subsequent time t+1, respectively. Table 1.2. Parameter values for the simple plant growth model Symbol Description Units Value Am max. leaf photosynthesis rate g CO2 m-2 leaf area s-1 1500 solar radiation conversion factor g CO2 J-1 12 k canopy extinction coefficient - 0.5 LAI leaf area index m2 leaf area m-2 ground area 2 kg growth rate constant day-1 1.98 kd degradation rate constant day-1 0.10 ks senescence rate constant day-1 0.05 Yg efficiency of structural synthesis - Ws substrates dry weight g C m-2 ground area 20 Wg structural dry weight g C m-2 ground area 130 tsr time of sunrise hour 6 tss time of sunset hour 18 It,d daily total solar irradiance J m-2 ground area day-1 10000000 0.75 Let us now implement Thornley’s simple plant growth model in Excel. Create a workbook and name it as Ex5. Rename one of the worksheets as CropGrowth, where in this worksheet, enter the following for the Control section: 35 Row 1 2 3 4 5 Col. A CONTROL max steps step size step criteria Col. B Cell name 10 1 0 =(_step/_stepsize)<B2 B3: _stepsize B4: _step B5: _criteria Cell B3 indicates that the time interval is 1 day, and cells B2 and B5 indicate that we will run the simulation for 10 days. The next is to enter the model parameters (listed in Table 1.2) as follows: Row 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 Col. A PARAMETERS Am k quantum LAI kg kd ks Yg tsr tss Itd INITIAL Ws Wg Col. B Cell name 1500 0.5 12 2 1.98 0.1 0.05 0.75 6 18 10000000 B8: Am B9: k B10: e B11: LAI B12: kg B13: kd B14: ks B15: Yg B16: tsr B17: tss B18: Itd 20 130 The implementation of the calculations for solar irradiance and daily canopy photosynthesis are as follows: Row 1 2 3 4 Col. D MODEL Solar radiation hour n1 5 n2 6 7 8 Io 9 10 Leaf photosyn. L n1 11 n2 Col. E Col. F Col. G Cell name E3: hour =Itd / (1800 * (tss-tsr)) =SIN(PI()* (hour-tsr) /(tsstsr))^2 =E4*E5 E6: Io E9: L =Am*e*k*Io* EXP(-k*L) =Am+e*k*Io* EXP(-k*L) 36 12 13 14 15 16 17 18 19 20 21 AL =E10/E11 Daily canopy photosyn. itg out ATd =(12/44)*36 00*LAI* E15/1000000 E16: ATd Weight wgt(t1) storage structure wgt. gain =(kd*Wgkg*Ws)* _stepsize+ ATd =(kg*Ws*Yg -kd*Wgks*Wg)* _stepsize wgt(t2) =Ws+F20 E20: Ws =Wg+F21 E21: Wg Cells D1 to G21 contain the various calculations for determining the solar irradiance and daily canopy photosynthesis. Cell E6 contains the solar irradiance for the hour as calculated by Eq. (1.4). BuildIt’s operation, ITG, is used to integrate Eq. (1.1) over the whole canopy and whole day to determine the daily canopy photosynthesis. Once that is determined, the weight gain by the plant’s storage and structure components are determined using BuildIt’s REP operation. Both ITG and REP operations are entered in the Operations section as follows: Row 1 2 3 Col. Q canopy photosyn. daily canopy photosyn. update wgt. Col. R itg Col. S =L Col. T =E12 Col. U =E15 Col. V 0 Col. W =LAI itg =hour =E12 =E15 =tsr =tss rep =E20: E21 =G20: G21 Col. X FALSE Cell R1 is defined with the name _operation to indicate the start of the Operation section. In this section, there are three operations: two ITG and one REP. Cells Q1 to Q3 are merely labels to describe their respective operations. As described earlier in section 1.3.5, the first two ITG operations are to determine the daily canopy photosynthesis which involves double integration of the function AL or Eq. (1.1): first over the whole canopy (cells R1 to X1), then over the day from sunrise to sunset (cells R2 to W2). The result, the daily canopy photosynthesis, is stored in cell E12, after which the dry weights of storage (cell G20) and structure (cell G21) components can be determined for the next time step, t+1. Their values are then copied to cells E20 and E21, respectively (using the REP operation in cells R3 to T3), and the whole cycle repeats. Note that in the Operation section, the REP is entered as follows: Row 3 Col. Q update wgt. Col. R rep Col. S =E20: E21 Col. T =G20: G21 37 Col. U Col. V Col. W Col. X The single REP operation above is not equivalent to having two separate REP operations: one for copying cell G20 to E20, and another for G21 to E21; that is, Row 3 4 Col. Q update storage wgt. update structure wgt. Col. R rep Col. S =E20 Col. T =G20 rep =E21 =G21 Col. U Col. V Col. W Col. X These two cases are not the same because the dry weight Ws,t+1 (cell G20) depends on Wg,t (cell E21), and Wg,t+1 (cell G21) on Ws,t (cell E20). Therefore, their copy operations must occur at the same time because their values depend on each other. Separate copy operations cause premature calculations which give wrong values which will then be copied to other locations, proliferating the error (see also section 1.3.6). A Prerun section is required to initialize the dry weights (cells E20 and E21). So enter the following: Row 7 8 9 Col. Q PRERUN initial storage wgt. initial structural wgt. Col. R Col. S Col. T ini ini =Ws =Wg =B21 =B22 Ensure that cell R8 is defined with the name _prerun so that BuildIt will examine cells R8 to T9 to initialise the storage dry weight (cell E20) with cell B21 and structure dry weight (cell E21) with cell B22. For model output, we will choose to output the day, daily canopy photosynthesis, dry weight gains in storage and structure, individual dry weight for storage and structure, and their total dry weight (Fig. 1.17). The entries are as follows: Row 1 2 Col. I to output step Col. J Col. K Col. L Col. M Col. N Col. O ATd gain Ws gain Wg Ws Wg 3 4 5 6 =_step =ATd =F20 FALSE =F21 FALSE =Ws FALSE =Wg FALSE total wgt. =M3+N3 FALSE model output 7 Cell I3 and I7 are defined with the names _read and _write, respectively. Note that cells K4 to O4 are FALSE to indicate that their cell contents in the corresponding row above should be saved before the ITG and REP operations are executed. Also note that cell O3 sums Ws and Wg, giving their total weight which will be saved in every iteration cycle. Fig. 1.17 shows the model output results. It shows a linear-like increase in the total plant dry weight and the structure dry weight (Wg). The dry weight for storage remained nearly constant. Because we fixed the daily solar irradiance and the times for sunrise and sunset, the daily canopy photosynthesis (ATd) is always the same throughout the simulation period. 38 Fig. 1.17. Model output listing for the simple plant growth model 1.3.8 Example 6: Factorial and triangular numbers This example demonstrates BuildIt’s ACC operation which determines either the summation or product of a series of numbers. The ACC operation has the following specification: ACC (x, accumulated_x, operator) where operator can either be + or * for addition or multiplication, respectively. If the operator is addition (+), ACC determines the summation of a series of numbers; that is, accumulated_x xi i But if the operator is multiplication (*), ACC determines the product of a series of numbers; that is, accumulated_x xi i The factorial of a natural number n, expressed as n!, is determined by 39 n! n x n0 (1.18) x 1 so that, for instance, 5! = 54321 = 120 and 3! = 321 = 6. On the hand, Tn is a triangular number which is the sum of n natural numbers from 1 to n, and it is determined by Tn n x n0 (1.19) x 1 Rather than summing every number from 1 to n, Tn can be determined alternatively by the formula: n(n+1)/2. For demonstration purposes, however, we will ignore this faster and easier formula to determine Tn. We will implement in Excel both Eq. (1.18) and (1.19) to determine the factorial and triangular number of any given natural number n. Create a workbook and save it as Ex6. Rename one of the worksheet as Model. Enter the following in the Model worksheet: Row 1 2 3 4 5 6 7 Col. A CONTROL Step size Step Criteria VALUE n Col. B Cell name 1 0 =x<=n B2: _stepsize B3: _step B4: _criteria 5 B7: n and for the implementing the model: Row 1 2 3 4 5 6 7 8 9 Col. D MODEL x1 Col. E Cell name x2(=x1+1) =x+1 D3: x Product Sum Factorial Triangular =IF(B7>0,E5,1) =IF(B7>0,E6,#N/A) Note that, unlike previous examples, there is no use for the maximum number of steps to terminate the inner loop iterations. Instead, the iterations will end only when the value of x (cell D3) is more than n (cell B7). In other words, iterations end when x<=n is FALSE (cell B4). Cell E5 holds the factorial of n, whereas cell E6 the triangular number of n. However, cell E8 handles the unique case for n = 0, so that 0!, by definition, is equal to 1. Likewise, cell E9 handles the case for T0 which returns the error message #N/A. Note that this worksheet assumes that n is always zero or positive. We need to use both of BuildIt’s ACC and REP operations to implement Eq.(1.18) and (1.19). The following shows how: 40 Row 1 2 3 4 Col. G OPERATION factorial triangular copy x2 to x1 Col. H Col. I Col. J Col. K acc acc rep =D3 =D3 =D3 =E5 =E6 =E3 * + Ensure that the name _operation is defined for cell H2 to specify to BuildIt that the list of operations begin from this cell. The first row, cells J2 to M2, instructs BuildIt to multiply x (cell D3) to the current product in cell E5, whereas the second row, cells J3 to M3, instructs BuildIt to add x (cell D3) to the current sum in cell E6. Both cells E5 and E6 will be updated by BuildIt to reflect their new summation and product values, respectively. After these two operations, cells J4 to M4 instruct BuildIt to copy the value from cell E3 to D3. Recall that the formula in cell E3 is x+1, so every iteration cycle increments x by one, as required by Eq. (1.18) and (1.19). Note that cell M3 is left blank, so the default value 1 is assumed for the num_of_replacements argument for the REP operation. A Prerun section is required to initialize the x variable (cell D3). So enter the following: Row 6 7 Col. G PRERUN initial x1=1 Col. H Col. I Col. J ini =x 1 Ensure that cell H7 is defined with the name _prerun so that BuildIt will examine cell H3 to J3 to initialise x (cell D3) with the value 1 (cell J7). Unlike previous examples, there is no need to define the names _read and _write because cells E8 and E9 will contain the factorial and triangular number of n, respectively. Choose Start Simulation from the BuildIt menu to start the simulation, and Fig. 1.18 shows that 5! and T5 are 120 and 15, respectively. You can change cell B7 to a different value for n and determine its factorial and triangular number by running the model again. Fig. 1.18. The setup and result for the factorial and triangular number of n 1.3.9 Example 7: Scenarios In simulation, we are often interested to determine the predicted outcome of different scenarios. This is often done by changing the values of some of the model parameters and running the simulation again to obtain the predicted outcome. In 41 Example 4 (section 1.3.6), we saw the dynamics of population rise and fall for both prey and predator (Fig. 1.14). What if we double the growth rates for both the prey and predator? That is, what happens to the population dynamics when we change the growth rate for prey from 0.1 to 0.2, and for predator from 0.001 to 0.002? One way is to change the value in cells B13 and B14 (in the Model worksheet of the Ex4 workbook) to 0.2 and 0.002, respectively. We then run the model again, and compare its output with the original outcome (with lower growth rates). Alternatively, we can use BuildIt’s functionality for running scenarios. In the Ex4 workbook, enter the following in the Model worksheet: Row 15 16 Col. I SCENARIO 2x growth rates Col. J Col. K Col. L Col. M =prey_growth 0.2 =pred_growth 0.002 We also define the name _scenario to cell J16 to indicate to BuildIt the start of the Scenario section and where our scenario list is located. Cell I15 and I16 are optional and serve as labels for the scenario operation. Whenever we define a cell with the name _scenario, BuildIt will begin looking at pairs of cells. The search starts with the cell defined with _scenario and moves progressively right, examining each cell pairs. BuildIt stops searching only when it encounters a blank cell. We defined _scenario to cell J16 in our example, so BuildIt will look at the pair of cells (J14, K14), followed by (L14, M14). BuildIt stops at (L14, M14) because the cell N14 (the cell right of M14) is blank (not shown). BuildIt treats each cell pair as follows: (destination, source) where the contents from the source cell is copied to that specified in the destination cell. To better explain this, let us now take the first cell pair, (J14, K14), which has the following formulas: (prey_growth, 0.2). This indicates to BuildIt to give prey_growth (cell B13) a value of 0.2. The second cell pair, (L14, M14), has the following formulas: (pred_growth, 0.002) which indicates to BuildIt that pred_growth (cell B14) will have the value 0.002. When we run the model, BuildIt first runs the simulation for the original growth rates of 0.1 and 0.001 for the prey and predator, respectively. Once the iterations in the inner loop stop, BuildIt checks for any more given scenarios. Since we have specified one more, iterations in the inner loop restart using the doubled growth rates for both prey and predator. BuildIt repeats this process for subsequent scenarios. To demonstrate this process, let us create three more scenarios. In other words, we have four scenarios in total: the first is with the original growth rates for prey and predator. The second scenario, as stated earlier, is the doubling of their growth rates. Why not also triple their growth rates as the third scenario? Finally, for the last scenario, we double both growth and death rates for both prey and predator. For these additional three scenarios, we implement them like this in the Model worksheet (for brevity, the labels in column I are not shown): Row 16 Col. J =prey_ growth Col. K 0.2 Col. L =pred_ growth Col. M 0.002 42 Col. N Col. O Col. P Col. Q 17 18 =prey_ growth =prey_ growth 0.3 0.2 =pred_ growth =pred_ growth 0.003 0.002 =prey_ death 0.2 =pred_ death 0.1 As before, ensure that cell J16 has been defined with the name _scenario. Cells J16 to M16 form the second scenario (doubling growth rates for prey and predator). The next row, cells J17 to M17, is the third scenario (tripling growth rates for prey and predator). The fourth and last scenario is specified from cell J18 to Q18 (doubling all rates for prey and predator). Consequently, we will have a set of four model output: one for the original scenario (that is, as shown partially by Fig. 1.14), and the next three are for the additional scenarios. In the output listing, each output set is separated by a blank row, and a row header (Fig. 1.19). We see that doubling the growth rates for both prey and predator changes the dynamics of their population significantly. As compared to the original growth rate, doubling the growth rate for prey did not cause a larger growth in its population. Instead, it showed a smaller increase in their population growth as the prey was suppressed by the larger population growth for the predator. Before, the predator population seldom exceeded their initial population of 15. But by the doubling their growth rate, predator population fluctuated more, between about 8 to 37. Similar comparisons can be done for the other two scenarios (not shown here). Fig. 1.19. Running scenarios for the prey-predator model Specifying scenarios does not have to be limited to replacing a value with another value. You could replace a value or formula with another formula. For instance, In the Ex1 workbook, cell E5 in the LeafPhotosyn worksheet gives the leaf photosynthetic rate, AL or Eq. (1.1). To keep this example simple, let us say that we 43 wish to take half its calculated value as one of the modeling scenarios. So in the LeafPhotosyn worksheet in the Ex1 workbook, enter the following: Row 1 2 Col. J SCENARIO half AL Col. K Col. L =E5 =0.5*E3/E4 As usual, we have to define the name _scenario and it is assigned to cell K2. Note that cell L2 (source) is not a value, but a formula that will be copied to cell E5 (destination), giving half AL at all times. Recall that cells E3 and E4 are the numerator and denominator in Eq. (1.1), respectively. We have to be careful, however, that we do not write formulas that will refer to itself after the copy operation. For instance, consider the following: Row 1 2 Col. J SCENARIO half AL Col. K Col. L =E5 =0.5*E5 The formula in cell L2, =0.5*E5, will be copied to cell E5 after which the formula in cell E5 will now read as =0.5*E5 which refers to itself. This self-referencing (or circular) formula causes subtle errors which may not be easily detected. 44 Chapter 2. Calculations in the generic crop growth model 2.1 Meteorology This chapter documents all the equations used in the gcg (generic crop growth) model. Calculations begin with the meteorology section. Properties such as solar irradiance, solar position, wind speed, air temperature and vapor pressure must be known at the outset before calculating other factors that affect plant growth and yield. 2.1.1 Daily properties Daily properties refer to meteorological properties for a given day of year (or date). 2.1.1.1 Solar declination 0.4093cos 2 td 10 365 (2.1) where is the solar declination (radians); and td is the day of year. 2.1.1.2 Sunrise, sunset and daylength sin sin acos 24 tss cos cos (2.2) sin sin acos cos cos (2.3) tsr 12 12 tss 12 12 DL sin sin acos tss tsr cos cos 24 (2.4) where tsr, tss and DL are the sunrise, sunset and daylength, respectively (all expressed in hours); is the solar declination (radians); and is the site latitude (radians). 2.1.1.3 Solar constant Ic 1370 1 0.033cos 2 td 10 / 365 (2.5) where Ic is the solar constant (W m-2); and td is the day of year. 2.1.1.4 Daily extraterrestrial solar irradiance 2 Iet , d 3600 Ic 24 a acos a b b 1 a b a sin sin and b cos cos (2.6) where Iet,d is the daily extraterrestrial solar irradiance (J m-2 day-1); Ic is the solar constant (W m-2); is the solar declination (radians); and is the site latitude (radians). 2.1.1.5 Daily total solar irradiance s It , d I et , d b0 b1 DL (2.7) 45 where It,d is the daily total solar irradiance (J m-2 day-1); Iet,d is the extraterrestrial solar irradiance (J m-2 day-1); b0 and b1 are empirical coefficients; s is the duration of sunshine hours (hours); and DL is the day length (hours). Note: The Angstrom coefficients b0 and b1 used for calculating daily solar radiation for different climate zones Climate zones Cold or temperate Dry tropical Humid tropical b0 0.18 0.25 0.29 b1 0.55 0.45 0.42 Direct and diffuse components It , d I et , d 0.07 It , d 2 I 1 2.3 I t , d I et , d 0.07 0.07 It , d I et , d 0.35 t , d I df , d I 1.33 1.46 I 0.35 It , d Iet , d 0.75 t , d I et , d t, d 0.23It , d 0.75 It , d I et , d I dr , d It , d I df , d (2.8) (2.9) where Idf,d is the daily diffuse solar irradiance (J m-2 day-1); Idr,d is the daily direct solar irradiance (J m-2 day-1); It,d is the daily total solar irradiance (J m-2 day-1); and Iet,d is the extraterrestrial solar irradiance (J m-2 day-1). 2.1.2 Hourly properties Hourly properties refer to meteorological properties for a given hour and day of year (or date and time). 2.1.2.1 Hour angle th 12 12 (2.10) where is the hour angle (radians); and th is the local solar time (hours). Note: hour angles will be negative for before solar noon (th < 12), positive for after solar noon (th > 12), and zero at exactly solar noon. 2.1.2.2 Solar position Solar inclination (and solar height) acos sin sin cos cos cos (2.11) where is the solar inclination (angle from vertical) (radians); is the solar declination (radians); is the hour angle (hours); and is the site latitude (radians). Note: Rather than its angle from vertical, solar angle can be specified alternatively as , the solar height or solar elevation, which is the solar angle from horizontal, determined by /2 - (radians). 46 Solar azimuth sin sin sin acos cos cos acos sin sin sin cos cos th 12 th 12 (2.12) where is the solar azimuth (angle from North in a clockwise direction) (radians); is the solar declination (radians); is the hour angle (hours); and is the site latitude (radians). 2.1.2.3 Hourly extraterrestrial solar irradiance Iet Ic sin Ic cos (2.13) where Iet is the hourly extraterrestrial solar irradiance (W m-2); Ic is the solar constant (W m-2); is the solar inclination (radians); and is the solar height (or solar elevation) (radians). Note: = /2 - . 2.1.2.4 Hourly total solar irradiance It a b cos th / 12 It , d 86400 a acos a b b 1 a b (2.14) 2 a sin sin and b cos cos where It is the hourly total solar irradiance (W m-2); It,d is the daily total solar irradiance (J m-2 day-1); th is the local solar hour (hours); and is the solar declination (radians); is the site latitude (radians). Direct and diffuse components It I et 0.22 It 2 It It 1 6.4 0.22 It I et 0.35 I df I 0.22 et 0.35< It I et K It 1.47 1.66 It I et K It I et It R (2.15) R 0.847 – 1.61sin 1.04sin 2 (2.16) K 1.47 – R /1.66 (2.17) I dr It I df (2.18) -2 -1 where Idf is the hourly diffuse solar irradiance (J m day ); Idr is the hourly direct solar irradiance (J m-2 day-1); It is the hourly total solar irradiance (W m-2); Iet is the 47 hourly extraterrestrial solar irradiance (W m-2); and is the solar height (or solar elevation) (radians). Note: = /2 - , where is the solar inclination. 2.1.2.5 Hourly air temperature Tmin Tset 24 th tss th t sr 1.5 Tset tsr 1.5 24 tss th tsr 1.5 Ta Tmin Tmax Tmin sin tsr 1.5 th t ss (2.19) tss tsr T Tmin Tset th tss th tss set tsr 1.5 24 tss tss tsr 1.5 Tset Tmin Tmax Tmin sin tss tsr (2.20) where Ta is the air temperature (C) at local solar time th (hours); Tmin and Tmax are the minimum and maximum air temperature (C), respectively; and tsr and tss are the times of sunrise and sunset, respectively (hours); and Tset is the air temperature (C) at sunset (tss). 2.1.2.6 Hourly wind speed Hourly wind speed (m s-1) is assumed uniform throughout the day and equal to the measured daily wind speed. 2.1.2.7 Saturated air vapor pressure es Ta 6.1078exp 17.269Ta Ta 237.3 (2.21) where es(Ta) is the saturated vapor pressure (mbar) at air temperature Ta (C). 2.1.2.8 Slope of the saturated vapor pressure curve 25029.4exp 17.269Ta Ta 237.3 Ta 237.32 (2.22) where is the slope of the saturated vapor pressure curve (mbar K-1 or equivalently, mbar C-1) at air temperature Ta (C). 2.1.2.9 Hourly air vapor pressure ea RH es (Ta ) 100 (2.23) where ea is the air vapor pressure (mbar); RH is the relative humidity (%); and es(Ta) is the saturated air vapor pressure (mbar) at air temperature Ta (C). Air vapor pressure deficit Air vapor pressure deficit is simply the difference between saturated and current air vapor pressure; that is, 48 D es (Ta ) ea (2.24) where D is the vapor pressure deficit (mbar); ea is the air vapor pressure (mbar); and es(Ta) is the saturated air vapor pressure (mbar) at air temperature Ta (C). 2.2 Canopy photosynthesis This section describes the amount of CO2 assimilated by the canopies. Essentially, calculations involve determining the solar irradiance within the canopies, calculating the CO2 assimilation rate by individual leaves, then scaling up to canopy assimilation rate. 2.2.1 PAR components within canopies There are four flux components within the canopies, and they are: Q p, dr (1 p)Qdr exp kdr L (2.25) Q p, dr , dr (1 p)Qdr exp kdr L Q p, dr , (2.26) Q p, dr Q p, dr, dr (2.27) 2 (1 p)Qdf 1 exp kdf L Q p, df kdf L (2.28) where Canopies flux components Qp,dr is the PAR irradiance for unintercepted beam with scattered beam (mol photons m-2 ground area s-1); Qp,dr,dr is the PAR irradiance for unintercepted beam without scattering (mol photons m-2 ground area s-1); Qp,dr, is the PAR irradiance of the scattered component only (mol photons m-2 leaf area s-1); and Q p, df is the mean diffuse irradiance (mol photons m-2 leaf area s-1). Note: Both Qp,dr, and Q p, df are based on a per unit leaf area (not per unit ground area as for the other two components: Qp,dr and Qp,dr,dr). PAR direct and diffuse irradiance Qdr I dr 0.5 4.55 (2.29) Qdf I df 0.5 4.55 (2.30) where Qdr and Qdf are, respectively, the hourly direct and diffuse PAR irradiance, both expressed in mol photons m-2 ground area s-1; and Idr and Idf are the hourly direct and diffuse solar irradiance, respectively (W m-2 ground area). Note: Total PAR irradiance is assumed 50% of total solar irradiance. It is then converted from unit W m-2 ground area to mol photons m-2 ground area s-1 by multiplying it with 4.55. 49 Canopy extinction coefficient for direct PAR kdr 0.5 0.5 sin cos (2.31) where kdr is the canopy extinction coefficient for direct PAR; is the solar height (or solar elevation) (radians); and is the solar inclination ( = /2 - ) (radians). Note: random distribution of leaves in the canopies is assumed. Canopy clustering coefficient (correcting for non-uniform distribution of canopies in the aerial space) 01 2 0 (2.32) L ln b (1 b ) exp kdr kdr L (1 b ) 1 1 L 3 L Lmax L Lmax 0 b (2.33) (2.34) where is the canopy clustering coefficient; 0 is the canopy clustering coefficient when the sun is at zenith (highest point in the sky); L is the total leaf area index (m2 leaf area m-2 ground area); Lmax is the maximum leaf area index for full canopy cover (taken as 4 m2 m-2); is the solar inclination (radians); and kdr is the canopy extinction coefficient for direct PAR. Canopy extinction coefficient for diffuse PAR kdf 0.6936 13.2910 L2 2.3648 L4 0.1701L6 1 22.6522 L2 4.0257 L4 0.2674 L6 (2.35) where kdf is the canopy extinction coefficient for diffuse PAR; and L is the total leaf area index (LAI) (m-2 leaf area m-2 ground area). Note: kdf has already been corrected for canopy clustering. Like that for kdr, the assumption in kdf is also that leaves are randomly distributed in the canopies. Canopy reflection and leaf absorption coefficients for PAR Canopy reflection coefficient for PAR, p, is taken as 0.04, and the leaf scattering coefficient for PAR, , is taken as 0.8. 2.2.2 PAR absorption by the leaves Qsl kdr Qdr Q p, df Q p, dr , Qsh Q p, df Q p, dr , (2.36) (2.37) where Qsl and Qsh are the PAR flux densities absorbed by the sunlit leaves and shaded leaves, respectively (mol photons m-2 leaf area s-1); kdr is the canopy extinction coefficient for direct PAR; Qdr is the hourly direct PAR irradiance (mol photons m-2 ground area s-1); Qp,dr, is the PAR irradiance of the scattered component only (mol 50 photons m-2 leaf area s-1); Q p, df is the mean diffuse irradiance (mol photons m-2 leaf area s-1); and is the leaf scattering coefficient (where in this case, it is also the leaf absorption coefficient) for PAR (0.8). Note: PAR flux densities absorbed (Qsl and Qsh) are based on a per unit leaf area (not per unit ground area). 2.2.3 Sunlit and shaded leaf area index 1 exp(kdr L) Lsl kdr (2.38) Lsh L Lsl (2.39) 2 where Lsl and Lsh are sunlit and shaded leaf area index, respectively (m leaf area m-2 ground area); L is the total leaf area index (m2 leaf area m-2 ground area); kdr is the canopy extinction coefficient for direct PAR; and is the canopy clustering coefficient 2.2.4 Canopy temperature Tf H c rac H s H c raa cp Tr (2.40) where Tf is the canopy (foliage) temperature (C); Tr is the air temperature at reference level (C); Hs and Hc are the soil and crop sensible heat fluxes, respectively (W m-2); raa is the aerodynamic resistance between the mean canopy flow and reference level (s m-1); rca is the bulk boundary layer resistance (s m-1); and cp is the volumetric heat capacity for air (1221.09 J m-3 K-1). 2.2.5 Temperature-dependent parameters There are some parameters whose values are sensitive to the canopy/foliage temperature Tf. Consequently, their values are adjusted according to (T 25)/10 (25) Q10 f where (25) is the parameter value at 25 ºC (Kc(25), Ko(25), (25) or Vc,max(25)); Tf is the canopy temperature (ºC); and Q10 is the relative change in the parameter for every 10 ºC change. Values for the model parameters at 25 ºC and their respective Q10 values are given below. Parameter values for the photosynthesis calculations. Parameters with subscript (25) denote their values at 25 ºC. (25) Kc(25) Ko(25) (25) Vc,max(25) Description Michaelis-Menten constant for CO2 Michaelis-Menten constant for O2 CO2 / O2 specificity factor Rubisco capacity rate Value Unit 300 mol mol-1 Q10 2.1 300000 mol mol-1 1.2 2600 mol mol-1 200 mol m-2 s-1 51 0.57 2.4 Michaelis-Menten constant for CO2 (T f 25)/10 Kc 300 2.1 (2.41) where Kc is the Michaelis-Menten constant for CO2 (mol mol-1); and Tf is the canopy temperature (ºC) Michaelis-Menten constant for O2 (T f 25)/10 Ko 300000 1.2 (2.42) where Ko is the Michaelis-Menten constant for CO2 (mol mol-1); and Tf is the canopy temperature (ºC) CO2/O2 specificity factor 2600 0.57 (T f 25)/10 (2.43) where is the CO2/O2 specificity factor; and Tf is the canopy temperature (ºC) CO2 compensation point O * a 2 (2.44) where * is the CO2 compensation point (mol mol-1); Oa is the ambient O2 concentration in air (210000 mol mol-1); and is CO2/O2 specificity factor. Rubisco capacity rate (T 25)/10 200 2.4 f Vc,max 1 exp 0.29 T f 40 (2.45) where Vc,max is the Rubisco capacity rate (mol m-2 leaf area s-1); and Tf is the canopy temperature (ºC). Note: Vc,max is corrected additionally for temperatures greater than 40 ºC after which causes a rapid decline in the capacity rate due to Rubisco degradation. 2.2.6 Gross leaf CO2 assimilation sl / sh MIN vc , vq, sl / sh , vs (2.46) where sl/sh is the gross leaf CO2 assimilation (mol CO2 m-2 leaf area s-1) for either sunlit (subscript sl) or shaded (subscript sh) leaves; and MIN() is a function to select the minimum of the three assimilation rates (vc, vq,sl/sh and vs). Rubisco-limited assimilation (vc) vc Vc,max Ci * Kc 1 Oa Ko Ci (2.47) where vc is the Rubisco-limited leaf CO2 assimilation rate (mol CO2 m-2 leaf area s-1); Kc is the Michaelis-Menten constant for CO2 (mol mol-1); Ko is the Michaelis- 52 Menten constant for CO2 (mol mol-1); * is the CO2 compensation point (mol mol-1); Oa is the ambient O2 concentration in air (210000 mol mol-1); Ci is the intercellular CO2 concentration (245 mol mol-1); and Vc,max is the Rubisco capacity rate (mol m-2 leaf area s-1). Note: Vc,max, *, Kc and Ko must be corrected for canopy temperature. Light-limited assimilation (vq) vq, sl / sh em Qsl / sh Ci * Ci 2 * (2.48) where vq,sl/sh is the light-limited leaf CO2 assimilation rate (mol CO2 m-2 leaf area s-1) for either sunlit (subscript sl) or shaded (subscript sh) leaves; * is the CO2 compensation point (mol mol-1); Ci is the intercellular CO2 concentration (245 mol mol-1); Qsl/sh is the PAR absorbed by either sunlit (subscript sl) or shaded (subscript sh) leaves (mol m-2 leaf area s-1); α is the leaf absorption of PAR (0.8); and em is the intrinsic quantum efficiency or quantum yield (0.08). Note: * must be corrected for canopy temperature. Sink-limited assimilation (vs) vs Vc,max (2.49) 2 where vs is the sink-limited leaf CO2 assimilation rate (mol CO2 m-2 leaf area s-1); and Vc,max is the Rubisco capacity rate (mol m-2 leaf area s-1). Note: Vc,max must be corrected for canopy temperature. 2.2.7 Gross canopy CO2 assimilation canopy sl Lsl sh Lsh (2.50) where canopy is the gross canopy CO2 assimilation (mol m-2 ground area s-1); sl and sh are the gross leaf CO2 assimilation rates for sunlit and shaded leaves, respectively (mol m-2 leaf area s-1); and Lsl and Lsh are the sunlit and shaded leaf area index, respectively (m2 leaf area m-2 ground area). 2.2.8 Daily integration Numerical method Gaussian integration is used to obtain the daily gross canopy photosynthesis. Five points (N=5) over the diurnal period (from sunrise to sunset) are selected, and for each selected hour, the gross canopy CO2 assimilation is calculated. Note: The daily gross canopy photosynthesis, canopy,d, must be converted from mol CO2 m-2 ground area day-1 to g CH2O m-2 ground area day-1 before proceeding to determine the plant respiration rates. 2.3 Energy Balance The energy balance of the soil-plant-atmosphere system is described using the electrical network analogy, where heat fluxes traverse a series of resistances to reach a reference level above the canopies. Such a network is as shown in Fig. 2.1. 53 Fig. 2.1. Energy balance described as a network of resistances. Key: ET and ETc and ETs are the latent heat fluxes from the system, crop and soil, respectively; H, Hc and Hs are the sensible heat fluxes from the system, crop and soil, respectively; Rn is the net radiation flux into the system; G is the heat conduction into the soil; Tr, Tf, To and Ts are the temperatures for the reference height, crop, mean canopy flow and soil, respectively; er, es and eo are the vapor pressure at the reference height, soil surface and mean canopy flow, respectively; es(T) is saturated vapor pressure at temperature T; raa is the aerodynamic resistance between the mean canopy flow and reference height; rsa is the aerodynamic resistance between the soil and mean canopy flow; rca is the bulk boundary layer resistance; rcs and rss are the canopy and soil surface resistance, respectively. 2.3.1 Net radiation Rn 1 p It RnL (2.51) b 1 b s DL RnL RnL (2.52) RLd RLu RnL (2.53) RLu Ta 273.15 4 (2.54) RLd 9.35 106 Ta 273.15 6 (2.55) where Rn is the net radiation (W m-2); It is the hourly total solar irradiance (W m-2); p is the surface albedo (typically, 0.15); RnL is the corrected net longwave radiation (after adjusting for cloud cover) (W m-2); R'nL is the uncorrected net longwave radiation (W m-2); s is the sunshine hours (hours); DL is the daylength (hours); b is an 54 empirical coefficient (between 0.1 and 0.3, taken as 0.2); RLd is the downward longwave radiation (W m-2); RLu is the upward longwave radiation (W m-2); Ta is the air temperature (C); and is the Stefan-Boltzmann constant (5.67 x 10-8 W m-2 K-4). 2.3.2 Energy available to crop and soil A Ac As Rn G (2.56) Ac 1 dr , Rn (2.57) As dr , Rn G (2.58) dr , exp kdr L (2.59) where A is the net radiation available to the system (soil and crop); Ac is the fraction of net radiation available to the crop (W m-2); As is the fraction of net radiation available to the soil (W m-2); G is the soil heat flux (W m-2); L is the total leaf area index (LAI); kdr is the canopy extinction coefficient for direct solar radiation; is the correction to the kdr due to canopy clustering, taken from Eq. (2.32)-(2.34); and α is the scattering coefficient for total solar radiation (0.5). 2.3.3 Soil/ground heat flux G 0.35 dr , Rn cos (2.60) where G is the soil heat flux (W m-2); dr, is the penetration function from Eq. (2.59); Rn is the net radiation (W m-2); and is the solar inclination (radians). 2.3.4 Wind speed profile This section describes properties related to how the wind speed varies with height above and within the plant canopies. 2.3.4.1 Crop roughness length and zero plane displacement d 0.64h z0 0.26 h d (2.61) (2.62) where d is the zero plane displacement height (m); z0 is the crop roughness length (m); and h is the plant height (m). 2.3.4.2 Friction velocity k u ( h) u* ln 1 0.26 (2.63) where u* is the friction velocity (m s-1); k is the von Karman constant (0.4); and u(h) is the wind speed (m s-1) at the canopy top; that is, wind speed at plant height h. Note: It is assumed that u(h) is equal to the daily wind speed measured by the weather station. 55 2.3.4.3 Wind speed above and within the canopies u* z d ln k z0 u( z) z u* h d k ln z exp 1 h 0 zh zh (2.64) where u(z) is the wind speed (m s-1) at height z (m); h is the plant height (m); d is the zero plane displacement height (m); z0 is the crop roughness length (m); k is the von Karman constant (0.4); u* is the friction velocity (m s-1); and is the wind speed extinction coefficient (taken as 2). 2.3.4.4 Eddy diffusivity z K ( z ) K (h) exp n 1 h (2.65) K (h) ku*h (2.66) where K(z) and K(h) are the eddy diffusivities at height z and at the canopy top, respectively (m2 s-1); h is the plant height (m); k is the von Karman constant (0.4); u* is the friction velocity (m s-1); and n is the eddy diffusivity extinction coefficient (taken as 2). 2.3.5 Flux resistances The heat fluxes have to traverse various types of resistances within the soilplant-atmosphere system. This section describes each of those resistance types. 2.3.5.1 Aerodynamic resistances Soil surface to mean canopy flow ras h exp(n) zs 0 z d exp n 0 exp n n K ( h) h h (2.67) where ras is the resistance between the soil surface and the mean canopy flow (s m-1); h is the plant height (m); k is the von Karman constant (0.4); u* is the friction velocity (m s-1); n is the eddy diffusivity extinction coefficient (taken as 2); d is the zero plane displacement height (m); z0 is the crop roughness length (m); and zs0 is the soil surface roughness length (m) Note: for flat, tilled land, zs0 can be taken as 0.004 m. Mean canopy flow to reference level raa z0 d 1 1 z d ln r exp n 1 1 ku* h d nku* h (2.68) where raa is the resistance between the mean canopy flow and the reference level (s m-1); h is the plant height (m); k is the von Karman constant (0.4); u* is the friction velocity (m s-1); n is the eddy diffusivity extinction coefficient (taken as 2); d is the 56 zero plane displacement height (m); z0 is the crop roughness length (m); and zr is the reference height (m). 2.3.5.2 Bulk boundary layer resistance rac 0.012 L 1 exp 2 u (h) w (2.69) where rac is the bulk boundary layer resistance (s m-1); L is the total leaf area index (m2 leaf area m-2 ground area); w is the mean leaf width (m); u(h) is the wind speed at the canopy top (i.e., at plant height h) (m s-1); and is the wind speed extinction coefficient (taken as 2). 2.3.5.3 Canopy resistance a1 I PAR, t rst a2 I PAR, t rst L rsc rst 0.5 Lcr (2.70) L 0.5Lcr L 0.5Lcr (2.71) where rsc is the canopy resistance (s m-1); rst is the leaf stomatal resistance (s m-1); L is the total leaf area index (m2 leaf area m-2 ground area); Lcr is the critical leaf area index (m2 leaf area m-2 ground area, taken as 4); and IPAR,t is the total PAR irradiance (W m-2); a1 and a2 are empirical coefficients, dependent on the crop type. Note: Total PAR irradiance is assumed 50% of total solar irradiance: IPAR,t = 0.5It. 2.3.5.4 Soil surface resistance l rss, dry p Dm, v 1 v,1 rss rss, dry exp v, sat (2.72) (2.73) where rss is the soil surface resistance (s m-1); Dm,v is the vapor diffusion coefficient in air (24.7 x 10-6 m2 s-1); is soil tortuosity (can be taken as 2); p is soil porosity; l is the dry soil layer thickness (taken as the first soil layer thickness) (m); v,1 is the volumetric soil water content of the first soil layer (m3 m-3); v,sat is the volumetric saturated soil water content (m3 m-3); and is the soil pore-size distribution index. Note: The soil profile is divided into two or more layers (see section 2.4.1). 2.3.6 Total latent heat flux ET Cc PM c Cs PM s (2.74) 57 raa rac PM c 1 rsc raa rac A c p D ras Ac raa ras PM s 1 rss raa ras A c p D rac As Cc 1 Rc Ra Rs Rc Ra 1 Cs 1 Rs Ra Rc Rs Ra 1 (2.75) (2.76) (2.77) (2.78) Ra raa (2.79) Rc rac rsc (2.80) Rs ras rss (2.81) where ET is the total latent heat flux (W m-2); raa is the aerodynamic resistance between the mean canopy flow and reference height (s m-1); rsa is the aerodynamic resistance between the soil and mean canopy flow (s m-1); rca is the bulk boundary layer resistance (s m-1); rcs and rss are the canopy and soil surface resistance, respectively (s m-1); A, As and Ac are energy available to the system (total), soil and crop, respectively (W m-2); is the slope of the saturated vapor pressure curve (mbar K-1); is the psychometric constant (0.658 mbar K-1); D is the vapor pressure deficit (mbar); and cp is the volumetric heat capacity for air (1221.09 J m-3 K-1). Note: To convert latent heat fluxes from unit W m-2 (equivalent to J m-2 s-1) to depth of water per second (mm s-1), simply divide it by , the latent heat of vaporization of water (2454000 J kg-1). For example, latent heat flux 120 W m-2 is equivalent to 120 J m-2 s-1 2454000 J kg-1 1000 mm water kg m-3 4.9 105 mm s-1 where the density of water, water, is approximately 1000 kg m-3. 2.3.7 Air vapor pressure deficit at the mean canopy flow ra D0 D a A ET c p (2.82) where D0 is the vapor pressure deficit at the mean canopy flow (mbar); ET is the total latent heat flux (W m-2); raa is the aerodynamic resistance between the mean canopy flow and reference height (s m-1); A is the total energy available to the system (W m-2); is the slope of the saturated vapor pressure curve (mbar K-1); is the psychometric constant (0.658 mbar K-1); D is the vapor pressure deficit (mbar); and cp is the volumetric heat capacity for air (1221.09 J m-3 K-1). 58 2.3.8 Latent heat fluxes for crop and soil ETs ETc As c p D0 ras rss ras (2.83) ras Ac c p D0 rac rsc rac (2.84) rac where ETs and ETc are the soil and crop latent heat fluxes, respectively (W m-2); As and Ac are energy available to the soil and crop, respectively (W m-2); rsa is the aerodynamic resistance between the soil and mean canopy flow (s m-1); rca is the bulk boundary layer resistance (s m-1); rcs and rss are the canopy and soil surface resistance, respectively (s m-1); is the slope of the saturated vapor pressure curve (mbar K-1); is the psychometric constant (0.658 mbar K-1); D0 is the vapor pressure deficit at the mean canopy flow (mbar); and cp is the volumetric heat capacity for air (1221.09 J m-3 K-1). 2.3.9 Sensible heat fluxes for crop and soil Hs Hc As rss ras c p D0 ras rss ras (2.85) Ac rsc rac c p D0 rac rsc rac (2.86) where Hs and Hc are the soil and crop sensible heat fluxes, respectively (W m-2); As and Ac are energy available to the soil and crop, respectively (W m-2); rsa is the aerodynamic resistance between the soil and mean canopy flow (s m-1); rca is the bulk boundary layer resistance (s m-1); rcs and rss are the canopy and soil surface resistance, respectively (s m-1); is the slope of the saturated vapor pressure curve (mbar K-1); is the psychometric constant (0.658 mbar K-1); D0 is the vapor pressure deficit at the mean canopy flow, respectively (mbar); and cp is the volumetric heat capacity for air (1221.09 J m-3 K-1). 2.3.10 Daily integration Numerical method Gaussian integration is used to obtain the daily latent and sensible heat fluxes. Knowing the daily latent heat fluxes will enable us to determine the daily amount of water transpired (by plants) and evaporated (by soil). Five points (N=5) over 24 hours in a day are selected, and for each selected hour, the heat fluxes are calculated. 2.4 Soil water For accurate simulation of the water content in the soil, the soil profile has to be divided into two or more layers, and for each layer, the soil water content is simulated. Simulation of soil water profile is intensive and time-consuming because it 59 involves repetitious calculations. This is because hydraulic conductivity is sensitive to the soil water content. 2.4.1 Partitioning of soil profile into several layers Fig. 2.2 shows that the soil profile is divided from the soil surface into six (N = 6) consecutive layers, where soil layer i (i = 1 to 6) has a thickness of si (m), and the depth from the soil surface to the middle of layer i is zi (m). Water flux into soil layer i is denoted as qi (m day-1). Fig. 2.2. Water flow in a soil profile which is divided into six successive layers Assumptions 1. Every soil layer has equal soil properties with each other. This means that all soil layers have the same soil texture and soil water retention properties. 2. No water table effect, which means that there is no capillary rise of water from the groundwater into the soil profile. 3. No irrigation is supplied and no surface runoff occurs. 60 4. The soil below the last soil layer is uniformly wet and it has the same water content as the last soil layer. This means that water flows out of the last soil layer (i.e., q7) due to gravitational pull alone (i.e., no matric suction gradient). 2.4.2 Soil layer depth and cumulative thickness zi N 0.5 si si 1 i 1 where s0 0 (2.87) where zi is the depth of soil layer i from the soil surface (m), taken from the middle of that soil layer to the soil surface; N is the number of soil layers (taken as 6); si and si-1 are the thickness of soil layer i and i-1, respectively (m). Cumulative thickness Si i sj (2.88) j 1 where Si is the cumulative thickness of soil layer i (m); that is, the sum of the thickness of layer i and all its preceding layers. 2.4.3 Actual evaporation Ea ETs RD, e RD, e (2.89) 1 1 3.6073 v,1 v, sat -9.3172 (2.90) where Ea is the actual evaporation (m day-1); ETs is the potential evaporation (m day-1); RD,e is the reduction factor for evaporation (ranging from 0 to 1); and v,1 and v,sat are the current soil water content in the first soil layer (i=1) and saturated soil water content, respectively (m3 m-3). Note: The soil water content from the first soil layer (i=1), v,1, is taken because all evaporation occurs from this layer only (as this first layer is in contact with the atmosphere). 2.4.4 Actual transpiration Ta ETc RD,t (2.91) 1 v, root v, wp RD, t v, cr v, wp 0 v, root v, cr v, wp v, root v, cr (2.92) v, root v, wp v, cr v, wp 0.5 v, sat v, wp (2.93) where Ta is the actual transpiration (m day-1); ETc is the potential transpiration (m day-1); RD,t is the reduction factor for transpiration (ranging from 0 to 1); v,root is the 61 total volumetric water content in the root zone (m3 m-3); v,wp is the volumetric water content at wilting point (m3 m-3); and v,sat is the volumetric water content at saturation (m3 m-3). The algorithm to determine the total volumetric water content in the root zone, v,root, is as follows: v, root 1 n i (2.94) d root i 1 in v, i si i v, i si Si droot i n (2.95) where i is the water content in soil layer i (m); droot is the rooting depth (m); si is the thickness of soil layer i (m); and Si is the cumulative thickness of soil layer i (m). The amount of water in the root zone is the summation of water content from the first soil layer (i=1) until the n-th layer. The value of n is such that in the n-th soil layer, the following relationship is true: Sn 1 Sn droot Sn 1 (2.96) 2.4.5 Root extraction of water The algorithm to determine the amount of water extracted by roots in each soil layer is as follows: Tai Ta i i 1 (2.97) j 1.8c j 0.8c j 2 (2.98) c j MIN 1, S j droot (2.99) where Tai is the amount of water extracted by roots in soil layer i (m day-1); droot is the rooting depth (m); Sj is the cumulative thickness of soil layer j (m); and MIN() is the minimum of the enclosed values. 2.4.6 Hydraulic conductivity The hydraulic conductivity in soil layer i (ki, m day-1) is read from the chart depicting the relationship between hydraulic conductivity and volumetric water content (Fig. 2.3). No hysterisis effect is assumed. 2.4.7 Matric suction head The soil matric suction in soil layer i (Hmi, m) is read from the chart depicting the relationship between soil suction and volumetric water content (Fig. 2.4). No hysterisis effect is assumed. Note: at soil saturation, suction is taken as 0 m. 62 1.2 1 0.8 hydraulic conductivity 0.6 (m day-1) 0.4 0.2 0 0 0.2 0.4 0.6 0.8 water content (m3 m-3) 1 Fig. 2.3. Relationship between hydraulic conductivity and volumetric soil water content 10000 1000 100 log-scale, suction (m) 10 1 0.1 0 0.1 0.2 0.3 0.4 water content (m3 m-3) 0.5 Fig. 2.4. Relationship between soil suction and volumetric soil water content 2.4.8 Gravity head H gi zi (2.100) where Hgi is the gravity head in soil layer i (m); and zi is the depth of the middle of soil layer i from the soil surface (m). 2.4.9 Hydraulic gradient Hi H mi H gi (2.101) where in soil layer i, Hi is the hydraulic gradient (m), Hmi is matric suction head (m), and Hgi is the gravity head (m). 63 2.4.10 Water content Water flux Darcy’s law is used to describe the water flow in the soil. Water flow is taken to occur from the middle of layer i-1 to the middle of layer i. Water flux into soil layer i is thus: i 1 R Ea Tai H i H i 1 qi k Tai 1 i N zi zi 1 k i N 1 N ki (2.102) ki 1si 1 ki si si 1 si (2.103) where subscripts i-1 and i denote soil layer i-1 and i, respectively; q is the water flux (m day-1); R is the amount of daily rainfall (m day-1); Ea is the actual daily soil evaporation (occurs only from the first soil layer) (m day-1); Ta is the daily extraction of water by roots (actual plant transpiration) (m day-1); k is the weighted average of the hydraulic conductivities of layer i and i-1 (m day-1); k and s are the soil layer’s hydraulic conductivity and thickness, respectively (m); and H is the hydraulic gradient (m). Note: Water flux out of the last soil layer (i = N) is denoted by qN+1, and it is merely equal to kN because of the assumption that the soil below the last layer is uniformly wet and it has the same water content as the last soil layer. Consequently, water flux is only due to gravity gradient (no matric suction gradient). In this case, qN+1 = kN. Net flux qˆi qi qi 1 (2.104) where qˆi is the net flux in soil layer i (m day-1); and qi and qi+1 are the water flux into soil layer i and i+1, respectively (m day-1). Water content i,t 1 i,t qˆi (2.105) where i,t and i,t+1 are the water content in soil layer i (m) at time step t and t+1, respectively; and qˆi is the net flux in soil layer i (m day-1). 2.4.11 Daily integration Hydraulic conductivity is sensitive to soil water content especially at near saturation. Consequently, it is vital that the water fluxes are calculated using very small time steps because using too large a time step (e.g., 1 day) may cause unrealistically large fluctuations or changes in the soil water content. To overcome this problem, the single time interval is divided into f number of subintervals, where the daily water content is simulated at successive subintervals. 64 Note: The larger the f, the more accurate the simulation results, but the slower the simulation run. The value of f depends on the hydraulic conductivity value, k; a large k often means a large f is required for accurate results. Typically, if the time step size is 1 day (i.e., t = 1), f should be more than 500 (i.e., about 170 seconds). 2.5 Plant growth development Food produced via photosynthesis is now used for plant maintenance (supporting processes for continual plant survival) and growth (synthesis of new cells). 2.5.1 Growth development stage and development rate s,t 1 s,t r ,t t (2.106) where s,t and s,t+1 are the growth development stage at time t and subsequent time step t+1; t is the interval for each time step (days); r,t is the growth development rate (days-1) at time t. Note: The scale for the growth development stage ranges from 0 to 2, where milestones along this scale are shown below. Scale 0 1 2 Growth stage Planting Flowering (anthesis) Maturity Growth development rate, r, is read from a chart which depicts its linear relationship with air temperature, as exemplified below (Fig. 2.5). 0.08 0.06 r 0.04 0.02 0 0 10 20 30 40 temperature (°C) Fig. 2.5. Dependence of growth development rate on air temperature 2.5.2 Temperature sum Daily temperature sum 0 Tts Tavg Tb Tavg Tb Tavg Tb (2.107) 65 where Tts is the daily temperature sum (ºC day); Tb is the base temperature for the crop (ºC); and Tavg is the mean of the minimum and maximum air temperature (ºC). Cumulative temperature sum The summation of each day’s temperature sum gives the cumulative temperature sum, and it is calculated by Tts Tts, t (2.108) t where Tts is the cumulative temperature sum (ºC day); and Tts,t is the temperature sum at day t (ºC day). Note: An example showing the determination of the daily temperature sum Tts and cumulative temperature sum Tts (base temperature Tb is 5 ºC) which depends on the average air temperature Tavg. Day Tavg Tts Tts 1 4 0 0 2 5 0 0 3 8 3 3 4 10 5 8 5 12 7 15 6 10 5 20 7 8 3 23 8 5 0 23 9 8 3 26 2.5.3 Maintenance respiration 2Ta 25 10 Wgreenleaves Wleaves RM RM RM i plant parts kM , iWi (2.109) kM , greenleavesWgreenleaves kM , stemWstem kM , rootsWroots kM , storageWstorage where RM is the maintenance respiration requirement (g CH2O m-2 ground area day-1); kM,i is the maintenance respiration coefficient (g CH2O g-1 dry matter day-1) for plant part i; and Wi is the weight (g dry matter m-2 ground area) for plant part i; and Ta is the air temperature (C). Maintenance respiration coefficient (at 25 C air temperature) for various plant parts Plant part green leaves, kM,greenleaves stem, kM,stem roots, kM,roots storage organs, kM,storage g CH2O g-1 dry matter day-1 0.030 0.015 0.015 0.010 Note: Maintenance respiration is corrected for air temperature and plant age. 66 2.5.4 Growth respiration G i plant parts Fi Gi Fgreenleaves Ggreenleaves Fstem Gstem Froots Groots Fstorage Gstorage (2.110) where G is the total glucose requirement (g CH2O g-1 dry matter); Gi is the glucose requirement for each plant part i (i.e., green leaves, stem, roots and storage organs) (g CH2O g-1 dry matter); and Fi is the fraction of dry matter of the individual plant parts. General glucose requirement for the synthesis of various plant parts g CH2O g-1 dry matter 1.463 1.513 1.444 1.415* Plant part green leaves, Ggreenleaves stem, Gstem roots, Groots storage organs, Gstorage * highly variable, dependent on crop type 2.5.5 Weight of plant parts (except leaves) canopy, d RM Wi, t 1 Wi, t Fi G t (2.111) where Wi,t and Wi,t+1 are the weights (g m-2 ground area) of a given plant part i (stem, roots or storage organs) at time step t and subsequent time step t+1, respectively; t is the interval for each time step (days); canopy,d is the daily gross canopy CO2 assimilation (g CH2O m-2 ground area day-1); RM is the maintenance respiration requirement (g CH2O m-2 ground area day-1); G is the total glucose requirement (g CH2O g-1 dry matter); and Fi is the fraction of dry matter of the individual plant parts. Note: The weight gain of leaves is calculated differently due to leaf death. 2.5.6 Leaf death Dleaves MAX Dage , Dshade (2.112) where Dleaves is the actual death rate of leaves (day-1); and MAX() is the maximum of the enclosed values. As shown above, there are two possible reasons for leaf death: 1) leaf age (Dage), and 2) self-shading of leaves (Dshade). Death due to age 0 Dage r 2 s r 0.1 2 s 1.0 0.1 2 s 1.0 (2.113) 2 s 0.1 67 where Dage is the leaf death rate due to leaf age (day-1); and r and s are the growth development rate (day-1) and growth development stage (unitless), respectively. Death due to self-shading 0 Dshade L Lcr MIN 0.03, 0.03 Lcr L Lcr L Lcr (2.114) where Dshade is the leaf death rate due to leaf self-shading (day-1); L and Lcr are the LAI and critical LAI, respectively (m2 m-2); and MIN[] is function to determine the minimum of the enclosed values. Note: Lcr is taken as 4 m2 m-2. 2.5.7 Weight of leaves Dead leaves Wdeadleaves, t 1 Wdeadleaves, t Wgreenleaves, t Dleaves, t t (2.115) where Wdeadleaves,t and Wdeadleaves,t+1 are the weights (g m-2 ground area) of dead leaves at time step t and subsequent time step t+1, respectively; t is the interval for each time step (days); and Dleaves,t is the death rate of leaves at time step t (day-1). Green (alive) leaves Wgreenleaves, t 1 Wgreenleaves, t canopy, d RM Fgreenleaves G t W greenleaves, t Dleaves, t (2.116) where Wgreenleaves,t and Wgreenleaves,t+1 are the weights (g m-2 ground area) of green leaves at time step t and subsequent time step t+1, respectively; t is the interval for each time step (days); Dleaves,t is the death rate of leaves at time step t (day-1); canopy,d is the daily gross canopy CO2 assimilation (g CH2O m-2 ground area day-1); RM is the maintenance respiration requirement (g CH2O m-2 ground area day-1); G is the total glucose requirement (g CH2O g-1 dry matter); and Fgreenleaves is the fraction of dry matter of green leaves. 2.5.8 Leaf area index Lt Wgreenleaves,t SLAt (2.117) where Lt is the leaf area index (m2 m-2) at time step t; Wgreenleaves,t is the weight of green leaves (g m-2 ground area) at time step t; and SLAt is the specific leaf area (m2 g-1, taken as 0.022 m2 g-1) at time step t. 2.5.9 Plant height dh ht 1 ht t dt (2.118) 68 b b h exp b1Tts dh Tts 0 1 m 2 dt 1 b0 exp b1Tts (2.119) where ht and ht+1 are the plant heights (m) at time t and subsequent time step t+1; t is the interval for each time step (days); Tts is the accumulated temperature sum (ºC day); Tts is the temperature sum (ºC day); hm is the maximum possible height of the plant (m); and b0 and b1 are the intercept (unitless) and slope (ºC-1 day-1) coefficients, respectively. 2.5.10 Root elongation v, t v, wp or s 1 d root , t d root , t 1 MIN d m , d root , t d g t v, t v, wp and s 1 (2.120) where droot,t and droot,t+1 are the rooting depth (m) at time step t and t+1, respectively; dm is the maximum rooting depth (m); dg is a constant root elongation rate, denoting rooting depth increase per day (m day-1, taken as 0.012 m day-1); t is the time step interval (days); s is the growth development stage; v,t is the volumetric soil water content at time t (m3 m-3); v,wp is volumetric soil water content at permenant wilting point (m3 m-3); and MIN[] is the minimum function to determine the smallest of the enclosed values. Note: no root death is assumed. 2.5.11 Effects of water stress Insufficient water limits growth according to the ratio between actual and potential plant transpiration: RD, t Ta ETc (2.121) where RD,t is the reduction factor for growth (ranging from 0 for zero growth to 1 for no growth suppression due to water stress); and Ta and ETc are the actual and potential transpiration rates, respectively (m day-1). The amount of assimilates potentially produced (i.e., in the absence of water stress) is reduced in proportion to the level of water stress: canopy , d canopy, d RD,t (2.122) and plant height growth rate is reduced to dh dh RD, t dt dt (2.123) as well as root elongation rate to d g d g RD,t (2.124) 69 2.6 Summary This section describes the flow or order of calculations to simulate the growth of a general crop. It also list the symbols used throughout this report and the model parameters required. The various components of the model are shown in Fig. 2.6. Fig. 2.6. Overview of the gcg model components 70 2.6.1 Calculations flow This section summarizes, using flowcharts (Fig. 2.7 to 2.15), the flow of calculations as described in the earlier sections. 2.6.1.1 Main flow Fig. 2.7. Main program flow for the generic crop growth model 71 2.6.1.2 Meteorology Fig. 2.8. Program flow to determine the daily weather properties 72 Fig. 2.9. Program flow to determine the hourly weather properties 73 2.6.1.3 Photosynthesis Fig. 2.10. Program flow to determine the daily gross canopy photosynthesis 74 Fig. 2.11. Program flow to determine the gross canopy assimilation rate 75 2.6.1.4 Energy balance Fig. 2.12. Program flow to determine the daily evapotranspiration 76 Fig. 2.13. Program flow to determine the various heat fluxes 77 2.6.1.5 Soil water Fig. 2.14. Program flow to determine the soil water content 78 2.6.1.6 Respiration Fig. 2.15. Program flow to determine the maintenance and growth respiration rates and the gains in the plant parts’ weights, leaf area index, plant height and rooting depth 2.6.2 Model parameters The following are parameters that must be measured or supplied to the model: 1. Meteorological properties: a. Daily weather properties: sunshine hours (s), min. and max. air temperature (Tmin and Tmax), relative humidity (RH), wind speed (u) and rain (R). b. Site latitude () and day of year (td). c. Reference height (zr) at which meteorological properties were measured. 79 2. Coefficients: a. Angstrom coefficients, b0 and b1. These (b0, b1) parameters are dependent on climate zones and can be taken generally as (0.18, 0.55) for cold temperate zones, (0.25, 0.45) for dry tropical zones, and (0.29. 0.42) for humid tropical zones. b. Surface albedo (p) which is typically 0.15 for most surfaces. c. Empirical coefficient, b, for correcting net radiation for cloud cover. It varies between 0.1 to 0.3. As an average, 0.2 can be taken. d. Extinction coefficients for wind speed () and eddy diffusivity (n). Both can be taken as 2. e. Soil surface roughness length (zs0). For flat, tilled land, it can be taken as 0.004 m. f. Empirical coefficients a1 and a2 for the relationship between stomatal resistance and PAR irradiance. 3. Plant properties: a. Initial values for plant height (h), rooting depth (droot) and dry weights (W) for plant parts such as stem, leaves, roots and storage organs. b. Mean leaf width (w). c. Root elongation rate (dg) and maximum rooting depth (dm). d. Critical LAI (Lcr) and LAI for maximum canopy cover (Lmax). Both can be 4 and 3 m2 m-2, respectively. e. Specific leaf area (SLA). f. Intercellular CO2 concentration (Ci) which can be taken as 245 mol mol-1. g. Intrinsic quantum efficiency or quantum yield (em) where for most plants, it can be taken as 0.08 mol mol-1. h. Relationship between growth development rate (r) and air temperature. i. Base temperature for crop growth (Tb). j. Maintenance respiration coefficient (kM) and glucose requirement for growth (G) for the various plant parts. k. Plant height properties: maximum height (hm), growth coefficients (b0 and b1). 4. Soil properties a. For each soil layer within the soil profile, the following must be specified: its thickness (si) and initial volumetric soil water content (v). b. For the first soil layer, the following must be specified additionally: pore-size distribution index (), porosity (p) and tortuosity (). Soil tortuosity can be taken as 2. 80 c. All soil layers are assumed equal in the following specified properties: i. Saturated and wilting point volumetric soil water content (v,sat and v,wp) ii. Relationship between hydraulic conductivity (k) and matric suction head (Hm) with volumetric soil water content. 2.6.3 Main symbols The main symbols used in this chapter are summarized below. Note that some symbols (such as and ) have more than one meaning, depending on their context. Symbol * 0 canopy canopy,d cp dr, ET ETc Description extinction coefficient for wind speed fraction of PAR absorbed (0.8) scattering coefficient (0.5 for total solar radiation, or 0.8 for PAR) solar elevation or height (from horizontal) solar declination solar azimuth (from North) psychometric constant (0.658) latent heat of vaporization of water (2454000) pore-size distribution index site latitude pi constant (3.14159) solar inclination (from vertical) hour angle CO2 / O2 specificity factor (2600) soil tortuosity Stefan-Boltzmann constant (5.67 x 10-8) canopy clustering coefficient slope of the saturated vapor pressure curve soil water content, expressed as water depth CO2 compensation point canopy clustering coefficient when the sun is at zenith gross canopy assimilation rate of CO2 daily gross canopy assimilation rate of CO2 volumetric heat capacity of air (1221.09) penetration function for direct solar radiation (corrected for scattering) total latent heat flux density latent heat flux density of crop 81 Unit radians radians radians mbar K-1 J kg-1 radians radians radians mol mol-1 W m-2 K-4 mbar K-1 m mol mol-1 mol CO2 m-2 ground area s-1 g CH2O m-2 ground area day-1 J m-3 K-1 W m-2 W m-2 ETs p r s sh sl t v v,cr v,root v,sat v,wp A Ac As b0, b1 b0, b1 Ci d dg dm droot D D0 Dage DL Dleaves Dm,v Dshade ea em es(Ta) Ea ETc ETs Fi G G latent heat flux density of soil soil porosity growth development rate growth development stage gross leaf assimilation rate of CO2 for shaded leaves gross leaf assimilation rate of CO2 for sunlit leaves size of each time step volumetric water content critical volumetric water content volumetric water content in the root zone saturated volumetric water content wilting point volumetric water content total energy supply fraction of energy available to the plant fraction of energy available to the soil Angstrom coefficients plant height growth coefficients intercellular CO2 concentration in air (245) zero plane displacement root elongation rate maximum rooting depth rooting depth vapor pressure deficit vapor pressure deficit at the mean canopy flow leaf death due to age day length leaf death vapor diffusion coefficient in air (24.7 x 10-6) leaf death due to self-shading air vapor pressure quantum efficiency (0.08) saturated vapor pressure at air temperature Ta actual soil evaporation potential transpiration potential evaporation dry matter fraction for plant part i (green leaves, stem, roots or storage) soil (ground) heat flux density total glucose requirement for growth 82 W m-2 day-1 mol CO2 m-2 leaf area s-1 mol CO2 m-2 leaf area s-1 day m3 m-3 m3 m-3 m3 m-3 m3 m-3 m3 m-3 W m-2 W m-2 W m-2 b0 (unitless), b1 (C day-1) mol mol-1 m m day-1 m m mbar mbar day-1 hour day-1 m2 s-1 day-1 mbar mol mol-1 mbar m day-1 m day-1 m day-1 W m-2 g CH2O g-1 dry matter Gi h hm Hc Hgi Hi Hmi Hs Ic Idf Idf,d Idr Idr,d Iet Iet,d IPAR It It,d k ki kdf kdr ki kM,i K(z) Kc Ko l L Lcr Lmax Lsh Lsl n Oa p qi glucose requirement for growth for plant part i (green leaves, stem, roots or storage) plant height maximum plant height sensible heat flux density of crop gravity head hydraulic gradient matric suction head sensible heat flux density of soil solar constant diffuse solar irradiance daily diffuse solar irradiance direct solar irradiance daily direct solar irradiance extraterrestrial solar irradiance daily extraterrestrial solar irradiance PAR irradiance (50% of It) total solar irradiance daily total solar irradiance von Karman’s constant (0.4) weighted average of hydraulic conductivity for water flow into soil layer i canopy extinction coefficient for diffuse solar radiation (corrected for canopy clustering) canopy extinction coefficient for direct radiation hydraulic conductivity for soil layer i maintenance respiration coefficient for plant part i (green leaves, stem, roots or storage) eddy diffusivity at height z Michaelis-Menten constant for CO2 (300) Michaelis-Menten constant for O2 (300000) dry soil layer thickness leaf area index (LAI) critical LAI (equal to Lmax) maximum LAI (4) shaded leaf area index sunlit leaf area index extinction coefficient for eddy diffusivity ambient concentration of O2 in air (210000) surface albedo (reflection) water flux into soil layer i 83 g CH2O g-1 dry matter m m W m-2 m m m W m-2 W m-2 W m-2 J m-2 day-1 W m-2 J m-2 day-1 W m-2 J m-2 day-1 W m-2 W m-2 J m-2 day-1 m day-1 - m day-1 g CH2O g-1 dry matter day-1 m2 s-1 mol mol-1 mol mol-1 m m2 leaf area m-2 ground area m2 leaf area m-2 ground area m2 leaf area m-2 ground area m2 leaf area m-2 ground area m2 leaf area m-2 ground area mol mol-1 m day-1 qˆi Q10 Qdf Qdr Q p, df Qp,dr Qp,dr, Qp,dr,dr Qsh Qsl ra a rc a rc s rsa rss rss,dry rst R R’M R’nL RD,e RD,t RH RLd RLu RM Rn RnL s si Si SLA td th tsr net water flux into soil layer i m day-1 relative change in a parameter for every 10 ºC change diffuse PAR component (above canopies) direct PAR component (above canopies) mean diffuse component of PAR (within canopies) unintercepted direct component of PAR (with scattering component) (within canopies) PAR scattered component only (within canopies) unintercepted direct component of PAR (without scattering component) (within canopies) total PAR absorbed by shaded leaves total PAR absorbed by sunlit leaves aerodynamic resistance between the mean canopy flow and reference height bulk boundary layer resistance canopy resistance aerodynamic resistance between the soil surface and mean canopy flow soil surface resistance soil surface resistance of dry soil stomatal resistance rainfall total maintenance respiration rate (uncorrected) net longwave radiation reduction factor for evaporation reduction factor for transpiration relative humidity downward longwave radiation upward longwave radiation total maintenance respiration rate (corrected for plant age and air temperature) net solar radiation (uncorrected) net longwave radiation (corrected) sunshine hours thickness of soil layer i cumulative thickness of soil layer i specific leaf area day of year local solar time time of sunrise - 84 mol m-2 leaf area s-1 mol m-2 leaf area s-1 mol m-2 leaf area s-1 mol m-2 leaf area s-1 mol m-2 leaf area s-1 mol m-2 leaf area s-1 mol m-2 leaf area s-1 mol m-2 leaf area s-1 s m-1 s m-1 s m-1 s m-1 s m-1 s m-1 s m-1 m day-1 g CH2O m-2 ground area day-1 W m-2 % W m-2 W m-2 g CH2O m-2 ground area day-1 W m-2 W m-2 hour m m m2 g-1 day hour hour tss Tts Ta Ta Ta,i Tavg Tb Tf Tmax Tmin Tset Tts u* u(h), u(z) vc vq vs Vc,max w Wi z z0 zi zr zs0 time of sunset accumulated temperature sum air temperature actual plant transpiration root extraction of water by roots in soil layer i average air temperature base temperature for crop growth temperature of canopy maximum air temperature minimum air temperature air temperature at sunset daily temperature sum friction velocity wind speed at plant height h or at height z Rubisco-limited rate of CO2 assimilation light-limited rate of CO2 assimilation sink-limited rate of CO2 assimilation Rubisco capacity rate (200) mean leaf width dry plant weight for plant part i (green leaves, dead leaves, stem, roots or storage) height surface roughness length depth from soil surface to the middle of soil layer i reference height roughness length of soil surface 85 hour ºC day ºC m day-1 m day-1 ºC ºC ºC ºC ºC ºC ºC day m s-1 m s-1 mol m-2 leaf area s-1 mol m-2 leaf area s-1 mol m-2 leaf area s-1 mol m-2 leaf area s-1 m g m-2 m m m m m Chapter 3. Building the generic crop growth model in Excel 3.1 Operator precedence in Excel This chapter shows how the various calculations are implemented in Excel to build the gcg (generic crop growth) model. It is assumed that you have at least a basic understanding of Excel’s operators, formulas and functions as well as how to navigate the cells within Excel. There are several mathematical operators in Excel, and Table 3.1 lists some of these operators. Table 3.1. Mathematical operators in Excel Operation Excel’s symbolic operator Exponentiation ^ Multiplication * Division / Addition + Subtraction - Less than < Greater than > Less than or equal to <= Greater than or equal to >= These operators are self-explanatory except perhaps for exponentiation which is an operation to raise a given constant (called base) to the power of another number. For example, a^b means that a is raised to the power b so that 2^3 gives 2*2*2 or 8. Excel follows the standard precedence of operators: exponents and roots first, followed by multiplication and division, and finally addition and subtraction. Any operations enclosed by brackets are always done first. Use of brackets or parentheses always overrides the operator precedence. In Excel, if we type the following formula =2+3*4-9/3 it gives 11 because the order of calculations are 3*4, then 9/3. Their answers are 12 and 3, respectively. Their difference: 12-3 gives 9 which is finally added to 2 to give the answer as 11. In another example, =2+3^2*4-9/3 gives 35 because the exponent 3^2 is done first to give 9 which is then multiplied by 4 to give 36. 9/3 is next calculated to give 3. This value is subtracted from 36 to give 33 which is finally added to 2 to give the final answer as 35. We can place brackets to 86 override the precedence of operators and to specify the order of calculations explicitly. For example, =2+3^(2*4)-9/3 gives 6560 because 2*4 within the brackets is done first to give 8 so that 3^8 gives 6561. Finally 2+6561-3 gives 6560. Unfortunately, Excel has a nonstandard order of precedence for unary operators. Unary operators are simply positive (+) or negative (-) that precedes a value. For instance, +2 and -2 mean positive and negative values of 2, respectively. In Excel, if we have the following formula =-2^4 it gives 16 because the calculations are done as (-2)^4. However, this does not conform to the standard order of operator precedence. The calculations ought to be -(2^4) to give -16. To circumvent this problem, we must write the formula as =-(2^4) which would give us the correct answer as -16. This is an issue that we have to remember when using Excel to perform calculations involving unary and exponentiation operators. 3.2 Functions and formulas in Excel The gcg model uses only a few of Excel’s vast collection of functions. Table 3.2 lists the functions used and includes a brief description of each of them. Most of these functions are self-explanatory. Consider an example of a data set in Fig. 3.1. Fig. 3.1. Using VLOOKUP function to find values in the table Based on the above tabulated data: VLOOKUP(4, A2:B11,2,FALSE) returns 45 VLOOKUP(6, A2:B11,2,FALSE) returns 233 VLOOKUP(6, A2:B11,2,TRUE) returns 233 VLOOKUP(1.5, A2:B11,2,TRUE) returns 23 VLOOKUP(1.5, A2:B11,2,FALSE) returns #N/A 87 The first case is VLOOKUP(4, A2:B11,2,FALSE) means that we wish to locate 4 in the first column of a table, where this table is located in cells A2 to B11. Once 4 is found in the first column, the function returns the corresponding value in the second column (index_number is 2) of the table. The value in the second column corresponding to 4 is 45 (cell B5). So the function returns the value 45. Table 3.2. List of Excel functions used to build the gcg model Type Function name Description Mathematics EXP(x) Returns ex, where e is about 2.71828. SQRT(x) Returns x. PI() Returns the value of (about 3.14159). RADIANS(x) DEGREES(x) Converts x from unit degrees to radians (RADIANS) or from radians to degrees (DEGREES) Trigonometry SIN(x) COS(x) ACOS(x) Sine, cosine ir arccosine of x Statistical MIN(x1, x2, …) MAX(x1, x2, …) Returns the minimum or maximum of the enclosed x values. Lookup VLOOKUP(value, table_array, index_number, range_lookup) Searches for value in the leftmost column of table_array and returns the value on the same row based on the index_number. The last argument range_lookup is set to FALSE if an exact match is required, else set to TRUE to return the next largest value that is less than value if an exact match cannot be found. The table_array must be sorted in an ascending order. Logical IF(logical_test, value_if_true, value_if_false) Returns value_if_true if the logical_test is TRUE, else it returns value_if_false if logical_test if FALSE. AND(logical_test1, logical_test2, …) Returns TRUE if all the given logical tests (logical_test1, logical_test2, and so on) are TRUE. Otherwise it returns FALSE. NOT(logical) Returns the opposite of logical. If logical is TRUE, this function returns FALSE, else it returns TRUE if logical is FALSE. The last argument, range_lookup, is either TRUE or FALSE. If it is FALSE, an exact match must be found. This is why the last case, VLOOKUP(1.5, A2:B11,2,FALSE), returns the error message #N/A (for not available) because the value 1.5 is not found in the first column of the table. However, VLOOKUP(1.5, 88 A2:B11,2,TRUE) returns 23 because the next largest value that is less than 1.5 in the first column is 1. So the corresponding value 23 in the second column is returned. It is important to ensure that the tabulated data is sorted in an ascending order for VLOOKUP to return the correct result. The IF function is called a logical function because what it returns is based on the given criteria. For instance, consider the following equation: x 10 x 10 y x / 10 x 10 which means we add 10 to x if x is smaller than 10, else we divide x by 10, and return to result to y. In Excel, let cell A1 store the value of x, and cell B1 the value of y. So in cell B1, we write the formula: =IF(A1<10,A1+10,A1/10) where A1+10 is performed if A1 is less than 10, but if A1 is greater than or equal to 10, A1/10 is performed instead. In other words, if A1<10 is TRUE, A1+10 is returned, but if A1<10 is FALSE, A1/10 is returned instead. It is possible to nest the IF functions. For example, consider an expanded equation: x0 0 y x 10 0 x 10 x / 10 x 10 where y can now have three possible values, depending on the value of x. In cell B1, we may write: =IF(A1<=0,0,IF(A1>=10, A1/10, A1+10)) If A1<=0 is TRUE, 0 is returned, but if A1<=0 is FALSE, another IF function, IF(A1>=10, A1/10, A1+10), is evaluated. In IF(A1>=10, A1/10, A1+10), if A1>=10 is TRUE, A1/10 is returned, else it is A1+10 (that is, A1>=10 is FALSE). The AND function returns either TRUE or FALSE only. If all its logical arguments are TRUE, the AND function returns TRUE, else it returns FALSE if one or more of its logical arguments are FALSE. Consider the following example in Fig. 3.2 to determine if x1 is greater than 0 and x2 less than 0. Fig. 3.2. Illustrating the use of the AND function Based on the above example, only the second case, where x1 is 1 and x2 is -2, that the AND function returns TRUE because both conditions x1>0 and x2<0 are TRUE. The AND function is particularly useful when it is used in conjunction with the IF function. For instance, instead of writing the formula like this, as we did before, 89 =IF(A1<=0,0,IF(A1>=10, A1/10, A1+10)) we can write it alternatively as =IF(A1<=0,0,IF(AND(A1>0,A1<10),A1+10,A1/10)) 3.3 Basic setup: workbook and worksheets A single workbook is required to build the gcg model. This workbook will contain several worksheets, where each worksheet either stores tabulated data or implements individual components of the model. Create a new Excel workbook and save it as “gcg”. Unless you specify explicitly the file extension, all workbook filenames in Excel 2003 will be saved with an extension “.xls”, whereas in Excel 2007, the appended extension is “.xlsx”. Depending on how Excel is setup in your computer system, your workbook will have either one or more blank worksheets, and they are named sequentially as Sheet1, Sheet2, Sheet3, and so on. If you have less than three worksheets in the workbook, insert worksheets until you have at least three worksheets. We will require more worksheets later as we gradually build up the crop growth model, but as for now, only three worksheets are required. 3.3.1 Weather worksheet The gcg model requires daily weather properties only. Hourly weather properties will be simulated using the daily weather properties. Looking up a value from the weather table is more efficient and convenient if all the site’s weather data are stored in a single worksheet. This includes storing all the site’s weather data for one or more years. For example, the weather data from Reading, UK for the years 2000 to 2004 should all be stored in a single worksheet. Avoid breaking up the weather data set, for instance, into individual years and storing each year’s data in a separate worksheet. In this book, the sample weather data from Serdang, Malaysia (from 19852004) will be used as an example. This weather data can be downloaded from www.agri.upm.edu.my/~chris/weather. The Serdang weather file obtained from the website is formatted such that the first three columns are for year, month and day. The next six columns are for daily weather properties: sunshine hours, maximum air temperature, minimum air temperature, relative humidity, wind speed and rainfall. Start up any text editor program (such as Windows Notepad) to open the Serdang weather text file which you downloaded from the website. Select and copy all the text (Fig. 3.3). Close the text editor program, if desired. In the gcg workbook, rename worksheet Sheet1 to Serdang. This worksheet will store the weather data for Serdang for all years 1985-2004. Paste the clipboard contents (containing the Serdang weather) in cell A2. You will see that the weather data are spread over columns A to I (with a blank first row). 90 Fig. 3.3. Open the Serdang weather text file using a text editor. Select all the text and copy into the clipboard to be later imported into Excel. Right click on column D, and choose Insert from the popup menu (Fig. 3.4). This will insert a new column which will appear to the left of column D. After this operation, the weather data will now be spread over columns A to J, with a new blank column D. Fig. 3.4. Insert a column for date at column D in the Serdang worksheet The empty first row in the Serdang worksheet serves as a table header to describe the individual weather properties. In cell A1, type year, followed by month, day and date in the subsequent cells B1, C1, D1, respectively. The first four columns denote the date of weather. As stated earlier, the daily weather consist of six measured properties: sunshine hours (sunhr), maximum air temperature (tmax), minimum air temperature (tmin), relative humidity (rh), wind speed (wind) and rainfall (rain). Consequently, type the following table headers sunhr, tmax, tmin, 91 rh, wind and rain in cells E1, F1, G1, H1, I1 and J1, respectively, to describe these six weather properties (Fig. 3.5). Fig. 3.5. The weather table formatted as required in the Serdang worksheet. Also notice the other three worksheets (Control, Output and Meteorology). At this moment, all columns from A to J are filled with data except the blank column D (which we inserted previously). The purpose for having this column is to specify the date of the weather. However, different countries specify dates in differing formats. For instance, a date written as “02/12/08” may mean 2 December 2008, 12 February 2008 or even 12 August 2002. To avoid this confusion, especially when the spreadsheet model is being executed in different computer systems, Excel’s DATE function will be used to specify the date of the weather correctly according to the computer’s regional settings. The DATE(year,month,day) function has three arguments which correspond to the year, month and day, respectively. Consequently, in cell D2, type the formula =DATE(A2,B2,C2) which will give the date (recall that columns A, B and C store the year, month and day, respectively). Do the same for all other cells in column D. To avoid repetitious and tedious copying-and-pasting, you can select cell D2, and double click the fill handle (a small square at the bottom right corner of the cell). When the mouse pointer moves over the fill handle, the mouse pointer changes into a small cross (Fig. 3.6). Double clicking on the cell’s fill handle copies and pastes the cell’s formula down the column. 92 Fig. 3.6. The fill handle is at bottom right hand corner of the cell. Double clicking it will paste the cell’s contents down the column. The gcg model requires that the weather data be sorted ascendingly according to the date; that is, arranged from the earliest to the latest year, and within each year, the data are sorted from 1 January to 31 December. The weather data must also be complete and should not have “gaps” or missing data for certain days. If this occurs, you have to interpolate between measured days. The formula for linear interpolation is simply x2 x1 x3 x1 t2 t1 t3 t1 where t is the date (e.g., day of year) and x is the weather property (e.g., sunshine hours). The missing data set (t2, x2) lies between two known sets, (t1, x1) and (t3, x3), and the determination of the missing value x2 at t2 is by linear interpolation between the two knowns x1 and x3 measured at t1 and t3, respectively. 3.3.2 Control worksheet The Control worksheet is where we specify the model’s step number, step size and the criteria to stop the iterations. In this worksheet, we will also have a list of operations to run. BuildIt requires at least three names to be defined: _stepsize, _step and _criteria. These names dictate to BuildIt the current step number (_step), the size of each iteration step (_stepsize) and when to stop the iteration runs (_criteria). Begin by renaming worksheet Sheet2 to Control. Enter the following in the Control worksheet: Row 1 2 Col. B Cell name 10 B2: maxsteps 3 Col. A CONTROL Number of iterations Step size 1 4 5 Current step Criteria 0 =(_step/_stepsize) < maxsteps B3: _stepsize B4: _step 6 7 8 9 10 Starting date Current date Day of year Current hour =DATE(2000,1,1) =B7+_step =B8-DATE(YEAR(B8),1,0) 12 Eq. ref. B5: _criteria B8: date B9: doy B10: th The values in cells B2, B3 and B4 and their respective defined names mean that maxsteps = 10, _stepsize = 1 and _step = 0, respectively. At the moment, their values are inconsequential and will be changed as required by a simulation task. Cell B5 specifies the criteria to BuildIt when to stop the model iteration runs. As long as (_step/_stepsize) < maxsteps (cell B5 is TRUE), iteration continues until (_step/_stepsize) maxsteps (cell B5 is FALSE). 93 Notice that the simulation start date in cell B7 is specified as =DATE(2000,1,1) which means that the simulation start date is 1 January 2000. You should enter the date using the DATE function, rather than entering “01/01/00” in cell B7. Recall that this format (e.g., 01/01/00) may be interpreted differently on different computer systems. In cell B8, the formula is =B7+_step which means that it adds the simulation start date (in cell B7) to the model’s step number (_step). BuildIt increments _step automatically, so as the iteration continues, the current simulation date will be updated accordingly. For instance, take the simulation start date as 1 Jan. 2000 and the _stepsize as 1. When the simulation begins, _step will be set to 0, so the current simulation date is 1 Jan. 2000. In the second iteration run, _step will be incremented by _stepsize; that is, _step = _step + _stepsize to give _step = 1. This means the current simulation date is now 2 Jan. 2000. In the third iteration step, the _step is 2 to give the current simulation date as 3 Jan. 2000, and so on. In cell B9, the formula to determine the day of year for the current date is =B8-DATE(YEAR(B8),1,0) which gives the number of days from the first day of the same year (1 January). However, since the day of year starts as 1 (not 0), the subtraction of dates must be specified as B8-DATE(YEAR(B8),1,0) and not as B8-DATE(YEAR(B8),1,1). It might seem odd that the day argument in DATE is given as 0 (e.g., there is no 0 January), but doing so will ensure that the day of year for 1 January is 1 (not 0). We also use the YEAR function to extract the year for the current simulation date (in cell B8), so that the day of year will always be within the range of 1 and 365 (or 366 for leap years). If we had typed the following in cell B9: =B8-B7+1 works so long as the years for the current date (cell B8) and starting date (cell B7) are not different. If the starting and current date are 1 January 2000 and 12 January 2001, respectively, the calculated day of year would have been erroneously 378 (note: year 2000 is a leap year). Note that because we are dealing with dates in cell B9, the result from the date subtraction may be displayed as a date format (e.g., displayed as 1-Jan-00) in cell B9. This can be confusing, so we have to change the display format to Number or General. Right click on cell B9, and choose Format Cells from the popup menu. Choose the Number tab, and ensure the display format is set either to General or Number (Fig. 3.7). If the latter format is chosen, you can set the number of decimal places to 0 since the day of year is an integer (i.e., no decimal places). Lastly, cell B10 is the current local solar hour for the simulation. 94 Fig. 3.7. Format Cells dialog to format the display of cells 3.3.3 Output worksheet We often want to store the model output results so that we can later analyze and interpret the simulation results, and even plot charts from the results. We need to tell BuildIt: 1) which data should be stored, and 2) where to store the results. For this purpose, BuildIt requires two names to be defined: _read and _write. When a cell name is given the name _read, the entire row for that cell is used by BuildIt to identify cell contents that should be stored at every iteration run. Complementing _read, the name _write is to tell BuildIt where the results should be displayed. When a cell is given the name _write, this cell serves as a starting point to store the output results. It is convenient if all model output results be stored in a separate worksheet, called as the Output worksheet. Rename the worksheet Sheet3 to Output. Define the names _read to cell A2 and _write to cell A6. In cell A5, type Model output: We will leave the Output worksheet as it is now, and return to it later when we have specific simulation tasks to run and their results to save. 3.4 Meteorology worksheet The meteorology model component will be implemented in a separate worksheet named Meteorology. Insert a new blank worksheet and rename it to 95 Meteorology. We will begin by specifying the model parameters (input) related to meteorology. Enter the following in the Meteorology worksheet: Row 1 2 3 4 5 Col. A INPUT lat. (deg) Angstrom, b0 Angstrom, b1 Weather file Col. B Cell name 3 0.29 0.42 Serdang Eq. ref. (2.7) (2.7) Site latitude (cell B2) is specified in degrees for Serdang, Malaysia. The Angstrom coefficients, b0 and b1, for determining the daily total solar irradiance are specified in cells B3 and B4, respectively, and their values are for a humid tropical climate zone. Surface albedo is 0.15 and is specified in cell B5. Lastly, cell B5 is the name of the worksheet that holds the weather data to be used in simulation. Since we are using the Serdang weather which is stored in the Serdang worksheet, we enter its worksheet’s name (Serdang) in cell B5. This is a convenient feature that allows us to specify quickly which weather data set to use in simulation. For example, we may have another weather data set for a different site such as for Semenyih, Malaysia which is stored in a separate worksheet named as Semenyih. Consequently, to use the Semenyih weather data set, we can enter Semenyih in cell B5. Excel functions require angles to be specified in unit radians, so we need to convert the site latitude from degrees to radians. Conversion is simple by using the function RADIANS (cell E2): Row 2 3 Col. D lat. (rad) Weather ref. Col. E =RADIANS(B2) =$B$5&"!D:J" Cell name Eq. ref. E2: lat Recall that cell B5 contains the name of the worksheet where the weather data are stored. In our example, the weather is stored in the Serdang worksheet, so cell B5 contains the text “Serdang”. In cell E3, the formula =B5&"!D:J" joins (concatenates) the two texts, “Serdang” (cell B5) and “!D:J”, to produce a single text “Serdang!D:J” which is a cell range reference to the weather table, and will be used to lookup the weather table (see next). 3.4.1 Daily weather lookup To look up values from the weather table, the function VLOOKUP is used. Recall that this function has the following specification: VLOOKUP(value,table_array,index_number,range_lookup) which searches for value in the leftmost column of table_array and returns the value on the same row based on the index_number. The last argument range_lookup is set to FALSE if an exact match is required, else set to TRUE to return the next largest value that is less than value if an exact match cannot be found. The following entries in the Meteorology worksheet illustrate how this function is used to lookup the data from the weather table: 96 Row 5 6 Col. D DAILY WEATHER sunshine hours 7 max. temp. 8 min. temp. 9 10 relative humidity wind speed 11 rain 12 mean temp. Col. E Cell name =VLOOKUP(date,INDIRECT(E3) ,2, FALSE) =VLOOKUP(date,INDIRECT(E3) ,3, FALSE) =VLOOKUP(date,INDIRECT(E3) ,4, FALSE) =VLOOKUP(date,INDIRECT(E3) ,5, FALSE) =VLOOKUP(date,INDIRECT(E3) ,6, FALSE) =VLOOKUP(date,INDIRECT(E3) ,7, FALSE) =(tmax+tmin)/2 E6: sunhr Eq. ref. E7: tmax E8: tmin E9: rh E10: daywind E11: rain E12: tmean For instance, to lookup the sunshine hours for 12 February 2000 for Serdang, we may write VLOOKUP(DATE(2000,2,12),Serdang!D:J,2,FALSE) where the first argument is the value that we wish to find (i.e., 12 February 2000) from the table in the Serdang worksheet in columns D to J (i.e., Serdang!D:J). If we look in the Serdang worksheet (Fig. 3.5), we see that the entire Serdang weather table (from 1985 to 2004) spreads from cell A2 to J7306. However, the first three columns (A, B and C), storing the year, month and day, respectively, will not be used in table lookup. Instead we will use the fourth column (D), storing the weather date, to lookup a table. Consequently, our table for weather lookup actually begins from column D to J. And since the entire Serdang worksheet is dedicated to storing the weather table, we can eliminate the row numbers and write Serdang!D:J instead of Serdang!D2:J7306. In our example, once the date 12 February 2000 is located from the table, the value from the second column (as specified by the third argument, index_number) of the table is returned. Looking in the Serdang worksheet again (Fig. 3.5), we see that the sunshine hours data are stored in column E which is the second column after column D. The last argument is set to FALSE because an exact match (not an approximate match) must be found. As another example, to lookup the maximum air temperature (located in column F in the Serdang worksheet), we may type VLOOKUP(DATE(2000,2,12),Serdang!D:J,3,FALSE) Recall that in cell E3, the formula written was =B5&"!D:J" which concatenates the name of the weather worksheet (stored in cell B5) and the text “!D:J”. So in our case, the resultant text in cell E3 is “Serdang!D:J”. But if we write like this VLOOKUP(DATE(2000,2,12),E3,2,FALSE) it fails to lookup the sunshine hours from the Serdang weather table because the second argument states that cell E3 is where the lookup table is located. Cell E3 contains the reference where the weather table is located and is not the lookup table itself. To circumvent this problem, we use the INDIRECT function. This function 97 returns the reference to a cell based on its text representation, so writing the formula like this VLOOKUP(DATE(2000,2,12),INDIRECT(E3),2,FALSE) is as if we had written like this VLOOKUP(DATE(2000,2,12),Serdang!D:J,2,FALSE) Consequently, for the current simulation date, daily weather properties will be looked up from the weather table via the function VLOOKUP(date,INDIRECT(E3),index_number,FALSE) where index_number is 2 to 7, depending on the weather property, and date is the name referring to cell B8 in the Control worksheet which holds the current simulation date. Based on this date, the weather table (in the Serdang worksheet) will be looked up for the daily weather properties. Lastly, in cell E12, the average of the minimum and maximum air temperature is calculated. 3.4.2 Solar position Solar position is defined by its angle from vertical (solar inclination) and from North in a clockwise direction (solar azimuth). Enter the following in the Meteorology worksheet: Row 14 15 Col. D SOLAR POSITION declination 16 17 18 19 20 hour angle a b inc suninc (rad) 21 22 suninc (deg) solar height 23 c 24 25 26 azi sunazi (rad) sunazi (deg) Col. E Cell name Eq. ref. =-0.4093 * COS(2*PI()*(doy+10)/365) =(PI()/12)*(th-12) =SIN(decl)*SIN(lat) =COS(decl)*COS(lat) =ACOS(E17+E18*COS(ha)) =IF(E19<PI()*0.5,E19,PI()* 0.5) =DEGREES(suninc) =PI()*0.5-suninc E15: decl (2.1) E16: ha (2.10) E20: suninc (2.11) (2.11) =(SIN(lat)*SIN(solarhgt)SIN(decl)) / (COS(lat)*COS(solarhgt)) =IF(E23<1,ACOS(E23),0) =PI()+IF(th<12,-E24,E24) =DEGREES(sunazi) E22: solarhgt (2.11) (2.11) (2.12) E25: sunazi (2.12) (2.12) (2.12) Note that a, b and c are intermediary variables. Cell E19 contains the calculated solar inclination (angle from vertical). However, if th is before sunrise or after sunset, solar inclination will exceed /2 radians (or 90) because the sun is below the horizon. In agriculture, calculating the solar position for hours before sunrise or after sunset is of little interest. Consequently, the IF function in cell E20 ensures that the solar inclination is capped at /2 if its calculated value exceeds /2. Another issue to deal with is the calculation of solar azimuth in cell E23. The intermediary variable, c, can exceed 1 due to rounding errors by the computer. If the arccosine of c is taken in this case, it will lead to an undefined value. To circumvent 98 this problem, the formula in cell E24 uses the IF function to check if c is less than 1 before returning the arccosine of c. Otherwise, the function returns 0 radian. Cells E21 and E26 contain the angles converted to unit degrees for our reference. 3.4.3 Sunrise, sunset and daylength The following determines the local solar hour for sunrise and sunset, and the difference between them gives the day length: Row 28 29 Col. D SUNRISE/SET sunset 30 31 sunrise daylength Col. E Cell name Eq. ref. =12+(12/PI())*ACOS(-E17 / E18) =24-E29 =tss-tsr E29: tss (2.3) E30: tsr (2.2) (2.4) E31: dl Cells E17 and E18 refer to the intermediary variables, a and b, respectively, as previously defined in section 3.4.2. 3.4.4 Air temperature The current air temperature is calculated as follows: Row 33 34 Col. D AIR TEMP. sunset temp. 35 Ta1 36 Ta2 37 Ta3 38 air temp.(°C) 39 air temp.(K) Col. E Cell name Eq. ref. =tmin+(tmax-tmin) * SIN((PI()*(tss-tsr-1.5)) / (tss-tsr)) =tset+((tmin-tset)*(24+thtss))/((tsr+1.5)+(24-tss)) =tmin+(tmax-tmin) * SIN((PI()*(th-tsr-1.5)) /(tss-tsr)) =tset+((tmin-tset)*(thtss))/((tsr+1.5)+(24-tss)) =IF(th<(tsr+1.5),E35,IF(th >tss,E37,E36)) =ta+273.15 E34: tset (2.20) (2.19) (2.19) (2.19) E38: ta (2.19) E39: tak (2.19) Cells E35, E36 and E37 show that there are three possible values to air temperature (i.e., Ta1, Ta2 and Ta3). Cell E38 chooses the correct value depending on the current local solar hour (th) using the nested IF functions. Finally, cell E39 converts the air temperature from unit degrees Celsius to Kelvin. 3.4.5 Air vapor pressure and wind speed Below determines the current air vapor pressure and saturated air vapor pressure. Also recall that the wind speed is assumed constant throughout the whole day. Row 41 42 43 44 Col. D AIR VAP. PRES. sat. vap. pressure vap. pressure Col. E Cell name Eq. ref. =6.1078 * EXP(17.269*ta/(ta+237.3)) =(rh/100)*E42 E42: es (2.21) E43: ea (2.23) 99 45 46 WIND SPEED wind speed E46: wind =daywind section 2.1.2.6 3.4.6 Solar radiation 3.4.6.1 Daily total solar radiation The following determines the daily total solar radiation and the partitioning into its diffuse and direct components: Row 1 Col. G SOLAR RADIATION eccentricity factor solar constant sinb Col. H Cell name 5 6 7 8 9 10 11 12 13 14 Daily ET Daily total =1+0.033*COS(2*PI()*(doy10)/365) =1370*H2 =(24/PI())*(E17*ACOS(E17/E18)+E18*SQRT(1(E17/E18)^2)) =3600*H3*H4 =H5*(B3+B4*sunhr/dl) total:et f1 f2 f3 f4 =Itd/H5 =Itd =Itd*(1-2.3*(H8-0.07)^2) =Itd*(1.33-1.46*H8) =Itd*0.23 Daily diffuse 15 Daily direct =IF(H8<0.07,H9,IF(AND(H8>= 0.07,H8<0.35),H10, IF(AND(H8>=0.35,H8<0.75),H 11,H12))) =Itd-H14 2 3 4 Eq. ref. (2.5) (2.5) (2.6) H6: Itd (2.6) (2.7) (2.8) (2.8) (2.8) (2.8) (2.8) H14: Idfd (2.8) H15: Idrd (2.9) Note that cells E17 and E18 refer to the intermediary variables, a and b, respectively, as defined previously in section 3.4.2. Cells H9 to H12 show that there are four possible values for the fraction of diffuse solar component (i.e., f1, f2, f3 and f4). Cell H14 chooses the correct value depending on the ratio of total solar irradiance to extraterrestrial solar irradiance using nested IF functions. 3.4.6.2 Hourly total solar radiation The following determines the hourly solar radiation and the partitioning into its diffuse and direct components: Row 17 18 19 Col. G ET p1 p2 20 21 22 23 phi phiA phiB total Col. H =H3*SIN(solarhgt) =PI()*Itd/86400 =E17*ACOS(-E17/E18) + E18*SQRT(1-(E17/E18)^2) =H18/H19 =-E18*H20 =E17*H20 =H21*COS(2*PI()*th/24) + H22 100 Cell name Eq. ref. (2.13) (2.14) (2.14) (2.14) (2.14) (2.14) (2.14) 24 25 26 27 Hourly total =IF(H23<0,0,H23) total:et R 28 29 30 31 32 33 34 K f1 f2 f3 f4 =It/H17 =0.847-1.61*SIN(solarhgt) + 1.04*(SIN(solarhgt)^2) =(1.47-H27)/1.66 =It =It*(1-6.4*(H26-0.22)^2) =It*(1.47-1.66*H26) =It*H27 35 Hourly direct Hourly diffuse =IF(It<=0,0,IF(H26<=0.22,H 29,IF(AND(H26>0.22,H26<=0. 35),H30,IF(AND(H26>0.35,H2 6<=H28),H31,H32)))) =It-H34 H24: It (2.14) (2.15) (2.16) (2.17) (2.15) (2.15) (2.15) (2.15) H34: Idf (2.15) H35: Idr (2.18) Note that cells E17 and E18 refer to the intermediary variables, a and b, respectively, as defined previously in section 3.4.2. Cell H23 calculates the total solar irradiance for the current local solar hour. However, the calculated value can be negative for hours before sunrise or after sunset. At these hours, there is no solar irradiance (that is, it is zero). Consequently, cell H24 ensures that hourly solar irradiance is never a negative value. Cells H29 to H32 show that there are four possible values for the fraction of diffuse solar component (i.e., f1, f2, f3 and f4—not related to those section 3.4.6.1). Cell H34 chooses the correct value depending on the ratio of total solar irradiance to extraterrestrial solar irradiance using nested IF functions. 3.4.7 Simulation exercise 3.5 Photosynthesis worksheet The photosynthesis model component will be implemented in a separate worksheet. Insert a new worksheet and rename it to Photosynthesis. As before, we will begin by specifying the model inputs relevant to photosynthesis in this worksheet: Row 1 2 3 4 Col. A INPUT foliage temp. LAI LAI max Col. B Cell name 20 1 4 B2: Tf Eq. ref. B3: lai B4: Lmax The three inputs to photosynthesis are foliage temperature (cell B2), leaf area index or LAI (cell B3), and maximum LAI (LAI for full canopy closure) (cell B4). Foliage temperature and LAI will later be simulated when we implement the energy balance and growth model components, respectively. For now, the first two parameters will be supplied to the model as constants. Also required are photosynthesis parameters, some of which are dependent on foliage or canopy temperature. 101 The following are model parameters that must be adjusted for foliage temperature: Row 7 8 9 10 11 12 13 14 15 16 17 18 19 20 Col. A Tempdependent MichaelisMenten CO2 MichaelisMenten O2 CO2-O2 specificity Rubisco capacity Non tempdependent quantum efficiency ambient O2 ambient CO2 intercell CO2 PAR reflection PAR absorption PAR scattering Col. B value(25) Col. C Q10 Col. D value(Tf) Cell name Eq. ref. 300 2.1 D8: Kc (2.41) 300000 1.2 D9: Ko (2.42) 2600 0.57 200 2.4 =B8*C8^((Tf25)/10) =B9*C9^((Tf25)/10) =B10*C10^((T f-25)/10) =(B11*C11^(( Tf-25)/10)) / (1+EXP(0.29* (Tf-40))) (2.43) D11: Vcmax 0.08 D14: em 210000 350 =0.7*B16 D15: Oa 0.04 D18: PARreflect 0.8 D19: PARabsorb 0.8 D20: PARscatter (2.45) D17: Ci Parameters sensitive to temperature are the Michaelis-Menten coefficient for CO2 and O2 (cells B8 and B9, respectively), CO2-O2 specificity factor (cell B10), and Rubisco capacity (cell B11). Their values in cells B8 to B11 are that for foliage temperature 25 C, and cells D8 to D11 show their corrected values for the given foliage temperature, Tf. In contrast, cells B14 to B20 are parameters not sensitive to foliage temperature. 3.5.1 PAR above the canopies The PAR (photosynthetically active radiation) above the canopies are calculated as shown below: Row 1 2 3 4 5 6 7 8 Col. F PAR above canopies PAR direct PAR diffuse Col. G Cell name Eq. ref. =0.5*Idr*4.55 =0.5*Idf*4.55 G2: PARdf (2.29) (2.30) k(direct) taub 1-taub zenith clump factor =0.5/COS(suninc) =IF(lai<Lmax,1-lai/Lmax,0) =1-G6 =-LN(G6+G7*EXP(G5*lai/G7))/(G5*lai) 102 G3: PARdf (2.31) (2.34) (2.33) (2.33) clump factor k(direct) adjusted =G8^(1-2*suninc/PI()) =G5*G9 11 12 n1 13 n2 14 k(diffuse) adjusted =0.6936+13.291*lai^22.3648*lai^4+0.1701*lai^6 =1+22.6522*lai^24.0257*lai^4+0.2674*lai^6 =G12/G13 9 10 15 16 17 LAI sunlit LAI shaded =(1-EXP(-kdr*lai))/kdr =lai-Lsl G10: kdr (2.32) (2.25), (2.26) (2.35) (2.35) G14: kdf (2.35) G16: Lsl (2.38) (2.39) G17: Lsh The canopy extinction coefficients for direct and diffuse PAR are calculated (cells G10 and G14, respectively), followed by the sunlit and shaded LAI (cells G16 and G17, respectively). Note that n1 and n2 (cells G16 and G17, respectively) are intermediary variables. 3.5.2 PAR within the canopies The PAR within the canopies are next calculated as shown below: Row 19 20 21 22 23 24 Col. F PAR within canopies direct with scattering direct without scattering scattering n mean diffuse Col. G Cell name =(1-PARreflect)*PARdr* EXP(-kdr * SQRT(PARscatter)*lai) =(1-PARreflect) *PARdr*EXP(-kdr*lai) =(G20-G21)/2 =kdf*SQRT(PARscatter)*lai =((1-PARreflect)*PARdf*(1EXP(-G23)))/G23 Eq. ref. (2.25) (2.26) (2.27) (2.28) (2.28) Recall that there are four PAR components within the canopies: unintercepted direct PAR with scattering (cell G20), unintercepted direct PAR without scattering (cell G21), the scattering component only (G22), and the mean diffuse PAR (cell G24). 3.5.3 PAR absorption The PAR absorbed by sunlit and shaded leaves are calculated as shown below: Row 26 27 Col. F PAR absorbed sunlit leaves 28 shaded leaves Col. G Cell name Eq. ref. =PARabsorb * (kdr*PARdr+G24+G22) =PARabsorb * (G24+G22) G27: PARsl (2.36) G28: PARsh (2.37) 3.5.4 CO2 assimilation by leaf and canopy After calculating the PAR irradiance above and within the canopies, and how much PAR has been absorbed by the leaves, the next step is to determine the amount of CO2 assimilated by the leaves. This amount is then scaled up to determine the canopy assimilation of CO2. The following shows the entries in the spreadsheet: 103 Row 30 Col. F CO2 assimilation CO2 compensation point Col. G =Oa/(2*D10) (2.44) Rubiscolimited Sink-limited Light-limited (sunlit) Light-limited (shaded) =Vcmax*(Ci-G31) / (Kc*(1+Oa/Ko)+Ci) =0.5*Vcmax =em*PARabsorb*PARsl * ((Ci-G31)/(Ci+2*G31)) =em*PARabsorb*PARsh * ((Ci-G31)/(Ci+2*G31)) (2.47) 37 38 Canopy assim. =Lsl*MIN(G33,G34,G35) + Lsh*MIN(G33,G34,G36) (2.50) 39 itg out 40 Daily canopy assim. (g CH2O m-2) 31 32 33 34 35 36 Cell name =G39*3600*30*10^-6 Eq. ref. (2.49) (2.48) (2.48) G40: assim section 2.2.8 section 2.2.8 Cell G38 contains the canopy CO2 assimilation rate for the current local solar hour, but to determine the daily photosynthetic rate, we have to integrate cell G38 from sunrise to sunset. To do this, we will use BuildIt’s integration operation, ITG. In the Control worksheet, do the following: In cell D1, type OPERATIONS. In cell D2, type daily photosynthesis. In cell E2, define the name _operation. This indicates to BuildIt that the list of operations (such as ITG) will be stated starting from cell E2. In cells E2 to J2, type the following: 2 E itg F =th G =Photosynthesis!G38 H =Photosynthesis!G39 I =tsr J =tss Recall that ITG has the following specification: ITG (x, func, output, lower, upper, single_integral) which specifies the integration of the function func of variable x on the interval [lower, upper]. The result of integration is to be stored in the output cell. The last argument, single_integral, specifies if it is a single or multiple integration (TRUE for the former, FALSE for the latter). In the case here, argument x (cell F2) is the local solar hour (th), func (cell G2) is the canopy CO2 assimilation rate (cell G38 in the Photosynthesis worksheet), output (cell H2) is the integration result to be stored in cell G39 in the Photosynthesis worksheet, and the integration limits, lower (cell I2) and upper (cell J2), are sunrise (tsr) and sunset (tss), respectively. In the Photosynthesis worksheet, cell G40 converts the integration result in cell G39 to unit g CH2O m-2 by the multiplication of 30x10-6. Multiplication by 3600 is to convert the canopy assimilation rate to unit hour. 104 3.5.5 Simulation exercise 3.6 Energy balance worksheet Insert a new worksheet and rename it to EnergyBal. This is the worksheet where the energy balance model component will be implemented. Recall that we had earlier assumed that the foliage temperature, Tf, was constant when we were building the photosynthesis model component. In cell B2 in the Photosynthesis worksheet, we fixed the foliage temperature and defined the name Tf to cell B2. In the EnergyBal worksheet, however, Tf will be calculated based on the energy balance for a given solar hour. Consequently, we need to remove the name definition Tf from cell B2 in the Photosynthesis worksheet. In Excel 2003’s main menu, choose the commands Insert|Name|Define. In the dialog box, find the name Tf from the list. Once found, select the name and click the Delete button to delete it. In Excel 2007, you have to choose the Name Manager command from the Formulas ribbon. A dialog box will be shown to display all the names in the workbook. Find the name Tf from the list. Select the Tf name and click the Delete button to delete it. Once deleted, several cells in the Photosynthesis worksheet will display the error message #NAME? because these cells use the missing name Tf (which we have deleted). This problem will be rectified later when we define the name Tf to another cell in the EnergyBal worksheet that holds the calculated foliage temperature. The energy balance component requires many inputs to be entered, as shown below: Row 1 2 Col. B Cell name 2 B2: zr 1 2 6 Col. A INPUT reference height crop height wind ext. coef. eddy ext. coef. leaf width 7 8 critical LAI stomata, a1 =Lmax 11.255 9 stomata, a2 0.005 B3: h B4: windattn B5: eddyattn B6: leafwidth B7: Lcr B8: stom_a1 B9: stom_a2 10 cloud (longwave) surface albedo 0.2 3 4 5 11 12 13 2 0.08 0.15 Soil parameters 105 Eq. ref. 14 15 16 17 18 19 20 water content saturated water content total porosity pore-size distribution tortuosity dry layer thickness roughness length 0.2 0.45 B15: vwcsat 0.42 0.18 2 0.02 0.004 B20: zs0 Cell B2 is the height of meteorological measurements, often 2 m or more. The plant height is specified in cell B3. When we later implement the growth model component, the plant height will vary according to the simulation time. But as for now, the plant height is fixed as a constant value. Both the extinction coefficients for wind speed and eddy diffusivity are fixed at 2 (cells B4 and B5, respectively). Leaf width is also assumed constant and is specified in cell B6. The critical leaf area index (cell B7) is needed to scale up the leaf stomatal resistance to the canopy level, and is assumed to be equal to maximum LAI (cell B4 in the Photosynthesis worksheet). Both the coefficients for stomatal resistance, a1 and a2, are specified in cells B8 and B9, respectively. Both describe how stomatal resistance vary according to PAR irradiance. Cell B10 is the coefficient to correct for cloud cover in the calculation of the net radiation. The fraction of reflected solar irradiance is fixed at 0.15 (cell B11). Parameters related to the soil properties are specified in cells B14 to B20. When the soil water model component is implemented, the soil water content in the top soil layer will vary according to the various water fluxes in the soil. Until then, however, we will assume that the volumetric soil water content is constant at 0.2 m 3 m-3 (cell B14). This parameter, along with others (saturated water content, porosity, tortuosity, dry layer thickness) are needed to calculate the soil surface resistance to heat flux, and they are each assumed as constant. Cell B20 measures the roughness length for a tilled, flat soil surface, taken as 4 mm. Constants such as Stefan-Boltzmann constant and von Karman’s constant are also specified below: Row 22 23 Col. A CONSTANTS psychometry Col. B Cell name 0.658 24 von Karman 0.4 25 air vol. heat capacity total solar scattering StefanBoltzmann 1221.09 B23: psycho B24: karman B25: pcp 26 27 0.5 =5.67*10^-8 Eq. ref. B26: solarscat B27: sfb 3.6.1 Net radiation and available energy After the model parameters and constants are specified, calculations can resume by determining the net radiation and energy supplied to the system which are as shown below: 106 Row 1 2 3 4 Col. D NET RADIATION Rlu Rld RnL 5 6 7 net radiation 8 9 10 11 penetration probability soil heat flux energy to crop energy to soil energy to system Col. E Cell name =sfb*tak^4 =(9.35*10^-6)*sfb*tak^6 =(E3-E2)*(B10+(1-B10) * sunhr/dl) =(1-B11)*It+E4 =EXP(-kdr * SQRT(solarscat)*lai) =0.35*(E7*Rn)*COS(suninc) =MAX(0,(1-E7)*Rn) =E7*Rn-G =Ac+As Eq. ref. (2.54) (2.55) (2.52) E5: Rn (2.51) (2.59) E8: G E9: Ac E10: As E11: A (2.60) (2.57) (2.58) (2.56) The MAX function is used in cell E9 to ensure that the energy available to the crop is always zero or more. Without it, energy available to the crop can be negative for hours before sunrise or after sunset. Other values that have to be calculated are related to the air vapour pressure. 3.6.2 Air vapor pressure and wind speed profile The slope of the saturated air vapor pressure curve (against air temperature) are calculated next. The difference between the saturated and current air vapor pressure is known as the vapor pressure deficit. Below shows their determination in the spreadsheet: Row 13 14 15 Col. D VAP. PRESSURE slope of svp to temp vapour pressure deficit Col. E Cell name Eq. ref. =(25029.4*EXP(17.269*ta/(t a+237.3)))/(ta+237.3)^2 =es-ea E14: slope (2.22) E15: vpd (2.24) Model variables related to the wind speed profile are calculated next: Row 17 18 19 20 21 22 Col. D WIND SPEED PROFILE zero displacement hgt crop roughness length friction velocity wind speed at canopy top eddy diffusivity at canopy top Col. E Cell name Eq. ref. =0.64*h E18: d (2.61) =0.26*(h-d) E19: z0 (2.62) =karman*wind/LN(1/0.26) E20: ustar (2.63) =(ustar/karman)*LN((h-d) / z0) =karman*ustar*h 3.6.3 Resistances We can now proceed to calculate the various flux resistances: 107 (2.64) (2.66) Row 24 25 Col. D RESISTANCES n1 26 27 28 29 30 n2 n3 rsa 31 32 n2 n3 33 34 35 raa 36 37 38 39 40 n2 rca 41 rcs 42 43 44 n1 n1 total PAR rst dry soil resistance rss Col. E Cell name =(h*EXP(eddyattn)) / (eddyattn*E22) =EXP(-eddyattn*zs0/h) =EXP(-eddyattn*(z0+d)/h) =E25*(E26-E27) =LN((zr-d)/(h-d)) / (karman*ustar) =h/(eddyattn*E22) =EXP(eddyattn * (1 (z0+d)/h))-1 =E30+E31*E32 =0.012*lai*(1 EXP(-windattn/2)) =SQRT(E21/leafwidth) =windattn/(E35*E36) =IF(It>0,It*0.5,0.01) =(stom_a1+E39) / (stom_a2*E39) =IF(lai<0.5*Lcr, rst/lai, rst/(0.5*Lcr)) =(B18*B19)/(B16*24.7 * 10^-6) =E43*EXP(-(1/B17) * B14/vwcsat) Eq. ref. (2.67) E28: rsa (2.67) (2.67) (2.67) (2.68) (2.68) (2.68) E33: raa (2.68) (2.69) E37: rca (2.69) (2.69) E40: rst (2.70) (2.70) E41: rcs (2.71) (2.72) E44: rss (2.73) Cell E39 calculates the PAR irradiance which is half (50%) of the total solar irradiance, It. However, a check by the IF function is required that It is not zero because the PAR irradiance is required by cell E40 to determine the stomatal resistance, else division by zero occurs. If It is zero, PAR irradiance is set to a very low value which will give a very high stomatal resistance in cell E40. 3.6.4 Latent heat fluxes Once the various resistances have been calculated, the total latent heat flux of the system can finally be calculated in cell H13: Row 1 2 3 Col. G ET Ra Rc 4 Rs 5 Cc 6 Cs 7 n1 Col. H Cell name =(slope+psycho)*raa =(slope+psycho)*rca + psycho*rcs =(slope+psycho)*rsa + psycho*rss =1/(1+(H3*H2)/(H4 * (H3+H2))) =1/(1+(H4*H2)/(H3 * (H4+H2))) =slope*A+(pcp*vpdslope*rca*As)/(raa+rca) 108 Eq. ref. (2.79) (2.80) (2.81) (2.77) (2.78) (2.75) 8 n2 9 10 PMc n1 11 n2 12 13 14 15 PMs total ET =slope+psycho*(1 + rcs/(raa+rca)) =H7/H8 =slope*A+(pcp*vpdslope*rsa*Ac)/(raa+rsa) =slope+psycho*(1+rss / (raa+rsa)) =H10/H11 =H5*H9+H6*H12 vap. pres. def. at mcf =vpd+(raa/pcp)*(slope*A(slope+psycho)*LET) (2.75) (2.75) (2.76) (2.76) H13: LET (2.76) (2.74) H15: vpd0 (2.82) After the total latent heat flux has been calculated, we can next calculate the vapor pressure deficit at the mean canopy flow, D0 (cell H15). D0 is needed to calculate the latent heat and sensible heat fluxes of the soil and crop components, as shown below: +Ro w 17 18 19 Col. G Col. H 20 21 ET soil itg ET soil 22 LATENT HEAT n1 n2 Cell name =slope*As+pcp*vpd0/rsa =slope+psycho * (rss+rsa)/rsa =H18/H19 H20: LETs Daily ET soil (mm) =H21*3600/2454000 H22: PETs 23 24 25 n1 n2 26 27 ET crop itg ET crop =slope*Ac+pcp*vpd0/rca =slope+psycho * (rcs+rca)/rca =H24/H25 H26: LETc 28 Daily ET crop (mm) =H27*3600/2454000 H28: PETc Daily total ET (mm) =H22+H28 29 30 Eq. ref. (2.83) (2.83) (2.83) section 2.3.10 section 2.3.10 (2.84) (2.84) (2.84) section 2.3.10 section 2.3.10 To determine the amount of water lost from the crop and soil on a daily basis, we need to integrate the latent heat fluxes over the whole day (from 0.0 to 24.0 hours). As before, we will use BuildIt’s integration operation, ITG. In the Control worksheet, do the following: In cells D3 and D4, type daily soil latent heat flux and daily crop latent heat flux, respectively. In cells E3 to J4, type the following: 3 4 E itg itg F =th =th G =LETs =LETc H =EnergyBal!H21 =EnergyBal!H27 109 I 0 0 J 24 24 For convenience, the specification of ITG will be repeated below: ITG (x, func, output, lower, upper, single_integral) which specifies the integration of the function func of variable x on the interval [lower, upper]. The result of integration is to be stored in the output cell. The last argument, single_integral, specifies if it is a single or multiple integration (TRUE for the former, FALSE for the latter). Row 3 in the Control worksheet specifies the integration operation to determine the daily soil heat flux. The soil heat flux function (LETs or cell H20 in EnergyBal worksheet) of local solar hour (th or cell B10 in the Control worksheet) will be integrated from 0 to 24 hours, and the result stored in cell H21 in the EnergyBal worksheet. Likewise, row 4 in the Control worksheet specifies the integration of the crop heat flux function (LETc) over the same interval, with the result being stored in H27 in the EnergyBal worksheet. In the EnergyBal worksheet, the integration results in cells H21 and H27 are converted to unit mm of water, and they are stored in cells H22 and H28, respectively. 3.6.5 Sensible heat fluxes and foliage temperature The daily soil and crop sensible heat fluxes are calculated in a similar manner as shown below: Row 32 33 Col. G SENSIBLE HEAT n1 34 n2 35 36 H soil itg H soil 37 Daily H soil (MJ m-2) =H36*3600/1000000 38 39 n1 40 n2 41 42 H crop itg H crop =psycho*Ac*(rcs+rca)pcp*vpd0 =slope*rca+psycho * (rcs+rca) =H39/H40 43 Daily H crop (MJ m-2) =H42*3600/1000000 H total Daily H total (MJ m-2) =H35+H41 =H37+H43 foliage temp. =((H41*rca+H45*raa)/pcp) + ta 44 45 46 47 48 Col. H Cell name =psycho*As*(rss+rsa)pcp*vpd0 =slope*rsa+psycho * (rss+rsa) =H33/H34 In the Control worksheet, do the following: 110 Eq. ref. (2.85) (2.85) (2.85) section 2.3.10 section 2.3.10 (2.86) (2.86) (2.86) section 2.3.10 section 2.3.10 H48: Tf (2.40) In cells D5 and D6, type daily soil sensible heat flux and daily crop sensible heat flux, respectively. From cells E5 to J6, type the following: 5 6 E itg itg F =th =th G =EnergyBal!H35 =EnergyBal!H41 H =EnergyBal!H36 =EnergyBal!H42 I 0 0 J 24 24 Row 5 and 6 in the Control worksheet specify that the functions for soil and crop sensible heat fluxes (cells H35 and H41 in the EnergyBal worksheet, respectively) are integrated on the interval [0, 24] hours to obtain their daily values which are stored, in the EnergyBal worksheet, in cells H36 and H42, respectively. Cells H37 and H43 in the EnergyBal worksheet store the results in units MJ m-2. Recall that earlier we had removed the definition of Tf from cell B2 in the Photosynthesis worksheet. We did that because we will calculate the foliage temperature from the crop and total sensible heat fluxes and the result will be stored in cell H48 in the EnergyBal worksheet. Consequently, now define the name Tf to the cell H48 in the EnergyBal worksheet. All cell formulas containing references to Tf will now refer to this cell H48. 3.6.6 Simulation exercise 3.7 Tables worksheet (soil water data) Insert a new worksheet and rename it to Tables. This is the worksheet where tabulated data are stored. In the next section, we will implement the soil water balance model component. Consequently, we will store the data related to that component in this worksheet. Two data sets are required at the moment. They depict the relationship between: 1) the soil matric suction head and the volumetric water content, and 2) the hydraulic conductivity and volumetric water content. The following shows the two tables in the Tables worksheet: Row 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Col. A WATER RETENTION vwc 0.005 0.01 0.025 0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4 0.45 1 Col. B Col. D HYDRAULIC COND. vwc 0.005 0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4 0.45 1 matric (m) 10000 3500 1000 200 40 10 6 3.5 2.2 1.4 0.56 0 0 111 Col. E k (m/day) 3.46E-09 4.32E-08 1.3E-07 6.91E-07 4.32E-06 2.59E-05 0.000173 0.001037 0.006912 0.0432 0.0432 The tabulated data showing the soil water retention characteristics ranges from A3:B15, whereas the data set for hydraulic conductivity is from D3:E13. 3.8 Soil water balance worksheet Insert a new worksheet and rename it to WaterBal. This worksheet implements the soil water balance. As before, we will begin by specifying the inputs for this model component which are mostly related to soil properties: Row 1 2 3 4 5 6 7 8 Col. A INPUT vwc airdry water vwc wilting point initial vwc rooting depth Col. B Cell name 0.01 B2: vwcres 0.07 B3: vwcpwp iteration per time step 100 fraction =stepsize/B6 0.4 0.2 Eq. ref. B5: rootdepth B8: frac The volumetric soil water content at air dry and wilting points are specified in cells B2 and B3, respectively. Recall that the saturated water content has already been specified in cell B15 in the EnergyBal worksheet. We are assuming that the soil profile is uniformly wet at every beginning of the simulation run. The initial soil water content is specified in cell B4. Cell B5 is the rooting depth, assumed as constant. When we later implement the plant growth model component, this value will change according to the simulation time. The calculations in this worksheet are highly repetitive and time-consuming. This is because hydraulic conductivity is very sensitive to soil water content. Choosing a time step size that is too large (e.g., 1 day time step) causes large and unrealistic fluctuations in the daily soil water content. Consequently, we require that a within each time step, another iteration cycle be carried out to simulate the soil water flow. The number of sub-iterations to run for each time step is specified in cell B6. In the case here, the value given is 100 which is adequate because the hydraulic conductivity in this example is slow (maximum of 0.0432 m day-1; see the Tables worksheet). For higher values of hydraulic conductivity, a higher value than 100 subiterations (e.g., 500 or more) may be required to prevent large fluctuations in the daily water cycle. Cell B8 contains the formula =_stepsize/B6 which divides the time step size, _stepsize, by the number of sub-iterations (cell B6). Recall that for each time step, there will be another iteration cycle to simulate the soil water flow. The value in cell B8 will be later used to calculate the rainfall intensity and evaporation rate. We are now ready to determine the actual evapotranspiration based on the actual soil water content: Row 1 Col. D ACTUAL Col. E Cell name 112 Eq. ref. 2 3 4 5 6 EVAPORATION relative vwc ETs reduction AETs (m/day) =E25/vwcsat =1/(1+(3.6073*E2)^-9.3172) =frac*PETs*E3/1000 (2.90) (2.90) (2.90) (2.93) 7 ACTUAL TRANSPIRATION critical pt. 8 9 vwc root zone ETc reduction 10 11 12 AETc (m/day) =vwcpwp+0.5*(vwcsatvwcpwp) =MAX(E34:J34)/rootdepth =IF(E8>=E7,1, IF(E8<=vwcpwp,0,(E8vwcpwp)/(E7-vwcpwp))) =frac*PETc*E9/1000 rainfall (m) =(rain/1000)*frac (2.92) (2.92) E10: AETc (2.91) The rates for rainfall (cell E12) and actual evapotranspiration (cells E4 and E10) are divided by 1000 to convert their values from unit mm to m. They are also multiplied by frac to adjust their rates due to the sub-iteration cycle within each time step. Cell E8 contains the calculated volumetric water content in the root zone. Its calculation methodology which will be explained later. 3.8.1 Partitioning of soil profile into layers and their initial soil water content The soil profile is divided into six layers, where the first two layers have a thickness of 0.05 and 0.1 m, respectively. The thicknesses of the other four soil layers are equal to each other at 0.2 m. As stated earlier, the soil water content in all layers are assumed equal to each other at the start of every simulation run. The initial volumetric water content for all layers is specified in cell B4, and their soil water content, converted to unit mm, are stored in cells E22:J22. Nevertheless, cells E24:J24 are the soil water content at the current time step. This means that when the simulation begins, the initial soil water content in cells E22:J22 must be copied to cells E24:J24 to indicate the soil water content for the layers for the first time step. And to copy these values, BuildIt’s operation, INI, is used. In the Control worksheet, do the following: In cell D20, type PRERUN. In cell D21, type initial soil water content. In cell D22, define the name _prerun. This indicates to BuildIt that the list of initiation operations (such as INI) will be stated starting from cell D22. In cells E21 to G21, type the following: 21 E ini F =WaterBal!E24:J24 Recall that INI has the following specification: INI (destination, source) 113 G =WaterBal!E22:J22 which specifies that the contents from source cells will be copied to the cells referred to in the destination cells. In our case, cells E22:J22 will be copied to cells E24:J24 (both source and destination cells are in the WaterBal worksheet). 3.8.2 Water fluxes The main goal of all the calculations in the soil water model component is to determine the net water flux in each soil layer (cells E42:J42) so that the water content in the next time step is simply computed as i,t 1 i,t qˆi where i,t and i,t+1 are the water content in soil layer i (m) at time step t and t+1, respectively; and qˆi is the net flux in soil layer i (m day-1). Cells E24:J24 and E43:J43 are the soil water content for the soil layers at the current time step (i.e., i, t ) and the next time step (i.e., i, t 1 ), respectively. For instance, cells E24:J24 and E43:J43 are the water content at time t1 and t2, respectively. Once the soil water content for all layers are determined at time t2, we copy the values from cells E43:J43 to cells E24:J24, so that cells E24:J24 and E43:J43 will now become the water content at time t2 and t3, respectively. We then repeat these operations until simulation ends. To copy contents from one or more cells to another, we use BuildIt’s REP operation. In the Control worksheet, do the following: In cell D7, type daily water content. In cells E7 to H7, type the following: 7 E rep F =WaterBal!E24:J24 G =WaterBal!E43:J43 H =WaterBal!B6 Recall that REP has the following specification: REP (destination, source, num_of_replacements) which specifies that the contents from source cells will be copied to the cells referred to in the destination cells, and this copying operation will be done num_of_replacements number of times. In our case, cells E43:J43 will be copied to cells E24:J24 (both source and destination cells are in the WaterBal worksheet) a hundred times (cell B6 in the WaterBal worksheet). Based on the current volumetric water content (cells E25:J25), the hydraulic conductivity (cells E26:J26) and matric suction head (cells E27:J27) for all soil layers will be determined by looking up the tabulated data in the Tables worksheet. Looking up the tables in this case uses the BuildIt’s function, interpolate, which has the following specification: interpolate (array_x, array_y, find_x) Based on an array of given (x, y) values, the interpolate function returns y corresponding to the given find_x. If no exact match is found, this function performs a linear interpolation to obtain y. For example, interpolate(Tables!$A$4:$A$16, Tables!$B$4:$B$16, 0.2) 114 looks up the water retention table in the Tables worksheet (where cells A4:A16 is the x values and cells B4:B16 the y values) and returns the exact value of 6. However, the following interpolate(Tables!$A$4:$A$16, Tables!$B$4:$B$16, 0.22) returns 5 by linear interpolating between (0.2, 6) and (0.25, 3.5). Note that the hydraulic conductivities for all layers (cells E26:J26) are multiplied by frac because there will be several iteration steps (100, in our case) within each time step to simulate the water flow. The next step is to determine the hydraulic gradient (which is simply the sum of the both the matric suction and gravity heads, where the latter is equal to the depth of the layer from the soil surface) and the mean hydraulic conductivity (cells E28:J28 and E29:J29, respectively). However, before we can calculate the water flux into each layer, we have to determine the amount of water lost from each layer via evaporation and transpiration. Water is lost by evaporation from the first soil layer only because this layer is in contact with the atmosphere (cells E39:J39). That this layer is in contact with the atmosphere also means that this layer receives water input via rainfall. Consequently, the water flux into the first soil layer is equal to the amount of rain it receives minus water lost by the actual evaporation and transpiration rates (cell E41). For the other soil layers, water flux is as determined by Darcy’s law and this calculated amount is additionally subtracted for water lost via transpiration (evaporation is taken as 0 for all soil layers below the first layer) (cells F41:J41). Once the water flux into each layer is calculated, the next step is to determine the net water flux (cells E42:J42) which is simply the difference of the amount of water flowing into and out of a given soil layer. A positive net flux means the given soil layer is gaining more water; hence, becoming wetter. In contrast, a negative net flux means the given soil layer is losing more water and becoming drier. Cells E43:J43 simply computes the water content for each soil layer for the next time step. BuildIt will copy their values into cells E24:J24 using the REP operation which we have specified in the Control worksheet. All the above calculations repeat, using the soil water content in cells E24:J24 to determine the new soil water content in cells E43:J43, and the latter values are copied again into cells E24:J24, and this cycle repeats until the subiteration loop terminates (after a hundred times in our case). Finally, we no longer require the volumetric soil water input in cell B14 in the EnergyBal worksheet to calculate the soil surface resistance to heat fluxes. Instead we will use the soil water content for the first soil layer as calculated in the WaterBal worksheet. This means that, in the EnergyBal worksheet, modify the formula in cell E44 from =E43*EXP(-(1/B17)*B14/vwcsat) to =E43*EXP(-(1/B17)*WaterBal!E25/vwcsat) 115 The following shows the entries in the WaterBal worksheet to determine the net flux of water in the individual soil layers: Row 14 15 16 17 18 19 20 21 22 23 24 25 26 Col. D thickness cum. thickness depth flow distance airdry water saturated water initial water soil water (t1) vwc hydraulic cond. 27 matric suction 28 hydraulic gradient Col. E SOIL LAYERS 1 0.05 =E16 Col. F Col. G Col. H Col. I Col. J Eq. ref. 2 0.1 =F16+E17 3 0.2 =G16+F17 4 0.2 =H16+G17 5 0.2 =I16+H17 6 0.2 =J16+I17 (2.88) =0.5*E16 =E18 =vwcres*E16 =vwcsat*E16 =E18+0.5* (E16+F16) =F18-E18 =vwcres*F16 =vwcsat*F16 =F18+0.5* (F16+G16) =G18-F18 =vwcres*G16 =vwcsat*G16 =G18+0.5* (G16+H16) =H18-G18 =vwcres*H16 =vwcsat*H16 =H18+0.5* (H16+I16) =I18-H18 =vwcres*I16 =vwcsat*I16 =I18+0.5* (I16+J16) =J18-I18 =vwcres*J16 =vwcsat*J16 =$B$4*E16 =$B$4*F16 =$B$4*G16 =$B$4*H16 =$B$4*I16 =$B$4*J16 (2.87) (2.102) section 2.4.11 =E24/E16 =interpolate (Tables! $D$3:$D$13, Tables! $E$3:$E$13, E25)*frac =interpolate (Tables! $A$3:$A$15,T ables! $B$3:$B$15, E25) =E27+E18 =F24/F16 =interpolate (Tables! $D$3:$D$13, Tables! $E$3:$E$13, F25)*frac =interpolate (Tables! $A$3:$A$15,T ables! $B$3:$B$15, F25) =F27+F18 =G24/G16 =interpolate (Tables! $D$3:$D$13, Tables! $E$3:$E$13, G25)*frac =interpolate (Tables! $A$3:$A$15, Tables! $B$3:$B$15, G25) =G27+G18 116 =H24/H16 =interpolate (Tables! $D$3:$D$13,T ables! $E$3:$E$13, H25)*frac =interpolate (Tables! $A$3:$A$15, Tables! $B$3:$B$15, H25) =H27+H18 =I24/I16 =interpolate (Tables! $D$3:$D$13,T ables! $E$3:$E$13, I25)*frac =interpolate (Tables! $A$3:$A$15, Tables! $B$3:$B$15, I25) =I27+I18 =J24/J16 =interpolate (Tables! $D$3:$D$13,T ables! $E$3:$E$13, J25)*frac =interpolate (Tables! $A$3:$A$15, Tables! $B$3:$B$15, J25) =J27+J18 section 2.4.6 section 2.4.7 (2.101) 29 30 31 mean hydraulic cond. rootdepth/cum . thickness n-th layer =rootdepth/ E17 =AND(E31<=1, E31>=0) 33 soil water for roots 34 cum. soil water (root zone) =IF(E32,E25 *(E16-(E17rootdepth)), E25*E16) =E33 32 35 36 cj 37 psi 38 transpiration =MIN(1,E17/ rootdepth) =1.8*E360.8*E36^2 =E37*AETc 39 40 41 evaporation =E4 flux in =E12(E39+E38) 42 43 net flux soil water (t2) =E41-F41 =MAX(E20, MIN(E21, E24+E42)) =(E26*E16 + F26*F16) / (F16+E16) =(F26*F16 + G26*G16) / (G16+F16) =(G26*G16 + H26*H16) / (H16+G16) =(H26*H16 + I26*I16) / (I16+H16) =(I26*I16 + J26*J16) / (J16+I16) (2.103) =rootdepth/ F17 =AND(F31<=1, F31 >= (E17/F17)) =IF(F32,F25* (F16-(F17rootdepth)), F25*F16) =IF(AND( NOT(E32), E34>0),E34+ F33,0) =rootdepth/ G17 =AND(G31<=1, G31 >= (F17/G17)) =IF(G32,G25* (G16-(G17rootdepth)), G25*G16) =IF(AND( NOT(F32), F34>0),F34+ G33,0) =rootdepth/ H17 =AND(H31<=1, H31 >= (G17/H17)) =IF(H32,H25* (H16-(H17rootdepth)), H25*H16) =IF(AND( NOT(G32), G34>0),G34+ H33,0) =rootdepth/ I17 =AND(I31<=1, I31 >= (H17/I17)) =IF(I32,I25* (I16-(I17rootdepth)), I25*I16) =IF(AND( NOT(H32), H34>0),H34+ I33,0) =rootdepth/ J17 =AND(J31<=1, J31 >= (I17/J17)) =IF(J32,J25* (J16-(J17rootdepth)), J25*J16) =IF(AND( NOT(I32), I34>0),I34+ J33,0) (2.96) =MIN(1,F17/ rootdepth) =1.8*F360.8*F36^2 =(F37-E37) * AETc 0 =MIN(1,G17/ rootdepth) =1.8*G360.8*G36^2 =(G37-F37) * AETc 0 =MIN(1,H17/ rootdepth) =1.8*H360.8*H36^2 =(H37-G37) * AETc 0 =MIN(1,I17/ rootdepth) =1.8*I360.8*I36^2 =(I37-H37) * AETc 0 =MIN(1,J17/ rootdepth) =1.8*J360.8*J36^2 =(J37-I37) * AETc 0 (2.99) =((F28-E28) *F29/F19)(F39+F38) =F41-G41 =MAX(F20, MIN(F21, F24+F42)) =((G28-F28) *G29/G19)(G39+G38) =G41-H41 =MAX(G20, MIN(G21, G24+G42)) =((H28-G28) *H29/H19)(H39+H38) =H41-I41 =MAX(H20, MIN(H21, H24+H42)) =((I28-H28) *I29/I19)(I39+I38) =I41-J41 =MAX(I20, MIN(I21, I24+I42)) =((J28-I28) *J29/J19)(J39+J38) =J41-J26 =MAX(J20, MIN(J21, J24+J42)) (2.102) 117 (2.96) (2.95) (2.94) (2.98) (2.97) (2.89) (2.104) (2.105), section 2.4.11 3.8.3 Simulation exercise 3.9 Tables worksheet (plant growth data) Data pertaining to plant growth will be tabulated in the Tables worksheet (the same location as the tabulated data for soil water). Three types of tables will be stored here. They are related to the: 1) partitioning of dry matter to various plant parts (such as stem, leaves, roots and storage organs), 2) specific leaf area, and 3) growth development rate Below shows the various tables for dry matter partitioning to the plant parts: Row 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 Col. A DRY MATTER PARTITIONING (DVS vs. fraction) LEAVES 0 0.1 0.25 0.5 0.7 0.95 2.5 Col. B 0.325 0.325 0.462 0.435 0.1395 0 0 STEM 0 0.1 0.25 0.5 0.7 0.95 0.175 0.175 0.198 0.435 0.7905 0.975 1.05 2.5 0 0 Row 38 Col. A ROOTS Col. B 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 0 0.1 0.2 0.35 0.4 0.5 0.6 0.7 0.8 0.9 1 1.1 1.2 2.5 0.5 0.5 0.4 0.22 0.17 0.13 0.1 0.07 0.05 0.03 0.02 0.01 0 0 STORAGE ORGANS 0 0.95 1.05 2.5 0 0 0.98 0 55 56 57 58 The table for dry matter partitioning to leaves is located in cells A20:B26, stem in cells A29:B36, roots in cells A39:B52, and storage organs in cells A55:B58. The partitioning of the dry matter to the various plant parts depends on the growth development stage (DVS). The partitioning to leaves, for example, is 32.5% from DVS 0 to 0.1, and increases to 46.2% at DVS 0.25. However, at near anthesis (DVS 0.95), the dry matter partitioning to leaves is zero. The next tabulated data required is the change in specific leaf area with DVS: Row 18 19 20 21 Col. F SPECIFIC LEAF AREA DVS 0 2.5 118 Col. G SLA 0.022 0.022 In our case, we are assuming that the specific leaf area is always constant at 0.022 m2 g-1. The final tabulated data required is the relationship between air temperature and growth development rate (DVR). Two tables are presented in our case: one for before anthesis (DVS1) and another for after anthesis (DVS>1): Row 24 25 26 27 28 29 30 31 32 33 34 Col. F TEMP vs. GROWTH DEV. RATE before anthesis 0 30 42 TEMP vs. GROWTH DEV. RATE after anthesis 0 30 42 Col. G 0 0.01 0.01 0 0.013 0.013 The table for before anthesis is located in cells F26:G28, and for after anthesis in cells F32:G34. 3.10 Plant growth worksheet Before we proceed to implement the plant growth component of the model, we need to remove some name definitions from several cells. Recall that leaf area index, plant height and rooting depth were previously supplied as constant model inputs because the plant growth model has yet to be implemented. However, with the plant growth model component, these model inputs should no longer be required as they will be calculated and they will vary with the plant growth development stage. In the Photosynthesis worksheet, remove the name definition lai from cell B3. In the EnegyBal worksheet, remove the name definition h from cell B3. In the WaterBal worksheet, remove the name definition rootdepth from cell B5. After you remove these name definitions, some cells will display the error message NAME#? because these cells refer to names that we had deleted. For the moment, ignore these error messages because we will later define the same names to other cells in the worksheet implementing the plant growth model component. We are now ready to implement the plant growth component. Insert a new worksheet and rename it to Growth. For model inputs, we will arrange them as usual in the upper left corner of the worksheet: Row 1 2 3 4 5 Col. A INPUT max rooting depth root growth rate max plant hgt hgt growth slope Col. B Cell name 1 0.012 0.6 0.007 119 Eq. ref. hgt growth intercept base temp dvs<1 base temp dvs>1 max dead leaf coef. 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 67 0 0 0.03 CONSTANTS Maintenance stem leaves roots storage organs 0.015 0.03 0.015 0.01 Growth stem leaves roots storage organs 1.513 1.463 1.444 1.415 Cells B2:B9 are model inputs, where cells B2 and B3 denote the maximum rooting depth and root growth rate, respectively. Cells B5 and B6 are the coefficients for plant height growth, and cells B7 and B8 are the base temperatures for plant growth before and after anthesis, respectively (both taken as 0 C). Lastly, cell B9 is the coefficient for maximum leaf death. Cells B13:B16 are the coefficients for maintenance requirement for the various plant parts. Likewise, cells B19:B22 are the coefficients for growth requirement for the plant parts. 3.10.1 Growth development rate and stage The scale for the plant growth development stage (DVS) ranges from 0 (plant emergence) to 1 (flowering) and ends with 2 (maturity). DVS is incremented based on the current growth development rate (DVR) as shown below: Row 2 3 4 5 6 Col. D dev. stage (DVS) (t1) dev. rate (DVR) preanthesis dev. rate (DVR) postanthesis DVR Col. E Cell name E2: dvs dev. stage (DVS) (t2) =dvs+E5*_stepsize =interpolate(Tables! F26:F28, Tables! G26:G28,tmean) =interpolate(Tables! F32:F34, Tables! G32:G34,tmean) =IF(dvs<=1,E3,E4) Eq. ref. (2.106) section 2.5.1 section 2.5.1 section 2.5.1 (2.106) Cell E2 is the current growth development stage (DVS) and its next DVS is determined in cell E6 which contains the formula =dvs+E5*_stepsize 120 which can be represented symbolically as s,t 1 s,t r ,t t where s,t and s,t+1 are the DVS at time t and subsequent time step t+1; t is the time step size (days); r,t is the growth development rate (DVR) (days-1) at time t. The plant’s growth development rate, as stated earlier, depends on air temperature. This relationship is tabulated in the Tables worksheet earlier, where there are two sets of table: one for before and another for after anthesis. using the interpolate function, the DVR before anthesis is contained in cell E3, and the DVR after anthesis is in cell E4. In cell E5, DVR is set equal to cell E3 if DVS is greater than or equal to 1; otherwise DVR is set equal to E4 for DVS > 1. Using this current value for DVR, the DVS for the next time step is calculated in cell E6. Once calculated, the value in cell E6 is copied to cell E2, and the cycle repeats. To implement this copying operation, BuildIt’s REP is used (see section 3.10.6). Also note that cell E2 is left blank because, as stated earlier, BuildIt will copy the value of DVS in cell E6 to cell E2 using the REP operation. However, we must supply an initial value of DVS for the first time step. This initial value will be supplied using BuildIt’s INI operation (see section 3.10.6). 3.10.2 Maintenance and growth respiration Water stress effects the amount of assimilates actually produced. It is reduced linearly depending on the ratio between the actual and potential transpiration rates. This ratio was previously calculated in cell E9 in the WaterBal worksheet. Below shows their calculations in Excel: Row 8 9 Col. D Growth reduction Assimilates Col. E =WaterBal!E9 =assim*E8 Cell name Eq. ref. (2.121) (2.122) Cell E8 merely refers to cell E9 in the WaterBal worksheet, and the actual assimilates available for maintenance and growth is scaled accordingly in cell E9 in the Growth worksheet. Cells E13:E17 are the current weights of the plant parts, and they are used to determine their maintenance requirement (cells F13:F17). The maintenance requirement for all part parts are then summed (cell F18) and adjusted for air temperature (cell E21) and plant age (cell E22). Cell E23 ensures that the total maintenance requirement does not exceed the total available assimilates. Assimilates left after fulfilling the maintenance requirement is subsequently available for growth (cell E24). Growth requirement for individual plant parts (cells H13:H17) are calculated based on the dry matter partitioning to the plant parts (cell G13:G17) which are obtained from the tabulated data in the Tables worksheet using the interpolate function. The growth requirement for all the plant parts are summed (cell H18) and used to determine the growth rate of the individual plant parts (cells E25 and I13:I17). Once the growth rates are calculate, we can update the weights of the plant parts for the next time step. 121 As stated earlier, cells E13:E17 are the current weights of the plant parts, and their weights are updated (for the next time step) in cells J13:J17 which contain the formula, described symbolically as Wi,t 1 Wi, t i t where Wi,t and Wi,t+1 are the weights (g m-2 ground area) of a given plant part i (stem, roots or storage organs) at time step t and subsequent time step t+1, respectively; t is the time step size (days); and i is the growth rate for plant part i. This translates to mean that weights Wi,t and Wi,t+1 are cells E13:E17 and J13:J17, respectively; growth rates, i, are cells I13:I17; and time step size, t, is _stepsize. Note that the weight gain by leaves are calculated differently than other plant parts because we have to account for leaf death, if any. Leaf death can be caused by two possibilities: 1) due to leaf age (cell E28), or 2) due to self-shading (cell E29). The maximum of those two is the actual leaf death (cell E30). This value is then used in cell I15 to calculate the death rate of leaves. Consequently, the difference between the growth and death rates of the green leaves determine the weight gain or loss of the green leaves (cell J14). The MAX function in cell J14 ensures that weight of green leaves do not become negative. Once the weights of the plant parts are updated in J13:J17, their values are copied to cells E13:E17. These calculations repeat to determine the weight change in the plant parts for every subsequent time step. To enable copying of cells J13:J17 to E13:E17, BuildIt’s REP operation is used (see section 3.10.6). Also note that cells E13:E17 are blank because their values will be copied from cells J13:J17, as described earlier. However, we must supply the initial weights to these plant parts for the first time step. For this purpose, we will use BuildIt’s INI operation (see section 3.10.6). 122 The following illustrates the calculation of the various plant growth processes in the Growth worksheet: Row 11 Col. D Current plant weight Col. E Col. F Col. G Col. H Col. I Col. J weight (t1) partitioning =interpolate (Tables! A29:A36, Tables! B29:B36,dvs) =interpolate (Tables! A20:A26, Tables! B20:B26,dvs) growth req. =G13*B19 growth rate =G13*E25 weight (t2) =E13+I13* _stepsize =G14*B20 =G14*E25 =MAX(0,E14+ (I14-I15)* _stepsize) (2.109), (2.110), (2.116) =E14*E30 =E15+I15* _stepsize =E16+I16* _stepsize (2.115) =E17+I17* _stepsize (2.109), (2.110), (2.111) 12 13 stem maint. req. =E13*B13 14 green leaves =E14*B14 15 dead leaves 16 roots =E16*B15 17 storage organs =E17*B16 18 total 19 20 Respiration =SUM(E13:E17) =SUM(F13: F17) =interpolate (Tables! A39:A52, Tables! B39:B52,dvs) =interpolate (Tables! A55:A58, Tables! B55:B58,dvs) =SUM(G13: G17) 123 =G16*B21 =G16*E25 =G17*B22 =G17*E25 =SUM(H13: H17) =SUM(J13: J17) Eq. ref. (2.109), (2.110), (2.111) (2.109), (2.110), (2.111) 21 maint (tempadjust) 22 pot. maint 23 24 total maint available for growth total growth 25 26 27 28 Leaf death due to old age 29 due to selfshading 30 actual leaf death rate =F18*2^ ((tmean-25) /10) =E21*E14/ SUM(E14:E15) =MIN(E22,E9) =E9-E23 (2.109) (2.109) (2.109) (2.111), (2.116) (2.111), (2.116) =IF(H18>0, E24/H18,0) =IF(E2>1, interpolate( Tables! F32:F34, Tables! G32:G34, tmean)/ MIN(0.1, 2dvs),0) =IF(lai>Lcr, MIN(B9, B9*(lai-Lcr) /Lcr),0) =MAX(E28,E29) (2.113) (2.114) (2.112) 124 3.10.3 Leaf area index Calculations to determine the leaf area index (LAI) is simple (cell E34). It is merely the weight of the green leaves (cell E14) multiplied by the specific leaf area (cell E33), where the latter is obtained from the tabulated data in the Tables worksheet. The following shows their determination: Row 32 33 Col. D LAI specific leaf area 34 LAI Col. E Cell name =interpolate(Tables! F20:F21,Tables!G20:G21, dvs) =E14*E33 Eq. ref. (2.117) E34: lai (2.117) Note that the name lai is defined for cell E34. 3.10.4 Rooting depth Roots only grow when three conditions are met: 1) DVS is before anthesis (cell E38), 2) soil water content in the root zone (cell E8 in the WaterBal worksheet) is above the soil’s permenant wilting point (cell E39), and 3) the current rooting depth is less than the maximum rooting depth (cell E40). When all these three conditions are true, the rooting depth is updated for the next time step (cell E42). The value in cell E42 is then copied to cell E36 so that these calculations can be repeated to determine the growth of the rooting depth for every subsequent time step. To copy cell E42 to E36, we will use BuildIt’s REP operation (see section 3.10.6). We also need to specify the initial rooting depth for cell E36 using BuildIt’s INI operation (see section 3.10.6). The following shows the calculations for the rooting depth: Row 36 37 38 39 40 41 42 Col. D Rooting depth rooting depth (t1) pre-anthesis? water > wilting point? less than max depth? root growth rate rooting depth (t2) Col. E Cell name Eq. ref. E33: rootdepth (2.120) =dvs<1 =WaterBal!E8>vwcpwp (2.120) (2.120) =E37<B2 (2.120) =B3*E8 (2.120) =IF(AND(E38,E39,E40),E37+ E41*stepsize,E37) (2.120) Note that the name rootdepth is defined for cell E37. 3.10.5 Plant height The growth of plant height requires the calculation of the daily degree day (cell E46) and cumulative degree days (cell E47). To sum the daily degree day in cell E46 to E47, we will use BuildIt’s ACC operation (see section 3.10.6). We next proceed to calculate the plant growth rate (cell E52) to determine the plant height for the next time step (cell E53). This value is then copied to cell E49 so that these calculations are repeated to determine the plant height growth for every subsequent time step. To copy cell E53 to E49, we will use BuildIt’s REP operation (see section x3.10.6). As 125 before, we also need to supply an initial value for plant height in cell E49 for the first time step. To do this, BuildIt’s INI operation is used (see section 3.10.6). The following shows the calculations for plant height growth: Row 44 45 46 47 48 49 50 51 52 53 Col. D Plant height base temp degree day cum. degree days plant height (t1) n1 n2 height growth rate plant height (t2) Col. E Cell name =IF(dvs<=1,B7,B8) =MAX(0,tmean-E45) Eq. ref. (2.107) (2.107) (2.108) E49: h (2.118) =B6*B5*B4*EXP(-B5*E47) =1+B6*EXP(-B5*E47) =(E46*E50/E51^2)*E8 (2.119) (2.119) (2.119) =E49+E52*_stepsize (2.118) Note that the name h is defined for cell E49. 3.10.6 BuildIt’s operations for plant growth The model component for plant growth requires several BuildIt’s operations (INI, REP and ACC) to accomplish its goals. Initial values must be supplied to: 1) DVS, 2) rooting depth, 3) plant height, and 4) the individual plant part weights. In cells D22 to G29 in the Control worksheet (in the _prerun section), type the following: 22 23 24 25 26 27 28 29 D DVS rooting depth plant height stem wgt green leaves wgt dead leaves wgt roots wgt storage organs wgt E ini ini ini ini ini ini ini ini F =dvs =rootdepth =h =Growth!E13 =Growth!E14 =Growth!E15 =Growth!E16 =Growth!E17 G 0 0.03 0.01 0.3 0.5 0 0.8 0 This means that the initial value for DVS is 0 (denoting plant emergence), rooting depth is 0.03 m and plant height is 0.01 m. Recall that the weights for the plant parts are located in cells E13:E17 in the Growth worksheet. The initial values for stem, green leaves, dead leaves, roots and storage organs are 0.3, 0.5, 0.0, 0.8 and 0.0 g, respectively. At the start of a simulation run, BuildIt will refer to the _prerun section in the Control worksheet and copy the values in column G to their specified destinations as specified in column F. In cells D8 to H12 in the Control worksheet (in the _operation section), type the following: 8 9 D degree days daily plant part weights E acc rep F =Growth!E46 =Growth!E13:E17 126 G =Growth!E47 =Growth!J13:J17 H + 1 10 11 12 rooting depth plant height growth dev. stage rep rep rep =rootdepth =h =dvs =Growth!E42 =Growth!E53 =Growth!E6 1 1 1 Rows 9 to 12 indicate that the values from the source cells as specified in column G will be copied to the destination cells as specified in column F. For example, in the Growth worksheet, values from cells J13:J17 will copied to E13:E17, from E42 to E33 (rootdepth), from E53 to E49 (h), and from E6 to E2 (dvs). These copy operations are to ensure that the plant part weights, rooting depth, plant height and DVS are updated for the next time step. The value 1 in column H indicate that these copy operations should only occur once per time step. In row 8, the ACC operation is used to accumulate the daily degree day to determine the cumulative degree days. Recall that the ACC operation has the following specification: ACC (x, accumulated_x, operator) where operator can either be + or * for addition or multiplication, respectively. If the operator is addition (as in our case), ACC is equivalent to accumulated_x xi i But if the operator is multiplication, ACC is equivalent to accumulated_x xi i Cells E8:H8 specify to BuildIt that it should sum each time step’s daily degree day from cell E46 and place the total in cell E47 in the same Growth worksheet. It is important to note that ACC operation (row 8) should be specified before the REP operation for updating the plant height (row 11). This is because the growth of plant height uses the cumulative degree days in its calculations. 3.11 Finalizing the model 3.11.1 Criteria to end simulation run (Control worksheet) There are two more tasks left to do to complete building the gcg model in Excel. The first is to modify the criteria to stop the model simulation run. Previously, we stated that simulation should end after a specified number of runs; that is, in the Control worksheet, we entered the following criteria in cell B5: =(step/_stepsize)<maxsteps We will add one more criterion. Simulation run should continue so long as: 1) the specified number of runs has not been reached, and 2) that the growth development stage of the plant (DVS) is 2 or less. Consequently, in cell B5 in the Control worksheet, enter the following: =AND((_step/_stepsize)<maxsteps,dvs<=2) Recall that the AND function returns TRUE only when both conditions (_step/_stepsize)<maxsteps and dvs<=2 are TRUE. 127 3.11.2 Model output results (output worksheet) The second task to do before we complete building the model is to specify which model variables should be displayed at every time step. Model output is displayed in the Output worksheet. In the Output worksheet, we previously defined the name _read to cell A2. BuildIt uses this cell position as a starting point to determine which model variables should be displayed at every time step; that is, all cells to its right will be read by BuildIt to determine which model variables are to be displayed. Complementing _read is _write because the latter name determines where the model results should be displayed. We previously defined cell A6 in the Output worksheet with the name _write. Consequently, this cell position will be used as a starting position where the output will be displayed; that is, all cells to its right will be used for displaying model output. In the Output worksheet, type the following (due to space constraints, the following table is presented with rows and columns running vertically and horizontally, respectively): Col. A B C D E F G H I J K L M N O P Q R S T U V W X Y Z Row 1 date elapsed rain vwc layer 1 vwc layer 2 vwc layer 3 vwc layer 4 vwc layer 5 vwc layer 6 DVS LAI GreenLv DeadLv Stem Roots Storage Hgt Root depth Photosyn ETc red Assim Maint Growth ETc ETs Total ET Row 2 =date =date-Control!B7 =rain/1000 =WaterBal!E25 =WaterBal!F25 =WaterBal!G25 =WaterBal!H25 =WaterBal!I25 =WaterBal!J25 =dvs =lai =Growth!E14 =Growth!E15 =Growth!E13 =Growth!E16 =Growth!E17 =h =rootdepth =assim =Growth!E8 =Growth!E9 =Growth!E23 =Growth!E25 =PETc =PETs =EnergyBal!H30 Row 3 FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE Cell A2 is the simulation date, and cell B2 is the number of elapsed days since the simulation start date. Cell C2 is the amount of rainfall (in meters), and is a convenient reference variable because the following six cells (D2:I2) are the volumetric soil water content for the first to the sixth and last layer. Cell J2 is the growth development stage of the plant, followed by cell K2 which is the leaf area 128 index. Cells L2:P2 are the weights for the green leaves, dead leaves, stem, roots and storage organs, respectively. Plant height is contained in cell Q2, followed by the rooting depth in cell R2. The total amount of assimilates produced potentially is in cell S2. However, due to water stress, this amount can be reduced by a fraction as displayed in cell T2 to give the actual assimilates produced via photosynthesis in cell U2. Cells V2 and W2 are the maintenance and growth respiration rates, respectively. the last three cells concern the potential rates for evaporation, transpiration and their total. The FALSE values in some cells in the third row are to instruct BuildIt to output the values of the corresponding cells at the beginning of every iteration run (Fig. xxx). If left blank or if the cells contain TRUE, BuildIt will only display the values of the corresponding cells at the end of each iteration run. How do we decide if to display a given variable at the start or end of every iteration run? We should choose the former option (i.e., FALSE) if we wish to display the variable’s value before it is changed in the iteration cycle. For example, in the first time step, t1, we supplied initial values to the soil water content for each soil layer. In this case, the values of the soil water content before entering the loop should be displayed. This is because when the model enters the first iteration cycle, the water fluxes are calculated and the soil water content in each layer is updated for the second time step, t2. If we choose to display their values at the end of the iteration cycle (i.e., TRUE), we then erroneously display the soil water content at t2 for t1. This is why other variables such as leaf area index, weights of the plant parts, plant height and rooting depth should be displayed before each iteration cycle. Their values will be updated for the next time step within the iteration cycle. Other variables such as photosynthesis and evapotranspiration should be displayed at the end of each iteration cycle because their values are only known after they have been calculated within each iteration cycle. The variables listed in cells A2:Z2 in the Output worksheet are only examples of model variables that can be displayed in every iteration cycle. You may add more variables or delete some of them as required. Once the model output has been specified, the model can be run by choosing the Start Simulation from the BuildIt menu. 129