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 writeMeshObject_H
35 #define 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,
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 // ************************************************************************* //
Foam::IOobject::NO_WRITE
Definition: IOobject.H:195
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:169
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:73
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::fileName
A class for handling file names.
Definition: fileName.H:73
Foam::Time::timeName
static word timeName(const scalar t, const int precision=precision_)
Definition: Time.C:780
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
Foam::writeMeshObject
bool writeMeshObject(const word &name, const fileName &meshDir, Time &runTime, const bool strictTypeChecking=true, const bool disableHeaderChecking=false)
Definition: writeMeshObject.H:43
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::meshObject
Definition: MeshObject.H:138
Foam::word::null
static const word null
An empty word.
Definition: word.H:80
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Foam::IOobject::MUST_READ
Definition: IOobject.H:185