Loading...
Searching...
No Matches
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-------------------------------------------------------------------------------
11License
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"
31
32// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33
34namespace Foam
35{
38}
39
40
41// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
42
43Foam::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 {
103 pistonPosition_.value() =
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// ************************************************************************* //
label size() const noexcept
Definition HashTable.H:358
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition IOobject.H:191
Foam::engineMesh.
Definition engineMesh.H:52
virtual ~engineMesh()
Destructor.
Definition engineMesh.C:123
dimensionedScalar deckHeight_
Definition engineMesh.H:76
const engineTime & engineDB_
Definition engineMesh.H:70
label cylinderHeadIndex_
Definition engineMesh.H:74
dimensionedScalar pistonPosition_
Definition engineMesh.H:77
An abstract class for the time description of the piston motion.
Definition engineTime.H:53
Mesh data needed to do the Finite Volume discretisation.
Definition fvMesh.H:85
const Time & time() const
Return the top-level database.
Definition fvMesh.H:360
fvMesh(const fvMesh &)=delete
No copy construct.
const word & name() const
Return reference to name.
Definition fvMesh.H:387
const fvBoundaryMesh & boundary() const noexcept
Return reference to boundary mesh.
Definition fvMesh.H:395
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition className.H:142
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition error.H:600
const auto & io
const std::string patch
OpenFOAM patch number as a std::string.
Namespace for OpenFOAM.
Type & refCast(U &obj)
A dynamic_cast (for references) to Type reference.
Definition typeInfo.H:172
bool returnReduceOr(const bool value, const int communicator=UPstream::worldComm)
Perform logical (or) MPI Allreduce on a copy. Uses UPstream::reduceOr.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition hashSets.C:40
const dimensionSet dimLength(0, 1, 0, 0, 0, 0, 0)
messageStream Info
Information stream (stdout output on master, null elsewhere).
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
void reduce(T &value, BinaryOp bop, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm)
Reduce inplace (cf. MPI Allreduce).
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition hashSets.C:26
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition errorManip.H:125
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
#define defineRunTimeSelectionTable(baseType, argNames)
Define run-time selection table.
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299