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 -------------------------------------------------------------------------------
10 License
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 
36 namespace Foam
37 {
38  defineTypeNameAndDebug(dynamicMultiMotionSolverFvMesh, 0);
40  (
41  dynamicFvMesh,
42  dynamicMultiMotionSolverFvMesh,
43  IOobject
44  );
46  (
47  dynamicFvMesh,
48  dynamicMultiMotionSolverFvMesh,
49  doInit
50  );
51 }
52 
53 
54 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
55 
56 Foam::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 
71 bool Foam::dynamicMultiMotionSolverFvMesh::init(const bool doInit)
72 {
73  if (doInit)
74  {
75  dynamicFvMesh::init(doInit);
76  }
77 
78  IOdictionary dynDict
79  (
80  IOobject
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 
123  IOobject io(dynDict, IOobject::NO_READ, IOobject::NO_WRITE);
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  {
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 // ************************************************************************* //
const labelIOList & zoneIDs
Definition: correctPhi.H:59
List< word > names(const UPtrList< T > &list, const UnaryMatchPredicate &matcher)
List of names generated by calling name() for each list item and filtered for matches.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
bool empty() const noexcept
True if List is empty (ie, size() is zero)
Definition: UList.H:666
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
virtual bool movePoints()
Do what is necessary if the mesh has moved.
virtual bool init(const bool doInit)
Initialise all non-demand-driven data.
Definition: dynamicFvMesh.C:84
static autoPtr< motionSolver > New(const polyMesh &)
Select constructed from polyMesh.
Definition: motionSolver.C:143
Ignore writing from objectRegistry::writeObject()
GeometricField< vector, fvPatchField, volMesh > volVectorField
Definition: volFieldsFwd.H:82
T returnReduce(const T &value, const BinaryOp &bop, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Perform reduction on a copy, using specified binary operation.
Macros for easy insertion into run-time selection tables.
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
const cellShapeList & cells
const pointField & points
label nPoints
static void syncPointList(const polyMesh &mesh, List< T > &pointValues, const CombineOp &cop, const T &nullValue, const TransformOp &top)
Synchronize values on all mesh points.
defineTypeNameAndDebug(combustionModel, 0)
#define WarningInFunction
Report a warning using Foam::Warning.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:627
Abstract base class for geometry and/or topology changing fvMesh.
Definition: dynamicFvMesh.H:74
Nothing to be read.
void correctBoundaryConditions()
Correct boundary field.
messageStream Info
Information stream (stdout output on master, null elsewhere)
virtual bool update()
Update the mesh for both mesh motion and topology change.
List< label > labelList
A List of labels.
Definition: List.H:62
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)
virtual bool init(const bool doInit)
Initialise all non-demand-driven data.
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:172
Do not request registration (bool: false)
Namespace for OpenFOAM.
addToRunTimeSelectionTable(functionObject, pointHistory, dictionary)
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
Definition: FlatOutput.H:225
IOerror FatalIOError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL IO ERROR&#39; header text and ...