writeMeshObject.H
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-2017 OpenFOAM Foundation
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 Global
27  writeMeshObject
28 
29 Description
30  Write a mesh object in the format specified in controlDict.
31 
32 \*---------------------------------------------------------------------------*/
33 
34 #ifndef Foam_writeMeshObject_H
35 #define Foam_writeMeshObject_H
36 
37 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
38 
39 namespace Foam
40 {
41 
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 
44 template<class Type, class CheckType = Type>
45 inline bool writeMeshObject
46 (
47  const word& name,
48  const fileName& meshDir,
49  Time& runTime,
50  const bool strictTypeChecking = true,
51  const bool disableHeaderChecking = false
52 )
53 {
54  IOobject io
55  (
56  name,
57  runTime.timeName(),
58  meshDir,
59  runTime,
63  );
64 
65  bool writeOk = false;
66 
67  if (io.typeHeaderOk<CheckType>(strictTypeChecking, true, false))
68  {
69  Info<< " Reading " << io.headerClassName()
70  << " : " << name << endl;
71 
72  // Switch off type checking (for reading e.g. faceZones as
73  // generic list of dictionaries).
74  const word oldTypeName = Type::typeName;
75  if (disableHeaderChecking)
76  {
77  const_cast<word&>(Type::typeName) = word::null;
78  }
79 
80  Type meshObject(io);
81 
82  if (disableHeaderChecking)
83  {
84  const_cast<word&>(Type::typeName) = oldTypeName;
85  // Fake type back to what was in field
86  const_cast<word&>(meshObject.type()) = io.headerClassName();
87  }
88 
89  Info<< " Writing " << name << endl;
90  writeOk = meshObject.regIOobject::write();
91  }
92 
93  return writeOk;
94 }
95 
96 
97 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
98 
99 } // End namespace Foam
100 
101 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
102 
103 #endif
104 
105 // ************************************************************************* //
bool writeMeshObject(const word &name, const fileName &meshDir, Time &runTime, const bool strictTypeChecking=true, const bool disableHeaderChecking=false)
A class for handling file names.
Definition: fileName.H:72
The meshObject is a concrete regIOobject.
Definition: MeshObject.H:179
engineTime & runTime
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
Ignore writing from objectRegistry::writeObject()
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:69
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
A class for handling words, derived from Foam::string.
Definition: word.H:63
static const word null
An empty word.
Definition: word.H:84
bool typeHeaderOk(const bool checkType=true, const bool search=true, const bool verbose=true)
Read header (respects is_globalIOobject trait) and check its info.
static word timeName(const scalar t, const int precision=precision_)
Return a time name for the given scalar time value formatted with the given precision.
Definition: Time.C:714
const word & headerClassName() const noexcept
Return name of the class name read from header.
Definition: IOobjectI.H:213
messageStream Info
Information stream (stdout output on master, null elsewhere)
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:172
Do not request registration (bool: false)
Namespace for OpenFOAM.