/// <summary> /// This routine updates our frontend. All updates are performed in a threadsafe manner, as the /// stochastic methods can take place on a separate thread /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void ReflCalc_Update(object sender, EventArgs e) { //Necessary due to the possibility of updating from a separate thread (such as stochastic fitting). Otherwise, events are fired which reset some of the values //below. A lock isn't necessary this isn't necessarilly a race condition m_isupdating = true; SubRough.ThreadSafeSetText(ReflCalc.GetSubRoughness.ToString()); if (ReflCalc.ImpNormCB) { NormCorrectTB.ThreadSafeSetText(ReflCalc.NormalizationFactor.ToString()); } Holdsigma.ThreadSafeChecked(ReflCalc.IsOneSigma); BoxCount.ThreadSafeSetText(ReflCalc.BoxCount.ToString()); ImpNormCB.ThreadSafeChecked(ReflCalc.ImpNormCB); //Blank our Rho data from the previous iteration for (int i = 0; i < RhoArray.Count; i++) { if (!m_bUseSLD) { RhoArray[i].ThreadSafeSetText(ReflCalc.RhoArray[i].ToString()); } else { RhoArray[i].ThreadSafeSetText((ReflCalc.RhoArray[i] / ReflCalc.SubphaseSLD).ToString()); } LengthArray[i].ThreadSafeSetText(ReflCalc.LengthArray[i].ToString()); SigmaArray[i].ThreadSafeSetText(ReflCalc.SigmaArray[i].ToString()); } if (Holdsigma.Checked) { ChangeRoughnessArray(); } if (m_bmodelreset) { ReflGraphing.Clear(); ReflGraphing.LoadDatawithErrorstoGraph("Reflectivity Data", Color.Black, SymbolType.Circle, 5, ReflData.Instance.GetQData, ReflData.Instance.GetReflData); m_bmodelreset = false; } GreyFields(); //Update graphs RhoGraphing.Pane.XAxis.Scale.Min = 0; RhoGraphing.Pane.XAxis.Scale.Max = ReflCalc.Z[ReflCalc.Z.Length - 1]; ReflGraphing.LoadfromArray("modelrefl", ReflData.Instance.GetQData, ReflCalc.ReflectivityMap, System.Drawing.Color.Black, SymbolType.XCross, 4, true, string.Empty); RhoGraphing.LoadfromArray("Model Dependent Fit", ReflCalc.Z, ReflCalc.ElectronDensityArray, System.Drawing.Color.Turquoise, SymbolType.None, 0, true, string.Empty); RhoGraphing.LoadfromArray("Model Dependent Box Fit", ReflCalc.Z, ReflCalc.BoxElectronDensityArray, System.Drawing.Color.Red, SymbolType.None, 0, false, string.Empty); chisquaretb.ThreadSafeSetText(ReflCalc.MakeChiSquare().ToString()); FitnessScoreTB.ThreadSafeSetText(ReflCalc.MakeFitnessScore().ToString()); m_isupdating = false; }
private void MakeReflectivity() { //Fill Rho array try { ReflCalc.IsOneSigma = Holdsigma.Checked; ReflCalc.ZOffset = 25; ReflCalc.GetSubRoughness = SubRough.ToDouble(); ReflCalc.BoxCount = BoxCount.ToInt(); ReflCalc.SubphaseSLD = SubphaseSLD.ToDouble(); ReflCalc.SuperphaseSLD = SupSLDTB.ToDouble(); ReflCalc.HighQOffset = Rightoffset.ToInt(); ReflCalc.LowQOffset = CritOffset.ToInt(); ReflCalc.NormalizationFactor = NormCorrectTB.ToDouble(); ReflCalc.ImpNormCB = ImpNormCB.Checked; ReflCalc.QSpreadTB = QSpreadTB.ToDouble(); //Blank our Rho data from the previous iteration ReflCalc.RhoArray.Clear(); ReflCalc.LengthArray.Clear(); ReflCalc.SigmaArray.Clear(); RhoArray.ForEach(p => ReflCalc.RhoArray.Add(p.ToDouble())); LengthArray.ForEach(p => ReflCalc.LengthArray.Add(p.ToDouble())); SigmaArray.ForEach(p => ReflCalc.SigmaArray.Add(p.ToDouble())); if (Holdsigma.Checked) { ChangeRoughnessArray(); } ReflCalc.UpdateProfile(); } catch (Exception ex) { MessageBox.Show(ex.Message.ToString()); } }
private void GetConstraints() { int arrayconst = 2; int holdcount = 0; if (SubRoughCB.Checked || SubRoughCB.Checked) { holdcount++; } //Check if any holds have been set Action <CheckBox> f = p => { if (p.Checked == true) { holdcount++; } }; HoldRhoArray.ForEach(f); HoldSigmaArray.ForEach(f); HoldLengthArray.ForEach(f); //Setup all of our constraints if true, if it has been uninitialized, if (ConstrForm.Initialized || holdcount > 0) { if (ReflCalc.IsOneSigma == false) { arrayconst = 3; } ReflCalc.UL = new double[2 + arrayconst * ReflCalc.BoxCount]; ReflCalc.LL = new double[2 + arrayconst * ReflCalc.BoxCount]; int ULLength = ReflCalc.UL.Length; //Set the subphase constraints if (SubRoughCB.Checked == true) { ReflCalc.UL[0] = SubRough.ToDouble(); ReflCalc.LL[0] = SubRough.ToDouble(); } else if (ConstrForm.Initialized == false) { ReflCalc.UL[0] = 10000; ReflCalc.LL[0] = -10000; } else { ReflCalc.UL[0] = ConstrForm.SubRoughMax; ReflCalc.LL[0] = ConstrForm.SubRoughMin; } //Set the Normalization const if (NormCB.Checked == true) { ReflCalc.UL[ULLength - 1] = NormCorrectTB.ToDouble(); ReflCalc.LL[ULLength - 1] = NormCorrectTB.ToDouble(); } else if (ConstrForm.Initialized == false) { ReflCalc.UL[ULLength - 1] = 10000; ReflCalc.LL[ULLength - 1] = -10000; } else { ReflCalc.UL[ULLength - 1] = ConstrForm.NormMax; ReflCalc.LL[ULLength - 1] = ConstrForm.NormMin; } for (int i = 0; i < ReflCalc.BoxCount; i++) { //Check for constraints if (ConstrForm.Initialized == true) { ReflCalc.UL[arrayconst * i + 1] = ConstrForm.ThickHighArray[i]; ReflCalc.LL[arrayconst * i + 1] = ConstrForm.ThickLowArray[i]; if (m_bUseSLD == false) { ReflCalc.UL[arrayconst * i + 2] = ConstrForm.RhoHighArray[i]; ReflCalc.LL[arrayconst * i + 2] = ConstrForm.RhoLowArray[i]; } else { if (ReflCalc.SubphaseSLD > 0) { ReflCalc.UL[arrayconst * i + 2] = ConstrForm.RhoHighArray[i] / ReflCalc.SubphaseSLD; ReflCalc.LL[arrayconst * i + 2] = ConstrForm.RhoLowArray[i] / ReflCalc.SubphaseSLD; } else { ReflCalc.LL[arrayconst * i + 2] = ConstrForm.RhoHighArray[i] / ReflCalc.SubphaseSLD; ReflCalc.UL[arrayconst * i + 2] = ConstrForm.RhoLowArray[i] / ReflCalc.SubphaseSLD; } } if (Holdsigma.Checked == false) { ReflCalc.UL[arrayconst * i + 3] = ConstrForm.SigmaHighArray[i]; ReflCalc.LL[arrayconst * i + 3] = ConstrForm.SigmaLowArray[i]; } } else { ReflCalc.UL[arrayconst * i + 2] = ReflCalc.UL[arrayconst * i + 1] = 10000; ReflCalc.LL[arrayconst * i + 2] = ReflCalc.LL[arrayconst * i + 1] = -10000; if (Holdsigma.Checked == false) { ReflCalc.UL[arrayconst * i + 3] = 10000; ReflCalc.LL[arrayconst * i + 3] = -10000; } } //Check for holds - holds take precedence over constraints if (HoldLengthArray[i].Checked == true) { ReflCalc.LL[arrayconst * i + 1] = ReflCalc.UL[arrayconst * i + 1] = LengthArray[i].ToDouble(); } if (HoldRhoArray[i].Checked == true) { ReflCalc.LL[arrayconst * i + 2] = ReflCalc.UL[arrayconst * i + 2] = RhoArray[i].ToDouble(); } if (HoldSigmaArray[i].Checked == true && Holdsigma.Checked == false) { ReflCalc.LL[arrayconst * i + 3] = ReflCalc.UL[arrayconst * i + 3] = SigmaArray[i].ToDouble(); } } } else { ReflCalc.UL = null; ReflCalc.LL = null; } }