From 78fd1f911c30dcd1eb66fa87217172feb4fc9204 Mon Sep 17 00:00:00 2001
From: Yvan Fournier <yvan.fournier@edf.fr>
Date: Sun, 13 Sep 2015 15:34:39 +0200
Subject: [PATCH] Fix for bug 0010637 (EnSight symmetric tensor components XZ
 and YZ are interchanged).

---
 IO/EnSight/vtkEnSight6BinaryReader.cxx    | 16 ++++++++--------
 IO/EnSight/vtkEnSight6Reader.cxx          |  8 ++++----
 IO/EnSight/vtkEnSightGoldBinaryReader.cxx |  6 +++---
 IO/EnSight/vtkEnSightGoldReader.cxx       |  8 +++++---
 4 files changed, 20 insertions(+), 18 deletions(-)

diff --git a/IO/EnSight/vtkEnSight6BinaryReader.cxx b/IO/EnSight/vtkEnSight6BinaryReader.cxx
index 7bf332c..51eaf3c 100644
--- a/IO/EnSight/vtkEnSight6BinaryReader.cxx
+++ b/IO/EnSight/vtkEnSight6BinaryReader.cxx
@@ -1457,8 +1457,8 @@ int vtkEnSight6BinaryReader::ReadTensorsPerNode(
       tensor[1] = tensorsRead[6*i+1];
       tensor[2] = tensorsRead[6*i+2];
       tensor[3] = tensorsRead[6*i+3];
-      tensor[4] = tensorsRead[6*i+4];
-      tensor[5] = tensorsRead[6*i+5];
+      tensor[4] = tensorsRead[6*i+5];
+      tensor[5] = tensorsRead[6*i+4];
       tensors->InsertTuple(i, tensor);
       }
 
@@ -1495,8 +1495,8 @@ int vtkEnSight6BinaryReader::ReadTensorsPerNode(
       tensor[1] = tensorsRead[6*i+1];
       tensor[2] = tensorsRead[6*i+2];
       tensor[3] = tensorsRead[6*i+3];
-      tensor[4] = tensorsRead[6*i+4];
-      tensor[5] = tensorsRead[6*i+5];
+      tensor[4] = tensorsRead[6*i+5];
+      tensor[5] = tensorsRead[6*i+4];
       tensors->InsertTuple(i, tensor);
       }
 
@@ -2057,8 +2057,8 @@ int vtkEnSight6BinaryReader::ReadTensorsPerElement(
           tensor[1] = tensorsRead[6*i+1];
           tensor[2] = tensorsRead[6*i+2];
           tensor[3] = tensorsRead[6*i+3];
-          tensor[4] = tensorsRead[6*i+4];
-          tensor[5] = tensorsRead[6*i+5];
+          tensor[4] = tensorsRead[6*i+5];
+          tensor[5] = tensorsRead[6*i+4];
 
           tensors->InsertTuple(this->GetCellIds(idx, elementType)->GetId(i),
                                tensor);
@@ -2078,8 +2078,8 @@ int vtkEnSight6BinaryReader::ReadTensorsPerElement(
         tensor[1] = tensorsRead[6*i+1];
         tensor[2] = tensorsRead[6*i+2];
         tensor[3] = tensorsRead[6*i+3];
-        tensor[4] = tensorsRead[6*i+4];
-        tensor[5] = tensorsRead[6*i+5];
+        tensor[4] = tensorsRead[6*i+5];
+        tensor[5] = tensorsRead[6*i+4];
         tensors->InsertTuple(i, tensor);
         }
       delete [] tensorsRead;
diff --git a/IO/EnSight/vtkEnSight6Reader.cxx b/IO/EnSight/vtkEnSight6Reader.cxx
index 948e972..950b443 100644
--- a/IO/EnSight/vtkEnSight6Reader.cxx
+++ b/IO/EnSight/vtkEnSight6Reader.cxx
@@ -993,7 +993,7 @@ int vtkEnSight6Reader::ReadTensorsPerNode(
       {
       vtkEnSight6ReaderRead3(line, " %12e %12e %12e %12e %12e %12e",
                              &tensor[0], &tensor[1],
-                             &tensor[2], &tensor[3], &tensor[4], &tensor[5]);
+                             &tensor[2], &tensor[3], &tensor[5], &tensor[4]);
       tensors->InsertTuple(i, tensor);
       lineRead = this->ReadNextDataLine(line);
       }
@@ -1032,7 +1032,7 @@ int vtkEnSight6Reader::ReadTensorsPerNode(
         this->ReadNextDataLine(line);
         vtkEnSight6ReaderRead3(line, " %12e %12e %12e %12e %12e %12e",
                                &values[0], &values[1],
-                               &values[2], &values[3], &values[4], &values[5]);
+                               &values[2], &values[3], &values[5], &values[4]);
         for (j = 0; j < 6; j++)
           {
           tensors->InsertComponent(i*6 + j, k, values[j]);
@@ -1506,7 +1506,7 @@ int vtkEnSight6Reader::ReadTensorsPerElement(
           this->ReadNextDataLine(line);
           vtkEnSight6ReaderRead3(line, " %12e %12e %12e %12e %12e %12e",
                                  &values[0], &values[1], &values[2],
-                                 &values[3], &values[4], &values[5]);
+                                 &values[3], &values[5], &values[4]);
           for (j = 0; j < 6; j++)
             {
             tensors->InsertComponent(i*6 + j, k, values[j]);
@@ -1546,7 +1546,7 @@ int vtkEnSight6Reader::ReadTensorsPerElement(
           this->ReadNextDataLine(line);
           vtkEnSight6ReaderRead3(line, " %12e %12e %12e %12e %12e %12e",
                                  &tensor[0], &tensor[1], &tensor[2],
-                                 &tensor[3], &tensor[4], &tensor[5]);
+                                 &tensor[3], &tensor[5], &tensor[4]);
           tensors->InsertTuple(this->GetCellIds(idx, elementType)->GetId(i),
                                tensor);
           }
diff --git a/IO/EnSight/vtkEnSightGoldBinaryReader.cxx b/IO/EnSight/vtkEnSightGoldBinaryReader.cxx
index 27406c4..8253f80 100644
--- a/IO/EnSight/vtkEnSightGoldBinaryReader.cxx
+++ b/IO/EnSight/vtkEnSightGoldBinaryReader.cxx
@@ -1798,8 +1798,8 @@ int vtkEnSightGoldBinaryReader::ReadTensorsPerNode(
       this->ReadFloatArray(comp2, numPts);
       this->ReadFloatArray(comp3, numPts);
       this->ReadFloatArray(comp4, numPts);
-      this->ReadFloatArray(comp5, numPts);
       this->ReadFloatArray(comp6, numPts);
+      this->ReadFloatArray(comp5, numPts);
       for (i = 0; i < numPts; i++)
         {
         tuple[0] = comp1[i];
@@ -2475,8 +2475,8 @@ int vtkEnSightGoldBinaryReader::ReadTensorsPerElement(
         this->ReadFloatArray(comp2, numCells);
         this->ReadFloatArray(comp3, numCells);
         this->ReadFloatArray(comp4, numCells);
-        this->ReadFloatArray(comp5, numCells);
         this->ReadFloatArray(comp6, numCells);
+        this->ReadFloatArray(comp5, numCells);
         for (i = 0; i < numCells; i++)
           {
           tuple[0] = comp1[i];
@@ -2530,8 +2530,8 @@ int vtkEnSightGoldBinaryReader::ReadTensorsPerElement(
           this->ReadFloatArray(comp2, numCellsPerElement);
           this->ReadFloatArray(comp3, numCellsPerElement);
           this->ReadFloatArray(comp4, numCellsPerElement);
-          this->ReadFloatArray(comp5, numCellsPerElement);
           this->ReadFloatArray(comp6, numCellsPerElement);
+          this->ReadFloatArray(comp5, numCellsPerElement);
           for (i = 0; i < numCellsPerElement; i++)
             {
             tuple[0] = comp1[i];
diff --git a/IO/EnSight/vtkEnSightGoldReader.cxx b/IO/EnSight/vtkEnSightGoldReader.cxx
index 51c9457..3e9b640 100644
--- a/IO/EnSight/vtkEnSightGoldReader.cxx
+++ b/IO/EnSight/vtkEnSightGoldReader.cxx
@@ -815,6 +815,7 @@ int vtkEnSightGoldReader::ReadTensorsPerNode(const char* fileName, const char* d
   int timeStep, vtkMultiBlockDataSet *compositeOutput)
 {
   char line[256];
+  int symmTensorOrder[6] = {0, 1, 2, 3, 5, 4};
   int partId, realId, numPts, i, j;
   vtkFloatArray *tensors;
   vtkDataSet *output;
@@ -913,7 +914,7 @@ int vtkEnSightGoldReader::ReadTensorsPerNode(const char* fileName, const char* d
         for (j = 0; j < numPts; j++)
           {
           this->ReadNextDataLine(line);
-          tensors->InsertComponent(j, i, atof(line));
+          tensors->InsertComponent(j, symmTensorOrder[i], atof(line));
           }
         }
       tensors->SetName(description);
@@ -1307,6 +1308,7 @@ int vtkEnSightGoldReader::ReadTensorsPerElement(const char* fileName,
   vtkMultiBlockDataSet *compositeOutput)
 {
   char line[256];
+  int symmTensorOrder[6] = {0, 1, 2, 3, 5, 4};
   int partId, realId, numCells, numCellsPerElement, i, j, idx;
   vtkFloatArray *tensors;
   int lineRead, elementType;
@@ -1413,7 +1415,7 @@ int vtkEnSightGoldReader::ReadTensorsPerElement(const char* fileName,
             {
             this->ReadNextDataLine(line);
             value = atof(line);
-            tensors->InsertComponent(j, i, value);
+            tensors->InsertComponent(j, symmTensorOrder[i], value);
             }
           }
         lineRead = this->ReadNextDataLine(line);
@@ -1442,7 +1444,7 @@ int vtkEnSightGoldReader::ReadTensorsPerElement(const char* fileName,
               this->ReadNextDataLine(line);
               value = atof(line);
               tensors->InsertComponent(this->GetCellIds(idx, elementType)->GetId(j),
-                i, value);
+                symmTensorOrder[i], value);
               }
             }
           lineRead = this->ReadNextDataLine(line);
-- 
2.5.1

