From 388cdc3b2070e6e6459a5f6af0c1ab7d57393759 Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Thu, 2 Feb 2012 10:27:23 +0000
Subject: [PATCH] tensor pview

---
 Mesh/Field.cpp      | 13 +++++---
 Post/OctreePost.cpp | 76 +++++++++++++++++++++++++++------------------
 Post/OctreePost.h   | 16 +++++-----
 3 files changed, 64 insertions(+), 41 deletions(-)

diff --git a/Mesh/Field.cpp b/Mesh/Field.cpp
index c791ef03c4..d4018edbeb 100644
--- a/Mesh/Field.cpp
+++ b/Mesh/Field.cpp
@@ -1043,7 +1043,7 @@ class MathEvalField : public Field
     options["F"] = new FieldOptionString
       (f, "Mathematical function to evaluate.", &update_needed);
     f = "F2 + Sin(z)";
-    callbacks["test"] = new FieldCallbackGeneric<MathEvalField>(this, &MathEvalField::myAction, "description blabla"); 
+    callbacks["test"] = new FieldCallbackGeneric<MathEvalField>(this, &MathEvalField::myAction, "description blabla");
   }
   double operator() (double x, double y, double z, GEntity *ge=0)
   {
@@ -1234,8 +1234,8 @@ class PostViewField : public Field
       update_needed = false;
     }
     double l = 0.;
-    // use large tolerance (in element reference coordinates) to
-    // maximize chance of finding an element
+    // use large tolerance (in element reference coordinates) to maximize chance
+    // of finding an element
     if(!octree->searchScalarWithTol(x, y, z, &l, 0, 0, 1.))
       Msg::Info("No scalar element found containing point (%g,%g,%g)", x, y, z);
     if(l <= 0 && crop_negative_values) return MAX_LC;
@@ -1251,13 +1251,18 @@ class PostViewField : public Field
       update_needed = false;
     }
     double l[9];
-    if(!octree->searchTensor(x, y, z, l, 0)){
+    // use large tolerance (in element reference coordinates) to maximize chance
+    // of finding an element
+    if(!octree->searchTensorWithTol(x, y, z, l, 0, 0, 1.)){
       Msg::Info("No tensor element found containing point (%g,%g,%g)", x, y, z);
       return;
     }
     metr(0, 0) = l[0];
+    metr(0, 1) = l[1];
+    metr(0, 2) = l[2];
     metr(1, 0) = l[3];
     metr(1, 1) = l[4];
+    metr(1, 2) = l[5];
     metr(2, 0) = l[6];
     metr(2, 1) = l[7];
     metr(2, 2) = l[8];
diff --git a/Post/OctreePost.cpp b/Post/OctreePost.cpp
index 4addb345af..7a58e526b8 100644
--- a/Post/OctreePost.cpp
+++ b/Post/OctreePost.cpp
@@ -208,7 +208,7 @@ static void addListOfStuff(Octree *o, std::vector<double> &l, int nbelm)
 
 // OctreePost implementation
 
-OctreePost::~OctreePost() 
+OctreePost::~OctreePost()
 {
   Octree_Delete(_SL); Octree_Delete(_VL); Octree_Delete(_TL);
   Octree_Delete(_ST); Octree_Delete(_VT); Octree_Delete(_TT);
@@ -219,19 +219,19 @@ OctreePost::~OctreePost()
   Octree_Delete(_SY); Octree_Delete(_VY); Octree_Delete(_TY);
 }
 
-OctreePost::OctreePost(PView *v) 
+OctreePost::OctreePost(PView *v)
 {
   _create(v->getData(true)); // use adaptive data if available
 }
 
-OctreePost::OctreePost(PViewData *data) 
+OctreePost::OctreePost(PViewData *data)
 {
   _create(data);
 }
 
 void OctreePost::_create(PViewData *data)
 {
-  _SL = _VL = _TL = _ST = _VT = _TT = _SQ = _VQ = _TQ = 0; 
+  _SL = _VL = _TL = _ST = _VT = _TT = _SQ = _VQ = _TQ = 0;
   _SS = _VS = _TS = _SH = _VH = _TH = _SI = _VI = _TI = 0;
   _SY = _VY = _TY = 0;
   _theViewDataList = 0;
@@ -263,7 +263,7 @@ void OctreePost::_create(PViewData *data)
                       bbmax.y() - bbmin.y(),
                       bbmax.z() - bbmin.z()};
     const int maxElePerBucket = 100; // memory vs. speed trade-off
-    
+
     _SL = Octree_Create(maxElePerBucket, min, size, linBB, linCentroid, linInEle);
     addListOfStuff(_SL, l->SL, 6 + 2 * l->getNumTimeSteps());
     Octree_Arrange(_SL);
@@ -273,7 +273,7 @@ void OctreePost::_create(PViewData *data)
     _TL = Octree_Create(maxElePerBucket, min, size, linBB, linCentroid, linInEle);
     addListOfStuff(_TL, l->TL, 6 + 18 * l->getNumTimeSteps());
     Octree_Arrange(_TL);
-    
+
     _ST = Octree_Create(maxElePerBucket, min, size, triBB, triCentroid, triInEle);
     addListOfStuff(_ST, l->ST, 9 + 3 * l->getNumTimeSteps());
     Octree_Arrange(_ST);
@@ -283,7 +283,7 @@ void OctreePost::_create(PViewData *data)
     _TT = Octree_Create(maxElePerBucket, min, size, triBB, triCentroid, triInEle);
     addListOfStuff(_TT, l->TT, 9 + 27 * l->getNumTimeSteps());
     Octree_Arrange(_TT);
-    
+
     _SQ = Octree_Create(maxElePerBucket, min, size, quaBB, quaCentroid, quaInEle);
     addListOfStuff(_SQ, l->SQ, 12 + 4 * l->getNumTimeSteps());
     Octree_Arrange(_SQ);
@@ -293,7 +293,7 @@ void OctreePost::_create(PViewData *data)
     _TQ = Octree_Create(maxElePerBucket, min, size, quaBB, quaCentroid, quaInEle);
     addListOfStuff(_TQ, l->TQ, 12 + 36 * l->getNumTimeSteps());
     Octree_Arrange(_TQ);
-    
+
     _SS = Octree_Create(maxElePerBucket, min, size, tetBB, tetCentroid, tetInEle);
     addListOfStuff(_SS, l->SS, 12 + 4 * l->getNumTimeSteps());
     Octree_Arrange(_SS);
@@ -303,7 +303,7 @@ void OctreePost::_create(PViewData *data)
     _TS = Octree_Create(maxElePerBucket, min, size, tetBB, tetCentroid, tetInEle);
     addListOfStuff(_TS, l->TS, 12 + 36 * l->getNumTimeSteps());
     Octree_Arrange(_TS);
-    
+
     _SH = Octree_Create(maxElePerBucket, min, size, hexBB, hexCentroid, hexInEle);
     addListOfStuff(_SH, l->SH, 24 + 8 * l->getNumTimeSteps());
     Octree_Arrange(_SH);
@@ -313,7 +313,7 @@ void OctreePost::_create(PViewData *data)
     _TH = Octree_Create(maxElePerBucket, min, size, hexBB, hexCentroid, hexInEle);
     addListOfStuff(_TH, l->TH, 24 + 72 * l->getNumTimeSteps());
     Octree_Arrange(_TH);
-    
+
     _SI = Octree_Create(maxElePerBucket, min, size, priBB, priCentroid, priInEle);
     addListOfStuff(_SI, l->SI, 18 + 6 * l->getNumTimeSteps());
     Octree_Arrange(_SI);
@@ -323,7 +323,7 @@ void OctreePost::_create(PViewData *data)
     _TI = Octree_Create(maxElePerBucket, min, size, priBB, priCentroid, priInEle);
     addListOfStuff(_TI, l->TI, 18 + 54 * l->getNumTimeSteps());
     Octree_Arrange(_TI);
-    
+
     _SY = Octree_Create(maxElePerBucket, min, size, pyrBB, pyrCentroid, pyrInEle);
     addListOfStuff(_SY, l->SY, 15 + 5 * l->getNumTimeSteps());
     Octree_Arrange(_SY);
@@ -336,7 +336,7 @@ void OctreePost::_create(PViewData *data)
   }
 }
 
-bool OctreePost::_getValue(void *in, int dim, int nbNod, int nbComp, 
+bool OctreePost::_getValue(void *in, int dim, int nbNod, int nbComp,
                            double P[3], int step, double *values,
                            double *elementSize)
 {
@@ -352,12 +352,12 @@ bool OctreePost::_getValue(void *in, int dim, int nbNod, int nbComp,
   if(step < 0){
     for(int i = 0; i < _theViewDataList->getNumTimeSteps(); i++)
       for(int j = 0; j < nbComp; j++)
-        values[nbComp * i + j] = e->interpolate(&V[nbNod * nbComp * i + j], 
+        values[nbComp * i + j] = e->interpolate(&V[nbNod * nbComp * i + j],
                                                 U[0], U[1], U[2], nbComp);
   }
   else{
     for(int j = 0; j < nbComp; j++)
-      values[j] = e->interpolate(&V[nbNod * nbComp * step + j], 
+      values[j] = e->interpolate(&V[nbNod * nbComp * step + j],
                                  U[0], U[1], U[2], nbComp);
   }
 
@@ -365,7 +365,7 @@ bool OctreePost::_getValue(void *in, int dim, int nbNod, int nbComp,
 
   delete e;
   return true;
-} 
+}
 
 bool OctreePost::_getValue(void *in, int nbComp, double P[3], int timestep,
                            double *values, double *elementSize)
@@ -383,7 +383,7 @@ bool OctreePost::_getValue(void *in, int nbComp, double P[3], int timestep,
   else
     for(int i = 0; i < e->getNumVertices(); i++)
       dataIndex[i] = e->getNum();
-    
+
   double U[3];
   e->xyz2uvw(P, U);
 
@@ -393,7 +393,7 @@ bool OctreePost::_getValue(void *in, int nbComp, double P[3], int timestep,
     if(timestep < 0 || step == timestep){
       for(int nod = 0; nod < e->getNumVertices(); nod++){
         for(int comp = 0; comp < nbComp; comp++)
-          _theViewDataGModel->getValueByIndex(step, dataIndex[nod], nod, comp, 
+          _theViewDataGModel->getValueByIndex(step, dataIndex[nod], nod, comp,
                                               nodeval[nod * nbComp + comp]);
       }
       for(int comp = 0; comp < nbComp; comp++){
@@ -405,12 +405,12 @@ bool OctreePost::_getValue(void *in, int nbComp, double P[3], int timestep,
       }
     }
   }
-  
+
   if(elementSize) *elementSize = e->maxEdge();
   return true;
-} 
+}
 
-bool OctreePost::searchScalar(double x, double y, double z, double *values, 
+bool OctreePost::searchScalar(double x, double y, double z, double *values,
                               int step, double *size)
 {
   double P[3] = {x, y, z};
@@ -420,7 +420,7 @@ bool OctreePost::searchScalar(double x, double y, double z, double *values,
     if(_theViewDataList) numSteps = _theViewDataList->getNumTimeSteps();
     else if(_theViewDataGModel) numSteps = _theViewDataGModel->getNumTimeSteps();
     for(int i = 0; i < numSteps; i++){
-      values[i] = 0.0; 
+      values[i] = 0.0;
     }
   }
   else
@@ -442,11 +442,11 @@ bool OctreePost::searchScalar(double x, double y, double z, double *values,
       if(_getValue(m->getMeshElementByCoord(pt), 1, P, step, values, size)) return true;
     }
   }
-  
+
   return false;
 }
 
-bool OctreePost::searchScalarWithTol(double x, double y, double z, double *values, 
+bool OctreePost::searchScalarWithTol(double x, double y, double z, double *values,
                                      int step, double *size, double tol)
 {
   bool a = searchScalar(x, y, z, values, step, size);
@@ -458,11 +458,11 @@ bool OctreePost::searchScalarWithTol(double x, double y, double z, double *value
     a = searchScalar(x, y, z, values, step, size);
     element::setTolerance(oldtol1);
     MElement::setTolerance(oldtol2);
-  }    
+  }
   return a;
 }
 
-bool OctreePost::searchVector(double x, double y, double z, double *values, 
+bool OctreePost::searchVector(double x, double y, double z, double *values,
                               int step, double *size)
 {
   double P[3] = {x, y, z};
@@ -472,7 +472,7 @@ bool OctreePost::searchVector(double x, double y, double z, double *values,
     if(_theViewDataList) numSteps = _theViewDataList->getNumTimeSteps();
     else if(_theViewDataGModel) numSteps = _theViewDataGModel->getNumTimeSteps();
     for(int i = 0; i < 3 * numSteps; i++)
-      values[i] = 0.0; 
+      values[i] = 0.0;
   }
   else
     for(int i = 0; i < 3; i++)
@@ -494,11 +494,11 @@ bool OctreePost::searchVector(double x, double y, double z, double *values,
       if(_getValue(m->getMeshElementByCoord(pt), 3, P, step, values, size)) return true;
     }
   }
-  
+
   return false;
 }
 
-bool OctreePost::searchTensor(double x, double y, double z, double *values, 
+bool OctreePost::searchTensor(double x, double y, double z, double *values,
                               int step, double *size)
 {
   double P[3] = {x, y, z};
@@ -508,7 +508,7 @@ bool OctreePost::searchTensor(double x, double y, double z, double *values,
     if(_theViewDataList) numSteps = _theViewDataList->getNumTimeSteps();
     else if(_theViewDataGModel) numSteps = _theViewDataGModel->getNumTimeSteps();
     for(int i = 0; i < 9 * numSteps; i++)
-      values[i] = 0.0; 
+      values[i] = 0.0;
   }
   else
     for(int i = 0; i < 9; i++)
@@ -530,6 +530,22 @@ bool OctreePost::searchTensor(double x, double y, double z, double *values,
       if(_getValue(m->getMeshElementByCoord(pt), 9, P, step, values, size)) return true;
     }
   }
-  
+
   return false;
 }
+
+bool OctreePost::searchTensorWithTol(double x, double y, double z, double *values,
+                                     int step, double *size, double tol)
+{
+  bool a = searchTensor(x, y, z, values, step, size);
+  if(!a && tol != 0.){
+    double oldtol1 = element::getTolerance();
+    double oldtol2 = MElement::getTolerance();
+    element::setTolerance(tol);
+    MElement::setTolerance(tol);
+    a = searchTensor(x, y, z, values, step, size);
+    element::setTolerance(oldtol1);
+    MElement::setTolerance(oldtol2);
+  }
+  return a;
+}
diff --git a/Post/OctreePost.h b/Post/OctreePost.h
index 34d1e48989..69564a6b3b 100644
--- a/Post/OctreePost.h
+++ b/Post/OctreePost.h
@@ -13,7 +13,7 @@ class PViewData;
 class PViewDataList;
 class PViewDataGModel;
 
-class OctreePost 
+class OctreePost
 {
  private:
   Octree *_SL, *_VL, *_TL;
@@ -26,10 +26,10 @@ class OctreePost
   PViewDataList *_theViewDataList;
   PViewDataGModel *_theViewDataGModel;
   void _create(PViewData *data);
-  bool _getValue(void *in, int dim, int nbNod, int nbComp, 
+  bool _getValue(void *in, int dim, int nbNod, int nbComp,
                  double P[3], int step, double *values,
                  double *elementSize);
-  bool _getValue(void *in, int nbComp, double P[3], int step, 
+  bool _getValue(void *in, int nbComp, double P[3], int step,
                  double *values, double *elementSize);
  public :
   OctreePost(PView *v);
@@ -40,14 +40,16 @@ class OctreePost
   // post element. If several time steps are present, they are all
   // interpolated unless time step is set to a different value than
   // -1.
-  bool searchScalar(double x, double y, double z, double *values, 
+  bool searchScalar(double x, double y, double z, double *values,
                     int step=-1, double *size=0);
-  bool searchScalarWithTol(double x, double y, double z, double *values, 
+  bool searchScalarWithTol(double x, double y, double z, double *values,
                            int step=-1, double *size=0, double tol=1.e-2);
-  bool searchVector(double x, double y, double z, double *values, 
+  bool searchVector(double x, double y, double z, double *values,
                     int step=-1, double *size=0);
-  bool searchTensor(double x, double y, double z, double *values, 
+  bool searchTensor(double x, double y, double z, double *values,
                     int step=-1, double *size=0);
+  bool searchTensorWithTol(double x, double y, double z, double *values,
+                           int step=-1, double *size=0, double tol=1.e-2);
 };
 
 #endif
-- 
GitLab