Exemple #1
0
        /// <summary>
        ///     Set up data sources and load stored models as selected choices
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void cpConsequenceModels_Load(object sender, EventArgs e)
        {
            var qraInst = QraStateContainer.Instance;

            cbNotionalNozzleModel.DataSource   = qraInst.NozzleModels;
            cbNotionalNozzleModel.SelectedItem = QraStateContainer.GetValue <NozzleModel>("NozzleModel");

            cbDeflagrationModel.DataSource = qraInst.DeflagrationModels;
            var model = QraStateContainer.GetValue <DeflagrationModel>("DeflagrationModel");

            cbDeflagrationModel.SelectedItem = model;
            UpdateCfdInput(model);

            cbThermalProbitModel.DataSource   = qraInst.ThermalProbitModels;
            cbThermalProbitModel.SelectedItem = QraStateContainer.GetValue <ThermalProbitModel>("ThermalProbit");

            cbOverpressureProbitModel.DataSource   = qraInst.OverpressureProbitModels;
            cbOverpressureProbitModel.SelectedItem =
                QraStateContainer.GetValue <OverpressureProbitModel>("OverpressureProbit");

            var radModel = QraStateContainer.GetValue <RadiativeSourceModels>("RadiativeSourceModel");

            cbRadiativeSourceModel.Fill(UiStateRoutines.GetRadiativeSourceModelDict(), radModel);
            cbRadiativeSourceModel.SelectedItem = radModel;
        }
Exemple #2
0
        private void FillIgnitionProbabilitiesTableFromMemory()
        {
            var immedIgnitionProbs = QraStateContainer.GetValue <double[]>("ImmedIgnitionProbs");
            var delayIgnitionProbs = QraStateContainer.GetValue <double[]>("DelayIgnitionProbs");

            SetDatagridColumn(dgIgnitionProbabilities, ColImmed, immedIgnitionProbs);
            SetDatagridColumn(dgIgnitionProbabilities, ColDelayed, delayIgnitionProbs);
        }
Exemple #3
0
        private void SetDatabaseExclusionRadius(double value)
        {
            var er = new double[1];

            er[0] = value;
            var exclusionRadius = QraStateContainer.GetValue <NdConvertibleValue>("QRAD:EXCLUSIONRADIUS");

            exclusionRadius.SetValue(UnitlessUnit.Unitless, er);
        }
Exemple #4
0
        private void UpdateIgnitionProbablitiesList()
        {
            var ignitionThresholds = QraStateContainer.GetValue <double[]>("IgnitionThresholds");

            for (var i = 0; i < ignitionThresholds.Length; ++i)
            {
                lbIgnitionProbabilities.Items.Add(ignitionThresholds[i]);
            }
        }
Exemple #5
0
        /// <summary>
        /// Compute results of overpressure and generate associated plots.
        /// </summary>
        /// <param name="ambPressure"></param>
        /// <param name="ambTemp"></param>
        /// <param name="h2Pressure"></param>
        /// <param name="h2Temp"></param>
        /// <param name="orificeDiam"></param>
        /// <param name="orificeDischargeCoeff"></param>
        /// <param name="tankVolume"></param>
        /// <param name="releaseDischargeCoeff"></param>
        /// <param name="releaseArea"></param>
        /// <param name="releaseHeight"></param>
        /// <param name="enclosureHeight"></param>
        /// <param name="floorCeilingArea"></param>
        /// <param name="distReleaseToWall"></param>
        /// <param name="ceilVentXArea"></param>
        /// <param name="ceilVentHeight"></param>
        /// <param name="floorVentXArea"></param>
        /// <param name="floorVentHeight"></param>
        /// <param name="flowRate"></param>
        /// <param name="releaseAngle"></param>
        /// <param name="timesToPlot"></param>
        /// <param name="dotMarkPressures"></param>
        /// <param name="dotMarkTimes"></param>
        /// <param name="limitLinePressures"></param>
        /// <param name="maxSimTime"></param>
        /// <param name="pressuresPerTime"></param>
        /// <param name="depths"></param>
        /// <param name="concentrations"></param>
        /// <param name="overpressure"></param>
        /// <param name="timeOfOverpressure"></param>
        /// <param name="pressurePlotFilepath"></param>
        /// <param name="massPlotFilepath"></param>
        /// <param name="layerPlotFilepath"></param>
        /// <param name="trajectoryPlotFilepath"></param>
        /// <returns></returns>
        public int ExecuteOverpressureAnalysis(
            double ambPressure, double ambTemp, double h2Pressure, double h2Temp, double orificeDiam, double orificeDischargeCoeff, double tankVolume,
            double releaseDischargeCoeff, double releaseArea, double releaseHeight, double enclosureHeight, double floorCeilingArea, double distReleaseToWall,
            double ceilVentXArea, double ceilVentHeight, double floorVentXArea, double floorVentHeight, double flowRate, double releaseAngle, double[] timesToPlot,
            double[] dotMarkPressures, double[] dotMarkTimes, double[] limitLinePressures, double maxSimTime,
            out double[] pressuresPerTime, out double[] depths, out double[] concentrations, out double overpressure, out double timeOfOverpressure,
            out string pressurePlotFilepath, out string massPlotFilepath, out string layerPlotFilepath, out string trajectoryPlotFilepath
            )
        {
            bool   isDebug    = QraStateContainer.GetValue <bool>("debug");
            string dataDirLoc = QraStateContainer.UserDataDir;

            Trace.TraceInformation("Acquiring python lock and importing module...");
            using (Py.GIL())
            {
                dynamic pyGC       = Py.Import("gc");
                dynamic pyHyramLib = Py.Import("hyram");

                try
                {
                    Trace.TraceInformation("Executing python overpressure call...");
                    // Execute python function call. Will return PyObject containing results.
                    dynamic resultPyObj = pyHyramLib.phys.capi.overpressure_indoor_release(
                        ambPressure, ambTemp, h2Pressure, h2Temp, tankVolume, orificeDiam, orificeDischargeCoeff,
                        releaseDischargeCoeff, releaseArea, releaseHeight, enclosureHeight, floorCeilingArea, distReleaseToWall,
                        ceilVentXArea, ceilVentHeight, floorVentXArea, floorVentHeight, flowRate, releaseAngle, timesToPlot,
                        dotMarkPressures, dotMarkTimes, limitLinePressures, maxSimTime, dataDirLoc, isDebug
                        );
                    Trace.TraceInformation("Python call complete. Processing results...");

                    pressuresPerTime       = (double[])resultPyObj["pressures_per_time"];
                    depths                 = (double[])resultPyObj["depths"];
                    concentrations         = (double[])resultPyObj["concentrations"];
                    overpressure           = (double)resultPyObj["overpressure"];
                    timeOfOverpressure     = (double)resultPyObj["time_of_overp"];
                    pressurePlotFilepath   = (string)resultPyObj["pres_plot_filepath"];
                    massPlotFilepath       = (string)resultPyObj["mass_plot_filepath"];
                    layerPlotFilepath      = (string)resultPyObj["layer_plot_filepath"];
                    trajectoryPlotFilepath = (string)resultPyObj["trajectory_plot_filepath"];
                }
                catch (Exception ex)
                {
                    Trace.TraceError(ex.ToString());
                    throw new InvalidOperationException("Error during overpressure calculation. Check log for details.");
                }
                finally
                {
                    pyGC.InvokeMethod("collect");
                    pyGC.Dispose();
                    pyHyramLib.Dispose();
                }
            }
            return(1);
        }
Exemple #6
0
        private void btnIgnitionProbabilitiesDelete_Click(object sender, EventArgs e)
        {
            var thresholdToRemove = Convert.ToDouble(lbIgnitionProbabilities.SelectedItem);

            if (lbIgnitionProbabilities.Items.Count > 1)
            {
                var ignitionThresholds = QraStateContainer.GetValue <double[]>("IgnitionThresholds");
                var immedIgnitionProbs = QraStateContainer.GetValue <double[]>("ImmedIgnitionProbs");
                var delayIgnitionProbs = QraStateContainer.GetValue <double[]>("DelayIgnitionProbs");

                var newIgnitionThresholds = new double[ignitionThresholds.Length - 1];
                var newImmediate = new double[immedIgnitionProbs.Length - 1];
                var newDelayed = new double[delayIgnitionProbs.Length - 1];
                int offset = 0, index = 0;
                for (var i = 0; i < ignitionThresholds.Length; ++i) //Insert new ignition threshold in order
                {
                    if (ignitionThresholds[i] == thresholdToRemove)
                    {
                        index = i;
                        ++offset;
                    }
                    else
                    {
                        newIgnitionThresholds[i - offset] = ignitionThresholds[i];
                    }
                }

                offset = 0;
                for (var i = 0; i < immedIgnitionProbs.Length; ++i)
                {
                    if (i == index)
                    {
                        ++offset;
                    }
                    else
                    {
                        newDelayed[i - offset]   = delayIgnitionProbs[i];
                        newImmediate[i - offset] = immedIgnitionProbs[i];
                    }
                }

                QraStateContainer.SetValue("IgnitionThresholds", newIgnitionThresholds);
                QraStateContainer.SetValue("ImmedIgnitionProbs", newImmediate);
                QraStateContainer.SetValue("DelayIgnitionProbs", newDelayed);
                lbIgnitionProbabilities.Items.Clear();
                dgIgnitionProbabilities.Rows.Clear();
                UpdateIgnitionProbablitiesList();
                FillIgnitionProbabilitiesTable();
            }
            else
            {
                MessageBox.Show("Error: At least one ignition threshold is required.");
            }
        }
Exemple #7
0
        public void AnalyzeRadiativeHeatFlux(
            double ambTemp, double ambPressure, double h2Temp, double h2Pressure, double orificeDiam, double leakHeight, double releaseAngle,
            NozzleModel notionalNozzleModel, double[] radHeatFluxX, double[] radHeatFluxY, double[] radHeatFluxZ, double relativeHumidity,
            RadiativeSourceModels radiativeSourceModel,
            double[] contourLevels, out double[] fluxData, out string fluxPlotFilepath, out string tempPlotFilepath)
        {
            bool   isDebug      = QraStateContainer.GetValue <bool>("debug");
            string dataDirLoc   = QraStateContainer.UserDataDir;
            string plotFilepath = "";

            Trace.TraceInformation("Acquiring python lock and importing module");
            using (Py.GIL())
            {
                dynamic pyGC       = Py.Import("gc");
                dynamic pyHyramLib = Py.Import("hyram");

                try
                {
                    Trace.TraceInformation("Executing python radiative heat flux analysis...");
                    dynamic resultPyObj = pyHyramLib.phys.capi.analyze_radiative_heat_flux(
                        ambTemp, ambPressure, h2Temp, h2Pressure, orificeDiam, leakHeight, releaseAngle,
                        notionalNozzleModel.GetKey(), radHeatFluxX, radHeatFluxY, radHeatFluxZ, relativeHumidity,
                        radiativeSourceModel.ToString().ToLower(),
                        contourLevels, dataDirLoc, isDebug
                        );
                    Trace.TraceInformation("Python call complete. Processing results...");

                    fluxData         = (double[])resultPyObj["flux_data"];
                    fluxPlotFilepath = (string)resultPyObj["flux_plot_filepath"];
                    tempPlotFilepath = (string)resultPyObj["temp_plot_filepath"];
                    Debug.WriteLine(" Flux results: " + plotFilepath);
                    Debug.WriteLine(" Flux plots: " + fluxPlotFilepath + ", " + tempPlotFilepath);
                }
                catch (Exception ex)
                {
                    Trace.TraceError(ex.ToString());
                    throw new InvalidOperationException(
                              "Error during rad heat flux analysis. Check log for details.");
                }
                finally
                {
                    pyGC.InvokeMethod("collect");
                    pyGC.Dispose();
                    pyHyramLib.Dispose();
                }
            }
        }
Exemple #8
0
        public string CreateFlameTemperaturePlot(
            double ambTemp, double ambPressure, double h2Temp, double h2Pressure,
            double orificeDiam, double y0, double releaseAngle, string nozzleModelKey)
        {
            bool isDebug = QraStateContainer.GetValue <bool>("debug");

            // Derive path to data dir for temp and data files, e.g. pickling
            string dataDirLoc   = QraStateContainer.UserDataDir;
            string plotFilepath = "";

            Trace.TraceInformation("Acquiring python lock and importing module...");
            using (Py.GIL())
            {
                dynamic pyGC       = Py.Import("gc");
                dynamic pyHyramLib = Py.Import("hyram");

                try
                {
                    // Execute python function call. Will return PyObject containing results.
                    Trace.TraceInformation("Executing python flame temp plot generation...");
                    dynamic resultPyObj = pyHyramLib.phys.capi.create_flame_temp_plot(
                        ambPressure, ambTemp, h2Pressure, h2Temp, orificeDiam, y0, releaseAngle, nozzleModelKey,
                        dataDirLoc, isDebug
                        );
                    Trace.TraceInformation("Python call complete. Processing results...");

                    plotFilepath = (string)resultPyObj;
                    Debug.WriteLine(" Created plot: " + plotFilepath);
                }
                catch (Exception ex)
                {
                    Trace.TraceError(ex.ToString());
                    throw new InvalidOperationException(
                              "Error during flame temp plot generation. Check log for details.");
                }
                finally
                {
                    pyGC.InvokeMethod("collect");
                    pyGC.Dispose();
                    pyHyramLib.Dispose();
                }
            }
            return(plotFilepath);
        }
Exemple #9
0
        /// <summary>
        /// Create plume plot via python
        /// </summary>
        /// <param name="ambientPressure"></param>
        /// <param name="ambientTemp"></param>
        /// <param name="h2Pressure"></param>
        /// <param name="h2Temp"></param>
        /// <param name="orificeDiam"></param>
        /// <param name="dischargeCoeff"></param>
        /// <param name="xMin"></param>
        /// <param name="xMax"></param>
        /// <param name="yMin"></param>
        /// <param name="yMax"></param>
        /// <param name="contours"></param>
        /// <param name="jetAngle"></param>
        /// <param name="plotTitle"></param>
        /// <returns></returns>
        public string CreatePlumePlot(
            double ambientPressure, double ambientTemp, double h2Pressure, double h2Temp, double orificeDiam,
            double dischargeCoeff, double xMin, double xMax, double yMin, double yMax, double contours, double jetAngle, string plotTitle)
        {
            bool isDebug = QraStateContainer.GetValue <bool>("debug");

            string dataDirLoc = QraStateContainer.UserDataDir;
            string plotFilepath;

            Trace.TraceInformation("Acquiring python lock and importing module...");

            using (Py.GIL())
            {
                dynamic pyGC       = Py.Import("gc");
                dynamic pyHyramLib = Py.Import("hyram");

                try
                {
                    // Execute python function call. Will return PyObject containing results.
                    Trace.TraceInformation("Executing python plume call...");
                    dynamic resultPyObj = pyHyramLib.phys.capi.create_plume_plot(
                        ambientPressure, ambientTemp, h2Pressure, h2Temp, orificeDiam, dischargeCoeff, xMin, xMax, yMin, yMax, contours,
                        jetAngle, plotTitle, dataDirLoc, isDebug
                        );
                    plotFilepath = (string)resultPyObj;
                    resultPyObj.Dispose();
                    Trace.TraceInformation("Python call complete. Created plot: " + plotFilepath);
                }
                catch (Exception ex)
                {
                    Trace.TraceError(ex.ToString());
                    throw new InvalidOperationException("Error during plume plot generation. Check log for details.");
                }
                finally
                {
                    pyGC.InvokeMethod("collect");
                    pyGC.Dispose();
                    pyHyramLib.Dispose();
                }
            }
            return(plotFilepath);
        }
Exemple #10
0
        private void FillIgnitionProbabilitiesTable()
        {
            _mIgnoringChangeEvents = true;

            var ignitionThresholds = QraStateContainer.GetValue <double[]>("IgnitionThresholds");

            if (ignitionThresholds.Length > 0)
            {
                dgIgnitionProbabilities.Rows.Add("<" + ignitionThresholds[0], "", "");
                for (var i = 1; i < ignitionThresholds.Length; ++i)
                {
                    dgIgnitionProbabilities.Rows.Add(ignitionThresholds[i - 1] + "-" + ignitionThresholds[i], "", "");
                }

                dgIgnitionProbabilities.Rows.Add("\u2265" + ignitionThresholds[ignitionThresholds.Length - 1], "", "");
                FillIgnitionProbabilitiesTableFromMemory();
            }

            _mIgnoringChangeEvents = false;
        }
Exemple #11
0
        private void frmQFEMain_Load(object sender, EventArgs e)
        {
            // Delete old temp files from prev runs
            QuickFunctions.ClearOldTemporaryFiles();

            ActiveScreen = this;

            tcNav.TabPages.Remove(tpNfpa2Mode);
            tcNav.TabPages.Remove(tpTests);
            tcNav.SelectedIndex = 0;
            tcNav.SelectedTab   = null;
            tcNav.SelectedTab   = tpQraMode;

            // Populate fuel selection dropdowns.
            // One dropdown on phys UI, one on QRA. Both sync to same backend param.
            fuelTypePhys.DataSource   = QraStateContainer.Instance.FuelTypes;
            fuelTypePhys.SelectedItem = QraStateContainer.GetValue <FuelType>("FuelType");
            fuelTypeQra.DataSource    = QraStateContainer.Instance.FuelTypes;
            fuelTypeQra.SelectedItem  = QraStateContainer.GetValue <FuelType>("FuelType");
        }
Exemple #12
0
        private void Execute()
        {
            // Blanket try block to help catch deployed issue Brian encountered
            Trace.TraceInformation("Gathering parameters for radiative flux analysis...");
            try
            {
                var ambTemp     = QraStateContainer.GetNdValue("SysParam.ExternalTempC", TempUnit.Kelvin);
                var ambPressure = QraStateContainer.GetNdValue("SysParam.ExternalPresMPA", PressureUnit.Pa);
                var h2Temp      = QraStateContainer.GetNdValue("FlameWrapper.T_H2", TempUnit.Kelvin);
                var h2Pressure  = QraStateContainer.GetNdValue("FlameWrapper.P_H2", PressureUnit.Pa);
                var orificeDiam = QraStateContainer.GetNdValue("FlameWrapper.d_orifice", DistanceUnit.Meter);
                var leakHeight  = QraStateContainer.GetNdValue("FlameWrapper.ReleaseHeight", DistanceUnit.Meter);
                _radHeatFluxX =
                    QraStateContainer.GetNdValueList("FlameWrapper.radiative_heat_flux_point:x", DistanceUnit.Meter);
                _radHeatFluxY =
                    QraStateContainer.GetNdValueList("FlameWrapper.radiative_heat_flux_point:y", DistanceUnit.Meter);
                _radHeatFluxZ =
                    QraStateContainer.GetNdValueList("FlameWrapper.radiative_heat_flux_point:z", DistanceUnit.Meter);
                var contourLevels =
                    QraStateContainer.GetNdValueList("FlameWrapper.contour_levels", UnitlessUnit.Unitless);
                var relativeHumidity     = QraStateContainer.GetNdValue("FlameWrapper.RH", UnitlessUnit.Unitless);
                var notionalNozzleModel  = QraStateContainer.GetValue <NozzleModel>("NozzleModel");
                var releaseAngle         = QraStateContainer.GetNdValue("OpWrapper.ReleaseAngle", AngleUnit.Radians);
                var radiativeSourceModel =
                    QraStateContainer.GetValue <RadiativeSourceModels>("RadiativeSourceModel");

                Trace.TraceInformation("Creating PhysInterface for python call");
                var physInt = new PhysInterface();
                physInt.AnalyzeRadiativeHeatFlux(ambTemp, ambPressure, h2Temp, h2Pressure, orificeDiam, leakHeight,
                                                 releaseAngle,
                                                 notionalNozzleModel, _radHeatFluxX, _radHeatFluxY, _radHeatFluxZ, relativeHumidity,
                                                 radiativeSourceModel,
                                                 contourLevels, out _fluxData, out _fluxPlotFilepath, out _tempPlotFilepath);
                Trace.TraceInformation("PhysInterface call complete");
            }
            catch (Exception ex)
            {
                Trace.TraceError(ex.ToString());
                MessageBox.Show(@"Heat flux analysis failed, please try again. Check log for details.");
            }
        }
Exemple #13
0
        private void GenerateResults()
        {
            ContentPanel.SetNarrative(this, Narratives.SS__ScenarioStats);
            var result = QraStateContainer.GetValue <QraResult>("Result");

            // Set risk metrics
            dgRiskMetrics.Rows[0].Cells[1].Value = result.TotalPll;
            dgRiskMetrics.Rows[1].Cells[1].Value = result.Far;
            dgRiskMetrics.Rows[2].Cells[1].Value = result.Air;

            var curRow = 1;

            for (var i = 0; i < result.LeakResults.Count; i++)
            {
                var leakRes = result.LeakResults[i];
                dgRanking.Rows.Add(curRow++, leakRes.GetLeakSizeString(), "Shutdown", leakRes.ShutdownAvgEvents,
                                   leakRes.ProbShutdown, 0);
                dgRanking.Rows.Add(curRow++, leakRes.GetLeakSizeString(), "Jet fire", leakRes.JetfireAvgEvents,
                                   leakRes.ProbJetfire, leakRes.JetfirePllContrib);
                dgRanking.Rows.Add(curRow++, leakRes.GetLeakSizeString(), "Explosion", leakRes.ExplosAvgEvents,
                                   leakRes.ProbExplosion, leakRes.ExplosionPllContrib);
                dgRanking.Rows.Add(curRow++, leakRes.GetLeakSizeString(), "No ignition", leakRes.NoIgnAvgEvents,
                                   leakRes.ProbNoIgnition, 0);
            }

            // Load position plots
            pbPositionPlot000d01.SizeMode = PictureBoxSizeMode.Zoom;
            pbPositionPlot000d01.Load(result.PositionPlotFilenames[0]);
            pbPositionPlot000d10.Load(result.PositionPlotFilenames[1]);
            pbPositionPlot001d00.Load(result.PositionPlotFilenames[2]);
            pbPositionPlot010d00.Load(result.PositionPlotFilenames[3]);
            pbPositionPlot100d00.Load(result.PositionPlotFilenames[4]);

            // Add cut set data
            PopulateCutSetTable(CutSetDGV000d01, result.LeakResults[0], false);
            PopulateCutSetTable(CutSetDGV000d10, result.LeakResults[1], false);
            PopulateCutSetTable(CutSetDGV001d00, result.LeakResults[2], false);
            PopulateCutSetTable(CutSetDGV010d00, result.LeakResults[3], false);
            PopulateCutSetTable(CutSetDGV100d00, result.LeakResults[4], true);
        }
Exemple #14
0
        private void cbNotionalNozzleModel_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (DesignMode)
            {
                return;
            }

            var newModel = NozzleModel.ParseNozzleModelName(cbNotionalNozzleModel.SelectedItem.ToString());

            QraStateContainer.SetValue("NozzleModel", newModel);
            //QraStateContainer.Instance.SetNozzleModel((string)cbNotionalNozzleModel.SelectedItem);
            var oldValue = _mNozzleModelSelected;

            //string NozzleName = QraStateContainer.Instance.GetObject("NotionalNozzleModel").ToString();
            //mNozzleModelSelected = QraStateContainer.Instance.GetNozzleModel();
            var oldModel = QraStateContainer.GetValue <NozzleModel>("NozzleModel");

            if (_mNozzleModelSelected != oldValue)
            {
                SpawnNotionalNozzleModelChangedEvent();
            }
        }
        private void Execute()
        {
            var ambPressure    = QraStateContainer.GetNdValue("SysParam.ExternalPresMPA", PressureUnit.Pa);
            var ambTemp        = QraStateContainer.GetNdValue("SysParam.ExternalTempC", TempUnit.Kelvin);
            var h2Pressure     = QraStateContainer.GetNdValue("FlameWrapper.P_H2", PressureUnit.Pa);
            var h2Temp         = QraStateContainer.GetNdValue("FlameWrapper.T_H2", TempUnit.Kelvin);
            var orificeDiam    = QraStateContainer.GetNdValue("FlameWrapper.d_orifice", DistanceUnit.Meter);
            var dischargeCoeff = QraStateContainer.GetNdValue("OpWrapper.Cd0", UnitlessUnit.Unitless);
            var xMin           = QraStateContainer.GetNdValue("PlumeWrapper.XMin", DistanceUnit.Meter);
            var xMax           = QraStateContainer.GetNdValue("PlumeWrapper.XMax", DistanceUnit.Meter);
            var yMin           = QraStateContainer.GetNdValue("PlumeWrapper.YMin", DistanceUnit.Meter);
            var yMax           = QraStateContainer.GetNdValue("PlumeWrapper.YMax", DistanceUnit.Meter);
            var contours       = QraStateContainer.GetNdValue("PlumeWrapper.Contours", UnitlessUnit.Unitless);
            var jetAngle       = QraStateContainer.GetNdValue("PlumeWrapper.jet_angle", AngleUnit.Radians);
            var plotTitle      = QraStateContainer.GetValue <string>("PlumeWrapper.PlotTitle");

            var physInt = new PhysInterface();

            _plotFilename = physInt.CreatePlumePlot(
                ambPressure, ambTemp, h2Pressure, h2Temp, orificeDiam, dischargeCoeff, xMin, xMax, yMin, yMax, contours,
                jetAngle, plotTitle);
        }
Exemple #16
0
        private void Execute()
        {
            var ambTemp = QraStateContainer.Instance.GetStateDefinedValueObject("SysParam.ExternalTempC")
                          .GetValue(TempUnit.Kelvin)[0];
            var ambPres = QraStateContainer.Instance.GetStateDefinedValueObject("SysParam.ExternalPresMPA")
                          .GetValue(PressureUnit.Pa)[0];
            var h2Temp = QraStateContainer.Instance.GetStateDefinedValueObject("FlameWrapper.T_H2")
                         .GetValue(TempUnit.Kelvin)[0];
            var h2Pres = QraStateContainer.Instance.GetStateDefinedValueObject("FlameWrapper.P_H2")
                         .GetValue(PressureUnit.Pa)[0];
            var orificeDiam = QraStateContainer.Instance.GetStateDefinedValueObject("FlameWrapper.d_orifice")
                              .GetValue(DistanceUnit.Meter)[0];
            var y0 = QraStateContainer.Instance.GetStateDefinedValueObject("FlameWrapper.ReleaseHeight")
                     .GetValue(DistanceUnit.Meter)[0];
            var releaseAngle = QraStateContainer.Instance.GetStateDefinedValueObject("OpWrapper.ReleaseAngle")
                               .GetValue(AngleUnit.Radians)[0];
            var nozzleModel = QraStateContainer.GetValue <NozzleModel>("NozzleModel");

            var physInt = new PhysInterface();

            _resultImageFilepath = physInt.CreateFlameTemperaturePlot(ambTemp, ambPres, h2Temp, h2Pres, orificeDiam, y0,
                                                                      releaseAngle, nozzleModel.GetKey());
        }
Exemple #17
0
        private void btnIgnitionProbabilitiesAdd_Click(object sender, EventArgs e)
        {
            double newThreshold = -1;

            Parsing.TryParseDouble(tbIgnitionProbabilitiesAdd.Text, out newThreshold);
            if (newThreshold > 0.0)
            {
                var ignitionThresholds = QraStateContainer.GetValue <double[]>("IgnitionThresholds");
                var immedIgnitionProbs = QraStateContainer.GetValue <double[]>("ImmedIgnitionProbs");
                var delayIgnitionProbs = QraStateContainer.GetValue <double[]>("DelayIgnitionProbs");
                if (!ignitionThresholds.Contains(newThreshold))
                {
                    var newIgnitionThresholds = new double[ignitionThresholds.Length + 1];
                    var newImmediate = new double[immedIgnitionProbs.Length + 1];
                    var newDelayed = new double[delayIgnitionProbs.Length + 1];
                    int offset = 0, index = 0;
                    for (var i = 0; i < newIgnitionThresholds.Length; ++i) //Insert new ignition threshold in order
                    {
                        if (offset == 0 && (i == newIgnitionThresholds.Length - 1 ||
                                            ignitionThresholds[i] > newThreshold))
                        {
                            newIgnitionThresholds[i] = newThreshold;
                            index = i;
                            ++offset;
                        }
                        else
                        {
                            newIgnitionThresholds[i] = ignitionThresholds[i - offset];
                        }
                    }

                    offset = 0;
                    for (var i = 0; i < newImmediate.Length; ++i)
                    {
                        if (i == index)
                        {
                            newImmediate[i] = 0.0;
                            newDelayed[i]   = 0.0;
                            ++offset;
                        }
                        else
                        {
                            newDelayed[i]   = delayIgnitionProbs[i - offset];
                            newImmediate[i] = immedIgnitionProbs[i - offset];
                        }
                    }

                    QraStateContainer.SetValue("IgnitionThresholds", newIgnitionThresholds);
                    QraStateContainer.SetValue("ImmedIgnitionProbs", newImmediate);
                    QraStateContainer.SetValue("DelayIgnitionProbs", newDelayed);
                    lbIgnitionProbabilities.Items.Clear();
                    dgIgnitionProbabilities.Rows.Clear();
                    UpdateIgnitionProbablitiesList();
                    FillIgnitionProbabilitiesTable();
                }
                else
                {
                    MessageBox.Show(newThreshold + " is already in the list of ignition thresholds.");
                }
            }
            else
            {
                MessageBox.Show("Error: ignition threshold must be greater than zero");
            }
        }
Exemple #18
0
        private void Execute()
        {
            var ambPressure           = QraStateContainer.GetNdValue("SysParam.ExternalPresMPA", PressureUnit.Pa);
            var ambTemp               = QraStateContainer.GetNdValue("SysParam.ExternalTempC", TempUnit.Kelvin);
            var h2Pressure            = QraStateContainer.GetNdValue("FlameWrapper.P_H2", PressureUnit.Pa);
            var h2Temp                = QraStateContainer.GetNdValue("FlameWrapper.T_H2", TempUnit.Kelvin);
            var orificeDiam           = QraStateContainer.GetNdValue("FlameWrapper.d_orifice", DistanceUnit.Meter);
            var orificeDischargeCoeff = QraStateContainer.GetNdValue("OpWrapper.Cd0", UnitlessUnit.Unitless);
            var tankVolume            = QraStateContainer.GetNdValue("OpWrapper.TankVolume", VolumeUnit.CubicMeter);
            var releaseDischargeCoeff = QraStateContainer.GetNdValue("OpWrapper.CdR", UnitlessUnit.Unitless);
            var releaseArea           = QraStateContainer.GetNdValue("OpWrapper.SecondaryArea", AreaUnit.SqMeters);
            var releaseHeight         = QraStateContainer.GetNdValue("OpWrapper.S0", DistanceUnit.Meter);
            var enclosureHeight       = QraStateContainer.GetNdValue("OpWrapper.H", DistanceUnit.Meter);
            var floorCeilingArea      = QraStateContainer.GetNdValue("OpWrapper.FCA", AreaUnit.SqMeters);
            var distReleaseToWall     = QraStateContainer.GetNdValue("OpWrapper.Xwall", DistanceUnit.Meter);
            var ceilVentXArea         = QraStateContainer.GetNdValue("OpWrapper.Av_ceil", AreaUnit.SqMeters);
            var ceilVentHeight        = QraStateContainer.GetNdValue("OpWrapper.CVHF", DistanceUnit.Meter);
            var floorVentXArea        = QraStateContainer.GetNdValue("OpWrapper.Av_floor", AreaUnit.SqMeters);
            var floorVentHeight       = QraStateContainer.GetNdValue("OpWrapper.FVHF", DistanceUnit.Meter);
            var flowRate              =
                QraStateContainer.GetNdValue("OpWrapper.VolumeFlowRate", VolumetricFlowUnit.CubicMetersPerSecond);
            var releaseAngle = QraStateContainer.GetNdValue("OpWrapper.ReleaseAngle", AngleUnit.Radians);

            // Blanket try block to catch odd Win8 VM issue
            try
            {
                Trace.TraceInformation("Primitive overpressure parameters gathered. Extracting advanced...");
                _timesToPlot =
                    QraStateContainer.GetNdValueList("OpWrapper.SecondsToPlot", ElapsingTimeConversionUnit.Second);

                // Whether to mark pressures on chart. Gets custom time-pressure objects
                NdPressureAtTime[] pressuresAtTimes = { };

                if (cbMarkChartWithPTDots.Checked)
                {
                    pressuresAtTimes =
                        QraStateContainer.GetValue <NdPressureAtTime[]>("OpWrapper.PlotDotsPressureAtTimes");
                    var numPressures = pressuresAtTimes.Length;
                    _dotMarkPressures = new double[numPressures];
                    _dotMarkTimes     = new double[numPressures];
                    for (var i = 0; i < numPressures; i++)
                    {
                        _dotMarkPressures[i] = pressuresAtTimes[i].Pressure;
                        _dotMarkTimes[i]     = pressuresAtTimes[i].Time;
                    }
                }
                else
                {
                    _dotMarkPressures = new double[0];
                    _dotMarkTimes     = new double[0];
                }

                // WHether to plot line pressures
                var      llp = QraStateContainer.GetNdValueList("OPWRAPPER.LIMITLINEPRESSURES", PressureUnit.KPa);
                double[] limitLinePressures = { };
                if (cbHorizontalLines.Checked)
                {
                    limitLinePressures = llp;
                }

                var maxSimTime =
                    QraStateContainer.GetNdValue("OpWrapper.MaxSimTime", ElapsingTimeConversionUnit.Second);

                // prep vars to hold results
                var numTimes = pressuresAtTimes.Length;
                _pressuresPerTime = new double[numTimes];
                _depths           = new double[numTimes];
                _concentrations   = new double[numTimes];

                Trace.TraceInformation("Initializing PhysInterface...");
                var physInt = new PhysInterface();
                var status  = physInt.ExecuteOverpressureAnalysis(
                    ambPressure, ambTemp, h2Pressure, h2Temp, orificeDiam, orificeDischargeCoeff, tankVolume,
                    releaseDischargeCoeff, releaseArea, releaseHeight, enclosureHeight, floorCeilingArea,
                    distReleaseToWall,
                    ceilVentXArea, ceilVentHeight, floorVentXArea, floorVentHeight, flowRate, releaseAngle,
                    _timesToPlot,
                    _dotMarkPressures, _dotMarkTimes, limitLinePressures, maxSimTime,
                    out _pressuresPerTime, out _depths, out _concentrations, out _overpressure, out _timeOfOverpressure,
                    out _pressurePlotFilepath, out _massPlotFilepath, out _layerPlotFilepath,
                    out _trajectoryPlotFilepath
                    );
                Trace.TraceInformation("PhysInterface call complete. Displaying results..");
            }
            catch (Exception ex)
            {
                Trace.TraceError(ex.Message);
            }
        }
Exemple #19
0
        private void SetRadiativeSourceModel()
        {
            var current = QraStateContainer.GetValue <RadiativeSourceModels>("RadiativeSourceModel");

            cbRadiativeSourceModel.Fill(UiStateRoutines.GetRadiativeSourceModelDict(), current);
        }
Exemple #20
0
        public void Execute()
        {
            var inst = QraStateContainer.Instance;

            var resultsAreStale = QraStateContainer.GetValue <bool>("ResultsAreStale");

            // Just return stored result if no inputs have changed
            if (!resultsAreStale)
            {
                return;
            }

            // Gather inputs
            var pipeLength     = QraStateContainer.GetNdValue("Components.PipeLength", DistanceUnit.Meter);
            var numCompressors = (int)QraStateContainer.GetNdValue("Components.NrCompressors");
            var numCylinders   = (int)QraStateContainer.GetNdValue("Components.NrCylinders");
            var numValves      = (int)QraStateContainer.GetNdValue("Components.NrValves");
            var numInstruments = (int)QraStateContainer.GetNdValue("Components.NrInstruments");
            var numJoints      = (int)QraStateContainer.GetNdValue("Components.NrJoints");
            var numHoses       = (int)QraStateContainer.GetNdValue("Components.NrHoses");
            var numFilters     = (int)QraStateContainer.GetNdValue("Components.NrFilters");
            var numFlanges     = (int)QraStateContainer.GetNdValue("Components.NrFlanges");
            var numExtraComp1  = (int)QraStateContainer.GetNdValue("Components.NrExtraComp1");
            var numExtraComp2  = (int)QraStateContainer.GetNdValue("Components.NrExtraComp2");

            var facilLength = QraStateContainer.GetNdValue("Facility.Length", DistanceUnit.Meter);
            var facilWidth  = QraStateContainer.GetNdValue("Facility.Width", DistanceUnit.Meter);
            var facilHeight = QraStateContainer.GetNdValue("Facility.Height", DistanceUnit.Meter);

            var pipeOuterD    = QraStateContainer.GetNdValue("SysParam.PipeOD", DistanceUnit.Meter);
            var pipeThickness = QraStateContainer.GetNdValue("SysParam.PipeWallThick", DistanceUnit.Meter);
            var h2Temp        = QraStateContainer.GetNdValue("SysParam.InternalTempC", TempUnit.Kelvin);
            var h2Pres        = QraStateContainer.GetNdValue("SysParam.InternalPresMPA", PressureUnit.Pa);
            var ambTemp       = QraStateContainer.GetNdValue("SysParam.ExternalTempC", TempUnit.Kelvin);
            var ambPres       = QraStateContainer.GetNdValue("SysParam.ExternalPresMPa", PressureUnit.Pa);

            var dischargeCoeff   = QraStateContainer.GetNdValue("DischargeCoefficient");
            var numVehicles      = QraStateContainer.GetNdValue("nVehicles");
            var numFuelingPerDay = QraStateContainer.GetNdValue("nFuelingsPerVehicleDay");
            var numVehicleOpDays = QraStateContainer.GetNdValue("nVehicleOperatingDays");

            var immediateIgnitionProbs = (double[])inst.Parameters["ImmedIgnitionProbs"];
            var delayedIgnitionProbs   = (double[])inst.Parameters["DelayIgnitionProbs"];
            var ignitionThresholds     = (double[])inst.Parameters["IgnitionThresholds"];

            var h2Release000d01       = QraStateContainer.GetNdValue("H2Release.000d01");
            var h2Release000d10       = QraStateContainer.GetNdValue("H2Release.000d10");
            var h2Release001d00       = QraStateContainer.GetNdValue("H2Release.001d00");
            var h2Release010d00       = QraStateContainer.GetNdValue("H2Release.010d00");
            var h2Release100d00       = QraStateContainer.GetNdValue("H2Release.100d00");
            var failureManualOverride = QraStateContainer.GetNdValue("Failure.ManualOverride");
            //double? FailureManualOverride = QraStateContainer.GetValue<double?>("Failure.ManualOverride");

            // Note (Cianan): this is currently always true
            var detectGasAndFlame = inst.GasAndFlameDetectionOn;
            var gasDetectCredit   = QraStateContainer.GetNdValue("PdetectIsolate");

            var probitThermalModelId = QraStateContainer.GetValue <ThermalProbitModel>("ThermalProbit").GetKey();
            var thermalExposureTime  =
                QraStateContainer.GetNdValue("t_expose_thermal", ElapsingTimeConversionUnit.Second);

            var probitOverpModelId =
                QraStateContainer.GetValue <OverpressureProbitModel>("OverpressureProbit").GetKey();
            var peakOverpressures = QraStateContainer.GetNdValueList("P_s", PressureUnit.Pa);
            var overpImpulses     = QraStateContainer.GetNdValueList("impulse", PressureUnit.Pa);
            // NOTE (Cianan): These aren't used yet
            double overpFragMass  = 0;
            double overpVelocity  = 0;
            double overpTotalMass = 0;

            var radSourceModel =
                QraStateContainer.GetValue <RadiativeSourceModels>("RadiativeSourceModel").ToString();
            var notionalNozzleModel = QraStateContainer.GetValue <NozzleModel>("NozzleModel").GetKey();
            var leakHeight          = QraStateContainer.GetNdValue("LeakHeight", DistanceUnit.Meter);
            var releaseAngle        = QraStateContainer.GetNdValue("ReleaseAngle", AngleUnit.Degrees);

            var exclusionRadius = QraStateContainer.GetNdValue("QRAD:EXCLUSIONRADIUS");
            var randomSeed      = (int)QraStateContainer.GetNdValue("RANDOMSEED");
            var relativeHumid   = QraStateContainer.GetNdValue("FlameWrapper.RH");

            var occupantDistributions =
                (OccupantDistributionInfoCollection)inst.Parameters["OccupantDistributions"];
            var occupantJson = JsonConvert.SerializeObject(occupantDistributions);

            // Massage component probabilities into double[][]
            var compList =
                QraStateContainer.GetValue <List <ComponentProbability> >("Prob.Compressor");
            var
                cylList    = QraStateContainer.GetValue <List <ComponentProbability> >("Prob.Cylinder");
            var filterList =
                QraStateContainer.GetValue <List <ComponentProbability> >("Prob.Filter");
            var flangeList =
                QraStateContainer.GetValue <List <ComponentProbability> >("Prob.Flange");
            var hoseList  = QraStateContainer.GetValue <List <ComponentProbability> >("Prob.Hose");
            var jointList = QraStateContainer.GetValue <List <ComponentProbability> >("Prob.Joint");
            var pipeList  = QraStateContainer.GetValue <List <ComponentProbability> >("Prob.Pipe");
            var valveList = QraStateContainer.GetValue <List <ComponentProbability> >("Prob.Valve");
            var instrList =
                QraStateContainer.GetValue <List <ComponentProbability> >("Prob.Instrument");
            var ex1List = QraStateContainer.GetValue <List <ComponentProbability> >("Prob.Extra1");
            var ex2List = QraStateContainer.GetValue <List <ComponentProbability> >("Prob.Extra2");

            // TODO (Cianan): Clean this up
            // NOTE (Cianan): Python.NET can't convert nullable list (e.g. double?) into numpy arr so  mu/sigma or mean/variance are set to -1000D if null
            double[][] compressorProbs =
            {
                compList[0].GetDataForPython(), compList[1].GetDataForPython(),
                compList[2].GetDataForPython(), compList[3].GetDataForPython(),
                compList[4].GetDataForPython()
            };

            double[][] cylinderProbs =
            {
                cylList[0].GetDataForPython(), cylList[1].GetDataForPython(),
                cylList[2].GetDataForPython(), cylList[3].GetDataForPython(),
                cylList[4].GetDataForPython()
            };

            double[][] filterProbs =
            {
                filterList[0].GetDataForPython(), filterList[1].GetDataForPython(),
                filterList[2].GetDataForPython(), filterList[3].GetDataForPython(),
                filterList[4].GetDataForPython()
            };

            double[][] flangeProbs =
            {
                flangeList[0].GetDataForPython(), flangeList[1].GetDataForPython(),
                flangeList[2].GetDataForPython(), flangeList[3].GetDataForPython(),
                flangeList[4].GetDataForPython()
            };

            double[][] hoseProbs =
            {
                hoseList[0].GetDataForPython(), hoseList[1].GetDataForPython(),
                hoseList[2].GetDataForPython(), hoseList[3].GetDataForPython(),
                hoseList[4].GetDataForPython()
            };

            double[][] jointProbs =
            {
                jointList[0].GetDataForPython(), jointList[1].GetDataForPython(),
                jointList[2].GetDataForPython(), jointList[3].GetDataForPython(),
                jointList[4].GetDataForPython()
            };

            double[][] pipeProbs =
            {
                pipeList[0].GetDataForPython(), pipeList[1].GetDataForPython(),
                pipeList[2].GetDataForPython(), pipeList[3].GetDataForPython(),
                pipeList[4].GetDataForPython()
            };

            double[][] valveProbs =
            {
                valveList[0].GetDataForPython(), valveList[1].GetDataForPython(),
                valveList[2].GetDataForPython(), valveList[3].GetDataForPython(),
                valveList[4].GetDataForPython()
            };

            double[][] instrumentProbs =
            {
                instrList[0].GetDataForPython(), instrList[1].GetDataForPython(),
                instrList[2].GetDataForPython(), instrList[3].GetDataForPython(),
                instrList[4].GetDataForPython()
            };

            double[][] extraComp1Probs =
            {
                ex1List[0].GetDataForPython(), ex1List[1].GetDataForPython(),
                ex1List[2].GetDataForPython(), ex1List[3].GetDataForPython(),
                ex1List[4].GetDataForPython()
            };

            double[][] extraComp2Probs =
            {
                ex2List[0].GetDataForPython(), ex2List[1].GetDataForPython(),
                ex2List[2].GetDataForPython(), ex2List[3].GetDataForPython(),
                ex2List[4].GetDataForPython()
            };

            var nozPo     = QraStateContainer.GetValue <FailureMode>("Failure.NozPO");
            var nozFtc    = QraStateContainer.GetValue <FailureMode>("Failure.NozFTC");
            var mValveFtc = QraStateContainer.GetValue <FailureMode>("Failure.MValveFTC");
            var sValveFtc = QraStateContainer.GetValue <FailureMode>("Failure.SValveFTC");
            var sValveCcf = QraStateContainer.GetValue <FailureMode>("Failure.SValveCCF");

            var overpFail    = QraStateContainer.GetValue <FailureMode>("Failure.Overp");
            var pValveFto    = QraStateContainer.GetValue <FailureMode>("Failure.PValveFTO");
            var driveoffFail = QraStateContainer.GetValue <FailureMode>("Failure.Driveoff");
            var couplingFtc  = QraStateContainer.GetValue <FailureMode>("Failure.CouplingFTC");

            var nozPoDist   = nozPo.Dist.ToString();
            var nozPoParamA = nozPo.ParamA;
            var nozPoParamB = nozPo.ParamB;

            var nozFtcDist   = nozFtc.Dist.ToString();
            var nozFtcParamA = nozFtc.ParamA;
            var nozFtcParamB = nozFtc.ParamB;

            var mValveFtcDist   = mValveFtc.Dist.ToString();
            var mValveFtcParamA = mValveFtc.ParamA;
            var mValveFtcParamB = mValveFtc.ParamB;

            var sValveFtcDist   = sValveFtc.Dist.ToString();
            var sValveFtcParamA = sValveFtc.ParamA;
            var sValveFtcParamB = sValveFtc.ParamB;

            var sValveCcfDist   = sValveCcf.Dist.ToString();
            var sValveCcfParamA = sValveCcf.ParamA;
            var sValveCcfParamB = sValveCcf.ParamB;

            var overpDist   = overpFail.Dist.ToString();
            var overpParamA = overpFail.ParamA;
            var overpParamB = overpFail.ParamB;

            var pValveFtoDist   = pValveFto.Dist.ToString();
            var pValveFtoParamA = pValveFto.ParamA;
            var pValveFtoParamB = pValveFto.ParamB;

            var driveoffDist   = driveoffFail.Dist.ToString();
            var driveoffParamA = driveoffFail.ParamA;
            var driveoffParamB = driveoffFail.ParamB;

            var couplingFtcDist   = couplingFtc.Dist.ToString();
            var couplingFtcParamA = couplingFtc.ParamA;
            var couplingFtcParamB = couplingFtc.ParamB;

            // Derive path to data dir for temp and data files, e.g. pickling
            var dataDirLoc = QraStateContainer.UserDataDir;

            QraResult result;

            using (Py.GIL())
            {
                //var lck = PythonEngine.AcquireLock();
                dynamic pyQraLib = Py.Import("hyram");

                try
                {
                    // Execute python analysis. Will return PyObject which is parsed in QRAResult.
                    var resultPyObj = pyQraLib.qra.capi.conduct_analysis(
                        pipeLength, numCompressors, numCylinders, numValves, numInstruments, numJoints, numHoses,
                        numFilters, numFlanges, numExtraComp1, numExtraComp2,
                        facilLength, facilWidth, facilHeight,
                        pipeOuterD, pipeThickness,
                        h2Temp, h2Pres, ambTemp, ambPres, dischargeCoeff,
                        numVehicles, numFuelingPerDay, numVehicleOpDays,
                        immediateIgnitionProbs, delayedIgnitionProbs, ignitionThresholds,
                        detectGasAndFlame, gasDetectCredit,
                        probitThermalModelId, thermalExposureTime,
                        probitOverpModelId, peakOverpressures, overpImpulses, overpFragMass, overpVelocity,
                        overpTotalMass,
                        radSourceModel, notionalNozzleModel,
                        leakHeight, releaseAngle,
                        exclusionRadius, randomSeed, relativeHumid,
                        occupantJson,
                        compressorProbs, cylinderProbs, valveProbs, instrumentProbs, pipeProbs, jointProbs, hoseProbs,
                        filterProbs, flangeProbs, extraComp1Probs, extraComp2Probs,
                        nozPoDist, nozPoParamA, nozPoParamB,
                        nozFtcDist, nozFtcParamA, nozFtcParamB,
                        mValveFtcDist, mValveFtcParamA, mValveFtcParamB,
                        sValveFtcDist, sValveFtcParamA, sValveFtcParamB,
                        sValveCcfDist, sValveCcfParamA, sValveCcfParamB,
                        overpDist, overpParamA, overpParamB,
                        pValveFtoDist, pValveFtoParamA, pValveFtoParamB,
                        driveoffDist, driveoffParamA, driveoffParamB,
                        couplingFtcDist, couplingFtcParamA, couplingFtcParamB,
                        h2Release000d01, h2Release000d10, h2Release001d00, h2Release010d00, h2Release100d00,
                        failureManualOverride,
                        dataDirLoc
                        );

                    result = new QraResult(resultPyObj);
                    QraStateContainer.SetValue("ResultsAreStale", false);
                    QraStateContainer.SetValue("Result", result);
                }
                catch (PythonException ex)
                {
                    QraStateContainer.SetValue("ResultsAreStale", true);
                    Trace.TraceError(ex.Message);
                    Debug.WriteLine(ex.Message);
                    throw new InvalidOperationException(
                              "Something went wrong during PyQRA execution. Check log for details.");
                }
                catch (Exception ex)
                {
                    Trace.TraceError(ex.Message);
                    QraStateContainer.SetValue("ResultsAreStale", true);
                    throw ex;
                }
                finally
                {
                    // Force display of stderr, stdout. This includes print statements from python
                    Console.Out.Flush();
                    Console.Error.Flush();

                    // Unload imports
                    pyQraLib.Dispose();
                    //PythonEngine.ReleaseLock(lck);
                }
            }
        }