wo80 / CSparse.NET

A concise library for solving sparse linear systems with direct methods.
GNU Lesser General Public License v2.1
58 stars 25 forks source link

Nonlinear equation system #28

Closed epsi1on closed 3 years ago

epsi1on commented 4 years ago

Hi, do you know any solver for nonlinear eq. system with enhanced methods like arc-length or work control specially for Finite Element Analysis of solids and structures with C#?

Thanks

wo80 commented 4 years ago

Hi, I just saw you found out about NonLinearEquationsSolver here on Github. I don't have a lot of experience in structural mechanics, so I can't give you a good advice here, but the arc-length method seems to be a good point to start, if you want to do nonlinear analysis.

romainmesnil commented 4 years ago

Hello, indeed arclength is a very good place to start. One thing to keep in mind, as you perform interations, the tangent stiffness matrix will change, and you will have to update the factorization. It is thus likely that iterative solvers will outperform direct methods in this case, since factorization might be time consuming. If your question is about the implementation of Finite Element in C#, I fear that there are very few librairies that do this, and that you will have to implement them on your own. Best, Romain

wo80 commented 4 years ago

@romainmesnil Good point. As I said, I'm not an expert on subject matter and just did a quick look at the arclength method. Performance of course depends on the properties of the matrix (and how much the matrix changes on each update). For example, if the matrix is spd and it's a rank 1 update, this could be efficiently done with Cholesky. If you choose an iterative solver, you could do an incomplete factorization for preconditioning, without updating in each iteration, in case the matrix doesn't change too much.

@epsi1on From the solver/performance point of view, I'd be glad to help.

romainmesnil commented 4 years ago

Hello, do you have an example of use of CSparse.NET in the context of iterative solver?

wo80 commented 4 years ago

Both dense and sparse matrix classes implement the ILinearOperator interface, which is enough to write an iterative solver. Locally, I have a couple of solvers implemented. The CSparse.NET package itself will not get any features extending the original C project, but I might publish a separate package including dense and iterative solvers, if I find the time.

epsi1on commented 4 years ago

@wo80 thanks. I think the stiffness matrix is not necessarily always SPD and can have zero or negative values on the main diagonal if any part of model goes into softening stage which will happen in ultimate condition of member! (SPD matrix do not have non positive on diagonal). and i think it frequently happens. Arclength can handle such nonlinearities, this is an example of arclength for a 1D problem with one input and one output:

https://www.youtube.com/watch?v=j4IaRcUM0Mk

As you know the newton iterative method cannot pass such curves. I think if we want to do real nonlinear analysis, we will face them always.

@romainmesnil , do you know other nonlinear software in this criteria? i mean software that can handle nonlinear in softening phase, also uses sophisticated and up-to-date formulation for calculating the tangent matrix? i know OpenSEES which is C++ opensource, and can use arc-length together with fiber-element which would be very powerful if works correct and fast at same time.

Do you think same as me that it could be re-invention of the wheel?

I have implemented a somehow good tangent stiffness matrix for 1d composite section (like concrete members etc.) in my masters thesis and during last few years (based on formulas proposed in this article, soon I'll publish in github,

So we can have:

I think this is all we need to implement a good static nonlinear finite element analyzer for structures with concrete or steel members that have new features, at least in domain of opensource software! Just we need a little effort to combine those into one working package.

footnote: I've tagged the guy that does have already implemented arc-length, @EduardBargues. Dear Mr. Eduard Bargues, Can you please take a look at this topic from my first post? Thanks...

I'm OK if you want to continue conversation privately about this topic, via email and CC etc. .

EduardBargues commented 4 years ago

Hello guys!! I see youve been having a really interesting conversation :). Indeed my library already implements arclength for solving nonlinear system of equations. Currently, it uses math.net to manage matrices and vectors and it is not optimized neither for sparse or simmetric matrices. But still works find for limited sized systems (less than 100000 dof). I tried in my master thesis and seemed to work okay. It is true that, in general, a nonlinear analysis can not assume sdp matrices. Tomorrow ill check again your whole conversation to get some ideas on what you want to accomplish. Talk soon!

epsi1on commented 4 years ago

@wo80 , do you have any suggestion for iterative solver for non SPD matrices? You already have contributed PCG to BFE, but as I know the PCG is only for SPD matrices.

Thanks

epsi1on commented 4 years ago

Currently, it uses math.net to manage matrices and vectors and it is not optimized neither for sparse or simmetric matrices. But still works find for limited sized systems (less than 100000 dof). I tried in my master thesis and seemed to work okay.

So math.net should use sparse matrix as 100K dof will cause 100k*100k dense stiffness matrix, which will have 10Billion members, each member 8 byte as double precision data type, and total 80GB of memory is used for only storage only, matrix operations are not counted yet. Am i right on mathnet also uses sparse matrix on this?

wo80 commented 4 years ago

For symmetric, but not positive definite matrices MINRES is a good choice. For general matrices, I like to use Bi-CGSTAB. See http://www.netlib.org/utk/people/JackDongarra/etemplates/node390.html. If you want to get started soon, I'll try to publish some code this weekend or within the next week.

@EduardBargues
Regarding the NonLinearEquationsSolver project: at the moment, it uses dense matrices and any call to matrix.Solve(rhs) (Predictor, Corrector and Solver classes) will perform a dense LU decomposition. This is not desirable with matrices of the size @epsi1on mentioned. I'd suggest to add a ISolver interface into the builder process to be able to configure the solver.

EDIT: Math.NET has a few iterative solvers, see src/Numerics/LinearAlgebra/Double/Solvers. Be aware that only the MILU0 preconditioner is optimized for sparse matrices, so a good combination would be BiCgStab+MILU0.

EDIT 2: also be aware, that Math.NET has no direct solvers for sparse matrices, see Math.NET Numerics and CSparse.

EduardBargues commented 4 years ago

that's a great explanation @wo80 !! :) Do you think we can arrange a meeting to discuss it in more detail? I'm still refatoring the code one part at a time.

EduardBargues commented 4 years ago

@epsi1on , I put an extra 0 on the dimension of the matrix :P ... Also, Math.Net does not use sparse matrices.

EduardBargues commented 4 years ago

Hello @epsi1on and @wo80 . I opened a pull-request in my repo where I include a solver interface to allow the use of sparse matrices. I also invited you both to become collaborators so you can review the pull-request. Let me know :) !