From 67e98eb9004e43f9cc7c93159ea309d9301b790e Mon Sep 17 00:00:00 2001
From: Thomas Toulorge <thomas.toulorge@mines-paristech.fr>
Date: Mon, 22 Sep 2014 15:47:08 +0000
Subject: [PATCH] Changer handling of results in general optimizer, added CAD
 distance to high order optimizer.

---
 .../OptHomObjContribCADDist.h                 |  9 ----
 .../OptHomObjContribMetricMin.h               |  9 ----
 .../OptHomObjContribScaledJac.h               |  9 ----
 contrib/HighOrderMeshOptimizer/OptHomRun.cpp  | 46 +++++++++++--------
 contrib/MeshOptimizer/CMakeLists.txt          |  1 -
 contrib/MeshOptimizer/MeshOpt.cpp             |  4 +-
 contrib/MeshOptimizer/MeshOpt.h               |  2 +-
 contrib/MeshOptimizer/MeshOptCommon.cpp       | 14 ------
 contrib/MeshOptimizer/MeshOptCommon.h         | 17 ++-----
 contrib/MeshOptimizer/MeshOptObjContrib.cpp   |  9 +++-
 contrib/MeshOptimizer/MeshOptObjContrib.h     |  3 +-
 .../MeshOptimizer/MeshOptObjContribFunc.cpp   | 27 +++++++++++
 contrib/MeshOptimizer/MeshOptObjContribFunc.h | 15 ++++++
 .../MeshOptObjContribScaledNodeDispSq.h       | 10 ----
 .../MeshOptObjectiveFunction.cpp              |  4 +-
 .../MeshOptimizer/MeshOptObjectiveFunction.h  |  3 +-
 contrib/MeshOptimizer/MeshOptimizer.cpp       | 33 +++++++------
 contrib/MeshOptimizer/MeshOptimizer.h         |  3 +-
 18 files changed, 104 insertions(+), 114 deletions(-)
 delete mode 100644 contrib/MeshOptimizer/MeshOptCommon.cpp

diff --git a/contrib/HighOrderMeshOptimizer/OptHomObjContribCADDist.h b/contrib/HighOrderMeshOptimizer/OptHomObjContribCADDist.h
index 40aeccd354..75e225fa95 100644
--- a/contrib/HighOrderMeshOptimizer/OptHomObjContribCADDist.h
+++ b/contrib/HighOrderMeshOptimizer/OptHomObjContribCADDist.h
@@ -20,7 +20,6 @@ public:
   virtual bool targetReached() { return FuncType::targetReached(_min, _max); }
   virtual bool stagnated() { return FuncType::stagnated(_min, _max); }
   virtual void updateMinMax();
-  virtual void updateResults(MeshOptResults &res) const;
 
 protected:
   Patch *_mesh;
@@ -94,12 +93,4 @@ void ObjContribCADDist<FuncType>::updateMinMax()
 }
 
 
-template<class FuncType>
-void ObjContribCADDist<FuncType>::updateResults(MeshOptResults &res) const
-{
-  res.minCADDist = std::min(_min, res.minCADDist);
-  res.maxCADDist = std::max(_max, res.maxCADDist);
-}
-
-
 #endif /* _OPTHOMOBJCONTRIBCADDIST_H_ */
diff --git a/contrib/HighOrderMeshOptimizer/OptHomObjContribMetricMin.h b/contrib/HighOrderMeshOptimizer/OptHomObjContribMetricMin.h
index b86b383e1c..b3b7bb3975 100644
--- a/contrib/HighOrderMeshOptimizer/OptHomObjContribMetricMin.h
+++ b/contrib/HighOrderMeshOptimizer/OptHomObjContribMetricMin.h
@@ -21,7 +21,6 @@ public:
   virtual bool targetReached() { return FuncType::targetReached(_min, _max); }
   virtual bool stagnated() { return FuncType::stagnated(_min, _max); }
   virtual void updateMinMax();
-  virtual void updateResults(MeshOptResults &res) const;
 
 protected:
   Patch *_mesh;
@@ -96,12 +95,4 @@ void ObjContribMetricMin<FuncType>::updateMinMax()
 }
 
 
-template<class FuncType>
-void ObjContribMetricMin<FuncType>::updateResults(MeshOptResults &res) const
-{
-  res.minMetricMin = std::min(_min, res.minMetricMin);
-  res.maxMetricMin = std::max(_max, res.maxMetricMin);
-}
-
-
 #endif /* _OPTHOMOBJCONTRIBMETRICMIN_H_ */
diff --git a/contrib/HighOrderMeshOptimizer/OptHomObjContribScaledJac.h b/contrib/HighOrderMeshOptimizer/OptHomObjContribScaledJac.h
index 93b3768eeb..ee5a557aa9 100644
--- a/contrib/HighOrderMeshOptimizer/OptHomObjContribScaledJac.h
+++ b/contrib/HighOrderMeshOptimizer/OptHomObjContribScaledJac.h
@@ -21,7 +21,6 @@ public:
   virtual bool targetReached() { return FuncType::targetReached(_min, _max); }
   virtual bool stagnated() { return FuncType::stagnated(_min, _max); }
   virtual void updateMinMax();
-  virtual void updateResults(MeshOptResults &res) const;
 
 protected:
   Patch *_mesh;
@@ -96,12 +95,4 @@ void ObjContribScaledJac<FuncType>::updateMinMax()
 }
 
 
-template<class FuncType>
-void ObjContribScaledJac<FuncType>::updateResults(MeshOptResults &res) const
-{
-  res.minScaledJac = std::min(_min, res.minScaledJac);
-  res.maxScaledJac = std::max(_max, res.maxScaledJac);
-}
-
-
 #endif /* _OPTHOMOBJCONTRIBSCALEDJAC_H_ */
diff --git a/contrib/HighOrderMeshOptimizer/OptHomRun.cpp b/contrib/HighOrderMeshOptimizer/OptHomRun.cpp
index 449bec78de..478b085c81 100644
--- a/contrib/HighOrderMeshOptimizer/OptHomRun.cpp
+++ b/contrib/HighOrderMeshOptimizer/OptHomRun.cpp
@@ -757,11 +757,13 @@ struct HOPatchDefParameters : public MeshOptParameters::PatchDefParameters
 {
   HOPatchDefParameters(const OptHomParameters &p);
   virtual ~HOPatchDefParameters() {}
-  virtual double elBadness(const MElement *el);
+  virtual double elBadness(MElement *el);
   virtual double maxDistance(const MElement *el);
 private:
   double jacMin, jacMax;
   double distanceFactor;
+  bool optCAD;
+  double optCADDistMax, optCADWeight, discrTolerance;
 };
 
 
@@ -781,13 +783,22 @@ HOPatchDefParameters::HOPatchDefParameters(const OptHomParameters &p)
     maxLayersAdaptFact = p.adaptBlobLayerFact;
     distanceAdaptFact = p.adaptBlobDistFact;
   }
+  optCAD = p.optCAD;
+  optCADDistMax = p.optCADDistMax;
+  optCADWeight = p.optCADWeight;
+  discrTolerance = p.discrTolerance;
 }
 
 
-double HOPatchDefParameters::elBadness(const MElement *el) {
+double HOPatchDefParameters::elBadness(MElement *el) {
   double jmin, jmax;
   el->scaledJacRange(jmin, jmax);
-  return std::min(jmin-jacMin, 0.) + std::min(jacMax-jmax, 0.);
+  double badness = std::min(jmin-jacMin, 0.) + std::min(jacMax-jmax, 0.);
+  if (optCAD) {
+    const double dist = computeBndDist(el, 2, fabs(discrTolerance));
+    badness += optCADWeight*std::min(optCADDistMax-dist, 0.);
+  }
+  return badness;
 }
 
 
@@ -814,37 +825,32 @@ void HighOrderMeshOptimizerNew(GModel *gm, OptHomParameters &p)
   minJacBarFunc.setTarget(p.BARRIER_MIN, 1.);
   ObjContribScaledJac<ObjContribFuncBarrierFixMinMovMax> minMaxJacBarFunc(1.);
   minMaxJacBarFunc.setTarget(p.BARRIER_MAX, 1.);
-  ObjContribCADDist<ObjContribFuncSimple> CADDistFunc(p.optCADWeight, p.discrTolerance);
+  ObjContribCADDist<ObjContribFuncSimpleTargetMin> CADDistFunc(p.optCADWeight, p.discrTolerance);
+  CADDistFunc.setTarget(p.optCADDistMax);
 
   MeshOptParameters::PassParameters minJacPass;
   minJacPass.barrierIterMax = p.optPassMax;
   minJacPass.optIterMax = p.itMax;
-  minJacPass.contrib.resize(2);
-  minJacPass.contrib[0] = &nodeDistFunc;
-  minJacPass.contrib[1] = &minJacBarFunc;
+  minJacPass.contrib.push_back(&nodeDistFunc);
+  minJacPass.contrib.push_back(&minJacBarFunc);
+  if (p.optCAD) minJacPass.contrib.push_back(&CADDistFunc);
   par.pass.push_back(minJacPass);
 
   if (p.BARRIER_MAX > 0.) {
     MeshOptParameters::PassParameters minMaxJacPass;
     minMaxJacPass.barrierIterMax = p.optPassMax;
     minMaxJacPass.optIterMax = p.itMax;
-    minMaxJacPass.contrib.resize(2);
-    minMaxJacPass.contrib[0] = &nodeDistFunc;
-    minMaxJacPass.contrib[1] = &minMaxJacBarFunc;
+    minMaxJacPass.contrib.push_back(&nodeDistFunc);
+    minMaxJacPass.contrib.push_back(&minMaxJacBarFunc);
+    if (p.optCAD) minJacPass.contrib.push_back(&CADDistFunc);
     par.pass.push_back(minMaxJacPass);
   }
 
-  if (p.optCAD) {
-
-  }
-
-  MeshOptResults res;
-
-  meshOptimizer(gm, par, res);
+  meshOptimizer(gm, par);
 
-  p.CPU = res.CPU;
-  p.minJac = res.minScaledJac;
-  p.maxJac = res.maxScaledJac;
+  p.CPU = par.CPU;
+  p.minJac = minMaxJacBarFunc.getMin();
+  p.maxJac = minMaxJacBarFunc.getMax();
 
   Msg::StatusBar(true, "Done optimizing high order mesh (%g s)", p.CPU);
 }
diff --git a/contrib/MeshOptimizer/CMakeLists.txt b/contrib/MeshOptimizer/CMakeLists.txt
index cc41baa392..525303ecd0 100644
--- a/contrib/MeshOptimizer/CMakeLists.txt
+++ b/contrib/MeshOptimizer/CMakeLists.txt
@@ -11,7 +11,6 @@ set(SRC
   MeshOptObjContrib.cpp
   MeshOptObjContribFunc.cpp
   MeshOptVertexCoord.cpp
-  MeshOptCommon.cpp 
 )
 
 file(GLOB_RECURSE HDR RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.hpp)
diff --git a/contrib/MeshOptimizer/MeshOpt.cpp b/contrib/MeshOptimizer/MeshOpt.cpp
index d483b0d8a2..6f29b5ab85 100644
--- a/contrib/MeshOptimizer/MeshOpt.cpp
+++ b/contrib/MeshOptimizer/MeshOpt.cpp
@@ -123,9 +123,9 @@ void MeshOpt::calcScale(alglib::real_1d_array &scale)
 }
 
 
-void MeshOpt::updateResults(MeshOptResults &res)
+void MeshOpt::updateResults()
 {
-  _objFunc->updateResults(res);
+  _objFunc->updateResults();
 }
 
 
diff --git a/contrib/MeshOptimizer/MeshOpt.h b/contrib/MeshOptimizer/MeshOpt.h
index fc3f881f05..f0ba9f8416 100644
--- a/contrib/MeshOptimizer/MeshOpt.h
+++ b/contrib/MeshOptimizer/MeshOpt.h
@@ -53,7 +53,7 @@ public:
   ~MeshOpt();
   int optimize(const MeshOptParameters &par);
   void updateMesh(const alglib::real_1d_array &x);
-  void updateResults(MeshOptResults &res);
+  void updateResults();
   void evalObjGrad(const alglib::real_1d_array &x,
                     double &Obj, alglib::real_1d_array &gradObj);
   void printProgress(const alglib::real_1d_array &x, double Obj);
diff --git a/contrib/MeshOptimizer/MeshOptCommon.cpp b/contrib/MeshOptimizer/MeshOptCommon.cpp
deleted file mode 100644
index 9d9c840496..0000000000
--- a/contrib/MeshOptimizer/MeshOptCommon.cpp
+++ /dev/null
@@ -1,14 +0,0 @@
-// TODO: Copyright
-
-#include "MeshOptCommon.h"
-
-
-const double MeshOptResults::BIGVAL = 1.e300;
-
-
-MeshOptResults::MeshOptResults() :
-  success(-1), CPU(0.), minNodeDisp(BIGVAL), maxNodeDisp(-BIGVAL),
-  minScaledJac(BIGVAL), maxScaledJac(-BIGVAL), minMetricMin(BIGVAL),
-  maxMetricMin(-BIGVAL)
-{
-}
diff --git a/contrib/MeshOptimizer/MeshOptCommon.h b/contrib/MeshOptimizer/MeshOptCommon.h
index 4b5ade040f..80fd94edae 100644
--- a/contrib/MeshOptimizer/MeshOptCommon.h
+++ b/contrib/MeshOptimizer/MeshOptCommon.h
@@ -37,19 +37,6 @@ class MElement;
 class ObjContrib;
 
 
-struct MeshOptResults {                             // Output of mesh optimization
-  int success;                                      // Success flag: -1 = fail, 0 = partial fail (target not reached), 1 = success
-  double CPU;                                       // Time for optimization
-  double minNodeDisp, maxNodeDisp;                  // Range of node displacement
-  double minScaledJac, maxScaledJac;                // Range of Scaled Jacobians
-  double minMetricMin, maxMetricMin;                // Range of min. of metric
-  double minCADDist, maxCADDist;                    // Range of distance to CAD
-  MeshOptResults();
-private:
-  static const double BIGVAL;
-};
-
-
 struct MeshOptParameters {                             // Parameters controlling the strategy
   enum { STRAT_CONNECTED, STRAT_ONEBYONE };
   struct PassParameters {                              // Parameters controlling the optimization procedure in each pass
@@ -68,7 +55,7 @@ struct MeshOptParameters {                             // Parameters controlling
       };
       bool weakMerge;                                   // If connected strategy: weak or strong merging of patches
     };
-    virtual double elBadness(const MElement *el) = 0;   // Pointer to function returning "badness" of element (for patch creation)
+    virtual double elBadness(MElement *el) = 0;         // Pointer to function returning "badness" of element (for patch creation)
     virtual double maxDistance(const MElement *el) = 0; // Pointer to function checking the patch distance criterion for a given bad element
   };
   int dim ;                                             // Which dimension to optimize
@@ -78,6 +65,8 @@ struct MeshOptParameters {                             // Parameters controlling
   std::vector<PassParameters> pass;
   int optDisplay;                                       // Sampling rate in opt. iterations for display
   int verbose;                                          // Level of information displayed and written to disk
+  int success;                                          // Success flag: -1 = fail, 0 = partial fail (target not reached), 1 = success
+  double CPU;                                           // Time for optimization
 };
 
 
diff --git a/contrib/MeshOptimizer/MeshOptObjContrib.cpp b/contrib/MeshOptimizer/MeshOptObjContrib.cpp
index 800447933a..fa244521ec 100644
--- a/contrib/MeshOptimizer/MeshOptObjContrib.cpp
+++ b/contrib/MeshOptimizer/MeshOptObjContrib.cpp
@@ -7,6 +7,13 @@ const double ObjContrib::BIGVAL = 1.e300;
 
 
 ObjContrib::ObjContrib(std::string mesName, std::string name) :
- _min(0.), _max(0.), _measureName(mesName), _name(name)
+ _parent(this), _min(BIGVAL), _max(-BIGVAL), _measureName(mesName), _name(name)
 {
 }
+
+
+void ObjContrib::updateResults()
+{
+  _parent->_min = std::min(_parent->_min, _min);
+  _parent->_max = std::max(_parent->_max, _max);
+}
diff --git a/contrib/MeshOptimizer/MeshOptObjContrib.h b/contrib/MeshOptimizer/MeshOptObjContrib.h
index 91b31b0941..698c56559a 100644
--- a/contrib/MeshOptimizer/MeshOptObjContrib.h
+++ b/contrib/MeshOptimizer/MeshOptObjContrib.h
@@ -28,10 +28,11 @@ public:
   virtual bool targetReached() = 0;
   virtual bool stagnated() = 0;
   virtual void updateMinMax() = 0;
-  virtual void updateResults(MeshOptResults &res) const = 0;
+  void updateResults();
 
 protected:
   static const double BIGVAL;
+  ObjContrib *_parent;
   std::string _measureName, _name;
   double _min, _max;
 };
diff --git a/contrib/MeshOptimizer/MeshOptObjContribFunc.cpp b/contrib/MeshOptimizer/MeshOptObjContribFunc.cpp
index c811ef8fd9..034eb2a1cf 100644
--- a/contrib/MeshOptimizer/MeshOptObjContribFunc.cpp
+++ b/contrib/MeshOptimizer/MeshOptObjContribFunc.cpp
@@ -4,6 +4,33 @@
 #include "MeshOptObjContribFunc.h"
 
 
+const double ObjContribFuncSimpleTargetMin::STAGTHRESHOLD = 0.01;
+
+
+ObjContribFuncSimpleTargetMin::ObjContribFuncSimpleTargetMin() :
+    _target(0.), _init(0.)
+{
+}
+
+
+void ObjContribFuncSimpleTargetMin::setTarget(double target)
+{
+  _target = target;
+}
+
+
+void ObjContribFuncSimpleTargetMin::updateParameters(double vMin, double vMax)
+{
+  _init = vMin;
+}
+
+
+bool ObjContribFuncSimpleTargetMin::stagnated(double vMin, double vMax)
+{
+  return (fabs((vMin-_init)/_init) < STAGTHRESHOLD);
+}
+
+
 const double ObjContribFuncBarrier::LOWMARGINMULT = 0.9;
 const double ObjContribFuncBarrier::UPMARGINMULT = 1.1;
 const double ObjContribFuncBarrier::STAGTHRESHOLD = 0.01;
diff --git a/contrib/MeshOptimizer/MeshOptObjContribFunc.h b/contrib/MeshOptimizer/MeshOptObjContribFunc.h
index fc2ee71de6..118b997703 100644
--- a/contrib/MeshOptimizer/MeshOptObjContribFunc.h
+++ b/contrib/MeshOptimizer/MeshOptObjContribFunc.h
@@ -19,6 +19,21 @@ protected:
 };
 
 
+class ObjContribFuncSimpleTargetMin : public ObjContribFuncSimple
+{
+public:
+  ObjContribFuncSimpleTargetMin();
+  void setTarget(double target);
+
+protected:
+  static const double STAGTHRESHOLD;                                              // Threshold to consider that measures stagnates
+  double _target, _init;
+  void updateParameters(double vMin, double vMax);
+  bool targetReached(double vMin, double vMax) { return (vMin >= _target); }
+  bool stagnated(double vMin, double vMax);
+};
+
+
 class ObjContribFuncBarrier
 {
 public:
diff --git a/contrib/MeshOptimizer/MeshOptObjContribScaledNodeDispSq.h b/contrib/MeshOptimizer/MeshOptObjContribScaledNodeDispSq.h
index b8cb7b8313..070d744447 100644
--- a/contrib/MeshOptimizer/MeshOptObjContribScaledNodeDispSq.h
+++ b/contrib/MeshOptimizer/MeshOptObjContribScaledNodeDispSq.h
@@ -21,7 +21,6 @@ public:
   virtual bool targetReached() { return FuncType::targetReached(_min, _max); }
   virtual bool stagnated() { return FuncType::stagnated(_min, _max); }
   virtual void updateMinMax();
-  virtual void updateResults(MeshOptResults &res) const;
 
 protected:
   Patch *_mesh;
@@ -94,13 +93,4 @@ void ObjContribScaledNodeDispSq<FuncType>::updateMinMax()
 }
 
 
-template<class FuncType>
-void ObjContribScaledNodeDispSq<FuncType>::updateResults(MeshOptResults &res) const
-{
-  const double scaleSq = 1./_mesh->invLengthScaleSq();
-  res.minNodeDisp = std::min(sqrt(_min*scaleSq), res.minNodeDisp);
-  res.maxNodeDisp = std::max(sqrt(_max*scaleSq), res.maxNodeDisp);
-}
-
-
 #endif /* _MESHOPTOBJCONTRIBSCALEDNODEDISPSQ_H_ */
diff --git a/contrib/MeshOptimizer/MeshOptObjectiveFunction.cpp b/contrib/MeshOptimizer/MeshOptObjectiveFunction.cpp
index 3fac82abec..6e0a05039a 100644
--- a/contrib/MeshOptimizer/MeshOptObjectiveFunction.cpp
+++ b/contrib/MeshOptimizer/MeshOptObjectiveFunction.cpp
@@ -48,10 +48,10 @@ void ObjectiveFunction::updateParameters()
 }
 
 
-void ObjectiveFunction::updateResults(MeshOptResults &res)
+void ObjectiveFunction::updateResults()
 {
   for (std::vector<ObjContrib*>::iterator it=begin(); it!=end(); it++)
-    (*it)->updateResults(res);
+    (*it)->updateResults();
 }
 
 
diff --git a/contrib/MeshOptimizer/MeshOptObjectiveFunction.h b/contrib/MeshOptimizer/MeshOptObjectiveFunction.h
index 08e5c95ab1..29d87ec3a7 100644
--- a/contrib/MeshOptimizer/MeshOptObjectiveFunction.h
+++ b/contrib/MeshOptimizer/MeshOptObjectiveFunction.h
@@ -8,7 +8,6 @@
 #include "ap.h"
 
 class ObjContrib;
-class MeshOptResults;
 class Patch;
 
 
@@ -20,7 +19,7 @@ public:
   std::string minMaxStr();
   void updateMinMax();
   void updateParameters();
-  void updateResults(MeshOptResults &res);
+  void updateResults();
   bool stagnated();
   bool targetReached();
   std::string failMeasures();
diff --git a/contrib/MeshOptimizer/MeshOptimizer.cpp b/contrib/MeshOptimizer/MeshOptimizer.cpp
index 240a6351e1..61053b12c0 100644
--- a/contrib/MeshOptimizer/MeshOptimizer.cpp
+++ b/contrib/MeshOptimizer/MeshOptimizer.cpp
@@ -252,10 +252,9 @@ static std::vector<std::pair<std::set<MElement*>, std::set<MVertex*> > > getConn
 static void optimizeConnectedPatches
   (const std::map<MVertex*, std::vector<MElement *> > &vertex2elements,
    const std::map<MElement*,GEntity*> &element2entity,
-   std::set<MElement*> &badasses,
-   MeshOptParameters &par, MeshOptResults &res)
+   std::set<MElement*> &badasses, MeshOptParameters &par)
 {
-  res.success = 1;
+  par.success = 1;
 
   std::vector<std::pair<std::set<MElement*>, std::set<MVertex*> > > toOptimize =
                               getConnectedPatches(vertex2elements, badasses, par);
@@ -288,11 +287,11 @@ static void optimizeConnectedPatches
     }
 
     // Evaluate mesh and update it if (partial) success
-    opt.updateResults(res);
+    opt.updateResults();
     if (success >= 0) opt.patch.updateGEntityPositions();
 
     //#pragma omp critical
-    res.success = std::min(res.success, success);
+    par.success = std::min(par.success, success);
   }
 
 }
@@ -318,9 +317,9 @@ static MElement *getWorstElement(std::set<MElement*> &badElts, const MeshOptPara
 static void optimizeOneByOne
   (const std::map<MVertex*, std::vector<MElement *> > &vertex2elements,
    const std::map<MElement*,GEntity*> &element2entity,
-   std::set<MElement*> badElts, MeshOptParameters &par, MeshOptResults &res)
+   std::set<MElement*> badElts, MeshOptParameters &par)
 {
-  res.success = 1;
+  par.success = 1;
 
   const int initNumBadElts = badElts.size();
   if (par.verbose > 0) Msg::Info("%d bad elements, starting to iterate...", initNumBadElts);
@@ -380,7 +379,7 @@ static void optimizeOneByOne
 
       // If (partial) success, update mesh and break adaptation loop, otherwise adapt
       if ((success > 0) || (iAdapt == par.patchDef->maxAdaptPatch-1)) {
-        opt.updateResults(res);
+        opt.updateResults();
         if (success >= 0) {
           opt.patch.updateGEntityPositions();
           break;
@@ -405,7 +404,7 @@ static void optimizeOneByOne
         case -1: Msg::Info("Patch %i failed", iBadEl); break;
       }
 
-    res.success = std::min(res.success, success);
+    par.success = std::min(par.success, success);
 
   }
 }
@@ -413,7 +412,7 @@ static void optimizeOneByOne
 #endif
 
 
-void meshOptimizer(GModel *gm, MeshOptParameters &par, MeshOptResults &res)
+void meshOptimizer(GModel *gm, MeshOptParameters &par)
 {
 #if defined(HAVE_BFGS)
 
@@ -447,22 +446,22 @@ void meshOptimizer(GModel *gm, MeshOptParameters &par, MeshOptResults &res)
   }
 
   if (par.patchDef->strategy == MeshOptParameters::STRAT_CONNECTED)
-    optimizeConnectedPatches(vertex2elements, element2entity, badElts, par, res);
+    optimizeConnectedPatches(vertex2elements, element2entity, badElts, par);
   else if (par.patchDef->strategy == MeshOptParameters::STRAT_ONEBYONE)
-    optimizeOneByOne(vertex2elements, element2entity, badElts, par, res);
+    optimizeOneByOne(vertex2elements, element2entity, badElts, par);
   else
     Msg::Error("Unknown strategy %d for mesh optimization", par.patchDef->strategy);
 
   if (par.verbose > 0) {
-    if (res.success == 1)
+    if (par.success == 1)
       Msg::Info("Optimization succeeded");
-    else if (res.success == 0)
+    else if (par.success == 0)
       Msg::Warning("Optimization partially failed (all measures above critical "
                     "value, but some below target)");
-    else if (res.success == -1)
+    else if (par.success == -1)
       Msg::Error("Optimization failed (some measures below critical value)");
-    res.CPU = Cpu()-startTime;
-    Msg::StatusBar(true, "Done optimizing mesh (%g s)", res.CPU);
+    par.CPU = Cpu()-startTime;
+    Msg::StatusBar(true, "Done optimizing mesh (%g s)", par.CPU);
   }
 
 
diff --git a/contrib/MeshOptimizer/MeshOptimizer.h b/contrib/MeshOptimizer/MeshOptimizer.h
index 1daf3fe70a..b3ed8940a2 100644
--- a/contrib/MeshOptimizer/MeshOptimizer.h
+++ b/contrib/MeshOptimizer/MeshOptimizer.h
@@ -33,10 +33,9 @@
 
 class GModel;
 class MeshOptParameters;
-class MeshOptResults;
 
 
-void meshOptimizer(GModel *gm, MeshOptParameters &par, MeshOptResults &res);
+void meshOptimizer(GModel *gm, MeshOptParameters &par);
 
 
 #endif
-- 
GitLab