blendingFactor.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 | Copyright (C) 2013-2015 OpenFOAM Foundation
6  \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
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 "blendingFactor.H"
27 #include "dictionary.H"
28 
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
30 
31 namespace Foam
32 {
33  defineTypeNameAndDebug(blendingFactor, 0);
34 }
35 
36 
37 // * * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * //
38 
40 {
41  writeHeader(os, "Blending factor");
42  writeCommented(os, "Time");
43  writeTabbed(os, "Scheme1");
44  writeTabbed(os, "Scheme2");
45  writeTabbed(os, "Blended");
46  os << endl;
47 }
48 
49 
50 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
51 
53 (
54  const word& name,
55  const objectRegistry& obr,
56  const dictionary& dict,
57  const bool loadFromFiles
58 )
59 :
61  functionObjectFile(obr, name, typeName, dict),
62  name_(name),
63  obr_(obr),
64  phiName_("phi"),
65  fieldName_("unknown-fieldName"),
66  resultName_(word::null),
67  tolerance_(0.001),
68  log_(true)
69 {
70  // Check if the available mesh is an fvMesh, otherwise deactivate
71  if (setActive<fvMesh>())
72  {
73  read(dict);
74  writeFileHeader(file());
75 
76  const fvMesh& mesh = refCast<const fvMesh>(obr_);
77 
78  volScalarField* indicatorPtr
79  (
80  new volScalarField
81  (
82  IOobject
83  (
84  resultName_,
85  mesh.time().timeName(),
86  mesh,
89  ),
90  mesh,
91  dimensionedScalar("0", dimless, 0.0),
92  zeroGradientFvPatchScalarField::typeName
93  )
94  );
95 
96  mesh.objectRegistry::store(indicatorPtr);
97  }
98 }
99 
100 
101 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
102 
104 {}
105 
106 
107 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
108 
110 {
111  if (active_)
112  {
114 
115  log_.readIfPresent("log", dict);
116 
117  dict.readIfPresent("phiName", phiName_);
118  dict.lookup("fieldName") >> fieldName_;
119 
120 
121  if (!dict.readIfPresent("resultName", resultName_))
122  {
123  resultName_ = name_ + ':' + fieldName_;
124  }
125 
126  dict.readIfPresent("tolerance", tolerance_);
127  if ((tolerance_ < 0) || (tolerance_ > 1))
128  {
130  << "tolerance must be in the range 0 to 1. Supplied value: "
131  << tolerance_ << exit(FatalError);
132  }
133  }
134 }
135 
136 
138 {
139  if (active_)
140  {
141  calc<scalar>();
142  calc<vector>();
143  }
144 }
145 
146 
148 {
149  // Do nothing
150 }
151 
152 
154 {
155  // Do nothing
156 }
157 
158 
160 {
161  if (active_)
162  {
163  const volScalarField& indicator =
164  obr_.lookupObject<volScalarField>(resultName_);
165 
166  if (log_) Info
167  << type() << " " << name_ << " output:" << nl
168  << " writing field " << indicator.name() << nl
169  << endl;
170 
171  indicator.write();
172  }
173 }
174 
175 
176 // ************************************************************************* //
Foam::blendingFactor::timeSet
virtual void timeSet()
Called when time was set at the end of the Time::operator++.
Definition: blendingFactor.C:153
Foam::IOobject
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
Foam::dimless
const dimensionSet dimless(0, 0, 0, 0, 0, 0, 0)
Definition: dimensionSets.H:47
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::functionObjectState
Base class for function objects, adding functionality to read/write state information (data required ...
Definition: functionObjectState.H:54
Foam::dictionary::readIfPresent
bool readIfPresent(const word &, T &, bool recursive=false, bool patternMatch=true) const
Find an entry if present, and assign to T.
Definition: dictionaryTemplates.C:94
Foam::read
bool read(const char *, int32_t &)
Definition: int32IO.C:87
Foam::blendingFactor::write
virtual void write()
Calculate the blendingFactor and write.
Definition: blendingFactor.C:159
Foam::functionObjectFile::writeTabbed
void writeTabbed(Ostream &os, const string &str) const
Write a tabbed string to stream.
Definition: functionObjectFile.C:230
Foam::dictionary::lookup
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:449
Foam::functionObjectFile::read
void read(const dictionary &dict)
Read.
Definition: functionObjectFile.C:178
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::IOobject::NO_WRITE
@ NO_WRITE
Definition: IOobject.H:118
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:50
Foam::IOobject::NO_READ
@ NO_READ
Definition: IOobject.H:111
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::Info
messageStream Info
Foam::blendingFactor::blendingFactor
blendingFactor(const blendingFactor &)
Disallow default bitwise copy construct.
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
Foam::functionObjectFile::writeHeader
void writeHeader(Ostream &os, const string &str) const
Write a commented header to stream.
Definition: functionObjectFile.C:240
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
Foam::dimensioned
Generic dimensioned Type class.
Definition: dimensionedScalarFwd.H:41
Foam::blendingFactor::read
virtual void read(const dictionary &)
Read the blendingFactor data.
Definition: blendingFactor.C:109
Foam::blendingFactor::end
virtual void end()
Execute at the final time-loop, currently does nothing.
Definition: blendingFactor.C:147
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:318
Foam::blendingFactor::~blendingFactor
virtual ~blendingFactor()
Destructor.
Definition: blendingFactor.C:103
Foam::Time::timeName
static word timeName(const scalar, const int precision=precision_)
Return time name of given scalar time.
Definition: Time.C:741
Foam::blendingFactor::execute
virtual void execute()
Execute, currently does nothing.
Definition: blendingFactor.C:137
Foam::functionObjectFile
Base class for output file data handling.
Definition: functionObjectFile.H:57
dictionary.H
Foam::word::null
static const word null
An empty word.
Definition: word.H:77
Foam::fvMesh::time
const Time & time() const
Return the top-level database.
Definition: fvMesh.H:243
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:53
Foam::type
fileName::Type type(const fileName &)
Return the file type: DIRECTORY or FILE.
Definition: POSIX.C:588
Foam::GeometricField
Generic GeometricField class.
Definition: surfaceFieldsFwd.H:52
Foam::blendingFactor::writeFileHeader
virtual void writeFileHeader(Ostream &os) const
Write the file header.
Definition: blendingFactor.C:39
Foam::functionObjectFile::writeCommented
void writeCommented(Ostream &os, const string &str) const
Write a commented string to stream.
Definition: functionObjectFile.C:219
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::name
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
blendingFactor.H