writeMeshObject.H
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-2022 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 Global
25  writeMeshObject
26 
27 Description
28  Write a mesh object in the format specified in controlDict.
29 
30 \*---------------------------------------------------------------------------*/
31 
32 #ifndef writeMeshObject_H
33 #define writeMeshObject_H
34 
35 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
36 
37 namespace Foam
38 {
39 
40 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
41 
42 template<class Type, class CheckType = Type>
43 inline bool writeMeshObject
44 (
45  const word& name,
46  const fileName& meshDir,
47  Time& runTime,
48  bool disableHeaderChecking = false
49 )
50 {
52  (
53  name,
54  runTime.name(),
55  meshDir,
56  runTime,
59  false
60  );
61 
62  bool writeOk = false;
63 
64  if (io.headerOk())
65  {
66  Info<< " Reading " << io.headerClassName()
67  << " : " << name << endl;
68 
69  // Switch off type checking (for reading e.g. faceZones as
70  // generic list of dictionaries).
71  word oldTypeName;
72  if (disableHeaderChecking)
73  {
74  oldTypeName = Type::typeName;
75  const_cast<word&>(Type::typeName) = word::null;
76  }
77 
78  Type meshObject(io);
79 
80  if (disableHeaderChecking)
81  {
82  const_cast<word&>(Type::typeName) = oldTypeName;
83  // Fake type back to what was in field
84  const_cast<word&>(meshObject.type()) = io.headerClassName();
85  }
86 
87  Info<< " Writing " << name << endl;
88  writeOk = meshObject.regIOobject::write();
89  }
90 
91  return writeOk;
92 }
93 
94 
95 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
96 
97 } // End namespace Foam
98 
99 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
100 
101 #endif
102 
103 // ************************************************************************* //
const word & headerClassName() const
Return name of the class name read from header.
Definition: IOobject.H:316
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:76
const word & name() const
Return const reference to name.
A class for handling file names.
Definition: fileName.H:82
Templated form of IOobject providing type information for file reading and header type checking.
Definition: IOobject.H:531
bool headerOk()
Read header (uses typeGlobalFile to find file) and check.
A class for handling words, derived from string.
Definition: word.H:62
static const word null
An empty word.
Definition: word.H:77
Namespace for OpenFOAM.
bool writeMeshObject(const word &name, const fileName &meshDir, Time &runTime, bool disableHeaderChecking=false)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
messageStream Info
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47