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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2013-2016 OpenFOAM Foundation
9  Copyright (C) 2015-2019 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
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 "blendingFactor.H"
32 
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
37 namespace functionObjects
38 {
39  defineTypeNameAndDebug(blendingFactor, 0);
40  addToRunTimeSelectionTable(functionObject, blendingFactor, dictionary);
41 }
42 }
43 
44 
45 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
46 
48 {
49  writeHeader(os, "Blending factor");
50  writeCommented(os, "Time");
51  writeTabbed(os, "Scheme1");
52  writeTabbed(os, "Scheme2");
53  writeTabbed(os, "Blended");
54  os << endl;
55 }
56 
57 
58 bool Foam::functionObjects::blendingFactor::calc()
59 {
60  bool processed = false;
61 
62  processed = processed || calcScheme<scalar>();
63  processed = processed || calcScheme<vector>();
64 
65  return processed;
66 }
67 
68 
69 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
70 
72 (
73  const word& name,
74  const Time& runTime,
75  const dictionary& dict
76 )
77 :
79  writeFile(obr_, name, typeName, dict),
80  phiName_("phi"),
81  tolerance_(0.001)
82 {
83  read(dict);
84  writeFileHeader(file());
85  setResultName(typeName, "");
86 
87  auto indicatorPtr = tmp<volScalarField>::New
88  (
89  IOobject
90  (
91  resultName_,
92  time_.timeName(),
93  mesh_,
96  ),
97  mesh_,
99  zeroGradientFvPatchScalarField::typeName
100  );
101 
102  store(resultName_, indicatorPtr);
103 }
104 
105 
106 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
107 
109 {}
110 
111 
112 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
113 
115 {
117  {
118  phiName_ = dict.lookupOrDefault<word>("phi", "phi");
119 
120  tolerance_ = 0.001;
121  if
122  (
123  dict.readIfPresent("tolerance", tolerance_)
124  && (tolerance_ < 0 || tolerance_ > 1)
125  )
126  {
128  << "tolerance must be in the range 0 to 1. Supplied value: "
129  << tolerance_ << exit(FatalError);
130  }
131 
132  return true;
133  }
134 
135  return false;
136 }
137 
138 
140 {
142  {
143  const volScalarField& indicator =
144  lookupObject<volScalarField>(resultName_);
145 
146  // Generate scheme statistics
147  label nCellsScheme1 = 0;
148  label nCellsScheme2 = 0;
149  label nCellsBlended = 0;
150  forAll(indicator, celli)
151  {
152  scalar i = indicator[celli];
153 
154  if (i < tolerance_)
155  {
156  nCellsScheme1++;
157  }
158  else if (i > (1 - tolerance_))
159  {
160  nCellsScheme2++;
161  }
162  else
163  {
164  nCellsBlended++;
165  }
166  }
167 
168  reduce(nCellsScheme1, sumOp<label>());
169  reduce(nCellsScheme2, sumOp<label>());
170  reduce(nCellsBlended, sumOp<label>());
171 
172  Log << " scheme 1 cells : " << nCellsScheme1 << nl
173  << " scheme 2 cells : " << nCellsScheme2 << nl
174  << " blended cells : " << nCellsBlended << nl
175  << endl;
176 
177  writeCurrentTime(file());
178 
179  file()
180  << token::TAB << nCellsScheme1
181  << token::TAB << nCellsScheme2
182  << token::TAB << nCellsBlended
183  << endl;
184  }
185 
186  return true;
187 }
188 
189 
190 // ************************************************************************* //
Foam::IOobject::NO_WRITE
Definition: IOobject.H:130
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Foam::IOobject
Defines the attributes of an object for which implicit objectRegistry management is supported,...
Definition: IOobject.H:104
Foam::dimless
const dimensionSet dimless(0, 0, 0, 0, 0, 0, 0)
Dimensionless.
Definition: dimensionSets.H:50
Foam::Time
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
Definition: Time.H:73
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::Zero
static constexpr const zero Zero
Global zero.
Definition: zero.H:128
Foam::read
bool read(const char *buf, int32_t &val)
Same as readInt32.
Definition: int32.H:108
Foam::functionObjects::blendingFactor::blendingFactor
blendingFactor(const word &name, const Time &runTime, const dictionary &dict)
Construct from Time and dictionary.
Definition: blendingFactor.C:72
Foam::functionObjects::fieldExpression::read
virtual bool read(const dictionary &dict)
Read the fieldExpression data.
Definition: fieldExpression.C:91
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:337
Foam::functionObjects::addToRunTimeSelectionTable
addToRunTimeSelectionTable(functionObject, add, dictionary)
Foam::sumOp
Definition: ops.H:213
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:290
Foam::functionObjects::blendingFactor::write
virtual bool write()
Write the blendingFactor.
Definition: blendingFactor.C:139
Foam::functionObjects::writeFile::writeHeader
virtual void writeHeader(Ostream &os, const string &str) const
Write a commented header to stream.
Definition: writeFile.C:284
Foam::functionObjects::writeFile::read
virtual bool read(const dictionary &dict)
Read.
Definition: writeFile.C:212
Foam::reduce
void reduce(const List< UPstream::commsStruct > &comms, T &Value, const BinaryOp &bop, const int tag, const label comm)
Definition: PstreamReduceOps.H:51
Foam::label
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:62
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
Foam::dimensionedScalar
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
Definition: dimensionedScalarFwd.H:43
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam::functionObjects::blendingFactor::writeFileHeader
virtual void writeFileHeader(Ostream &os) const
Write the file header.
Definition: blendingFactor.C:47
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::functionObjects::blendingFactor::read
virtual bool read(const dictionary &)
Read the blendingFactor data.
Definition: blendingFactor.C:114
Foam::functionObjects::blendingFactor::~blendingFactor
virtual ~blendingFactor()
Destructor.
Definition: blendingFactor.C:108
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::functionObjects::defineTypeNameAndDebug
defineTypeNameAndDebug(fvMeshFunctionObject, 0)
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:355
Foam::functionObjects::writeFile::writeCommented
virtual void writeCommented(Ostream &os, const string &str) const
Write a commented string to stream.
Definition: writeFile.C:258
Foam::functionObjects::fieldExpression
Base class for field expression function objects.
Definition: fieldExpression.H:60
Foam::nl
constexpr char nl
Definition: Ostream.H:372
Foam::token::TAB
Tab [isspace].
Definition: token.H:113
Foam::tmp::New
static tmp< T > New(Args &&... args)
Construct tmp of T with forwarding arguments.
Foam::functionObjects::writeFile
functionObject base class for writing single files
Definition: writeFile.H:59
Foam::functionObjects::fieldExpression::write
virtual bool write()
Write the result field.
Definition: fieldExpression.C:124
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
Foam::GeometricField< scalar, fvPatchField, volMesh >
Foam::IOobject::NO_READ
Definition: IOobject.H:123
zeroGradientFvPatchFields.H
Foam::functionObjects::writeFile::writeTabbed
virtual void writeTabbed(Ostream &os, const string &str) const
Write a tabbed string to stream.
Definition: writeFile.C:274
Log
#define Log
Report write to Foam::Info if the local log switch is true.
Definition: messageStream.H:332
blendingFactor.H