From 0ef981adbc6b25a866823e79abfe2acc863f5043 Mon Sep 17 00:00:00 2001
From: Mark Olesen <Mark.Olesen@esi-group.com>
Date: Fri, 5 Apr 2024 12:14:49 +0200
Subject: [PATCH] BUG: cached ensight type not a word (fixes #3133)

- the type/name for field caching were saved as word, but ensight has
  things like "tensor symm" etc, which do not parse very well as
  'word'. Now save as 'string' type.

  Backwards compatibility is OK since a word token will also be
  readable as string etc.
---
 src/fileFormats/ensight/file/ensightWriterCaching.C       | 4 ++--
 src/fileFormats/ensight/file/ensightWriterCaching.H       | 8 ++++++--
 .../writers/ensight/ensightCoordSetWriterCollated.C       | 6 +++---
 .../writers/ensight/ensightSurfaceWriterCollated.C        | 6 +++---
 4 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/src/fileFormats/ensight/file/ensightWriterCaching.C b/src/fileFormats/ensight/file/ensightWriterCaching.C
index 4d6ed044bc2..7674415e81e 100644
--- a/src/fileFormats/ensight/file/ensightWriterCaching.C
+++ b/src/fileFormats/ensight/file/ensightWriterCaching.C
@@ -5,7 +5,7 @@
     \\  /    A nd           | www.openfoam.com
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
-    Copyright (C) 2016-2023 OpenCFD Ltd.
+    Copyright (C) 2016-2024 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -203,7 +203,7 @@ bool Foam::ensightOutput::writerCaching::update
     const scalar timeValue,
     const bool geomChanged,
     const word& fieldName,
-    const word& fieldType,
+    const string& fieldType,  // May contain spaces (eg, "tensor symm")
     const word& varName
 )
 {
diff --git a/src/fileFormats/ensight/file/ensightWriterCaching.H b/src/fileFormats/ensight/file/ensightWriterCaching.H
index b9a1abfd88e..40b56a20e8b 100644
--- a/src/fileFormats/ensight/file/ensightWriterCaching.H
+++ b/src/fileFormats/ensight/file/ensightWriterCaching.H
@@ -5,7 +5,7 @@
     \\  /    A nd           | www.openfoam.com
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
-    Copyright (C) 2016-2022 OpenCFD Ltd.
+    Copyright (C) 2016-2024 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -139,6 +139,10 @@ public:
 
         //- Update time/geometry information and file cache.
         //- This routine should only be called from the master process
+        //
+        //  Note that the ensight field type may contain spaces
+        //  (eg, "tensor symm")
+        //
         //  \return True if there is a state change, which is either a
         //      geometry change or a new time interval
         bool update
@@ -147,7 +151,7 @@ public:
             const scalar timeValue,     //!< The current time value
             const bool geomChanged,     //!< Monitored geometry changed
             const word& fieldName,      //!< Name of field
-            const word& fieldType,      //!< Type of field
+            const string& fieldType,    //!< Ensight type of field
             const word& varName = word::null //!< Alternative field name
         );
 };
diff --git a/src/meshTools/coordSet/writers/ensight/ensightCoordSetWriterCollated.C b/src/meshTools/coordSet/writers/ensight/ensightCoordSetWriterCollated.C
index 3e378c2933c..7e9303eced8 100644
--- a/src/meshTools/coordSet/writers/ensight/ensightCoordSetWriterCollated.C
+++ b/src/meshTools/coordSet/writers/ensight/ensightCoordSetWriterCollated.C
@@ -5,7 +5,7 @@
     \\  /    A nd           | www.openfoam.com
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
-    Copyright (C) 2022-2023 OpenCFD Ltd.
+    Copyright (C) 2022-2024 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -222,7 +222,7 @@ Foam::fileName Foam::coordSetWriters::ensightWriter::writeCollated
             {
                 const dictionary& subDict = dEntry.dict();
 
-                const word varType(subDict.get<word>("type"));
+                const string varType(subDict.get<string>("type"));
                 const word varName
                 (
                     subDict.getOrDefault<word>
@@ -233,7 +233,7 @@ Foam::fileName Foam::coordSetWriters::ensightWriter::writeCollated
                 );
 
                 osCase
-                    << varType
+                    << varType.c_str()
                     <<
                     (
                         true  // this->isPointData()
diff --git a/src/surfMesh/writers/ensight/ensightSurfaceWriterCollated.C b/src/surfMesh/writers/ensight/ensightSurfaceWriterCollated.C
index 1d5595564ec..6e27fe3bee4 100644
--- a/src/surfMesh/writers/ensight/ensightSurfaceWriterCollated.C
+++ b/src/surfMesh/writers/ensight/ensightSurfaceWriterCollated.C
@@ -6,7 +6,7 @@
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
     Copyright (C) 2011-2014 OpenFOAM Foundation
-    Copyright (C) 2015-2023 OpenCFD Ltd.
+    Copyright (C) 2015-2024 OpenCFD Ltd.
 -------------------------------------------------------------------------------
 License
     This file is part of OpenFOAM.
@@ -236,7 +236,7 @@ Foam::fileName Foam::surfaceWriters::ensightWriter::writeCollated
             {
                 const dictionary& subDict = dEntry.dict();
 
-                const word varType(subDict.get<word>("type"));
+                const string varType(subDict.get<string>("type"));
                 const word varName
                 (
                     subDict.getOrDefault<word>
@@ -247,7 +247,7 @@ Foam::fileName Foam::surfaceWriters::ensightWriter::writeCollated
                 );
 
                 osCase
-                    << varType
+                    << varType.c_str()
                     <<
                     (
                         this->isPointData()
-- 
GitLab