reference.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) 2018 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "reference.H"
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35 namespace functionObjects
36 {
37  defineTypeNameAndDebug(reference, 0);
38 
40  (
41  functionObject,
42  reference,
43  dictionary
44  );
45 }
46 }
47 
48 
49 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
50 
51 bool Foam::functionObjects::reference::calc()
52 {
53  Log << type() << " " << name() << " output:" << nl;
54 
55  bool processed = calcType<scalar>();
56  processed = processed || calcType<vector>();
57  processed = processed || calcType<sphericalTensor>();
58  processed = processed || calcType<symmTensor>();
59  processed = processed || calcType<tensor>();
60 
61  Log << endl;
62 
63 
64  return returnReduce(processed, orOp<bool>());
65 }
66 
67 
68 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
69 
71 (
72  const word& name,
73  const Time& runTime,
74  const dictionary& dict
75 )
76 :
78  localDict_(dict),
79  position_(Zero),
80  positionIsSet_(false),
81  celli_(-1),
82  interpolationScheme_("cell"),
83  scale_(1)
84 {
85  read(dict);
86 
87  // Forcing default result name to include the name of the field
88  setResultName(typeName, word::null);
89 }
90 
91 
92 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
93 
95 {}
96 
97 
99 {
101  {
102  localDict_ = dict;
103 
104  Log << type() << " " << name() << nl
105  << " field: " << fieldName_ << nl;
106 
107  if (dict.readIfPresent("scale", scale_))
108  {
109  Log << " scale: " << scale_ << nl;
110  }
111 
112  if (dict.readIfPresent("position", position_))
113  {
114  Log << " sample position: " << position_ << nl;
115 
116  positionIsSet_ = true;
117 
118  celli_ = mesh_.findCell(position_);
119 
120  label celli = returnReduce(celli_, maxOp<label>());
121 
122  if (celli == -1)
123  {
125  << "Sample cell could not be found at position "
126  << position_ << exit(FatalIOError);
127  }
128 
129  interpolationScheme_ =
130  dict.lookupOrDefault<word>("interpolationScheme", "cell");
131  }
132 
133  Log << endl;
134 
135  return true;
136  }
137 
138  return false;
139 }
140 
141 
142 // ************************************************************************* //
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Foam::maxOp
Definition: ops.H:223
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::returnReduce
T returnReduce(const T &Value, const BinaryOp &bop, const int tag=Pstream::msgType(), const label comm=UPstream::worldComm)
Definition: PstreamReduceOps.H:94
Foam::functionObjects::reference::reference
reference(const word &name, const Time &runTime, const dictionary &dict)
Construct from Time and dictionary.
Definition: reference.C:71
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::FatalIOError
IOerror FatalIOError
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::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::functionObjects::reference::~reference
virtual ~reference()
Destructor.
Definition: reference.C:94
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:121
reference.H
addToRunTimeSelectionTable.H
Macros for easy insertion into run-time selection tables.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::functionObjects::defineTypeNameAndDebug
defineTypeNameAndDebug(fvMeshFunctionObject, 0)
Foam::functionObjects::fieldExpression
Base class for field expression function objects.
Definition: fieldExpression.H:60
Foam::nl
constexpr char nl
Definition: Ostream.H:372
Foam::functionObject::name
const word & name() const
Return the name of this functionObject.
Definition: functionObject.C:131
Foam::functionObject::type
virtual const word & type() const =0
Runtime type information.
Foam::type
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: MSwindows.C:590
Foam::word::null
static const word null
An empty word.
Definition: word.H:77
FatalIOErrorInFunction
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:375
Foam::functionObjects::reference::read
virtual bool read(const dictionary &dict)
Read the fieldExpression data.
Definition: reference.C:98
Log
#define Log
Report write to Foam::Info if the local log switch is true.
Definition: messageStream.H:332