From d8f925f84c37f0265d34ba165a45efebb9cef76a Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Fri, 15 Feb 2013 14:04:39 +0000
Subject: [PATCH] provide mapping for non-uniform partitioning

---
 Plugin/SimplePartition.cpp | 30 ++++++++++++++++++++++++++++--
 Plugin/SimplePartition.h   |  2 ++
 2 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/Plugin/SimplePartition.cpp b/Plugin/SimplePartition.cpp
index 5ba882e0e2..44ba96b02f 100644
--- a/Plugin/SimplePartition.cpp
+++ b/Plugin/SimplePartition.cpp
@@ -13,6 +13,7 @@
 #include "MQuadrangle.h"
 #include "MFace.h"
 #include "MEdge.h"
+#include "mathEvaluator.h"
 #if defined(HAVE_MESH)
 #include "meshPartition.h"
 #endif
@@ -23,6 +24,10 @@ StringXNumber SimplePartitionOptions_Number[] = {
   {GMSH_FULLRC, "CreateBoundaries", NULL, 1.},
 };
 
+StringXString SimplePartitionOptions_String[] = {
+  {GMSH_FULLRC, "Mapping", NULL, "t"}
+};
+
 extern "C"
 {
   GMSH_Plugin *GMSH_RegisterSimplePartitionPlugin()
@@ -49,11 +54,23 @@ StringXNumber *GMSH_SimplePartitionPlugin::getOption(int iopt)
   return &SimplePartitionOptions_Number[iopt];
 }
 
+int GMSH_SimplePartitionPlugin::getNbOptionsStr() const
+{
+  return sizeof(SimplePartitionOptions_String) / sizeof(StringXString);
+}
+
+StringXString *GMSH_SimplePartitionPlugin::getOptionStr(int iopt)
+{
+  return &SimplePartitionOptions_String[iopt];
+}
+
 PView *GMSH_SimplePartitionPlugin::execute(PView *v)
 {
   int numSlices = (int)SimplePartitionOptions_Number[0].def;
   int direction = (int)SimplePartitionOptions_Number[1].def;
   int createBoundaries = (int)SimplePartitionOptions_Number[2].def;
+  std::vector<std::string> expr(1);
+  expr[0] = SimplePartitionOptions_String[0].def;
 
   // partition the highest dimension elements in the current model (lower
   // dimension elements on boundaries cannot be tagged a priori: there are
@@ -63,8 +80,17 @@ PView *GMSH_SimplePartitionPlugin::execute(PView *v)
   SBoundingBox3d bbox = m->bounds();
   double pmin = bbox.min()[direction], pmax = bbox.max()[direction];
   std::vector<double> pp(numSlices + 1);
-  for(int p = 0; p <= numSlices; p++)
-    pp[p] = pmin + p * (pmax - pmin) / numSlices;
+
+  std::vector<std::string> variables(1);
+  variables[0] = "t";
+  mathEvaluator f(expr, variables);
+  if(expr.empty()) return v;
+  std::vector<double> values(1), res(1);
+  for(int p = 0; p <= numSlices; p++){
+    double t = values[0] = (double)p / (double)numSlices;
+    if(f.eval(values, res)) t = res[0];
+    pp[p] = pmin + t * (pmax - pmin);
+  }
   int dim = m->getDim();
   std::vector<GEntity*> entities;
   m->getEntities(entities);
diff --git a/Plugin/SimplePartition.h b/Plugin/SimplePartition.h
index b436070c46..b04e35e848 100644
--- a/Plugin/SimplePartition.h
+++ b/Plugin/SimplePartition.h
@@ -25,6 +25,8 @@ class GMSH_SimplePartitionPlugin : public GMSH_PostPlugin
   std::string getHelp() const;
   int getNbOptions() const;
   StringXNumber* getOption(int iopt);
+  int getNbOptionsStr() const;
+  StringXString* getOptionStr(int iopt);
   PView *execute(PView *);
 };
 
-- 
GitLab