public void SetStateInitialConditions(Mike1DData mike1DData, IDiagnostics diagnostics) { // State file name template IFilePath stateFilePath = mike1DData.Connection.FilePath.Clone(); stateFilePath.Extension = ".sta1d"; stateFilePath.FileNameWithoutExtension += "-{0}"; // DateTime of state to use. Here using mike1DData.SimulationStart; DateTime startTime = mike1DData.SimulationStart; stateFilePath.Path = string.Format(stateFilePath.Path, startTime.ToString("yyyyMMddTHHmmss")); // If state file exists, use it if (System.IO.File.Exists(stateFilePath.FullFilePath)) { StatestartInfo statestartInfo = new StatestartInfo(stateFilePath); mike1DData.StatestartInfos.Add(statestartInfo); diagnostics.Info("Using state file: " + stateFilePath.Path); } else { diagnostics.Info("Could not find any state file named: " + stateFilePath.Path); } }
/// <summary> /// This method will add catchment connections to nodes with /// the same id as the catchment id, for catchments in the <paramref name="rrFile"/> /// </summary> private static void UpdateCatchmentConnections(Mike1DData mike1DData, IFilePath rrFile, IDiagnostics diagnostics) { // Make a map of all node id's - for fast searching on node id, used to only add connections to existing nodes var nodeIdDictionary = new HashSet <string>(mike1DData.Network.Nodes.Select(n => n.Id), StringComparer.OrdinalIgnoreCase); // Assume rrFile path is relative to setup file. rrFile.BaseFilePath = mike1DData.Connection.FilePath; // load rrFile - but only header, not data. IResultData resultData = new ResultData(); resultData.Connection = Connection.Create(rrFile); Diagnostics resultDiagnostics = new Diagnostics("Example"); resultData.LoadHeader(resultDiagnostics); // Create new CatchmentConnections int countCreated = 0; int countSkipped = 0; foreach (IRes1DCatchment res1DCatchment in resultData.Catchments) { // Only add if node with this ID exists if (nodeIdDictionary.Contains(res1DCatchment.ID)) { CatchmentConnection catchmentConnection = new CatchmentConnection { Fraction = 1, CatchmentId = res1DCatchment.ID, NodeId = res1DCatchment.ID }; mike1DData.Network.CatchmentConnections.Add(catchmentConnection); countCreated++; } else { diagnostics.Warning(new DiagnosticItem(string.Format("Catchment-Node with ID {0} not found, catchment is ignored", res1DCatchment.ID))); countSkipped++; } } string msgs = string.Format("Updating Catchment Connections {0}, skipped {1} - for file: {2}", countCreated, countSkipped, rrFile.Path); Console.Out.WriteLine(msgs); diagnostics.Info(msgs); }
public void ModifySetup(Mike1DData mike1DData, IDiagnostics diagnostics, bool addWaterDepth = false, double alpha = 1.0) { // Use diagnostics object to add to setup log file diagnostics.Info(string.Format("Modifying setup, adding depth: {0}", addWaterDepth)); // Add Water Depth to default HD result output ResultSpecification hdResSpec = mike1DData.ResultSpecifications.Find(rs => rs.ID == "DefaultHDResults"); if (hdResSpec != null) { if (addWaterDepth) { hdResSpec.What.Add(Quantity.Create(PredefinedQuantity.WaterDepth)); } } // Change alpha parameter mike1DData.HDParameters.SolverSettings.Alpha = alpha; }