private void SetBoundaryConditions(TypeOfFixation type, IBoundaryCondition conditions)
        {
            foreach (var item in conditions.FixedNodes)
            {
                int ind = item.Key * DEGREES_OF_FREEDOM;
                switch (type)
                {
                case TypeOfFixation.RIGID:
                    MathOps.SetZerosRow(ref globalMatrix, ind);
                    MemoryMatrix.SetDoubleValue(ref globalMatrix, ind, ind, 1.0);
                    MathOps.SetZerosRow(ref globalMatrix, ind + 1);
                    MemoryMatrix.SetDoubleValue(ref globalMatrix, ind + 1, ind + 1, 1.0);
                    MathOps.SetZerosRow(ref globalMatrix, ind + 2);
                    MemoryMatrix.SetDoubleValue(ref globalMatrix, ind + 2, ind + 2, 1.0);

                    loads[ind]     = 0.0;
                    loads[ind + 1] = 0.0;
                    loads[ind + 2] = 0.0;
                    break;

                case TypeOfFixation.ARTICULATION_YZ: throw new NotImplementedException();

                case TypeOfFixation.ARTICULATION_XZ: throw new NotImplementedException();

                case TypeOfFixation.ARTICULATION_XY: throw new NotImplementedException();

                default: throw new ArgumentException("Wrong type of the fixation");
                }
            }
        }
        private void GenerateGlobalMatrix()
        {
            int length = nodes.Count * DEGREES_OF_FREEDOM;

            //MemoryMatrix.Init(ref globalMatrix, length);

            //globalMatrix = new Dictionary<int, IntPtr>(length);
            //for (int i = 0; i < length; i++)
            //{
            //    globalMatrix.Add(i, Marshal.AllocHGlobal(sizeof(double) * length));
            //    //globalMatrix.Add(i, Marshal.AllocCoTaskMem(sizeof(double) * length));
            //}

            Dictionary <int, double[]> dictionary = new Dictionary <int, double[]>(length);

            for (int i = 0; i < length; i++)
            {
                dictionary.Add(i, new double[length]);
                //globalMatrix.Add(i, Marshal.AllocCoTaskMem(sizeof(double) * length));
            }

            for (int i = 0; i < length; i++)
            {
                for (int j = 0; j < length; j++)
                {
                    MemoryMatrix.SetDoubleValue(ref globalMatrix, i, j, 0);
                }
            }

            foreach (var element in tetrahedrons)
            {
                double[,] k = GenerateLocalK(element);

                for (int si = 0; si < element.Nodes.Count; si++)
                {
                    for (int sj = 0; sj < element.Nodes.Count; sj++)
                    {
                        for (int ki = 0; ki < DEGREES_OF_FREEDOM; ki++)
                        {
                            for (int kj = 0; kj < DEGREES_OF_FREEDOM; kj++)
                            {
                                int gSi  = element.Nodes[si].GlobalIndex;
                                int gSj  = element.Nodes[sj].GlobalIndex;
                                int gI   = gSi * DEGREES_OF_FREEDOM + ki;
                                int gJ   = gSj * DEGREES_OF_FREEDOM + kj;
                                int locI = si * DEGREES_OF_FREEDOM + ki;
                                int locJ = sj * DEGREES_OF_FREEDOM + kj;

                                double tmp = MemoryMatrix.GetDoubleValue(ref globalMatrix, gI, gJ);
                                MemoryMatrix.SetDoubleValue(ref globalMatrix, gI, gJ, tmp + k[locI, locJ]);
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        private void GenerateGlobalMatrix()
        {
            int length = nodes.Count * DEGREES_OF_FREEDOM;

            ulong size = sizeof(double) * (ulong)length * (ulong)length;

            MemoryMatrix.Init(ref globalMatrix, size);

            for (int i = 0; i < length; i++)
            {
                for (int j = 0; j < length; j++)
                {
                    //MemoryMatrix.SetDoubleValue(ref globalMatrix, i * length + j, 0);
                    MemoryMatrix.SetDoubleValue(ref globalMatrix, i, j, length, 0);
                }
            }

            foreach (var element in tetrahedrons)
            {
                double[,] k = GenerateLocalK(element);

                for (int si = 0; si < element.Nodes.Count; si++)
                {
                    for (int sj = 0; sj < element.Nodes.Count; sj++)
                    {
                        for (int ki = 0; ki < DEGREES_OF_FREEDOM; ki++)
                        {
                            for (int kj = 0; kj < DEGREES_OF_FREEDOM; kj++)
                            {
                                int gSi  = element.Nodes[si].GlobalIndex;
                                int gSj  = element.Nodes[sj].GlobalIndex;
                                int gI   = gSi * DEGREES_OF_FREEDOM + ki;
                                int gJ   = gSj * DEGREES_OF_FREEDOM + kj;
                                int locI = si * DEGREES_OF_FREEDOM + ki;
                                int locJ = sj * DEGREES_OF_FREEDOM + kj;

                                //double tmp = MemoryMatrix.GetDoubleValue(ref globalMatrix, gI * length + gJ);
                                //MemoryMatrix.SetDoubleValue(ref globalMatrix, gI * length + gJ, tmp + k[locI, locJ]);

                                double tmp = MemoryMatrix.GetDoubleValue(ref globalMatrix, gI, gJ, length);
                                MemoryMatrix.SetDoubleValue(ref globalMatrix, gI, gJ, length, tmp + k[locI, locJ]);
                            }
                        }
                    }
                }
            }
        }