Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add wind eqn #228

Merged
merged 5 commits into from
Jul 29, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions Models/Agroforestry/LocalMicroClimate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ public class LocalMicroClimate : Model, IWeather
{

[Link]
Weather weather=null; // parent weather.
Weather weather = null; // parent weather.
[Link]
StaticForestrySystem ParentSystem=null;
StaticForestrySystem ParentSystem = null;
[Link]
Clock clock = null;

/// <summary>Gets the start date of the weather file</summary>
public DateTime StartDate { get { return weather.StartDate; } }
Expand All @@ -42,7 +44,7 @@ public class LocalMicroClimate : Model, IWeather
/// <summary>
/// Gets or sets the wind value found in weather file or zero if not specified.
/// </summary>
public double Wind { get { return weather.Wind * (1 - ParentSystem.GetWindReduction(Parent as Zone) / 100); } }
public double Wind { get { return weather.Wind * ParentSystem.GetWindReduction(Parent as Zone, clock.Today); } }

/// <summary>
/// Gets or sets the CO2 level. If not specified in the weather file the default is 350.
Expand Down
68 changes: 52 additions & 16 deletions Models/Agroforestry/StaticForestrySystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Data;
using System.Linq;
using System.Text;
using MathNet.Numerics.Interpolation;
using Models.Core;
using System.Xml.Serialization;
using Models.Interfaces;
Expand Down Expand Up @@ -44,7 +45,19 @@ public class StaticForestrySystem : Zone,IUptake
public List<ZoneInfo> ZoneInfoList;

/// <summary>
/// Return the distance from the tree for a given zone
/// Date list for tree heights over lime
/// </summary>
[Summary]
public DateTime[] dates { get; set; }

/// <summary>
/// Tree heights
/// </summary>
[Summary]
public double[] heights { get; set; }

/// <summary>
/// Return the distance from the tree for a given zone. The tree is assumed to be in the first Zone.
/// </summary>
/// <param name="z">Zone</param>
/// <returns>Distance from a static tree</returns>
Expand All @@ -63,7 +76,7 @@ public double GetDistanceFromTrees(Zone z)
return D;
}

throw new ApsimXException(this, "Could not find a shade value for zone called " + z.Name);
throw new ApsimXException(this, "Could not find zone called " + z.Name);
}
/// <summary>
/// Return the %Shade for a given zone
Expand All @@ -76,18 +89,47 @@ public double GetShade(Zone z)
if (zi.zone == z)
return zi.Shade;
throw new ApsimXException(this, "Could not find a shade value for zone called " + z.Name);


}
/// <summary>
/// Return the %Wind Reduction for a given zone
/// </summary>
/// <param name="z">Zone</param>
/// <param name="Today">The current date</param>
/// <returns>%Wind Reduction</returns>
public double GetWindReduction(Zone z)
public double GetWindReduction(Zone z, DateTime Today)
{
foreach (ZoneInfo zi in ZoneInfoList)
if (zi.zone == z)
return zi.WindReduction;
throw new ApsimXException(this, "Could not find a shade value for zone called " + z.Name);
{
double UrelMin = Math.Max(0.0, 1.14 * 0.5 - 0.16); // 0.5 is porosity, will be dynamic in the future
double Urel;
double H;
bool didInterp;
double[] OADates = new double[dates.Count()];
double heightToday;

for (int i = 0; i < dates.Count(); i++)
OADates[i] = dates[i].ToOADate();

heightToday = MathUtilities.LinearInterpReal(Today.ToOADate(), OADates, heights, out didInterp);

if (heightToday < 1000)
Urel = 1;
else
{
H = GetDistanceFromTrees(z) / (heightToday / 1000);
if (H < 6)
Urel = UrelMin + (1 - UrelMin) / 2 - H / 6 * (1 - UrelMin) / 2;
else if (H < 6.1)
Urel = UrelMin;
else
Urel = UrelMin + (1 - UrelMin) / (1 + 0.000928 * Math.Exp(Math.Pow(12.9372 * (H - 6), -0.26953)));
}
return Urel;
}
throw new ApsimXException(this, "Could not find zone called " + z.Name);
}
/// <summary>
/// Return the area of the zone.
Expand Down Expand Up @@ -131,12 +173,11 @@ private void OnSimulationCommencing(object sender, EventArgs e)
for (int i = 2; i < Table.Count; i++)
{
ZoneInfo newZone = new ZoneInfo();
newZone.zone = Apsim.Child(this,Table[0][i - 1]) as Zone;
newZone.WindReduction = Convert.ToDouble(Table[i][0]);
newZone.Shade = Convert.ToDouble(Table[i][1]);
newZone.RLD = new double[Table[1].Count - 4];
for (int j = 4; j < Table[1].Count; j++)
newZone.RLD[j - 4] = Convert.ToDouble(Table[i][j]);
newZone.zone = Apsim.Child(this, Table[0][i - 1]) as Zone;
newZone.Shade = Convert.ToDouble(Table[i][0]);
newZone.RLD = new double[Table[1].Count - 3];
for (int j = 3; j < Table[1].Count; j++)
newZone.RLD[j - 3] = Convert.ToDouble(Table[i][j]);
ZoneInfoList.Add(newZone);
}
}
Expand Down Expand Up @@ -304,11 +345,6 @@ public struct ZoneInfo
/// </summary>
public Zone zone;

/// <summary>
/// Wind value.
/// </summary>
public double WindReduction;

/// <summary>
/// Shade value.
/// </summary>
Expand Down
Loading