public DenseMatrixDouble SolveLinearSystemByLU(ref SparseMatrixDouble A, ref DenseMatrixDouble b) { if (A.RowCount != b.RowCount) { throw new Exception("The dimension of A and b must be agree"); } CholmodInfo cholmodb = CholmodConverter.ConvertDouble(ref b); CholmodInfo cholmodA = CholmodConverter.ConverterDouble(ref A, CholmodInfo.CholmodMatrixStorage.CCS); double[] x = new double[A.ColumnCount]; fixed(int *Index = cholmodA.rowIndex, Pt = cholmodA.colIndex) fixed(double *val = cholmodA.values, bp = cholmodb.values, xx = x) { SolveRealByLU_CCS(cholmodA.RowCount, cholmodA.ColumnCount, cholmodA.nnz, Index, //Row Index Pt, //Column Pointer val, xx, bp); } DenseMatrixDouble unknown = CholmodConverter.dConvertArrayToDenseMatrix(ref x, x.Length, 1); cholmodA = null; cholmodb = null; GC.Collect(); return(unknown); }
protected DenseMatrixDouble ComputeTrivaialConnection(SparseMatrixDouble d0, SparseMatrixDouble d1, double[] Guassian) { DenseMatrixDouble b = CholmodConverter.dConvertArrayToDenseMatrix(ref Guassian, Guassian.Length, 1); double[] singularValues = new double[Singularities.Count]; //Init with avg of 2 double avgValue = 2.0f / (double)Singularities.Count; int j = 0; foreach (KeyValuePair <TriMesh.Vertex, double> vItem in Singularities) { int index = vItem.Key.Index; double value = vItem.Value; b[index, 0] = Guassian[index] - 2 * Math.PI * value; j++; } for (int i = 0; i < Guassian.Length; i++) { b[i, 0] = -b[i, 0]; } SparseMatrixDouble A = d0.Transpose(); DenseMatrixDouble x = LinearSystemGenericByLib.Instance.SolveLinerSystem(ref A, ref b); SparseMatrixDouble d1T = d1.Transpose(); SparseMatrixDouble Laplace = d1 * d1T; DenseMatrixDouble rhs = d1 * x; DenseMatrixDouble y = LinearSystemGenericByLib.Instance.SolveLinerSystem(ref Laplace, ref rhs); x = x - d1T * y; return(x); }