createEngineZones.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2024 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Application
25  createEngineZones
26 
27 Description
28  Utility to create the cylinder head and piston bowl pointZones
29 
30 \*---------------------------------------------------------------------------*/
31 
32 #include "argList.H"
33 #include "Time.H"
34 #include "multiValveEngine.H"
35 #include "pistonPointEdgeData.H"
36 #include "PointEdgeWave.H"
37 
38 using namespace Foam;
39 
40 void calcCylinderHeadPoints(const fvMeshMovers::multiValveEngine& mve)
41 {
42  const fvMesh& mesh = mve.mesh();
43 
44  const pointField& points = mesh.points();
45  const polyBoundaryMesh& pbm = mesh.boundaryMesh();
46 
47  // Set the cylinderHead point flags
48  boolList cylinderHeadPoints(points.size(), false);
50  {
52  (
53  cylinderHeadPoints,
54  pbm[iter.key()].meshPoints()
55  ) = true;
56  }
57 
58  // Set the liner point flags
59  boolList linerPoints(points.size(), false);
61  {
63  (
64  linerPoints,
65  pbm[iter.key()].meshPoints()
66  ) = true;
67  }
68 
69  // Find the minimum axis_ coordinate of the cylinder head region
70  // from the bottom of the intersections with the liner
71  // for which both the cylinderHead and liner point flags are true
72  // Assumes the piston moves in the positive axis direction
73 
74  scalar minZ = great;
75  forAll(cylinderHeadPoints, pi)
76  {
77  if (cylinderHeadPoints[pi] && linerPoints[pi])
78  {
79  minZ = min(mve.piston.axis & points[pi], minZ);
80  }
81  }
82  reduce(minZ, maxOp<scalar>());
83 
84  // Create the cylinderHead point set
85  labelHashSet cylinderHeadPointSet;
86  forAll(points, pi)
87  {
88  if ((mve.piston.axis & points[pi]) > minZ)
89  {
90  cylinderHeadPointSet.insert(pi);
91  }
92  }
93 
94  // Add the cylinderHead pointZone
95  mesh.pointZones().append
96  (
97  new pointZone
98  (
99  mve.cylinderHeadName,
100  cylinderHeadPointSet.toc(),
101  mesh.pointZones()
102  )
103  );
104 }
105 
106 
107 void calcPistonBowlPoints(const fvMeshMovers::multiValveEngine& mve)
108 {
109  const fvMesh& mesh = mve.mesh();
111 
112  const polyBoundaryMesh& pbm = mesh.boundaryMesh();
113 
114  // Find the maximum axis coordinate of the piston patch-set
115  // Assumes the piston moves in the positive axis direction
116  scalar maxZ = -great;
117  forAllConstIter(labelHashSet, piston.patchSet, iter)
118  {
119  const label patchi = iter.key();
120  if (pbm[patchi].localPoints().size())
121  {
122  maxZ = max(maxZ, max(piston.axis & pbm[patchi].localPoints()));
123  }
124  }
125  reduce(maxZ, maxOp<scalar>());
126 
127 
128  // Search for points starting at the piston surface and stopping at maxZ
129  // using a PointEdgeWave
130 
131  label nPistonPatchPoints = 0;
132  forAllConstIter(labelHashSet, piston.patchSet, iter)
133  {
134  const label patchi = iter.key();
135  nPistonPatchPoints += pbm[patchi].meshPoints().size();
136  }
137 
138 
139  const pointField& points = mesh.points();
141 
142  // Set initial changed points to all the patch points(if patch present)
143  List<pistonPointEdgeData> pistonPatchPointData(nPistonPatchPoints);
144  labelList pistonPatchPoints(nPistonPatchPoints);
145 
146  // Add the patch points to the pistonPatchPointData
147  nPistonPatchPoints = 0;
148  forAllConstIter(labelHashSet, piston.patchSet, iter)
149  {
150  const label patchi = iter.key();
151  const labelList& mp = pbm[patchi].meshPoints();
152 
153  forAll(mp, ppi)
154  {
155  pistonPatchPoints[nPistonPatchPoints] = mp[ppi];
156  pistonPatchPointData[nPistonPatchPoints] = pistonPointEdgeData
157  (
158  true
159  );
160  nPistonPatchPoints++;
161  }
162  }
163 
164  // Point data for wave
165  List<pistonPointEdgeData> allPointData(mesh.nPoints());
166 
167  // Edge data for wave
168  List<pistonPointEdgeData> allEdgeData(mesh.nEdges());
169 
171  <
174  > patchCalc
175  (
176  mesh,
177  pistonPatchPoints,
178  pistonPatchPointData,
179 
180  allPointData,
181  allEdgeData,
182  mesh.globalData().nTotalPoints(), // max iterations
183  td
184  );
185 
186  // Create a labelHashSet of the point labels in the piston bowl
187  labelHashSet pistonBowlPointSet;
188  forAll(allPointData, pointi)
189  {
190  if (allPointData[pointi].inBowl())
191  {
192  pistonBowlPointSet.insert(pointi);
193  }
194  }
195 
196  // Convert the labelHashSet to a pointZone and add to the pointZones
197  mesh.pointZones().append
198  (
199  new pointZone
200  (
201  piston.pistonBowlName,
202  pistonBowlPointSet.toc(),
203  mesh.pointZones()
204  )
205  );
206 }
207 
208 
209 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
210 
211 int main(int argc, char *argv[])
212 {
214 
215  #include "addRegionOption.H"
216 
218  (
219  "cylinderHead",
220  "Create the cylinderHead pointZone"
221  );
222 
224  (
225  "pistonBowl",
226  "Create the piston pointZone"
227  );
228 
229  #include "setRootCase.H"
231 
232  const bool cylinderHeadZone = args.optionFound("cylinderHead");
233  const bool pistonBowlZone = args.optionFound("pistonBowl");
234 
235  if (!cylinderHeadZone && !pistonBowlZone)
236  {
238  << "Neither cylinderHeadZone nor pistonBowl pointZones requested"
239  << exit(FatalError);
240  }
241 
242  #include "createRegionMesh.H"
243 
245  (
246  refCast<const fvMeshMovers::multiValveEngine>(mesh.mover())
247  );
248 
249  if (cylinderHeadZone)
250  {
251  calcCylinderHeadPoints(mve);
252  }
253 
254  if (pistonBowlZone)
255  {
256  calcPistonBowlPoints(mve);
257  }
258 
259  // Take over refinement levels and write to new time directory.
260  Info<< "Writing pointZones" << endl;
261  mesh.pointZones().write();
262 
263  Info<< "End\n" << endl;
264 
265  return 0;
266 }
267 
268 
269 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
#define forAllConstIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:477
bool insert(const Key &key)
Insert a new entry.
Definition: HashSet.H:109
List< Key > toc() const
Return the table of contents.
Definition: HashTable.C:227
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
Wave propagation of information through grid. Every iteration information goes through one layer of e...
Definition: PointEdgeWave.H:89
A List with indirect addressing.
Definition: UIndirectList.H:60
label size() const
Return the number of elements in the UPtrList.
Definition: UPtrListI.H:29
void append(ZoneType *) const
Append or update a zone.
Definition: ZoneList.C:176
static void addBoolOption(const word &opt, const string &usage="")
Add to a bool option to validOptions with usage information.
Definition: argList.C:118
bool optionFound(const word &opt) const
Return true if the named option is found.
Definition: argListI.H:114
static void noParallel()
Remove the parallel options.
Definition: argList.C:175
fvMesh & mesh()
Return the fvMesh.
Definition: fvMeshMover.H:132
const labelHashSet & patchSet
Object patchSet.
static word pistonBowlName
Name of the piston bowl pointZone.
A mesh mover using explicit node translation based on scaled distance functions per moving object....
const labelHashSet & staticPatchSet
Static patch set.
const labelHashSet & linerPatchSet
User-defined liner patches.
const pistonObject & piston
Piston object.
static word cylinderHeadName
Name of the cylinder head pointZone.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:99
const fvMeshMover & mover() const
Return the mover function class.
Definition: fvMesh.C:1050
label nTotalPoints() const
Return total number of points in decomposed mesh. Not.
Class used to pass data into container.
Holds information regarding nearest wall point. Used in PointEdgeWave. (so not standard FaceCellWave)...
A subset of mesh points. The labels of points in the zone can be obtained from the addressing() list.
Definition: pointZone.H:59
Foam::polyBoundaryMesh.
const pointZoneList & pointZones() const
Return point zones.
Definition: polyMesh.H:440
const globalMeshData & globalData() const
Return parallel info.
Definition: polyMesh.C:1515
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:404
virtual const pointField & points() const
Return raw points.
Definition: polyMesh.C:1313
label nEdges() const
label nPoints() const
virtual bool write(const bool write=true) const
Write using setting from DB.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
int main(int argc, char *argv[])
Definition: financialFoam.C:44
label patchi
const pointField & points
const dimensionedScalar mp
Proton mass.
Namespace for OpenFOAM.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
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:59
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:257
messageStream Info
layerAndWeight min(const layerAndWeight &a, const layerAndWeight &b)
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
error FatalError
Foam::argList args(argc, argv)