Esempio n. 1
0
 private double[] PCG(double[,] stiffnessMatrix, double[] forceVector)
 {
     double[] solutionVector = new double[forceVector.Length];
     double[,] preconditioner = new double[stiffnessMatrix.GetLength(0), stiffnessMatrix.GetLength(1)];
     for (int i = 0; i < preconditioner.GetLength(0); i++)
     {
         preconditioner[i, i] = 1 / stiffnessMatrix[i, i];
     }
     double[] residual = VectorOperations.VectorVectorSubtraction(
         forceVector,
         VectorOperations.MatrixVectorProduct(stiffnessMatrix, solutionVector)
         );
     double[] preconVector = VectorOperations.MatrixVectorProduct(preconditioner, residual);
     for (int iter = 0; iter < maxIterations; iter++)
     {
         double[] u = VectorOperations.MatrixVectorProduct(stiffnessMatrix, preconVector);
         double   residualDotOld = VectorOperations.VectorDotProduct(residual, preconVector);
         double   alpha          = residualDotOld / VectorOperations.VectorDotProduct(preconVector, u);
         solutionVector = VectorOperations.VectorVectorAddition(solutionVector, VectorOperations.VectorScalarProductNew(preconVector, alpha));
         residual       = VectorOperations.VectorVectorSubtraction(residual, VectorOperations.VectorScalarProductNew(u, alpha));
         if (VectorOperations.VectorDotProduct(residual, residual) < tolerance)
         {
             break;
         }
         double residualDotNew = VectorOperations.VectorDotProduct(residual, VectorOperations.MatrixVectorProduct(preconditioner, residual));
         double beta           = residualDotNew / residualDotOld;
         preconVector = VectorOperations.VectorVectorAddition(
             VectorOperations.MatrixVectorProduct(preconditioner, residual),
             VectorOperations.VectorScalarProductNew(preconVector, beta)
             );
     }
     return(solutionVector);
 }
Esempio n. 2
0
        private Tuple <double[], double, double[], double[], double> MasterSegmentGeometry(double[,] daMatrix, double[,] da2Matrix)
        {
            double Xm1 = Nodes[1].XCoordinate + DisplacementVector[0];
            double Ym1 = Nodes[1].YCoordinate + DisplacementVector[1];
            double Xm2 = Nodes[2].XCoordinate + DisplacementVector[2];
            double Ym2 = Nodes[2].YCoordinate + DisplacementVector[3];
            double Xm3 = Nodes[3].XCoordinate + DisplacementVector[4];
            double Ym3 = Nodes[3].YCoordinate + DisplacementVector[5];
            double Xs  = Nodes[4].XCoordinate + DisplacementVector[6];
            double Ys  = Nodes[4].YCoordinate + DisplacementVector[7];

            double[] xupd                    = new double[] { -Xm1, -Ym1, -Xm2, -Ym2, -Xm3, -Ym3, -Xs, -Ys };
            double[] surfaceVector           = VectorOperations.MatrixVectorProduct(daMatrix, xupd);
            double[] surfaceVectorDerivative = VectorOperations.MatrixVectorProduct(da2Matrix, xupd);

            double detm = VectorOperations.VectorDotProduct(surfaceVector, surfaceVector);
            double m11  = 1.0 / detm;

            double[] vector     = new double[] { -surfaceVector[1], surfaceVector[0] };
            double   scalarCoef = 1.0 / (Math.Sqrt(detm));

            double[] normalUnitVec   = VectorOperations.VectorScalarProductNew(vector, scalarCoef);
            double[] tangentVector   = VectorOperations.VectorScalarProductNew(surfaceVector, scalarCoef);
            double   scalarCoef2     = Math.Pow(m11, 2.0);
            double   curvatureTensor = scalarCoef2 * VectorOperations.VectorDotProduct(surfaceVectorDerivative, normalUnitVec);

            return(new Tuple <double[], double, double[], double[], double>(surfaceVector, m11, normalUnitVec, tangentVector, curvatureTensor));
        }
Esempio n. 3
0
        private double CalculatePenetration(double[] normalVector, double[,] aMatrix, double[] xUpdated)
        {
            double ksi3 = VectorOperations.VectorDotProduct(
                xUpdated, VectorOperations.MatrixVectorProduct(
                    MatrixOperations.Transpose(aMatrix), normalVector));

            return(ksi3);
        }
Esempio n. 4
0
 private double[,] MetricTensor(List <double[]> dRho)
 {
     double[,] m = new double[2, 2];
     m[0, 0]     = VectorOperations.VectorDotProduct(dRho[0], dRho[0]);
     m[0, 1]     = VectorOperations.VectorDotProduct(dRho[0], dRho[1]);
     m[1, 0]     = VectorOperations.VectorDotProduct(dRho[1], dRho[0]);
     m[1, 1]     = VectorOperations.VectorDotProduct(dRho[1], dRho[1]);
     return(m);
 }
Esempio n. 5
0
        private double CalculatePenetration(double[,] aMatrix, double[] n)
        {
            double[,] AT = MatrixOperations.Transpose(aMatrix);
            double[] AT_n      = VectorOperations.MatrixVectorProduct(AT, n);
            double[] xupd      = NodalXUpdated();
            double   normalGap = VectorOperations.VectorDotProduct(xupd, AT_n);

            return(normalGap);
        }
Esempio n. 6
0
        private double[] BiCGSTAB(double[,] stiffnessMatrix, double[] forceVector)
        {
            double[] solutionVector = new double[forceVector.Length];

            double[] xVector = new double[forceVector.Length];
            double[] pVector = new double[forceVector.Length];
            double[] vVector = new double[forceVector.Length];

            double[,] K = stiffnessMatrix;

            double[] bVector     = forceVector;
            double[] rVector     = VectorOperations.VectorVectorSubtraction(bVector, VectorOperations.MatrixVectorProduct(K, xVector));
            double[] r0hatVector = rVector;

            double rho0 = 1.0;
            double w    = 1.0;
            double a    = 1.0;
            double rho1 = VectorOperations.VectorDotProduct(r0hatVector, rVector);
            double b;

            double[] sVector;
            double[] tVector;
            int      iters = 100;
            double   converged;

            for (int i = 0; i < iters; i++)
            {
                b       = (rho1 / rho0) * (a / w);
                pVector = VectorOperations.VectorVectorAddition(rVector,
                                                                VectorOperations.VectorScalarProductNew(
                                                                    VectorOperations.VectorVectorSubtraction(pVector,
                                                                                                             VectorOperations.VectorScalarProductNew(vVector, w)), b));
                vVector = VectorOperations.MatrixVectorProduct(K, pVector);
                a       = rho1 / VectorOperations.VectorDotProduct(r0hatVector, vVector);
                sVector = VectorOperations.VectorVectorSubtraction(rVector,
                                                                   VectorOperations.VectorScalarProductNew(vVector, a));
                tVector = VectorOperations.MatrixVectorProduct(K, sVector);
                w       = VectorOperations.VectorDotProduct(tVector, sVector) / VectorOperations.VectorDotProduct(tVector, tVector);
                rho0    = rho1;
                rho1    = -w *VectorOperations.VectorDotProduct(r0hatVector, tVector);

                xVector = VectorOperations.VectorVectorAddition(xVector,
                                                                VectorOperations.VectorScalarProductNew(pVector, a));
                xVector = VectorOperations.VectorVectorAddition(xVector,
                                                                VectorOperations.VectorScalarProductNew(sVector, w));
                rVector = VectorOperations.VectorVectorSubtraction(sVector,
                                                                   VectorOperations.VectorScalarProductNew(tVector, w));
                converged = VectorOperations.VectorNorm2(rVector);
                if (i == iters | converged < 0.00000001)
                {
                    break;
                }
            }
            solutionVector = xVector;
            return(solutionVector);
        }
Esempio n. 7
0
        private double CalculateDeltaKsi(double[] masterSlaveRelativeVector, double[] surfaceVector, double[] surfaceVectorDerivative)
        {
            double scalar1 = VectorOperations.VectorDotProduct(surfaceVector, masterSlaveRelativeVector);
            double scalar2 = VectorOperations.VectorDotProduct(surfaceVectorDerivative, masterSlaveRelativeVector) -
                             VectorOperations.VectorDotProduct(surfaceVector, surfaceVector);

            double deltaKsi = -scalar1 / scalar2;

            return(deltaKsi);
        }
Esempio n. 8
0
 private double[] Calculate_f(List <double[]> dRho, double[,] aMatrix, double[] xUpdated)
 {
     double[] f = new double[2];
     f[0] = VectorOperations.VectorDotProduct(
         dRho[0], VectorOperations.MatrixVectorProduct(
             aMatrix, xUpdated));
     f[1] = VectorOperations.VectorDotProduct(
         dRho[1], VectorOperations.MatrixVectorProduct(
             aMatrix, xUpdated));
     return(f);
 }
Esempio n. 9
0
        private double CalculateTangentialTraction()
        {
            double[,] A  = CalculatePositionMatrix();
            double[,] AT = MatrixOperations.Transpose(A);
            double[] displacementVector = DisplacementVector;
            double[] tangentUnitvector  = CalculateTangentUnitVector();
            double[] aT_t               = VectorOperations.MatrixVectorProduct(AT, tangentUnitvector);
            double   tangentGap         = VectorOperations.VectorDotProduct(displacementVector, aT_t);
            double   tangentialTraction = -PenaltyFactor * tangentGap;

            return(tangentialTraction);
        }
Esempio n. 10
0
        private double Calculate_e(double[,] aMatrix, double[] xUpdated)
        {
            double[] dRho12 = new double[] {
                0.25 * (xUpdated[0] - xUpdated[3] + xUpdated[6] - xUpdated[9]),
                0.25 * (xUpdated[1] - xUpdated[4] + xUpdated[7] - xUpdated[10]),
                0.25 * (xUpdated[2] - xUpdated[5] + xUpdated[8] - xUpdated[11])
            };

            double e = VectorOperations.VectorDotProduct(
                dRho12, VectorOperations.MatrixVectorProduct(
                    aMatrix, xUpdated));

            return(e);
        }
Esempio n. 11
0
        private double CalculateNormalGap(double[,] aMatrix, double[] n)
        {
            double[,] AT = MatrixOperations.Transpose(aMatrix);
            double[] AT_n = VectorOperations.MatrixVectorProduct(AT, n);
            double[] xupd = new double[] {
                Nodes[1].XCoordinate + DisplacementVector[0],
                Nodes[1].YCoordinate + DisplacementVector[1],
                Nodes[2].XCoordinate + DisplacementVector[2],
                Nodes[2].YCoordinate + DisplacementVector[3],
                Nodes[3].XCoordinate + DisplacementVector[4],
                Nodes[3].YCoordinate + DisplacementVector[5]
            };
            double normalGap = VectorOperations.VectorDotProduct(xupd, AT_n);

            return(normalGap);
        }
Esempio n. 12
0
        private double CalculateNormalGap()
        {
            double[,] A  = CalculatePositionMatrix();
            double[,] AT = MatrixOperations.Transpose(A);
            double[] n    = CalculateNormalUnitVector();
            double[] AT_n = VectorOperations.MatrixVectorProduct(AT, n);
            double[] xupd = new double[] {
                Nodes[1].XCoordinate + DisplacementVector[0],
                Nodes[1].YCoordinate + DisplacementVector[1],
                Nodes[2].XCoordinate + DisplacementVector[2],
                Nodes[2].YCoordinate + DisplacementVector[3]
            };
            double normalGap = VectorOperations.VectorDotProduct(xupd, AT_n);

            return(normalGap);
        }
Esempio n. 13
0
        private double CalculatePenetration(double ksi1, double ksi2)
        {
            double[]        xUpdated = xUpdatedVector();
            List <double[]> dRho     = SurfaceVectors(ksi1, ksi2);

            double[,] m = MetricTensor(dRho);
            double[] n = NormalVector(m, dRho);
            Tuple <double[, ], double[, ], double[, ]> aMatrices = CalculatePositionMatrix(ksi1, ksi2);

            double[,] a  = aMatrices.Item1;
            double[,] aT = MatrixOperations.Transpose(a);
            double ksi3 = VectorOperations.VectorDotProduct(
                xUpdated, VectorOperations.MatrixVectorProduct(
                    aT, n));

            return(ksi3);
        }
Esempio n. 14
0
        private Tuple <double[], double, double[], double[], double> SlaveSegmentGeometry(double[,] daMatrix, double[,] da2Matrix)
        {
            double[] xupd                    = NodalXUpdated();
            double[] surfaceVector           = VectorOperations.MatrixVectorProduct(daMatrix, xupd);
            double[] surfaceVectorDerivative = VectorOperations.MatrixVectorProduct(da2Matrix, xupd);

            double detm = VectorOperations.VectorDotProduct(surfaceVector, surfaceVector);
            double m11  = 1.0 / detm;

            double[] vector     = new double[] { -surfaceVector[1], surfaceVector[0] };
            double   scalarCoef = 1.0 / (Math.Sqrt(detm));

            double[] normalUnitVec   = VectorOperations.VectorScalarProductNew(vector, scalarCoef);
            double[] tangentVector   = VectorOperations.VectorScalarProductNew(surfaceVector, scalarCoef);
            double   scalarCoef2     = Math.Pow(m11, 2.0);
            double   curvatureTensor = scalarCoef2 * VectorOperations.VectorDotProduct(surfaceVectorDerivative, normalUnitVec);

            return(new Tuple <double[], double, double[], double[], double>(surfaceVector, detm, normalUnitVec, tangentVector, curvatureTensor));
        }
Esempio n. 15
0
        private Tuple <double[], double, double[]> SurfaceGeometry(double[,] daMatrix)
        {
            double Xm1 = Nodes[1].XCoordinate + DisplacementVector[0];
            double Ym1 = Nodes[1].YCoordinate + DisplacementVector[1];
            double Xm2 = Nodes[2].XCoordinate + DisplacementVector[2];
            double Ym2 = Nodes[2].YCoordinate + DisplacementVector[3];
            double Xs  = Nodes[3].XCoordinate + DisplacementVector[4];
            double Ys  = Nodes[3].YCoordinate + DisplacementVector[5];

            double[] xupd          = new double[] { -Xm1, -Ym1, -Xm2, -Ym2, -Xs, -Ys };
            double[] surfaceVector = VectorOperations.MatrixVectorProduct(daMatrix, xupd);
            double   detm          = VectorOperations.VectorDotProduct(surfaceVector, surfaceVector);
            double   m11           = 1.0 / detm;

            double[] vector     = new double[] { Ym2 - Ym1, Xm1 - Xm2 };
            double   scalarCoef = -1.0 / (2.0 * Math.Sqrt(detm));

            double[] normalUnitVec = VectorOperations.VectorScalarProductNew(vector, scalarCoef);

            return(new Tuple <double[], double, double[]>(surfaceVector, m11, normalUnitVec));
        }
Esempio n. 16
0
        private Tuple <double[], double, double[], double[], double> MasterSegmentGeometry(double[,] daMatrix, double[,] da2Matrix)
        {
            double[] xupd                    = VectorOperations.VectorScalarProduct(NodalXUpdated(), -1);
            double[] surfaceVector           = VectorOperations.MatrixVectorProduct(daMatrix, xupd);
            double[] surfaceVectorDerivative = VectorOperations.MatrixVectorProduct(da2Matrix, xupd);

            double detm = VectorOperations.VectorDotProduct(surfaceVector, surfaceVector);
            double m11  = 1.0 / detm;

            double[] vector      = new double[2];
            double   scalarCoef  = new double();
            double   scalarCoef2 = Math.Pow(m11, 2.0);

            double[] tangentVector   = new double[2];
            double   curvatureTensor = new double();

            if (Properties.MasterSegmentPolynomialDegree == 1)
            {
                double Xm1 = Nodes[1].XCoordinate + DisplacementVector[0];
                double Ym1 = Nodes[1].YCoordinate + DisplacementVector[1];
                double Xm2 = Nodes[2].XCoordinate + DisplacementVector[2];
                double Ym2 = Nodes[2].YCoordinate + DisplacementVector[3];
                vector[0]  = Ym2 - Ym1;
                vector[1]  = Xm1 - Xm2;
                scalarCoef = -1.0 / (2.0 * Math.Sqrt(detm));
            }
            else
            {
                vector[0]     = -surfaceVector[1];
                vector[1]     = surfaceVector[0];
                scalarCoef    = 1.0 / (Math.Sqrt(detm));
                tangentVector = VectorOperations.VectorScalarProductNew(surfaceVector, scalarCoef);
            }
            double[] normalUnitVec = VectorOperations.VectorScalarProductNew(vector, scalarCoef);
            curvatureTensor = scalarCoef2 * VectorOperations.VectorDotProduct(surfaceVectorDerivative, normalUnitVec);
            return(new Tuple <double[], double, double[], double[], double>(surfaceVector, m11, normalUnitVec, tangentVector, curvatureTensor));
        }