Loading...
Searching...
No Matches
dynamicMultiMotionSolverFvMesh.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-2022 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26\*---------------------------------------------------------------------------*/
27
30#include "volFields.H"
31#include "bitSet.H"
32#include "syncTools.H"
33
34// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35
36namespace Foam
37{
40 (
44 );
46 (
49 doInit
50 );
51}
52
53
54// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
55
56Foam::dynamicMultiMotionSolverFvMesh::dynamicMultiMotionSolverFvMesh
57(
58 const IOobject& io,
59 const bool doInit
60)
61:
62 dynamicFvMesh(io, doInit)
63{
64 if (doInit)
65 {
66 init(false); // do not initialise lower levels
67 }
68}
69
70
72{
73 if (doInit)
74 {
75 dynamicFvMesh::init(doInit);
76 }
77
78 IOdictionary dynDict
79 (
81 (
82 "dynamicMeshDict",
83 time().constant(),
84 *this,
88 )
89 );
90 const dictionary& dynamicMeshCoeffs = dynDict.subDict(typeName + "Coeffs");
91
92 motionPtr_.resize(dynamicMeshCoeffs.size());
93 pointIDs_.resize(dynamicMeshCoeffs.size());
94
95 label zonei = 0;
96
97 bitSet movePts;
98
99 for (const entry& dEntry : dynamicMeshCoeffs)
100 {
101 if (dEntry.isDict())
102 {
103 const dictionary& subDict = dEntry.dict();
104
105 wordRe cellZoneName;
106 subDict.readEntry("cellZone", cellZoneName);
107
108 // Also handles groups, multiple zones (as wordRe match) ...
109 labelList zoneIDs = cellZones().indices(cellZoneName);
110
111 if (zoneIDs.empty())
112 {
113 FatalIOErrorInFunction(dynamicMeshCoeffs)
114 << "No matching cellZones: " << cellZoneName << nl
115 << " Valid zones : "
116 << flatOutput(cellZones().names()) << nl
117 << " Valid groups: "
118 << flatOutput(cellZones().groupNames())
119 << nl
120 << exit(FatalIOError);
121 }
122
124
125 motionPtr_.set
126 (
127 zonei,
129 (
130 *this,
131 IOdictionary(io, subDict)
132 )
133 );
134
135
136 // Markup points associated with cell zone(s)
137
138 movePts.reset();
139 movePts.resize(nPoints());
140
141 for (const label zoneID : zoneIDs)
142 {
143 for (const label celli : cellZones()[zoneID])
144 {
145 for (const label facei : cells()[celli])
146 {
147 movePts.set(faces()[facei]);
148 }
149 }
150 }
151
153 (
154 *this, movePts, orEqOp<unsigned int>(), 0u
155 );
156
157 pointIDs_[zonei] = movePts.sortedToc();
158
159 Info<< "Applying motionSolver " << motionPtr_[zonei].type()
160 << " to "
161 << returnReduce(pointIDs_[zonei].size(), sumOp<label>())
162 << " points of cellZone " << cellZoneName << endl;
163
164 ++zonei;
165 }
166 }
167
168 motionPtr_.resize(zonei);
169 pointIDs_.resize(zonei);
170
171 // Assume changed ...
172 return true;
173}
174
175
176// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
177
179{
180 pointField transformedPts(points());
181
182 forAll(motionPtr_, zonei)
183 {
184 const labelList& zonePoints = pointIDs_[zonei];
185
186 const pointField newPoints(motionPtr_[zonei].newPoints());
187
188 for (const label pointi : zonePoints)
189 {
190 transformedPts[pointi] = newPoints[pointi];
191 }
192 }
193
194 fvMesh::movePoints(transformedPts);
195
196 static bool hasWarned = false;
197
198 volVectorField* Uptr = getObjectPtr<volVectorField>("U");
199
200 if (Uptr)
201 {
202 Uptr->correctBoundaryConditions();
203 }
204 else if (!hasWarned)
205 {
206 hasWarned = true;
207
209 << "Did not find volVectorField U."
210 << " Not updating U boundary conditions." << endl;
211 }
212
213 return true;
214}
215
216
217// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
label size() const noexcept
The number of elements in list.
Definition DLListBase.H:194
void correctBoundaryConditions()
Correct boundary field.
label size() const noexcept
Definition HashTable.H:358
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.
@ NO_WRITE
Ignore writing from objectRegistry::writeObject().
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition IOobject.H:191
void resize(const label numElem, const unsigned int val=0u)
Reset addressable list size, does not shrink the allocated size.
void reset()
Clear all bits but do not adjust the addressable size.
bool empty() const noexcept
True if List is empty (ie, size() is zero).
Definition UList.H:701
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition bitSet.H:61
labelList sortedToc() const
The indices of the on bits as a sorted labelList.
Definition bitSetI.H:441
void set(const bitSet &bitset)
Set specified bits from another bitset.
Definition bitSetI.H:502
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
const dictionary & subDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary.
Definition dictionary.C:441
Abstract base class for geometry and/or topology changing fvMesh.
virtual bool init(const bool doInit)
Initialise all non-demand-driven data.
Mesh motion described per cellZone. Individual motion solvers solve over whole domain but are only ap...
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.
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
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 faceList & faces() const
Return raw faces.
Definition polyMesh.C:1088
const cellZoneMesh & cellZones() const noexcept
Return cell zone mesh.
Definition polyMesh.H:679
static void syncPointList(const polyMesh &mesh, List< T > &pointValues, const CombineOp &cop, const T &nullValue, const TransformOp &top)
Synchronize values on all mesh points.
A wordRe is a Foam::word, but can contain a regular expression for matching words or strings.
Definition wordRe.H:81
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition className.H:142
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition error.H:629
const auto & io
auto & names
const pointField & points
label nPoints
const cellShapeList & cells
const labelIOList & zoneIDs
Definition correctPhi.H:59
#define WarningInFunction
Report a warning using Foam::Warning.
Different types of constants.
Namespace for OpenFOAM.
GeometricField< vector, fvPatchField, volMesh > volVectorField
List< label > labelList
A List of labels.
Definition List.H:62
messageStream Info
Information stream (stdout output on master, null elsewhere).
T returnReduce(const T &value, BinaryOp bop, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm)
Perform reduction on a copy, using specified binary operation.
const word GlobalIOList< Tuple2< scalar, vector > >::typeName("scalarVectorTable")
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
Definition FlatOutput.H:217
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...
vectorField pointField
pointField is a vectorField.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition errorManip.H:125
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299