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-------------------------------------------------------------------------------
10License
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
26Global
27 writeMeshObject
28
29Description
30 Write a mesh object in the format specified in controlDict.
31
32\*---------------------------------------------------------------------------*/
33
34#ifndef writeMeshObject_H
35#define writeMeshObject_H
36
37// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
38
39namespace Foam
40{
41
42// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43
44template<class Type, class CheckType = Type>
45inline bool writeMeshObject
46(
47 const word& name,
48 const fileName& meshDir,
50 const bool strictTypeChecking = true,
51 const bool disableHeaderChecking = false
52)
53{
55 (
56 name,
58 meshDir,
59 runTime,
62 false
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 word oldTypeName;
75 if (disableHeaderChecking)
76 {
77 oldTypeName = Type::typeName;
78 const_cast<word&>(Type::typeName) = word::null;
79 }
80
81 Type meshObject(io);
82
83 if (disableHeaderChecking)
84 {
85 const_cast<word&>(Type::typeName) = oldTypeName;
86 // Fake type back to what was in field
87 const_cast<word&>(meshObject.type()) = io.headerClassName();
88 }
89
90 Info<< " Writing " << name << endl;
91 writeOk = meshObject.regIOobject::write();
92 }
93
94 return writeOk;
95}
96
97
98// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
99
100} // End namespace Foam
101
102// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
103
104#endif
105
106// ************************************************************************* //
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:170
const word & headerClassName() const noexcept
Return name of the class name read from header.
Definition: IOobjectI.H:83
bool typeHeaderOk(const bool checkType=true, const bool search=true, const bool verbose=true)
Read header (uses typeFilePath to find file) and check its info.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:80
static word timeName(const scalar t, const int precision=precision_)
Definition: Time.C:780
A class for handling file names.
Definition: fileName.H:76
A class for handling words, derived from Foam::string.
Definition: word.H:68
engineTime & runTime
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, false)
Namespace for OpenFOAM.
messageStream Info
Information stream (stdout output on master, null elsewhere)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
bool writeMeshObject(const word &name, const fileName &meshDir, Time &runTime, const bool strictTypeChecking=true, const bool disableHeaderChecking=false)
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59