You are not logged in. Click here to log in.

Application Lifecycle Management

Search In Project

Search inClear

Tags:  not added yet

CSMLite - The Simple Modular Crop Simulation Model Example

Download
CSMLite Project
CSMLite is a small crop growth simulation model written in FORTRAN, containing a main program and primary subroutines for weather, soil water availability, and plant growth. A more detailed description of the model can be found at http://www.icasa.net/modular/index.html. The modular design of the model makes it a good training example for integration with the OMS framework. The original source code files can be accessed as noted below. The following exercises demonstrate the relevant steps to developing and maintaining the model as shown in the Figure below in OMS.

Invalid link [!/OMS FORTRAN Training/Slide3.PNG!]

The Figure above shows the conceptual structure of the CSMLite model.

  • Components are shown in boxes, representing different states within the execution.
  • Connecting arrows between the boxes represent data flow of some sort
    • Parameter settings
    • Data flow between components within a timestep
    • Data flow between components across a timestep

The Listing below (csm.sim) shows the OMS representation of the Data flow Figure as an executable simulation script.

/*
 * $Id: csm.sim 64915db25869 2011-10-23 23:38 -0600 Olaf David <odavid@colostate.edu> $
 *
 * Simulation file.
 */
sim(name:"CSM") {

    // for building from within the OMS Console
    build()

    // mostly for DLL/SO resources
    resource "$oms_prj/dist"

    // define output strategy: output base dir and
    // the strategy NUMBERED|SIMPLE|TIME
    //    outputstrategy(dir: "$oms_prj/output", scheme:SIMPLE)

    // run the model while the control component is not done.
    model (while:"control.notDone") {

        components {
            'control'       'csm.gen.Controller'    // model controller
            'input'         'csm.gen.Input_Init'    // input paramter from file
            'we'            'csm.gen.Weather_Rate'  // climate input
            'sw_rate'       'csm.gen.SW_Rate'       // SW rate
            'sw_integ'      'csm.gen.SW_Integ'      // SW integr
            'sw_outpt'      'csm.gen.SW_Outpt'      // SW ouput
            'pl_rate'       'csm.gen.Plant_Rate'    // plant rate
            'pl_integ'      'csm.gen.Plant_Integ'   // plant integration
            'pl_outpt'      'csm.gen.Plant_Outpt'   // plant output
        }
    
        connect {
            // control connect
            'control.doy' 'we sw_rate pl_rate \
                           sw_integ pl_integ \
                           sw_outpt pl_outpt'

            // weather input
            'we.srad' 'sw_rate sw_integ sw_outpt'
            'we.tmax' 'sw_rate sw_integ sw_outpt pl_rate pl_integ pl_outpt'
            'we.tmin' 'sw_rate sw_integ sw_outpt pl_rate pl_integ pl_outpt'
            'we.rain' 'sw_rate sw_integ sw_outpt'
            'we.par'  'pl_rate pl_integ pl_outpt'

            // input 
            'input.doyp'  'pl_rate pl_integ pl_outpt'

            // rate calculations
            'sw_rate.swfac1' 'pl_rate'
            'sw_rate.swfac2' 'pl_rate'
            
            // integration
            'pl_rate.lai' 'sw_integ'
            'sw_integ.swfac1' 'pl_integ'
            'sw_integ.swfac2' 'pl_integ'
            
            // output phase
            'pl_integ.lai' 'sw_outpt'
            'sw_outpt.swfac1' 'pl_outpt'
            'sw_outpt.swfac2' 'pl_outpt'
        }

        feedback {
             // carry lai into next day
            'pl_integ.lai'  'sw_rate'
        }
            
        parameter {
            // general
            'control.count'         3
            'input.simctrl'         "$oms_prj/data/SIMCTRL.INP"
            'we.simctrl'            "$oms_prj/data/WEATHER.INP"

            // soil water
            'sw_rate.soil_inp'      "$oms_prj/data/SOIL.INP"
            'sw_rate.irrig_inp'     "$oms_prj/data/IRRIG.INP"
            'sw_rate.sw_out'        "$oms_prj/output/sw.out"

            // plant
            'pl_rate.plant_inp'     "$oms_prj/data/PLANT.INP"
            'pl_rate.plant_out'     "$oms_prj/output/plant.out"
        }

        // optional logging 
        logging {
            'csm.Sw'        'OFF'
            'csm.Plant'     'OFF'
            'csm.Input'     'OFF'
            'csm.Weather'   'OFF'
        }
    }
}



EXERCISE 1 - Load the OMS CSMLite Modeling Project

The purpose of this exercise is to demonstrate how to create a modeling project in OMS. OMS provides the CSM project called oms3.prj.csm containing the directory structure and configuration/properties files for Netbeans and OMS so that modelers do not have to spend a lot of time setting this up. In most cases, modelers will modify existing projects such this ome to create new ones. For this training, the basic template and the CSMLite project will be provided to participants.

Exercise Steps

  1. Copy oms3.prj.csm to a directory of your choosing.
  2. Start Netbeans and open this projects
  3. Start the OMS Console and select this project

During this exercise we will review the contents of the projects, and review OMS relevant features in Netbeans.

Reference Section

  • Getting Started - Netbeans and the OMS Console

EXERCISE 2 - Features of the OMS Console

The purpose of this exercise is to become familiar with the functionality of the OMS Console.

Exercise Steps
  1. Start the OMS Console and select the oms3.prj.csm project
  2. Interact with the 17 buttons and features of the main console.
  3. Go to the Parameter editor. The features of the editor will be explained. Explore the functionality of the tool.
  4. Go to the Analysis Output Window. The features of this tool will be explained. Explore the functionality of the tool.

Reference Section

  • Getting Started - Netbeans and the OMS Console

EXERCISE 3 - Study the CSMLite Components for OMS

The purpose of this exercise is to gain initial proficiency in studying the annotations of FORTRAN source code files so that they can be later adjusted and compiled into OMS components.

Exercise Steps
  1. Start Netbeans and open the oms3.prj.csm project.
  2. Double click on the incomplete CSMLite component to bring up the source code in the edit window.
  3. Study the component annotations, JNA-related syntax, and FORTRAN to C data type mapping as necessary.
  4. Right click on the oms3.prj.csm to clean and build project. Examine and correct errors. When build is successful, check resulting output to the build and dist folders.

Reference Sections

  • Creating FORTRAN Science Components
  • OMS Annotation Reference

EXERCISE 4 - Use OMS DSL to Run a Unit Test of a CSMLite Component

The purpose of this exercise is to build proficiency in creating and running unit tests of OMS FORTRAN components.

Exercise Steps
  1. Start OMS Console and select oms3.prj.csm project.
  2. Open the incomplete unit test simulation file.
  3. Complete the unit test simulation file.
  4. Run the test simulation and examine results.

Reference Sections

  • Creating FORTRAN Science Components
  • OMS Annotation Reference

EXERCISE 5 - Use OMS DSL to Build and Run the CSMLite Model

The purpose of this exercise is to become proficient in creating simulations for building and running OMS models, including setting parameters, provisioning input data, and managing, visulizing, and analyzing output.

Exercise Steps
  1. Start the OMS Console and select the oms3.prj.csm project.
  2. Open the incomplete simulation file (with .sim extension).
  3. Complete the sub-elements in the simulation file
    1. Specify the output strategy
    2. Specify the components
    3. Connect the components
    4. Connect feedback components
    5. Add data input and parameters
    6. Compare the new simulation file to the completed counterpart.
  4. Run the simulation and inspect output/error logs
  5. Modify and add sub-elements in the simulation file at your discretion
    1. Change parameter values at your discretion
    2. Add more analysis elements to the simulation (optional)
  6. Re-Run the simulation and inspect output/error logs

Reference Sections

  • Building and Running a Model of FORTRAN Science Components in OMS
  • OMS DSL Reference

EXERCISE 6 - Generate Model System Documentation Automatically

The purpose of this exercise is to understand how the OMS auto-documentation process works.

Exercise Steps
  1. Start the OMS Console and open the oms3.prj.csm project
  2. Select the CSMLite simulation
  3. Click on the Auto-Doc button on the console toolbar and watch the output/error window to check progress.
  4. Open and examine the CSMLite XML file in the output folder.
  5. An instructor will open and display a PDF created from the XML file.

Reference Section

  • Creating OMS Model System Documentation

EXERCISE 7 - Modify the CSMLite Model

Download
CSMLite with Plant2
The purpose of this exercise is to understand the process for replacing one science component with another and re-building the model.

Exercise Steps
  1. Start Netbeans and open the oms3.prj.csm project.
  2. Open the Plant2 source code file.
  3. Annotate and modify to make OMS compatible
  4. Compare to completed OMS compatible source code file
  5. Right click on oms3.prj.csm to clean and build project
  6. Check contents of build and dist folders
  7. Start OMS Console and select oms3.prj.csm
  8. Open new simulation
  9. Copy contents of previous basic simulation to new simulation
  10. Modify components, connect, and feedback sub-elements to incorporate replacement component.
  11. Run new simulation and check output/error logs

Reference Sections

  • Creating OMS Fortran Science Components
  • Building and Running a Model of FORTRAN Science Components in OMS
  • OMS Annotation Reference
  • OMS DSL Reference

EXERCISE 8 - Consider Options for Data Input and Output Management

The purpose of this exercise is to explore various approaches for managing data input and output with OMS.

Exercise Steps
  1. Start the OMS Console and select oms3.prj.csm project
  2. Engage in facilitated discussion to examine data I/O management on the OMS Java side visavis on the FORTRAN side.

Reference Section

  • Provisioning Data to OMS Models (Data Input/Output)

EXERCISE 9 - Use OMS DSL to Calibrate a Model

The purpose of this exercise is to introduce the shuffled complex evolution method of model calibration using the Luca tool. The direction of this exercise will be determined after discussion with participants during the workshop.

Exercise Steps

  1. Start the OMS Console and select either oms3.prj.csm or oms3.prj.prms.
  2. Open a Luca simuation.
  3. Run the simulation and view results
  4. Make changes to the elements and sub-elements
  5. Re-run the simulation and view results

Reference Sections

  • Building and Running a Model of FORTRAN Science Components in OMS
  • OMS DSL Reference

CSMLite Model Source Code, Simulation, and Data Files

CSMLite Source Code


Original
Main
Weather
Soil-Water Availability
Plant Growth

Adjusted for OMS
Provided to participants via mobile storage device

Alternative CSMLite Plant Component
Alternative Plant Component
Adjusted Simulation Control Data Input File
Adjusted FORTRAN Main

CSMLite OMS Simulation Files

Provided to participants via mobile storage device

CSMLite Data Input Files
Provided to participants via mobile storage device

CSMLite Output Files
Provided to participants via mobile storage device