public void AddCatchment() { GlobalDefinition gd = new GlobalDefinition(); CatchmentDefinition catchment = new CatchmentDefinition { Id = "catchment-124" }; const int numCells = 9; for (int cells = 0; cells < numCells; cells++) { CellDefinition cell = new CellDefinition { Id = "cell-" + cells }; catchment.Cells.Add(cell); } gd.AddCatchment(catchment); Assert.That(gd.Count, Is.EqualTo(1)); List <CellDefinition> gdCells = gd.GetFlatCellList(); Assert.AreEqual(gdCells.Count, numCells); foreach (CellDefinition cell in gdCells) { Assert.That(catchment.Cells, Contains.Item(cell)); } }
/// <summary> /// Initializes a new instance of the <see cref="BaseGriddedCatchmentObjectiveEvaluator"/> class. /// </summary> /// <param name="globalDefinitionFileInfo">The global definition file info.</param> /// <param name="objectivesDefinitionFileInfo">The objectives definition file info.</param> /// <param name="rank">The rank of the process in the 'world'</param> /// <param name="size">World communicator size</param> /// <param name="worldCommunicator">The world communicator</param> protected BaseGriddedCatchmentObjectiveEvaluator(FileInfo globalDefinitionFileInfo, FileInfo objectivesDefinitionFileInfo, int rank, int size, IIntracommunicatorProxy worldCommunicator) { // funny smell: WorldRank and rank are the same thing, always. Should remove one. this.rank = rank; this.size = size; WorldRank = GetWorldRank(); IsFirstRun = true; if (IsMaster && GetWorldSize() < 2) { throw new ConfigurationException("At least 2 MPI processes are required to run this application."); } ObjectiveDefinitionFileName = objectivesDefinitionFileInfo.FullName; Log.DebugFormat("Rank {0}: Loading global definition", WorldRank); //Added by Bill Wang on 27/10/2014 to read split catchment-based calibration definition files if (globalDefinitionFileInfo.FullName.EndsWith(".csv", true, null)) { StreamReader sr = null; GlobalDefinition = new GlobalDefinition(); try { sr = new StreamReader(globalDefinitionFileInfo.FullName); sr.ReadLine(); //skip the header line for (string line = sr.ReadLine(); line != null; line = sr.ReadLine()) { FileInfo catchmentFileInfo = new FileInfo(line.Split(new char[] { ',' })[1]); GlobalDefinition catchmentDef = SerializationHelper.XmlDeserialize <GlobalDefinition>(catchmentFileInfo); foreach (var cat in catchmentDef.Catchments) { GlobalDefinition.AddCatchment(cat); } } } catch (Exception e) { Log.Error(e.ToString()); throw e; } finally { if (sr != null) { sr.Close(); } } } else { GlobalDefinition = SerializationHelper.XmlDeserialize <GlobalDefinition>(globalDefinitionFileInfo); } Log.DebugFormat("Rank {0}: global definition complete", WorldRank); world = worldCommunicator; }
static public void RandomCatchments(this GlobalDefinition globalDef, int numCatchments, int minCellCount = 1, int maxCellCount = 50) { for (int i = 0; i < numCatchments; i++) { CatchmentDefinition catchment = new CatchmentDefinition { Id = "catchment-" + Rand.Next() }; int numCells = Rand.Next(minCellCount, maxCellCount + 1); for (int cells = 0; cells < numCells; cells++) { CellDefinition cell = new CellDefinition { Id = "cell-" + Rand.Next(), CatchmentId = catchment.Id }; cell.ModelRunDefinition.PopulateWithTestData(); catchment.Cells.Add(cell); } globalDef.AddCatchment(catchment); } }