private void RunNextExperiment(int expIndex) { IExperiment exp = (IExperiment)scanMethod[expIndex]; log.Add("Configuring " + ((ParametrizableObject)exp).Name + "..."); enExperimentStatus expStatus = exp.Configure(null, scanMethodResultsPath); if ((expStatus != enExperimentStatus.OK) && (expStatus != enExperimentStatus.Idle)) { log.Warning("Experiment Sequence Aborted due to exp.Configure() returning: " + expStatus); OnNotifyScanEnded(new ExperimentEndedEventArgs(enExperimentStatus.Error, null)); } exp.NotifyExperimentDataUpdated -= Exp_NotifyExperimentDataUpdated; exp.NotifyExperimentDataUpdated += Exp_NotifyExperimentDataUpdated; exp.NotifyExperimentEnded -= Exp_NotifyExperimentEnded; exp.NotifyExperimentEnded += Exp_NotifyExperimentEnded; experimentRunning = expIndex; experimentRunningName = (scanMethod[experimentRunning] as ParametrizableObject).Name; log.Add("Running " + ((ParametrizableObject)exp).Name + "..."); expStatus = exp.Run(); if ((expStatus != enExperimentStatus.OK) && (expStatus != enExperimentStatus.Running)) { exp.NotifyExperimentDataUpdated -= Exp_NotifyExperimentDataUpdated; exp.NotifyExperimentEnded -= Exp_NotifyExperimentEnded; try { // just in case Experiment was started exp.Abort(); } catch (Exception e) { } log.Warning("Experiment Sequence Aborted due to exp.Run() returning: " + expStatus); OnNotifyScanEnded(new ExperimentEndedEventArgs(enExperimentStatus.Error, null)); } }
/// <summary> /// Run an experiment /// </summary> /// <param name="projectPathAndFile"></param> /// <param name="experimentName"></param> /// <param name="saveModelAfterRun"></param> /// <param name="explanation"></param> /// <returns></returns> public static bool RunExperiment(string projectFullPath, string modelName, string experimentName, bool saveModelAfterRun, out string explanation) { explanation = ""; string marker = "Begin"; try { // Set an extensions path to where we can locate User Extensions, etc. string extensionsPath = System.AppDomain.CurrentDomain.BaseDirectory; marker = $"Setting Extensions Path to={extensionsPath}"; LogIt($"Info: {marker}"); SimioProjectFactory.SetExtensionsPath(extensionsPath); marker = $"Loading Project from={projectFullPath}"; ISimioProject project = LoadProject(projectFullPath, out explanation); if (project == null) { return(false); } marker = $"Loading Model named={modelName}"; IModel model = LoadModel(project, modelName, out explanation); if (model == null) { return(false); } marker = $"Loading Experiment named={experimentName}"; IExperiment experiment = LoadExperiment(model, experimentName, out explanation); if (experiment == null) { return(false); } // Create some methods to handle experiment events experiment.ReplicationEnded += (s, e) => { LogIt($"Info: Event=> Ended Replication={e.ReplicationNumber} of Scenario={e.Scenario.Name}."); }; experiment.ScenarioEnded += (s, e) => { LogIt($"Info: Event=> Scenario={e.Scenario.Name} Ended."); }; experiment.RunCompleted += (s, e) => { LogIt($"Info: Event=> Experiment={experiment.Name} Run Complete. "); }; // Now do the run. experiment.Reset(); experiment.Run(); //experiment.RunAsync(); // Another option if (saveModelAfterRun) { marker = $"Save Project After Experiment Run to= (SimioProjectFactory.SaveProject)"; LogIt($"Info: {marker}"); string[] warnings; SimioProjectFactory.SaveProject(project, projectFullPath, out warnings); foreach (string warning in warnings) { LogIt($"Warning: {warning}"); } } return(true); } catch (Exception ex) { throw new ApplicationException($"Marker={marker} Err={ex}"); } }
/// <summary> /// Run an experiment. The experiment is Reset prior to run. /// If the saveProjectPath is present and exists, then the project will be /// saved to that location. If there are Save warnings, then true is still /// returned, but the warnings are in explanation. /// </summary> /// <param name="projectPathAndFile"></param> /// <param name="experimentName"></param> /// <param name="saveModelAfterRun"></param> /// <param name="explanation"></param> /// <returns></returns> public static bool RunModelExperiment(ISimioProject project, string saveProjectPath, string modelName, string experimentName, out string explanation) { explanation = ""; string marker = "Begin"; try { marker = $"Loading Model named={modelName}"; IModel model = LoadModel(project, modelName, out explanation); if (model == null) { return(false); } marker = $"Loading Experiment named={experimentName}"; IExperiment experiment = LoadExperiment(model, experimentName, out explanation); if (experiment == null) { return(false); } // Create some methods to handle experiment events. Events are: // RunStarted, RunProgessChanged, RunCompleted // ScenarioStarted, ScenarioEnded // ReplicationStarted, ReplicationEnded // // Here the 'e' is RunStartedEventArgs experiment.RunStarted += (s, e) => { LogIt($"Info: Event=> Experiment={experiment.Name} Run Started. "); }; // Here the 'e' is ReplicationEndedEventArgs experiment.ReplicationEnded += (s, e) => { LogIt($"Info: Event=> Ended Replication={e.ReplicationNumber} of Scenario={e.Scenario.Name}."); }; // Here the 'e' is ScenarioStartedEventArgs experiment.ScenarioStarted += (s, e) => { LogIt($"Info: Event=> Scenario={e.Scenario.Name} Started."); }; experiment.ScenarioEnded += (s, e) => { LogIt($"Info: Event=> Scenario={e.Scenario.Name} Ended."); }; // Here the 'e' is RunCompletedEventArgs experiment.RunCompleted += (s, e) => { LogIt($"Info: Event=> Experiment={experiment.Name} Run Complete. "); foreach (ITable table in model.Tables) { table.ExportForInteractive(); } }; // Now do the run. experiment.Reset(); experiment.Run(); //experiment.RunAsync(); // Another option // Let's look at some results var response = experiment.Responses; if (File.Exists(saveProjectPath)) { marker = $"Save Project After Experiment Run to={saveProjectPath}"; LogIt($"Info: {marker}"); string[] warnings; SimioProjectFactory.SaveProject(project, saveProjectPath, out warnings); explanation = ""; int nn = 0; foreach (string warning in warnings) { explanation += $"Save Warnings({warnings.Length}): Warning{++nn}:{warning}"; LogIt($"Warning: {warning}"); } } return(true); } catch (Exception ex) { throw new ApplicationException($"Marker={marker} Err={ex.Message}"); } }
private void step_button_Click(object sender, EventArgs e) { dimension = 1; conduction_band.Series["conduction_band_data"].Points.Clear(); conduction_band.Series["valence_band_data"].Points.Clear(); conduction_band.Series["x_data"].Points.Clear(); density.Series["car_dens_data"].Points.Clear(); density.Series["dop_dens_data"].Points.Clear(); density.Series["gphi_data"].Points.Clear(); int nz; int i = int.Parse(count_no_label.Text); if (!int.TryParse(nz1Dval.Text, out nz)) { MessageBox.Show("Format of Nz for dopent potential is invalid"); return; } // initialise dopent experiment if the count is zero if (i == 0) { exp1d = new OneD_ThomasFermiPoisson.Experiment(); car_dens = new SpinResolved_Data(nz); dop_dens = new SpinResolved_Data(nz); Dictionary <string, object> inputs_tmp = Create_Dictionary(); foreach (KeyValuePair <string, object> option in inputs_tmp) { inputs.Add(option.Key.Replace("_1d", ""), option.Value); } inputs["surface_charge"] = 0.0; inputs["max_iterations"] = 0.0; exp1d.Initialise(inputs); } converged = exp1d.Run(); ILayer[] layers = exp1d.Layers; double dz = exp1d.Dz_Pot; double zmin = exp1d.Zmin_Pot; car_dens = exp1d.Carrier_Density; dop_dens = exp1d.Dopent_Density; Band_Data x = Physics_Base.q_e * exp1d.X; Band_Data gphi = exp1d.GPhi; chem_pot = (Input_Band_Structure.Get_BandStructure_Grid(layers, dz, nz, zmin) - exp1d.Chemical_Potential); // + x); val_pot = (-1.0 * Input_Band_Structure.Get_BandStructure_Grid(layers, dz, nz, zmin) - exp1d.Chemical_Potential); // + x); for (int j = 0; j < chem_pot.Length; j++) { double pos = zmin + dz * j; conduction_band.Series["conduction_band_data"].Points.AddXY(pos, chem_pot[j]); conduction_band.Series["valence_band_data"].Points.AddXY(pos, val_pot[j]); conduction_band.Series["x_data"].Points.AddXY(pos, x[j]); density.Series["car_dens_data"].Points.AddXY(pos, car_dens.Spin_Summed_Data[j]); density.Series["dop_dens_data"].Points.AddXY(pos, dop_dens.Spin_Summed_Data[j]); density.Series["gphi_data"].Points.AddXY(pos, gphi[j]); } Set_Plot_Axes(dens_xmin_val.Text, dens_xmax_val.Text, density.ChartAreas["ChartArea1"].AxisX); Set_Plot_Axes(dens_ymin_val.Text, dens_ymax_val.Text, density.ChartAreas["ChartArea1"].AxisY); Set_Plot_Axes(pot_xmin_val.Text, pot_xmax_val.Text, conduction_band.ChartAreas["ChartArea1"].AxisX); Set_Plot_Axes(pot_ymin_val.Text, pot_ymax_val.Text, conduction_band.ChartAreas["ChartArea1"].AxisY); conduction_band.Refresh(); density.Refresh(); this.count_no_label.Text = (i + 1).ToString(); this.temperature_val_label.Text = exp1d.Current_Temperature.ToString() + " K"; this.carrier_dopent_density_Text.Text = (from val in car_dens.Spin_Summed_Data.vec where val < 0.0 select - 1.0e14 * val * dz / Physics_Base.q_e).ToArray().Sum().ToString("e3"); }
/// <summary> /// Run an experiment. The experiment is Reset prior to run. /// A loaded project is passed in that must contain the named Model and Experiment. /// If the saveProjectPath is present and exists, then the project will be /// saved to that location. If there are Save warnings, then true is still /// returned, but the warnings are in explanation. /// </summary> /// <param name="model"></param> /// <param name="experimentName"></param> /// <param name="explanation"></param> /// <returns></returns> public static bool RunModelExperiment(IModel model, string experimentName, out string explanation) { explanation = ""; string marker = "Begin"; try { marker = $"Loading Experiment named={experimentName}"; IExperiment experiment = LoadExperiment(model, experimentName, out explanation); if (experiment == null) { return(false); } // Create some methods to handle experiment events. Events are: // RunStarted, RunProgessChanged, RunCompleted // ScenarioStarted, ScenarioEnded // ReplicationStarted, ReplicationEnded // // Here the 'e' is RunStartedEventArgs experiment.RunStarted += (s, e) => { LogIt($"Info: Event=> Experiment={experiment.Name} Run Started. "); }; // Here the 'e' is ReplicationEndedEventArgs experiment.ReplicationEnded += (s, e) => { LogIt($"Info: Event=> Ended Replication={e.ReplicationNumber} of Scenario={e.Scenario.Name}."); }; // Here the 'e' is ScenarioStartedEventArgs experiment.ScenarioStarted += (s, e) => { LogIt($"Info: Event=> Scenario={e.Scenario.Name} Started."); }; experiment.ScenarioEnded += (s, e) => { LogIt($"Info: Event=> Scenario={e.Scenario.Name} Ended."); }; // Here the 'e' is RunCompletedEventArgs experiment.RunCompleted += (s, e) => { LogIt($"Info: Event=> Experiment={experiment.Name} Run Complete. "); foreach (ITable table in model.Tables) { table.ExportForInteractive(); } }; // Now do the run. LogIt($"Info: Resetting Experiment={experiment.Name}"); experiment.Reset(); LogIt($"Info: Running Experiment={experiment.Name}"); experiment.Run(); //experiment.RunAsync(); // Another option // Let's look at some results var response = experiment.Responses; return(true); } catch (Exception ex) { throw new ApplicationException($"Marker={marker} Err={ex.Message}"); } }