MIKE+ DomainService¶
Purpose and scope¶
The purpose of this module is to separate all the BL oriented data processing from GUI layer and focus on the implementation of specific logics for specific domain. This separation is also a preparation for the support of Client/Server type application.
Design & usage¶
The difference between DataModule and DomainService are as following:
- BL in DataModule is mostly data oriented and generic and does not apply only for a specific domain application. While BL in DomainService is normally not generic and only related to a specific domain.
- Besides BL, DataModule also abstract the lower level data access and data validation, while DomainService does not. E.g. different data source is handled by DataModule and is not aware by DomainService.
- DataModule is more focus on Data Access Abstraction, unit conversion and data validation. While DomainService is on complex and specific BL implementation.
- DomainService is supposed to provide a tailored APIs for GUI modules, but DataModule doesn’t directly talk to GUI modules.
DomainService interface overview¶
- IAmeliaDataService This interface is bridge between GUI and DataModule, it contians more data business logic. It contians generic data business logic.
- IAmeliaEngineService This interface is used to run MIKE+ simulations.
Table 1 Methods in IAmeliaEngineService
| Method name | Description |
|---|---|
| RunEngine_CS | run simulation for "Rovers, collection system and overland flows" module |
| RunEngine_AllEpanet | run simulation for "Water distribution" 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,
}
- IAmeliaLicenseService This interface is used to deal license affairs.
- IAmeliaMapService This interface is to deal with business logic related to map function, like split link and so on. Most of the functions are sptial analysis.
- IAmeliaEditorService This interface contains business logic which happens in MIKE+ editor GUI.
- IAmelia2DService This interface contains business logic which related to 2d overland function, is more about manpulating data in 2d overland tables.
- IAmeliaDomainService This interface contains business logic which related to flooding function, is mainly to maintain the 2d domain data in memory and files.
- IAmeliaToolService This interface contains the access to the tools engine. E.g. IAmeliaToolService.GeneralSQLTool_ExecuteSQLCommand is to execute a SQL syntax for current opend MIKE+ database.
Example to run simuation for CS MIKE 1D module¶
using DHI.Amelia.DataModule.Services.DataTables;
using DHI.Amelia.DataModule.Interface.Services;
using DHI.Amelia.DataModule.Services.DataSource;
using DHI.Amelia.DomainServices.Services;
using DHI.Amelia.DomainServices.Interface.SharedEntity;
using DHI.Amelia.GlobalUtility.DataType;
public void Run_MIKE_Plus_CS_Engine(string dbOrmuppFile)
{
// Please go to DataModule chapter to get CreateDataTableContainer function
var dataTables = CreateDataTableContainer(dbOrmuppFile);
var amlEngineService = new AmeliaEngineService();
amlEngineService.DataTables = dataTables;
amlEngineService.DataService = new AmeliaDataService() { DataTables = dataTables };
// Run the active simulation in MIKE+, you can also give a simulation id to run
amlEngineService.RunEngine_CS(out DhiEngineSimpleLauncher launcher, out List<string> msgs);
launcher.Start();
launcher.EngineStatusCB += _StatusCB;
launcher.EngineRTInfoCB += _LogMessageCB;
void _StatusCB(DhiEngineSimpleLauncher.EngineStatusType type, MUSimulationOption simType)
{
switch (type)
{
case DhiEngineSimpleLauncher.EngineStatusType.SimEnd:
// Simulation has been finished.
break;
}
}
void _LogMessageCB(DhiEngineSimpleLauncher.EngineRTInfoType type, string[] sa, MUSimulationOption simType)
{
switch (type)
{
case DhiEngineSimpleLauncher.EngineRTInfoType.LogUpdate: //Log message
break;
case DhiEngineSimpleLauncher.EngineRTInfoType.ProgreUpdate: //Progress and stat message
break;
}
}
}
Example to run simuation for WD Epanet module¶
public void RunEngineEpanent()
{
var dataTables = CreateDataTableContainer(dbOrmuppFile);
var amlEngineService = new AmeliaEngineService();
amlEngineService.DataTables = dataTables;
amlEngineService.DataService = new AmeliaDataService() { DataTables = dataTables };
var cancellationTokenSource = new CancellationTokenSource();
amlEngineService.RunEngine_AllEpanet(MUSimulationOption.WD_EPANET, cancellationTokenSource.Token, out List<string> errorMsg);
}
Example to run simuation for CS SWMMM module¶
public void RunEngineSWMM()
{
var dataTables = CreateDataTableContainer(dbOrmuppFile);
var amlEngineService = new AmeliaEngineService();
amlEngineService.DataTables = dataTables;
amlEngineService.DataService = new AmeliaDataService() { DataTables = dataTables };
var cancellationTokenSource = new CancellationTokenSource();
amlEngineService.RunEngine_AllSWMM(cancellationTokenSource.Token, out List<string> errorMsg);
}
Example to run simuation for CS 1D-2D coupling module¶
public void RunEngineCoupling()
{
var dataTables = CreateDataTableContainer(dbOrmuppFile);
(dataTables as DataTableContainer).ImportExportPfsFile = new ImportExportPfsFile();
(dataTables as DataTableContainer).UndoRedoManager = new AmlUndoRedoManager();
var amlEngineService = new AmeliaEngineService();
amlEngineService.DataTables = dataTables;
amlEngineService.DataService = new AmeliaDataService() { DataTables = dataTables };
amlEngineService.FloodDataService = new AmeliaDomainService() { DataTables = dataTables, DataService = amlEngineService.DataService };
amlEngineService.FloodDataService.UpdateDomainTopoData(); // If 2d overland simulation included
var cancellationTokenSource = new CancellationTokenSource();
amlEngineService.RunEngine_CS(out DhiEngineSimpleLauncher launcher, out List<string> msgs);
launcher.Start();
launcher.EngineStatusCB += _StatusCB;
launcher.EngineRTInfoCB += _LogMessageCB;
Thread.Sleep(10000000);
void _StatusCB(DhiEngineSimpleLauncher.EngineStatusType type, MUSimulationOption simType)
{
switch (type)
{
case DhiEngineSimpleLauncher.EngineStatusType.SimEnd:
launcher.EngineStatusCB -= _StatusCB;
launcher = null;
Environment.Exit(0);
break;
}
}
}