/// <summary> /// Test to verify the preconditions /// </summary> public string TestPreConditions(SiriusQualityMeteo.MeteoState meteostate, string callID) { try { //Set current values of the inputs to the static VarInfo representing the input properties of the domain classes SiriusQualityMeteo.MeteoStateVarInfo.maxTair.CurrentValue = meteostate.maxTair; SiriusQualityMeteo.MeteoStateVarInfo.minTair.CurrentValue = meteostate.minTair; SiriusQualityMeteo.MeteoStateVarInfo.dayOfYear.CurrentValue = meteostate.dayOfYear; //Create the collection of the conditions to test ConditionsCollection prc = new ConditionsCollection(); Preconditions pre = new Preconditions(); RangeBasedCondition r1 = new RangeBasedCondition(SiriusQualityMeteo.MeteoStateVarInfo.maxTair); if (r1.ApplicableVarInfoValueTypes.Contains(SiriusQualityMeteo.MeteoStateVarInfo.maxTair.ValueType)) { prc.AddCondition(r1); } RangeBasedCondition r2 = new RangeBasedCondition(SiriusQualityMeteo.MeteoStateVarInfo.minTair); if (r2.ApplicableVarInfoValueTypes.Contains(SiriusQualityMeteo.MeteoStateVarInfo.minTair.ValueType)) { prc.AddCondition(r2); } RangeBasedCondition r3 = new RangeBasedCondition(SiriusQualityMeteo.MeteoStateVarInfo.dayOfYear); if (r3.ApplicableVarInfoValueTypes.Contains(SiriusQualityMeteo.MeteoStateVarInfo.dayOfYear.ValueType)) { prc.AddCondition(r3); } prc.AddCondition(new RangeBasedCondition(_modellingOptionsManager.GetParameterByName("latitude"))); //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 SiriusQualityMeteo.Strategies, 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 SiriusQualityMeteo.Strategies, " + this.GetType().Name + ": Unhandled exception running pre-condition test. "; throw new Exception(msg, exception); } }
private void CalculateModel(SiriusQualityMeteo.MeteoState meteostate) { //GENERATED CODE END - PLACE YOUR CUSTOM CODE BELOW - Section1 //Code written below will not be overwritten by a future code generation //double LatR = latitude * Math.PI / 180; //double soldec = meteostate.solarDeclination; double DOY = meteostate.dayOfYear; double costheta = 0.0; double So = 0.0; double Io = 1370 * (1 + 0.033 * Math.Cos(2 * Math.PI * (DOY / 365))) * (3600.0 / 1000000.0); double RsRso = 0.0; double R = 0.0; double K = 0.0; double ratioDiffDir = 0.0; // double hoursrad = 0.0; for (int ihours = 0; ihours < 24; ihours++) { meteostate.hourlyIdir[ihours] = 0.0; meteostate.hourlyIdiff[ihours] = 0.0; // hoursrad = (2 * Math.PI / 24) * (ihours - 12);//A vérifier // costheta = Math.Sin(LatR) * Math.Sin(soldec) + Math.Cos(LatR) * Math.Cos(soldec) * Math.Cos(hoursrad); costheta = Math.Sin(meteostate.hourlySolarElevation[ihours]); So = Io * costheta; RsRso = meteostate.hourlyRadiation[ihours] / So; R = 0.847 - 1.61 * costheta + 1.04 * costheta * costheta; K = (1.47 - R) / 1.66; if (RsRso <= 0.22) { ratioDiffDir = 1.0; } else if (RsRso <= 0.35) { ratioDiffDir = 1.0 - 6.4 * (RsRso - 0.22) * (RsRso - 0.22); } else if (RsRso <= K) { ratioDiffDir = 1.47 - 1.66 * RsRso; } else { ratioDiffDir = R; } meteostate.hourlyIdir[ihours] = meteostate.hourlyRadiation[ihours] / (1 + ratioDiffDir); meteostate.hourlyIdiff[ihours] = meteostate.hourlyRadiation[ihours] * ratioDiffDir / (1 + ratioDiffDir); } //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 }
private void CalcVPDair(SiriusQualityMeteo.MeteoState meteostate) { for (int i = 0; i < 24; i++) { meteostate.hourlyVPDAir[i] = 6.108 * (Math.Exp((17.27 * meteostate.hourlyAirTemperature[i]) / (meteostate.hourlyAirTemperature[i] + 237.3)) - meteostate.RH[i] / 100 * Math.Exp((17.27 * meteostate.hourlyAirTemperature[i]) / (meteostate.hourlyAirTemperature[i] + 237.3))); } }
private void CalculateModel(SiriusQualityMeteo.MeteoState meteostate) { //GENERATED CODE END - PLACE YOUR CUSTOM CODE BELOW - Section1 //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 - Section1 }
//GENERATED CODE END - PLACE YOUR CUSTOM CODE BELOW - Section2 //Code written below will not be overwritten by a future code generation private void calcHourlyWeatherVars(SiriusQualityMeteo.MeteoState meteostate) { CalcHourlySVP(meteostate.hourlyAirTemperature); // hourly relative humidity // if daily max and min RH is unavailable, use -1 double maxRH = -1; double minRH = -1; CalcRH(meteostate, maxRH, minRH); }
} //m/d #endregion public MeteoBiomaWrapper(Universe universe) : base(universe) { meteoComponent = new SiriusQualityMeteo.Strategies.Meteorology(); meteoState = new SiriusQualityMeteo.MeteoState(); // airTComponent = new CRA.Clima.AirT.Strategies.HATGoudriaanVanLaar(); // airTState =new CRA.Clima.AirT.Interfaces.AirTData(); loadParameters(); }
//Parameters static VarInfo list of the composite class #endregion #region pre/post conditions management /// <summary> /// Test to verify the postconditions /// </summary> public string TestPostConditions(SiriusQualityMeteo.MeteoState meteostate, string callID) { try { //Set current values of the outputs to the static VarInfo representing the output properties of the domain classes SiriusQualityMeteo.MeteoStateVarInfo.hourlyRadiation.CurrentValue = meteostate.hourlyRadiation; SiriusQualityMeteo.MeteoStateVarInfo.hourlySolarElevation.CurrentValue = meteostate.hourlySolarElevation; //Create the collection of the conditions to test ConditionsCollection prc = new ConditionsCollection(); Preconditions pre = new Preconditions(); RangeBasedCondition r6 = new RangeBasedCondition(SiriusQualityMeteo.MeteoStateVarInfo.hourlyRadiation); if (r6.ApplicableVarInfoValueTypes.Contains(SiriusQualityMeteo.MeteoStateVarInfo.hourlyRadiation.ValueType)) { prc.AddCondition(r6); } RangeBasedCondition r7 = new RangeBasedCondition(SiriusQualityMeteo.MeteoStateVarInfo.hourlySolarElevation); if (r7.ApplicableVarInfoValueTypes.Contains(SiriusQualityMeteo.MeteoStateVarInfo.hourlySolarElevation.ValueType)) { prc.AddCondition(r7); } //GENERATED CODE END - PLACE YOUR CUSTOM CODE BELOW - Section4 //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 - Section4 //Get the evaluation of postconditions string postConditionsResult = pre.VerifyPostconditions(prc, callID); //if we have errors, send it to the configured output if (!string.IsNullOrEmpty(postConditionsResult)) { pre.TestsOut(postConditionsResult, true, "PostConditions errors in component SiriusQualityMeteo.Strategies, strategy " + this.GetType().Name); } return(postConditionsResult); } catch (Exception exception) { //Uncomment the next line to use the trace //TraceStrategies.TraceEvent(System.Diagnostics.TraceEventType.Error, 1001, "Strategy: " + this.GetType().Name + " - Unhandled exception running post-conditions"); string msg = "Component SiriusQualityMeteo.Strategies, " + this.GetType().Name + ": Unhandled exception running post-condition test. "; throw new Exception(msg, exception); } }
/// <summary> /// Test to verify the preconditions /// </summary> public string TestPreConditions(SiriusQualityMeteo.MeteoState meteostate, string callID) { try { //Set current values of the inputs to the static VarInfo representing the input properties of the domain classes //Create the collection of the conditions to test ConditionsCollection prc = new ConditionsCollection(); Preconditions pre = new Preconditions(); string ret = ""; ret += _calculatedailyvpd.TestPreConditions(meteostate, "strategy SiriusQualityMeteo.Strategies.CalculateDailyVPD"); ret += _calculatehourlyairtemperature.TestPreConditions(meteostate, "strategy SiriusQualityMeteo.Strategies.CalculateHourlyAirTemperature"); ret += _calculatehourlydirdifradiations.TestPreConditions(meteostate, "strategy SiriusQualityMeteo.Strategies.CalculateHourlyDirDifRadiations"); ret += _calculatehourlyradiation.TestPreConditions(meteostate, "strategy SiriusQualityMeteo.Strategies.CalculateHourlyRadiation"); ret += _calculatehourlyvpdair.TestPreConditions(meteostate, "strategy SiriusQualityMeteo.Strategies.calculateHourlyVPDAir"); ret += _calculatehourlywindspeed.TestPreConditions(meteostate, "strategy SiriusQualityMeteo.Strategies.CalculateHourlyWindSpeed"); ret += _calculateminmaxdailywindspeed.TestPreConditions(meteostate, "strategy SiriusQualityMeteo.Strategies.CalculateMinMaxDailyWindSpeed"); ret += _calculatephotoperiod.TestPreConditions(meteostate, "strategy SiriusQualityMeteo.Strategies.CalculatePhotoperiod"); if (ret != "") { pre.TestsOut(ret, true, " preconditions tests of associated classes"); } //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 SiriusQualityMeteo.Strategies, 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 SiriusQualityMeteo.Strategies, " + this.GetType().Name + ": Unhandled exception running pre-condition test. "; throw new Exception(msg, exception); } }
private void CalculateModel(SiriusQualityMeteo.MeteoState meteostate) { //GENERATED CODE END - PLACE YOUR CUSTOM CODE BELOW - Section1 //Code written below will not be overwritten by a future code generation meteostate.hourlyAirTemperature = getHourlyTemperature(meteostate.maxTair, meteostate.minTair, meteostate.dayOfYear, latitude, 1.5, 4, 1); //meteostate.hourlyAirTemperature = getHourlyTemperature(meteostate.maxTair, meteostate.minTair, meteostate.dayOfYear, meteostate.dayLength, 1.5, 4, 1); //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 }
private void CalculateModel(SiriusQualityMeteo.MeteoState meteostate) { //GENERATED CODE END - PLACE YOUR CUSTOM CODE BELOW - Section1 //Code written below will not be overwritten by a future code generation //Goudriaan, J., and H.H. Van Laar. 1994. Modelling potential crop growth processes. Kluwer Academic Publishers, London, United Kingdom. for (int ihour = 0; ihour < 24; ihour++) { meteostate.hourlyWindSpeed[ihour] = meteostate.dailyMinWindSpeed + (meteostate.dailyMaxWindSpeed - meteostate.dailyMinWindSpeed) * (Math.Max(0.0, meteostate.hourlySolarElevation[ihour]) / meteostate.hourlySolarElevation[11]); } //m/d //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 }
/// <summary> /// Calculate method for the component with test of preconditions /// </summary> /// <param name=m>MeteoState Domain class contains the accessors to values</param> /// <param name="saveLog">Save log via a writer or show on screen</param> /// <param name="callID">Context description for violations</param> public void Estimate (IStrategySiriusQualityMeteo st, MeteoState m, bool saveLog, string callID) { _resultPreConditions = String.Empty; _resultPostConditions = String.Empty; _resultPreConditions = st.TestPreConditions(m, callID); st.Estimate (m); _resultPostConditions = st.TestPostConditions(m, callID); if (_resultPreConditions != String.Empty || _resultPostConditions != String.Empty) { p.TestsOut(_resultPreConditions + _resultPostConditions, saveLog, callID); } }
private void CalculateModel(SiriusQualityMeteo.MeteoState meteostate) { //GENERATED CODE END - PLACE YOUR CUSTOM CODE BELOW - Section1 //Code written below will not be overwritten by a future code generation //Ephrath, J.E., J. Goudriaan, and A. Marani. 1996. Modelling diurnal patterns of air temperatures, radiation, wind speed and relative humidity by equations for daily characteristics. Agr. Sys., 51:377-393. //Calculate hour of sunrise int hsunrise = 0; for (int ihour = 0; ihour < 24; ihour++) { if (meteostate.hourlySolarElevation[ihour] > 0.0) { hsunrise = ihour + 1; break; } } //Calculate hour of sunrise int hsunset = 0; for (int ihour = 11; ihour < 24; ihour++) { if (meteostate.hourlySolarElevation[ihour] == 0.0) { hsunset = ihour + 1; break; } } double T1 = hsunrise + hourOfBlowingBeginingT1; double T3 = hsunset + hourOfBlowingStopT3; //Calculate daily minimum wind speed meteostate.dailyMinWindSpeed = (meteostate.dailyMeanWindSpeed / (24 * 3600)) * nightTimeWindFactor; //m s-1 //Calculate daily maximum wind temperature double SFsum = 4 * (T3 - T1); meteostate.dailyMaxWindSpeed = 24 * 2 * Math.PI * (((meteostate.dailyMeanWindSpeed / (24 * 3600)) - meteostate.dailyMinWindSpeed) / SFsum); //m s-1 //Coversion from m s-1 to m d-1 meteostate.dailyMinWindSpeed = meteostate.dailyMinWindSpeed * (24 * 3600); meteostate.dailyMaxWindSpeed = meteostate.dailyMaxWindSpeed * (24 * 3600); //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 }
//Call of the associated strategies private void EstimateOfAssociatedClasses(SiriusQualityMeteo.MeteoState meteostate) { _calculatedailyvpd.Estimate(meteostate); _calculateminmaxdailywindspeed.Estimate(meteostate); _calculatephotoperiod.Estimate(meteostate); if (meteostate.calculateHourly == 1) { _calculatehourlyairtemperature.Estimate(meteostate); _calculatehourlyradiation.Estimate(meteostate); _calculatehourlydirdifradiations.Estimate(meteostate); _calculatehourlyvpdair.Estimate(meteostate); _calculatehourlywindspeed.Estimate(meteostate); } }
private void CalcRH(SiriusQualityMeteo.MeteoState meteostate, double RHMax, double RHMin) { // calculate relative humidity double wP; if (RHMax < 0.0 || RHMin < 0.0) { wP = CalcSVP(meteostate.minTair) * 0.90; // svp at Tmin } else { wP = (CalcSVP(meteostate.minTair) * (RHMax / 100.0) + CalcSVP(meteostate.maxTair) / (RHMin / 100.0)) / 2.0; } for (int i = 0; i < 24; i++) { meteostate.RH[i] = 100 * (wP / SVP[i]); } }
/// <summary> /// Run the strategy to calculate the outputs. In case of error during the execution, the preconditions tests are executed. /// </summary> public void Estimate(SiriusQualityMeteo.MeteoState meteostate) { try { CalculateModel(meteostate); //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 SiriusQualityMeteo.Strategies, strategy: " + this.GetType().Name + ": Unhandled exception running model. " + exception.GetType().FullName + " - " + exception.Message; throw new Exception(msg, exception); } }
///<summary> ///Calculate air (VPDair) and air-to-canopy (VPDairCanopy) vapour pressure deficit ///OUTPUT UNITS: hPa ///</summary> ///<param name="meanAirTemperature"></param> ///<param name="meanCanopyTemperature"></param> ///<param name="vp"></param> ///<returns></returns> public void CalculateVPD(SiriusQualityMeteo.MeteoState meteostate) { meteostate.VPDair = Math.Max(0.0, CalculateSaturationVaporPressure(meteostate.minTair, meteostate.maxTair) - meteostate.vaporPressure); // returns hPa meteostate.VPDairCanopy = Math.Max(0.0, CalculateSaturationVaporPressure(meteostate.minShootTemperature, meteostate.maxShootTemperature) - meteostate.vaporPressure); // returns hPa }
//GENERATED CODE END - PLACE YOUR CUSTOM CODE BELOW - Section2 //Code written below will not be overwritten by a future code generation ///<summary> ///Slope of saturated vapour pressure temperature curve at temperature T ///OUTPUT UNITS: hPa �C-1 ///</summary> ///<param name="meanTemperature"></param> ///<param name="temperatureWaterTriplePoint"></param> ///<returns></returns> public void EstimateHSlope(SiriusQualityMeteo.MeteoState meteostate) { meteostate.HSlope = 4098 * CalculateSaturationVaporPressure(meteostate.minTair, meteostate.maxTair) / (Math.Pow(meteostate.meanTair + 237.3, 2)); }
public MeteoState(MeteoState toCopy, bool copyAll) { _parametersIO = new ParametersIO(this); _dayLengthHorizonZero = toCopy.dayLengthHorizonZero; _dayLength = toCopy.dayLength; _photoperiod = toCopy.photoperiod; _radTopAtm = toCopy.radTopAtm; _radTopAtmHorizonZero = toCopy.radTopAtmHorizonZero; _HSlope = toCopy.HSlope; _saturationVaporPressure = toCopy.saturationVaporPressure; _VPDair = toCopy.VPDair; _VPDairCanopy = toCopy.VPDairCanopy; _RH = new double[24]; _hourlyAirTemperature = new double[24]; _hourlyVPDAir = new double[24]; _hourlyRadiation = new double[24]; _hourlySolarElevation = new double[24]; _hourlyWindSpeed = new double[24]; for (int i = 0; i < 24; i++) { _hourlyRadiation[i] = toCopy.hourlyRadiation[i]; } for (int i = 0; i < 24; i++) { _hourlyIdir[i] = toCopy.hourlyRadiation[i]; } for (int i = 0; i < 24; i++) { _hourlyIdiff[i] = toCopy.hourlyRadiation[i]; } for (int i = 0; i < 24; i++) { _hourlySolarElevation[i] = toCopy._hourlySolarElevation[i]; } for (int i = 0; i < 24; i++) { _hourlyWindSpeed[i] = toCopy._hourlyWindSpeed[i]; } if (toCopy.calculateHourly == 1) { for (int i = 0; i < 24; i++) { _RH[i] = toCopy.RH[i]; _hourlyAirTemperature[i] = toCopy.hourlyAirTemperature[i]; _hourlyVPDAir[i] = toCopy.hourlyVPDAir[i]; } } if (copyAll) { _calculateHourly = toCopy.calculateHourly; _minTair = toCopy.minTair; _maxTair = toCopy.maxTair; _meanTair = toCopy.meanTair; _minShootTemperature = toCopy.minShootTemperature; _maxShootTemperature = toCopy.maxShootTemperature; _dayOfYear = toCopy.dayOfYear; _vaporPressure = toCopy.vaporPressure; _solarRadiation = toCopy.solarRadiation; } _dailyMeanWindSpeed = toCopy._dailyMeanWindSpeed; _dailyMaxWindSpeed = toCopy._dailyMaxWindSpeed; _dailyMinWindSpeed = toCopy._dailyMinWindSpeed; }
private void CalculateModel(SiriusQualityMeteo.MeteoState meteostate) { //GENERATED CODE END - PLACE YOUR CUSTOM CODE BELOW - Section1 //Code written below will not be overwritten by a future code generation var alat = latitude * Math.PI / 180;// / 57.296; const double dayNumber = 365; const double _2Pi = 2.0 * Math.PI; const double dayLength = 24; double[] photop = { 0, 0, 0 }; double[] dayLengths = { 0, 0, 0 }; double[] days = { 0, 0, 0 }; double jday = meteostate.dayOfYear; days[1] = (jday == dayNumber) ? 1 : jday; days[2] = (days[1] + 1 > dayNumber) ? 1 : days[1] + 1; days[0] = (days[1] - 1 < 0) ? dayNumber : days[1] - 1; // Daylength is calculated following the treatment of // Sellers, Physical Climatology, pp 15-16 and Appendix 2. //Debug /* var th1 = _2Pi * (days[1] - 80.0) / dayNumber; * var th2 = 0.0335 * (Math.Sin(_2Pi * days[1] / dayNumber) - Math.Sin(_2Pi * 80.0 / dayNumber)); * * var th = th1 + th2; * * meteostate.solarDeclination = Math.Asin(0.3978 * Math.Sin(th));*/ //Debug double dec = 0; for (var i = 0; i < 3; ++i) { var theta1 = _2Pi * (days[i] - 80.0) / dayNumber; var theta2 = 0.0335 * (Math.Sin(_2Pi * days[i] / dayNumber) - Math.Sin(_2Pi * 80.0 / dayNumber)); var theta = theta1 + theta2; dec = Math.Asin(0.3978 * Math.Sin(theta)); // Daylength is calculated with a correction for atmospheric // refraction equivalent to 50 minutes var x1 = Math.Cos(alat) * Math.Cos(dec); var b = -0.01454 / x1; var x2 = Math.Tan(alat) * Math.Tan(dec); var h = Math.Acos(b - x2); dayLengths[i] = dayLength * h / Math.PI; // Photoperiod is calculated assuming that light is perceived // until the centre of the sun is 6 degrees below the horizon var d = -1.0 * 0.10453 / (Math.Cos(alat) * Math.Cos(dec)); var p = Math.Acos(d - (Math.Tan(alat) * Math.Tan(dec))); photop[i] = Math.Min(dayLength * p / Math.PI, dayLength); } meteostate.dayLength = dayLengths[1]; meteostate.photoperiod = photop[1]; //DeltaPP = (photop[2] - photop[1]) / 2.0; // Calculation of radiation receipt at top of Atmosphere, after Spitters C.J.T, Toussaint H.A.J.M. and Goudriaan J (1986). Agricultural and Forest Meteorology, 38 (1986) 217-229 //Right Spitters adapted to actual definition of daylength meteostate.radTopAtm = 1370.0 * (1.0 + 0.033 * Math.Cos(Math.PI / 180.0 * 360.0 * jday / dayNumber)) * 3600.0 * (dayLengths[1] * Math.Sin(alat) * Math.Sin(dec) + dayLength / Math.PI * Math.Cos(alat) * Math.Cos(dec)) * (1.0 - Math.Pow(Math.Tan(alat), 2) * Math.Pow(Math.Tan(dec), 2)) / 1000000.0; //Right //Wrong // meteostate.radTopAtm = 1370.0 * (1.0 + 0.033 * Math.Cos(Math.PI / 180.0 * 360.0 * jday / dayNumber)) // * 3600.0 * (dayLengths[1] * Math.Sin(alat) * Math.Sin(dec) + dayLength / Math.PI * Math.Cos(alat) * Math.Cos(dec) * Math.Sqrt(1.0 - Math.Pow(Math.Tan(alat), 2) * Math.Pow(Math.Tan(dec), 2)))/ 1000000.0; //Wrong bad definition iof daylength //Right // meteostate.radTopAtm = 1370.0 * (1.0 + 0.033 * Math.Cos(Math.PI / 180.0 * 360.0 * jday / dayNumber)) * 3600.0 * ((12 + (24 / 180) * Math.Asin(Math.Tan(alat) - Math.Tan(dec))) * Math.Sin(alat) * Math.Sin(dec) + dayLength / Math.PI * Math.Cos(alat) * Math.Cos(dec) * Math.Sqrt(1.0 - Math.Pow(Math.Tan(alat), 2) * Math.Pow(Math.Tan(dec), 2))) / 1000000.0; //Right exactly Spitters //Debug // meteostate.radTopAtm = 1370.0 * (1.0 + 0.033 * Math.Cos(Math.PI / 180.0 * 360.0 * jday / dayNumber)) // * 3600.0 * (dayLengths[1] * Math.Sin(alat) * Math.Sin(dec) + dayLength / Math.PI * Math.Cos(alat) * Math.Cos(dec) * Math.Sqrt(1.0 - ((-0.1454 / (Math.Cos(alat) * Math.Cos(dec))) - Math.Pow(Math.Tan(alat), 2) * Math.Pow(Math.Tan(dec), 2)))) / 1000000.0; //Calculations used in the others strategies meteostate.solarDeclination = CalcSolarDeclination(meteostate.dayOfYear); meteostate.dayLengthHorizonZero = CalcDayLength(alat, meteostate.solarDeclination); double RATIO = 0.75; //Hammer, Wright (Aust. J. Agric. Res., 1994, 45) meteostate.radTopAtmHorizonZero = CalcSolarRadn(RATIO, meteostate.dayLengthHorizonZero, alat, meteostate.solarDeclination); //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 }
private void CalculateModel(SiriusQualityMeteo.MeteoState meteostate) { //GENERATED CODE END - PLACE YOUR CUSTOM CODE BELOW - Section1 //Code written below will not be overwritten by a future code generation for (int i = 0; i < 24; i++) { meteostate.hourlyRadiation[i] = 0.0; } // some constants double LatR = latitude * Math.PI / 180; // some calculations //double SolarDec = CalcSolarDeclination(meteostate.dayOfYear); double SolarDec = meteostate.solarDeclination; //double DayL = CalcDayLength(LatR, SolarDec); // day length (radians) //double DayLH = (2.0 / 15.0 * DayL) * (180 / Math.PI); // day length (hours) //Debug double DayL = meteostate.dayLengthHorizonZero; // day length (radians) double DayLH = (2.0 / 15.0 * DayL) * (180 / Math.PI); // day length (hours) //double DayLH = meteostate.dayLength; // day length (hours) // double DayL = meteostate.dayLength * (Math.PI / 24.0); // day length (radians) //Debug //double Solar = CalcSolarRadn(RATIO, DayL, LatR, SolarDec); // solar radiation //Debug double Solar = meteostate.radTopAtmHorizonZero; // solar radiation //double Solar = meteostate.radTopAtm;// solar radiation //Debug //do the radiation calculation zeroing at dawn double DuskDawnFract = (DayLH - (int)DayLH) / 2; //the remainder part of the hour at dusk and dawn double DawnTime = 12 - (DayLH / 2); // DawnTime = (180 - RadToDeg(acos(-1 * tan(LatR) * tan(SolarDec)))) / 360 * 24; //Wikipedia ??? //The first partial hour // meteostate.hourlyRadiation[(int)DawnTime] += (GlobalRadiation(DuskDawnFract / DayLH, LatR, SolarDec, DayLH, Solar)[0] * 3600 * DuskDawnFract); meteostate.hourlyRadiation[(int)DawnTime] = (GlobalRadiation(DuskDawnFract / DayLH, LatR, SolarDec, DayLH, Solar)[0] * 3600 * DuskDawnFract); meteostate.hourlySolarElevation[(int)DawnTime] = GlobalRadiation(DuskDawnFract / DayLH, LatR, SolarDec, DayLH, Solar)[2]; //Add the next lot for (int i = 0; i < (int)(DayLH - 1); i++) { // meteostate.hourlyRadiation[(int)DawnTime + i + 1] += (GlobalRadiation((DuskDawnFract / DayLH) + ((i + 1) * 1.0 / Math.Truncate(DayLH)), LatR, SolarDec, DayLH, Solar)[0] * 3600); meteostate.hourlyRadiation[(int)DawnTime + i + 1] = (GlobalRadiation((DuskDawnFract / DayLH) + ((i + 1) * 1.0 / Math.Truncate(DayLH)), LatR, SolarDec, DayLH, Solar)[0] * 3600); meteostate.hourlySolarElevation[(int)DawnTime + i + 1] = GlobalRadiation((DuskDawnFract / DayLH) + ((i + 1) * 1.0 / Math.Truncate(DayLH)), LatR, SolarDec, DayLH, Solar)[2]; } //Add the last one //meteostate.hourlyRadiation[(int)DawnTime + (int)DayLH + 1] += (GlobalRadiation(1, LatR, SolarDec, DayLH, Solar)[0] * 3600 * DuskDawnFract); meteostate.hourlyRadiation[(int)DawnTime + (int)DayLH + 1] = (GlobalRadiation(1, LatR, SolarDec, DayLH, Solar)[0] * 3600 * DuskDawnFract); meteostate.hourlySolarElevation[(int)DawnTime + (int)DayLH + 1] = GlobalRadiation(1, LatR, SolarDec, DayLH, Solar)[2]; double TotalRad = 0; for (int i = 0; i < 24; i++) { TotalRad += meteostate.hourlyRadiation[i]; } for (int i = 0; i < 24; i++) { meteostate.hourlyRadiation[i] = meteostate.hourlyRadiation[i] / TotalRad * meteostate.solarRadiation; } //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 }
/// <summary> /// Calculate method for the component /// </summary> /// <param name=m>MeteoState Domain class contains the accessors to values</param> public void Estimate (IStrategySiriusQualityMeteo st, MeteoState m) { st.Estimate (m); }