setUpdaterTemplates.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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011 OpenFOAM Foundation
9  Copyright (C) 2019-2023 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "setUpdater.H"
30 #include "polyMesh.H"
31 #include "Time.H"
32 #include "mapPolyMesh.H"
33 #include "IOobjectList.H"
34 
35 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
36 
37 template<class SetType>
38 void Foam::setUpdater::updateSets(const mapPolyMesh& map)
39 {
40  //
41  // Update all sets in memory
42  //
43 
44  // Note: objectRegistry::lookupClass() instead of
45  // objectRegistry::csorted() since it is also used to check
46  // contains() in the next bit of code
47 
48  const HashTable<const SetType*> sets
49  (
50  map.mesh().objectRegistry::lookupClass<const SetType>()
51  );
52 
53  for (const auto& iter : sets.csorted())
54  {
55  SetType& set = const_cast<SetType&>(*iter.val());
56 
57  DebugPout
58  << "Set:" << set.name() << " size:" << set.size()
59  << " updated in memory" << endl;
60 
61  set.updateMesh(map);
62 
63  // Write or not? Debatable.
64  set.write();
65  }
66 
67 
68  //
69  // Update all sets on disk
70  //
71 
72  // Get last valid mesh (discard points-only change)
73  IOobjectList objs
74  (
75  map.mesh().time(),
76  map.mesh().facesInstance(),
77  "polyMesh/sets"
78  );
79 
80  for (const IOobject& io : objs.csorted<SetType>())
81  {
82  if (!sets.contains(io.name()))
83  {
84  // Not in memory. Load it.
85  SetType set(io);
86 
87  DebugPout
88  << "Set:" << set.name() << " size:" << set.size()
89  << " updated on disk" << endl;
90 
91  set.updateMesh(map);
92  set.write();
93  }
94  else
95  {
96  DebugPout
97  << "Set:" << io.name()
98  << " already updated from memory" << endl;
99  }
100  }
101 }
102 
103 
104 // ************************************************************************* //
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
virtual bool write(const token &tok)=0
Write token to stream or otherwise handle it.
#define DebugPout
Report an information message using Foam::Pout.
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)