Beispiel #1
0
        /// <summary>
        /// Run the strategy to calculate the outputs. In case of error during the execution, the preconditions tests are executed.
        /// </summary>
        public void Estimate(SiriusQualityEnergyBalanceDomainClass.EnergyBalanceState energybalancestate, SiriusQualityEnergyBalanceDomainClass.EnergyBalanceState energybalancestate1, SiriusQualityEnergyBalanceDomainClass.EnergyBalanceExogenous energybalanceexogenous, CRA.AgroManagement.ActEvents actevents)
        {
            try
            {
                CalculateModel(energybalancestate, energybalancestate1, energybalanceexogenous, actevents);

                //Uncomment the next line to use the trace
                //TraceStrategies.TraceEvent(System.Diagnostics.TraceEventType.Verbose, 1005,"Strategy: " + this.GetType().Name + " - Model executed");
            }
            catch (Exception exception)
            {
                //Uncomment the next line to use the trace
                //TraceStrategies.TraceEvent(System.Diagnostics.TraceEventType.Error, 1003,		"Strategy: " + this.GetType().Name + " - Unhandled exception running model");

                string msg = "Error in component SiriusQualityEnergyBalance, strategy: " + this.GetType().Name + ": Unhandled exception running model. " + exception.GetType().FullName + " - " + exception.Message;
                throw new Exception(msg, exception);
            }
        }
Beispiel #2
0
        private void CalculateModel(SiriusQualityEnergyBalanceDomainClass.EnergyBalanceState energybalancestate, SiriusQualityEnergyBalanceDomainClass.EnergyBalanceState energybalancestate1, SiriusQualityEnergyBalanceDomainClass.EnergyBalanceExogenous energybalanceexogenous, CRA.AgroManagement.ActEvents actevents)
        {
            //GENERATED CODE END - PLACE YOUR CUSTOM CODE BELOW - Section1
            //Code written below will not be overwritten by a future code generation

            #region Inputs

            //double[] soilHeatFlux = energybalancestate.hourlySoilHeatFlux;
            double[] As = energybalancestate.hourlyNetRadSoil;
            Dictionary <string, Dictionary <int, Dictionary <int, double> > > Av = energybalancestate.hourlyNetRadVeg;

            #endregion

            #region Auxilliary

            double[] AvTot = new double[24];

            foreach (string isunshade in Av.Keys)
            {
                foreach (int ihour in Av[isunshade].Keys)
                {
                    foreach (int ilayer in Av[isunshade][ihour].Keys)
                    {
                        AvTot[ihour] += Av[isunshade][ihour][ilayer];
                    }
                }
            }

            #endregion

            #region Outputs

            //for (int ihour = 0; ihour < 24; ihour++) energybalancestate.hourlyNetRadTotAv[ihour] = As[ihour] + AvTot[ihour] - soilHeatFlux[ihour];
            for (int ihour = 0; ihour < 24; ihour++)
            {
                energybalancestate.hourlyNetRadTotAv[ihour] = As[ihour] + AvTot[ihour];
            }

            #endregion

            //End of custom code. Do not place your custom code below. It will be overwritten by a future code generation.
            //PLACE YOUR CUSTOM CODE ABOVE - GENERATED CODE START - Section1
        }
Beispiel #3
0
        /// <summary>
        /// Test to verify the preconditions
        /// </summary>
        public string TestPreConditions(SiriusQualityEnergyBalanceDomainClass.EnergyBalanceState energybalancestate, SiriusQualityEnergyBalanceDomainClass.EnergyBalanceState energybalancestate1, SiriusQualityEnergyBalanceDomainClass.EnergyBalanceExogenous energybalanceexogenous, string callID)
        {
            try
            {
                //Set current values of the inputs to the static VarInfo representing the input properties of the domain classes

                SiriusQualityEnergyBalanceDomainClass.EnergyBalanceStateVarInfo.hourlyNetRadSoil.CurrentValue   = energybalancestate.hourlyNetRadSoil;
                SiriusQualityEnergyBalanceDomainClass.EnergyBalanceStateVarInfo.hourlyNetLWVeg.CurrentValue     = energybalancestate.hourlyNetLWVeg;
                SiriusQualityEnergyBalanceDomainClass.EnergyBalanceStateVarInfo.hourlySoilHeatFlux.CurrentValue = energybalancestate.hourlySoilHeatFlux;

                //Create the collection of the conditions to test
                ConditionsCollection prc = new ConditionsCollection();
                Preconditions        pre = new Preconditions();


                RangeBasedCondition r1 = new RangeBasedCondition(SiriusQualityEnergyBalanceDomainClass.EnergyBalanceStateVarInfo.hourlyNetRadSoil);
                if (r1.ApplicableVarInfoValueTypes.Contains(SiriusQualityEnergyBalanceDomainClass.EnergyBalanceStateVarInfo.hourlyNetRadSoil.ValueType))
                {
                    prc.AddCondition(r1);
                }
                RangeBasedCondition r2 = new RangeBasedCondition(SiriusQualityEnergyBalanceDomainClass.EnergyBalanceStateVarInfo.hourlyNetLWVeg);
                if (r2.ApplicableVarInfoValueTypes.Contains(SiriusQualityEnergyBalanceDomainClass.EnergyBalanceStateVarInfo.hourlyNetLWVeg.ValueType))
                {
                    prc.AddCondition(r2);
                }
                RangeBasedCondition r3 = new RangeBasedCondition(SiriusQualityEnergyBalanceDomainClass.EnergyBalanceStateVarInfo.hourlySoilHeatFlux);
                if (r3.ApplicableVarInfoValueTypes.Contains(SiriusQualityEnergyBalanceDomainClass.EnergyBalanceStateVarInfo.hourlySoilHeatFlux.ValueType))
                {
                    prc.AddCondition(r3);
                }



                //GENERATED CODE END - PLACE YOUR CUSTOM CODE BELOW - Section3
                //Code written below will not be overwritten by a future code generation



                //End of custom code. Do not place your custom code below. It will be overwritten by a future code generation.
                //PLACE YOUR CUSTOM CODE ABOVE - GENERATED CODE START - Section3

                //Get the evaluation of preconditions;
                string preConditionsResult = pre.VerifyPreconditions(prc, callID);
                //if we have errors, send it to the configured output
                if (!string.IsNullOrEmpty(preConditionsResult))
                {
                    pre.TestsOut(preConditionsResult, true, "PreConditions errors in component SiriusQualityEnergyBalance, strategy " + this.GetType().Name);
                }
                return(preConditionsResult);
            }
            catch (Exception exception)
            {
                //Uncomment the next line to use the trace
                //	TraceStrategies.TraceEvent(System.Diagnostics.TraceEventType.Error, 1002,"Strategy: " + this.GetType().Name + " - Unhandled exception running pre-conditions");

                string msg = "Component SiriusQualityEnergyBalance, " + this.GetType().Name + ": Unhandled exception running pre-condition test. ";
                throw new Exception(msg, exception);
            }
        }