foamVtkFileWriterTemplates.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) 2019 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 <type_traits>
29 #include "foamVtkOutput.H"
30 
31 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
32 
33 template<class Type>
35 (
36  const word& fieldName,
37  const Type& val,
38  const label nValues
39 )
40 {
41  static_assert
42  (
43  (
44  std::is_same<label, typename pTraits<Type>::cmptType>::value
45  || std::is_floating_point<typename pTraits<Type>::cmptType>::value
46  ),
47  "Label and Floating-point vector space only"
48  );
49 
51 
52  if (format_)
53  {
54  if (std::is_same<label, typename pTraits<Type>::cmptType>::value)
55  {
56  if (legacy())
57  {
58  legacy::intField<nCmpt>(format(), fieldName, nValues);
59  }
60  else
61  {
62  const uint64_t payLoad = vtk::sizeofData<label, nCmpt>(nValues);
63 
64  format().beginDataArray<label, nCmpt>(fieldName);
65  format().writeSize(payLoad);
66  }
67  }
68  else
69  {
70  if (legacy())
71  {
72  legacy::floatField<nCmpt>(format(), fieldName, nValues);
73  }
74  else
75  {
76  const uint64_t payLoad = vtk::sizeofData<float, nCmpt>(nValues);
77 
78  format().beginDataArray<float, nCmpt>(fieldName);
79  format().writeSize(payLoad);
80  }
81  }
82  }
83 
84  if (format_)
85  {
86  vtk::write(format(), val, nValues);
87  }
88 
89  if (format_)
90  {
91  format().flush();
92  format().endDataArray();
93  }
94 }
95 
96 
97 // ************************************************************************* //
foamVtkOutput.H
Foam::val
label ListType::const_reference val
Definition: ListOps.H:407
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::vtk::fileWriter::writeUniform
void writeUniform(const word &fieldName, const Type &val, const label nValues)
Write uniform field content.
Definition: foamVtkFileWriterTemplates.C:35
format
word format(conversionProperties.get< word >("format"))
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:62
Foam::pTraits
Traits class for primitives.
Definition: pTraits.H:52
Foam::direction
uint8_t direction
Definition: direction.H:47
Foam::vtk::write
void write(vtk::formatter &fmt, const Type &val, const label n=1)
Component-wise write of a value (N times)
Definition: foamVtkOutputTemplates.C:35