diff --git a/applications/TrilinosApplication/custom_python/add_trilinos_space_to_python.cpp b/applications/TrilinosApplication/custom_python/add_trilinos_space_to_python.cpp index f058b711b290..a8280e1c0e72 100644 --- a/applications/TrilinosApplication/custom_python/add_trilinos_space_to_python.cpp +++ b/applications/TrilinosApplication/custom_python/add_trilinos_space_to_python.cpp @@ -313,6 +313,8 @@ void AddBasicOperations(pybind11::module& m) .def("SetValue", SetValue) //.def("GetValue", GetValue) //deliberately commented out. Only works for local Ids .def("GatherValues", GatherValues) + .def_static("IsDistributed", &TrilinosSparseSpaceType::IsDistributed) + .def_static("FastestDirectSolverList", &TrilinosSparseSpaceType::FastestDirectSolverList) ; m.def("CreateCommunicator", CreateCommunicator); diff --git a/applications/TrilinosApplication/trilinos_space.h b/applications/TrilinosApplication/trilinos_space.h index 983284afb8ce..cfc3120c13fc 100644 --- a/applications/TrilinosApplication/trilinos_space.h +++ b/applications/TrilinosApplication/trilinos_space.h @@ -862,6 +862,28 @@ class TrilinosSpace return true; } + /** + * @brief Returns a list of the fastest direct solvers. + * @details This function returns a vector of strings representing the names of the fastest direct solvers. The order of the solvers in the list may need to be updated and reordered depending on the size of the equation system. + * @return A vector of strings containing the names of the fastest direct solvers. + */ + inline static std::vector FastestDirectSolverList() + { + // May need to be updated and reordered. In fact I think it depends of the size of the equation system + std::vector faster_direct_solvers({ + "mumps2", // Amesos2 (if compiled with MUMPS-support) + "mumps", // Amesos (if compiled with MUMPS-support) + "super_lu_dist2", // Amesos2 SuperLUDist (if compiled with MPI-support) + "super_lu_dist", // Amesos SuperLUDist (if compiled with MPI-support) + "amesos2", // Amesos2 + "amesos", // Amesos + "klu2", // Amesos2 KLU + "klu", // Amesos KLU + "basker" // Amesos2 Basker + }); + return faster_direct_solvers; + } + /** * @brief This function returns a value from a given vector according to a given index * @param rX The vector from which values are to be gathered diff --git a/kratos/python/add_sparse_matrices_to_python.cpp b/kratos/python/add_sparse_matrices_to_python.cpp index db7af8d80847..7159e4c7d93a 100644 --- a/kratos/python/add_sparse_matrices_to_python.cpp +++ b/kratos/python/add_sparse_matrices_to_python.cpp @@ -1,4 +1,3 @@ - // | / | // ' / __| _` | __| _ \ __| // . \ | ( | | ( |\__ ` diff --git a/kratos/python/add_strategies_to_python.cpp b/kratos/python/add_strategies_to_python.cpp index f078fd189644..8b1f2035b47b 100644 --- a/kratos/python/add_strategies_to_python.cpp +++ b/kratos/python/add_strategies_to_python.cpp @@ -521,9 +521,16 @@ namespace Kratos:: Python auto sparse_space_binder = CreateSpaceInterface< SparseSpaceType >(m,"UblasSparseSpace"); sparse_space_binder.def("TwoNorm", TwoNorm); - //the dot product of two vectors + // The dot product of two vectors sparse_space_binder.def("Dot", Dot); sparse_space_binder.def("TransposeMult", TransposeMult); + // Size functions + sparse_space_binder.def("Size", &SparseSpaceType::Size); + sparse_space_binder.def("Size1", &SparseSpaceType::Size1); + sparse_space_binder.def("Size2", &SparseSpaceType::Size2); + // Information functions + sparse_space_binder.def("IsDistributed", &SparseSpaceType::IsDistributed); + sparse_space_binder.def("FastestDirectSolverList", &SparseSpaceType::FastestDirectSolverList); auto cplx_sparse_space_binder = CreateSpaceInterface< ComplexSparseSpaceType >(m,"UblasComplexSparseSpace"); diff --git a/kratos/python_scripts/python_linear_solver_factory.py b/kratos/python_scripts/python_linear_solver_factory.py index 6b5a83d798ea..ab83f20e415c 100644 --- a/kratos/python_scripts/python_linear_solver_factory.py +++ b/kratos/python_scripts/python_linear_solver_factory.py @@ -2,7 +2,6 @@ from KratosMultiphysics import kratos_utilities as kratos_utils from importlib import import_module - def ConstructSolver(configuration): if(type(configuration) != KM.Parameters): raise Exception("input is expected to be provided as a Kratos Parameters object") @@ -26,11 +25,7 @@ def CreateFastestAvailableDirectLinearSolver(): if kratos_utils.CheckIfApplicationsAvailable("LinearSolversApplication"): from KratosMultiphysics import LinearSolversApplication - linear_solvers_by_speed = [ - "pardiso_lu", # LinearSolversApplication (if compiled with Intel-support) - "sparse_lu", # LinearSolversApplication - "skyline_lu_factorization" # in Core, always available, but slow - ] + linear_solvers_by_speed = KM.UblasSparseSpace.FastestDirectSolverList() for solver_name in linear_solvers_by_speed: if KM.LinearSolverFactory().Has(solver_name): @@ -41,7 +36,6 @@ def CreateFastestAvailableDirectLinearSolver(): raise Exception("Linear-Solver could not be constructed!") - def __GetSolverTypeAndImportApplication(solver_type): # remove unused "KratosMultiphysics. if solver_type.startswith("KratosMultiphysics."): @@ -57,5 +51,4 @@ def __GetSolverTypeAndImportApplication(solver_type): solver_type = splitted_name[1] import_module("KratosMultiphysics." + app_name) - return solver_type - + return solver_type \ No newline at end of file diff --git a/kratos/spaces/ublas_space.h b/kratos/spaces/ublas_space.h index 558681879d1e..3a95c15054ad 100644 --- a/kratos/spaces/ublas_space.h +++ b/kratos/spaces/ublas_space.h @@ -891,6 +891,22 @@ class UblasSpace return false; } + /** + * @brief Returns a list of the fastest direct solvers. + * @details This function returns a vector of strings representing the names of the fastest direct solvers. The order of the solvers in the list may need to be updated and reordered depending on the size of the equation system. + * @return A vector of strings containing the names of the fastest direct solvers. + */ + inline static std::vector FastestDirectSolverList() + { + std::vector faster_direct_solvers({ + "pardiso_lu", // LinearSolversApplication (if compiled with Intel-support) + "pardiso_ldlt", // LinearSolversApplication (if compiled with Intel-support) + "sparse_lu", // LinearSolversApplication + "skyline_lu_factorization" // In Core, always available, but slow + }); + return faster_direct_solvers; + } + //*********************************************************************** inline static TDataType GetValue(const VectorType& x, std::size_t I)