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-2023 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
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 
33 template<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 
55 template<class Type>
56 void 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 
66 template<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 
103 template<class Type>
105 (
106  OFstream& os,
107  const List<labelList>& addr,
108  const IOobjectList& cloudObjects
109 )
110 {
111  for (const IOobject& io : cloudObjects.csorted<IOField<Type>>())
112  {
113  Info<< " reading field " << io.name() << endl;
114  IOField<Type> field(io);
115 
116  writeVTKField<Type>(os, field, addr);
117  }
118 }
119 
120 
121 // ************************************************************************* //
rDeltaTY field()
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:608
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:40
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
void writeVTKField(OFstream &os, const IOField< Type > &field, const List< labelList > &addr)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tf1, const word &name, const dimensionSet &dimensions, const bool initCopy=false)
Global function forwards to reuseTmpDimensionedField::New.
::Foam::direction nComponents(const expressions::valueTypeCode) noexcept
The number of components associated with given valueTypeCode.
Definition: exprTraits.C:40
void processFields(OFstream &os, const List< labelList > &addr, const IOobjectList &cloudObjects)
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
errorManip< error > abort(error &err)
Definition: errorManip.H:139
OBJstream os(runTime.globalPath()/outputName)
messageStream Info
Information stream (stdout output on master, null elsewhere)
tmp< IOField< Type > > readParticleField(const word &fieldName, const IOobjectList &cloudObjects)
void writeVTK(OFstream &os, const Type &value)
List< label > labelList
A List of labels.
Definition: List.H:62
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)
A class for managing temporary objects.
Definition: HashPtrTable.H:50
void component(FieldField< Field, typename FieldField< Field, Type >::cmptType > &sf, const FieldField< Field, Type > &f, const direction d)