From baeb2a2c8f986bd17cc06434323fbdaf075624d4 Mon Sep 17 00:00:00 2001
From: acrovato <a.crovato@uliege.be>
Date: Sun, 26 Jun 2022 10:47:39 +0200
Subject: [PATCH] Decrease GMRES tolerance for adjoint mesh morpher, more
 robust.

---
 dart/src/wAdjoint.cpp | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)

diff --git a/dart/src/wAdjoint.cpp b/dart/src/wAdjoint.cpp
index 791ed09..2a24919 100644
--- a/dart/src/wAdjoint.cpp
+++ b/dart/src/wAdjoint.cpp
@@ -58,17 +58,23 @@ Adjoint::Adjoint(std::shared_ptr<Newton> _sol, std::shared_ptr<tbox::MshDeform>
     nthreads = sol->nthreads;
     verbose = sol->verbose;
 
-    // Linear solvers
+    // Linear solvers (if GMRES, use the same, but with a thighter tolerance)
     if (sol->linsol->type() == LSOLTYPE::GMRES_ILUT)
     {
-        // Use the same GMRES, but with a thighter tolerance
         std::shared_ptr<Gmres> gmres = std::make_shared<Gmres>(*dynamic_cast<Gmres *>(sol->linsol.get()));
         gmres->setTolerance(1e-8);
         alinsol = gmres;
     }
     else
         alinsol = sol->linsol;
-    mlinsol = morph->linsol;
+    if (morph->linsol->type() == LSOLTYPE::GMRES_ILUT)
+    {
+        std::shared_ptr<Gmres> gmres = std::make_shared<Gmres>(*dynamic_cast<Gmres *>(morph->linsol.get()));
+        gmres->setTolerance(1e-12);
+        mlinsol = gmres;
+    }
+    else
+        mlinsol = morph->linsol;
 
     // Update element gradients
     sol->pbl->initGradElems();
@@ -423,7 +429,7 @@ void Adjoint::buildGradientLoadsFlow(Eigen::SparseMatrix<double, Eigen::RowMajor
 
 /**
  * @brief Build gradients of the load coefficients with respect to the flow variables on a given body
- * 
+ *
  * Note: this is essentially the same as buildGradientLoadsFlow, but with an additional projection performed inside the loop for performance
  */
 void Adjoint::buildGradientCoefficientsFlow(Eigen::RowVectorXd &dCl, Eigen::RowVectorXd &dCd, Body const &bnd)
@@ -669,7 +675,7 @@ void Adjoint::buildGradientLoadsMesh(Eigen::SparseMatrix<double, Eigen::RowMajor
 
 /**
  * @brief Build gradients of the loads with respect to mesh coordinates on a given body
- * 
+ *
  * Note: this is essentially the same as buildGradientLoadsMesh, but with an additional projection performed inside the loop for performance
  */
 void Adjoint::buildGradientCoefficientsMesh(Eigen::RowVectorXd &dCl, Eigen::RowVectorXd &dCd, Body const &bnd)
-- 
GitLab