Skip to content

MIKE+ Engine Tool

Purpose and scope

This chapter is to describe how to use the MIKE+ engine tool to run all kind of simulations. It works on both windows and Linux.

Command line to run MIKE+ simulations

DHI.MIKEPlus.EngineShell.dll can be used to run the simulation in command line on Windows. You can also use dotnet sdk to run this tool on Linux.

Usage:
    DHI.MIKEPlus.EngineShell.exe [Options] [File] -- for windows
    dotnet DHI.MIKEPlus.EngineShell.dll [Options] [File] -- for windows/Linux
Options:
    -h: Show the help
    -e: Export files for simulation
    -r: Run simulation
    -rb: Run batch simulation
    -m: Model to operate (CS, WD, SWMM)
    -id: Simulation ID, if not specified, active simulation is used
    -gpu <gpu count> <Device id>: Run simulation on GPU. If there is no gpu count specified, it will use all GPU. This is only avaliable for 2d overland module and flooding module.
    -mpi <Process core count>: Run simulation Parallelly by MPI. If there is no process core count specified, it will use all process core. This is only avaliable for 2d overland module and flooding module.
    -simtype <simulation type>: Only works for EPANET special analysis.
    -id <Special analysis id>' is needed. It is the special analysis id.
    Simulation type list:
        n=21 : PIPECRITICALITY analysis
        n=22 : FIREFLOW analysis
        n=23 : SHUTDOWNPLANNING analysis
        n=24 : FLUSHINGALAYSIS analysis
        n=25 : EPANET simulation with OPTIMIZATION
        n=26 : EPANET simulation with AUTOCALIBRATION

File:
    MIKE+ MuppOrSqlite file
Examples:
    DHI.MIKEPlus.EngineShell.exe -h
        Show the usage
    DHI.MIKEPlus.EngineShell.exe -e demo.sqlite
        Export active model and simulation to files in demo.sqlite
    DHI.MIKEPlus.EngineShell.exe -r demo.sqlite
        Run simulation for active model and simulation in demo.sqlite
    DHI.MIKEPlus.EngineShell.exe -e -m CS -id SimID demo.sqlite
        Export CS model to files for 'SimID' in demo.sqlite
    DHI.MIKEPlus.EngineShell.exe -r -m CS -id SimID demo.sqlite
        Run simulation for CS model with SimID in demo.sqlite
    DHI.MIKEPlus.EngineShell.exe -r -gpu 2 demo.sqlite
        Run simulation for active simulation by using 2 gpu
    DHI.MIKEPlus.EngineShell.exe -r -mpi 2 demo.sqlite
        Parallelly run simulation for active simulation by using 2 CPU with MPI
    DHI.MIKEPlus.EngineShell.exe -r -simtype 22 -id 'Fireflow_Demo' demo.sqlite
        Run fire flow simuation for 'Fireflow_Demo'

MIKE+ API to run the simulation

DHI.Amelia.Tools.EngineTool can be reference to run all kinds of simulations in MIKE+.

Method name Description
RunEngine_CS run simulation for "Rovers, collection system and overland flows" module
RunEngine_CS_Batch batch run all the simulations which have included in the btach
RunEngine_LTS_JobList run long term statistics simulation
RunEngine_AllEpanet run simulation for "Water distribution" module
RunEngine_AllEpanet run fireflow simulation for WD module
RunEngine_AllSWMM run simulation for "SWMM5 collection system and overland flows" module
ExportToM1dXFile Export current active simulation setup into .m1dx file, only the data for MIKE 1D engine
Export_EpanetINPFile Export current active simulation setup into .inp file, only the data for Epanet engine
Export_SwmmINPFile Export current active simulation setup into .inp file, only the data for SWMM engine
Export_SetupPfsFile Export current active simulation setup into .couple file or .m21fm, only the data for coupling engine and FemEngine

There are several simulation options when using above RunEngine_ methods. Please check below enum for detail. The simulation options have been set down by MIKE+ database for "Rovers, collection system and overland flows" and "SWMM5 collection system and overland flows". You can't configure the SimulationOption for these two module. But SimulationOption can be delivered to RunEngine_AllEpanet.

public enum MUSimulationOption
{
    UNDEFINED = 0,
    CS_MIKE_1D,
    CS_MIKE_1D_JobList,
    CS_MIKE_21FM,
    CS_MIKE_COUPLING,
    CS_MIKE_COUPLING_21FMModelLink,
    CS_MIKE_BATCH,
    CS_SWMM,
    CS_SWMM_BATCH,
    WD_EPANET,
    WD_EPANET_PIPECRITICALITY,
    WD_EPANET_FIREFLOW,
    WD_EPANET_FIREFLOW_HYD,
    WD_EPANET_SHUTDOWNPLANNING,
    WD_EPANET_FLUSHINGALAYSIS,
    WD_EPANET_OPTIMIZATION,
    WD_EPANET_BATCH,
    CS_MIKE_1D_PESE,
    SWMM_MIKE_COUPLING,
    SWMM_MIKE_COUPLING_21FMModelLink,
}

Example

Example to run CS, river and coupling simulations.

using DHI.Amelia.Tools.EngineTool
using DHI.Amelia.DataModule.Interface.Services;
using DHI.Amelia.DomainServices.Interface.SharedEntity;
using DHI.Amelia.GlobalUtility.Constants.DbTablesAndFields;
using DHI.Amelia.GlobalUtility.DataType;

var engineTool = new EngineTool.EngineTool { DataTables = _dataTables };

DhiEngineSimpleLauncher launcher;
List<string> msgs;

if (inputParam.RunBatch
    ? !engineTool.RunEngine_CS_Batch(out launcher, out msgs)
    : inputParam.RunJobList
        ? !engineTool.RunEngine_LTS_JobList(out launcher, out msgs, cmdLine.SimulationID)
        : !engineTool.RunEngine_CS(out launcher, out msgs, cmdLine.SimulationID))
{
    msgs.Add("\n" + "The simulation is not allowed.");
    Logging(msgs);
    return;
}
if (launcher != null)
{
    launcher.UseGPU = inputParam.useGPU;
    launcher.GPUCount = inputParam.gpuCount;
    launcher.UseMPI = inputParam.useMPI;
    launcher.ProcCount = inputParam.procCount;
    launcher.Start();
}

Example to run WD simulations.

using DHI.Amelia.Tools.EngineTool
using DHI.Amelia.DataModule.Interface.Services;
using DHI.Amelia.DomainServices.Interface.SharedEntity;
using DHI.Amelia.GlobalUtility.Constants.DbTablesAndFields;
using DHI.Amelia.GlobalUtility.DataType;

List<string> msgs;
DhiEngineSimpleLauncher launcher = null;
launcher = new DhiEngineSimpleLauncher();
// Run simulation out of process
var engineTool = new EngineTool.EngineTool { DataTables = _dataTables };

var activeOption = inputParam.simOption;
if (inputParam.simOption == MUSimulationOption.UNDEFINED)
    activeOption = MUSimulationOption.WD_EPANET;
else if ((int)inputParam.simOption < (int)MUSimulationOption.WD_EPANET || (int)inputParam.simOption > (int)MUSimulationOption.WD_EPANET_AUTOCALIBRATION)
{
    Console.WriteLine(string.Format("Simulation option of '{0}' is not supported for this module. Default EPANET option will be used.", inputParam.simOption.ToString()));
    activeOption = MUSimulationOption.WD_EPANET;
}

// Fire flow is quite special, there are some option which needs GUI input.
// For commandline, it doesn't need to consider GUI input params.
CancellationToken token = new CancellationToken();
if (activeOption == MUSimulationOption.WD_EPANET_FIREFLOW)
    engineTool.RunEngine_FireFlow(inputParam.SimulationID, token, null, CallBackEvent, EpanetCallBacMsg, null);
else
    engineTool.RunEngine_AllEpanet(activeOption, token, out msgs, CallBackEvent, EpanetCallBacMsg, null, inputParam.SimulationID, null);

Example to run SWMM simulations.

using DHI.Amelia.Tools.EngineTool
using DHI.Amelia.DataModule.Interface.Services;
using DHI.Amelia.DomainServices.Interface.SharedEntity;
using DHI.Amelia.GlobalUtility.Constants.DbTablesAndFields;
using DHI.Amelia.GlobalUtility.DataType;

 DhiEngineSimpleLauncher launcher = null;
 var engineTool = new EngineTool.EngineTool { DataTables = _dataTables };
 bool has2DSim = false;
 var activeOption = ((IMssProjectTable)_dataTables[DbTableNames.MssProjectTable]).GetSimulationOption(inputParam.SimulationID);
 switch (activeOption)
 {
     case MUSimulationOption.CS_MIKE_21FM:
     case MUSimulationOption.SWMM_MIKE_COUPLING:
     case MUSimulationOption.SWMM_MIKE_COUPLING_21FMModelLink:
         has2DSim = true;
         break;
 }
 if (has2DSim)
 {
     if (!engineTool.RunEngine_CS(out launcher, out var msgs, inputParam.SimulationID))
     {
         msgs.ForEach(msg => Console.WriteLine(msg));
     }
 }
 else
 {
     engineTool.RunEngine_AllSWMM(new CancellationToken(), out List<string> msgs, CallBackEvent, PinnedCallBack, simMuid: inputParam.SimulationID, launcher: launcher);
     msgs.ForEach(msg => Console.WriteLine(msg));
 }
 if (launcher != null)
 {
     launcher.Start();
 }