Maksim, Let me start by saying that integrating a new linear solver in Chrono (or more generally within an implicit integrator) is not as simple as being able to solve a linear system once. This is certainly the case for an AMG-preconditioned iterative solver.
Currently, such a solver doesn’t fit well within the current framework. But if you really want to try it, you could hack it by deriving from ChDirectSolverLS. That class will give you the functions necessary to set up the problem matrix from the Chrono system descriptor (look at ChDirectSolverLS::Setup). Chrono uses the Eigen sparse matrix. You’ll have to make sure that is converted to the CSR (I believe) format used by AmgX; one thing you’ll need for that is compress the Eigen matrix (already done in ChDirectSolverLS::Setup). For the solve phase, you’d ideally use a matrix-free approach. As far as I know, AmgX does not do this “out of the box”, but there may be a way to only provide an SPMV function. --Radu From: [email protected] <[email protected]> On Behalf Of Maksym Riabov Sent: Sunday, November 3, 2024 11:47 PM To: ProjectChrono <[email protected]> Subject: [chrono] AmgX parameter question Hello Chrono, After this post<https://urldefense.com/v3/__https:/groups.google.com/g/projectchrono/c/of58DygfuAA__;!!Mak6IKo!IzjUUAQc_uj9xS3w_88-24O4_sj9dpnpHNVOnK-Wc3la05cTct-K-VIvGEdoAl6GV5TpRC5bzkz1IbGE9zk7iQJItQ$>, I've actually sat down to implement AmgX in chrono. It seems easier than I thought... Or at least I think. This is `Setup` from solver: ``` bool ChSolverAmgX::Setup(ChSystemDescriptor& sysd) { // code assuming one AmgX per machine although it may well not be in the case of multiple instances of Chrono // running in paralel AMGX_SAFE_CALL(AMGX_initialize()); // also can be created from a string. You know solvers better, so config up to you. AMGX_SAFE_CALL(AMGX_config_create_from_file(&cfg, "path_to_config_here")) AMGX_resources_create_simple(&rsrc, cfg); AMGX_matrix_create(&A, rsrc, mode); // the code seems to never create the matrices first. AMGX_vector_create(&x, rsrc, mode); AMGX_vector_create(&b, rsrc, mode); AMGX_solver_create(&solver, rsrc, mode, cfg); // sysd.WriteMatrixMtx("where_to_read_matrix_from.", "prefix_sample_", true); // AMGX_read_system(A, b, x, "prefix_sample_.mtx");// this is if we want store and read file. ChSparseMatrix Z; sysd.BuildSystemMatrix(&Z, &m_rhs); AMGX_matrix_upload_all(A, Z., Z.nonZeros(), Z.outerSize(), Z.innerSize(), Z.outerIndexPtr(), Z.innerIndexPtr(), &Z.data(), Z.diagonal().data()); // I'm not dead sure about block_dimx, block_dimy... AMGX_solver_setup(solver, A); // bulk of the matrix setup return true; } ``` The AMGX_matrix_upload_all command is basically to put chrono vectors of data to amgx. So it needs that data for solution. It requires `n`, `block_dimx` and `block_dimy` parameters: [cid:[email protected]] I don't 100% know how solvers work on the inside, so where can I take these values? I understand that these values are arising from bodies and constraints, but I'm not 100% sure. What do I need to input there? Cheers, Maksym Riabov P.S. I'll add the two files that serve as logic, so you may take a look - maybe you'd say something. -- You received this message because you are subscribed to the Google Groups "ProjectChrono" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]<mailto:[email protected]>. To view this discussion visit https://groups.google.com/d/msgid/projectchrono/f120fba4-b8ae-459b-8782-3b029c149ccdn%40googlegroups.com<https://urldefense.com/v3/__https:/groups.google.com/d/msgid/projectchrono/f120fba4-b8ae-459b-8782-3b029c149ccdn*40googlegroups.com?utm_medium=email&utm_source=footer__;JQ!!Mak6IKo!IzjUUAQc_uj9xS3w_88-24O4_sj9dpnpHNVOnK-Wc3la05cTct-K-VIvGEdoAl6GV5TpRC5bzkz1IbGE9zmMf4NvFQ$>. -- You received this message because you are subscribed to the Google Groups "ProjectChrono" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion visit https://groups.google.com/d/msgid/projectchrono/CH3PPF46CDC2185C18F3FBF3B77F1A05472A7512%40CH3PPF46CDC2185.namprd06.prod.outlook.com.
