Esempio n. 1
0
        public static void CheckModel_mpc(Model model, LoadCase lc)
        {
            var n = model.Nodes.Count * 6;

            //model.ReIndexNodes();
            //LoadCase.DefaultLoadCase

            var perm = CalcUtil.GenerateP_Delta_Mpc(model, lc, new Mathh.GaussRrefFinder());

            var np = perm.Item1.ColumnCount;//master count

            var rd = perm.Item2;

            var pd = perm.Item1;

            var kt = MatrixAssemblerUtil.AssembleFullStiffnessMatrix(model);


            if (perm.Item1.RowCount > 0 && perm.Item1.RowCount > 0)
            {
                var pf = pd.Transpose();


                var kr = pf.Multiply(kt).Multiply(pd);

                var nr = kr.RowCount;

                for (int i = 0; i < nr; i++)
                {
                    //two conditions:
                    // 1 - DoF[i] in reduced structure is a member of bounded dof group with MPC equations
                    // 2 - DoF[i] in reduced structure is not in first condition, it is standalone and not related to any other DoF or Fixed Value

                    var t = kr.At(i, i);

                    if (t > 0)
                    {
                        continue;
                    }



                    var nodeNum = 6.0 / 6;

                    if (t == 0)
                    {
                        model.Trace.Write(Common.TraceLevel.Warning, "DoF {0} of Node {1} not properly constrained", 7 % 6, nodeNum);
                    }
                    else//t < 0
                    {
                        model.Trace.Write(Common.TraceLevel.Warning, "DoF {0} of Node {1} not member", 7 % 6, nodeNum);
                    }
                }
            }
        }
Esempio n. 2
0
        public static void CheckModel(Model model, LoadCase lc)
        {
            model.ReIndexNodes();
            //LoadCase.DefaultLoadCase

            var fullst = MatrixAssemblerUtil.AssembleFullStiffnessMatrix(model);

            var mgr = DofMappingManager.Create(model, lc);

            var dvd = CalcUtil.GetReducedZoneDividedMatrix(fullst, mgr);

            var stiffness = dvd.ReleasedReleasedPart;


            var n = stiffness.ColumnCount;

            for (int i = 0; i < n; i++)
            {
                var t = stiffness.At(i, i);

                if (t > 0)
                {
                    continue;
                }

                var m1 = mgr.RMap2[i];
                var m2 = mgr.RMap1[m1];

                var nodeNum = m2 / 6;

                if (t == 0)
                {
                    model.Trace.Write(Common.TraceLevel.Warning, "DoF {0} of Node {1} not properly constrained", m2 % 6, nodeNum);
                }
                else//t < 0
                {
                    model.Trace.Write(Common.TraceLevel.Warning, "DoF {0} of Node {1} not member", m2 % 6, nodeNum);
                }
            }

            var k = MatrixAssemblerUtil.AssembleFullStiffnessMatrix(model);
            //CalcUtil.MakeMatrixSymetric(k);


            var kt = k.Transpose();

            Enumerable.Range(0, k.Values.Length).ToList().ForEach(i => kt.Values[i] = -kt.Values[i]);

            var sym = k.Add(kt);



            var max = sym.Values.Max(i => Math.Abs(i));
        }
Esempio n. 3
0
        /// <summary>
        /// Adds the analysis result.
        /// </summary>
        /// <param name="loadCase">The load case.</param>
        /// <remarks>if model is analyzed against specific load case, then displacements are available through <see cref="Displacements"/> property.
        /// If system is not analyses against a specific load case, then this method will analyses structure against <see cref="LoadCase"/>.
        /// While this method is using pre computed Cholesky Decomposition , its have a high performance in solving the system.
        /// </remarks>
        public static void AddAnalysisResult(this StaticLinearAnalysisResult thiis, LoadCase loadCase)
        {
            ISolver solver;

            var map = DofMappingManager.Create(thiis.Parent, loadCase);

            var n = thiis.Parent.Nodes.Count;                                        //node count
            var m = map.M;                                                           //master node count

            var pu = PermutationGenerator.GetDisplacementPermute(thiis.Parent, map); //permutation of U
            var pf = PermutationGenerator.GetForcePermute(thiis.Parent, map);        //permutation of F

            var fe = thiis.ElementForces[loadCase] = thiis.GetTotalElementsForceVector(loadCase);
            var fc = thiis.ConcentratedForces[loadCase] = thiis.GetTotalConcentratedForceVector(loadCase);


            var ft = fe.Add(fc);


            var fr  = pf.Multiply(ft);
            var ffr = thiis.GetFreePartOfReducedVector(fr, map);
            var fsr = thiis.GetFixedPartOfReducedVector(fr, map);

            var kt = MatrixAssemblerUtil.AssembleFullStiffnessMatrix(thiis.Parent);
            var kr = (CCS)((CCS)pf.Multiply(kt)).Multiply(pu);

            #region  U_s,r
            var usr = new double[map.RMap3.Length];

            {
                //should fill usr
                var ut_temp = thiis.GetTotalDispVector(loadCase, map);

                for (int i = 0; i < usr.Length; i++)
                {
                    var t1 = map.RMap3[i];
                    var t2 = map.RMap1[t1];

                    usr[i] = ut_temp[t2];
                }
            }

            #endregion

            var krd = CalcUtil.GetReducedZoneDividedMatrix(kr, map);
            thiis.AnalyseStiffnessMatrixForWarnings(krd, map, loadCase);

            {//TODO: remove
                var minAbsDiag = double.MaxValue;

                foreach (var tpl in krd.ReleasedReleasedPart.EnumerateIndexed())
                {
                    if (tpl.Item1 == tpl.Item2)
                    {
                        minAbsDiag = Math.Min(minAbsDiag, Math.Abs(tpl.Item3));
                    }
                }

                if (krd.ReleasedReleasedPart.RowCount != 0)
                {
                    //var kk = krd.ReleasedReleasedPart.ToDenseMatrix();
                }
            }

            #region  solver

            if (thiis.Solvers.ContainsKey(map.MasterMap))
            {
                solver = thiis.Solvers[map.MasterMap];
            }
            else
            {
                solver =
                    //SolverGenerator(krd.ReleasedReleasedPart);
                    thiis.SolverFactory.CreateSolver(krd.ReleasedReleasedPart);

                thiis.Solvers[map.MasterMap] = solver;
            }


            if (!solver.IsInitialized)
            {
                solver.Initialize();
            }

            #endregion

            double[] ufr = new double[map.RMap2.Length];
            //string message;

            var input = ffr.Subtract(krd.ReleasedFixedPart.Multiply(usr));


            solver.Solve(input, ufr);

            //if (res2 != SolverResult.Success)
            //    throw new BriefFiniteElementNetException(message);

            var fpsr = krd.FixedReleasedPart.Multiply(ufr).Add(krd.FixedFixedPart.Multiply(usr));

            var fsrt = fpsr.Subtract(fsr);// no needed

            var fx = thiis.SupportReactions[loadCase] = new double[6 * n];

            #region forming ft


            for (var i = 0; i < map.Fixity.Length; i++)
            {
                if (map.Fixity[i] == DofConstraint.Fixed)
                {
                    ft[i] = 0;
                }
            }

            for (var i = 0; i < fpsr.Length; i++)
            {
                var totDofNum = map.RMap1[map.RMap3[i]];

                ft[totDofNum] = fx[totDofNum] = fpsr[i];
            }


            #endregion

            #region forming ur

            var ur = new double[map.M * 6];


            for (var i = 0; i < usr.Length; i++)
            {
                ur[map.RMap3[i]] = usr[i];
            }

            for (var i = 0; i < ufr.Length; i++)
            {
                ur[map.RMap2[i]] = ufr[i];
            }

            #endregion

            var ut = pu.Multiply(ur);

            thiis.Forces[loadCase]        = ft;
            thiis.Displacements[loadCase] = ut;
        }
Esempio n. 4
0
        public static void FixUnrestrainedDofs(Model model, LoadCase lc)
        {
            model.ReIndexNodes();


            var fullst = MatrixAssemblerUtil.AssembleFullStiffnessMatrix(model);

            var mgr = DofMappingManager.Create(model, lc);

            var dvd = CalcUtil.GetReducedZoneDividedMatrix(fullst, mgr);

            var stiffness = dvd.ReleasedReleasedPart;


            var n = stiffness.ColumnCount;

            for (int i = 0; i < n; i++)
            {
                var t = stiffness.At(i, i);

                if (t > 0)
                {
                    continue;
                }

                var m1 = mgr.RMap2[i];
                var m2 = mgr.RMap1[m1];

                var nodeNum = m2 / 6;

                var targetDof = (DoF)(m2 % 6);

                var nde = model.Nodes[nodeNum];

                switch (targetDof)
                {
                case DoF.Dx:
                    nde.Constraints = nde.Constraints & Constraint.FixedDX;
                    break;

                case DoF.Dy:
                    nde.Constraints = nde.Constraints & Constraint.FixedDY;
                    break;

                case DoF.Dz:
                    nde.Constraints = nde.Constraints & Constraint.FixedDZ;
                    break;

                case DoF.Rx:
                    nde.Constraints = nde.Constraints & Constraint.FixedRX;
                    break;

                case DoF.Ry:
                    nde.Constraints = nde.Constraints & Constraint.FixedRY;
                    break;

                case DoF.Rz:
                    nde.Constraints = nde.Constraints & Constraint.FixedRZ;
                    break;
                }
            }
        }
Esempio n. 5
0
        public static void CheckModel_mpc(Model model, LoadCase lc)
        {
            var n = model.Nodes.Count * 6;

            model.ReIndexNodes();
            model.ReIndexElements();
            //LoadCase.DefaultLoadCase

            var perm = CalcUtil.GenerateP_Delta_Mpc(model, lc, new CsparsenetQrDisplacementPermutationCalculator());

            var np = perm.Item1.ColumnCount;//master count

            var rd = perm.Item2;

            var pd = perm.Item1;

            var kt = MatrixAssemblerUtil.AssembleFullStiffnessMatrix(model);


            if (perm.Item1.RowCount > 0 && perm.Item1.RowCount > 0)
            {
                var pf = pd.Transpose();


                var kr = pf.Multiply(kt).Multiply(pd);

                var nr = kr.RowCount;

                for (int i = 0; i < nr; i++)
                {
                    //model.Solve_MPC
                    //two conditions:
                    // 1 - DoF[i] in reduced structure is a member of bounded dof group with MPC equations
                    // 2 - DoF[i] in reduced structure is not in first condition, it is standalone and not related to any other DoF or Fixed Value

                    var t = kr.At(i, i);

                    if (t > 0)
                    {
                        continue;
                    }

                    var nums = pd.EnumerateColumnMembers(i);


                    foreach (var num in nums)
                    {
                        var dofT = num.Item1;

                        var nodeNum = dofT / 6;
                        var dof     = (DoF)(dofT % 6);


                        if (double.IsNaN(t))
                        {
                            var connectedElements = model.Elements.Where(ii => ii.Nodes.Any(jj => jj.Index == nodeNum));

                            var susps = "";

                            foreach (var elm in connectedElements)
                            {
                                var stf = elm.GetGlobalStifnessMatrix();

                                if (stf.Values.Any(ii => double.IsNaN(ii)))
                                {
                                    susps += elm.Index + ",";
                                }
                            }

                            model.Trace.Write(Common.TraceLevel.Warning, "DoF {0} of Node with index {1} have Nan in stifness matrix, suspecious connected elements with Nan in stiffness matrix are {2}", dof, nodeNum, susps);
                        }


                        if (t == 0)
                        {
                            model.Trace.Write(Common.TraceLevel.Warning, "DoF {0} of Node with index {1} not properly constrained", dof, nodeNum);
                        }
                        else//t < 0
                        {
                            model.Trace.Write(Common.TraceLevel.Warning, "DoF {0} of Node #{1} not member", dof, nodeNum);
                        }
                    }
                }
            }
        }