Esempio n. 1
0
        //This function pulls in the data from GREET that can be classified as user input, meaning it was a custom user value
        //In order to change the values in GREET you go into the data editor tab, and select either the pathway or resource
        //You want to change (in this case we are only looking at resources) and then change the values and hit apply
        //After you apply the changes, you can hit the pull user values button and it will allow you to update values in real time
        public void pullUserParameterValues()
        {
            IGDataDictionary <int, IResource> resources = ResultsAccess.controler.CurrentProject.Data.Resources;
            IGDataDictionary <int, IPathway>  pathways  = ResultsAccess.controler.CurrentProject.Data.Pathways;

            //The number value that goes into ValueForKey is the ID number for the pathway you are looking to use
            IPathway myPathway = pathways.ValueForKey(CRUDE_PATHWAY_ID);
            // Grab the int id for the resource
            int       productID = myPathway.MainOutputResourceID;
            IResource resource  = resources.ValueForKey(productID);

            label11.Text = resource.Density.UserValue.ToString();

            //The number value that goes into ValueForKey is the ID number for the pathway you are looking to use
            myPathway = pathways.ValueForKey(COAL_PATHWAY_ID);
            // Grab the int id for the resource
            productID    = myPathway.MainOutputResourceID;
            resource     = resources.ValueForKey(productID);
            label10.Text = resource.LowerHeatingValue.UserValue.ToString();

            //The number value that goes into ValueForKey is the ID number for the pathway you are looking to use
            myPathway = pathways.ValueForKey(LSDIESEL_PATHWAY_ID);
            // Grab the int id for the resource
            productID   = myPathway.MainOutputResourceID;
            resource    = resources.ValueForKey(productID);
            label9.Text = resource.SulfurRatio.UserValue.ToString();
        }
Esempio n. 2
0
        public void pullGREETParameterValues()
        {
            //You need to create these dictionaries in order to pull out the values you want
            IGDataDictionary <int, IResource> resources = ResultsAccess.controler.CurrentProject.Data.Resources;
            IGDataDictionary <int, IPathway>  pathways  = ResultsAccess.controler.CurrentProject.Data.Pathways;

            //The number value that goes into ValueForKey is the ID number for the pathway you are looking to use
            IPathway myPathway = pathways.ValueForKey(CRUDE_PATHWAY_ID);
            // Grab the int id for the resource
            int       productID = myPathway.MainOutputResourceID;
            IResource resource  = resources.ValueForKey(productID);

            label4.Text = resource.Density.GreetValue.ToString();

            //The number value that goes into ValueForKey is the ID number for the pathway you are looking to use
            myPathway = pathways.ValueForKey(COAL_PATHWAY_ID);
            // Grab the int id for the resource
            productID   = myPathway.MainOutputResourceID;
            resource    = resources.ValueForKey(productID);
            label5.Text = resource.LowerHeatingValue.GreetValue.ToString();

            //The number value that goes into ValueForKey is the ID number for the pathway you are looking to use
            myPathway = pathways.ValueForKey(LSDIESEL_PATHWAY_ID);
            // Grab the int id for the resource
            productID   = myPathway.MainOutputResourceID;
            resource    = resources.ValueForKey(productID);
            label7.Text = resource.SulfurRatio.GreetValue.ToString();
        }
Esempio n. 3
0
        /// <summary>
        /// Creates the list of available pathways and mixes
        /// </summary>
        public void InitializeControls()
        {
            //Gets the dictionary of IParameters object indexed by IParameters.Id
            //Parameters are used to store all input data necessary to the model (flows quantities, shares, heating values, carbon ratios, emission factors...
            IGDataDictionary <string, IParameter> parameters = ParametersExample.controler.CurrentProject.Data.Parameters;

            this.listBox1.Items.Clear();

            //Adding all parameters to the list box items so user can select a parameter
            foreach (IParameter param in parameters.AllValues.OrderBy(item => item.Id))
            {
                this.listBox1.Items.Add(param);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// This function is pulling the BTUPerGal for Conventional Diesel so it can be used to calculate the gallons per trip. (This is ultimately recalculated in the Results code)
        /// </summary>
        /// <returns> The total BTUs per Gallon of conventional diesel </returns>
        public double getApproxBTUperGAL()
        {
            IGDataDictionary <int, IResource> resources = ResultsAccess.controler.CurrentProject.Data.Resources;
            IGDataDictionary <int, IPathway>  pathways  = ResultsAccess.controler.CurrentProject.Data.Pathways;
            IGDataDictionary <int, IMix>      mixes     = ResultsAccess.controler.CurrentProject.Data.Mixes;
            IPathway myPathway = pathways.ValueForKey(CD_PATH_ID);
            int      productID = myPathway.MainOutputResourceID;

            productID = myPathway.MainOutputResourceID;
            IResource ConvDiesel = resources.ValueForKey(productID);

            if (ConvDiesel.LowerHeatingValue.UserValue == 0)
            {
                return((ConvDiesel.LowerHeatingValue.GreetValue) * (1 / GALLONS_PER_CUBIC_METER) * (1 / JOULES_PER_BTU));
            }
            else
            {
                return((ConvDiesel.LowerHeatingValue.UserValue) * (1 / GALLONS_PER_CUBIC_METER) * (1 / JOULES_PER_BTU));
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Creates the list of available pathways and mixes
        /// </summary>
        public void InitializeControls()
        {
            //Gets the dictionary of IResource object indexed by IResource.Id
            IGDataDictionary <int, IResource> resources = ResultsAccess.controler.CurrentProject.Data.Resources;
            //Gets the dictionary of IPathways object indexed by IPathway.Id
            IGDataDictionary <int, IPathway> pathways = ResultsAccess.controler.CurrentProject.Data.Pathways;
            //Gets the dictionary of IMixes object indexed by IMid.Id
            IGDataDictionary <int, IMix> mixes = ResultsAccess.controler.CurrentProject.Data.Mixes;

            this.treeView1.Nodes.Clear();

            //Adds pathways and mixes to the list so the user can select one
            foreach (IResource resource in resources.AllValues.OrderBy(item => item.Name))
            {
                TreeNode resourceTreeNode = new TreeNode(resource.Name);
                resourceTreeNode.Tag = resource;

                foreach (IPathway pathway in pathways.AllValues.Where(item => item.MainOutputResourceID == resource.Id))
                {
                    TreeNode pathwayNode = new TreeNode("Pathway: " + pathway.Name);
                    pathwayNode.Tag = pathway;
                    resourceTreeNode.Nodes.Add(pathwayNode);
                }

                foreach (IMix mix in mixes.AllValues.Where(item => item.MainOutputResourceID == resource.Id))
                {
                    TreeNode mixNode = new TreeNode("Mix: " + mix.Name);
                    mixNode.Tag = mix;
                    resourceTreeNode.Nodes.Add(mixNode);
                }

                if (resourceTreeNode.Nodes.Count > 0)
                {
                    this.treeView1.Nodes.Add(resourceTreeNode);
                }
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Get information about all the pathways and mixes.
        /// </summary>
        public void Run()
        {
            //Gets the dictionary of IResource object indexed by IResource.Id
            IGDataDictionary <int, IResource> resources = ResultsAccess.controler.CurrentProject.Data.Resources;
            //Gets the dictionary of IPathways object indexed by IPathway.Id
            IGDataDictionary <int, IPathway> pathways = ResultsAccess.controler.CurrentProject.Data.Pathways;
            //Gets the dictionary of IMixes object indexed by IMid.Id
            IGDataDictionary <int, IMix> mixes = ResultsAccess.controler.CurrentProject.Data.Mixes;
            // Gets the dictionary of vehicles.
            IGDataDictionary <int, IVehicle> vehicles = ResultsAccess.controler.CurrentProject.Data.Vehicles;

            int i = 0;

            using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"datafor_test.json"))
            {
                file.Write("{\"greetTests\":[");

                // resource name = resource.Name
                foreach (IPathway pathway in pathways.AllValues)
                {
                    IResults result      = null;
                    int      productID   = -1;
                    string   pathwayName = "";

                    //We ask the pathway what is the product defined as the main product for this pathway
                    //then store an integer that corresponds to an IResource.ID
                    productID = ResultsAccess.controler.CurrentProject.Data.Helper.PathwayMainOutputResouce(pathway.Id);
                    //We use the ID of the Resource that corresponds to the main output of the pathway to get the correct results
                    try
                    {
                        Dictionary <IIO, IResults> availableResults = pathway.GetUpstreamResults(ResultsAccess.controler.CurrentProject.Data);

                        Guid desiredOutput = new Guid();
                        foreach (IIO io in availableResults.Keys.Where(item => item.ResourceId == productID))
                        {
                            desiredOutput = io.Id;
                            if (io.Id == pathway.MainOutput)
                            {
                                desiredOutput = io.Id;
                                break;
                            }
                        }
                        result = availableResults.SingleOrDefault(item => item.Key.Id == desiredOutput).Value;
                        //We set the string variable as the name of the pathway
                        pathwayName = pathway.Name;

                        //if we found a pathway or a mix and we have all the necessary parameters
                        //we Invoke the SetResults method of our user control in charge of displaying the life cycle upstream results
                        if (result != null && productID != -1 && !String.IsNullOrEmpty(pathwayName))
                        {
                            System.Guid id = new Guid("dddddddddddddddddddddddddddddddd");
                            SetResults(file, pathwayName, "", id, result, i);
                            i++;
                        }


                        //Greet.DataStructureV4.Entities.Vehicle v = vehicle as Greet.DataStructureV4.Entities.Vehicle;

                        //getting the results for each individual vertex (canonical process representation of a process model) in the pathway
                        Greet.DataStructureV4.Entities.Pathway p = pathway as Greet.DataStructureV4.Entities.Pathway;
                        foreach (KeyValuePair <Guid, Greet.DataStructureV4.ResultsStorage.CanonicalProcess> pair in p.CanonicalProcesses)
                        {//iterate over all the processes in the pathway
                            Guid vertexUniqueId = pair.Key;
                            Greet.DataStructureV4.ResultsStorage.CanonicalProcess vertexProcessRepresentation = pair.Value;

                            int    processModelId = pair.Value.ModelId;
                            string processName    = ResultsAccess.controler.CurrentProject.Data.Processes.ValueForKey(processModelId).Name;

                            foreach (KeyValuePair <Guid, Greet.DataStructureV4.ResultsStorage.CanonicalOutput> outputPair in vertexProcessRepresentation.OutputsResults)
                            {//iterating over all the allocated outputs that have upstream results associated with them
                                Guid outputUniqueGui = outputPair.Key;
                                Greet.DataStructureV4.ResultsStorage.CanonicalOutput output = outputPair.Value;
                                IResults outputUpstreamResults = output.Results;

                                //if we found a pathway or a mix and we have all the necessary parameters
                                //we Invoke the SetResults method of our user control in charge of displaying the life cycle upstream results
                                if (outputUpstreamResults != null && productID != -1 && !String.IsNullOrEmpty(pathwayName))
                                {
                                    SetResults(file, pathwayName, processName, outputUniqueGui, outputUpstreamResults, i);
                                    i++;
                                }

                                AOutput referenceToOriginalProcessOutputInstance = outputPair.Value.Output;
                                double  calculatedOutputBiogenicCarbonMassRatio  = outputPair.Value.MassBiogenicCarbonRatio;
                            }
                        }
                    }
                    catch (System.Exception e)
                    {
                        Console.WriteLine("Problem with pathway {1}: {0}", e, pathway.Name);
                    }
                }

                foreach (IMix mix in mixes.AllValues)
                {
                    IResults result    = null;
                    int      productID = -1;
                    string   name      = "";

                    //We ask the mix what is the product defined as the main product for this mix
                    //then store an integer that corresponds to an IResource.ID
                    productID = mix.MainOutputResourceID;
                    //We use the ID of the Resource that corresponds to the main output of the pathway to get the correct results
                    var upstream = mix.GetUpstreamResults(ResultsAccess.controler.CurrentProject.Data);

                    if (null == upstream.Keys.SingleOrDefault(item => item.ResourceId == productID))
                    {
                        MessageBox.Show("Selected mix does not produce the fuel selected. Please remove it from the Fule Types list");
                        return;
                    }

                    //a mix has a single output so we can safely do the folowing
                    result = upstream.SingleOrDefault(item => item.Key.ResourceId == productID).Value;

                    //We set the string variable as the name of the pathway
                    name = mix.Name;

                    //if we found a pathway or a mix and we have all the necessary parameters
                    //we Invoke the SetResults method of our user control in charge of displaying the life cycle upstream results
                    if (result != null && productID != -1 && !String.IsNullOrEmpty(name))
                    {
                        System.Guid id = new Guid("dddddddddddddddddddddddddddddddd");
                        SetResults(file, name, "", id, result, i);
                        i++;
                    }
                }
                file.WriteLine("\n]}");
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Invoked when a pathway is selected in order to represent the life cycle results
        /// for the product produced by this pathway and defined as it's main output (which is
        /// equivalent to the main output of the last process in the pathway)
        /// </summary>
        /// <param name="name">Name of the pathway, will simply be displayed as is</param>
        /// <param name="results">Result object from the pathway for the desired productID</param>
        /// <returns>Returns 0 if succeed</returns>
        public int SetResults(System.IO.StreamWriter file, string pathwayName, string processName, Guid outputID, IResults results, int i)
        {
            if (i != 0)
            {
                file.Write(",\n");
            }
            else
            {
                file.Write("\n");
            }

            //Check that the resuls object is non null
            if (results == null)
            {
                return(-1);
            }

            file.WriteLine("\t{");
            file.WriteLine("\t\t\"i\": \"{0}\",", i);
            file.WriteLine("\t\t\"Pathway\": \"{0}\",", pathwayName);
            file.WriteLine("\t\t\"Process\": \"{0}\",", processName);
            file.WriteLine("\t\t\"OutputID\": \"{0}\",", outputID);

            //Get an instance of the data object that we are going to use to look for a Resource
            IData data = ResultsAccess.controler.CurrentProject.Data;
            //Gets the dictionary of IGases object indexed by IGas.Id
            IGDataDictionary <int, IGas>      gases     = ResultsAccess.controler.CurrentProject.Data.Gases;
            IGDataDictionary <int, IResource> resources = ResultsAccess.controler.CurrentProject.Data.Resources;

            file.Write("\t\t\"WTPEmis\": {");
            int ii = 0;

            foreach (KeyValuePair <int, IValue> emission in results.WellToProductEmissions())
            {
                if (ii != 0)
                {
                    file.Write(",\n");
                }
                else
                {
                    file.Write("\n");
                }
                IGas gas = gases.ValueForKey(emission.Key);
                //Format the value nicely using the quantity and the unit as well as the preferences defined by the user in the main UI GREET preferences
                file.Write("\t\t\t\"{0}\": {{\"val\":{1},\"units\":\"{2}\"}}", gas.Name, emission.Value.Value, emission.Value.UnitExpression);
                ii++;
            }

            file.Write("\n\t\t},\n\t\t\"OnSiteEmis\": {");
            ii = 0;
            foreach (KeyValuePair <int, IValue> emission in results.OnSiteEmissions())
            {
                if (ii != 0)
                {
                    file.Write(",\n");
                }
                else
                {
                    file.Write("\n");
                }
                IGas gas = gases.ValueForKey(emission.Key);
                //Format the value nicely using the quantity and the unit as well as the preferences defined by the user in the main UI GREET preferences
                file.Write("\t\t\t\"{0}\": {{\"val\":{1},\"units\":\"{2}\"}}", gas.Name, emission.Value.Value, emission.Value.UnitExpression);
                ii++;
            }

            file.Write("\n\t\t},\n\t\t\"WTPResources\": {");
            ii = 0;
            foreach (KeyValuePair <int, IValue> resUse in results.WellToProductResources())
            {
                if (ii != 0)
                {
                    file.Write(",\n");
                }
                else
                {
                    file.Write("\n");
                }
                IResource res = resources.ValueForKey(resUse.Key);
                //Format the value nicely using the quantity and the unit as well as the preferences defined by the user in the main UI GREET preferences
                file.Write("\t\t\t\"{0}\": {{\"val\":{1},\"units\":\"{2}\"}}", res.Name, resUse.Value.Value, resUse.Value.UnitExpression);
                ii++;
            }

            file.Write("\n\t\t},\n\t\t\"OnSiteResources\": {");
            ii = 0;
            foreach (KeyValuePair <int, IValue> resUse in results.OnSiteResources())
            {
                if (ii != 0)
                {
                    file.Write(",\n");
                }
                else
                {
                    file.Write("\n");
                }
                IResource res = resources.ValueForKey(resUse.Key);
                //Format the value nicely using the quantity and the unit as well as the preferences defined by the user in the main UI GREET preferences
                file.Write("\t\t\t\"{0}\": {{\"val\":{1},\"units\":\"{2}\"}}", res.Name, resUse.Value.Value, resUse.Value.UnitExpression);
                ii++;
            }
            file.Write("\n\t\t},\n");

            //Displays the functional unit for this results, very important in order to know if we are looking at results
            //per joule of product, or per cubic meters of product, or per kilograms of prododuct
            file.Write("\t\t\"FunctionalUnit\": \"{0}\"\n\t}}", results.FunctionalUnit);
            //If the user wants to see results in a different functional unit, the IValue quantity must be converted to the desired functional unit

            return(0);
        }