diff --git a/tbox/_src/tboxw.i b/tbox/_src/tboxw.i index 8f2c75bb2992ad3b81321d6c894916e5f138aab4..135b6a94aeca4184098dd2ad2ef54ffaefd6aa7d 100644 --- a/tbox/_src/tboxw.i +++ b/tbox/_src/tboxw.i @@ -97,9 +97,7 @@ namespace std { %include "wNode.h" %nodefault tbox::Element; // Element is pure virtual but swig doesn't know it. -%warnfilter(509); // Shadowed overloaded method MATTYPE. Code compiling and running. %include "wElement.h" -%warnfilter(+509); %include "wTag.h" %include "wQuad4.h" %include "wTetra4.h" diff --git a/tbox/src/wDss.cpp b/tbox/src/wDss.cpp index d29dceb634fde03baabc1912417de9218db5f132..3aaf5235356874006cedd45b5d30a5b8c50df7c5 100644 --- a/tbox/src/wDss.cpp +++ b/tbox/src/wDss.cpp @@ -94,7 +94,7 @@ void Dss::print(int cod) void Dss::write(std::ostream &out) const { - out << "DSS (MKL)" << std::endl; + out << "Intel MKL DSS (PARDISO)" << std::endl; } #endif // USE_MKL diff --git a/tbox/src/wDss.h b/tbox/src/wDss.h index a7e3d2de9e9347abc94f36ca8bf8d34f2e8cfdd6..6994db0b587d526387f36d7e116928e3a35f7876 100644 --- a/tbox/src/wDss.h +++ b/tbox/src/wDss.h @@ -40,6 +40,7 @@ class TBOX_API Dss : public LinearSolver public: Dss(); ~Dss(); + virtual LSOLTYPE type() const { return LSOLTYPE::DSS; } #ifndef SWIG virtual void analyze(Eigen::SparseMatrix<double> const &A) override; diff --git a/tbox/src/wGmres.cpp b/tbox/src/wGmres.cpp index b708c6e54fb045932d808cc5ddcbd9ef39158fa2..40a7db3c275cf368865dd5bc15e948e7f8a3a378 100644 --- a/tbox/src/wGmres.cpp +++ b/tbox/src/wGmres.cpp @@ -17,14 +17,14 @@ #include "wGmres.h" using namespace tbox; -Gmres::Gmres() : LinearSolver() +Gmres::Gmres(int _fill, double _tsh, int _rst, double _tol, int _mit) : LinearSolver(), fill(_fill), tsh(_tsh), rst(_rst), tol(_tol), mit(_mit) { - // set the preconditioner and solver parameters to "good" starting values - solver.preconditioner().setFillfactor(1); - solver.preconditioner().setDroptol(1e-6); - solver.set_restart(50); - solver.setTolerance(1e-8); - solver.setMaxIterations(1000); + // set the preconditioner and solver parameters + solver.preconditioner().setFillfactor(fill); + solver.preconditioner().setDroptol(tsh); + solver.set_restart(rst); + solver.setTolerance(tol); + solver.setMaxIterations(mit); } void Gmres::analyze(Eigen::SparseMatrix<double> const &A) @@ -45,7 +45,13 @@ void Gmres::compute(Eigen::SparseMatrix<double> const &A, Eigen::Map<Eigen::Vect x = solver.solve(b); } +void Gmres::setTolerance(double t) +{ + tol = t; + solver.setTolerance(t); +} + void Gmres::write(std::ostream &out) const { - out << "GMRES (Eigen)" << std::endl; + out << "Eigen GMRES(" << rst << "," << static_cast<int>(log10(tol)) << ")/ILUT(" << fill << "," << static_cast<int>(log10(tsh)) << ")" << std::endl; } diff --git a/tbox/src/wGmres.h b/tbox/src/wGmres.h index 105706918f1ea9062d25840566518ae3171f0eaf..2a0de151eab5c867d8bd3006454a64b2682c3935 100644 --- a/tbox/src/wGmres.h +++ b/tbox/src/wGmres.h @@ -30,11 +30,18 @@ namespace tbox */ class TBOX_API Gmres : public LinearSolver { + int fill; // fill-in factor for ILUT + double tsh; // drop tolerance threshold for ILUT + int rst; // number of iterations before restart for GMRES + double tol; // relative tolerance for GMRES + int mit; // maximum number of iterations for GMRES Eigen::GMRES<Eigen::SparseMatrix<double>, Eigen::IncompleteLUT<double>> solver; public: - Gmres(); + Gmres(int _fill = 1, double _tsh = 1e-6, int _rst = 30, double _tol = 1e-8, int _mit = 1000); + Gmres(const Gmres &gmres) : Gmres(gmres.fill, gmres.tsh, gmres.rst, gmres.tol, gmres.mit) {} virtual ~Gmres() {} + virtual LSOLTYPE type() const override { return LSOLTYPE::GMRES_ILUT; } #ifndef SWIG virtual void analyze(Eigen::SparseMatrix<double> const &A) override; @@ -45,17 +52,10 @@ public: virtual double getError() override { return solver.error(); } virtual int getIterations() override { return static_cast<int>(solver.iterations()); } + void setTolerance(double t); + virtual void write(std::ostream &out) const override; #endif - - void setFillFactor(int f) - { - solver.preconditioner().setFillfactor(f); - } - void setDropTol(double t) { solver.preconditioner().setDroptol(t); } - void setTolerance(double t) { solver.setTolerance(t); } - void setRestart(int r) { solver.set_restart(r); } - void setMaxIterations(int n) { solver.setMaxIterations(n); } }; } // namespace tbox diff --git a/tbox/src/wGmshExport.h b/tbox/src/wGmshExport.h index eefcf4470d05730ceeaa7aba8552ae93c06c15bd..0ba8b0bb76aa1f02bc9dc8486ee44a7c8eee874b 100644 --- a/tbox/src/wGmshExport.h +++ b/tbox/src/wGmshExport.h @@ -34,6 +34,7 @@ class TBOX_API GmshExport : public MshExport public: GmshExport(std::shared_ptr<MshData> _msh); virtual ~GmshExport(); + virtual WRTTYPE type() const override { return WRTTYPE::GMSH; } virtual void save(std::string const &fname) const override; #ifndef SWIG @@ -45,4 +46,4 @@ public: } // namespace tbox -#endif //WGMSHUTILS_H +#endif // WGMSHEXPORT_H diff --git a/tbox/src/wLinearSolver.h b/tbox/src/wLinearSolver.h index 3e93813a4db7b1899b03c5fd6cfb80b81c44bfd6..575f0c2b769e4593a93da702282055ae9e0105a4 100644 --- a/tbox/src/wLinearSolver.h +++ b/tbox/src/wLinearSolver.h @@ -24,6 +24,20 @@ namespace tbox { +/** + * @brief Solver type + * @authors Adrien Crovato + */ +enum class LSOLTYPE +{ + UNDEFINED = 0, + SPARSE_LU = 1, + GMRES_ILUT = 2, + PARDISO = 3, + DSS = 4, + MUMPS = 5 +}; + /** * @brief Base interface class for linear solvers * @authors Adrien Crovato @@ -33,6 +47,7 @@ class TBOX_API LinearSolver : public fwk::wSharedObject public: LinearSolver() {} virtual ~LinearSolver() {} + virtual LSOLTYPE type() const { return LSOLTYPE::UNDEFINED; } #ifndef SWIG virtual void analyze(Eigen::SparseMatrix<double> const &A); diff --git a/tbox/src/wMshDeform.cpp b/tbox/src/wMshDeform.cpp index 1c2009ca9bb360142bb2b86a43e3f79949c08795..72a3a5e3abf05212584621874ed0ce461aa76473 100644 --- a/tbox/src/wMshDeform.cpp +++ b/tbox/src/wMshDeform.cpp @@ -32,10 +32,10 @@ using namespace tbox; MshDeform::MshDeform(std::shared_ptr<MshData> _msh, std::shared_ptr<tbox::LinearSolver> _linsol, - int _nDim, int nthrds) : wSharedObject(), linsol(_linsol), + int _nDim, int nthrds) : wSharedObject(), nDim(_nDim), nthreads(nthrds), - field(false), fixed(false), - moving(false), msh(_msh) + field(false), fixed(false), moving(false), + msh(_msh), linsol(_linsol) { // Check problem dimension if (nDim != 2 && nDim != 3) diff --git a/tbox/src/wMshDeform.h b/tbox/src/wMshDeform.h index 839001d1343571b831197c40cf4896c713dd8d55..91b76867e149851751c0b800d98680d1e206a5ec 100644 --- a/tbox/src/wMshDeform.h +++ b/tbox/src/wMshDeform.h @@ -34,7 +34,6 @@ namespace tbox class TBOX_API MshDeform : public fwk::wSharedObject { private: - std::shared_ptr<tbox::LinearSolver> linsol; ///< linear (inner) solver size_t mshSize; ///< number of nodes in the mesh int nDim; ///< dimension of the problem (2 or 3) int nthreads; ///< number of threads @@ -62,7 +61,8 @@ private: Eigen::MatrixXd buildK(tbox::Element const &e, Eigen::MatrixXd const &H); public: - std::shared_ptr<MshData> msh; ///< mesh + std::shared_ptr<MshData> msh; ///< mesh + std::shared_ptr<tbox::LinearSolver> linsol; ///< linear (inner) solver MshDeform(std::shared_ptr<MshData> _msh, std::shared_ptr<tbox::LinearSolver> _linsol, int _nDim, int nthrds = 1); virtual ~MshDeform() { std::cout << "~MshDeform()\n"; } @@ -85,4 +85,4 @@ public: } // namespace tbox -#endif //WMSHDEFORM_H \ No newline at end of file +#endif // WMSHDEFORM_H \ No newline at end of file diff --git a/tbox/src/wMshExport.h b/tbox/src/wMshExport.h index 50627aa1df3ce090c589b2853ced287dbaa5449d..fad7cf4e22dbd8c7c0522ab098e4f95938753408 100644 --- a/tbox/src/wMshExport.h +++ b/tbox/src/wMshExport.h @@ -25,6 +25,17 @@ namespace tbox { +/** + * @brief Writer type + * @authors Adrien Crovato + */ +enum class WRTTYPE +{ + UNDEFINED = 0, + GMSH = 1, + VTK = 2 +}; + /** * @brief Base class to write mesh * @authors Adrien Crovato, Romain Boman @@ -38,6 +49,7 @@ public: MshExport(std::shared_ptr<MshData> _msh); virtual ~MshExport() {} + virtual WRTTYPE type() const { return WRTTYPE::UNDEFINED; } virtual void save(std::string const &fname) const; #ifndef SWIG @@ -47,4 +59,4 @@ public: } // namespace tbox -#endif //WMSHEXPORT_H +#endif // WMSHEXPORT_H diff --git a/tbox/src/wMumps.h b/tbox/src/wMumps.h index 479d29f551fc5717078f53ff3269516d115a9191..518fc4d7eac131a069a8f4cb87e53735947b2610 100644 --- a/tbox/src/wMumps.h +++ b/tbox/src/wMumps.h @@ -53,6 +53,7 @@ private: public: Mumps(); ~Mumps(); + virtual LSOLTYPE type() const override { return LSOLTYPE::MUMPS; } #ifndef SWIG virtual void analyze(Eigen::SparseMatrix<double> const &A) override; diff --git a/tbox/src/wPardiso.cpp b/tbox/src/wPardiso.cpp index 01a589036b406527c7995d4d20c940fb83871dd8..dc9b8201f5213ff70e544d98c650c563a8f12def 100644 --- a/tbox/src/wPardiso.cpp +++ b/tbox/src/wPardiso.cpp @@ -50,7 +50,7 @@ void Pardiso::setOption(int k, int v) void Pardiso::write(std::ostream &out) const { - out << "Pardiso (MKL/Eigen)" << std::endl; + out << "Eigen Intel MKL PARDISO" << std::endl; } #endif // USE_MKL diff --git a/tbox/src/wPardiso.h b/tbox/src/wPardiso.h index 5936fe69e72896615cf63cfddcc1185c53351cd5..e8cdd63124bba0b718a33a01c726125a6f0fdece 100644 --- a/tbox/src/wPardiso.h +++ b/tbox/src/wPardiso.h @@ -38,6 +38,7 @@ class TBOX_API Pardiso : public LinearSolver public: Pardiso() : LinearSolver() {} virtual ~Pardiso() {} + virtual LSOLTYPE type() const override { return LSOLTYPE::PARDISO; } #ifndef SWIG virtual void analyze(Eigen::SparseMatrix<double> const &A) override; diff --git a/tbox/src/wSparseLu.cpp b/tbox/src/wSparseLu.cpp index e22a5271e90e83c8a00158b501a11a2b0ba30c3c..50bfb308e5a083ff0fd8a55c0e2905b1fd3de2e7 100644 --- a/tbox/src/wSparseLu.cpp +++ b/tbox/src/wSparseLu.cpp @@ -37,5 +37,5 @@ void SparseLu::compute(Eigen::SparseMatrix<double> const &A, Eigen::Map<Eigen::V void SparseLu::write(std::ostream &out) const { - out << "SparseLU (Eigen)" << std::endl; + out << "Eigen SparseLU" << std::endl; } diff --git a/tbox/src/wSparseLu.h b/tbox/src/wSparseLu.h index 323a5d628b90e522114ed53e33f46f1c29ae9345..16768eeb508498253f9268a64811dd286798fbcc 100644 --- a/tbox/src/wSparseLu.h +++ b/tbox/src/wSparseLu.h @@ -38,6 +38,7 @@ class TBOX_API SparseLu : public LinearSolver public: SparseLu() : LinearSolver() {} virtual ~SparseLu() {} + virtual LSOLTYPE type() const override { return LSOLTYPE::SPARSE_LU; } #ifndef SWIG virtual void analyze(Eigen::SparseMatrix<double> const &A) override; diff --git a/tboxVtk/src/wVtkExport.h b/tboxVtk/src/wVtkExport.h index 8dea4d0fdfd78c8a35c0ee1db8991a4e7ce4932b..7077c3058154b3a5a72a7f5c4b629e4a5a3a5173 100644 --- a/tboxVtk/src/wVtkExport.h +++ b/tboxVtk/src/wVtkExport.h @@ -44,6 +44,7 @@ class TBOXVTK_API VtkExport : public tbox::MshExport public: VtkExport(std::shared_ptr<tbox::MshData> _msh); virtual ~VtkExport(); + virtual tbox::WRTTYPE type() const { return tbox::WRTTYPE::VTK; } virtual void save(std::string const &fname) const override; #ifndef SWIG @@ -55,4 +56,4 @@ public: } // namespace tboxVtk -#endif //WGMSHUTILS_H +#endif // WVTKEXPORT_H