Ejemplo n.º 1
0
        public void plotDeriv(EPRPlotView pw)
        {
            LineSeries se = new LineSeries
            {
                ItemsSource = BPUtil.getDataPoints(this.getX(), this.getDerivative()),
                Title       = "Derivative"
            };

            pw.Model.Series.Add(se);
            pw.InvalidatePlot();
            pw.rescale();
        }
Ejemplo n.º 2
0
        private void DerivButton_Click(object sender, RoutedEventArgs e)
        {
            EPRPlotView pw = this.getActivePlotView();

            if (!this.getActiveSpectrum().showDeriv)
            {
                this.getActiveSpectrum().showDeriv = true;
                this.DerivButton.Foreground        = Brushes.SaddleBrown;
                this.getActiveSpectrum().plotDeriv(pw);
            }
            else
            {
                var test = pw.Model.Series.Where(s => s.Title.Contains("Derivative"));
                if (test.Count() != 0)
                {
                    pw.Model.Series.Remove(test.First());
                }
                this.getActiveSpectrum().showDeriv = false;
                pw.InvalidatePlot();
                pw.rescale();
                this.DerivButton.Foreground = Brushes.Black;
            }
        }
Ejemplo n.º 3
0
        private void IntButton_Click(object sender, RoutedEventArgs e)
        {
            EPRPlotView pw = this.getActivePlotView();

            if (!this.getActiveSpectrum().showInt)
            {
                this.getActiveSpectrum().showInt = true;
                this.IntButton.Foreground        = Brushes.Magenta;
                this.getActiveSpectrum().plotInt(pw);
            }
            else
            {
                var test = pw.Model.Series.Where(s => s.Title.Contains("Integral"));
                if (test.Count() != 0)
                {
                    pw.Model.Series.Remove(test.First());
                }
                this.getActiveSpectrum().showInt = false;
                pw.InvalidatePlot();
                pw.rescale();
                this.IntButton.Foreground = Brushes.Black;
            }
        }
Ejemplo n.º 4
0
        private void SubmitButton_Click(object sender, RoutedEventArgs e)
        {
            Button btn = (Button)sender;

            btn.IsEnabled = false;

            //remove existing sim
            var test = plotView.Model.Series.Where(s => s.Title.Contains("Simulation"));

            if (test.Count() != 0)
            {
                plotView.Model.Series.Remove(test.First());
            }

            this.ExpTBlock.Text = "Experimental Data: \nFrequency: " + exp.frequency + " GHz \nRange: " + this.spc.getX().First() + " - "
                                  + this.spc.getX().Last() + " mT\nResolution: " + this.spc.getX().Length
                                  + " Points\nTemperature: " + this.exp.Temperature + " K";
            NumberFormatInfo nfi = new NumberFormatInfo();

            nfi.NumberDecimalSeparator = ".";

            double Spin = getSpin();

            double[] g = Array.ConvertAll(TB_gVal.Text.Split(','), i => Convert.ToDouble(i, CultureInfo.InvariantCulture));
            double[] A = new double[] { };
            if (TB_HFCoup.Text.Length != 0)
            {
                A = Array.ConvertAll(TB_HFCoup.Text.Split(','), i => Convert.ToDouble(i, CultureInfo.InvariantCulture));
            }
            double[] D = new double[] { };
            if (TB_ZFS.Text.Length != 0)
            {
                D = Array.ConvertAll(TB_ZFS.Text.Split(','), i => Convert.ToDouble(i, CultureInfo.InvariantCulture));
            }
            string[] Nucs = new string[] { };
            if (TB_Nucs.Text.Length != 0)
            {
                Nucs = TB_Nucs.Text.Split(',');
            }
            int[] N = new int[] { };
            if (TB_NucsN.Text.Length != 0)
            {
                N = Array.ConvertAll(TB_NucsN.Text.Split(','), i => Convert.ToInt32(i, CultureInfo.InvariantCulture));
            }

            this.ExpTBlock.Text += "\n\nSimulation Parameters:\nSpin: " + Spin + "\ng-Values: " + String.Join(",", g.Select(p => p.ToString(nfi)).ToArray());
            this.ExpTBlock.Text += "\nNucs: " + String.Join(",", Nucs.Select(p => p.ToString(nfi)).ToArray());
            this.ExpTBlock.Text += "\nA: " + String.Join(",", A.Select(p => p.ToString(nfi)).ToArray());
            double lw = 0;

            double[] gStrain = new double[] { };
            if (Spin <= 0.5)
            {
                lw = Convert.ToDouble(TB_lw.Text, nfi);
                this.ExpTBlock.Text += "\nn: " + TB_NucsN.Text + "\nlw: " + lw;
            }
            else
            {
                if (TB_lw.Text.Length != 0)
                {
                    this.ExpTBlock.Text += "\nD: " + String.Join(",", D.Select(p => p.ToString(nfi)).ToArray());
                    gStrain              = Array.ConvertAll(TB_lw.Text.Split(','), i => Convert.ToDouble(i, CultureInfo.InvariantCulture));
                    this.ExpTBlock.Text += "\ngStrain: " + String.Join(",", gStrain.Select(p => p.ToString(nfi)).ToArray());
                }
            }
            string additional = "";

            if (ToggleAdditional.IsChecked == true)
            {
                additional           = TB_Additional.Text;
                this.ExpTBlock.Text += "\nAddtional Parameters: \n" + additional;
            }
            Sys sys;

            //garlic mode
            if (Spin <= 0.5)
            {
                sys = new Sys(Spin, g, A, Nucs, N, lw, additional);
                Task.Factory.StartNew(() =>
                {
                    double[] y = AddSim(sys, this.exp, spc);
                    Dispatcher.Invoke(() =>
                    {
                        LineSeries se = new LineSeries
                        {
                            ItemsSource = BPUtil.getDataPoints(spc.getX(), y),
                            Title       = "Simulation"
                        };


                        plotView.Model.Series.Add(se);
                        plotView.InvalidatePlot();
                        plotView.rescale();

                        btn.IsEnabled = true;
                    });
                });
                this.ExpTBlock.Text += "\nMode is garlic";
            }

            //pepper mode
            else
            {
                sys = new Sys(Spin, g, D, A, gStrain, Nucs, additional);
                Task.Factory.StartNew(() =>
                {
                    double[] y = AddSim(sys, this.exp, spc);
                    Dispatcher.Invoke(() =>
                    {
                        LineSeries se = new LineSeries
                        {
                            ItemsSource = BPUtil.getDataPoints(spc.getX(), y),
                            Title       = "Simulation"
                        };


                        plotView.Model.Series.Add(se);
                        plotView.InvalidatePlot();
                        plotView.rescale();

                        btn.IsEnabled = true;
                    });
                });
                this.ExpTBlock.Text += "\nMode is pepper";
            }

            //save sim-File
            string filename = spc.fileName + ".sim";

            using (StreamWriter sw = File.CreateText(filename))
            {
                JsonSerializer json = new JsonSerializer();
                json.Serialize(sw, sys);
                this.ExpTBlock.Text += "\n\nParameters saved to " + filename;
            }
        }