dynamicMotionSolverFvMeshAMI.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) 2019-2020 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 "motionSolver.H"
31 #include "volFields.H"
32 #include "surfaceFields.H"
33 #include "cyclicAMIPolyPatch.H"
34 #include "polyTopoChange.H"
35 #include "MeshObject.H"
36 #include "lduMesh.H"
37 #include "surfaceInterpolate.H"
38 
39 #include "processorFvPatch.H"
40 
41 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
42 
43 namespace Foam
44 {
45  defineTypeNameAndDebug(dynamicMotionSolverFvMeshAMI, 0);
47  (
48  dynamicFvMesh,
49  dynamicMotionSolverFvMeshAMI,
50  IOobject
51  );
53  (
54  dynamicFvMesh,
55  dynamicMotionSolverFvMeshAMI,
56  doInit
57  );
58 }
59 
60 
61 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
62 
63 Foam::dynamicMotionSolverFvMeshAMI::dynamicMotionSolverFvMeshAMI
64 (
65  const IOobject& io,
66  const bool doInit
67 )
68 :
69  dynamicFvMesh(io, doInit)
70 {
71  if (doInit)
72  {
73  init(false); // do not initialise lower levels
74  }
75 }
76 
77 
79 {
80  if (doInit)
81  {
82  dynamicFvMesh::init(doInit);
83  }
84 
85  motionPtr_ = motionSolver::New(*this);
86  return true;
87 }
88 
89 
90 Foam::dynamicMotionSolverFvMeshAMI::dynamicMotionSolverFvMeshAMI
91 (
92  const IOobject& io,
94  faceList&& faces,
95  labelList&& allOwner,
96  labelList&& allNeighbour,
97  const bool syncPar
98 )
99 :
101  (
102  io,
103  std::move(points),
104  std::move(faces),
105  std::move(allOwner),
106  std::move(allNeighbour),
107  syncPar
108  ),
109  motionPtr_(motionSolver::New(*this))
110 {}
111 
112 
113 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
114 
116 {
117  return *motionPtr_;
118 }
119 
120 
122 {
123  // Mesh not moved/changed yet
124  moving(false);
125  topoChanging(false);
126 
127  if (debug)
128  {
129  for (const fvPatch& fvp : boundary())
130  {
131  if (!isA<processorFvPatch>(fvp))
132  {
133  Info<< "1 --- patch:" << fvp.patch().name()
134  << " area:" << gSum(fvp.magSf()) << endl;
135  }
136  }
137  }
138 
139  pointField newPoints(motionPtr_->curPoints());
140 
141  polyBoundaryMesh& pbm = const_cast<polyBoundaryMesh&>(boundaryMesh());
142 
143  // Scan all patches and see if we want to apply a mesh topology update
144  bool changeRequired = false;
145  for (polyPatch& pp : pbm)
146  {
147  DebugInfo
148  << "pre-topology change: patch " << pp.name()
149  << " size:" << returnReduce(pp.size(), sumOp<label>())
150  << " mag(faceAreas):" << gSum(mag(pp.faceAreas())) << endl;
151 
152  //changeRequired = pp.changeTopology(newPoints) || changeRequired;
153  changeRequired = pp.changeTopology() || changeRequired;
154  }
155 
156  reduce(changeRequired, orOp<bool>());
157 
158  if (changeRequired)
159  {
160  polyTopoChange polyTopo(*this);
161 
162  // Set new point positions in polyTopo object
163  polyTopo.movePoints(newPoints);
164 
165  // Accumulate the patch-based mesh changes on the current mesh
166  // Note:
167  // - updates the AMIs using the new points
168  // - creates a topo change object that removes old added faces and
169  // adds the new faces
170  for (polyPatch& pp : pbm)
171  {
172  pp.setTopology(polyTopo);
173  }
174 
175  // Update geometry
176  // Note
177  // - changeMesh leads to polyMesh::resetPrimitives which will also
178  // trigger polyBoundaryMesh::updateMesh (init and update) and
179  // ::calcGeometry (with topoChanging = false)
180  // - BUT: mesh still corresponds to original (non-extended mesh) so
181  // we want to bypass these calls...
182  // - after changes topoChanging = true
184  polyTopo.changeMesh
185  (
186  *this,
187  true // We will be calling movePoints after this update
188  );
189 
190  // Apply topology change - update fv geometry and map fields
191  // - polyMesh::updateMesh
192  // - fires initUpdateMesh and updateMesh in AMI BCs - called before
193  // mapFields
194  // - AMI addressing must be up-to-date - used by, e.g. FaceCellWave
195  // - will trigger (again) polyBoundaryMesh::updateMesh (init and update)
196  updateMesh(map());
197 
198  // Move points and update derived properties
199  // Note:
200  // - resets face areas based on raw point locations!
201  // - polyBoundaryMesh::updateMesh (init and update)
202  // Note:
203  // - processorPolyPatches will trigger calculation of faceCentres
204  // (and therefore cell volumes), so need to update faceAreas in
205  // initMovePoints since proc patches will be evaluated later than
206  // AMI patches
207  if (map().hasMotionPoints())
208  {
209  movePoints(map().preMotionPoints());
210  }
211  }
212  else
213  {
214  fvMesh::movePoints(newPoints);
215  }
216 
217  volVectorField* Uptr = getObjectPtr<volVectorField>("U");
218 
219  if (Uptr)
220  {
222 
223  surfaceVectorField* UfPtr = getObjectPtr<surfaceVectorField>("Uf");
224  if (UfPtr)
225  {
226  *UfPtr = fvc::interpolate(*Uptr);
227  }
228  }
229 
230  if (debug)
231  {
232  for (const fvPatch& fvp : boundary())
233  {
234  if (!isA<processorFvPatch>(fvp))
235  {
236  Info<< "2 --- patch:" << fvp.patch().name()
237  << " area:" << gSum(fvp.magSf()) << endl;
238  }
239  }
240  }
241 
242  return true;
243 }
244 
245 
246 // ************************************************************************* //
Foam::expressions::patchExpr::debug
int debug
Static debugging option.
Foam::addToRunTimeSelectionTable
addToRunTimeSelectionTable(decompositionMethod, kahipDecomp, dictionary)
Foam::motionSolver::New
static autoPtr< motionSolver > New(const polyMesh &)
Select constructed from polyMesh.
Definition: motionSolver.C:150
volFields.H
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:104
processorFvPatch.H
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::polyBoundaryMesh
A polyBoundaryMesh is a polyPatch list with additional search methods and registered IO.
Definition: polyBoundaryMesh.H:62
motionSolver.H
Foam::polyTopoChange::changeMesh
autoPtr< mapPolyMesh > changeMesh(polyMesh &mesh, const bool inflate, const bool syncParallel=true, const bool orderCells=false, const bool orderPoints=false)
Inplace changes mesh without change of patches.
Definition: polyTopoChange.C:2959
polyTopoChange.H
Foam::polyTopoChange
Direct mesh changes based on v1.3 polyTopoChange syntax.
Definition: polyTopoChange.H:99
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::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:350
surfaceFields.H
Foam::surfaceFields.
Foam::gSum
Type gSum(const FieldField< Field, Type > &f)
Definition: FieldFieldFunctions.C:594
Foam::sumOp
Definition: ops.H:213
Foam::reduce
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
Definition: PstreamReduceOps.H:51
Foam::Field< vector >
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
Foam::polyPatch
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:68
Foam::fvPatch
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:65
init
mesh init(true)
dynamicMotionSolverFvMeshAMI.H
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::fvc::interpolate
static tmp< GeometricField< Type, fvsPatchField, surfaceMesh > > interpolate(const GeometricField< Type, fvPatchField, volMesh > &tvf, const surfaceScalarField &faceFlux, Istream &schemeData)
Interpolate field onto faces using scheme given by Istream.
Foam::dynamicMotionSolverFvMeshAMI::motion
const motionSolver & motion() const
Return the motionSolver.
Definition: dynamicMotionSolverFvMeshAMI.C:115
cyclicAMIPolyPatch.H
Foam::GeometricField::correctBoundaryConditions
void correctBoundaryConditions()
Correct boundary field.
Definition: GeometricField.C:940
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::motionSolver
Virtual base class for mesh motion solver.
Definition: motionSolver.H:58
DebugInfo
#define DebugInfo
Report an information message using Foam::Info.
Definition: messageStream.H:359
Foam::dynamicMotionSolverFvMeshAMI::update
virtual bool update()
Update the mesh for both mesh motion and topology change.
Definition: dynamicMotionSolverFvMeshAMI.C:121
Foam::List< face >
Foam::mag
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
points
const pointField & points
Definition: gmvOutputHeader.H:1
MeshObject.H
Foam::boundaryMesh
Addressing for all faces on surface of mesh. Can either be read from polyMesh or from triSurface....
Definition: boundaryMesh.H:62
Foam::GeometricField< vector, fvPatchField, volMesh >
lduMesh.H
Foam::orOp
Definition: ops.H:234
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
boundary
faceListList boundary
Definition: createBlockMesh.H:4
Foam::polyTopoChange::movePoints
void movePoints(const pointField &newPoints)
Move all points. Incompatible with other topology changes.
Definition: polyTopoChange.C:2659
Foam::dynamicMotionSolverFvMeshAMI::init
virtual bool init(const bool doInit)
Initialise all non-demand-driven data.
Definition: dynamicMotionSolverFvMeshAMI.C:78