Loading...
Searching...
No Matches
dynamicMotionSolverListFvMesh.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) 2016 OpenFOAM Foundation
9 Copyright (C) 2019-2022 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
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
31#include "motionSolver.H"
32#include "pointMesh.H"
33#include "volFields.H"
34
35// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
36
37namespace Foam
38{
41 (
45 );
47 (
50 doInit
51 );
52}
53
54
55// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
56
57Foam::dynamicMotionSolverListFvMesh::dynamicMotionSolverListFvMesh
58(
59 const IOobject& io,
60 const bool doInit
61)
62:
63 dynamicFvMesh(io, doInit),
64 motionSolvers_()
65{
66 if (doInit)
67 {
68 init(false); // do not initialise lower levels
69 }
70}
71
72
74(
75 const bool doInit,
76 const bool mandatory
77)
78{
79 if (doInit)
80 {
81 dynamicFvMesh::init(doInit);
82 }
83
84 IOobject ioDict
85 (
86 "dynamicMeshDict",
87 time().constant(),
88 *this,
92 );
93
94 IOdictionary dict(ioDict);
95
96 label i = 0;
97
98 const auto* dictptr = dict.findDict("solvers");
99 if (dictptr)
100 {
101 const dictionary& solverDict = *dictptr;
102
103 motionSolvers_.setSize(solverDict.size());
104
105 for (const entry& dEntry : solverDict)
106 {
107 if (dEntry.isDict())
108 {
109 IOobject io(ioDict);
110 io.readOpt(IOobject::NO_READ);
111 io.writeOpt(IOobject::AUTO_WRITE);
112 io.rename(dEntry.dict().dictName());
113
114 IOdictionary IOsolverDict
115 (
116 io,
117 dEntry.dict()
118 );
119
120 motionSolvers_.set
121 (
122 i++,
123 motionSolver::New(*this, IOsolverDict)
124 );
125 }
126 }
127 motionSolvers_.setSize(i);
128 }
129 else if (mandatory)
130 {
131 motionSolvers_.setSize(1);
132 motionSolvers_.set(i++, motionSolver::New(*this, dict));
134
135 // Assume something changed
136 return true;
137}
138
139
140bool Foam::dynamicMotionSolverListFvMesh::init(const bool doInit)
141{
142 // Fall-back to always constructing motionSolver
143 return init(doInit, true);
144}
145
146
147// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
148
150{}
151
152
153// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
154
155
157(
158 const mapPolyMesh& mpm
159)
160{
162
163 // Update the motionSolvers for any topo change ...
164 for (auto& ms : motionSolvers_)
165 {
166 ms.updateMesh(mpm);
167 }
168}
169
170
172{
173 if (motionSolvers_.size())
174 {
175 // Accumulated displacement
176 pointField disp(motionSolvers_[0].newPoints() - fvMesh::points());
177
178 for (label i = 1; i < motionSolvers_.size(); i++)
179 {
180 disp += motionSolvers_[i].newPoints() - fvMesh::points();
181 }
182
183 fvMesh::movePoints(points() + disp);
184
185 volVectorField* Uptr = getObjectPtr<volVectorField>("U");
186
187 if (Uptr)
188 {
189 Uptr->correctBoundaryConditions();
190 }
191 }
192
193 return true;
194}
195
196
197// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
void correctBoundaryConditions()
Correct boundary field.
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
@ NO_REGISTER
Do not request registration (bool: false).
@ NO_READ
Nothing to be read.
@ MUST_READ
Reading required.
@ NO_WRITE
Ignore writing from objectRegistry::writeObject().
@ AUTO_WRITE
Automatically write from objectRegistry::writeObject().
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition IOobject.H:191
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
const dictionary * findDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary pointer if present (and it is a dictionary) otherwise return nullptr...
Abstract base class for geometry and/or topology changing fvMesh.
virtual bool init(const bool doInit)
Initialise all non-demand-driven data.
Dynamic mesh able to handle multiple motion solvers. NOTE: If the word entry "solvers" is not found i...
virtual bool init(const bool doInit)
Initialise all non-demand-driven data.
virtual bool update()
Update the mesh for both mesh motion and topology change.
virtual void mapFields(const mapPolyMesh &mpm)
Map all fields in time using given map. Triggered by topo change.
A keyword and a list of tokens is an 'entry'.
Definition entry.H:66
virtual bool movePoints()
Avoid masking surfaceInterpolation method.
const Time & time() const
Return the top-level database.
Definition fvMesh.H:360
virtual void mapFields(const mapPolyMesh &mpm)
Map all fields in time using given map.
Definition fvMesh.C:730
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
static autoPtr< motionSolver > New(const polyMesh &)
Select constructed from polyMesh.
Type * getObjectPtr(const word &name, const bool recursive=false) const
Return non-const pointer to the object of the given Type, using a const-cast to have it behave like a...
virtual const pointField & points() const
Return raw points.
Definition polyMesh.C:1063
const dictionary & solverDict(const word &name) const
The solver controls dictionary for the given field. Same as solversDict().subDict(....
Definition solution.C:467
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition className.H:142
const auto & io
const pointField & points
Different types of constants.
Namespace for OpenFOAM.
GeometricField< vector, fvPatchField, volMesh > volVectorField
vectorField pointField
pointField is a vectorField.
dictionary dict