sampledSetsGrouping.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 | Copyright (C) 2011-2015 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 
34 {
36  vectorFields_.clear();
37  sphericalTensorFields_.clear();
38  symmTensorFields_.clear();
39  tensorFields_.clear();
40 }
41 
42 
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 
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 // ************************************************************************* //
Foam::sampledSets::fieldGroup::clear
void clear()
Reset format and field list.
Definition: sampledSets.H:93
volFields.H
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::sampledSets::vectorFields_
fieldGroup< vector > vectorFields_
Definition: sampledSets.H:188
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::sampledSets::tensorFields_
fieldGroup< tensor > tensorFields_
Definition: sampledSets.H:191
Foam::sampledSets::symmTensorFields_
fieldGroup< symmTensor > symmTensorFields_
Definition: sampledSets.H:190
Foam::IOobjectList::sortedNames
wordList sortedNames() const
Return the sorted list of names of the IOobjects.
Definition: IOobjectList.C:227
Foam::sampledSets::clearFieldGroups
void clearFieldGroups()
Clear old field groups.
Definition: sampledSetsGrouping.C:33
IOobjectList.H
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
sampledSets.H
Foam::label
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
Foam::sampledSets::appendFieldGroup
label appendFieldGroup(const word &fieldName, const word &fieldType)
Append fieldName to the appropriate group.
Definition: sampledSetsGrouping.C:44
Foam::sampledSets::classifyFields
label classifyFields()
Classify field types, returns the number of fields.
Definition: sampledSetsGrouping.C:79
Foam::IOobjectList
List of IOobjects with searching and retrieving facilities.
Definition: IOobjectList.H:50
Foam::findStrings
bool findStrings(const wordReListMatcher &matcher, const std::string &str)
Return true if string matches one of the regular expressions.
Definition: stringListOps.H:52
Foam::sampledSets::sphericalTensorFields_
fieldGroup< sphericalTensor > sphericalTensorFields_
Definition: sampledSets.H:189
Foam::sampledSets::scalarFields_
fieldGroup< scalar > scalarFields_
Definition: sampledSets.H:187
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
stringListOps.H
Operations on lists of strings.
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:259