calcMag.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 "calcMag.H"
27 #include "volFields.H"
28 #include "dictionary.H"
29 #include "calcMag.H"
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35  defineTypeNameAndDebug(calcMag, 0);
36 }
37 
38 
39 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
40 
42 (
43  const word& name,
44  const objectRegistry& obr,
45  const dictionary& dict,
46  const bool loadFromFiles
47 )
48 :
49  name_(name),
50  obr_(obr),
51  active_(true),
52  fieldName_("undefined-fieldName"),
53  resultName_(word::null),
54  log_(true)
55 {
56  // Check if the available mesh is an fvMesh, otherwise deactivate
57  if (!isA<fvMesh>(obr_))
58  {
59  active_ = false;
61  << "No fvMesh available, deactivating." << nl
62  << endl;
63  }
64 
65  read(dict);
66 }
67 
68 
69 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
70 
72 {}
73 
74 
75 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
76 
78 {
79  if (active_)
80  {
81  log_.readIfPresent("log", dict);
82 
83  dict.lookup("fieldName") >> fieldName_;
84  dict.readIfPresent("resultName", resultName_);
85 
86  if (resultName_ == word::null)
87  {
88  resultName_ = "mag(" + fieldName_ + ")";
89  }
90  }
91 }
92 
93 
95 {
96  if (active_)
97  {
98  bool processed = false;
99 
100  calc<scalar>(fieldName_, resultName_, processed);
101  calc<vector>(fieldName_, resultName_, processed);
102  calc<sphericalTensor>(fieldName_, resultName_, processed);
103  calc<symmTensor>(fieldName_, resultName_, processed);
104  calc<tensor>(fieldName_, resultName_, processed);
105 
106  if (!processed)
107  {
109  << "Unprocessed field " << fieldName_ << endl;
110  }
111  }
112 }
113 
114 
116 {
117  // Do nothing
118 }
119 
120 
122 {
123  // Do nothing
124 }
125 
126 
128 {
129  if (active_)
130  {
131  if (obr_.foundObject<regIOobject>(resultName_))
132  {
133  const regIOobject& field =
134  obr_.lookupObject<regIOobject>(resultName_);
135 
136  if (log_) Info
137  << type() << " " << name_ << " output:" << nl
138  << " writing field " << field.name() << nl << endl;
139 
140  field.write();
141  }
142  }
143 }
144 
145 
146 // ************************************************************************* //
volFields.H
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
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::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::regIOobject::write
virtual bool write() const
Write using setting from DB.
Definition: regIOobjectWrite.C:126
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:50
Foam::calcMag::end
virtual void end()
Execute at the final time-loop, currently does nothing.
Definition: calcMag.C:115
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::Info
messageStream Info
Foam::calcMag::write
virtual void write()
Calculate the calcMag and write.
Definition: calcMag.C:127
Foam::IOobject::name
const word & name() const
Return name.
Definition: IOobject.H:273
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::dictionary
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:137
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::regIOobject
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:60
Foam::calcMag::read
virtual void read(const dictionary &)
Read the calcMag data.
Definition: calcMag.C:77
dictionary.H
Foam::word::null
static const word null
An empty word.
Definition: word.H:77
Foam::calcMag::timeSet
virtual void timeSet()
Called when time was set at the end of the Time::operator++.
Definition: calcMag.C:121
Foam::calcMag::calcMag
calcMag(const calcMag &)
Disallow default bitwise copy construct.
Foam::calcMag::~calcMag
virtual ~calcMag()
Destructor.
Definition: calcMag.C:71
calcMag.H
Foam::type
fileName::Type type(const fileName &)
Return the file type: DIRECTORY or FILE.
Definition: POSIX.C:588
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:259
Foam::name
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
Foam::calcMag::execute
virtual void execute()
Execute, currently does nothing.
Definition: calcMag.C:94