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-2013 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  (
115  "motionSolver::New(const polyMesh& mesh)"
116  ) << "solver table is empty"
117  << exit(FatalError);
118  }
119 
120  dictionaryConstructorTable::iterator cstrIter =
121  dictionaryConstructorTablePtr_->find(solverTypeName);
122 
123  if (cstrIter == dictionaryConstructorTablePtr_->end())
124  {
126  (
127  "motionSolver::New(const polyMesh&)"
128  ) << "Unknown solver type "
129  << solverTypeName << nl << nl
130  << "Valid solver types are:" << endl
131  << dictionaryConstructorTablePtr_->sortedToc()
132  << exit(FatalError);
133  }
134 
135  return autoPtr<motionSolver>(cstrIter()(mesh, solverDict));
136 }
137 
138 
140 {
141  IOdictionary solverDict
142  (
143  IOobject
144  (
145  "dynamicMeshDict",
146  mesh.time().constant(),
147  mesh,
150  )
151  );
152 
153  return New(mesh, solverDict);
154 }
155 
156 
157 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
158 
160 {}
161 
162 
163 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
164 
166 {
167  solve();
168  return curPoints();
169 }
170 
171 
173 {
175 }
176 
177 
179 {}
180 
181 
183 (
187 ) const
188 {
189  return true;
190 }
191 
192 
194 {
195  if (regIOobject::read())
196  {
197  coeffDict_ = subDict(type() + "Coeffs");
198 
199  return true;
200  }
201  else
202  {
203  return false;
204  }
205 }
206 
207 
208 // ************************************************************************* //
virtual bool writeObject(IOstream::streamFormat fmt, IOstream::versionNumber ver, IOstream::compressionType cmp) const
Write state using given format, version and compression.
Definition: motionSolver.C:183
void correctPoints(pointField &p) const
Correct motion points.
motionSolver(const polyMesh &mesh)
Construct from polyMesh.
Definition: motionSolver.C:62
virtual void updateMesh(const mapPolyMesh &)=0
Update local data for topology changes.
Definition: motionSolver.C:178
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
Definition: mapPolyMesh.H:158
static const twoDPointCorrector & New(const polyMesh &mesh)
A class for handling words, derived from string.
Definition: word.H:59
const polyMesh & mesh() const
Return reference to mesh.
Definition: motionSolver.H:123
virtual void twoDCorrectPoints(pointField &) const
Definition: motionSolver.C:172
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
messageStream Info
const dictionary & subDict(const word &) const
Find and return a sub-dictionary.
Definition: dictionary.C:638
const word & constant() const
Return constant name.
Definition: TimePaths.H:124
Namespace for OpenFOAM.
dictionary dict
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:68
static const char nl
Definition: Ostream.H:260
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
streamFormat
Enumeration for the format of data in the stream.
Definition: IOstream.H:86
volScalarField & p
Definition: createFields.H:51
virtual void solve()=0
Solve for motion.
virtual ~motionSolver()
Destructor.
Definition: motionSolver.C:159
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:53
virtual tmp< pointField > curPoints() const =0
Provide current points for motion. Uses current motion field.
virtual bool read()
Read object.
fileName::Type type(const fileName &)
Return the file type: DIRECTORY or FILE.
Definition: POSIX.C:589
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:314
compressionType
Enumeration for the format of data in the stream.
Definition: IOstream.H:193
static autoPtr< motionSolver > New(const polyMesh &)
Select constructed from polyMesh.
Definition: motionSolver.C:139
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:452
error FatalError
Constant dispersed-phase particle diameter model.
defineRunTimeSelectionTable(reactionRateFlameArea, dictionary)
virtual tmp< pointField > newPoints()
Provide new points for motion. Solves for motion.
Definition: motionSolver.C:165
const Time & time() const
Return time.
IOdictionary(const IOobject &)
Construct given an IOobject.
Definition: IOdictionary.C:45
Version number type.
Definition: IOstream.H:96
A class for managing temporary objects.
Definition: PtrList.H:118
virtual bool read()
Read dynamicMeshDict dictionary.
Definition: motionSolver.C:193
defineTypeNameAndDebug(combustionModel, 0)