lagrangianFieldReconstructorTemplates.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-2023 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 #include "IOobjectList.H"
28 #include "CompactIOField.H"
29 
30 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
31 
32 template<class FieldType>
33 bool Foam::lagrangianFieldReconstructor::reconstructs
34 (
35  const IOobjectList& objects,
36  const HashSet<word>& selectedFields
37 )
38 {
39  IOobjectList fields = objects.lookupClass(FieldType::typeName);
40 
41  if (fields.size() && selectedFields.empty())
42  {
43  return true;
44  }
45 
46  forAllConstIter(IOobjectList, fields, fieldIter)
47  {
48  if (selectedFields.found(fieldIter()->name()))
49  {
50  return true;
51  }
52  }
53 
54  return false;
55 }
56 
57 
58 template
59 <
60  class Type,
61  template<class> class IOContainer,
62  template<class> class IOContainerType
63 >
65 Foam::lagrangianFieldReconstructor::reconstructField
66 (
67  const IOobject& fieldIoObject
68 ) const
69 {
70  // Construct the complete field
71  tmp<IOContainer<Type>> tfield
72  (
73  new IOContainer<Type>
74  (
75  IOobject
76  (
77  fieldIoObject.name(),
78  completeMesh_.time().name(),
79  cloud::prefix/cloudName_,
80  completeMesh_,
83  ),
84  Field<Type>(0)
85  )
86  );
87  Field<Type>& field = tfield.ref();
88 
89  // Combine the processor fields into the complete field
90  forAll(procMeshes_, proci)
91  {
92  typeIOobject<IOContainerType<Type>> localIOobject
93  (
94  fieldIoObject.name(),
95  procMeshes_[proci].time().name(),
96  cloud::prefix/cloudName_,
97  procMeshes_[proci],
100  );
101 
102  if (localIOobject.headerOk())
103  {
104  IOContainer<Type> fieldi(localIOobject);
105 
106  label offset = field.size();
107  field.setSize(offset + fieldi.size());
108 
109  forAll(fieldi, j)
110  {
111  field[offset + j] = fieldi[j];
112  }
113  }
114  }
115 
116  return tfield;
117 }
118 
119 
120 template
121 <
122  class Type,
123  template<class> class IOContainer,
124  template<class> class IOContainerType
125 >
126 void Foam::lagrangianFieldReconstructor::reconstructFields
127 (
128  const IOobjectList& objects,
129  const HashSet<word>& selectedFields
130 )
131 {
132  const word& fieldClassName = IOContainerType<Type>::typeName;
133 
134  IOobjectList fields = objects.lookupClass(fieldClassName);
135 
136  if (fields.size())
137  {
138  Info<< nl << " Reconstructing lagrangian "
139  << fieldClassName << "s" << nl << endl;
140 
141  forAllConstIter(IOobjectList, fields, fieldIter)
142  {
143  if
144  (
145  selectedFields.empty()
146  || selectedFields.found(fieldIter()->name())
147  )
148  {
149  Info<< " " << fieldIter()->name() << endl;
150 
151  reconstructField<Type, IOContainer, IOContainerType>
152  (
153  *fieldIter()
154  )().write();
155  }
156  }
157  }
158 }
159 
160 
161 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
162 
163 template<class Type>
164 void Foam::lagrangianFieldReconstructor::reconstructFields
165 (
166  const IOobjectList& objects,
167  const HashSet<word>& selectedFields
168 )
169 {
170  reconstructFields<Type, IOField, IOField>
171  (objects, selectedFields);
172  reconstructFields<Field<Type>, CompactIOField, IOField>
173  (objects, selectedFields);
174  reconstructFields<Field<Type>, CompactIOField, CompactIOField>
175  (objects, selectedFields);
176 }
177 
178 
179 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
#define forAllConstIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:477
static const word prefix
The prefix to local: lagrangian.
Definition: cloud.H:63
A class for managing temporary objects.
Definition: tmp.H:55
Info<< "Calculating turbulent flame speed field St\n"<< endl;volScalarField St(IOobject("St", runTime.name(), mesh, IOobject::NO_READ, IOobject::AUTO_WRITE), flameWrinkling->Xi() *Su);multivariateSurfaceInterpolationScheme< scalar >::fieldTable fields
Definition: createFields.H:228
void write(std::ostream &os, const bool binary, List< floatScalar > &fField)
Write floats ascii or binary.
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
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:257
word name(const bool)
Return a word representation of a bool.
Definition: boolIO.C:39
messageStream Info
void offset(label &lst, const label o)
static const char nl
Definition: Ostream.H:266
objects