Windows Create and Debug Model

From OpenM++
Jump to: navigation, search

Contents

Where is OpenM++

Optional: Before you begin

If you want to debug your model then you will need to rebuild openM++ runtime library first as described at Windows Quick Start for Developers

Create New Model

  • create new directory for your model under models subfolder i.e.: C:\SomeDir\models\MyModel. It is not required, but recommended to have folder name same as your model name.
  • copy one of the test model VC++ project files into your model subfolder, i.e.: from C:\SomeDir\models\NewCaseBased\ompp\* into C:\SomeDir\models\MyModel\ompp
  • copy your model files *.ompp *.mpp and custom.h files into C:\SomeDir\models\MyModel\code\ subfolder
  • copy your data files *.odat *.dat files into C:\SomeDir\models\MyModel\parameters\Default\ subfolder
  • start Visual Studio and open C:\SomeDir\models\MyModel\ompp\Model.vcxproj project
  • save your new Model.sln solution
  • build your model

At bottom Output window of Visual Studio you will see something like:

1>Model.vcxproj -> C:\SomeDir\models\MyModel\ompp\bin//MyModelD.exe
1>Model.vcxproj -> C:\SomeDir\models\MyModel\ompp\bin//MyModelD.pdb (Partial PDB)
1>2017-06-06 20:43:34.0479 MyModel
1>2017-06-06 20:43:34.0547 Run: 102
1>2017-06-06 20:43:34.0550 Get fixed and missing parameters
1>2017-06-06 20:43:34.0554 Get scenario parameters
1>2017-06-06 20:43:34.0561 Sub-value 0
1>2017-06-06 20:43:34.0565 compute derived parameters
1>2017-06-06 20:43:34.0569 Initialize invariant entity data
1>2017-06-06 20:43:34.0572 Member=0 simulation progress=0%
1>..........
1>2017-06-06 20:43:35.0115 member=0 write output tables - finish
1>2017-06-06 20:43:35.0126 Writing Output Tables Expressions
1>2017-06-06 20:43:35.0160 Done.
1>Done building project "Model.vcxproj".
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

You can set model name of your new model either in Visual Studio or by editing C:\SomeDir\models\MyModel\ompp\Model.props in Notepad:

<MODEL_NAME>MyModel</MODEL_NAME>

Debug your Model

  • build your model as described above
  • copy default model database into model "current directory", otherwise you will get an exception with error message:
DB error: unable to open database file

If you are debugging under Visual Studio then your "current directory" is your project directory and you need copy C:\SomeDir\models\MyModel\ompp\output\MyModel.sqlite into C:\SomeDir\models\MyModel\ompp\

  • open file om_definitions.cpp
  • put breakpoint at any of model entry point at RunModel function or at other meodel entry points:
    • RunOnce
    • RunInit
    • ModelStartup
    • ModelShutdown
  • and start debugger
File:Model debug vstudio 20180205.png
Debug MyModel in Visual Studio

<metadesc>OpenM++: open source microsimulation platform</metadesc>

<metadesc>OpenM++: open source microsimulation platform</metadesc>