steadyParticleTracksTemplates.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) 2011-2016 OpenFOAM Foundation
9 Copyright (C) 2016-2022 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27\*---------------------------------------------------------------------------*/
28
30
31// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32
33template<class Type>
35(
36 const word& fieldName,
37 const IOobjectList& cloudObjects
38)
39{
40 const IOobject* io = cloudObjects.cfindObject<IOField<Type>>(fieldName);
41 if (io)
42 {
43 return tmp<IOField<Type>>::New(*io);
44 }
45
47 << "Cloud field name " << fieldName
48 << " not found or the incorrect type"
49 << abort(FatalError);
50
51 return nullptr;
52}
53
54
55template<class Type>
56void Foam::writeVTK(OFstream& os, const Type& value)
57{
58 os << component(value, 0);
59 for (label d=1; d < pTraits<Type>::nComponents; ++d)
60 {
61 os << ' ' << component(value, d);
62 }
63}
64
65
66template<class Type>
68(
69 OFstream& os,
70 const IOField<Type>& field,
71 const List<labelList>& addr
72)
73{
74 const label step = max(1, floor(8/pTraits<Type>::nComponents));
75
76 Info<< " writing field " << field.name() << endl;
77 os << nl << field.name() << ' '
78 << int(pTraits<Type>::nComponents) << ' '
79 << field.size() << " float" << nl;
80
82 for (const labelList& ids : addr)
83 {
84 List<Type> data(UIndirectList<Type>(field, ids));
85 label nData = data.size() - 1;
86 forAll(data, i)
87 {
88 writeVTK<Type>(os, data[i]);
89 if (((i + 1) % step == 0) || (i == nData))
90 {
91 os << nl;
92 }
93 else
94 {
95 os << ' ';
96 }
97 }
99 }
100}
101
102
103template<class Type>
105(
106 OFstream& os,
107 const List<labelList>& addr,
108 const IOobjectList& cloudObjects
109)
110{
111 for (const word& fldName : cloudObjects.sortedNames<IOField<Type>>())
112 {
113 const IOobject* io = cloudObjects.cfindObject<IOField<Type>>(fldName);
114
115 if (!io)
116 {
118 << "Could not read field:" << fldName
119 << " type:" << IOField<Type>::typeName
120 << abort(FatalError);
121 }
122 else
123 {
124 Info<< " reading field " << fldName << endl;
125 IOField<Type> field(*io);
126
127 writeVTKField<Type>(os, field, addr);
128 }
129 }
130}
131
132
133// ************************************************************************* //
Y[inertIndex] max(0.0)
A class for managing temporary objects.
Definition: tmp.H:65
rDeltaTY field()
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
OBJstream os(runTime.globalPath()/outputName)
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, false)
void component(FieldField< Field, typename FieldField< Field, Type >::cmptType > &sf, const FieldField< Field, Type > &f, const direction d)
void writeVTK(OFstream &os, const Type &value)
messageStream Info
Information stream (stdout output on master, null elsewhere)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
void processFields(OFstream &os, const List< labelList > &addr, const IOobjectList &cloudObjects)
errorManip< error > abort(error &err)
Definition: errorManip.H:144
tmp< IOField< Type > > readParticleField(const word &fieldName, const IOobjectList &cloudObjects)
void writeVTKField(OFstream &os, const IOField< Type > &field, const List< labelList > &addr)
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333