Beispiel #1
0
        private void OnCLEMInitialiseResource(object sender, EventArgs e)
        {
            // activity is performed in CLEMUpdatePasture not CLEMGetResources and has no labour
            this.AllocationStyle = ResourceAllocationStyle.Manual;

            // locate Land Type resource for this forage.
            LinkedLandItem     = Resources.GetResourceItem(this, LandTypeNameToUse, OnMissingResourceActionTypes.ReportErrorAndStop, OnMissingResourceActionTypes.ReportErrorAndStop) as LandType;
            LandConditionIndex = Apsim.Children(this, typeof(RelationshipTracker)).Where(a => a.Name == "LandConditionIndex").FirstOrDefault() as RelationshipTracker;
            GrassBasalArea     = Apsim.Children(this, typeof(RelationshipTracker)).Where(a => a.Name == "GrassBasalArea").FirstOrDefault() as RelationshipTracker;
            FilePasture        = Apsim.ChildrenRecursively(ZoneCLEM.Parent).Where(a => a.Name == PastureDataReader).FirstOrDefault() as IFilePasture;

            if (UseAreaAvailable)
            {
                LinkedLandItem.TransactionOccurred += LinkedLandItem_TransactionOccurred;
            }

            ResourceRequestList = new List <ResourceRequest>
            {
                new ResourceRequest()
                {
                    AllowTransmutation = false,
                    Required           = UseAreaAvailable ? LinkedLandItem.AreaAvailable : AreaRequested,
                    ResourceType       = typeof(Land),
                    ResourceTypeName   = LandTypeNameToUse.Split('.').Last(),
                    ActivityModel      = this,
                    Reason             = UseAreaAvailable ?"Assign unallocated":"Assign",
                    FilterDetails      = null
                }
            };

            CheckResources(ResourceRequestList, Guid.NewGuid());
            gotLandRequested = TakeResources(ResourceRequestList, false);

            //Now the Land has been allocated we have an Area
            if (gotLandRequested)
            {
                //get the units of area for this run from the Land resource parent.
                unitsOfArea2Ha = Resources.Land().UnitsOfAreaToHaConversion;

                // locate Pasture Type resource
                LinkedNativeFoodType = Resources.GetResourceItem(this, FeedTypeName, OnMissingResourceActionTypes.ReportErrorAndStop, OnMissingResourceActionTypes.ReportErrorAndStop) as GrazeFoodStoreType;

                //Assign the area actually got after taking it. It might be less than AreaRequested (if partial)
                Area = ResourceRequestList.FirstOrDefault().Provided;

                // ensure no other activity has set the area of this GrazeFoodStore
                LinkedNativeFoodType.Manager = this as IPastureManager;

                soilIndex = ((LandType)ResourceRequestList.FirstOrDefault().Resource).SoilType;

                LinkedNativeFoodType.CurrentEcologicalIndicators.LandConditionIndex = LandConditionIndex.StartingValue;
                LinkedNativeFoodType.CurrentEcologicalIndicators.GrassBasalArea     = GrassBasalArea.StartingValue;
                LinkedNativeFoodType.CurrentEcologicalIndicators.StockingRate       = StartingStockingRate;
                StockingRateSummed = StartingStockingRate;

                //Now we have a stocking rate and we have starting values for Land Condition and Grass Basal Area
                //get the starting pasture data list from Pasture reader
                if (FilePasture != null)
                {
                    GetPastureDataList_TodayToNextEcolCalculation();
                    SetupStartingPasturePools(StartingAmount);
                }
            }
        }
        private void OnCLEMInitialiseResource(object sender, EventArgs e)
        {
            // activity is performed in CLEMUpdatePasture not CLEMGetResources and has no labour
            this.AllocationStyle = ResourceAllocationStyle.Manual;

            // locate Land Type resource for this forage.
            LinkedLandItem     = Resources.GetResourceItem(this, LandTypeNameToUse, OnMissingResourceActionTypes.ReportErrorAndStop, OnMissingResourceActionTypes.ReportErrorAndStop) as LandType;
            LandConditionIndex = FindAllDescendants <RelationshipRunningValue>().Where(a => (new string[] { "lc", "landcondition", "landcon", "landconditionindex" }).Contains(a.Name.ToLower())).FirstOrDefault() as RelationshipRunningValue;
            GrassBasalArea     = FindAllDescendants <RelationshipRunningValue>().Where(a => (new string[] { "gba", "basalarea", "grassbasalarea" }).Contains(a.Name.ToLower())).FirstOrDefault() as RelationshipRunningValue;
            FilePasture        = ZoneCLEM.Parent.FindAllDescendants().Where(a => a.Name == PastureDataReader).FirstOrDefault() as IFilePasture;

            if (FilePasture != null)
            {
                // check that database has region id and land id
                ZoneCLEM clem = FindAncestor <ZoneCLEM>();
                int      recs = FilePasture.RecordsFound((FilePasture as FileSQLitePasture).RegionColumnName, clem.ClimateRegion);
                if (recs == 0)
                {
                    throw new ApsimXException(this, $"No pasture production records were located by [x={(FilePasture as Model).Name}] for [a={this.Name}] given [Region id] = [{clem.ClimateRegion}] as specified in [{clem.Name}]");
                }
                LandType land = Resources.GetResourceItem(this, LandTypeNameToUse, OnMissingResourceActionTypes.ReportErrorAndStop, OnMissingResourceActionTypes.ReportErrorAndStop) as LandType;
                if (land != null)
                {
                    recs = FilePasture.RecordsFound((FilePasture as FileSQLitePasture).LandIdColumnName, land.SoilType);
                    if (recs == 0)
                    {
                        throw new ApsimXException(this, $"No pasture production records were located by [x={(FilePasture as Model).Name}] for [a={this.Name}] given [Land id] = [{land.SoilType}] as specified in [{land.Name}] used to manage the pasture");
                    }
                }
            }

            if (UseAreaAvailable)
            {
                LinkedLandItem.TransactionOccurred += LinkedLandItem_TransactionOccurred;
            }

            ResourceRequestList = new List <ResourceRequest>
            {
                new ResourceRequest()
                {
                    AllowTransmutation = false,
                    Required           = UseAreaAvailable ? LinkedLandItem.AreaAvailable : AreaRequested,
                    ResourceType       = typeof(Land),
                    ResourceTypeName   = LandTypeNameToUse.Split('.').Last(),
                    ActivityModel      = this,
                    Category           = UseAreaAvailable ?"Assign unallocated":"Assign",
                    FilterDetails      = null
                }
            };

            CheckResources(ResourceRequestList, Guid.NewGuid());
            gotLandRequested = TakeResources(ResourceRequestList, false);

            //Now the Land has been allocated we have an Area
            if (gotLandRequested)
            {
                //get the units of area for this run from the Land resource parent.
                unitsOfArea2Ha = Resources.Land().UnitsOfAreaToHaConversion;

                // locate Pasture Type resource
                LinkedNativeFoodType = Resources.GetResourceItem(this, FeedTypeName, OnMissingResourceActionTypes.ReportErrorAndStop, OnMissingResourceActionTypes.ReportErrorAndStop) as GrazeFoodStoreType;

                //Assign the area actually got after taking it. It might be less than AreaRequested (if partial)
                Area = ResourceRequestList.FirstOrDefault().Provided;

                // ensure no other activity has set the area of this GrazeFoodStore
                LinkedNativeFoodType.Manager = this as IPastureManager;

                soilIndex = ((LandType)ResourceRequestList.FirstOrDefault().Resource).SoilType;

                if (!(LandConditionIndex is null))
                {
                    LinkedNativeFoodType.CurrentEcologicalIndicators.LandConditionIndex = LandConditionIndex.StartingValue;
                }
                if (!(GrassBasalArea is null))
                {
                    LinkedNativeFoodType.CurrentEcologicalIndicators.GrassBasalArea = GrassBasalArea.StartingValue;
                }
                LinkedNativeFoodType.CurrentEcologicalIndicators.StockingRate = StartingStockingRate;
                StockingRateSummed = StartingStockingRate;

                //Now we have a stocking rate and we have starting values for Land Condition and Grass Basal Area
                //get the starting pasture data list from Pasture reader
                if (FilePasture != null)
                {
                    GetPastureDataList_TodayToNextEcolCalculation();
                    SetupStartingPasturePools(StartingAmount);
                }
            }
        }