motionSolver.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-2021 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 "motionSolver.H"
30 #include "Time.H"
31 #include "polyMesh.H"
32 #include "dictionaryEntry.H"
33 #include "dlLibraryTable.H"
34 #include "twoDPointCorrector.H"
35 
36 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
37 
38 namespace Foam
39 {
42 }
43 
44 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
45 
47 (
48  const IOdictionary& dict
49 )
50 {
51  IOobject io(dict);
52  if (dict.registerObject())
53  {
54  // De-register if necessary
55  const_cast<IOdictionary&>(dict).checkOut();
56  }
57  io.registerObject(true);
58 
59  return io;
60 }
61 
62 
63 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
64 
66 :
68  (
69  IOobject
70  (
71  "dynamicMeshDict",
72  mesh.time().constant(),
73  mesh,
74  IOobject::MUST_READ_IF_MODIFIED,
75  IOobject::AUTO_WRITE
76  )
77  ),
78  mesh_(mesh)
79 {}
80 
81 
83 (
84  const polyMesh& mesh,
85  const IOdictionary& dict,
86  const word& type
87 )
88 :
89  IOdictionary(stealRegistration(dict), dict),
90  mesh_(mesh),
91  coeffDict_(dict.optionalSubDict(type + "Coeffs"))
92 {}
93 
94 
96 {
98  return nullptr;
99 }
100 
101 
102 // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
103 
105 (
106  const polyMesh& mesh,
107  const IOdictionary& solverDict
108 )
109 {
110  // The change from "solver" to "motionSolver" has not been
111  // applied consistently. Accept both without complaint.
112  const word solverName
113  (
114  solverDict.getCompat<word>("motionSolver", {{"solver", -1612}})
115  );
116 
117  Info<< "Selecting motion solver: " << solverName << nl;
118 
119  mesh.time().libs().open
120  (
121  solverDict,
122  "motionSolverLibs",
123  dictionaryConstructorTablePtr_
124  );
125 
126  if (!dictionaryConstructorTablePtr_)
127  {
129  << "solver table is empty"
130  << exit(FatalError);
131  }
132 
133  auto* ctorPtr = dictionaryConstructorTable(solverName);
134 
135  if (!ctorPtr)
136  {
138  (
139  solverDict,
140  "solver",
141  solverName,
142  *dictionaryConstructorTablePtr_
144  }
145 
146  return autoPtr<motionSolver>(ctorPtr(mesh, solverDict));
147 }
148 
149 
151 {
152  IOdictionary solverDict
153  (
154  IOobject
155  (
156  "dynamicMeshDict",
157  mesh.time().constant(),
158  mesh,
161  )
162  );
163 
164  return New(mesh, solverDict);
165 }
166 
167 
169 :
170  mesh_(mesh)
171 {}
172 
173 
174 Foam::autoPtr<Foam::motionSolver> Foam::motionSolver::iNew::operator()
175 (
176  Istream& is
177 ) const
178 {
179  dictionaryEntry dictEntry(dictionary::null, is);
180 
181  return motionSolver::New
182  (
183  mesh_,
185  (
186  IOobject
187  (
188  dictEntry.name() + ":meshSolver",
189  mesh_.time().constant(),
190  mesh_
191  ),
192  dictEntry
193  )
194  );
195 }
196 
197 
198 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
199 
201 {
202  solve();
203  return curPoints();
204 }
205 
208 {
210 }
212 
214 {}
215 
216 
218 (
220  const bool writeOnProc
221 ) const
222 {
223  return true;
224 }
225 
226 
228 {
229  if (regIOobject::read())
230  {
231  coeffDict_ = optionalSubDict(type() + "Coeffs");
232 
233  return true;
234  }
235 
236  return false;
237 }
238 
239 
240 // ************************************************************************* //
virtual bool writeObject(IOstreamOption streamOpt, const bool writeOnProc) const
Write state using stream options.
Definition: motionSolver.C:211
dictionary dict
dlLibraryTable & libs() const noexcept
Mutable access to the loaded dynamic libraries.
Definition: Time.H:730
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
virtual tmp< pointField > newPoints()
Provide new points for motion. Solves for motion.
Definition: motionSolver.C:193
virtual bool read()
Read object.
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:598
static const twoDPointCorrector & New(const polyMesh &mesh, Args &&... args)
Get existing or create a new MeshObject. Registered with typeName.
Definition: MeshObject.C:53
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tf1, const word &name, const dimensionSet &dimensions, const bool initCopy=false)
Global function forwards to reuseTmpDimensionedField::New.
Virtual base class for mesh motion solver.
Definition: motionSolver.H:54
static autoPtr< motionSolver > New(const polyMesh &)
Select constructed from polyMesh.
Definition: motionSolver.C:143
A simple container for options an IOstream can normally have.
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:360
A keyword and a list of tokens is a &#39;dictionaryEntry&#39;.
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:157
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:50
void correctPoints(pointField &p) const
Correct motion points.
const dictionary & optionalSubDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary, otherwise return this dictionary.
Definition: dictionary.C:560
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: POSIX.C:799
virtual void updateMesh(const mapPolyMesh &)=0
Update local data for topology changes.
Definition: motionSolver.C:206
dynamicFvMesh & mesh
iNew(const polyMesh &mesh)
Definition: motionSolver.C:161
A class for handling words, derived from Foam::string.
Definition: word.H:63
const Time & time() const noexcept
Return time registry.
motionSolver(const polyMesh &mesh)
Construct from polyMesh.
Definition: motionSolver.C:58
static IOobject stealRegistration(const IOdictionary &dict)
De-register object if registered and assign to current.
Definition: motionSolver.C:40
static const dictionary null
An empty dictionary, which is also the parent for all dictionaries.
Definition: dictionary.H:474
virtual void solve()=0
Solve for motion.
virtual bool read()
Read dynamicMeshDict dictionary.
Definition: motionSolver.C:220
bool checkOut()
Remove all file watches and remove object from registry.
Definition: regIOobject.C:221
const word & constant() const noexcept
Return constant name.
Definition: TimePathsI.H:112
defineRunTimeSelectionTable(reactionRateFlameArea, dictionary)
defineTypeNameAndDebug(combustionModel, 0)
T getCompat(const word &keyword, std::initializer_list< std::pair< const char *, int >> compat, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a T using any compatibility names if needed. FatalIOError if not found, or if there are excess tokens.
virtual tmp< pointField > curPoints() const =0
Provide current points for motion. Uses current motion field.
Automatically write from objectRegistry::writeObject()
messageStream Info
Information stream (stdout output on master, null elsewhere)
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
volScalarField & p
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)
A class for managing temporary objects.
Definition: HashPtrTable.H:50
bool open(bool verbose=true)
Open named, but unopened libraries. These names will normally have been added with the append() metho...
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:686
virtual autoPtr< motionSolver > clone() const
Clone function.
Definition: motionSolver.C:88
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:172
virtual void twoDCorrectPoints(pointField &) const
Definition: motionSolver.C:200
#define FatalIOErrorInLookup(ios, lookupTag, lookupName, lookupTable)
Report an error message using Foam::FatalIOError.
Definition: error.H:635
Namespace for OpenFOAM.
IOerror FatalIOError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL IO ERROR&#39; header text and ...