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 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  );
45 }
46 
47 
48 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
49 
50 Foam::dynamicMultiMotionSolverFvMesh::dynamicMultiMotionSolverFvMesh
51 (
52  const IOobject& io
53 )
54 :
55  dynamicFvMesh(io)
56 {
57  IOdictionary dynDict
58  (
59  IOobject
60  (
61  "dynamicMeshDict",
62  io.time().constant(),
63  *this,
64  IOobject::MUST_READ_IF_MODIFIED,
65  IOobject::NO_WRITE,
66  false
67  )
68  );
69  const dictionary& dynamicMeshCoeffs = dynDict.subDict(typeName + "Coeffs");
70 
71  zoneIDs_.setSize(dynamicMeshCoeffs.size());
72  motionPtr_.setSize(dynamicMeshCoeffs.size());
73  pointIDs_.setSize(dynamicMeshCoeffs.size());
74 
75  label zonei = 0;
76 
77  bitSet movePts;
78 
79  for (const entry& dEntry : dynamicMeshCoeffs)
80  {
81  if (dEntry.isDict())
82  {
83  const dictionary& subDict = dEntry.dict();
84 
85  const word zoneName(subDict.get<word>("cellZone"));
86 
87  zoneIDs_[zonei] = cellZones().findZoneID(zoneName);
88 
89  if (zoneIDs_[zonei] == -1)
90  {
91  FatalIOErrorInFunction(dynamicMeshCoeffs)
92  << "Cannot find cellZone named " << zoneName
93  << ". Valid zones are " << cellZones().names()
94  << exit(FatalIOError);
95  }
96 
97  IOobject io(dynDict);
98  io.readOpt() = IOobject::NO_READ;
99 
100  motionPtr_.set
101  (
102  zonei,
104  (
105  *this,
106  IOdictionary(io, subDict)
107  )
108  );
109 
110 
111  // Collect points of cell zone.
112 
113  movePts.reset();
114  movePts.resize(nPoints());
115 
116  for (const label celli : cellZones()[zoneIDs_[zonei]])
117  {
118  for (const label facei : cells()[celli])
119  {
120  movePts.set(faces()[facei]); // set multiple points
121  }
122  }
123 
124  syncTools::syncPointList
125  (
126  *this, movePts, orEqOp<unsigned int>(), 0u
127  );
128 
129  pointIDs_[zonei] = movePts.sortedToc();
130 
131  Info<< "Applying motionSolver " << motionPtr_[zonei].type()
132  << " to "
133  << returnReduce(pointIDs_[zonei].size(), sumOp<label>())
134  << " points of cellZone " << zoneName << endl;
135 
136  ++zonei;
137  }
138  }
139  zoneIDs_.setSize(zonei);
140  motionPtr_.setSize(zonei);
141  pointIDs_.setSize(zonei);
142 }
143 
144 
145 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
146 
148 {
149  pointField transformedPts(points());
150 
151  forAll(motionPtr_, zonei)
152  {
153  tmp<pointField> tnewPoints(motionPtr_[zonei].newPoints());
154  const pointField& newPoints = tnewPoints();
155 
156  for (const label pointi : pointIDs_[zonei])
157  {
158  transformedPts[pointi] = newPoints[pointi];
159  }
160  }
161 
162  fvMesh::movePoints(transformedPts);
163 
164  static bool hasWarned = false;
165 
166  volVectorField* Uptr = getObjectPtr<volVectorField>("U");
167 
168  if (Uptr)
169  {
171  }
172  else if (!hasWarned)
173  {
174  hasWarned = true;
175 
177  << "Did not find volVectorField U."
178  << " Not updating U boundary conditions." << endl;
179  }
180 
181  return true;
182 }
183 
184 
185 // ************************************************************************* //
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
Foam::entry
A keyword and a list of tokens is an 'entry'.
Definition: entry.H:67
volFields.H
Foam::IOdictionary
IOdictionary is derived from dictionary and IOobject to give the dictionary automatic IO functionalit...
Definition: IOdictionary.H:54
Foam::PackedList::reset
void reset()
Clear all bits but do not adjust the addressable size.
Definition: PackedListI.H:495
Foam::polyMesh::points
virtual const pointField & points() const
Return raw points.
Definition: polyMesh.C:1038
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:104
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
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:64
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:59
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:563
Foam::orEqOp
Definition: ops.H:86
Foam::FatalIOError
IOerror FatalIOError
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:337
Foam::dictionary::get
T get(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Definition: dictionaryTemplates.C:81
bitSet.H
Foam::IOobject::time
const Time & time() const
Return time.
Definition: IOobject.C:438
Foam::PackedList::resize
void resize(const label nElem, const unsigned int val=0u)
Reset addressable list size, does not shrink the allocated size.
Definition: PackedListI.H:388
syncTools.H
Foam::sumOp
Definition: ops.H:213
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:290
nPoints
label nPoints
Definition: gmvOutputHeader.H:2
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:62
Foam::Field< vector >
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
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:523
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::surfaceInterpolation::movePoints
bool movePoints()
Do what is necessary if the mesh has moved.
Definition: surfaceInterpolation.C:125
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
dynamicMultiMotionSolverFvMesh.H
Foam::GeometricField::correctBoundaryConditions
void correctBoundaryConditions()
Correct boundary field.
Definition: GeometricField.C:909
Foam::New
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
Definition: DimensionedFieldReuseFunctions.H:105
Foam::IOobject::readOpt
readOption readOpt() const
The read option.
Definition: IOobjectI.H:141
FatalIOErrorInFunction
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:375
cells
const cellShapeList & cells
Definition: gmvOutputHeader.H:3
Foam::TimePaths::constant
const word & constant() const
Return constant name.
Definition: TimePathsI.H:88
Foam::GeometricField< vector, fvPatchField, volMesh >
Foam::dynamicMultiMotionSolverFvMesh::update
virtual bool update()
Update the mesh for both mesh motion and topology change.
Definition: dynamicMultiMotionSolverFvMesh.C:147
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:294
Foam::bitSet::sortedToc
labelList sortedToc() const
The indices of the on bits as a sorted labelList.
Definition: bitSetI.H:518