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  const HashTable<const SetType*> sets
45  (
46  map.mesh().objectRegistry::lookupClass<const SetType>()
47  );
48 
49  for (const auto& iter : sets.csorted())
50  {
51  SetType& set = const_cast<SetType&>(*iter.val());
52 
53  DebugPout
54  << "Set:" << set.name() << " size:" << set.size()
55  << " updated in memory" << endl;
56 
57  set.updateMesh(map);
58 
59  // Write or not? Debatable.
60  set.write();
61  }
62 
63 
64  //
65  // Update all sets on disk
66  //
67 
68  // Get last valid mesh (discard points-only change)
69  IOobjectList objs
70  (
71  map.mesh().time(),
72  map.mesh().facesInstance(),
73  "polyMesh/sets"
74  );
75 
76  for (const IOobject& io : objs.csorted<SetType>())
77  {
78  if (!sets.contains(io.name()))
79  {
80  // Not in memory. Load it.
81  SetType set(io);
82 
83  DebugPout
84  << "Set:" << set.name() << " size:" << set.size()
85  << " updated on disk" << endl;
86 
87  set.updateMesh(map);
88  set.write();
89  }
90  else
91  {
92  DebugPout
93  << "Set:" << io.name()
94  << " already updated from memory" << endl;
95  }
96  }
97 }
98 
99 
100 // ************************************************************************* //
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)