Exemplo n.º 1
0
        private void Solve(UmfpackSolve sys, T[] input, T[] result)
        {
            if (!factorized)
            {
                Factorize();
            }

            int status = DoSolve(sys, input, result);

            if (status != Constants.UMFPACK_OK)
            {
                throw new UmfpackException(status);
            }
        }
Exemplo n.º 2
0
        protected override int DoSolve(UmfpackSolve sys, Complex[] input, Complex[] result)
        {
            var ha = GCHandle.Alloc(matrix.Values, GCHandleType.Pinned);
            var hx = GCHandle.Alloc(result, GCHandleType.Pinned);
            var hb = GCHandle.Alloc(input, GCHandleType.Pinned);

            try
            {
                return(NativeMethods.umfpack_zi_solve((int)sys, matrix.ColumnPointers, matrix.RowIndices,
                                                      ha.AddrOfPinnedObject(), IntPtr.Zero,
                                                      hx.AddrOfPinnedObject(), IntPtr.Zero,
                                                      hb.AddrOfPinnedObject(), IntPtr.Zero, numeric, control.Raw, info.Raw));
            }
            finally
            {
                ha.Free();
                hx.Free();
                hb.Free();
            }
        }
Exemplo n.º 3
0
        private void Solve(UmfpackSolve sys, DenseColumnMajorStorage <T> input, DenseColumnMajorStorage <T> result)
        {
            if (!factorized)
            {
                Factorize();
            }

            // The number of right-hand sides.
            int count = input.ColumnCount;

            if (count != result.ColumnCount)
            {
                throw new ArgumentException("result");
            }

            int rows    = matrix.RowCount;
            int columns = matrix.ColumnCount;

            var wi = new int[columns];
            var wx = CreateWorkspace(columns, Control.IterativeRefinement > 0);

            var x = new T[columns];
            var b = new T[rows];

            for (int i = 0; i < count; i++)
            {
                input.Column(i, b);

                int status = DoSolve(sys, b, x, wi, wx);

                if (status != Constants.UMFPACK_OK)
                {
                    throw new UmfpackException(status);
                }

                result.SetColumn(i, x);
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// Solve system of linear equations using given workspace.
 /// </summary>
 /// <param name="sys">The system to solve.</param>
 /// <param name="input">Right-hand side b.</param>
 /// <param name="result">The solution x.</param>
 /// <param name="wi">Integer workspace.</param>
 /// <param name="wx">Double workspace.</param>
 /// <returns></returns>
 protected abstract int DoSolve(UmfpackSolve sys, T[] input, T[] result, int[] wi, double[] wx);
Exemplo n.º 5
0
 /// <summary>
 /// Solve system of linear equations.
 /// </summary>
 /// <param name="sys">The system to solve.</param>
 /// <param name="input">Right-hand side b.</param>
 /// <param name="result">The solution x.</param>
 /// <returns></returns>
 protected abstract int DoSolve(UmfpackSolve sys, T[] input, T[] result);
Exemplo n.º 6
0
 protected override int DoSolve(UmfpackSolve sys, double[] input, double[] result, int[] wi, double[] wx)
 {
     return(NativeMethods.umfpack_di_wsolve((int)sys, matrix.ColumnPointers, matrix.RowIndices, matrix.Values,
                                            result, input, numeric, control.Raw, info.Raw, wi, wx));
 }