engineCompRatio.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) 2011-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  engineCompRatio
26 
27 Description
28  Calculate the compression ratio of the engine combustion chamber
29 
30  If the combustion chamber is not the entire mesh a \c cellSet or
31  \c cellZone name of the cells in the combustion chamber can be provided.
32 
33 Usage
34  \b engineCompRatio [OPTION]
35 
36  - \par -cellSet <name>
37  Specify the cellSet name of the combustion chamber
38 
39  - \par -cellZone zoneName
40  Specify the cellZone name of the combustion chamber
41 
42 \*---------------------------------------------------------------------------*/
43 
44 #include "argList.H"
45 #include "volMesh.H"
46 #include "cellSet.H"
47 
48 using namespace Foam;
49 
50 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
51 
52 int main(int argc, char *argv[])
53 {
54  #include "addMeshOption.H"
55  #include "addRegionOption.H"
56 
58  (
59  "cellSet",
60  "name",
61  "Calculate the volume of the specified cellSet"
62  );
63 
65  (
66  "cellZone",
67  "name",
68  "Calculate the volume of the specified cellZone"
69  );
70 
71  #include "setRootCase.H"
72  #include "createTime.H"
73  #include "createSpecifiedMesh.H"
74 
75  // Cell labels of the cells in the combustion chamber
76  // Defaults to all cells
77  labelList ccCells(identityMap(mesh.nCells()));
78 
79  word cellSetName;
80  word cellZoneName;
81  if (args.optionReadIfPresent("cellSet", cellSetName))
82  {
83  // Read the cellSet for the combustion chamber
84  const cellSet ccCellSet(mesh, cellSetName);
85  ccCells = ccCellSet.toc();
86  }
87  else if (args.optionReadIfPresent("cellZone", cellZoneName))
88  {
89  const cellZone& ccCellZone = mesh.cellZones()[cellZoneName];
90  ccCells = ccCellZone;
91  }
92 
93  // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
94 
95  const scalar eps = 1.0e-10;
96 
97  // Search for the CA >= the current CA which is divisible by 180
98  int ca0 = -360;
99  while (runTime.userTimeValue() > ca0)
100  {
101  ca0 += 180;
102  }
103  int ca1 = ca0 + 180;
104 
105  if (mag(runTime.userTimeValue() - ca0) > eps)
106  {
107  const scalar t0 = runTime.userTimeToTime(ca0 - runTime.userTimeValue());
108  runTime.setDeltaT(t0);
109  runTime++;
110  Info<< "Moving to CA = " << runTime.userTimeValue() << endl;
111  mesh.move();
112  }
113 
114  const scalar V0 = gSum(scalarField(mesh.V(), ccCells));
115  Info << "Volume at " << runTime.userTimeValue() << "CA = " << V0 << endl;
116 
117  if (mag(runTime.userTimeValue()-ca1) > eps)
118  {
119  const scalar t1 = runTime.userTimeToTime(ca1 - runTime.userTimeValue());
120  runTime.setDeltaT(t1);
121  runTime++;
122  Info<< "Moving to CA = " << runTime.userTimeValue() << endl;
123  mesh.move();
124  }
125 
126  const scalar V1 = gSum(scalarField(mesh.V(), ccCells));
127  Info << "Volume at " << runTime.userTimeValue() << "CA = " << V1 << endl;
128 
129  const scalar Vmin(min(V0, V1));
130  const scalar Vmax(max(V0, V1));
131 
132  Info<< "\nCompression ratio = " << Vmax/Vmin << endl;
133 
134  Info<< "\nEnd\n" << endl;
135 
136  return 0;
137 }
138 
139 
140 // ************************************************************************* //
static void addOption(const word &opt, const string &param="", const string &usage="")
Add to an option to validOptions with usage information.
Definition: argList.C:128
bool optionReadIfPresent(const word &opt, T &) const
Read a value from the named option if present.
Definition: argListI.H:255
A collection of cell labels.
Definition: cellSet.H:51
Named list of cell indices representing a sub-set of the mesh.
Definition: cellZone.H:61
const DimensionedField< scalar, volMesh > & V() const
Return cell volumes.
bool move()
Move the mesh.
Definition: fvMesh.C:765
const cellZoneList & cellZones() const
Return cell zones.
Definition: polyMesh.H:449
label nCells() const
A class for handling words, derived from string.
Definition: word.H:62
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
int main(int argc, char *argv[])
Definition: financialFoam.C:44
Namespace for OpenFOAM.
Type gSum(const FieldField< Field, Type > &f)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:258
messageStream Info
void mag(LagrangianPatchField< scalar > &f, const LagrangianPatchField< Type > &f1)
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
layerAndWeight min(const layerAndWeight &a, const layerAndWeight &b)
layerAndWeight max(const layerAndWeight &a, const layerAndWeight &b)
labelList identityMap(const label len)
Create identity map (map[i] == i) of given length.
Definition: ListOps.C:104
Foam::argList args(argc, argv)