Example #1
0
        //output func for visualization
        public void outputNodeWeights()
        {
            nodeW.Clear();

            for (int i = 0; i < numNodes; i++)
            {
                var len = nodes[i].w.Length;
                for (int j = 0; j < len; j++)
                {
                    nodeW.Add(nodes[i].w[j], new GH_Path(i));
                }
            }
        }
        private void _deformationsCheck__valueChanged(object sender, EventArgs e)
        {
            var box_state = ((MenuCheckBox)sender).Active;

            if (!box_state)
            {
                _resulttypeDrop.Clear();
                _feMeshes.Clear();
                _meshdisplacements.Clear();
                _meshdisplacementsByType.Clear();
                _deformedMeshes.Clear();
                _controlPoints.Clear();
                _memberdisplacements.Clear();
                _memberdisplacementsByType.Clear();
                _deformedMembers.Clear();
                _sfcNo.Clear();
                _memberNo.Clear();
            }
            _resetLC = true; // Get results

            setModelProps();
        }
Example #3
0
        private void OpenFileButton_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == DialogResult.Cancel)
            {
                return;
            }

            string filename = openFileDialog1.FileName;

            dt.Clear();
            grpchng = -1;
            dt      = xmlworker.LoadFromFile(filename);
            UpdateTree();
        }
Example #4
0
        public void applyProgramInputs(int numInputs)
        {
            inputs = new Input[numInputs];
            inputW.Clear();

            for (int i = 0; i < numInputs; i++)
            {
                inputs[i] = new Input(numWeights, i, progInputs);

                for (int j = 0; j < numWeights; j++)
                {
                    inputW.Add(inputs[i].w[j], new GH_Path(i));
                }
            }
        }
Example #5
0
        private void GetInvalidatedCacheItems()
        {
            lock (invalidatedCacheItems)
            {
                if (Response.Contains("invalidatedcacheitems"))
                {
                    Response["invalidatedcacheitems"].Merge((DataTree)invalidatedCacheItems.Clone());
                }
                else
                {
                    Response["invalidatedcacheitems"] = (DataTree)invalidatedCacheItems.Clone();
                }

                invalidatedCacheItems.Clear();
            }
        }
Example #6
0
        /// <summary>
        /// Clear single day's events from cache. Day means entries for one user and during one day.
        /// </summary>
        /// <param name="day"></param>
        private void InvalidateDay(DataTree day)
        {
            try
            {
                lock (documents)
                {
                    // Clear day's entries from hashtable.
                    foreach (DataTree entry in day["entries"])
                    {
                        if (documents.ContainsKey(entry["_id"]))
                        {
                            documents.Remove(entry["id"]);
                        }
                    }

                    day.Clear();
                }
            }
            catch (Exception ex)
            {
                logger.LogError("Failed to clear day in document cache", ex, day);
            }
        }
Example #7
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)
        {
            Surface surface = null;
            int     uCount  = 10;
            int     vCount  = 10;

            if (!DA.GetData(0, ref surface))
            {
                return;
            }
            if (!DA.GetData(1, ref uCount))
            {
                return;
            }
            if (!DA.GetData(2, ref vCount))
            {
                return;
            }
            /////////////////////////////////

            Surface x  = surface;
            int     un = uCount;
            int     vn = vCount;

            /////////////////////////////////////////////////////////////
            x.SetDomain(0, new Interval(0, 1));
            x.SetDomain(1, new Interval(0, 1));
            double             uu   = 1.0 / (2 * un);
            double             vv   = 1.0 / (2 * vn);
            List <double>      us   = new List <double>();
            List <double>      vs   = new List <double>();
            DataTree <Point3d> pts1 = new DataTree <Point3d>();
            DataTree <Point3d> pts2 = new DataTree <Point3d>();
            //DataTree<Brep> bps = new DataTree<Brep>();/////四边形面
            //DataTree<Brep> bps2 = new DataTree<Brep>();/////三角形面
            DataTree <Polyline> Four  = new DataTree <Polyline>(); /////四边形面
            DataTree <Polyline> Three = new DataTree <Polyline>(); /////三角形面
            double startU             = 0;
            double startV             = 0;
            int    index1             = 0;
            int    index2             = 0;
            int    indexBrep          = 0;

            #region///////////////////////////////////////////////////得到网格角点值
            for (int i = 0; i < 2 * un + 1; i++)
            {
                us.Add(startU);
                startU += uu;
            }
            for (int i = 0; i < 2 * vn + 1; i++)
            {
                vs.Add(startV);
                startV += vv;
            }
            ////////////////////////////////////////////////////////////
            for (int i = 1; i < 2 * un + 1; i += 2)
            {
                for (int j = 0; j < 2 * vn + 1; j += 2)
                {
                    pts1.Add(x.PointAt(us[i], vs[j]), new GH_Path(0, DA.Iteration, index1));
                }
                index1++;
            }
            for (int i = 0; i < 2 * un + 1; i += 2)
            {
                for (int j = 1; j < 2 * vn + 1; j += 2)
                {
                    pts2.Add(x.PointAt(us[i], vs[j]), new GH_Path(0, DA.Iteration, index2));
                }
                index2++;
            }
            #endregion ;



            #region////////////////////////////////////////////四边形曲面
            for (int i = 1; i < 2 * un; i++)
            {
                if (i / 2.0 != Convert.ToInt32(i / 2.0))//奇数
                {
                    List <Point3d> ptuu  = pts1.Branch((i - 1) / 2);
                    List <Point3d> ptvv1 = pts2.Branch((i - 1) / 2);
                    List <Point3d> ptvv2 = pts2.Branch((i - 1) / 2 + 1);
                    for (int k = 0; k < ptvv1.Count; k++)
                    {
                        Point3d p1 = ptuu[k];
                        Point3d p2 = ptuu[k + 1];
                        Point3d p3 = ptvv1[k];
                        Point3d p4 = ptvv2[k];
                        //Brep bb = Brep.CreateFromCornerPoints(p1, p3, p2, p4, 0);
                        //bps.Add(bb, new GH_Path(0, indexBrep));
                        Point3d[] points = { p1, p3, p2, p4, p1 };
                        Polyline  pln    = new Polyline(points);
                        Four.Add(pln, new GH_Path(0, DA.Iteration, indexBrep));//////////////////////////
                    }
                }
                else///偶数
                {
                    List <Point3d> ptxx = pts2.Branch(i / 2);
                    List <Point3d> ptyy = pts1.Branch(i / 2 - 1);
                    List <Point3d> ptzz = pts1.Branch(i / 2);
                    for (int q = 0; q < ptxx.Count - 1; q++)
                    {
                        Point3d pa = ptxx[q];
                        Point3d pb = ptxx[q + 1];
                        Point3d pc = ptyy[q + 1];
                        Point3d pd = ptzz[q + 1];
                        //Brep bb = Brep.CreateFromCornerPoints(pa, pc, pb, pd, 0);
                        //bps.Add(bb, new GH_Path(0, indexBrep));
                        Point3d[] points = { pa, pc, pb, pd, pa };
                        Polyline  pln    = new Polyline(points);
                        Four.Add(pln, new GH_Path(0, DA.Iteration, indexBrep));//////////////////////////
                    }
                }
                indexBrep++;
            }
            if (x.IsClosed(1))//////////////////////////////////如果v方向闭合
            {
                int indexnew = -1;
                for (int k = 0; k < pts2.BranchCount - 2; k++)
                {
                    Point3d pa = pts2.Branch(k + 1)[pts2.Branch(k).Count - 1];
                    Point3d pb = pts2.Branch(k + 1)[0];
                    Point3d pc = pts1.Branch(k)[0];
                    Point3d pd = pts1.Branch(k + 1)[0];
                    //Brep bb = Brep.CreateFromCornerPoints(pa, pc, pb, pd, 0);
                    //bps.Add(bb, new GH_Path(0, indexnew += 2));
                    Point3d[] points = { pa, pc, pb, pd, pa };
                    Polyline  pln    = new Polyline(points);
                    Four.Add(pln, new GH_Path(0, DA.Iteration, indexnew += 2));//////////////////////////
                }
            }
            if (x.IsClosed(0))//////////////////////////////////如果u方向闭合
            {
                int indexnew = -1;
                for (int k = 0; k < pts2.Branch(0).Count - 1; k++)
                {
                    Point3d pa = pts2.Branch(0)[k];
                    Point3d pb = pts2.Branch(0)[k + 1];
                    Point3d pc = pts1.Branch(0)[k + 1];
                    Point3d pd = pts1.Branch(pts1.BranchCount - 1)[k + 1];
                    //Brep bb = Brep.CreateFromCornerPoints(pa, pc, pb, pd, 0);
                    //bps.Add(bb, new GH_Path(0, indexnew += 2));
                    Point3d[] points = { pa, pc, pb, pd, pa };
                    Polyline  pln    = new Polyline(points);
                    Four.Add(pln, new GH_Path(0, DA.Iteration, indexnew += 2));//////////////////////////
                }
            }
            #endregion ;
            #region////////////////////////////////////////////////////////////////////三角形曲面
            List <Point3d> ptsa1 = new List <Point3d>();
            ptsa1.Add(x.PointAt(0, 0));
            ptsa1.AddRange(pts2.Branch(0));
            ptsa1.Add(x.PointAt(0, 1));
            for (int i = 0; i < ptsa1.Count - 1; i++)
            {
                //Brep bb = Brep.CreateFromCornerPoints(ptsa1[i], ptsa1[i + 1], pts1.Branch(0)[i], 0);
                //bps2.Add(bb, new GH_Path(0, 0));
                Point3d[] points = { ptsa1[i], ptsa1[i + 1], pts1.Branch(0)[i], ptsa1[i] };
                Polyline  pln    = new Polyline(points);
                Three.Add(pln, new GH_Path(0, DA.Iteration, 0));//////////////////////////
            }
            ////////////////////////////////////////////////////////////////////////////第一组
            List <Point3d> ptsa2 = new List <Point3d>();
            ptsa2.Add(x.PointAt(1, 0));
            ptsa2.AddRange(pts2.Branch(pts2.BranchCount - 1));
            ptsa2.Add(x.PointAt(1, 1));
            for (int i = 0; i < ptsa2.Count - 1; i++)
            {
                //Brep bb = Brep.CreateFromCornerPoints(ptsa2[i], ptsa2[i + 1], pts1.Branch(pts1.BranchCount - 1)[i], 0);
                //bps2.Add(bb, new GH_Path(0, 1));
                Point3d[] points = { ptsa2[i], ptsa2[i + 1], pts1.Branch(pts1.BranchCount - 1)[i], ptsa2[i] };
                Polyline  pln    = new Polyline(points);
                Three.Add(pln, new GH_Path(0, DA.Iteration, 1));//////////////////////////
            }
            ////////////////////////////////////////////////////////////////////////////第二组
            for (int i = 0; i < pts1.BranchCount - 1; i++)
            {
                //Brep bb = Brep.CreateFromCornerPoints(pts1.Branch(i)[0], pts1.Branch(i + 1)[0], pts2.Branch(i + 1)[0], 0);
                //bps2.Add(bb, new GH_Path(0, 2));
                Point3d[] points = { pts1.Branch(i)[0], pts1.Branch(i + 1)[0], pts2.Branch(i + 1)[0], pts1.Branch(i)[0] };
                Polyline  pln    = new Polyline(points);
                Three.Add(pln, new GH_Path(0, DA.Iteration, 2));//////////////////////////
            }
            ////////////////////////////////////////////////////////////////////////////第三组
            for (int i = 0; i < pts1.BranchCount - 1; i++)
            {
                //Brep bb = Brep.CreateFromCornerPoints(pts1.Branch(i)[pts1.Branch(i).Count - 1], pts1.Branch(i + 1)[pts1.Branch(i).Count - 1], pts2.Branch(i + 1)[pts2.Branch(i + 1).Count - 1], 0);
                //bps2.Add(bb, new GH_Path(0, 3));
                Point3d[] points = { pts1.Branch(i)[pts1.Branch(i).Count - 1], pts1.Branch(i + 1)[pts1.Branch(i).Count - 1], pts2.Branch(i + 1)[pts2.Branch(i + 1).Count - 1], pts1.Branch(i)[pts1.Branch(i).Count - 1] };
                Polyline  pln    = new Polyline(points);
                Three.Add(pln, new GH_Path(0, DA.Iteration, 3));//////////////////////////
            }
            ////////////////////////////////////////////////////////////////////////////第四组
            if (x.IsClosed(1))                                          ///////////////////如果v方向闭合
            {
                DataTree <Polyline> Three2 = new DataTree <Polyline>(); /////三角形边
                List <Polyline>     poly1  = Three.Branch(0);
                List <Polyline>     poly2  = Three.Branch(1);
                poly1.RemoveAt(0);
                poly1.RemoveAt(poly1.Count - 1);
                poly2.RemoveAt(0);
                poly2.RemoveAt(poly2.Count - 1);
                Point3d[] points = { pts2.Branch(0)[0], pts2.Branch(0)[pts2.Branch(0).Count - 1], pts1.Branch(0)[0], pts2.Branch(0)[0] };
                Polyline  pln    = new Polyline(points);
                poly1.Add(pln);
                Point3d[] points2 = { pts2.Branch(pts2.BranchCount - 1)[0], pts2.Branch(pts2.BranchCount - 1)[pts2.Branch(pts2.BranchCount - 1).Count - 1], pts1.Branch(pts1.BranchCount - 1)[0], pts2.Branch(pts2.BranchCount - 1)[0] };
                Polyline  pln2    = new Polyline(points2);
                poly2.Add(pln2);
                Three2.AddRange(poly1, new GH_Path(0, DA.Iteration, 0));
                Three2.AddRange(poly2, new GH_Path(0, DA.Iteration, 1));
                Three.Clear();
                Three = Three2;
            }
            if (x.IsClosed(0))///////////////////如果u方向闭合
            {
                //DataTree<Brep> bps3 = new DataTree<Brep>();/////三角形面
                DataTree <Polyline> Three2 = new DataTree <Polyline>();/////三角形边
                //List<Brep> newpb1 = bps2.Branch(2);
                //List<Brep> newpb2 = bps2.Branch(3);
                List <Polyline> poly1 = Three.Branch(2);
                List <Polyline> poly2 = Three.Branch(3);
                //Brep bb1 = Brep.CreateFromCornerPoints(pts1.Branch(0)[0], pts1.Branch(pts1.BranchCount - 1)[0], pts2.Branch(0)[0], 0);
                //newpb1.Add(bb1);
                Point3d[] points = { pts1.Branch(0)[0], pts1.Branch(pts1.BranchCount - 1)[0], pts2.Branch(0)[0], pts1.Branch(0)[0] };
                Polyline  pln    = new Polyline(points);
                poly1.Add(pln);//////////////////////////
                //Brep bb2 = Brep.CreateFromCornerPoints(pts1.Branch(0)[pts1.Branch(0).Count - 1], pts1.Branch(pts1.BranchCount - 1)[pts1.Branch(pts1.BranchCount - 1).Count - 1], pts2.Branch(pts2.BranchCount - 1)[pts2.Branch(pts2.BranchCount - 1).Count - 1], 0);
                //newpb2.Add(bb2);
                Point3d[] points2 = { pts1.Branch(0)[pts1.Branch(0).Count - 1], pts1.Branch(pts1.BranchCount - 1)[pts1.Branch(pts1.BranchCount - 1).Count - 1], pts2.Branch(pts2.BranchCount - 1)[pts2.Branch(pts2.BranchCount - 1).Count - 1], pts1.Branch(0)[pts1.Branch(0).Count - 1] };
                Polyline  pln2    = new Polyline(points2);
                poly2.Add(pln2);//////////////////////////
                ////
                //bps3.AddRange(newpb1, new GH_Path(0, 0));
                //bps3.AddRange(newpb2, new GH_Path(0, 1));
                //bps2 = bps3;
                Three2.AddRange(poly1, new GH_Path(0, DA.Iteration, 0));
                Three2.AddRange(poly2, new GH_Path(0, DA.Iteration, 1));
                Three = Three2;
            }
            #endregion ;
            DA.SetDataTree(0, Four);
            DA.SetDataTree(1, Three);
        }
Example #8
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)
        {
            Surface surface = null;
            int     uCount  = 10;
            int     vCount  = 10;

            if (!DA.GetData(0, ref surface))
            {
                return;
            }
            if (!DA.GetData(1, ref uCount))
            {
                return;
            }
            if (!DA.GetData(2, ref vCount))
            {
                return;
            }
            //////////////////////////////////////////////
            Surface x  = surface;
            int     un = uCount;
            int     vn = vCount;

            x.SetDomain(0, new Interval(0, 1));
            x.SetDomain(1, new Interval(0, 1));
            double        uu     = 1.0 / un;
            double        vv     = 1.0 / vn;
            double        ustart = 0;
            double        vstart = 0;
            List <double> us1    = new List <double>();
            List <double> us2    = new List <double>();
            List <double> vs     = new List <double>();

            for (int i = 0; i < un + 1; i++)
            {
                us1.Add(ustart);
                ustart += uu;
            }
            ///////////////////////////////////////
            us2.Add(0);
            us2.Add(uu / 2);
            ustart = uu / 2;
            for (int i = 0; i < un - 1; i++)
            {
                ustart += uu;
                us2.Add(ustart);
            }
            us2.Add(1);
            ///////////////////////////////////////
            for (int i = 0; i < vn + 1; i++)
            {
                vs.Add(vstart);
                vstart += vv;
            }
            //////////////////////////////////////
            DataTree <Point3d> pts = new DataTree <Point3d>();
            int index = 0;

            for (int i = 0; i < vn + 1; i++)
            {
                if ((i + 1) / 2.0 == Convert.ToInt32((i + 1) / 2.0))//奇数
                {
                    for (int j = 0; j < us2.Count; j++)
                    {
                        Point3d pt = x.PointAt(us2[j], vs[i]);
                        pts.Add(pt, new GH_Path(0, DA.Iteration, index));
                    }
                }
                else//偶数
                {
                    for (int j = 0; j < us1.Count; j++)
                    {
                        Point3d pt = x.PointAt(us1[j], vs[i]);
                        pts.Add(pt, new GH_Path(0, DA.Iteration, index));
                    }
                }
                index++;
            }
            //////////////////////////////////////////////////////////////
            DataTree <Polyline> pls = new DataTree <Polyline>();

            index = 0;
            for (int i = 0; i < pts.BranchCount - 1; i++)
            {
                if ((i + 1) / 2.0 == Convert.ToInt32((i + 1) / 2.0))//奇数
                {
                    List <Polyline> pln = PL2(pts.Branch(i), pts.Branch(i + 1));
                    pls.AddRange(pln, new GH_Path(0, DA.Iteration, index));
                }
                else
                {
                    List <Polyline> pln = PL1(pts.Branch(i), pts.Branch(i + 1));
                    pls.AddRange(pln, new GH_Path(0, DA.Iteration, index));
                }
                index++;
            }
            ////////////////////////////////////////////////////////////////如果u方向闭合
            DataTree <Point3d> pts2 = new DataTree <Point3d>();

            index = 0;
            if (x.IsClosed(0))
            {
                for (int i = 0; i < pts.BranchCount; i++)
                {
                    Point3d[]      ptsnew = Point3d.CullDuplicates(pts.Branch(i), 0.000001);
                    List <Point3d> ptend  = ptsnew.ToList();
                    if ((i + 1) / 2.0 == Convert.ToInt32((i + 1) / 2.0))//奇数
                    {
                        ptend.RemoveAt(0);
                    }
                    pts2.AddRange(ptend, new GH_Path(0, DA.Iteration, index));
                    index++;
                }
                pls.Clear();
                index = 0;
                for (int i = 0; i < pts2.BranchCount - 1; i++)
                {
                    if ((i + 1) / 2.0 == Convert.ToInt32((i + 1) / 2.0))//奇数
                    {
                        List <Polyline> plyss = PL4(pts2.Branch(i), pts2.Branch(i + 1));
                        pls.AddRange(plyss, new GH_Path(0, DA.Iteration, index));
                    }
                    else
                    {
                        List <Polyline> plyss = PL3(pts2.Branch(i), pts2.Branch(i + 1));
                        pls.AddRange(plyss, new GH_Path(0, DA.Iteration, index));
                    }
                    index++;
                }
                DA.SetDataTree(1, pts2);
            }
            else
            {
                DA.SetDataTree(1, pts);
            }
            DA.SetDataTree(0, pls);
        }
Example #9
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object can be used to retrieve data from input parameters and
        /// to store data in output parameters.</param>
        protected override void SolveInstance(IGH_DataAccess DA, EvaluationUnit unit)
        {
            // RFEM variables
            var        modelName = "";
            IModel     model     = null;
            IModelData data      = null;
            ILoads     loads     = null;

            // Assign GH Input
            bool   run       = false;
            var    scale     = 0.0;
            string iLoadCase = "";

            DA.GetData(0, ref run);
            DA.GetData(1, ref scale);

            // Do stuff
            if (run)
            {
                msg = new List <string>();

                if (!DA.GetData(5, ref modelName))
                {
                    Component_GetData.ConnectRFEM(ref model, ref data);
                }
                else
                {
                    Component_GetData.ConnectRFEM(modelName, ref model, ref data);
                }
                _saveddata = data;
                try
                {
                    // Get deformtions
                    _resetLC = true;
                    // Get loads
                    Component_GetData.GetLoadsFromRFEM(model, ref loads);
                    // Update load cases and combos to display in dropdown menu
                    _results = model.GetCalculation();

                    // Get load cases and combos to
                    var newLoadCasesAndCombos = new List <string>();
                    newLoadCasesAndCombos = loads.GetLoadCasesAndCombos(ref _countCases, ref _countCombos, ref _countRcombos);
                    if (_lCasesAndCombos == null || _lCasesAndCombos.Count == 0 || !_lCasesAndCombos.Equals(newLoadCasesAndCombos))
                    {
                        _lCasesAndCombos     = newLoadCasesAndCombos;
                        _loadDropLastValue   = 0; // reset dropdown menus if run
                        _resultDropLastValue = 0;
                        _lastLoadCase        = "";
                        _lastType            = 0;
                        _restoreDropDown     = true;
                    }
                    // Get members
                    _rfMembers = Component_GetData.GetRFMembers(data.GetMembers().ToList(), data);
                    // Get Fe Meshes from RFEM
                    _rfemMesh = _results.GetFeMesh();
                    _feMeshes = CreateFEMeshes(ref msg);

                    // Disconnect RFEM
                    Component_GetData.DisconnectRFEM(ref model, ref data);

                    // Results are displayed just when the button is set to 0 - if no LC is provided
                    var dummyLC = "";
                    if (!DA.GetData(2, ref dummyLC))
                    {
                        AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Set run to false to display results");
                        return;
                    }
                }
                catch (Exception ex)
                {
                    Component_GetData.DisconnectRFEM(ref model, ref data);
                    // Clear output!!!
                    _saveddata = null;
                    _rfemMesh  = null;
                    _results   = null;
                    _lcresults = null;
                    outResults = null;
                    _feMeshes.Clear();
                    _meshdisplacements.Clear();
                    _meshdisplacementsByType.Clear();
                    _deformedMeshes.Clear();
                    _controlPoints.Clear();
                    _memberdisplacements.Clear();
                    _memberdisplacementsByType.Clear();
                    _deformedMembers.Clear();
                    _sfcNo.Clear();
                    _memberNo.Clear();
                    throw ex;
                }
            }

            // do stuff
            if (msg.Count == 0) // if there are no calculation errors
            {
                // Get Load Case Number and result type
                int    result_type      = 0;
                string result_type_name = "";
                if (DA.GetData(2, ref iLoadCase))
                {
                    if (DA.GetData(3, ref result_type))
                    {
                        if (result_type <= 0 || result_type > Enum.GetNames(typeof(ResultsValueType)).Length - 1)
                        {
                            _loadDrop.Clear();
                            _resulttypeDrop.Clear();
                            _restoreDropDown = true; // for next time
                            AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Provide Valid Result Type.");
                            return;
                        }
                        result_type_name = Enum.GetName(typeof(ResultsValueType), result_type);
                        if (_lastLoadCase != iLoadCase || _lastType != result_type) // otherwise execution comes from change in scale and no need to reset load case
                        {
                            _resetLC = true;
                        }
                        _loadDrop.Clear();
                        _resulttypeDrop.Clear();
                        _restoreDropDown = true; // for next time
                    }
                    else
                    {
                        _loadDrop.Clear();
                        _resulttypeDrop.Clear();
                        _restoreDropDown = true; // for next time
                        AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Provide Result Type.");
                        return;
                    }
                }
                else if (DA.GetData(3, ref result_type))
                {
                    _loadDrop.Clear();
                    _resulttypeDrop.Clear();
                    _restoreDropDown = true; // for next time
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Provide Load Case or Combo.");
                    return;
                }
                else // get values from dropdown menus
                {
                    if (_lCasesAndCombos.Count == 0)
                    {
                        AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "No results to display");
                        _loadDrop.Clear();
                        _resulttypeDrop.Clear();
                        return;
                    }
                    if (_restoreDropDown) // from previous execution when it was overwritten
                    {
                        updateDropDownMenu(_lCasesAndCombos);
                        _resetLC         = true;
                        _restoreDropDown = false; // for next time
                    }
                    iLoadCase = _loadDrop.Items[_loadDrop.Value].name;
                }

                // Get results to display
                // 1) Results from load case or combo for all types 2) Results for selected result type 3) Apply scale
                if (_resetLC)
                {
                    int no    = Int16.Parse(iLoadCase.Split(' ')[1]);
                    var value = _lCasesAndCombos.IndexOf(iLoadCase);
                    _loadDropLastValue = value;
                    _lastLoadCase      = iLoadCase;
                    if (value == -1)
                    {
                        AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, $"{iLoadCase} has no results. Provide valid load case.");
                        return;
                    }
                    if (value < _countCases)
                    {
                        _lcresults = _results.GetResultsInFeNodes(LoadingType.LoadCaseType, no);
                    }
                    else if (value < _countCases + _countCombos)
                    {
                        _lcresults = _results.GetResultsInFeNodes(LoadingType.LoadCombinationType, no);
                    }
                    else if (value < _countCases + _countCombos + _countRcombos)
                    {
                        _lcresults = _results.GetResultsInFeNodes(LoadingType.ResultCombinationType, no);
                    }
                    else
                    {
                        msg.Add("Load case or combo not found");
                        return;
                    }
                    // Update drop down menu of result types
                    _resultTypes = new List <ResultsValueType>();
                    // Get deformations
                    _meshdisplacements   = GetMeshDisplacements(ref _sfcNo, ref msg);
                    _memberdisplacements = GetMemberDisplacements(ref _memberNo, ref msg);
                    //Get results by type
                    if (result_type == 0) // if no value obtaines through overwrite
                    {
                        _resultDropLastValue = 0;
                        updateDropDownMenu2(_resultTypes.Distinct().ToList(), ref result_type);
                    }
                    _meshdisplacementsByType   = GetMeshDisplacementsByType(result_type);
                    _memberdisplacementsByType = GetMemberDisplacementsByType(result_type);
                    // Get analysis results
                    outResults = new RFResults(_lcresults, _saveddata, iLoadCase,
                                               _memberForcesCheck.Active, _surfaceForcesCheck.Active, _nodalReactionsCheck.Active);
                    // Set _resetLC to false again
                    _resetLC = false;
                }
                if (_resetResultType)     // when there are changes in drop down menu
                {
                    if (result_type == 0) // if no value obtaines through overwrite
                    {
                        result_type = Int32.Parse(_resulttypeDrop.Items[_resulttypeDrop.Value].name);
                    }
                    _meshdisplacementsByType   = GetMeshDisplacementsByType(result_type);
                    _memberdisplacementsByType = GetMemberDisplacementsByType(result_type);
                    // Get analysis results
                    outResults = new RFResults(_lcresults, _saveddata, iLoadCase,
                                               _memberForcesCheck.Active, _surfaceForcesCheck.Active, _nodalReactionsCheck.Active);
                    // Set _resetType to false again
                    _resetResultType = false;
                }
                _lastType = result_type;
                // Check results
                if (_meshdisplacements.DataCount > 0 && _meshdisplacementsByType.DataCount == 0)
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, $"No surface results found for result type {((ResultsValueType)result_type).ToString()}");
                }
                if (_memberdisplacements.DataCount > 0 && _memberdisplacementsByType.DataCount == 0)
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, $"No member results found for result type {((ResultsValueType)result_type).ToString()}");
                }
                // Get output
                _deformedMeshes  = GetDeformedMeshes(scale, ref msg);
                _deformedMembers = GetDeformedMembers(scale, ref msg);

                // Output calculation results
                DA.SetData(0, outResults);

                // Assign GH Output
                DA.SetDataList(1, _deformedMembers);
                DA.SetDataList(2, _memberNo);
                DA.SetDataList(3, _deformedMeshes);
                DA.SetDataList(4, _sfcNo);
            }
            if (msg.Count > 0)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, String.Join(System.Environment.NewLine, msg.ToArray()));
            }
        }
Example #10
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)
        {
            Surface surface = null;
            int     uCount  = 10;
            int     vCount  = 10;

            if (!DA.GetData(0, ref surface))
            {
                return;
            }
            if (!DA.GetData(1, ref uCount))
            {
                return;
            }
            if (!DA.GetData(2, ref vCount))
            {
                return;
            }
            ///////////////////////////////////////
            Surface x  = surface;
            int     Un = uCount;
            int     Vn = vCount;

            /////////////////////////////////////////////////////////////////
            x.SetDomain(0, new Interval(0, 1));
            x.SetDomain(1, new Interval(0, 1));
            double        u      = 1.0 / (3 * Un);
            double        v      = 1.0 / (2 * Vn);
            double        ustart = u;
            double        vstart = 0;
            List <double> us1    = new List <double>(); //u方向的第一种列表类型
            List <double> us2    = new List <double>(); //u方向的第二种列表类型
            List <double> vs     = new List <double>(); /// v方向列表类型

            #region                                     /////////点坐标设置
            us1.Add(0);
            us1.Add(u);
            for (int i = 0; i < 2 * Un - 1; i++)
            {
                if ((i + 1) / 2.0 == Convert.ToInt32((i + 1) / 2.0))
                {
                    ustart += 2 * u;
                }
                else
                {
                    ustart += u;
                }
                us1.Add(ustart);
            }
            us1.Add(1);
            ///////////////////
            ustart = 0.5 * u;
            us2.Add(0);
            us2.Add(u * 0.5);
            for (int i = 0; i < 2 * Un - 1; i++)
            {
                if ((i + 1) / 2.0 == Convert.ToInt32((i + 1) / 2.0))
                {
                    ustart += u;
                }
                else
                {
                    ustart += 2 * u;
                }
                us2.Add(ustart);
            }
            us2.Add(1);
            ///////////////////////////////////////////////////////////////////////////////////
            for (int i = 0; i < 2 * Vn + 1; i++)
            {
                vs.Add(vstart);
                vstart += v;
            }
            #endregion ;
            DataTree <Point3d> pts = new DataTree <Point3d>();
            int index = 0;
            for (int i = 0; i < 2 * Vn + 1; i++)
            {
                for (int j = 0; j < 2 + 2 * Un; j++)
                {
                    if ((i + 1) / 2.0 == Convert.ToInt32((i + 1) / 2.0))
                    {
                        Point3d pp = x.PointAt(us2[j], vs[i]);
                        pts.Add(pp, new GH_Path(0, DA.Iteration, index));
                    }
                    else
                    {
                        Point3d pp = x.PointAt(us1[j], vs[i]);
                        pts.Add(pp, new GH_Path(0, DA.Iteration, index));
                    }
                }
                index++;
            }
            //////////////////////////////////////////////////////////////////////////////
            DataTree <Point3d> ptsnew = new DataTree <Point3d>();
            int index2 = 0;
            for (int i = 0; i < 2 * Un + 2; i++)
            {
                for (int j = 0; j < pts.BranchCount; j++)
                {
                    ptsnew.Add(pts.Branch(j)[i], new GH_Path(0, DA.Iteration, index2));
                }
                index2++;
            }
            ///////////////////////////////////////////////////////////////////////////////filp列表
            DataTree <Polyline> polys = new DataTree <Polyline>();
            int index3 = 0;
            for (int i = 0; i < ptsnew.BranchCount - 1; i++)
            {
                if ((i + 1) / 2.0 == Convert.ToInt32((i + 1) / 2.0))
                {
                    List <Polyline> ply = hexagon2(ptsnew.Branch(i), ptsnew.Branch(i + 1));
                    polys.AddRange(ply, new GH_Path(0, DA.Iteration, index3));
                }
                else
                {
                    List <Polyline> ply = hexagon1(ptsnew.Branch(i), ptsnew.Branch(i + 1));
                    polys.AddRange(ply, new GH_Path(0, DA.Iteration, index3));
                }

                index3++;
            }
            if (x.IsClosed(1))////v方向闭合
            {
                polys.Clear();
                index3 = 0;
                for (int i = 0; i < ptsnew.BranchCount - 1; i++)
                {
                    if ((i + 1) / 2.0 == Convert.ToInt32((i + 1) / 2.0))
                    {
                        List <Polyline> ply = hexagon2(ptsnew.Branch(i), ptsnew.Branch(i + 1));
                        polys.AddRange(ply, new GH_Path(0, DA.Iteration, index3));
                    }
                    else
                    {
                        List <Polyline> ply = hexagon3(ptsnew.Branch(i), ptsnew.Branch(i + 1));
                        polys.AddRange(ply, new GH_Path(0, DA.Iteration, index3));
                    }
                    index3++;
                }
            }
            //////////////////////////////////////////////////////////////////////////////////////////////////
            DataTree <Point3d> ptsnew2 = new DataTree <Point3d>();
            int index4 = 1;
            if (x.IsClosed(0))////u方向闭合
            {
                polys.Clear();
                ptsnew2.AddRange(ptsnew.Branch(ptsnew.BranchCount - 2), new GH_Path(0, DA.Iteration, 0));
                for (int i = 1; i < ptsnew.BranchCount - 1; i++)
                {
                    ptsnew2.AddRange(ptsnew.Branch(i), new GH_Path(0, DA.Iteration, index4));
                    index4++;
                }
                index4 = 0;
                for (int i = 0; i < ptsnew2.BranchCount - 1; i++)
                {
                    if ((i + 1) / 2.0 == Convert.ToInt32((i + 1) / 2.0))
                    {
                        List <Polyline> ply = hexagon2(ptsnew2.Branch(i), ptsnew2.Branch(i + 1));
                        polys.AddRange(ply, new GH_Path(0, DA.Iteration, index4));
                    }
                    else
                    {
                        List <Polyline> ply = hexagon1(ptsnew2.Branch(i), ptsnew2.Branch(i + 1));
                        polys.AddRange(ply, new GH_Path(0, DA.Iteration, index4));
                    }
                    index4++;
                }
                ptsnew = ptsnew2;
            }

            DA.SetDataTree(0, polys);
            DA.SetDataTree(1, ptsnew);
        }
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object can be used to retrieve data from input parameters and
        /// to store data in output parameters.</param>
        protected override void SolveInstance(IGH_DataAccess DA, EvaluationUnit unit)
        {
            //OnComponentLoaded();

            // Input counter
            //modelDataCount1 = 1 + modelDataCount2;

            // RFEM variables
            var        modelName = "";
            IModel     model     = null;
            IModelData data      = null;
            ILoads     loads     = null;

            // Output message
            var msg = new List <string>();

            // Assign GH Input
            bool run   = false;
            var  scale = 0.0;

            DA.GetData(0, ref run);
            DA.GetData(1, ref scale);

            // Do stuff
            if (run)
            {
                if (!DA.GetData(3, ref modelName))
                {
                    Component_GetData.ConnectRFEM(ref model, ref data);
                }
                else
                {
                    Component_GetData.ConnectRFEM(modelName, ref model, ref data);
                }
                _saveddata = data;
                try
                {
                    // Get deformtions
                    _resetLC = true;
                    // Get loads
                    Component_GetData.GetLoadsFromRFEM(model, ref loads);
                    // Get calculation results
                    _results = model.GetCalculation();
                    var errors = _results.CalculateAll();
                    if (errors != null)
                    {
                        msg.AddRange(errors.Select(x => x.Description));
                    }
                    // Update load cases and combos to display in dropdown menu
                    loads.GetLoadCasesAndCombos(ref _lCasesAndCombos, ref _countCases, ref _countCombos, ref _countRcombos);
                    updateDropDownMenu(_lCasesAndCombos);
                    // Get Fe Meshes from RFEM
                    _rfemMesh = _results.GetFeMesh();
                    _feMeshes = CreateFEMeshes(ref msg);
                    // _controlPoints = CreateControlPoints(ref msg); -> Obtained with displacements
                }
                catch (Exception ex)
                {
                    // Clear output!!!
                    _saveddata = null;
                    _rfemMesh  = null;
                    _results   = null;
                    _lcresults = null;
                    _feMeshes.Clear();
                    _meshdisplacements.Clear();
                    _deformedMeshes.Clear();
                    _controlPoints.Clear();
                    _memberdisplacements.Clear();
                    _deformedMembers.Clear();
                    throw ex;
                }
                Component_GetData.DisconnectRFEM(ref model, ref data);
            }
            // Get results to display
            if (_loadDrop.Items.Count > 0 && _resetLC && msg.Count == 0)
            {
                int no = Int16.Parse(_loadDrop.Items[_loadDrop.Value].name.Split(' ')[1]);
                if (_loadDrop.Value < _countCases)
                {
                    _lcresults = _results.GetResultsInFeNodes(LoadingType.LoadCaseType, no);
                }
                else if (_loadDrop.Value < _countCases + _countCombos)
                {
                    _lcresults = _results.GetResultsInFeNodes(LoadingType.LoadCombinationType, no);
                }
                else if (_loadDrop.Value < _countCases + _countCombos + _countRcombos)
                {
                    _lcresults = _results.GetResultsInFeNodes(LoadingType.ResultCombinationType, no);
                }
                else
                {
                    msg.Add("Load case or combo not found");
                }
                // Get deformations
                _meshdisplacements   = GetMeshDisplacements(ref msg);
                _memberdisplacements = GetMemberDisplacements(ref msg);
                // Set _resetLC to false again
                _resetLC = false;
            }

            // Get output
            _deformedMeshes  = GetDeformedMeshes(scale, ref msg);
            _deformedMembers = GetDeformedMembers(scale, ref msg);

            // Assign GH Output
            DA.SetDataTree(0, _deformedMembers);
            DA.SetDataTree(1, _deformedMeshes);

            if (msg.Count != 0)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, String.Join(System.Environment.NewLine, msg.ToArray()));
            }
        }
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object can be used to retrieve data from input parameters and
        /// to store data in output parameters.</param>
        protected override void SolveInstance(IGH_DataAccess DA, EvaluationUnit unit)
        {
            // RFEM variables
            var        modelName = "";
            IModel     model     = null;
            IModelData data      = null;

            //Additional variables
            var dicMat  = new Dictionary <int, Material>();
            var dicMass = new Dictionary <int, List <double> >();
            var dicVol  = new Dictionary <int, List <double> >();
            var dicGeo  = new Dictionary <int, List <Brep> >();

            // Input
            var msg  = "";
            var msgs = new List <string>();
            var run  = false;

            DA.GetData(0, ref run);


            if (run)
            {
                if (!DA.GetData(1, ref modelName))
                {
                    Component_GetData.ConnectRFEM(ref model, ref data);
                }
                else
                {
                    Component_GetData.ConnectRFEM(modelName, ref model, ref data);
                }
                _materials.Clear();
                _massTree.Clear();
                _volumeTree.Clear();
                _brepTree.Clear();
                try
                {
                    // Get Surfaces
                    var sfcs = Component_GetData.GetRFSurfaces(data.GetSurfaces().ToList(), data);
                    foreach (var sfc in sfcs)
                    {
                        // Add material to dictionary
                        if (!dicMat.ContainsKey(sfc.MaterialNo))
                        {
                            dicMat.Add(sfc.MaterialNo, data.GetMaterial(sfc.MaterialNo, ItemAt.AtNo).GetData());
                            dicMass.Add(sfc.MaterialNo, new List <double>());
                            dicVol.Add(sfc.MaterialNo, new List <double>());
                            dicGeo.Add(sfc.MaterialNo, new List <Brep>());
                        }
                        // Add mass to output list
                        dicVol[sfc.MaterialNo].Add(sfc.Area * sfc.Thickness);
                        dicMass[sfc.MaterialNo].Add(sfc.Area * sfc.Thickness * dicMat[sfc.MaterialNo].SpecificWeight / 10.0);

                        // Add Geometry to output list
                        dicGeo[sfc.MaterialNo].Add(sfc.ToBrep());
                    }
                    // Get Members
                    var members    = Component_GetData.GetRFMembers(data.GetMembers().ToList(), data);
                    var crosecs    = Component_GetData.GetRFCroSecs(data.GetCrossSections().ToList(), model, ref msgs);
                    var cs_indeces = crosecs.Select(x => x.No).ToList();
                    foreach (var member in members)
                    {
                        var mat_index = crosecs.Where(x => x.No == member.StartCrossSectionNo).ToList()[0].MatNo;


                        // Add material to dictionary
                        if (!dicMat.ContainsKey(mat_index))
                        {
                            dicMat.Add(mat_index, data.GetMaterial(mat_index, ItemAt.AtNo).GetData());
                            dicMass.Add(mat_index, new List <double>());
                            dicVol.Add(mat_index, new List <double>());
                            dicGeo.Add(mat_index, new List <Brep>());
                        }

                        // Add mass to output list
                        if (member.EndCrossSectionNo == 0) // In case of tension members, etc.
                        {
                            member.EndCrossSectionNo = member.StartCrossSectionNo;
                        }
                        if (!(cs_indeces.Contains(member.StartCrossSectionNo)) || (!(cs_indeces.Contains(member.EndCrossSectionNo))))
                        {
                            AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, $"Provide cross sections for member No {member.No}.");
                            continue;
                        }
                        var startCroSec = crosecs[cs_indeces.IndexOf(member.StartCrossSectionNo)];
                        var endCroSec   = crosecs[cs_indeces.IndexOf(member.EndCrossSectionNo)];
                        var volume      = (startCroSec.A + endCroSec.A) / 2 * member.Length;
                        dicVol[mat_index].Add(volume);
                        dicMass[mat_index].Add(member.Weight);

                        // Add Geometry to output list
                        var memberShape = Component_ExtrudeMembers.ExtrudeMembersToBrep(member, crosecs, member.Length / 8.0, out msg);
                        if (memberShape == null)
                        {
                            dicGeo[mat_index].Add(null);
                        }
                        else
                        {
                            dicGeo[mat_index].Add(memberShape[0]);
                        }
                    }
                    // Prepare Output
                    var matSorted = dicMat.Values.OrderBy(x => x.No).ToList();
                    _materials = matSorted.Select(x => x.Description).ToList();
                    for (int i = 0; i < matSorted.Count; i++)
                    {
                        var path = new GH_Path(i);
                        _volumeTree.EnsurePath(path);
                        _volumeTree.Branch(path).AddRange(dicVol[matSorted[i].No]);
                        _massTree.EnsurePath(path);
                        _massTree.Branch(path).AddRange(dicMass[matSorted[i].No]);
                        _brepTree.EnsurePath(path);
                        _brepTree.Branch(path).AddRange(dicGeo[matSorted[i].No]);
                    }
                }
                catch (Exception ex)
                {
                    Component_GetData.DisconnectRFEM(ref model, ref data);
                    _materials.Clear();
                    _massTree.Clear();
                    _volumeTree.Clear();
                    _brepTree.Clear();
                    throw ex;
                }
                Component_GetData.DisconnectRFEM(ref model, ref data);
                if (msgs.Count > 0)
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, String.Join(System.Environment.NewLine, msg.ToArray()));
                }
                if (msg != "")
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, msg);
                }
            }
            DA.SetDataList(0, _materials);
            DA.SetDataTree(1, _brepTree);
            DA.SetDataTree(2, _massTree);
            DA.SetDataTree(3, _volumeTree);
        }