private void mnuScaleToFundamental_Click(object sender, EventArgs e) { if (Bore == null) { ShowError("You must calculate the impedance first."); return; } ScaleBoreToFundamental dlg = new ScaleBoreToFundamental((decimal)ImpedanceData.ImpedancePeakFrequencies[0]); DialogResult dr = dlg.ShowDialog(this); decimal targetFundamental = dlg.SelectedFundamental; if (dr == DialogResult.OK) { Bore previousBore = Bore; decimal currentFundamental = (decimal)ImpedanceData.ImpedancePeakFrequencies[0]; while (currentFundamental != targetFundamental) { decimal scaleAmount = currentFundamental / targetFundamental; List<BoreSection> newBoreSections = new List<BoreSection>(); foreach (BoreSection boreSection in previousBore.BoreSections) newBoreSections.Add(new BoreSection(boreSection.OpeningRadius, boreSection.ClosingRadius, boreSection.Length * scaleAmount)); Bore newBore = new Bore(newBoreSections); if (targetFundamental > currentFundamental) { Complex lastImpedance = newBore.GetImpedance((double)currentFundamental); for (decimal freq = currentFundamental + 1; true; freq++) { Complex currentImpedance = newBore.GetImpedance((double)freq); if (currentImpedance.Magnitude < lastImpedance.Magnitude) { if (newBore.InputImpedance.Count == 2) { newBore.GetImpedance((double)currentFundamental - 1); } newBore.FindResonances(2); ImpedanceData tempImpedanceData = new ImpedanceData(newBore.InputImpedance); currentFundamental = (decimal)tempImpedanceData.ImpedancePeakFrequencies[0]; previousBore = newBore; break; } lastImpedance = currentImpedance; } } else { Complex lastImpedance = newBore.GetImpedance(1); for (decimal freq = 2; true; freq++) { Complex currentImpedance = newBore.GetImpedance((double)freq); if (currentImpedance.Magnitude < lastImpedance.Magnitude) { newBore.FindResonances(2); ImpedanceData tempImpedanceData = new ImpedanceData(newBore.InputImpedance); currentFundamental =(decimal)tempImpedanceData.ImpedancePeakFrequencies[0]; previousBore = newBore; break; } lastImpedance = currentImpedance; } } } didgePropertyEditor_DimensionsChanged(); List<BoreSection> boreSections = new List<BoreSection>(); foreach (BoreSection section in previousBore.BoreSections) boreSections.Add(new BoreSection(section.OpeningRadius, section.ClosingRadius, Math.Round(section.Length, 5))); didgePropertyEditor.BoreSections = boreSections; } }
private void btnCalculate_Click(object sender, EventArgs e) { if (!didgeValid) { ShowError("There is an error with the entered dimensions."); return; } tabPlots.Enabled = true; verticalLines.Clear(); calculatedFrequencyCount = 0; DidgeDesignProperties didgeProperties = didgePropertyEditor.DidgeDesignProperties; Bore bore = new Bore(didgeProperties.BoreSections); if (bore.Length == 0) { ShowError("The bore has a length of 0."); return; } bore.CalculatedFrequency += new Bore.CalculatedFrequencyDelegate(bore_CalculatedFrequency); DidgeData data = (DidgeData)treeDidgeHistory.SelectedNode.Tag; data.didge = didgePropertyEditor.DidgeDesignProperties; data.bore = bore; finishedThreads = 0; ParameterizedThreadStart threadStart = (threadNum) => { //split the work up among however many threads we have int startFrequency = (int)Math.Round((2000.0 / settings.NumberOfThreads) * ((int)threadNum) + 1.0, 0); int endFrequency = (int)Math.Round((2000.0 / settings.NumberOfThreads) * ((int)threadNum + 1.0), 0); bore.CalculateInputImpedance(startFrequency, endFrequency, 1); SetImpedanceData(); }; for (int i=0; i<settings.NumberOfThreads; i++) { Thread thread = new Thread(threadStart); thread.Start(i); } progressDialog = new Progress(); progressDialog.ShowDialog(this); }