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-2021 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 
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,
87  false
88  )
89  );
90  const dictionary& dynamicMeshCoeffs = dynDict.subDict(typeName + "Coeffs");
91 
92  zoneIDs_.setSize(dynamicMeshCoeffs.size());
93  motionPtr_.setSize(dynamicMeshCoeffs.size());
94  pointIDs_.setSize(dynamicMeshCoeffs.size());
95 
96  label zonei = 0;
97 
98  bitSet movePts;
99 
100  for (const entry& dEntry : dynamicMeshCoeffs)
101  {
102  if (dEntry.isDict())
103  {
104  const dictionary& subDict = dEntry.dict();
105 
106  const word zoneName(subDict.get<word>("cellZone"));
107 
108  zoneIDs_[zonei] = cellZones().findZoneID(zoneName);
109 
110  if (zoneIDs_[zonei] == -1)
111  {
112  FatalIOErrorInFunction(dynamicMeshCoeffs)
113  << "Cannot find cellZone named " << zoneName
114  << ". Valid zones are " << cellZones().names()
115  << exit(FatalIOError);
116  }
117 
118  IOobject io(dynDict);
120 
121  motionPtr_.set
122  (
123  zonei,
125  (
126  *this,
127  IOdictionary(io, subDict)
128  )
129  );
130 
131 
132  // Collect points of cell zone.
133 
134  movePts.reset();
135  movePts.resize(nPoints());
136 
137  for (const label celli : cellZones()[zoneIDs_[zonei]])
138  {
139  for (const label facei : cells()[celli])
140  {
141  movePts.set(faces()[facei]); // set multiple points
142  }
143  }
144 
146  (
147  *this, movePts, orEqOp<unsigned int>(), 0u
148  );
149 
150  pointIDs_[zonei] = movePts.sortedToc();
151 
152  Info<< "Applying motionSolver " << motionPtr_[zonei].type()
153  << " to "
154  << returnReduce(pointIDs_[zonei].size(), sumOp<label>())
155  << " points of cellZone " << zoneName << endl;
156 
157  ++zonei;
158  }
159  }
160  zoneIDs_.setSize(zonei);
161  motionPtr_.setSize(zonei);
162  pointIDs_.setSize(zonei);
163 
164  // Assume changed ...
165  return true;
166 }
167 
168 
169 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
170 
172 {
173  pointField transformedPts(points());
174 
175  forAll(motionPtr_, zonei)
176  {
177  tmp<pointField> tnewPoints(motionPtr_[zonei].newPoints());
178  const pointField& newPoints = tnewPoints();
179 
180  for (const label pointi : pointIDs_[zonei])
181  {
182  transformedPts[pointi] = newPoints[pointi];
183  }
184  }
185 
186  fvMesh::movePoints(transformedPts);
187 
188  static bool hasWarned = false;
189 
190  volVectorField* Uptr = getObjectPtr<volVectorField>("U");
191 
192  if (Uptr)
193  {
195  }
196  else if (!hasWarned)
197  {
198  hasWarned = true;
199 
201  << "Did not find volVectorField U."
202  << " Not updating U boundary conditions." << endl;
203  }
204 
205  return true;
206 }
207 
208 
209 // ************************************************************************* //
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
Foam::entry
A keyword and a list of tokens is an 'entry'.
Definition: entry.H:67
Foam::IOobject::NO_WRITE
Definition: IOobject.H:195
Foam::motionSolver::New
static autoPtr< motionSolver > New(const polyMesh &)
Select constructed from polyMesh.
Definition: motionSolver.C:150
volFields.H
Foam::IOdictionary
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:54
Foam::HashTable< regIOobject * >::size
label size() const noexcept
The number of elements in table.
Definition: HashTableI.H:52
Foam::PackedList::reset
void reset()
Clear all bits but do not adjust the addressable size.
Definition: PackedListI.H:505
Foam::PackedList::resize
void resize(const label numElem, const unsigned int val=0u)
Reset addressable list size, does not shrink the allocated size.
Definition: PackedListI.H:409
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:169
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::returnReduce
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
Definition: PstreamReduceOps.H:94
Foam::bitSet
A bitSet stores bits (elements with only two states) in packed internal format and supports a variety...
Definition: bitSet.H:63
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::primitiveMesh::cells
const cellList & cells() const
Definition: primitiveMeshCells.C:138
Foam::dynamicFvMesh::init
virtual bool init(const bool doInit)
Initialise all non-demand-driven data.
Definition: dynamicFvMesh.C:90
Foam::dynamicFvMesh
Abstract base class for geometry and/or topology changing fvMesh.
Definition: dynamicFvMesh.H:78
Foam::bitSet::set
void set(const bitSet &bitset)
Set specified bits from another bitset.
Definition: bitSetI.H:574
Foam::orEqOp
Definition: ops.H:86
Foam::FatalIOError
IOerror FatalIOError
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::dictionary::get
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionaryTemplates.C:107
bitSet.H
syncTools.H
Foam::syncTools::syncPointList
static void syncPointList(const polyMesh &mesh, List< T > &pointValues, const CombineOp &cop, const T &nullValue, const TransformOp &top)
Synchronize values on all mesh points.
Definition: syncToolsTemplates.C:721
Foam::sumOp
Definition: ops.H:213
Foam::primitiveMesh::nPoints
label nPoints() const noexcept
Number of mesh points.
Definition: primitiveMeshI.H:37
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::Field< vector >
Foam::Info
messageStream Info
Information stream (stdout output on master, null elsewhere)
Foam::polyMesh::cellZones
const cellZoneMesh & cellZones() const noexcept
Return cell zone mesh.
Definition: polyMesh.H:492
Foam::List::setSize
void setSize(const label n)
Alias for resize()
Definition: List.H:222
init
mesh init(true)
Foam::dictionary::subDict
const dictionary & subDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary.
Definition: dictionary.C:460
Foam::IOdictionary::IOdictionary
IOdictionary(const IOobject &io, const dictionary *fallback=nullptr)
Definition: IOdictionary.C:37
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::surfaceInterpolation::movePoints
virtual bool movePoints()
Do what is necessary if the mesh has moved.
Definition: surfaceInterpolation.C:151
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::ZoneMesh::findZoneID
label findZoneID(const word &zoneName) const
Find zone index by name, return -1 if not found.
Definition: ZoneMesh.C:519
Foam::ZoneMesh::names
wordList names() const
A list of the zone names.
Definition: ZoneMesh.C:305
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::IOobject::readOpt
readOption readOpt() const noexcept
The read option.
Definition: IOobjectI.H:164
dynamicMultiMotionSolverFvMesh.H
Foam::GeometricField::correctBoundaryConditions
void correctBoundaryConditions()
Correct boundary field.
Definition: GeometricField.C:940
Foam::polyMesh::faces
virtual const faceList & faces() const
Return raw faces.
Definition: polyMesh.C:1094
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::IOobject::MUST_READ_IF_MODIFIED
Definition: IOobject.H:186
Foam::dynamicMultiMotionSolverFvMesh::init
virtual bool init(const bool doInit)
Initialise all non-demand-driven data.
Definition: dynamicMultiMotionSolverFvMesh.C:71
Foam::fvMesh::time
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:280
FatalIOErrorInFunction
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:473
Foam::GeometricField< vector, fvPatchField, volMesh >
Foam::dynamicMultiMotionSolverFvMesh::update
virtual bool update()
Update the mesh for both mesh motion and topology change.
Definition: dynamicMultiMotionSolverFvMesh.C:171
Foam::IOobject::NO_READ
Definition: IOobject.H:188
constant
constant condensation/saturation model.
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:328
Foam::bitSet::sortedToc
labelList sortedToc() const
The indices of the on bits as a sorted labelList.
Definition: bitSetI.H:532