writePointFields.H
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) 2020-2021 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
12 
13 InNamespace
14  Foam
15 
16 Description
17  Read point fields from disk and write as ensight data
18 
19 \*---------------------------------------------------------------------------*/
20 
21 #ifndef ensight_writePointFields_H
22 #define ensight_writePointFields_H
23 
24 #include "readFields.H"
25 #include "ensightMesh.H"
26 #include "fvMesh.H"
27 
28 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
29 
30 namespace Foam
31 {
32 
33 template<class Type>
34 bool writePointField
35 (
36  ensightCase& ensCase,
37  const ensightMesh& ensMesh,
38  const tmp<GeometricField<Type, pointPatchField, pointMesh>>& tfield
39 )
40 {
41  if (!tfield.valid())
42  {
43  return false;
44  }
45 
46  const auto& field = tfield();
47 
48  // PointData = true
49  autoPtr<ensightFile> os = ensCase.newData<Type>(field.name(), true);
50 
51  bool wrote = ensightOutput::writePointField<Type>
52  (
53  os.ref(),
54  field,
55  ensMesh
56  );
57 
58  tfield.clear();
59  return wrote;
60 }
61 
62 
63 template<class Type>
64 label writePointFields
65 (
66  ensightCase& ensCase,
67  const ensightMesh& ensMesh,
68  const IOobjectList& objects
69 )
70 {
71  typedef GeometricField<Type, pointPatchField, pointMesh> GeoField;
72 
73  const pointMesh& ptMesh = pointMesh::New(ensMesh.mesh());
74 
75  label count = 0;
76 
77  for (const word& fieldName : objects.sortedNames<GeoField>())
78  {
79  if
80  (
81  writePointField<Type>
82  (
83  ensCase,
84  ensMesh,
85  getField<GeoField>(ptMesh, objects, fieldName)
86  )
87  )
88  {
89  Info<< ' ' << fieldName;
90  ++count;
91  }
92  }
93 
94  return count;
95 }
96 
97 
99 (
100  ensightCase& ensCase,
101  const ensightMesh& ensMesh,
102  const IOobjectList& objects
103 )
104 {
105  #undef ensight_WRITE_FIELD
106  #define ensight_WRITE_FIELD(PrimitiveType) \
107  writePointFields<PrimitiveType> \
108  ( \
109  ensCase, \
110  ensMesh, \
111  objects \
112  )
113 
114  label count = 0;
115  count += ensight_WRITE_FIELD(scalar);
120 
121  #undef ensight_WRITE_FIELD
122  return count;
123 }
124 
125 } // End namespace Foam
126 
127 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
128 
129 #endif
130 
131 // ************************************************************************* //
Foam::Tensor< scalar >
Foam::ensightCase::newData
autoPtr< ensightFile > newData(const word &varName, const bool isPointData=false) const
Open stream for new data file (on master), with current index.
Foam::ensightMesh
Encapsulation of volume meshes for writing in ensight format. It manages cellZones,...
Definition: ensightMesh.H:82
Foam::SymmTensor< scalar >
Foam::writePointFields
label writePointFields(ensightCase &ensCase, const ensightMesh &ensMesh, const IOobjectList &objects)
Definition: writePointFields.H:73
readFields.H
Helper routines for reading a field or fields, for foamToEnsight.
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::MeshObject< polyMesh, UpdateableMeshObject, pointMesh >::New
static const pointMesh & New(const polyMesh &mesh, Args &&... args)
Get existing or create a new MeshObject.
Definition: MeshObject.C:48
Foam::IOobjectList::sortedNames
wordList sortedNames() const
The sorted names of the IOobjects.
Definition: IOobjectList.C:345
Foam::ensightMesh::mesh
const polyMesh & mesh() const noexcept
Reference to the underlying polyMesh.
Definition: ensightMesh.H:148
ensightMesh.H
ensight_WRITE_FIELD
#define ensight_WRITE_FIELD(PrimitiveType)
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
field
rDeltaTY field()
Foam::writePointField
bool writePointField(ensightCase &ensCase, const ensightMesh &ensMesh, const tmp< GeometricField< Type, pointPatchField, pointMesh >> &tfield)
Definition: writePointFields.H:43
os
OBJstream os(runTime.globalPath()/outputName)
fvMesh.H
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::pointMesh
Mesh representing a set of points created from polyMesh.
Definition: pointMesh.H:51
Foam::SphericalTensor< scalar >
Foam::IOobjectList
List of IOobjects with searching and retrieving facilities.
Definition: IOobjectList.H:55
Foam::ensightCase
Supports writing of ensight cases as well as providing common factory methods to open new files.
Definition: ensightCase.H:67
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::BitOps::count
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of 'true' entries.
Definition: BitOps.H:77
Foam::Vector< scalar >
Foam::GeometricField
Generic GeometricField class.
Definition: areaFieldsFwd.H:53
Foam::writeAllPointFields
label writeAllPointFields(ensightCase &ensCase, const ensightMesh &ensMesh, const IOobjectList &objects)
Definition: writePointFields.H:107