NonLinearEquationsSolver icon indicating copy to clipboard operation
NonLinearEquationsSolver copied to clipboard

Remove Math.Net dependency

Open EduardBargues opened this issue 3 years ago • 7 comments

@EduardBargues Removing the Math.NET dependency would be great. You could either use arrays like CSparse.NET (see Vector helper class) or implement a simple vector type which wraps a double array.

@epsi1on The ILinearSolver allows to choose whichever matrix implementation you like and the goal is to be completely independend of any third party library.

EDIT: introducing an array pool is a good idea, but might not be necessary. To eliminate the cloning of the array in the example code above, the Corrector would need to have a working array of the appropriate size (which could be initialized when the NonLinearSolver is built):

// equilibrium array/vector is a class member info.InitialLoad.CopyTo(equilibrium); equilibrium.Add(newState.Lambda, info.ReferenceLoad, equilibrium); equilibrium.Add(-1.0, reaction, equilibrium);

EduardBargues avatar Aug 09 '20 18:08 EduardBargues

I think you can remove Math.Net dependency with two approaches as @wo80 mentioned. First is a wrapper around double[] array which works same as Vector<double>in Math.NET, second is use double[] instead of Vector<double>.

epsi1on avatar Aug 10 '20 07:08 epsi1on

yeah, Ill have a look which one is the best :) !! Pull-request is comming :P !

EduardBargues avatar Aug 10 '20 17:08 EduardBargues

I'd suggest to use arrays and keep the implementation private. To optimize performance, you could then introduce very specific functions like

static class VectorHelper
{
    /// <summary>
    /// target = v + scalew * w + scalez * z.
    /// </summary>
    public static void Add(int n, double[] v, double scalew, double[] w, double scalez, double[] z, double[] target)
    {
        for (int i = 0; i < n; i++)
        {
            target[i] = v[i] + scalew * w[i] + scalez * z[i];
        }
    }
}

The above example equation would then be written as

using static VectorHelper;

// equilibrium = info.InitialLoad + newState.Lambda * info.ReferenceLoad - reaction;
Add(equilibrium.Length, info.InitialLoad, newState.Lambda, info.ReferenceLoad, -1.0, reaction, equilibrium);

wo80 avatar Aug 10 '20 19:08 wo80

Hello, If you did not start yet, i can do and create a pull request?

Thanks

epsi1on avatar Aug 26 '20 05:08 epsi1on

Sure!! Im on vacations and wont start untill next week

EduardBargues avatar Aug 26 '20 08:08 EduardBargues

Hey @epsi1on ! Did you manage to do something? If not I can work on that. Have a good day!

EduardBargues avatar Sep 12 '20 16:09 EduardBargues

Hi, Didn't start yet Thanks

epsi1on avatar Sep 12 '20 16:09 epsi1on