Loading...
Searching...
No Matches
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-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 "motionSolver.H"
31#include "volFields.H"
32#include "surfaceFields.H"
33#include "cyclicAMIPolyPatch.H"
34#include "cyclicACMIPolyPatch.H"
35#include "polyTopoChange.H"
36#include "MeshObject.H"
37#include "lduMesh.H"
38#include "surfaceInterpolate.H"
41
42// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
43
44namespace Foam
45{
48 (
52 );
54 (
57 doInit
58 );
59}
60
61
62// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
63
64Foam::dynamicMotionSolverFvMeshAMI::dynamicMotionSolverFvMeshAMI
65(
66 const IOobject& io,
67 const bool doInit
68)
69:
70 dynamicFvMesh(io, doInit)
71{
72 if (doInit)
73 {
74 init(false); // do not initialise lower levels
75 }
76}
77
78
79bool Foam::dynamicMotionSolverFvMeshAMI::init(const bool doInit)
80{
81 if (doInit)
82 {
83 dynamicFvMesh::init(doInit);
84 }
85
86 motionPtr_ = motionSolver::New(*this);
87
88 // allow restarts during initialization to match patch field values if
89 // required
90 const auto& pbm = boundaryMesh();
91 bool changeRequired = false;
92 for (label patchi = 0; patchi < pbm.nNonProcessor(); ++patchi)
93 {
94 const auto* cycAmiPtr = isA<cyclicAMIPolyPatch>(pbm[patchi]);
95
96 if (cycAmiPtr)
97 {
98 changeRequired = cycAmiPtr->createAMIFaces() || changeRequired;
99 }
100 else
101 {
102 const auto* cycAcmiPtr = isA<cyclicACMIPolyPatch>(pbm[patchi]);
103 if (cycAcmiPtr)
104 {
105 changeRequired =
106 cycAcmiPtr->cyclicAMIPolyPatch::createAMIFaces()
107 || changeRequired;
108 }
109 }
110 }
111 if (returnReduceOr(changeRequired))
112 {
114 }
115
116 return true;
117}
118
119
120Foam::dynamicMotionSolverFvMeshAMI::dynamicMotionSolverFvMeshAMI
121(
122 const IOobject& io,
124 faceList&& faces,
125 labelList&& allOwner,
126 labelList&& allNeighbour,
127 const bool syncPar
128)
129:
130 dynamicFvMesh
131 (
132 io,
133 std::move(points),
134 std::move(faces),
135 std::move(allOwner),
136 std::move(allNeighbour),
137 syncPar
138 ),
139 motionPtr_(motionSolver::New(*this))
140{}
141
142
143// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
146{
147 return *motionPtr_;
148}
149
150
152{
153 // Mesh not moved/changed yet
154 moving(false);
155 topoChanging(false);
156
157 if (debug)
158 {
159 for (const fvPatch& fvp : boundary())
160 {
161 if (!isA<processorFvPatch>(fvp))
162 {
163 Info<< "1 --- patch:" << fvp.patch().name()
164 << " area:" << gSum(fvp.magSf()) << endl;
165 }
166 }
167 }
168
169 pointField newPoints(motionPtr_->curPoints());
170
172
173 // Scan all patches and see if we want to apply a mesh topology update
174 bool changeRequired = false;
175 for (label patchi = 0; patchi < pbm.nNonProcessor(); ++patchi)
176 {
177 const polyPatch& pp = pbm[patchi];
178
180 << "pre-topology change: patch " << pp.name()
181 << " size:" << returnReduce(pp.size(), sumOp<label>())
182 << " mag(faceAreas):" << gSum(mag(pp.faceAreas())) << endl;
183
184 //changeRequired = pp.changeTopology(newPoints) || changeRequired;
185 changeRequired = pp.changeTopology() || changeRequired;
186 }
187
188 if (returnReduceOr(changeRequired))
189 {
190 polyTopoChange polyTopo(*this);
191
192 // Set new point positions in polyTopo object
193 polyTopo.movePoints(newPoints);
194
195 // Accumulate the patch-based mesh changes on the current mesh
196 // Note:
197 // - updates the AMIs using the new points
198 // - creates a topo change object that removes old added faces and
199 // adds the new faces
200 for (polyPatch& pp : pbm)
201 {
202 pp.setTopology(polyTopo);
203 }
204
205 // Update geometry
206 // Note
207 // - changeMesh leads to polyMesh::resetPrimitives which will also
208 // trigger polyBoundaryMesh::updateMesh (init and update) and
209 // ::calcGeometry (with topoChanging = false)
210 // - BUT: mesh still corresponds to original (non-extended mesh) so
211 // we want to bypass these calls...
212 // - after changes topoChanging = true
214 polyTopo.changeMesh
215 (
216 *this,
217 true // We will be calling movePoints after this update
218 );
219
220 // Apply topology change - update fv geometry and map fields
221 // - polyMesh::updateMesh
222 // - fires initUpdateMesh and updateMesh in AMI BCs - called before
223 // mapFields
224 // - AMI addressing must be up-to-date - used by, e.g. FaceCellWave
225 // - will trigger (again) polyBoundaryMesh::updateMesh (init and update)
226 updateMesh(map());
227
228 // Move points and update derived properties
229 // Note:
230 // - resets face areas based on raw point locations!
231 // - polyBoundaryMesh::updateMesh (init and update)
232 // Note:
233 // - processorPolyPatches will trigger calculation of faceCentres
234 // (and therefore cell volumes), so need to update faceAreas in
235 // initMovePoints since proc patches will be evaluated later than
236 // AMI patches
237 if (map().hasMotionPoints())
238 {
239 movePoints(map().preMotionPoints());
240 }
241 }
242 else
243 {
244 fvMesh::movePoints(newPoints);
245 }
246
247 volVectorField* Uptr = getObjectPtr<volVectorField>("U");
248
249 if (Uptr)
250 {
251 Uptr->correctBoundaryConditions();
252
253 surfaceVectorField* UfPtr = getObjectPtr<surfaceVectorField>("Uf");
254 if (UfPtr)
255 {
256 *UfPtr = fvc::interpolate(*Uptr);
257 }
258 }
259
260 if (debug)
261 {
262 for (const fvPatch& fvp : boundary())
263 {
264 if (!isA<processorFvPatch>(fvp))
265 {
266 Info<< "2 --- patch:" << fvp.patch().name()
267 << " area:" << gSum(fvp.magSf()) << endl;
268 }
269 }
270 }
271
272 return true;
273}
274
275
276// ************************************************************************* //
Macros for easy insertion into run-time selection tables.
#define addToRunTimeSelectionTable(baseType, thisType, argNames)
Add to construction table with typeName as the key.
uindirectPrimitivePatch pp(UIndirectList< face >(mesh.faces(), faceLabels), mesh.points())
const polyBoundaryMesh & pbm
void correctBoundaryConditions()
Correct boundary field.
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition IOobject.H:191
label size() const noexcept
The number of elements in the list.
const Field< point_type > & faceAreas() const
Return face area vectors for patch.
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition autoPtr.H:65
Addressing for all faces on surface of mesh. Can either be read from polyMesh or from triSurface....
Abstract base class for geometry and/or topology changing fvMesh.
virtual bool init(const bool doInit)
Initialise all non-demand-driven data.
static autoPtr< dynamicFvMesh > New(const IOobject &io)
Select, construct and return the dynamicFvMesh.
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.
const motionSolver & motion() const
Return the motionSolver.
virtual bool movePoints()
Avoid masking surfaceInterpolation method.
virtual void updateMesh(const mapPolyMesh &mpm)
Update mesh corresponding to the given map.
Definition fvMesh.C:960
virtual void movePoints(const pointField &)
Move points, returns volumes swept by faces in motion.
Definition fvMesh.C:884
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition fvPatch.H:71
Virtual base class for mesh motion solver.
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...
A polyBoundaryMesh is a polyPatch list with registered IO, a reference to the associated polyMesh,...
label nNonProcessor() const
The number of patches before the first processor patch.
virtual const faceList & faces() const
Return raw faces.
Definition polyMesh.C:1088
bool moving() const noexcept
Is mesh moving.
Definition polyMesh.H:732
bool topoChanging() const noexcept
Is mesh topology changing.
Definition polyMesh.H:750
virtual const pointField & points() const
Return raw points.
Definition polyMesh.C:1063
A patch is a list of labels that address the faces in the global face list.
Definition polyPatch.H:73
Direct mesh changes based on v1.3 polyTopoChange syntax.
void movePoints(const pointField &newPoints)
Move all points. Incompatible with other topology changes.
autoPtr< mapPolyMesh > changeMesh(polyMesh &mesh, const labelUList &patchMap, const bool inflate, const bool syncParallel=true, const bool orderCells=false, const bool orderPoints=false)
Inplace changes mesh without change of patches.
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition className.H:142
mesh update()
faceListList boundary
const auto & io
const pointField & points
#define DebugInfo
Report an information message using Foam::Info.
Namespace for handling debugging switches.
Definition debug.C:45
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.
Namespace for OpenFOAM.
GeometricField< vector, fvsPatchField, surfaceMesh > surfaceVectorField
bool returnReduceOr(const bool value, const int communicator=UPstream::worldComm)
Perform logical (or) MPI Allreduce on a copy. Uses UPstream::reduceOr.
Type gSum(const FieldField< Field, Type > &f)
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).
List< face > faceList
List of faces.
Definition faceListFwd.H:41
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.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
const Type * isA(const U &obj)
Attempt dynamic_cast to Type.
Definition typeInfo.H:87
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
vectorField pointField
pointField is a vectorField.
Foam::surfaceFields.