All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
sampledSetsGrouping.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-2018 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 
26 #include "sampledSets.H"
27 #include "volFields.H"
28 #include "IOobjectList.H"
29 #include "stringListOps.H"
30 
31 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
32 
33 void Foam::sampledSets::clearFieldGroups()
34 {
35  scalarFields_.clear();
36  vectorFields_.clear();
37  sphericalTensorFields_.clear();
38  symmTensorFields_.clear();
39  tensorFields_.clear();
40 }
41 
42 
43 Foam::label Foam::sampledSets::appendFieldGroup
44 (
45  const word& fieldName,
46  const word& fieldType
47 )
48 {
49  if (fieldType == volScalarField::typeName)
50  {
51  scalarFields_.append(fieldName);
52  return 1;
53  }
54  else if (fieldType == volVectorField::typeName)
55  {
56  vectorFields_.append(fieldName);
57  return 1;
58  }
59  else if (fieldType == volSphericalTensorField::typeName)
60  {
61  sphericalTensorFields_.append(fieldName);
62  return 1;
63  }
64  else if (fieldType == volSymmTensorField::typeName)
65  {
66  symmTensorFields_.append(fieldName);
67  return 1;
68  }
69  else if (fieldType == volTensorField::typeName)
70  {
71  tensorFields_.append(fieldName);
72  return 1;
73  }
74 
75  return 0;
76 }
77 
78 
79 Foam::label Foam::sampledSets::classifyFields()
80 {
81  label nFields = 0;
82  clearFieldGroups();
83 
84  if (loadFromFiles_)
85  {
86  // Check files for a particular time
87  IOobjectList objects(mesh_, mesh_.time().timeName());
88  wordList allFields = objects.sortedNames();
89 
90  forAll(fieldSelection_, i)
91  {
92  labelList indices = findStrings(fieldSelection_[i], allFields);
93 
94  if (indices.size())
95  {
96  forAll(indices, fieldi)
97  {
98  const word& fieldName = allFields[indices[fieldi]];
99 
100  nFields += appendFieldGroup
101  (
102  fieldName,
103  objects.find(fieldName)()->headerClassName()
104  );
105  }
106  }
107  else
108  {
110  << "Cannot find field file matching "
111  << fieldSelection_[i] << endl;
112  }
113  }
114  }
115  else
116  {
117  // Check currently available fields
118  wordList allFields = mesh_.sortedNames();
119  labelList indices = findStrings(fieldSelection_, allFields);
120 
121  forAll(fieldSelection_, i)
122  {
123  labelList indices = findStrings(fieldSelection_[i], allFields);
124 
125  if (indices.size())
126  {
127  forAll(indices, fieldi)
128  {
129  const word& fieldName = allFields[indices[fieldi]];
130 
131  nFields += appendFieldGroup
132  (
133  fieldName,
134  mesh_.find(fieldName)()->type()
135  );
136  }
137  }
138  else
139  {
141  << "Cannot find registered field matching "
142  << fieldSelection_[i] << endl;
143  }
144  }
145  }
146 
147  return nFields;
148 }
149 
150 
151 // ************************************************************************* //
#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
static const char *const typeName
Definition: Field.H:105
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
static word timeName(const scalar, const int precision=precision_)
Return time name of given scalar time.
Definition: Time.C:636
Operations on lists of strings.
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:239
bool findStrings(const wordReListMatcher &matcher, const std::string &str)
Return true if string matches one of the regular expressions.
Definition: stringListOps.H:52
iterator find(const Key &)
Find and return an iterator set at the hashedEntry.
Definition: HashTable.C:142
wordList sortedNames() const
Return the sorted list of names of the IOobjects.
virtual const word & type() const =0
Runtime type information.
List< label > labelList
A List of labels.
Definition: labelList.H:56
objects
List< word > wordList
A List of words.
Definition: fileName.H:54
#define WarningInFunction
Report a warning using Foam::Warning.