Exemplo n.º 1
0
 public void Initialize(IProject project)
 {
     if (project != null)
     {
         mGrid    = project.Model.Grid as MFGrid;
         _Prms    = (project.Model as HeiflowModel).PRMSModel;
         _Modflow = (project.Model as HeiflowModel).ModflowModel;
     }
 }
Exemplo n.º 2
0
        public HeiflowModel()
        {
            Name           = "HEIFLOW";
            Description    = "HEIFLOW model version 1.0.0";
            this.Icon      = Resources.RasterImageAnalysisPanSharpen16;
            this.LargeIcon = Resources.RasterImageAnalysisPanSharpen32;
            _IsDirty       = false;

            _MasterPackage             = new MasterPackage(MasterPackageName);
            _MasterPackage.Owner       = this;
            _ExtensionManPackage       = new ExtensionManPackage();
            _ExtensionManPackage.Owner = this;

            _PRMS       = new PRMS();
            _PRMS.Owner = this;
            Children.Add(_PRMS.Name, _PRMS);

            _Modflow       = new Modflow();
            _Modflow.Owner = this;
            Children.Add(_Modflow.Name, _Modflow);
        }
        public override bool Execute(ICancelProgressHandler cancelProgressHandler)
        {
            var     shell    = MyAppManager.Instance.CompositionContainer.GetExportedValue <IShellService>();
            var     prj      = MyAppManager.Instance.CompositionContainer.GetExportedValue <IProjectService>();
            var     model    = prj.Project.Model;
            int     progress = 0;
            int     count    = 1;
            double  sumOfDis = 0;
            double  sumOfVa  = 0;
            Modflow mf       = null;

            if (model is HeiflowModel)
            {
                mf = (model as HeiflowModel).ModflowModel;
            }
            else if (model is Modflow)
            {
                mf = model as Modflow;
            }
            if (mf != null)
            {
                var pck         = mf.GetPackage(DISPackage.PackageName) as DISPackage;
                int npt         = _boreholefs.Features.Count;
                int nlayer      = mf.Grid.ActualLayerCount;
                var known_sites = new Site[npt];
                var ncell       = _grid_layer.DataTable.Rows.Count;
                var height_dc   = new DataCube <float>(pck.Grid.ActualLayerCount, 1, ncell);
                InverseDistanceWeighting idw = new InverseDistanceWeighting();
                string msg = "";
                for (int i = 0; i < npt; i++)
                {
                    var cor = _boreholefs.Features[i].Geometry.Coordinate;
                    known_sites[i] = new Site()
                    {
                        LocalX = cor.X,
                        LocalY = cor.Y,
                        ID     = i,
                        Values = new double[nlayer]
                    };
                    for (int j = 0; j < nlayer; j++)
                    {
                        var colname = LayerPrefix + (j + 1).ToString();
                        if (_boreholefs.DataTable.Columns.Contains(colname))
                        {
                            known_sites[i].Values[j] = float.Parse(_boreholefs.Features[i].DataRow[colname].ToString());
                        }
                        else
                        {
                            known_sites[i].Values[j] = DefaultLayerHeight;
                        }
                        if (known_sites[i].Values[j] < 0)
                        {
                            known_sites[i].Values[j] = DefaultLayerHeight;
                            msg += string.Format(" Warning: layer height at Point {0} is negative.", i + 1);
                        }
                    }
                }
                if (Neighbors > npt || Neighbors < 0)
                {
                    Neighbors = npt;
                }

                for (int i = 0; i < ncell; i++)
                {
                    for (int j = 0; j < nlayer; j++)
                    {
                        var cor        = _grid_layer.Features[i].Geometry.Coordinate;
                        var site_intep = new Site()
                        {
                            LocalX = cor.X,
                            LocalY = cor.Y,
                            ID     = i
                        };
                        var neighborSites = idw.FindNeareastSites(Neighbors, known_sites, site_intep);
                        sumOfDis = 0;
                        sumOfVa  = 0;
                        foreach (var nsite in neighborSites)
                        {
                            var    vv   = nsite.Values[j];
                            double temp = 1 / System.Math.Pow(nsite.Distance, Power);
                            sumOfVa  += vv * temp;
                            sumOfDis += temp;
                        }
                        if (sumOfDis != 0)
                        {
                            height_dc[j, 0, i] = (float)(sumOfVa / sumOfDis);
                        }
                        else
                        {
                            height_dc[j, 0, i] = DefaultLayerHeight;
                        }
                    }
                    progress = i * 100 / ncell;
                    if (progress > count)
                    {
                        cancelProgressHandler.Progress("Package_Tool", progress, "Processing cell: " + (i + 1));
                        count++;
                    }
                }

                for (int i = 0; i < ncell; i++)
                {
                    for (int j = 0; j < nlayer; j++)
                    {
                        pck.Elevation[j + 1, 0, i] = pck.Elevation[j, 0, i] - height_dc[j, 0, i];
                    }
                }

                pck.IsDirty = true;
                //pck.Save(null);
                // pck.ChangeState(Models.Generic.ModelObjectState.Ready);
                return(true);
            }
            else
            {
                cancelProgressHandler.Progress("Package_Tool", 100, "Error message: Modflow is used by this tool.");
                return(false);
            }
        }
Exemplo n.º 4
0
        public override bool Execute(ICancelProgressHandler cancelProgressHandler)
        {
            var     shell    = MyAppManager.Instance.CompositionContainer.GetExportedValue <IShellService>();
            var     prj      = MyAppManager.Instance.CompositionContainer.GetExportedValue <IProjectService>();
            var     model    = prj.Project.Model;
            int     progress = 0;
            int     count    = 1;
            Modflow mf       = null;

            if (model is HeiflowModel)
            {
                mf = (model as HeiflowModel).ModflowModel;
            }
            else if (model is Modflow)
            {
                mf = model as Modflow;
            }
            if (mf != null)
            {
                if (!mf.Packages.ContainsKey(FHBPackage.PackageName))
                {
                    var fhb = mf.Select(FHBPackage.PackageName);
                    mf.Add(fhb);
                }
                var pck = mf.GetPackage(FHBPackage.PackageName) as FHBPackage;
                pck.NBDTIM = 2;
                pck.NHED   = 0;
                pck.IFHBSS = 1;
                pck.BDTIM  = new int[] { 0, prj.Project.Model.TimeService.NumTimeStep };
                List <FlowBound> list = new List <FlowBound>();
                int npt = _sourcefs.Features.Count;
                for (int i = 0; i < npt; i++)
                {
                    var   pt    = _sourcefs.Features[i].Geometry.Coordinate;
                    int   layer = 1;
                    float rate  = 0;
                    if (!string.IsNullOrEmpty(LayerField))
                    {
                        int.TryParse(_sourcefs.DataTable.Rows[i][LayerField].ToString(), out layer);
                    }
                    if (!string.IsNullOrEmpty(FluxRateField))
                    {
                        float.TryParse(_sourcefs.DataTable.Rows[i][FluxRateField].ToString(), out rate);
                    }
                    for (int j = 0; j < _grid_layer.Features.Count; j++)
                    {
                        var cell = _grid_layer.Features[j].Geometry.Coordinates;
                        if (SpatialRelationship.PointInPolygon(cell, pt))
                        {
                            FlowBound bound = new FlowBound()
                            {
                                Layer    = layer,
                                FlowRate = rate,
                                Row      = int.Parse(_grid_layer.DataTable.Rows[j]["ROW"].ToString()),
                                Col      = int.Parse(_grid_layer.DataTable.Rows[j]["COLUMN"].ToString()),
                            };
                            list.Add(bound);
                            break;
                        }
                    }
                    progress = i * 100 / npt;
                    if (progress > count)
                    {
                        cancelProgressHandler.Progress("Package_Tool", progress, "Processing point: " + i);
                        count++;
                    }
                }
                if (list.Count > 0)
                {
                    pck.NFLW = list.Count;
                    var FlowRate = new DataCube <float>(4 + pck.NBDTIM, 1, pck.NFLW)
                    {
                        Name           = "FHB_FlowRate",
                        TimeBrowsable  = false,
                        AllowTableEdit = true
                    };
                    FlowRate.Variables[0] = "Layer";//Layer Row Column IAUX  FLWRAT(NBDTIM)
                    FlowRate.Variables[1] = "Row";
                    FlowRate.Variables[2] = "Column";
                    FlowRate.Variables[3] = "IAUX";
                    for (int i = 0; i < pck.NBDTIM; i++)
                    {
                        FlowRate.Variables[4 + i] = "FLWRAT " + (i + 1);
                    }
                    for (int i = 0; i < pck.NFLW; i++)
                    {
                        var bound = list[i];
                        FlowRate[0, 0, i] = bound.Layer;
                        FlowRate[1, 0, i] = bound.Row;
                        FlowRate[2, 0, i] = bound.Col;
                        FlowRate[3, 0, i] = 0;
                        for (int j = 0; j < pck.NBDTIM; j++)
                        {
                            FlowRate[4 + j, 0, i] = bound.FlowRate;
                        }
                    }
                    FlowRate.TimeBrowsable = false;
                    pck.FlowRate           = FlowRate;
                    pck.CreateFeature(shell.MapAppManager.Map.Projection, prj.Project.GeoSpatialDirectory);
                    pck.BuildTopology();
                    pck.IsDirty = true;
                    pck.Save(null);
                    pck.ChangeState(Models.Generic.ModelObjectState.Ready);
                }
                else
                {
                    pck.ChangeState(Models.Generic.ModelObjectState.Standby);
                    cancelProgressHandler.Progress("Package_Tool", 100, "Warning: no points located in the modeling domain.");
                }
                return(true);
            }
            else
            {
                cancelProgressHandler.Progress("Package_Tool", 100, "Error message: Modflow is used by this tool.");
                return(false);
            }
        }