multiValveEngineState.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 \*---------------------------------------------------------------------------*/
25 
26 #include "multiValveEngineState.H"
28 
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
30 
31 namespace Foam
32 {
33 namespace functionObjects
34 {
36 
38  (
42  );
43 }
44 }
45 
46 
47 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
48 
50 Foam::functionObjects::multiValveEngineState::mve() const
51 {
52  return refCast<const fvMeshMovers::multiValveEngine>(mesh_.mover());
53 }
54 
55 
56 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
57 
59 (
60  const word& name,
61  const Time& runTime,
62  const dictionary& dict
63 )
64 :
65  fvMeshFunctionObject(name, runTime, dict),
66  logFiles(obr_, name)
67 {
68  read(dict);
69 }
70 
71 
72 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
73 
75 {}
76 
77 
78 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
79 
81 {
83 
84  resetName(typeName);
85 
86  return true;
87 }
88 
89 
91 (
92  const label i
93 )
94 {
95  writeHeader(file(), "Engine Motion State");
96  writeCommented(file(), "Time");
97  writeTabbed(file(), "piston from TDC");
98  writeTabbed(file(), "piston speed");
99  writeTabbed(file(), "piston displacement");
100  writeTabbed(file(), "piston clearance");
101 
102  const fvMeshMovers::multiValveEngine& mve = this->mve();
104 
105  forAll(valves, valvei)
106  {
108  valves[valvei];
109 
110  writeTabbed(file(), valve.name + " lift");
111  writeTabbed(file(), valve.name + " speed");
112  writeTabbed(file(), valve.name + " displacement");
113  }
114 
115  file() << endl;
116 }
117 
118 
120 {
121  return true;
122 }
123 
124 
126 {
127  logFiles::write();
128 
129  if (Pstream::master())
130  {
131  const fvMeshMovers::multiValveEngine& mve = this->mve();
132 
134 
135  Log << "Piston: " << nl
136  << " position from TDC: " << piston.position() << " m" << nl
137  << " speed = " << piston.speed() << " m/s" << nl
138  << " displacement: " << piston.displacement() << " m" << nl
139  << " clearance: " << piston.clearance() << " m" << endl;
140 
141  writeTime(file());
142  file()
143  << tab
144  << piston.position() << tab
145  << piston.speed() << tab
146  << piston.displacement() << tab
147  << piston.clearance();
148 
149 
151 
152  forAll(valves, valvei)
153  {
155  valves[valvei];
156 
157  Log << "Valve " << valve.name << nl
158  << " lift: " << (valve.isOpen() ? valve.lift() : 0)
159  << " m "
160  << (valve.isOpen() ? "(open)" : "(closed)") << nl
161  << " speed: " << valve.speed() << " m/s" << nl
162  << " displacement: " << valve.displacement() << " m" << endl;
163 
164  file()
165  << tab
166  << (valve.isOpen() ? valve.lift() : 0) << tab
167  << valve.speed() << tab
168  << valve.displacement();
169  }
170 
171  file() << endl;
172  Log << endl;
173  }
174 
175  return true;
176 }
177 
178 
179 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
Macros for easy insertion into run-time selection tables.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:76
static bool master(const label communicator=0)
Am I the master process.
Definition: UPstream.H:423
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:162
Abstract base-class for Time/database functionObjects.
Specialisation of Foam::functionObject for an Foam::fvMesh, providing a reference to the Foam::fvMesh...
const fvMesh & mesh_
Reference to the fvMesh.
functionObject base class for creating, maintaining and writing log files e.g. integrated of averaged...
Definition: logFiles.H:60
virtual bool write()
Write function.
Definition: logFiles.C:173
Writes the multi-valve engine motion state.
multiValveEngineState(const word &name, const Time &runTime, const dictionary &dict)
Construct from Time and dictionary.
virtual void writeFileHeader(const label i)
File header information.
virtual bool execute()
Execute, currently does nothing.
virtual bool write()
Write the multiValveEngineState.
virtual bool read(const dictionary &)
Read the multiValveEngineState data.
virtual bool read(const dictionary &)
Read optional controls.
scalar clearance() const
Return clearance estimate.
Definition: piston.C:141
scalar displacement() const
Return piston displacement for current time-step.
Definition: piston.C:126
scalar position(const scalar theta) const
Return the piston position for the given CA theta.
Definition: piston.C:110
scalar speed() const
Return piston position for current time-step.
Definition: piston.C:134
bool isOpen() const
Is the valve open?
Definition: valve.C:54
scalar lift(const scalar theta) const
Return valve position for the given time.
Definition: valve.C:46
scalar displacement() const
Return valve displacement for current time-step.
Definition: valve.C:85
scalar speed() const
Return current valve speed.
Definition: valve.C:70
A mesh mover using explicit node translation based on scaled distance functions per moving object....
const valveList & valves
Container for all valves.
const pistonObject & piston
Piston object.
const fvMeshMover & mover() const
Return the mover function class.
Definition: fvMesh.C:1050
A class for handling words, derived from string.
Definition: word.H:62
#define Log
Report write to Foam::Info if the local log switch is true.
defineTypeNameAndDebug(adjustTimeStepToCombustion, 0)
addToRunTimeSelectionTable(functionObject, adjustTimeStepToCombustion, dictionary)
void writeHeader(std::ostream &, const bool isBinary, const std::string &title)
Write header.
Namespace for OpenFOAM.
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
word name(const bool)
Return a word representation of a bool.
Definition: boolIO.C:39
static const char tab
Definition: Ostream.H:265
static const char nl
Definition: Ostream.H:266
dictionary dict