writeAreaFields.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) 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 finiteArea fields from disk and write ensightFaMesh
18 
19 \*---------------------------------------------------------------------------*/
20 
21 #ifndef ensight_writeAreaFields_H
22 #define ensight_writeAreaFields_H
23 
24 #include "readFields.H"
25 #include "areaFaMesh.H"
26 
27 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
28 
29 namespace Foam
30 {
31 
32 template<class Type>
33 bool writeAreaField
34 (
35  ensightCase& ensCase,
36  const ensightFaMesh& ensMesh,
37  const tmp<GeometricField<Type, faPatchField, areaMesh>>& tfield
38 )
39 {
40  if (!tfield.valid())
41  {
42  return false;
43  }
44  const auto& field = tfield();
45 
46  autoPtr<ensightFile> os =
47  ensCase.newData<Type>(field.name());
48 
49  bool wrote = ensightOutput::writeAreaField<Type>
50  (
51  os.ref(),
52  field,
53  ensMesh
54  );
55 
56  tfield.clear();
57  return wrote;
58 }
59 
60 
61 template<class Type>
62 label writeAreaFields
63 (
64  ensightCase& ensCase,
65  const ensightFaMesh& ensMesh,
66  const IOobjectList& objects
67 )
68 {
69  typedef GeometricField<Type, faPatchField, areaMesh> GeoField;
70 
71  const faMesh& mesh = ensMesh.mesh();
72 
73  label count = 0;
74 
75  for (const word& fieldName : objects.sortedNames<GeoField>())
76  {
77  if
78  (
79  writeAreaField<Type>
80  (
81  ensCase,
82  ensMesh,
83  getField<GeoField>(objects.findObject(fieldName), mesh)
84  )
85  )
86  {
87  Info<< ' ' << fieldName;
88  ++count;
89  }
90  }
91 
92  return count;
93 }
94 
95 
97 (
98  ensightCase& ensCase,
99  const ensightFaMesh& ensMesh,
100  const IOobjectList& objects
101 )
102 {
103  #undef ensight_WRITE_FIELD
104  #define ensight_WRITE_FIELD(PrimitiveType) \
105  writeAreaFields<PrimitiveType> \
106  ( \
107  ensCase, \
108  ensMesh, \
109  objects \
110  )
111 
112  label count = 0;
113  count += ensight_WRITE_FIELD(scalar);
118 
119  #undef ensight_WRITE_FIELD
120  return count;
121 }
122 
123 } // End namespace Foam
124 
125 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
126 
127 #endif
128 
129 // ************************************************************************* //
ensight_WRITE_FIELD
#define ensight_WRITE_FIELD(PrimitiveType)
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::SymmTensor< scalar >
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::IOobjectList::findObject
const IOobject * findObject(const word &objName) const
Return const pointer to the object found by name.
Definition: IOobjectList.C:270
Foam::IOobjectList::sortedNames
wordList sortedNames() const
The sorted names of the IOobjects.
Definition: IOobjectList.C:345
Foam::writeAreaField
bool writeAreaField(ensightCase &ensCase, const ensightFaMesh &ensMesh, const tmp< GeometricField< Type, faPatchField, areaMesh >> &tfield)
Definition: writeAreaFields.H:42
Foam::ensightFaMesh
Encapsulation of area meshes for writing in ensight format.
Definition: ensightFaMesh.H:62
Foam::writeAreaFields
label writeAreaFields(ensightCase &ensCase, const ensightFaMesh &ensMesh, const IOobjectList &objects)
Definition: writeAreaFields.H:71
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
field
rDeltaTY field()
os
OBJstream os(runTime.globalPath()/outputName)
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::SphericalTensor< scalar >
Foam::IOobjectList
List of IOobjects with searching and retrieving facilities.
Definition: IOobjectList.H:55
Foam::ensightFaMesh::mesh
const faMesh & mesh() const noexcept
Reference to the underlying faMesh.
Definition: ensightFaMesh.H:104
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
areaFaMesh.H
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::faMesh
Finite area mesh. Used for 2-D non-Euclidian finite area method.
Definition: faMesh.H:82
Foam::writeAllAreaFields
label writeAllAreaFields(ensightCase &ensCase, const ensightFaMesh &ensMesh, const IOobjectList &objects)
Definition: writeAreaFields.H:105
Foam::GeometricField
Generic GeometricField class.
Definition: areaFieldsFwd.H:53