motionSolver.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "motionSolver.H"
27 #include "Time.H"
28 #include "polyMesh.H"
29 #include "dlLibraryTable.H"
30 #include "twoDPointCorrector.H"
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
36  defineTypeNameAndDebug(motionSolver, 0);
37  defineRunTimeSelectionTable(motionSolver, dictionary);
38 }
39 
40 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
41 
42 Foam::IOobject Foam::motionSolver::stealRegistration
43 (
44  const IOdictionary& dict
45 )
46 {
47  IOobject io(dict);
48  if (dict.registerObject())
49  {
50  // De-register if necessary
51  const_cast<IOdictionary&>(dict).checkOut();
52 
53  io.registerObject() = true;
54  }
55 
56  return io;
57 }
58 
59 
60 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
61 
63 :
65  (
66  IOobject
67  (
68  "dynamicMeshDict",
69  mesh.time().constant(),
70  mesh,
71  IOobject::MUST_READ_IF_MODIFIED,
72  IOobject::AUTO_WRITE
73  )
74  ),
75  mesh_(mesh)
76 {}
77 
78 
80 (
81  const polyMesh& mesh,
82  const IOdictionary& dict,
83  const word& type
84 )
85 :
86  IOdictionary(stealRegistration(dict), dict),
87  mesh_(mesh),
88  coeffDict_(dict.optionalSubDict(type + "Coeffs"))
89 {}
90 
91 
93 {
95  return autoPtr<motionSolver>(nullptr);
96 }
97 
98 
99 // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
100 
102 (
103  const polyMesh& mesh,
104  const IOdictionary& solverDict
105 )
106 {
107  const word solverTypeName
108  (
109  solverDict.found("motionSolver")
110  ? solverDict.lookup("motionSolver")
111  : solverDict.lookup("solver")
112  );
113 
114  Info<< "Selecting motion solver: " << solverTypeName << endl;
115 
116  const_cast<Time&>(mesh.time()).libs().open
117  (
118  solverDict,
119  "motionSolverLibs",
120  dictionaryConstructorTablePtr_
121  );
122 
123  if (!dictionaryConstructorTablePtr_)
124  {
126  << "solver table is empty"
127  << exit(FatalError);
128  }
129 
130  dictionaryConstructorTable::iterator cstrIter =
131  dictionaryConstructorTablePtr_->find(solverTypeName);
132 
133  if (cstrIter == dictionaryConstructorTablePtr_->end())
134  {
136  << "Unknown solver type "
137  << solverTypeName << nl << nl
138  << "Valid solver types are:" << endl
139  << dictionaryConstructorTablePtr_->sortedToc()
140  << exit(FatalError);
141  }
142 
143  return autoPtr<motionSolver>(cstrIter()(mesh, solverDict));
144 }
145 
146 
148 {
149  IOdictionary solverDict
150  (
151  IOobject
152  (
153  "dynamicMeshDict",
154  mesh.time().constant(),
155  mesh,
158  )
159  );
160 
161  return New(mesh, solverDict);
162 }
163 
164 
166 :
167  mesh_(mesh)
168 {}
169 
170 
171 Foam::autoPtr<Foam::motionSolver> Foam::motionSolver::iNew::operator()
172 (
173  Istream& is
174 ) const
175 {
177 
178  return motionSolver::New
179  (
180  mesh_,
182  (
183  IOobject
184  (
185  dict.name() + ":meshSolver",
186  mesh_.time().constant(),
187  mesh_
188  ),
189  dict
190  )
191  );
192 }
193 
194 
195 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
196 
198 {}
199 
200 
201 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
202 
204 {
205  solve();
206  return curPoints();
207 }
208 
209 
211 {
213 }
214 
215 
217 {}
218 
219 
221 (
225  const bool valid
226 ) const
227 {
228  return true;
229 }
230 
231 
233 {
234  if (regIOobject::read())
235  {
236  coeffDict_ = optionalSubDict(type() + "Coeffs");
237 
238  return true;
239  }
240  else
241  {
242  return false;
243  }
244 }
245 
246 
247 // ************************************************************************* //
dictionary dict
bool found(const word &, bool recursive=false, bool patternMatch=true) const
Search dictionary for given keyword.
Definition: dictionary.C:431
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
virtual tmp< pointField > newPoints()
Provide new points for motion. Solves for motion.
Definition: motionSolver.C:203
virtual bool read()
Read object.
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
static const dictionary null
Null dictionary.
Definition: dictionary.H:202
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:256
const fileName & name() const
Return the dictionary name (scoped, e.g. dictA::dictB::dictC)
static autoPtr< motionSolver > New(const polyMesh &)
Select constructed from polyMesh.
Definition: motionSolver.C:147
A keyword and a list of tokens is a &#39;dictionaryEntry&#39;.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:158
virtual bool writeObject(IOstream::streamFormat fmt, IOstream::versionNumber ver, IOstream::compressionType cmp, const bool valid) const
Write state using given format, version and compression.
Definition: motionSolver.C:221
static const twoDPointCorrector & New(const polyMesh &mesh)
Definition: MeshObject.C:44
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:52
void correctPoints(pointField &p) const
Correct motion points.
virtual void updateMesh(const mapPolyMesh &)=0
Update local data for topology changes.
Definition: motionSolver.C:216
iNew(const polyMesh &mesh)
Definition: motionSolver.C:165
const dictionary & optionalSubDict(const word &) const
Find and return a sub-dictionary if found.
Definition: dictionary.C:759
A class for handling words, derived from string.
Definition: word.H:59
virtual ~motionSolver()
Destructor.
Definition: motionSolver.C:197
const word & constant() const
Return constant name.
Definition: TimePaths.H:124
motionSolver(const polyMesh &mesh)
Construct from polyMesh.
Definition: motionSolver.C:62
streamFormat
Enumeration for the format of data in the stream.
Definition: IOstream.H:86
virtual void solve()=0
Solve for motion.
virtual bool read()
Read dynamicMeshDict dictionary.
Definition: motionSolver.C:232
compressionType
Enumeration for the format of data in the stream.
Definition: IOstream.H:193
static const char nl
Definition: Ostream.H:265
defineRunTimeSelectionTable(reactionRateFlameArea, dictionary)
const Time & time() const
Return time.
defineTypeNameAndDebug(combustionModel, 0)
fileName::Type type(const fileName &, const bool followLink=true)
Return the file type: DIRECTORY or FILE.
Definition: POSIX.C:481
virtual tmp< pointField > curPoints() const =0
Provide current points for motion. Uses current motion field.
IOdictionary(const IOobject &)
Construct given an IOobject.
Definition: IOdictionary.C:30
Version number type.
Definition: IOstream.H:96
messageStream Info
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
const polyMesh & mesh() const
Return reference to mesh.
Definition: motionSolver.H:141
volScalarField & p
A class for managing temporary objects.
Definition: PtrList.H:53
#define NotImplemented
Issue a FatalErrorIn for a function not currently implemented.
Definition: error.H:366
virtual autoPtr< motionSolver > clone() const
Clone function.
Definition: motionSolver.C:92
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:92
virtual void twoDCorrectPoints(pointField &) const
Definition: motionSolver.C:210
Namespace for OpenFOAM.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:576