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 {
40  defineTypeNameAndDebug(motionSolver, 0);
41  defineRunTimeSelectionTable(motionSolver, dictionary);
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_
143  ) << exit(FatalIOError);
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 
206 
208 {
210 }
211 
212 
214 {}
215 
216 
218 (
220  const bool valid
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 // ************************************************************************* //
Foam::motionSolver::New
static autoPtr< motionSolver > New(const polyMesh &)
Select constructed from polyMesh.
Definition: motionSolver.C:150
Foam::IOdictionary
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:54
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:169
Foam::dictionaryEntry
A keyword and a list of tokens is a 'dictionaryEntry'.
Definition: dictionaryEntry.H:65
p
volScalarField & p
Definition: createFieldRefs.H:8
Foam::IOobject::AUTO_WRITE
Definition: IOobject.H:194
Foam::dictionaryEntry::name
virtual const fileName & name() const
Return the scoped dictionary name (eg, dictA.dictB.dictC)
Definition: dictionaryEntry.H:116
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::IOobject::registerObject
bool registerObject() const noexcept
Should object created with this IOobject be registered?
Definition: IOobjectI.H:107
motionSolver.H
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::defineRunTimeSelectionTable
defineRunTimeSelectionTable(reactionRateFlameArea, dictionary)
Foam::MeshObject< polyMesh, UpdateableMeshObject, twoDPointCorrector >::New
static const twoDPointCorrector & New(const polyMesh &mesh, Args &&... args)
Get existing or create a new MeshObject.
Definition: MeshObject.C:48
Foam::regIOobject::read
virtual bool read()
Read object.
Definition: regIOobjectRead.C:191
Foam::motionSolver::twoDCorrectPoints
virtual void twoDCorrectPoints(pointField &) const
Definition: motionSolver.C:207
Foam::FatalIOError
IOerror FatalIOError
Foam::motionSolver::motionSolver
motionSolver(const polyMesh &mesh)
Construct from polyMesh.
Definition: motionSolver.C:65
Foam::dictionary::getCompat
T getCompat(const word &keyword, std::initializer_list< std::pair< const char *, int >> compat, enum keyType::option=keyType::REGEX) const
Definition: dictionaryTemplates.C:134
polyMesh.H
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
Foam::motionSolver::solve
virtual void solve()=0
Solve for motion.
Foam::dictionary::null
static const dictionary null
An empty dictionary, which is also the parent for all dictionaries.
Definition: dictionary.H:392
NotImplemented
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:517
FatalIOErrorInLookup
#define FatalIOErrorInLookup(ios, lookupTag, lookupName, lookupTable)
Report an error message using Foam::FatalIOError.
Definition: error.H:478
Foam::motionSolver::iNew::iNew
iNew(const polyMesh &mesh)
Definition: motionSolver.C:168
Foam::Field< vector >
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
Foam::motionSolver::curPoints
virtual tmp< pointField > curPoints() const =0
Provide current points for motion. Uses current motion field.
Foam::IOstreamOption
The IOstreamOption is a simple container for options an IOstream can normally have.
Definition: IOstreamOption.H:63
Foam::motionSolver::read
virtual bool read()
Read dynamicMeshDict dictionary.
Definition: motionSolver.C:227
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
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
dictionaryEntry.H
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
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
Time.H
Foam::autoPtr< Foam::motionSolver >
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Foam::motionSolver::clone
virtual autoPtr< motionSolver > clone() const
Clone function.
Definition: motionSolver.C:95
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::motionSolver::newPoints
virtual tmp< pointField > newPoints()
Provide new points for motion. Solves for motion.
Definition: motionSolver.C:200
Foam::motionSolver::stealRegistration
static IOobject stealRegistration(const IOdictionary &dict)
De-register object if registered and assign to current.
Definition: motionSolver.C:47
Foam::type
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: MSwindows.C:590
dlLibraryTable.H
Foam::motionSolver::updateMesh
virtual void updateMesh(const mapPolyMesh &)=0
Update local data for topology changes.
Definition: motionSolver.C:213
Foam::IOobject::MUST_READ_IF_MODIFIED
Definition: IOobject.H:186
Foam::motionSolver::writeObject
virtual bool writeObject(IOstreamOption streamOpt, const bool valid) const
Write state using stream options.
Definition: motionSolver.C:218
Foam::dictionary::optionalSubDict
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:577
Foam::mapPolyMesh
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:161
Foam::fvMesh::time
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:280
twoDPointCorrector.H
Foam::twoDPointCorrector::correctPoints
void correctPoints(pointField &p) const
Correct motion points.
Definition: twoDPointCorrector.C:271
Foam::TimePaths::constant
const word & constant() const
Return constant name.
Definition: TimePathsI.H:96
constant
constant condensation/saturation model.
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::objectRegistry::time
const Time & time() const noexcept
Return time registry.
Definition: objectRegistry.H:178