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-2022 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
12
13InNamespace
14 Foam
15
16Description
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
30namespace Foam
31{
32
33template<class Type>
35(
36 ensightCase& ensCase,
37 const ensightMesh& ensMesh,
38 const tmp<PointField<Type>>& tfield
39)
40{
41 if (!tfield)
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
63template<class Type>
65(
66 ensightCase& ensCase,
67 const ensightMesh& ensMesh,
68 const IOobjectList& objects
69)
70{
71 typedef PointField<Type> FieldType;
73 const pointMesh& ptMesh = pointMesh::New(ensMesh.mesh());
74
75 label count = 0;
76
77 for (const word& fieldName : objects.sortedNames<FieldType>())
78 {
79 if
80 (
81 writePointField<Type>
82 (
83 ensCase,
84 ensMesh,
85 getField<FieldType>(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);
116 count += ensight_WRITE_FIELD(vector);
119 count += ensight_WRITE_FIELD(tensor);
120
121 #undef ensight_WRITE_FIELD
122 return count;
123}
124
125} // End namespace Foam
126
127// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
128
129#endif
130
131// ************************************************************************* //
List of IOobjects with searching and retrieving facilities.
Definition: IOobjectList.H:59
wordList sortedNames() const
The sorted names of the IOobjects.
Definition: IOobjectList.C:383
static autoPtr< Time > New()
Construct (dummy) Time - no functionObjects or libraries.
Definition: Time.C:717
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: autoPtr.H:66
Supports writing of ensight cases as well as providing common factory methods to open new files.
Definition: ensightCase.H:69
autoPtr< ensightFile > newData(const word &varName, const bool isPointData=false) const
Open stream for new data file (on master), with current index.
Encapsulation of volume meshes for writing in ensight format. It manages cellZones,...
Definition: ensightMesh.H:83
const polyMesh & mesh() const noexcept
Reference to the underlying polyMesh.
Definition: ensightMesh.H:159
Mesh representing a set of points created from polyMesh.
Definition: pointMesh.H:55
A class for managing temporary objects.
Definition: tmp.H:65
A class for handling words, derived from Foam::string.
Definition: word.H:68
rDeltaTY field()
OBJstream os(runTime.globalPath()/outputName)
#define ensight_WRITE_FIELD(PrimitiveType)
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of 'true' entries.
Definition: BitOps.H:78
Namespace for OpenFOAM.
label writeAllPointFields(ensightCase &ensCase, const ensightMesh &ensMesh, const IOobjectList &objects)
messageStream Info
Information stream (stdout output on master, null elsewhere)
bool writePointField(ensightCase &ensCase, const ensightMesh &ensMesh, const tmp< PointField< Type > > &tfield)
label writePointFields(ensightCase &ensCase, const ensightMesh &ensMesh, const IOobjectList &objects)