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 "addRegionOption.H"
55 
57  (
58  "cellSet",
59  "name",
60  "Calculate the volume of the specified cellSet"
61  );
62 
64  (
65  "cellZone",
66  "name",
67  "Calculate the volume of the specified cellZone"
68  );
69 
70  #include "setRootCase.H"
71  #include "createTime.H"
72  #include "createRegionMesh.H"
73 
74  // Cell labels of the cells in the combustion chamber
75  // Defaults to all cells
76  labelList ccCells(identityMap(mesh.nCells()));
77 
78  word cellSetName;
79  word cellZoneName;
80  if (args.optionReadIfPresent("cellSet", cellSetName))
81  {
82  // Read the cellSet for the combustion chamber
83  const cellSet ccCellSet(mesh, cellSetName);
84  ccCells = ccCellSet.toc();
85  }
86  else if (args.optionReadIfPresent("cellZone", cellZoneName))
87  {
88  const cellZone& ccCellZone = mesh.cellZones()[cellZoneName];
89  ccCells = ccCellZone;
90  }
91 
92  // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
93 
94  const scalar eps = 1.0e-10;
95 
96  // Search for the CA >= the current CA which is divisible by 180
97  int ca0 = -360;
98  while (runTime.userTimeValue() > ca0)
99  {
100  ca0 += 180;
101  }
102  int ca1 = ca0 + 180;
103 
104  if (mag(runTime.userTimeValue() - ca0) > eps)
105  {
106  const scalar t0 = runTime.userTimeToTime(ca0 - runTime.userTimeValue());
107  runTime.setDeltaT(t0);
108  runTime++;
109  Info<< "Moving to CA = " << runTime.userTimeValue() << endl;
110  mesh.move();
111  }
112 
113  const scalar V0 = gSum(scalarField(mesh.V(), ccCells));
114  Info << "Volume at " << runTime.userTimeValue() << "CA = " << V0 << endl;
115 
116  if (mag(runTime.userTimeValue()-ca1) > eps)
117  {
118  const scalar t1 = runTime.userTimeToTime(ca1 - runTime.userTimeValue());
119  runTime.setDeltaT(t1);
120  runTime++;
121  Info<< "Moving to CA = " << runTime.userTimeValue() << endl;
122  mesh.move();
123  }
124 
125  const scalar V1 = gSum(scalarField(mesh.V(), ccCells));
126  Info << "Volume at " << runTime.userTimeValue() << "CA = " << V1 << endl;
127 
128  const scalar Vmin(min(V0, V1));
129  const scalar Vmax(max(V0, V1));
130 
131  Info<< "\nCompression ratio = " << Vmax/Vmin << endl;
132 
133  Info<< "\nEnd\n" << endl;
134 
135  return 0;
136 }
137 
138 
139 // ************************************************************************* //
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:204
A collection of cell labels.
Definition: cellSet.H:51
A subset of mesh cells.
Definition: cellZone.H:58
A class for handling words, derived from string.
Definition: word.H:62
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:257
messageStream Info
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
layerAndWeight min(const layerAndWeight &a, const layerAndWeight &b)
dimensioned< scalar > mag(const dimensioned< Type > &)
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)