engineMesh.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) 2011-2015 OpenFOAM Foundation
9  Copyright (C) 2022 OpenCFD Ltd.
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 
29 #include "engineMesh.H"
30 #include "dimensionedScalar.H"
31 
32 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 
34 namespace Foam
35 {
38 }
39 
40 
41 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
42 
43 Foam::engineMesh::engineMesh(const IOobject& io)
44 :
45  fvMesh(io),
46  engineDB_(refCast<const engineTime>(time())),
47  pistonIndex_(-1),
48  linerIndex_(-1),
49  cylinderHeadIndex_(-1),
50  deckHeight_("deckHeight", dimLength, GREAT),
51  pistonPosition_("pistonPosition", dimLength, -GREAT)
52 {
53  bool foundPiston = false;
54  bool foundLiner = false;
55  bool foundCylinderHead = false;
56 
57  forAll(boundary(), i)
58  {
59  if (boundary()[i].name() == "piston")
60  {
61  pistonIndex_ = i;
62  foundPiston = true;
63  }
64  else if (boundary()[i].name() == "liner")
65  {
66  linerIndex_ = i;
67  foundLiner = true;
68  }
69  else if (boundary()[i].name() == "cylinderHead")
70  {
72  foundCylinderHead = true;
73  }
74  }
75 
76  if (!returnReduceOr(foundPiston))
77  {
79  << "cannot find piston patch"
80  << exit(FatalError);
81  }
82 
83  if (!returnReduceOr(foundLiner))
84  {
86  << "cannot find liner patch"
87  << exit(FatalError);
88  }
89 
90  if (!returnReduceOr(foundCylinderHead))
91  {
93  << "cannot find cylinderHead patch"
94  << exit(FatalError);
95  }
96 
97  {
98  if (pistonIndex_ != -1)
99  {
100  pistonPosition_.value() = -GREAT;
101  if (boundary()[pistonIndex_].patch().localPoints().size())
102  {
104  max(boundary()[pistonIndex_].patch().localPoints()).z();
105  }
106  }
107  reduce(pistonPosition_.value(), maxOp<scalar>());
108 
109  if (cylinderHeadIndex_ != -1)
110  {
111  deckHeight_.value() = GREAT;
112  if (boundary()[cylinderHeadIndex_].patch().localPoints().size())
113  {
114  deckHeight_.value() = min
115  (
116  boundary()[cylinderHeadIndex_].patch().localPoints()
117  ).z();
118  }
119  }
120  reduce(deckHeight_.value(), minOp<scalar>());
121 
122  Info<< "deckHeight: " << deckHeight_.value() << nl
123  << "piston position: " << pistonPosition_.value() << endl;
124  }
125 }
126 
127 
128 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
129 
131 {}
132 
133 // ************************************************************************* //
const Type & value() const noexcept
Return const reference to value.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:598
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:40
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
Type & refCast(U &obj)
A dynamic_cast (for references). Generates a FatalError on failed casts and uses the virtual type() m...
Definition: typeInfo.H:159
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
virtual ~engineMesh()
Destructor.
Definition: engineMesh.C:123
An abstract class for the time description of the piston motion.
Definition: engineTime.H:50
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
label size() const noexcept
The number of elements in table.
Definition: HashTable.H:342
dimensionedScalar deckHeight_
Definition: engineMesh.H:76
label pistonIndex_
Definition: engineMesh.H:72
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:26
Foam::engineMesh.
Definition: engineMesh.H:49
defineRunTimeSelectionTable(reactionRateFlameArea, dictionary)
defineTypeNameAndDebug(combustionModel, 0)
const word & name() const
Return reference to name.
Definition: fvMesh.H:387
const dimensionSet dimLength(0, 1, 0, 0, 0, 0, 0)
Definition: dimensionSets.H:50
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
const std::string patch
OpenFOAM patch number as a std::string.
messageStream Info
Information stream (stdout output on master, null elsewhere)
const fvBoundaryMesh & boundary() const noexcept
Return reference to boundary mesh.
Definition: fvMesh.H:395
IOobject io("surfaceFilmProperties", mesh.time().constant(), mesh, IOobject::READ_IF_PRESENT, IOobject::NO_WRITE, IOobject::NO_REGISTER)
label cylinderHeadIndex_
Definition: engineMesh.H:74
bool returnReduceOr(const bool value, const label comm=UPstream::worldComm)
Perform logical (or) MPI Allreduce on a copy. Uses UPstream::reduceOr.
Defines the attributes of an object for which implicit objectRegistry management is supported...
Definition: IOobject.H:172
dimensionedScalar pistonPosition_
Definition: engineMesh.H:77
void reduce(T &Value, const BinaryOp &bop) const
Helper: reduce with current communicator.
Namespace for OpenFOAM.