internal InternalBoundaryProp(PFSSection Section)
        {
            _pfsHandle = Section;

              for (int i = 1; i <= Section.GetSectionsNo(); i++)
              {
            PFSSection sub = Section.GetSection(i);
            switch (sub.Name)
            {
            case "TIME_SERIES_FILE":
              _tIME_SERIES_FILE = new DFS_2D_DATA_FILE(sub);
              break;
            case "DFS_2D_DATA_FILE":
              _dFS_2D_DATA_FILE = new DFS_2D_DATA_FILE(sub);
              break;
            case "LeakCoef":
              _leakCoef = new Topography(sub);
              break;
            case "Conductance":
              _conductance = new Topography(sub);
              break;
            case "RiverBottomElevation":
              _riverBottomElevation = new Bathymetry(sub);
              break;
              default:
            _unMappedSections.Add(sub.Name);
              break;
            }
              }
        }
 public BottomProfile(int numberOfPointsInTransect, GeoSegment geoSegment , Bathymetry bathymetry)
 {
     MaxDepth = double.MinValue;
     Profile = new List<BottomProfilePoint>();
     Length = Geo.RadiansToMeters(geoSegment.LengthRadians);
     //Length = transect.StartPoint.DistanceKilometers(transect.EndPoint) * 1000;
     var stepLength = Length / (numberOfPointsInTransect - 1);
     var stepFraction = 1.0 / numberOfPointsInTransect;
     //var currentPoint = transect.StartPoint;
     var currentPoint = geoSegment[0];
     var curRange = 0.0;
     for (var i = 0; i < numberOfPointsInTransect; i++)
     {
         var curDepth = Math.Round(-1.0 * TwoDBilinearApproximation(bathymetry, currentPoint), 2);
         Profile.Add(new BottomProfilePoint { Depth = curDepth, Range = (curRange / 1000.0) });
         if (MaxDepth < curDepth)
         {
             MaxDepth = curDepth;
             DeepestPoint = currentPoint;
         }
         currentPoint = geoSegment.Slerp(stepFraction * i);
         //currentPoint = currentPoint.Offset(Geo.KilometersToRadians(stepLength / 1000f), Geo.DegreesToRadians(transect.Bearing));
         curRange += stepLength;
     }
     //Profile = profile.ToList();
 }
예제 #3
0
        internal Drainage(PFSSection Section)
        {
            _pfsHandle = Section;

              for (int i = 1; i <= Section.GetSectionsNo(); i++)
              {
            PFSSection sub = Section.GetSection(i);
            switch (sub.Name)
            {
            case "Level":
              _level = new Bathymetry(sub);
              break;
            case "TimeConstant":
              _timeConstant = new Topography(sub);
              break;
            case "DrainCode":
              _drainCode = new Topography(sub);
              break;
            case "DistributedOptionCode":
              _distributedOptionCode = new Topography(sub);
              break;
              default:
            _unMappedSections.Add(sub.Name);
              break;
            }
              }
        }
 public void StaticDensitySeed()
 {
     var geoRect = new GeoRect(1, -1, 1, -1);
     var bathymetry = new Bathymetry();
     bathymetry.Samples.Add(new Geo<float>(geoRect.Center.Latitude,geoRect.Center.Longitude,100));
     var list = Animat.Seed(new ScenarioSpecies{LatinName = "Orca orca", PopulationDensity = .2f}, geoRect,bathymetry);
     foreach (var animatLocation in list.Locations)
     {
         Assert.IsTrue(geoRect.Contains(animatLocation));
         Assert.IsTrue(animatLocation.Data < 100 && animatLocation.Data > 0);
     }
 }
        public static Animat Seed(ScenarioSpecies species, GeoRect geoRect, Bathymetry bathymetry)
        {
            var bounds = new GeoArray(geoRect.NorthWest, geoRect.NorthEast, geoRect.SouthEast, geoRect.SouthWest, geoRect.NorthWest);
            var result = new Animat { ScenarioSpecies = species };

            var area = bounds.Area;
            //Debug.WriteLine("Area: {0}",area);
            var population = (int)Math.Floor(area * species.PopulationDensity);
            for (var i = 0; i < population; i++)
            {
                var location = bounds.RandomLocationWithinPerimeter();
                var depth = bathymetry.Samples.GetNearestPoint(location).Data;
                if (depth < 0) result.Locations.Add(new Geo<float>(location.Latitude, location.Longitude, (float)(depth * Random.NextDouble())));
            }
            result.TotalAnimats = population;
            return result;
        }
예제 #6
0
        internal Layer_2(PFSSection Section)
        {
            _pfsHandle = Section;

              for (int i = 1; i <= Section.GetSectionsNo(); i++)
              {
            PFSSection sub = Section.GetSection(i);
            switch (sub.Name)
            {
            case "LowerLevel":
              _lowerLevel = new Bathymetry(sub);
              break;
            case "InitPotHead":
              _initPotHead = new Bathymetry(sub);
              break;
            case "InitialSoilTemperature":
              _initialSoilTemperature = new Bathymetry(sub);
              break;
            case "OuterBoundary":
              _outerBoundary = new OuterBoundary(sub);
              break;
            case "HydrHeadUsedForAirFlow":
              _hydrHeadUsedForAirFlow = new Topography(sub);
              break;
            case "WettingThreshold":
              _wettingThreshold = new Topography(sub);
              break;
            case "InternalBoundary":
              _internalBoundary = new InternalBoundary1(sub);
              break;
            case "Initial_Concentration":
              _initial_Concentration = new InitialMass(sub);
              break;
            case "Initial_Immobile_Concentration":
              _initial_Immobile_Concentration = new InitialMass(sub);
              break;
              default:
            _unMappedSections.Add(sub.Name);
              break;
            }
              }
        }
예제 #7
0
        internal River(PFSSection Section)
        {
            _pfsHandle = Section;

              for (int i = 1; i <= Section.GetSectionsNo(); i++)
              {
            PFSSection sub = Section.GetSection(i);
            switch (sub.Name)
            {
            case "FloodCodes":
              _floodCodes = new Topography(sub);
              break;
            case "Bathymetry":
              _bathymetry = new Bathymetry(sub);
              break;
              default:
            _unMappedSections.Add(sub.Name);
              break;
            }
              }
        }
        internal UZGroundWaterDepthList(PFSSection Section)
        {
            _pfsHandle = Section;

              for (int i = 1; i <= Section.GetSectionsNo(); i++)
              {
            PFSSection sub = Section.GetSection(i);
            switch (sub.Name)
            {
            case "UZGroundWaterTable":
              _uZGroundWaterTable = new Bathymetry(sub);
              break;
            case "UZGroundWaterDepth1":
              _uZGroundWaterDepth1 = new UZGroundWaterDepth1(sub);
              break;
              default:
            _unMappedSections.Add(sub.Name);
              break;
            }
              }
        }
 public async static Task<Animat> SeedAsyncWithout3MB(ScenarioSpecies species, GeoRect geoRect, Bathymetry bathymetry)
 {
     var bounds = new GeoArray(geoRect.NorthWest, geoRect.NorthEast, geoRect.SouthEast, geoRect.SouthWest, geoRect.NorthWest);
     var result = new Animat { ScenarioSpecies = species };
     
     var area = bounds.Area;
     //Debug.WriteLine("Area: {0}",area);
     var transformManyBlock = new TransformManyBlock<int, Geo<float>>(count =>
     {
         var geos = new List<Geo<float>>();
         for (var i = 0; i < count; i++)
         {
             var location = bounds.RandomLocationWithinPerimeter();
             var depth = bathymetry.Samples.GetNearestPointAsync(location).Result.Data;
             if (depth < -50) geos.Add(new Geo<float>(location.Latitude, location.Longitude, (float)(depth * Random.NextDouble())));
         }
         return geos;
     }, new ExecutionDataflowBlockOptions
     {
         TaskScheduler = TaskScheduler.Default,
         BoundedCapacity = -1,
         MaxDegreeOfParallelism = -1,
     });
     var bufferBlock = new BufferBlock<Geo<float>>();
     transformManyBlock.LinkTo(bufferBlock);
     var population = (int)Math.Round(area * species.PopulationDensity);
     result.TotalAnimats = population;
     const int blockSize = 100;
     while (population > 0)
     {
         transformManyBlock.Post(population > blockSize ? blockSize : population);
         population -= blockSize;
     }
     transformManyBlock.Complete();
     await transformManyBlock.Completion;
     IList<Geo<float>> animatGeos;
     if (bufferBlock.TryReceiveAll(out animatGeos))
         result.Locations.AddRange(animatGeos);
     return result;
 }
예제 #10
0
        internal Lense_1(PFSSection Section)
        {
            _pfsHandle = Section;

              for (int i = 1; i <= Section.GetSectionsNo(); i++)
              {
            PFSSection sub = Section.GetSection(i);
            switch (sub.Name)
            {
            case "HorBoundary":
              _horBoundary = new Topography(sub);
              break;
            case "UpperLevel":
              _upperLevel = new Bathymetry(sub);
              break;
            case "LowerLevel":
              _lowerLevel = new Bathymetry(sub);
              break;
            case "GeoUnit":
              _geoUnit = new Topography(sub);
              break;
            case "HorHydrCon":
              _horHydrCon = new Topography(sub);
              break;
            case "VerHydrCon":
              _verHydrCon = new Topography(sub);
              break;
            case "SpecificYield":
              _specificYield = new Topography(sub);
              break;
            case "StorageCoef":
              _storageCoef = new Topography(sub);
              break;
            case "HydrHeadUsedForAirFlow":
              _hydrHeadUsedForAirFlow = new Topography(sub);
              break;
            case "WettingThreshold":
              _wettingThreshold = new Topography(sub);
              break;
            case "HorizontalAnisotropyRatio":
              _horizontalAnisotropyRatio = new Topography(sub);
              break;
            case "VanGenuchtenAlpha":
              _vanGenuchtenAlpha = new Topography(sub);
              break;
            case "VanGenuchtenBeta":
              _vanGenuchtenBeta = new Topography(sub);
              break;
            case "ResidualSaturation":
              _residualSaturation = new Topography(sub);
              break;
            case "BrooksCoreyRelativePermeabilityExponent":
              _brooksCoreyRelativePermeabilityExponent = new Topography(sub);
              break;
            case "Porosity":
              _porosity = new Topography(sub);
              break;
            case "MatrixPorosity":
              _matrixPorosity = new Topography(sub);
              break;
            case "BulkDensity":
              _bulkDensity = new Topography(sub);
              break;
            case "LHHDispCoeff":
              _lHHDispCoeff = new Topography(sub);
              break;
            case "THHDispCoeff":
              _tHHDispCoeff = new Topography(sub);
              break;
            case "TVHDispCoeff":
              _tVHDispCoeff = new Topography(sub);
              break;
            case "LVVDispCoeff":
              _lVVDispCoeff = new Topography(sub);
              break;
            case "THVDispCoeff":
              _tHVDispCoeff = new Topography(sub);
              break;
              default:
            _unMappedSections.Add(sub.Name);
              break;
            }
              }
        }
        public static double TwoDBilinearApproximation(Bathymetry bathymetry, Geo pt)
        {
            var bounds = GeoRect.Inflate(bathymetry.Samples.GeoRect, 0.01);
            if (!bounds.Contains(pt)) 
                throw new BathymetryOutOfBoundsException("TwoDBilinearApproximation: XCoord and YCoord must be within the provided data set.  This is an interpolation routine not an extrapolation one.");
            var lat = pt.Latitude;
            var lon = pt.Longitude;
            for (var i = 0; i < bathymetry.Samples.Latitudes.Count - 1; i++)
            {
                // elevations.Latitudes go from south to north, so a southern elevations.Latitudes come before northern ones
                if ((bathymetry.Samples.Latitudes[i] > lat) || (lat > bathymetry.Samples.Latitudes[i + 1])) continue;
                for (var j = 0; j < bathymetry.Samples.Longitudes.Count - 1; j++)
                {
                    // elevations.Longitudes go from west to east, so western elevations.Longitudes come before eastern ones
                    if ((bathymetry.Samples.Longitudes[j] > lon) || (lon > bathymetry.Samples.Longitudes[j + 1])) continue;
                    var north = i + 1;
                    var south = i;
                    var east = j + 1;
                    var west = j;
                    var northEast = bathymetry.Samples[(uint)east, (uint)north];
                    var northWest = bathymetry.Samples[(uint)west, (uint)north];
                    var southEast = bathymetry.Samples[(uint)east, (uint)south];
                    var southWest = bathymetry.Samples[(uint)west, (uint)south];

                    return BilinearRecursive(pt, // Point to interpolate
                        northEast, northWest, southEast, southWest);
                } // for j
            } // for i
            throw new BathymetryOutOfBoundsException("TwoDBilinearApproximation: Desired point does not appear to be in data set.  This message should never appear!");
        }
예제 #12
0
        internal MIKESHE_FLOWMODEL(PFSSection Section)
        {
            _pfsHandle = Section;

              for (int i = 1; i <= Section.GetSectionsNo(); i++)
              {
            PFSSection sub = Section.GetSection(i);
            switch (sub.Name)
            {
            case "FlowModelDocVersion":
              _flowModelDocVersion = new FlowModelDocVersion(sub);
              break;
            case "ViewSettings":
              _viewSettings = new ViewSettings(sub);
              break;
            case "Overlays":
              _overlays = new Overlays(sub);
              break;
            case "SimSpec":
              _simSpec = new SimSpec(sub);
              break;
            case "ModelCompWQ":
              _modelCompWQ = new ModelCompWQ(sub);
              break;
            case "Species":
              _species = new Species(sub);
              break;
            case "Processes":
              _processes = new Processes(sub);
              break;
            case "Catchment":
              _catchment = new Catchment(sub);
              break;
            case "Subcatchments":
              _subcatchments = new Subcatchments(sub);
              break;
            case "Topography":
              _topography = new Topography(sub);
              break;
            case "Climate":
              _climate = new Climate(sub);
              break;
            case "LandUse":
              _landUse = new LandUse(sub);
              break;
            case "River":
              _river = new River(sub);
              break;
            case "RiverMF":
              _riverMF = new RiverMF(sub);
              break;
            case "Overland":
              _overland = new Overland(sub);
              break;
            case "OverlandSubcatchment":
              _overlandSubcatchment = new Subcatchments(sub);
              break;
            case "Unsatzone":
              _unsatzone = new Unsatzone(sub);
              break;
            case "SaturatedZone":
              _saturatedZone = new SaturatedZone(sub);
              break;
            case "SaturatedZoneSubCatchment":
              _saturatedZoneSubCatchment = new SaturatedZoneSubCatchment(sub);
              break;
            case "GroundwaterTable":
              _groundwaterTable = new Bathymetry(sub);
              break;
            case "Sources":
              _sources = new Sources1(sub);
              break;
            case "StoringOfResults":
              _storingOfResults = new StoringOfResults(sub);
              break;
            case "OutputModflow":
              _outputModflow = new OutputModflow(sub);
              break;
            case "ExtraParams":
              _extraParams = new ExtraParams(sub);
              break;
            case "ExecuteEngineFlagsPfs":
              _executeEngineFlagsPfs = new ExecuteEngineFlagsPfs(sub);
              break;
            case "Result":
              _result = new Result(sub);
              break;
            case "Overview":
              _overview = new STRESSPERIOD_PROPPAGE(sub);
              break;
            case "GeoScene3D":
              _geoScene3D = new GeoScene3D(sub);
              break;
              default:
            _unMappedSections.Add(sub.Name);
              break;
            }
              }
        }
예제 #13
0
        public async static Task<Animat> SeedAsync(ScenarioSpecies species, GeoRect geoRect, Bathymetry bathymetry)
        {
            var yxzFileName = Path.Combine(Path.GetTempPath(), Path.GetFileNameWithoutExtension(Path.GetRandomFileName()) + ".txt");
            bathymetry.ToYXZ(yxzFileName, -1);
            var mbs = new C3mbs();
            mbsRESULT mbsResult;
            if (mbsRESULT.OK != (mbsResult = mbs.SetOutputDirectory(Path.GetTempPath())))
                throw new AnimatInterfaceMMBSException("SetOutputDirectory Error:" + mbs.ResultToTc(mbsResult));
            var config = mbs.GetConfiguration();
            config.enabled = false;             // binary output enabled/disabled
            config.durationLess = true;         // make sure we're in durationless mode.
            mbs.SetConfiguration(config);
            mbsResult = mbs.LoadBathymetryFromTextFile(yxzFileName);
            if (mbsRESULT.OK != mbsResult) throw new AnimatInterfaceMMBSException("Bathymetry failed to load: " + mbs.ResultToTc(mbsResult));
            mbsResult = mbs.AddSpecies(species.SpeciesDefinitionFilePath);
            if (mbsRESULT.OK != mbsResult) throw new AnimatInterfaceMMBSException(string.Format("C3mbs::AddSpecies FATAL error {0} for species {1}", mbs.ResultToTc(mbsResult), species.SpeciesDefinitionFilePath));

            var bounds = new GeoArray(geoRect.NorthWest, geoRect.NorthEast, geoRect.SouthEast, geoRect.SouthWest, geoRect.NorthWest);
            var result = new Animat { ScenarioSpecies = species };
            
            var area = bounds.Area;
            //Debug.WriteLine("Area: {0}",area);
            var transformManyBlock = new TransformManyBlock<int, Geo<float>>(count =>
            {
                var geos = new List<Geo<float>>();
                for (var i = 0; i < count; i++)
                {
                    var location = bounds.RandomLocationWithinPerimeter();
                    var depth = bathymetry.Samples.GetNearestPointAsync(location).Result.Data;
                    mbsRESULT retval;
                    lock (mbs) retval = mbs.AddIndividualAnimat(0, new mbsPosition { latitude = location.Latitude, longitude = location.Longitude, depth = 0 });
                    if (mbsRESULT.OK == retval) geos.Add(new Geo<float>(location.Latitude, location.Longitude, (float)(depth * Random.NextDouble())));
                }
                return geos;
            }, new ExecutionDataflowBlockOptions
            {
                TaskScheduler = TaskScheduler.Default,
                BoundedCapacity = -1,
                MaxDegreeOfParallelism = -1,
            });
            var bufferBlock = new BufferBlock<Geo<float>>();
            transformManyBlock.LinkTo(bufferBlock);
            var population = (int)Math.Round(area * species.PopulationDensity);
            result.TotalAnimats = population;
            const int blockSize = 100;
            while (population > 0)
            {
                transformManyBlock.Post(population > blockSize ? blockSize : population);
                population -= blockSize;
            }
            transformManyBlock.Complete();
            await transformManyBlock.Completion;
            //mbsResult = mbs.InitializeRun();
            //if (mbsRESULT.OK == mbsResult) while (mbsRUNSTATE.INITIALIZING == mbs.GetRunState()) Thread.Sleep(1);
            //else throw new AnimatInterfaceMMBSException("C3mbs::Initialize FATAL error " + mbs.ResultToTc(mbsResult));
            mbsResult = mbs.FinishRun();
            if (mbsRESULT.OK != mbsResult) throw new AnimatInterfaceMMBSException("C3mbs::FinishRun FATAL error " + mbs.ResultToTc(mbsResult));

            IList<Geo<float>> animatGeos;
            if (bufferBlock.TryReceiveAll(out animatGeos))
                result.Locations.AddRange(animatGeos);
            return result;
        }