ensightCaseTemplates.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2016-2024 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "cloud.H"
29 #include "ensightPTraits.H"
30 
31 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
32 
33 template<class StringType>
35 (
36  const StringType& input,
37  const label timeIndex
38 )
39 {
40  StringType result(input);
41 
42  const auto nMask = std::count(input.begin(), input.end(), '*');
43 
44  // If there are any '*' chars, they are assumed to be contiguous
45  // Eg, data/******/geometry
46 
47  if (nMask)
48  {
49  result.replace
50  (
51  ensightCase::mask(nMask),
53  );
54  }
55 
56  return result;
57 }
58 
59 
60 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
61 
62 template<class Type>
65 (
66  const word& name,
67  const bool isPointData
68 ) const
69 {
71 
72  if (UPstream::master())
73  {
74  const ensight::VarName varName(name);
75  output = createDataFile(varName);
76 
77  // Description
78  output().writeString
79  (
80  padded(timeIndex_) / varName
81  + " <" + pTraits<Type>::typeName + ">"
82  );
83  output().newline();
84 
85  // Remember the field variable for later use
86  noteVariable(varName, ensightPTraits<Type>::typeName);
87 
88  // Could warn about existing variables that changed representation
89  if (isPointData)
90  {
91  nodeVariables_.set(varName);
92  }
93  }
94 
95  return output;
96 }
97 
98 
99 template<class Type>
102 (
103  const word& name
104 ) const
105 {
106  return newData<Type>(name, true); // POINT_DATA
107 }
108 
109 
110 template<class Type>
113 (
114  const word& cloudName,
115  const word& name
116 ) const
117 {
119 
120  if (UPstream::master())
121  {
122  const ensight::VarName varName(name);
123  output = createCloudFile(cloudName, varName);
124 
125  // Description
126  output().writeString
127  (
128  padded(timeIndex_) / cloudName / varName
129  + " <" + pTraits<Type>::typeName + ">"
130  );
131  output().newline();
132 
133  // Remember the cloud variable for later use
134  noteCloud(cloudName, varName, ensightPTraits<Type>::typeName);
135  }
136 
137  return output;
138 }
139 
140 
141 // ************************************************************************* //
autoPtr< ensightFile > newCloudData(const word &cloudName, const word &varName) const
Open stream for new cloud data file (on master), with current index.
Ensight names and component order for base types.
static StringType expand_mask(const StringType &input, const label index)
Replace the &#39;*&#39; mask chars with zero-padded integer value.
A traits class, which is primarily used for primitives and vector-space.
Definition: pTraits.H:75
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of &#39;true&#39; entries.
Definition: BitOps.H:73
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
const word cloudName(propsDict.get< word >("cloud"))
autoPtr< ensightFile > newData(const word &varName, const bool isPointData=false) const
Open stream for new data file (on master), with current index.
A class for handling words, derived from Foam::string.
Definition: word.H:63
static Istream & input(Istream &is, IntRange< T > &range)
Definition: IntRanges.C:33
Specification of a valid Ensight variable-name.
static word padded(const int nwidth, const label index)
Stringified zero-padded integer value of specified width.
Definition: ensightCase.C:48
static bool master(const label communicator=worldComm)
True if process corresponds to the master rank in the communicator.
Definition: UPstream.H:1094
static Ostream & output(Ostream &os, const IntRange< T > &range)
Definition: IntRanges.C:44
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
const word & mask() const
The output &#39;*&#39; mask.
Definition: ensightCaseI.H:41
autoPtr< ensightFile > newPointData(const word &varName) const
Open stream for new data file (on master), with current index and marking as containing POINT_DATA...
label timeIndex
Definition: getTimeIndex.H:24