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  Copyright (C) 2026 Keysight Technologies
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
31 #include "volFields.H"
32 
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
37  defineTypeNameAndDebug(dynamicMultiMotionSolverFvMesh, 0);
39  (
40  dynamicFvMesh,
41  dynamicMultiMotionSolverFvMesh,
42  IOobject
43  );
45  (
46  dynamicFvMesh,
47  dynamicMultiMotionSolverFvMesh,
48  doInit
49  );
50 }
51 
52 
53 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
54 
56 (
57  const IOobject& io,
58  const bool doInit
59 )
60 :
61  dynamicFvMesh(io, doInit)
62 {
63  if (doInit)
64  {
65  init(false); // do not initialise lower levels
66  }
67 }
68 
69 
70 bool Foam::dynamicMultiMotionSolverFvMesh::init(const bool doInit)
71 {
72  if (doInit)
73  {
74  dynamicFvMesh::init(doInit);
75  }
76 
77  IOobject dynMeshDictIO
78  (
79  "dynamicMeshDict",
80  time().constant(),
81  *this,
82  IOobjectOption::MUST_READ, //<- MUST_READ for initial setup
85  );
86 
87  dictionary dynDict(IOdictionary::readContents(dynMeshDictIO));
88  const auto& dynamicMeshCoeffs = dynDict.subDict(typeName + "Coeffs");
89 
90  // NO_READ for further construction
91  dynMeshDictIO.readOpt(IOobjectOption::NO_READ);
92 
93  motionSolvers_.resize(dynamicMeshCoeffs.size());
94  zoneMotions_.resize(dynamicMeshCoeffs.size());
95 
96  const auto& allCellZones = this->cellZones();
97 
98  label zonei = 0;
99 
100  for (const entry& e : dynamicMeshCoeffs)
101  {
102  if (const auto* dictptr = e.dictPtr())
103  {
104  const auto& subDict = *dictptr;
105 
106  wordRe cellZoneName;
107  subDict.readEntry("cellZone", cellZoneName);
108 
109  // Also handles groups, multiple zones (as wordRe match) ...
110  labelList zoneIDs = allCellZones.indices(cellZoneName);
111 
112  if (zoneIDs.empty())
113  {
114  FatalIOErrorInFunction(dynamicMeshCoeffs)
115  << "No matching cellZones: " << cellZoneName << nl
116  << " Valid zones : "
117  << flatOutput(allCellZones.names()) << nl
118  << " Valid groups: "
119  << flatOutput(allCellZones.groupNames()) << nl
120  << exit(FatalIOError);
121  }
122 
123  motionSolvers_.set
124  (
125  zonei,
127  (
128  *this,
129  IOdictionary(dynMeshDictIO, subDict)
130  )
131  );
132 
133  // The points associated with cell zone(s)
134  auto& zoneMove = zoneMotions_.emplace_set(zonei, *this, zoneIDs);
135 
136  Info<< "Applying motionSolver " << motionSolvers_[zonei].type()
137  << " to "
138  << returnReduce(zoneMove.pointIDs().size(), sumOp<label>())
139  << " points of cellZone " << cellZoneName << endl;
140 
141  ++zonei;
142  }
143  }
144 
145  motionSolvers_.resize(zonei);
146  zoneMotions_.resize(zonei);
147 
148  // Assume changed ...
149  return true;
150 }
151 
152 
153 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
154 
156 {
157  pointField transformedPts(this->points());
158 
159  forAll(motionSolvers_, zonei)
160  {
161  const labelUList& zonePoints = zoneMotions_[zonei].pointIDs();
162 
163  const pointField newPoints(motionSolvers_[zonei].newPoints());
164 
165  for (const label pointi : zonePoints)
166  {
167  transformedPts[pointi] = newPoints[pointi];
168  }
169  }
170 
171  fvMesh::movePoints(transformedPts);
172 
173  static bool hasWarned = false;
174 
175  if (auto* Uptr = getObjectPtr<volVectorField>("U"))
176  {
177  Uptr->correctBoundaryConditions();
178  }
179  else if (!hasWarned)
180  {
181  hasWarned = true;
182 
184  << "Did not find volVectorField U."
185  << " Not updating U boundary conditions." << endl;
186  }
187 
188  return true;
189 }
190 
191 
192 // ************************************************************************* //
const labelIOList & zoneIDs
Definition: correctPhi.H:59
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:702
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:518
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()
static dictionary readContents(const IOobject &io)
Read and return contents, testing for "dictionary" type. The IOobject will not be registered...
Definition: IOdictionary.C:89
Macros for easy insertion into run-time selection tables.
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:400
const dimensionedScalar e
Elementary charge.
Definition: createFields.H:11
const pointField & points
const auto & io
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.
defineTypeNameAndDebug(combustionModel, 0)
Expression::UniformListWrap< scalar > constant
Wrap of constant as a list expression.
#define WarningInFunction
Report a warning using Foam::Warning.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:681
Abstract base class for geometry and/or topology changing fvMesh.
Definition: dynamicFvMesh.H:74
Nothing to be read.
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:61
virtual bool init(const bool doInit)
Initialise all non-demand-driven data.
dynamicMultiMotionSolverFvMesh(const dynamicMultiMotionSolverFvMesh &)=delete
No copy construct.
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:188
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:217
IOerror FatalIOError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL IO ERROR&#39; header text and ...