예제 #1
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            var tuple1 = new List <double>();
            var tuple2 = new List <double>();

            if (!DA.GetDataList(0, tuple1))
            {
                return;
            }
            if (!DA.GetDataList(1, tuple2))
            {
                return;
            }

            var tuple = ITuple.CartesianProduct(tuple1, tuple2);

            DA.SetDataList(0, tuple);
        }
예제 #2
0
파일: Comp_Reader.cs 프로젝트: viccharp/Ivy
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            var path_wd = "";

            if (!DA.GetData(0, ref path_wd))
            {
                return;
            }

            Grid grid_act;
            Grid grid_shp;
            Grid grid_glb;

            int[][] topo_shell_face;
            int[]   topo_shell_node;
            int     n_glb, n_act, n_shp, n_shell;

            double[][,] Fields;


            // OPEN DB FILE
            string workingDir = Path.GetDirectoryName(path_wd.ToString());
            string dbName     = "data.db";
            string dbPath     = workingDir + "\\" + dbName;

            using (var connection = new SQLiteConnection("Data Source = " + dbPath))
            {
                connection.Open();
                using (var cmd = new SQLiteCommand(connection))
                {
                    grid_act        = SqlReadGrid("GRID_ACT", cmd);
                    grid_shp        = SqlReadGrid("GRID_SHP", cmd);
                    grid_glb        = SqlReadGrid("GRID_GLB", cmd);
                    topo_shell_face = SqlReadTopoShellFace("TOPO_SHELL_FACE", cmd);
                    topo_shell_node = SqlReadTopoShellNode("TOPO_SHELL_NODE", cmd);

                    n_glb   = grid_glb.NodeCount;
                    n_act   = grid_act.NodeCount;
                    n_shp   = grid_shp.NodeCount;
                    n_shell = topo_shell_node.Length;

                    // déclaration des champs vectoriels
                    // un champ vertcoriel par noeud parametric global
                    Fields = new double[n_shell][, ];

                    // ALLOCATION
                    for (int i = 0; i < n_shell; i++)
                    {
                        // X,Y,Z,DX,DY,DZ for each global parametric node
                        Fields[i] = new double[n_glb, 6];
                    }

                    cmd.CommandText = "select * from FIELD";
                    using (var reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            var nodeActIndex = reader.GetInt32(0) - 1;
                            var nodeShpIndex = reader.GetInt32(1) - 1;

                            var tuple_act = grid_act.Nodes[nodeActIndex].Tuple.Value;
                            var tuple_shp = grid_shp.Nodes[nodeShpIndex].Tuple.Value;
                            var tuple_glb = ITuple.CartesianProduct(tuple_act, tuple_shp);


                            var nodeGlbIndex = grid_glb.NodeIndex(tuple_glb);

                            var nodeShell = reader.GetInt32(2) - 1;

                            Fields[nodeShell][nodeGlbIndex, 0] = reader.GetDouble(3);
                            Fields[nodeShell][nodeGlbIndex, 1] = reader.GetDouble(4);
                            Fields[nodeShell][nodeGlbIndex, 2] = reader.GetDouble(5);

                            Fields[nodeShell][nodeGlbIndex, 3] = reader.GetDouble(6);
                            Fields[nodeShell][nodeGlbIndex, 4] = reader.GetDouble(7);
                            Fields[nodeShell][nodeGlbIndex, 5] = reader.GetDouble(8);
                        }
                        reader.Close();
                    }
                    connection.Close();
                }
            }

            var topo_tree = new DataTree <int>();

            for (int i = 0; i < topo_shell_face.Length; i++)
            {
                topo_tree.AddRange(topo_shell_face[i], new GH_Path(i));
            }

            var field_tree = new DataTree <double>();

            for (int i = 0; i < n_shell; i++)
            {
                for (int j = 0; j < n_glb; j++)
                {
                    var values = new double[6];
                    var path   = new GH_Path(new int[2] {
                        i, j
                    });
                    for (int k = 0; k < 6; k++)
                    {
                        values[k] = Fields[i][j, k];
                    }
                    field_tree.AddRange(values, path);
                }
            }

            DA.SetData(0, grid_glb.Info());
            DA.SetData(1, new GH_Grid(grid_glb));
            DA.SetData(2, new GH_Grid(grid_act));
            DA.SetData(3, new GH_Grid(grid_shp));
            DA.SetDataList(4, topo_shell_node);
            DA.SetDataTree(5, topo_tree);
            DA.SetDataTree(6, field_tree);
        }