public void FactorizationLU(ref SparseMatrixQuaternion A) { CholmodInfo cholmodA = CholmodConverter.qConverter(ref A, CholmodInfo.CholmodMatrixStorage.CCS); m = A.RowCount; n = A.ColumnCount; fixed(int *Index = cholmodA.rowIndex, Pt = cholmodA.colIndex) fixed(double *val = cholmodA.values) { solver = CreateSolverLUUMFPACK_CCS(cholmodA.RowCount, cholmodA.ColumnCount, cholmodA.nnz, Index, Pt, val ); } if (solver == null) { throw new Exception("Create Solver Fail"); } }
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); }
/* * For Complex Calculation */ public void FactorizationCholesky(ref SparseMatrixComplex A) { CholmodInfo cholmodA = CholmodConverter.cConverter(ref A, CholmodInfo.CholmodMatrixStorage.CCS); m = A.RowCount; n = A.ColumnCount; fixed(int *Index = cholmodA.rowIndex, Pt = cholmodA.colIndex) fixed(double *val = cholmodA.values) { solver = CreateSolverCholesky_CCS_Complex(cholmodA.RowCount, cholmodA.ColumnCount, cholmodA.nnz, Pt, Index, val); } if (solver == null) { throw new Exception("Create Solver Fail"); } }
public DenseMatrixDouble SolveByFactorizedLU(ref DenseMatrixDouble b) { CholmodInfo cholmodb = CholmodConverter.ConvertDouble(ref b); DenseMatrixDouble result = new DenseMatrixDouble(n, 1); double[] x = new double[n]; SolveLU(ref cholmodb.values, ref x); for (int i = 0; i < n; i++) { result[i, 0] = x[i]; } x = null; GC.Collect(); return(result); }
public DenseMatrixComplex SolveByFactorizedLU(ref DenseMatrixComplex b) { CholmodInfo cholmodb = CholmodConverter.cConverter(ref b); DenseMatrixComplex result = new DenseMatrixComplex(n, 1); double[] x = new double[2 * n]; SolveLUComplex(ref cholmodb.values, ref x); for (int i = 0; i < n; i++) { result[i, 0] = new Complex(x[2 * i], x[2 * i + 1]); } x = null; GC.Collect(); return(result); }
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); }