public void ValueTest() { // arrange var loss = new TransmissionLoss(3, 0.0271, 5.3407, 50, 240, 720); // act var lossValue = loss.Value; // assert Assert.AreEqual(0.38, lossValue, 0.01); }
public ActionResult Transmission(TransmissionLossModel model) { if (!ModelState.IsValid) { model.HasResult = false; return(PartialView("_TransmissionResults", model)); } var loss = new TransmissionLoss( model.PhaseCount, model.Resistivity, model.Current, model.Length, model.Size, model.Time); model.Loss = loss.Value; model.HasResult = true; return(PartialView("_TransmissionResults", model)); }
void Copy(Scenario scenario) { Name = scenario.Name; Comments = scenario.Comments; ShowAllAnalysisPoints = scenario.ShowAllAnalysisPoints; ShowAllPerimeters = scenario.ShowAllPerimeters; ShowAllSpecies = scenario.ShowAllSpecies; StartTime = new TimeSpan(scenario.StartTime.Ticks); Duration = new TimeSpan(scenario.Duration.Ticks); TimePeriod = (TimePeriod)scenario.TimePeriod; Location = scenario.Location; Wind = scenario.Wind; SoundSpeed = scenario.SoundSpeed; Sediment = scenario.Sediment; Bathymetry = scenario.Bathymetry; // Here we map the old perimeter to the new perimeter so that the copied platform gets the proper perimeter var perimeterMap = new Dictionary<Guid, Guid>(); foreach (var perimeter in scenario.Perimeters) { var newPerimeter = new Perimeter(perimeter) { Scenario = this }; perimeterMap.Add(perimeter.Guid, newPerimeter.Guid); Perimeters.Add(newPerimeter); } var modeMap = new Dictionary<Guid, Guid>(); var allModes = new List<Mode>(); foreach (var platform in scenario.Platforms) { var newPlatform = new Platform(platform) { Scenario = this }; // Make sure the new perimeter gets the proper copied perimeter from the original scenario if (platform.Perimeter != null) newPlatform.Perimeter = Perimeters.Find(p => p.Guid == perimeterMap[platform.Perimeter.Guid]); Platforms.Add(newPlatform); foreach (var source in platform.Sources) { var newSource = new Source(source) { Platform = newPlatform }; newPlatform.Sources.Add(newSource); foreach (var mode in source.Modes) { var newMode = new Mode(mode) { Source = newSource }; modeMap.Add(mode.Guid, newMode.Guid); newSource.Modes.Add(newMode); allModes.Add(newMode); } } } foreach (var analysisPoint in scenario.AnalysisPoints) { var newAnalysisPoint = new AnalysisPoint(analysisPoint) { Scenario = this }; AnalysisPoints.Add(newAnalysisPoint); foreach (var transmissionLoss in analysisPoint.TransmissionLosses) { var newTransmissionLoss = new TransmissionLoss { AnalysisPoint = newAnalysisPoint, LayerSettings = new LayerSettings(transmissionLoss.LayerSettings) }; foreach (var mode in transmissionLoss.Modes) newTransmissionLoss.Modes.Add(allModes.Find(m => m.Guid == modeMap[mode.Guid])); newAnalysisPoint.TransmissionLosses.Add(newTransmissionLoss); foreach (var radial in transmissionLoss.Radials) { var newRadial = new Radial(radial) { TransmissionLoss = newTransmissionLoss }; newTransmissionLoss.Radials.Add(newRadial); newRadial.CopyFiles(radial); } } } foreach (var species in scenario.ScenarioSpecies) { var newSpecies = new ScenarioSpecies(species) { Scenario = this }; ScenarioSpecies.Add(newSpecies); newSpecies.CopyFiles(species); } }
/// <summary> /// Update all the AnalysisPoints contained in a specified Scenario, ensuring that all modes are properly represented across /// all AnalysisPoints /// </summary> /// <param name="scenario"></param> public static void UpdateAnalysisPoints(this Scenario scenario) { // If there are no analysis points, there's nothing to update if (scenario.AnalysisPoints == null) return; // Group acoustically equivalent modes var groupedModes = scenario.GroupEquivalentModes(); if (groupedModes == null || groupedModes.Groups == null) throw new ApplicationException("groupedModes or groupedModes.Groups is null"); // Get the grouped modes into a mode convenient form - a List of Lists of equivalent modes var unmatchedModeGroups = (from CollectionViewGroup collectionViewGroup in groupedModes.Groups select (from item in collectionViewGroup.Items select (Mode)item).ToList()).ToList(); // Internal variable used to track which groups of modes have been matched to existing TransmissionLosses var matchedModeGroups = new List<List<Mode>>(); // Examine all the AnalysisPoints in the Scenario foreach (var analysisPoint in scenario.AnalysisPoints.ToList()) { // Examine each TransmissionLoss in the current AnalysisPoint foreach (var transmissionLoss in analysisPoint.TransmissionLosses.ToList()) { // If the current TransmissionLoss has no modes if (transmissionLoss.Modes == null || transmissionLoss.Modes.Count == 0) { Debug.WriteLine("Deleting empty TL at {0}", (Geo)transmissionLoss.AnalysisPoint.Geo); // Delete the current TransmissionLoss transmissionLoss.Delete(); // And look at the next one continue; } // Get a representative Mode from the current TransmissionLoss. var originalMode = transmissionLoss.Modes.First(); // Find a group of modes that matches the representative Mode var matchingModeGroup = (from modeGroup in unmatchedModeGroups let curMode = modeGroup.First() where curMode.IsAcousticallyEquivalentTo(originalMode) select modeGroup).FirstOrDefault(); // If no current mode group matches the representative Mode if (matchingModeGroup == null) { Debug.WriteLine("Deleting TL [{0}:{1}] at {2}", transmissionLoss.Modes.First().ModeName, transmissionLoss.Modes.First().MaxPropagationRadius, (Geo)transmissionLoss.AnalysisPoint.Geo); // Delete the current TransmissionLoss transmissionLoss.Delete(); // And look at the next one continue; } // Get the list of the original modes in the current TransmissionLoss that don't match the new mode group. // Match criteria (provided by GuidComparer<Mode>) are that the Guids in each mode must be identical var unmatchedOriginalModes = transmissionLoss.Modes.Except(matchingModeGroup, new GuidComparer<Mode>()).ToList(); // Remove the unmatched original modes in the current TransmissionLoss unmatchedOriginalModes.ForEach(m => { Debug.WriteLine("Removing mode [{0}:{1}] from [{2}:{3}] at {4}", m.ModeName, m.MaxPropagationRadius, transmissionLoss.Modes.First().ModeName, transmissionLoss.Modes.First().MaxPropagationRadius, (Geo)transmissionLoss.AnalysisPoint.Geo); transmissionLoss.Modes.Remove(m); m.TransmissionLosses.Remove(transmissionLoss); }); // Get the list of the modes in the new mode group that don't match modes already in the current TransmissionLoss. // Match criteria (provided by GuidComparer<Mode>) are that the Guids in each mode must be identical var unmatchedNewModes = matchingModeGroup.Except(transmissionLoss.Modes, new GuidComparer<Mode>()).ToList(); // Add those new modes to the current TransmissionLoss unmatchedNewModes.ForEach(m => { Debug.WriteLine("Adding mode [{0}:{1}] to [{2}:{3}] at {4}", m.ModeName, m.MaxPropagationRadius, transmissionLoss.Modes.First().ModeName, transmissionLoss.Modes.First().MaxPropagationRadius, (Geo)transmissionLoss.AnalysisPoint.Geo); m.TransmissionLosses.Add(transmissionLoss); transmissionLoss.Modes.Add(m); }); // Add the matching mode group to the internal holding list so we can re-use it for the next analysis point matchedModeGroups.Add(matchingModeGroup); // Remove the matching mode group from the list of unmatched mode groups so it can't match another TransmissionLoss // in the current AnalysisPoint unmatchedModeGroups.Remove(matchingModeGroup); // Update the current TransmissionLoss transmissionLoss.Update(); } // If any mode groups remain unmatched in the current AnalysisPoint, add new TransmissionLosses to hold them foreach (var newModeGroup in unmatchedModeGroups) { // Get the bathymetry for the scenario that the AnalysisPoint belongs to var bathymetry = analysisPoint.Scenario.BathymetryData; // Look up the depth at the AnalysisPoint var depthAtAnalysisPoint = bathymetry.Samples.IsFast2DLookupAvailable ? -bathymetry.Samples.GetNearestPointAsync(analysisPoint.Geo).Result.Data : -bathymetry.Samples.GetNearestPoint(analysisPoint.Geo).Data; // Get a representative mode from the list of modes var firstMode = newModeGroup.First(); // Calculate the actual source depth of the mode var sourceDepth = firstMode.Source.Platform.Depth; if (firstMode.Depth.HasValue) sourceDepth += firstMode.Depth.Value; // If the source depth is greater than the depth at this AnalysisPoint, // then don't add a TransmissionLoss for this list of modes to the current AnalysisPoint if (sourceDepth >= depthAtAnalysisPoint) { Debug.WriteLine("Skipping TL mode [{0}:{1}] at {2} because depth is too shallow ", firstMode.ModeName, firstMode.MaxPropagationRadius, (Geo)analysisPoint.Geo); continue; } // The depth check is OK, so create a new TransmissionLoss Debug.WriteLine("Creating new TL for mode [{0}:{1}] at {2}", firstMode.ModeName, firstMode.MaxPropagationRadius, (Geo)analysisPoint.Geo); var transmissionLoss = new TransmissionLoss { AnalysisPoint = analysisPoint }; // Add the list of modes to the TransmissionLoss newModeGroup.ForEach(m => { Debug.WriteLine("Adding mode [{0}:{1}] to new TL at {2}", m.ModeName, m.MaxPropagationRadius, (Geo)transmissionLoss.AnalysisPoint.Geo); transmissionLoss.Modes.Add(m); m.TransmissionLosses.Add(transmissionLoss); }); // Add the TransmissionLoss to the current AnalysisPoint analysisPoint.TransmissionLosses.Add(transmissionLoss); // Verify the TransmissionLoss, which will create the radials and queue them for calculation transmissionLoss.Update(); } // Add the matched mode groups from the last pass back into the list of unmatched mode groups for the next iteration unmatchedModeGroups.AddRange(matchedModeGroups); // Clear the matched mode group list for the next iteration matchedModeGroups.Clear(); Globals.Dispatcher.InvokeIfRequired(analysisPoint.UpdateMapLayers); } }
void ViewTransmissionLoss(TransmissionLoss transmissionLoss) { try { var transmissionLossViewModel = new TransmissionLossViewModel { TransmissionLoss = transmissionLoss }; var window = Globals.VisualizerService.ShowWindow("TransmissionLossWindowView", transmissionLossViewModel); _openPopups.Add(window); transmissionLossViewModel.Window = window; transmissionLossViewModel.SaveFileService = Globals.SaveFileService; } catch (InvalidOperationException ex) { Globals.MessageBoxService.ShowError(string.Format("Error displaying transmission loss: {0}", ex.Message)); } }
void RecalculateTransmissionLoss(TransmissionLoss transmissionLoss) { if (Globals.MessageBoxService.ShowYesNo(string.Format("Are you sure you want to recalculate this transmission loss \"{0}\"?", transmissionLoss.AnalysisPoint.Geo), MessageBoxImage.Warning) != MessageBoxResult.Yes) return; transmissionLoss.Recalculate(); }
void DeleteTransmissionLoss(TransmissionLoss transmissionLoss) { if (Globals.MessageBoxService.ShowYesNo(string.Format("Are you sure you want to delete this transmission loss \"{0}\"?", transmissionLoss.AnalysisPoint.Geo), MessageBoxImage.Warning) != MessageBoxResult.Yes) return; //transmissionLoss.LayerSettings.IsChecked = false; //transmissionLoss.RemoveMapLayers(); //await Task.Delay(50); transmissionLoss.Delete(); }