Skip to content

How to...

This section will answer the most common questions related to working with models in MIKE Workbench.

How can I run a scenario automatically, but only if a condition is met?

Sometimes, it is best to only trigger a simulation if a condition is met (e.g. the threshold at a station is exceeded). It is possible to set up a job, running at regular (short) intervals, that will contain two steps:

  • Target1: Checks if the condition is met. This can be done by running a script that returns TRUE or FALSE.
  • Target2: Run model, only if Target1 is TRUE

The Job Manager explains how to set up such execution.

How can I execute my scenario outside of MIKE OPERATIONS, but from the same machine / network?

Generally, MIKE OPERATIONS simulations are started either manually (e.g. from MIKE Workbench, MIKE OPERATIONS Desktop or MIKE OPERATIONS Web) or on schedule (i.e., with a Job).

Sometimes, the execution should be triggered by / from an external application, for example if an event is dedected.

Depending on the complexity of the task, two options are possible. Either a Job is configured and triggered externally or MIKE OPERATIONS is loaded in memory.

Job exectution

A Job can be configured with a Runs a scenario task that will execute the model. This Job can then be triggering using:

"C:\Program Files (x86)\DHI\MIKE OPERATIONS\2025\bin\DHI.Solutions.JobManager.JobRunner.exe" /user:user /password:password /target:target

Note

This will run the job using credentials set on the Windows Task Scheduler task. The job could be starting another job, which would then run simulations under the same credentials as all other MO jobs (i.e., just trigger the job service to start a new job).

For more information, read the Job Manager documentation.

In memory MIKE OPERATIONS

MIKE OPERATIONS has APIs and can be accessed from external tools and scripts. The key is to connect to the database by instantiating an Application object.

The example below connects such Application object to a PostgreSQL database hosted locally (localhost). After connecting, it will run the given scenario as a Job on the machine.

This approach will allow the user to update scenario inputs before running the model.

 import clr
 clr.AddReference("DHI.Solutions.Application")
 clr.AddReference('DHI.Solutions.Generic')
 clr.AddReference('DHI.Solutions.ScenarioManager.Interfaces')
 clr.AddReference('DHI.Solutions.JobManager.Interfaces')

 import DHI.Solutions.Generic
 from DHI.Solutions.ScenarioManager.Interfaces import *
 from DHI.Solutions.Application import *
 from DHI.Solutions.JobManager.Interfaces import *

 scenarioPath= "/Group of soil_moisture/soil_moisture/Scenario of soil_moisture_hungary"

 dbflavour="PostgreSQL"
 dbhost = "localhost"
 dbport = "5432"
 dbuser = "user"
 dbpw = "password"
 dbname = "database"

 app = Application()
 cnn = r"Host="+dbhost+";Database="+dbname+";Port="+dbport+";dbflavour="+dbflavour
 app.SetConnection(cnn);
 app.Login(dbuser, dbpw, "workspace1");
 app.StartUp();

 sModule = app.Modules.Get('Scenario Manager')
 scenarioModule = IScenarioModule(sModule)

 jmodule = app.Modules.Get('Job Manager')
 jobModule = IJobModule(jmodule)

 jobs = jobModule.JobHosts
 scenario = scenarioModule.ScenarioList.Fetch(scenarioPath);
 jobInstance = scenarioModule.RunScenarioAsJob(jobModule.JobHosts[0], scenario, False, False)

How can I execute my scenario from outside my network?

When interacting with MIKE OPERATIONS from outside the network on which the system is installed, the user should use REST calls and open up MIKE OPERATIONS with the WebAPIs.

With MIKE OPERATIONS 2025.2, WebAPIs are provided with the installation (C:\Program Files (x86)\DHI\MIKE OPERATIONS\2025\bin\WebApi).

The documentation is provided on request.