Example #1
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        ///
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            string filepath;

            //Domain omega;
            //FluidSolver ffd;
            //DataExtractor de;

            //double t;
            bool resetFFD = false;


            // current filepath
            filepath = Path.GetDirectoryName(this.OnPingDocument().FilePath);
            string residualstxt = filepath + @"\\residual.txt";


            // *********************************************************************************
            // Inputs
            // *********************************************************************************
            List <double> xyzsize = new List <double>();

            if (!DA.GetDataList(0, xyzsize))
            {
                return;
            }
            ;

            List <int> Nxyz = new List <int>();

            if (!DA.GetDataList(1, Nxyz))
            {
                return;
            }
            ;
            int Nx = Nxyz[0];
            int Ny = Nxyz[1];
            int Nz = Nxyz[2];


            List <double[]> geom = new List <double[]>();

            if (!DA.GetDataList(2, geom))
            {
                return;
            }
            ;

            for (int i = 0; i < geom.Count; i++)
            {
                double[] geo = geom[i];
                //Rhino.RhinoApp.WriteLine($"[{i}] {geo[0]}, {geo[1]}, {geo[2]}, {geo[3]}, {geo[4]}, {geo[5]}");
                if (i == 10)
                {
                    break;
                }
            }



            // time step
            double dt = 0.1;

            if (!DA.GetData(3, ref dt))
            {
                return;
            }

            // horizon
            double t_end = 1;

            if (!DA.GetData(4, ref t_end))
            {
                return;
            }

            // wind speed
            double Vmet = 10;

            if (!DA.GetData(5, ref Vmet))
            {
                return;
            }

            //terrain type
            int terrain = 0;

            if (!DA.GetData(6, ref terrain))
            {
                return;
            }


            bool run = false;

            if (!DA.GetData(7, ref run))
            {
                return;
            }



            //List<Mesh> mshCp = new List<Mesh>();
            //DA.GetDataList(10, mshCp);
            bool writeresults = false;

            DA.GetData(8, ref writeresults);

            bool writeVTK = false;

            DA.GetData(9, ref writeVTK);


            DA.GetData(10, ref resetFFD);


            bool calcres = false;

            DA.GetData(12, ref calcres);

            int m = 10;

            DA.GetData(13, ref m);

            string strparam = null;

            DA.GetData(11, ref strparam);

            string[] str_params = null;
            if (strparam != null)
            {
                str_params = strparam.Split(';');
            }


            bool addResiduals = true;

            DA.GetData(12, ref addResiduals);

            int meanDt = 10;

            DA.GetData(13, ref meanDt);

            bool stop = false;

            DA.GetData(14, ref stop);

            bool update = false;

            DA.GetData(15, ref update);


            if (stop)
            {
                ffdSolver.StopRun();
                //running[0] = false;
                //Rhino.RhinoApp.WriteLine("stoprun()");

                //computingTask.Dispose();
                //Rhino.RhinoApp.WriteLine("dispose()");
            }


            if ((skipSolution && run == false) || update)
            {
                skipSolution = false;
                DA.IncrementIteration();

                //DA.SetDataList(0, veloutCen);
                //DA.SetData(1, p);
                //DA.SetDataList(2, veloutStag);
                //DA.SetData(3, pstag);
                //DA.SetData(3, pstagResults);
                //DA.SetData(4, de);
                //DA.SetData(5, obstacle_cells);
                DA.SetData(6, ffdSolver);
                DA.SetData(7, ffdSolver.omega);
                DA.SetData(8, ffdSolver.ffd);
                //Rhino.RhinoApp.WriteLine("trying to update outputs");
                Grasshopper.Instances.RedrawAll();
            }
            else if (!componentBusy)
            {
                DA.DisableGapLogic();

                //if (resetFFD)
                //{
                //    ffdSolver.run = false;
                //    ffdSolver = new FFDSolver(
                //        this.OnPingDocument().FilePath,
                //        Nxyz,
                //        xyzsize,
                //        geom,
                //        t_end,
                //        Vmet,
                //        terrain,
                //        strparam
                //        );

                //}
                bool returnSomething()
                {
                    return(true);
                }

                Task <bool> computingTask = new Task <bool>(() => returnSomething());

                if (resetFFD)
                {
                    ffdSolver = new FFDSolver(
                        this.OnPingDocument().FilePath,
                        Nxyz,
                        xyzsize,
                        geom,
                        t_end,
                        dt,
                        meanDt,
                        Vmet,
                        terrain,
                        strparam
                        );
                }

                if (run)
                {
                    ffdSolver.run = false;
                    if (ffdSolver.dt == 0.0) //we know it's empty.
                    {
                        ffdSolver = new FFDSolver(
                            this.OnPingDocument().FilePath,
                            Nxyz,
                            xyzsize,
                            geom,
                            t_end,
                            dt,
                            meanDt,
                            Vmet,
                            terrain,
                            strparam
                            );
                    }


                    computingTask = new Task <bool>(() => ffdSolver.Run());
                }



                computingTask.ContinueWith(r =>
                {
                    if (r.Status == TaskStatus.RanToCompletion)
                    {
                        bool result = computingTask.Result;
                        if (result == true)
                        {
                            //Rhino.RhinoApp.WriteLine("outputting");
                            NickName     = "Task Finished!";
                            skipSolution = true;

                            //pstagResults = ffdSolver.pstag;



                            //p = ffdSolver.p;
                            //veloutCen = ffdSolver.veloutCen;
                            //veloutStag = ffdSolver.veloutStag;
                            //pstag = ffdSolver.pstag;
                            de             = ffdSolver.de;
                            obstacle_cells = ffdSolver.obstacle_cells;



                            ExpireSolution(false);
                            Grasshopper.Instances.ActiveCanvas.Document.NewSolution(false);
                        }
                        else
                        {
                            Rhino.RhinoApp.WriteLine("failed");
                            NickName = "Task Failed.";
                            Grasshopper.Instances.RedrawAll();
                        }
                        componentBusy = false;
                    }
                    else if (r.Status == TaskStatus.Faulted)
                    {
                        NickName = "Task Faulted.";
                        Grasshopper.Instances.RedrawAll();
                        componentBusy = false;
                    }
                },
                                           TaskScheduler.FromCurrentSynchronizationContext()


                                           );


                computingTask.Start();
                if (run)
                {
                    NickName = "Processing...";
                }
                Grasshopper.Instances.RedrawAll();
                componentBusy = true;

                //if (stop)
                //{
                //    ffdSolver.StopRun();

                //    Rhino.RhinoApp.WriteLine("stoprun()");

                //    computingTask.Dispose();
                //    Rhino.RhinoApp.WriteLine("dispose()");
                //}
            }
        }
Example #2
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            List <double> xyzsize = new List <double>();

            if (!DA.GetDataList(0, xyzsize))
            {
                return;
            }
            ;

            List <int> Nxyz = new List <int>();

            if (!DA.GetDataList(1, Nxyz))
            {
                return;
            }
            ;
            int Nx = Nxyz[0];
            int Ny = Nxyz[1];
            int Nz = Nxyz[2];



            List <double[]> geom = new List <double[]>();

            if (!DA.GetDataList(2, geom))
            {
                return;
            }
            ;


            // time step
            double dt = 0.1;

            if (!DA.GetData(3, ref dt))
            {
                return;
            }

            // horizon
            double t_end = 1;

            if (!DA.GetData(4, ref t_end))
            {
                return;
            }

            // wind speed
            double Vmet = 10;

            if (!DA.GetData(5, ref Vmet))
            {
                return;
            }

            //terrain type
            int terrain = 0;

            if (!DA.GetData(6, ref terrain))
            {
                return;
            }

            bool run = false;

            if (!DA.GetData(7, ref run))
            {
                return;
            }



            bool writeresults = false;

            DA.GetData(8, ref writeresults);

            bool writeVTK = false;

            DA.GetData(9, ref writeVTK);


            //DA.GetData(10, ref resetFFD);


            bool calcres = false;

            DA.GetData(12, ref calcres);

            int m = 10;

            DA.GetData(13, ref m);

            string strparam = null;

            DA.GetData(11, ref strparam);

            string[] str_params = null;
            if (strparam != null)
            {
                str_params = strparam.Split(';');
            }


            bool addResiduals = true;

            DA.GetData(12, ref addResiduals);

            int meanDt = 10;

            DA.GetData(13, ref meanDt);



            if (run)
            {
                ffdSolver.run = false;

                ffdSolver = new FFDSolver(
                    this.OnPingDocument().FilePath,
                    Nxyz,
                    xyzsize,
                    geom,
                    t_end,
                    dt,
                    meanDt,
                    Vmet,
                    terrain,
                    strparam
                    );



                ffdSolver.Run();
            }

            DA.SetData(6, ffdSolver);

            Rhino.RhinoApp.WriteLine($"so far xx");

            GH_Structure <GH_Number> outNumbers = new GH_Structure <GH_Number>();

            Rhino.RhinoApp.WriteLine($"veloutstag count {ffdSolver.veloutStag.Count}");



            for (int j = 0; j < ffdSolver.veloutStag[0].GetLength(0); j++)
            {
                //Rhino.RhinoApp.WriteLine($"outputting numbers from {j}");


                for (int k = 0; k < ffdSolver.veloutStag[0].GetLength(1); k++)
                {
                    double velocity = Math.Sqrt(ffdSolver.veloutStag[0][j, k, 1] * ffdSolver.veloutStag[0][j, k, 1] + ffdSolver.veloutStag[1][j, k, 1] * ffdSolver.veloutStag[1][j, k, 1] + ffdSolver.veloutStag[2][j, k, 1] * ffdSolver.veloutStag[2][j, k, 1]);

                    outNumbers.Append(new GH_Number(velocity), new GH_Path(j, k));
                }
            }


            DA.SetDataList(0, ffdSolver.veloutCen);
            DA.SetData(1, ffdSolver.p);
            DA.SetDataList(2, ffdSolver.veloutStag);
            DA.SetData(3, ffdSolver.pstag);
            DA.SetData(4, ffdSolver.de);

            DA.SetData(5, ffdSolver.omega.obstacle_cells);



            DA.SetDataTree(9, outNumbers);
        }