From 6f4509b9387f9e11499604cabc64ef298ccfe29d Mon Sep 17 00:00:00 2001
From: mark <mark@opencfd>
Date: Fri, 23 Sep 2016 09:10:57 +0200
Subject: [PATCH] BUG: incorrect symmTensor order for some ensight output
 (fixes #243)

- affects foamToEnsightParts, sampled surfaces

- Use ensightPTraits mechanism throughout to avoid this issue
---
 .../foamToEnsight/ensightCloudTemplates.C     | 14 +++++------
 .../ensightOutputFunctions.C                  | 25 ++++++++-----------
 .../ensight/part/ensightPartTemplates.C       | 19 +++++---------
 3 files changed, 24 insertions(+), 34 deletions(-)

diff --git a/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightCloudTemplates.C b/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightCloudTemplates.C
index efcd11beb97..ac2559f17cf 100644
--- a/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightCloudTemplates.C
+++ b/applications/utilities/postProcessing/dataConversion/foamToEnsight/ensightCloudTemplates.C
@@ -57,10 +57,10 @@ void Foam::writeCloudField
                     val = Zero;
                 }
 
-                for (direction i=0; i < pTraits<Type>::nComponents; ++i)
+                for (direction d=0; d < pTraits<Type>::nComponents; ++d)
                 {
-                    label cmpt = ensightPTraits<Type>::componentOrder[i];
-                    os.write( component(val, cmpt) );
+                    label cmpt = ensightPTraits<Type>::componentOrder[d];
+                    os.write(component(val, cmpt));
 
                     if (++count % 6 == 0)
                     {
@@ -84,10 +84,10 @@ void Foam::writeCloudField
                         val = Zero;
                     }
 
-                    for (direction i=0; i < pTraits<Type>::nComponents; ++i)
+                    for (direction d=0; d < pTraits<Type>::nComponents; ++d)
                     {
-                        label cmpt = ensightPTraits<Type>::componentOrder[i];
-                        os.write( component(val, cmpt) );
+                        label cmpt = ensightPTraits<Type>::componentOrder[d];
+                        os.write(component(val, cmpt));
 
                         if (++count % 6 == 0)
                         {
@@ -168,9 +168,9 @@ void Foam::ensightCloudField
         }
 
         filePtr = new ensightFile(dataDir, postFileName, format);
+        // description
         filePtr->write
         (
-            // description
             string(postFileName + " <" + pTraits<Type>::typeName + ">")
         );
         filePtr->newline();
diff --git a/applications/utilities/postProcessing/dataConversion/foamToEnsightParts/ensightOutputFunctions.C b/applications/utilities/postProcessing/dataConversion/foamToEnsightParts/ensightOutputFunctions.C
index 2c92bee9cc4..148aa401453 100644
--- a/applications/utilities/postProcessing/dataConversion/foamToEnsightParts/ensightOutputFunctions.C
+++ b/applications/utilities/postProcessing/dataConversion/foamToEnsightParts/ensightOutputFunctions.C
@@ -24,6 +24,7 @@ License
 \*---------------------------------------------------------------------------*/
 
 #include "ensightOutputFunctions.H"
+#include "ensightPTraits.H"
 
 #include "passiveParticle.H"
 #include "IOField.H"
@@ -171,11 +172,8 @@ void Foam::ensightLagrangianField
     // when writing positions
 
     ensightFile os(dataDir, postFileName, format);
-    os.write
-    (
-        // description
-        string(postFileName + " with " + pTraits<Type>::typeName + " values")
-    );
+    // description
+    os.write(string(postFileName + " <" + pTraits<Type>::typeName + ">"));
     os.newline();
 
     IOField<Type> field(fieldObject);
@@ -187,21 +185,20 @@ void Foam::ensightLagrangianField
     {
         Type val = field[i];
 
-        if (mag(val) < 1.0e-90)
+        if (mag(val) < 1e-90)
         {
             val = Zero;
         }
 
-        for (direction cmpt=0; cmpt < pTraits<Type>::nComponents; cmpt++)
+        for (direction d=0; d < pTraits<Type>::nComponents; ++d)
         {
-            os.write( component(val, cmpt) );
-        }
+            label cmpt = ensightPTraits<Type>::componentOrder[d];
+            os.write(component(val, cmpt));
 
-        count += pTraits<Type>::nComponents;
-
-        if (count % 6 == 0)
-        {
-            os.newline();
+            if (++count % 6 == 0)
+            {
+                os.newline();
+            }
         }
     }
 
diff --git a/src/conversion/ensight/part/ensightPartTemplates.C b/src/conversion/ensight/part/ensightPartTemplates.C
index 32be0caef8d..13186460402 100644
--- a/src/conversion/ensight/part/ensightPartTemplates.C
+++ b/src/conversion/ensight/part/ensightPartTemplates.C
@@ -3,7 +3,7 @@
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
     \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
-     \\/     M anipulation  |
+     \\/     M anipulation  | Copyright (C) 2016 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -27,6 +27,7 @@ Description
 \*---------------------------------------------------------------------------*/
 
 #include "ensightPart.H"
+#include "ensightPTraits.H"
 
 // * * * * * * * * * * * * * * * Global Functions  * * * * * * * * * * * * * //
 
@@ -45,13 +46,9 @@ void Foam::ensightPart::writeField
         if (perNode)
         {
             os.writeKeyword("coordinates");
-            for
-            (
-                direction cmpt=0;
-                cmpt < pTraits<Type>::nComponents;
-                ++cmpt
-            )
+            for (direction d=0; d < pTraits<Type>::nComponents; ++d)
             {
+                label cmpt = ensightPTraits<Type>::componentOrder[d];
                 writeFieldList(os, field.component(cmpt), labelUList::null());
             }
         }
@@ -65,13 +62,9 @@ void Foam::ensightPart::writeField
                 {
                     os.writeKeyword(elementTypes()[elemI]);
 
-                    for
-                    (
-                        direction cmpt=0;
-                        cmpt < pTraits<Type>::nComponents;
-                        ++cmpt
-                    )
+                    for (direction d=0; d < pTraits<Type>::nComponents; ++d)
                     {
+                        label cmpt = ensightPTraits<Type>::componentOrder[d];
                         writeFieldList(os, field.component(cmpt), idList);
                     }
                 }
-- 
GitLab