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-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 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 {
51  IOobject io
52  (
53  name,
54  runTime.timeName(),
55  meshDir,
56  runTime,
59  false
60  );
61 
62  bool writeOk = false;
63 
64  if
65  (
66  io.typeHeaderOk<Type>(false)
67  && io.headerClassName() == CheckType::typeName
68  )
69  {
70  Info<< " Reading " << io.headerClassName()
71  << " : " << name << endl;
72 
73  // Switch off type checking (for reading e.g. faceZones as
74  // generic list of dictionaries).
75  word oldTypeName;
76  if (disableHeaderChecking)
77  {
78  oldTypeName = Type::typeName;
79  const_cast<word&>(Type::typeName) = word::null;
80  }
81 
82  Type meshObject(io);
83 
84  if (disableHeaderChecking)
85  {
86  const_cast<word&>(Type::typeName) = oldTypeName;
87  // Fake type back to what was in field
88  const_cast<word&>(meshObject.type()) = io.headerClassName();
89  }
90 
91  Info<< " Writing " << name << endl;
92  writeOk = meshObject.regIOobject::write();
93  }
94 
95  return writeOk;
96 }
97 
98 
99 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
100 
101 } // End namespace Foam
102 
103 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
104 
105 #endif
106 
107 // ************************************************************************* //
A class for handling file names.
Definition: fileName.H:69
engineTime & runTime
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:256
static word timeName(const scalar, const int precision=precision_)
Return time name of given scalar time.
Definition: Time.C:626
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
A class for handling words, derived from string.
Definition: word.H:59
static const word null
An empty word.
Definition: word.H:77
bool writeMeshObject(const word &name, const fileName &meshDir, Time &runTime, bool disableHeaderChecking=false)
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
messageStream Info
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:92
Namespace for OpenFOAM.