dynamicFvMeshNew.C
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  Copyright (C) 2019-2020 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "staticFvMesh.H"
31 #include "argList.H"
32 
33 // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
34 
36 {
37  // Note: - do not register the dictionary since dynamicFvMeshes themselves
38  // do this.
39  // - defaultRegion (region0) gets loaded from constant, other ones
40  // get loaded from constant/<regionname>. Normally we'd use
41  // polyMesh::dbDir() but we haven't got a polyMesh yet ...
42  IOobject dictHeader
43  (
44  "dynamicMeshDict",
45  io.time().constant(),
46  (io.name() == polyMesh::defaultRegion ? "" : io.name()),
47  io.db(),
50  false // Do not register
51  );
52 
53  if (dictHeader.typeHeaderOk<IOdictionary>(true))
54  {
55  IOdictionary dict(dictHeader);
56 
57  const word modelType(dict.get<word>("dynamicFvMesh"));
58 
59  Info<< "Selecting dynamicFvMesh " << modelType << endl;
60 
61  io.time().libs().open
62  (
63  dict,
64  "dynamicFvMeshLibs",
65  IOobjectConstructorTablePtr_
66  );
67 
68  if (!IOobjectConstructorTablePtr_)
69  {
71  << "dynamicFvMesh table is empty"
72  << exit(FatalError);
73  }
74 
75  auto doInitCstrIter = doInitConstructorTablePtr_->cfind(modelType);
76 
77  if (doInitCstrIter.found())
78  {
79  DebugInfo
80  << "Constructing dynamicFvMesh with explicit initialisation"
81  << endl;
82 
83  // Two-step constructor
84  // 1. Construct mesh, do not initialise
85  autoPtr<dynamicFvMesh> meshPtr(doInitCstrIter()(io, false));
86 
87  // 2. Initialise parents and itself
88  meshPtr().init(true);
89 
90  return meshPtr;
91  }
92 
93  auto cstrIter = IOobjectConstructorTablePtr_->cfind(modelType);
94 
95  if (!cstrIter.found())
96  {
98  (
99  dict,
100  "dynamicFvMesh",
101  modelType,
102  *IOobjectConstructorTablePtr_
103  ) << exit(FatalIOError);
104  }
105 
106  return autoPtr<dynamicFvMesh>(cstrIter()(io));
107  }
108 
109  DebugInfo
110  << "Constructing staticFvMesh with explicit initialisation" << endl;
111 
112  // 1. Construct mesh, do not initialise
114 
115  // 2. Initialise parents and itself
116  meshPtr().init(true);
117 
118  return meshPtr;
119 }
120 
121 
123 (
124  const argList& args,
125  const Time& runTime
126 )
127 {
128  if (args.found("dry-run") || args.found("dry-run-write"))
129  {
130  Info
131  << "Operating in 'dry-run' mode: case will run for 1 time step. "
132  << "All checks assumed OK on a clean exit" << endl;
133 
135 
136  // Stop after 1 iteration of the simplified mesh
137 
138  if (args.found("dry-run-write"))
139  {
140  // Using saWriteNow triggers function objects execute(), write()
142  }
143  else
144  {
145  // Using saNoWriteNow triggers function objects execute(),
146  // but not write()
148  }
149 
150  functionObject::outputPrefix = "postProcessing-dry-run";
151 
152  return
154  (
155  IOobject
156  (
158  runTime.timeName(),
159  runTime,
161  )
162  );
163  }
164  else
165  {
166  return
167  New
168  (
169  IOobject
170  (
172  runTime.timeName(),
173  runTime,
175  )
176  );
177  }
178 }
179 
180 
181 // ************************************************************************* //
Foam::IOobject::NO_WRITE
Definition: IOobject.H:130
Foam::IOdictionary
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:54
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:104
meshPtr
Foam::autoPtr< Foam::fvMesh > meshPtr(nullptr)
Foam::staticFvMesh
Foam::staticFvMesh.
Definition: staticFvMesh.H:51
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:73
Foam::IOobject::name
const word & name() const
Return name.
Definition: IOobjectI.H:70
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::dynamicFvMesh::New
static autoPtr< dynamicFvMesh > New(const IOobject &io)
Select, construct and return the dynamicFvMesh.
Definition: dynamicFvMeshNew.C:35
Foam::polyMesh::defaultRegion
static word defaultRegion
Return the default region name.
Definition: polyMesh.H:318
Foam::FieldBase::allowConstructFromLargerSize
static bool allowConstructFromLargerSize
Definition: FieldBase.H:61
Foam::Time::timeName
static word timeName(const scalar t, const int precision=precision_)
Definition: Time.C:780
Foam::Time::stopAt
virtual stopAtControls stopAt() const
Return the stop control information.
Definition: Time.C:879
Foam::argList
Extract command arguments and options from the supplied argc and argv parameters.
Definition: argList.H:123
Foam::FatalIOError
IOerror FatalIOError
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:350
Foam::IOobject::time
const Time & time() const
Return time.
Definition: IOobject.C:463
Foam::IOobject::db
const objectRegistry & db() const
Return the local objectRegistry.
Definition: IOobject.C:457
FatalIOErrorInLookup
#define FatalIOErrorInLookup(ios, lookupTag, lookupName, lookupTable)
Report an error message using Foam::FatalIOError.
Definition: error.H:406
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
argList.H
Foam::Time::saNoWriteNow
Adjust endTime to stop immediately w/o writing.
Definition: Time.H:100
Foam::functionObject::outputPrefix
static word outputPrefix
Directory prefix.
Definition: functionObject.H:352
simplifiedDynamicFvMesh.H
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::FatalError
error FatalError
Foam::Time::libs
dlLibraryTable & libs() const
Mutable access to the loaded dynamic libraries.
Definition: Time.H:505
Foam::dlLibraryTable::open
bool open(bool verbose=true)
Definition: dlLibraryTable.C:409
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
staticFvMesh.H
Foam::New
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
Definition: DimensionedFieldReuseFunctions.H:105
Foam::simplifiedMeshes::simplifiedDynamicFvMeshBase::New
static autoPtr< dynamicFvMesh > New(const IOobject &io)
Return a reference to the selected simplified mesh.
Definition: simplifiedDynamicFvMesh.C:46
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:381
DebugInfo
#define DebugInfo
Report an information message using Foam::Info.
Definition: messageStream.H:359
Foam::HashTable::cfind
const_iterator cfind(const Key &key) const
Find and return an const_iterator set at the hashed entry.
Definition: HashTableI.H:141
Foam::Time::saWriteNow
adjust endTime to stop immediately w/ writing
Definition: Time.H:101
Foam::IOobject::MUST_READ_IF_MODIFIED
Definition: IOobject.H:121
Foam::TimePaths::constant
const word & constant() const
Return constant name.
Definition: TimePathsI.H:88
args
Foam::argList args(argc, argv)
Foam::argList::found
bool found(const word &optName) const
Return true if the named option is found.
Definition: argListI.H:151
Foam::IOobject::MUST_READ
Definition: IOobject.H:120