All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
steadyParticleTracksTemplates.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
27 
28 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
29 
30 template<class Type>
31 bool Foam::fieldOk(const IOobjectList& cloudObjs, const word& name)
32 {
33  IOobjectList objects(cloudObjs.lookupClass(IOField<Type>::typeName));
34 
35  return (objects.lookup(name) != nullptr);
36 }
37 
38 
39 template<class Type>
41 (
42  const word& name,
43  const IOobjectList cloudObjs
44 )
45 {
46  IOobjectList objects(cloudObjs.lookupClass(IOField<Type>::typeName));
47 
48  const IOobject* obj = objects.lookup(name);
49  if (obj != nullptr)
50  {
51  IOField<Type> newField(*obj);
52  return tmp<Field<Type>>(new Field<Type>(move(newField)));
53  }
54 
56  << "error: cloud field name " << name << " not found"
57  << abort(FatalError);
58 
59  return Field<Type>::null();
60 }
61 
62 
63 template<class Type>
65 (
66  PtrList<List<Type>>& values,
67  const List<word>& fieldNames,
68  const IOobjectList& cloudObjs
69 )
70 {
71  IOobjectList objects(cloudObjs.lookupClass(IOField<Type>::typeName));
72 
73  forAll(fieldNames, j)
74  {
75  const IOobject* obj = objects.lookup(fieldNames[j]);
76  if (obj != nullptr)
77  {
78  Info<< " reading field " << fieldNames[j] << endl;
79  IOField<Type> newField(*obj);
80  values.set(j, new List<Type>(move(newField)));
81  }
82  else
83  {
85  << "Unable to read field " << fieldNames[j]
86  << abort(FatalError);
87  }
88  }
89 }
90 
91 
92 template<class Type>
93 void Foam::writeVTK(OFstream& os, const Type& value)
94 {
95  os << value.component(0);
96  for (label i=1; i<pTraits<Type>::nComponents; i++)
97  {
98  os << ' ' << value.component(i);
99  }
100 }
101 
102 
103 template<class Type>
105 (
106  OFstream& os,
107  const PtrList<List<Type>>& values,
108  const List<List<label>>& addr,
109  const List<word>& fieldNames
110 )
111 {
112  label step = max(floor(8/pTraits<Type>::nComponents), 1);
113 
114  forAll(values, fieldi)
115  {
116  Info<< " writing field " << fieldNames[fieldi] << endl;
117  os << nl << fieldNames[fieldi] << ' ' << pTraits<Type>::nComponents
118  << ' ' << values[fieldi].size() << " float" << nl;
119  label offset = 0;
120  forAll(addr, trackI)
121  {
122  const List<label> ids(addr[trackI]);
123 
124  List<Type> data(UIndirectList<Type>(values[fieldi], ids));
125  label nData = data.size() - 1;
126  forAll(data, i)
127  {
128  writeVTK<Type>(os, data[i]);
129  if (((i + 1) % step == 0) || (i == nData))
130  {
131  os << nl;
132  }
133  else
134  {
135  os << ' ';
136  }
137  }
138  offset += ids.size();
139  }
140  }
141 }
142 
143 
144 template<class Type>
146 (
147  OFstream& os,
148  const List<List<label>>& addr,
149  const List<word>& userFieldNames,
150  const IOobjectList& cloudObjs
151 )
152 {
153  IOobjectList objects(cloudObjs.lookupClass(IOField<Type>::typeName));
154 
155  if (objects.size())
156  {
157  DynamicList<word> fieldNames(objects.size());
158  forAll(userFieldNames, i)
159  {
160  IOobject* obj = objects.lookup(userFieldNames[i]);
161  if (obj != nullptr)
162  {
163  fieldNames.append(obj->name());
164  }
165  }
166  fieldNames.shrink();
167 
168  PtrList<List<Type>> values(fieldNames.size());
169  readFields<Type>(values, fieldNames, cloudObjs);
170 
171  writeVTKFields<Type>
172  (
173  os,
174  values,
175  addr,
176  fieldNames
177  );
178  }
179 }
180 
181 
182 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
void readFields(const typename GeoFieldType::Mesh &mesh, const IOobjectList &objects, const HashSet< word > &selectedFields, LIFOStack< regIOobject *> &storedObjects)
Read the selected GeometricFields of the specified type.
Definition: ReadFields.C:244
error FatalError
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:323
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
static List< word > fieldNames
Definition: globalFoam.H:46
bool fieldOk(const IOobjectList &cloudObjs, const word &name)
tmp< Field< Type > > readParticleField(const word &name, const IOobjectList cloudObjs)
void processFields(OFstream &os, const List< List< label >> &addr, const List< word > &userFieldNames, const IOobjectList &cloudObjs)
errorManip< error > abort(error &err)
Definition: errorManip.H:131
static const char nl
Definition: Ostream.H:260
objects
void writeVTKFields(OFstream &os, const PtrList< List< Type >> &values, const List< List< label >> &addr, const List< word > &fieldNames)
messageStream Info
void writeVTK(OFstream &os, const Type &value)
A class for managing temporary objects.
Definition: PtrList.H:53