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 | Copyright (C) 2011-2015 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.subDict(type + "Coeffs"))
89 {}
90 
91 
92 // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
93 
95 (
96  const polyMesh& mesh,
97  const IOdictionary& solverDict
98 )
99 {
100  const word solverTypeName(solverDict.lookup("solver"));
101 
102  Info<< "Selecting motion solver: " << solverTypeName << endl;
103 
104  const_cast<Time&>(mesh.time()).libs().open
105  (
106  solverDict,
107  "motionSolverLibs",
108  dictionaryConstructorTablePtr_
109  );
110 
111  if (!dictionaryConstructorTablePtr_)
112  {
114  << "solver table is empty"
115  << exit(FatalError);
116  }
117 
118  dictionaryConstructorTable::iterator cstrIter =
119  dictionaryConstructorTablePtr_->find(solverTypeName);
120 
121  if (cstrIter == dictionaryConstructorTablePtr_->end())
122  {
124  << "Unknown solver type "
125  << solverTypeName << nl << nl
126  << "Valid solver types are:" << endl
127  << dictionaryConstructorTablePtr_->sortedToc()
128  << exit(FatalError);
129  }
130 
131  return autoPtr<motionSolver>(cstrIter()(mesh, solverDict));
132 }
133 
134 
136 {
137  IOdictionary solverDict
138  (
139  IOobject
140  (
141  "dynamicMeshDict",
142  mesh.time().constant(),
143  mesh,
146  )
147  );
148 
149  return New(mesh, solverDict);
150 }
151 
152 
153 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
154 
156 {}
157 
158 
159 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
160 
162 {
163  solve();
164  return curPoints();
165 }
166 
167 
169 {
171 }
172 
173 
175 {}
176 
177 
179 (
183 ) const
184 {
185  return true;
186 }
187 
188 
190 {
191  if (regIOobject::read())
192  {
193  coeffDict_ = subDict(type() + "Coeffs");
194 
195  return true;
196  }
197  else
198  {
199  return false;
200  }
201 }
202 
203 
204 // ************************************************************************* //
const Time & time() const
Return time.
dictionary dict
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:161
virtual bool read()
Read object.
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
virtual void twoDCorrectPoints(pointField &) const
Definition: motionSolver.C:168
const dictionary & subDict(const word &) const
Find and return a sub-dictionary.
Definition: dictionary.C:633
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
static autoPtr< motionSolver > New(const polyMesh &)
Select constructed from polyMesh.
Definition: motionSolver.C:135
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
static const twoDPointCorrector & New(const polyMesh &mesh)
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:53
virtual void updateMesh(const mapPolyMesh &)=0
Update local data for topology changes.
Definition: motionSolver.C:174
virtual bool writeObject(IOstream::streamFormat fmt, IOstream::versionNumber ver, IOstream::compressionType cmp) const
Write state using given format, version and compression.
Definition: motionSolver.C:179
A class for handling words, derived from string.
Definition: word.H:59
virtual ~motionSolver()
Destructor.
Definition: motionSolver.C:155
motionSolver(const polyMesh &mesh)
Construct from polyMesh.
Definition: motionSolver.C:62
const polyMesh & mesh() const
Return reference to mesh.
Definition: motionSolver.H:123
streamFormat
Enumeration for the format of data in the stream.
Definition: IOstream.H:86
virtual void solve()=0
Solve for motion.
const word & constant() const
Return constant name.
Definition: TimePaths.H:124
virtual bool read()
Read dynamicMeshDict dictionary.
Definition: motionSolver.C:189
compressionType
Enumeration for the format of data in the stream.
Definition: IOstream.H:193
static const char nl
Definition: Ostream.H:262
defineRunTimeSelectionTable(reactionRateFlameArea, dictionary)
defineTypeNameAndDebug(combustionModel, 0)
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:45
fileName::Type type(const fileName &)
Return the file type: DIRECTORY or FILE.
Definition: POSIX.C:461
Constant dispersed-phase particle diameter model.
Version number type.
Definition: IOstream.H:96
messageStream Info
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
volScalarField & p
A class for managing temporary objects.
Definition: PtrList.H:54
void correctPoints(pointField &p) const
Correct motion points.
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
Namespace for OpenFOAM.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:451