All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
setUpdaterTemplates.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 "setUpdater.H"
27 #include "polyMesh.H"
28 #include "Time.H"
29 #include "mapPolyMesh.H"
30 #include "IOobjectList.H"
31 
32 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
33 
34 template<class Type>
35 void Foam::setUpdater::updateSets(const mapPolyMesh& morphMap) const
36 {
37  //
38  // Update all sets in memory.
39  //
40 
41  HashTable<const Type*> memSets =
42  morphMap.mesh().objectRegistry::lookupClass<Type>();
43 
44  forAllIter(typename HashTable<const Type*>, memSets, iter)
45  {
46  Type& set = const_cast<Type&>(*iter());
47 
48  if (debug)
49  {
50  Pout<< "Set:" << set.name() << " size:" << set.size()
51  << " updated in memory" << endl;
52  }
53 
54  set.updateMesh(morphMap);
55 
56  // Write or not? Debatable.
57  set.write();
58  }
59 
60 
61  //
62  // Update all sets on disk
63  //
64 
65  // Get last valid mesh (discard points-only change)
66  IOobjectList Objects
67  (
68  morphMap.mesh().time(),
69  morphMap.mesh().facesInstance(),
70  "polyMesh/sets"
71  );
72 
73  IOobjectList fileSets(Objects.lookupClass(Type::typeName));
74 
75  forAllConstIter(IOobjectList, fileSets, iter)
76  {
77  if (!memSets.found(iter.key()))
78  {
79  // Not in memory. Load it.
80  Type set(*iter());
81 
82  if (debug)
83  {
84  Pout<< "Set:" << set.name() << " size:" << set.size()
85  << " updated on disk" << endl;
86  }
87 
88  set.updateMesh(morphMap);
89 
90  set.write();
91  }
92  else
93  {
94  if (debug)
95  {
96  Pout<< "Set:" << iter.key() << " already updated from memory"
97  << endl;
98  }
99  }
100  }
101 }
102 
103 
104 // ************************************************************************* //
virtual const fileName & name() const
Return the name of the stream.
Definition: OSstream.H:82
virtual Ostream & write(const char)=0
Write character.
#define forAllIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:459
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
forAllConstIter(PtrDictionary< phaseModel >, mixture.phases(), phase)
Definition: pEqn.H:29
prefixOSstream Pout(cout, "Pout")
Definition: IOstreams.H:53