calcFvcDiv.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 "calcFvcDiv.H"
27 #include "volFields.H"
28 #include "dictionary.H"
29 #include "calcFvcDiv.H"
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35  defineTypeNameAndDebug(calcFvcDiv, 0);
36 }
37 
38 
39 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
40 
42 (
43  const word& divName,
44  const dimensionSet& dims
45 )
46 {
47  const fvMesh& mesh = refCast<const fvMesh>(obr_);
48 
49  if (!mesh.foundObject<volScalarField>(divName))
50  {
51  volScalarField* divFieldPtr
52  (
53  new volScalarField
54  (
55  IOobject
56  (
57  divName,
58  mesh.time().timeName(),
59  mesh,
60  IOobject::NO_READ,
61  IOobject::NO_WRITE
62  ),
63  mesh,
64  dimensionedScalar("zero", dims/dimLength, 0.0)
65  )
66  );
67 
68  mesh.objectRegistry::store(divFieldPtr);
69  }
70 
71  const volScalarField& field = mesh.lookupObject<volScalarField>(divName);
72 
73  return const_cast<volScalarField&>(field);
74 }
75 
76 
77 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
78 
80 (
81  const word& name,
82  const objectRegistry& obr,
83  const dictionary& dict,
84  const bool loadFromFiles
85 )
86 :
87  name_(name),
88  obr_(obr),
89  active_(true),
90  fieldName_("undefined-fieldName"),
91  resultName_(word::null),
92  log_(true)
93 {
94  // Check if the available mesh is an fvMesh, otherwise deactivate
95  if (!isA<fvMesh>(obr_))
96  {
97  active_ = false;
99  << "No fvMesh available, deactivating." << nl
100  << endl;
101  }
102 
103  read(dict);
104 }
105 
106 
107 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
108 
110 {}
111 
112 
113 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
114 
116 {
117  if (active_)
118  {
119  log_.readIfPresent("log", dict);
120 
121  dict.lookup("fieldName") >> fieldName_;
122  dict.readIfPresent("resultName", resultName_);
123 
124  if (resultName_ == word::null)
125  {
126  resultName_ = "fvc::div(" + fieldName_ + ")";
127  }
128  }
129 }
130 
131 
133 {
134  if (active_)
135  {
136  bool processed = false;
137 
138  calcDiv<surfaceScalarField>(fieldName_, resultName_, processed);
139  calcDiv<volVectorField>(fieldName_, resultName_, processed);
140 
141  if (!processed)
142  {
144  << "Unprocessed field " << fieldName_ << endl;
145  }
146  }
147 }
148 
149 
151 {
152  // Do nothing
153 }
154 
155 
157 {
158  // Do nothing
159 }
160 
161 
163 {
164  if (active_)
165  {
166  if (obr_.foundObject<regIOobject>(resultName_))
167  {
168  const regIOobject& field =
169  obr_.lookupObject<regIOobject>(resultName_);
170 
171  if (log_) Info
172  << type() << " " << name_ << " output:" << nl
173  << " writing field " << field.name() << nl << endl;
174 
175  field.write();
176  }
177  }
178 }
179 
180 
181 // ************************************************************************* //
volFields.H
Foam::IOobject
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::dimLength
const dimensionSet dimLength(0, 1, 0, 0, 0, 0, 0)
Definition: dimensionSets.H:50
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::dimensionSet
Dimension set for the base types.
Definition: dimensionSet.H:116
Foam::calcFvcDiv::end
virtual void end()
Execute at the final time-loop, currently does nothing.
Definition: calcFvcDiv.C:150
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:50
Foam::calcFvcDiv::calcFvcDiv
calcFvcDiv(const calcFvcDiv &)
Disallow default bitwise copy construct.
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::Info
messageStream Info
Foam::calcFvcDiv::write
virtual void write()
Calculate the calcFvcDiv and write.
Definition: calcFvcDiv.C:162
Foam::IOobject::name
const word & name() const
Return name.
Definition: IOobject.H:273
Foam::calcFvcDiv::timeSet
virtual void timeSet()
Called when time was set at the end of the Time::operator++.
Definition: calcFvcDiv.C:156
Foam::calcFvcDiv::divField
volScalarField & divField(const word &gradName, const dimensionSet &dims)
Helper function to create/store/return the divergence field.
Definition: calcFvcDiv.C:42
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
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:18
Foam::dimensioned
Generic dimensioned Type class.
Definition: dimensionedScalarFwd.H:41
Foam::fvMesh
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:78
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
dictionary.H
Foam::calcFvcDiv::execute
virtual void execute()
Execute, currently does nothing.
Definition: calcFvcDiv.C:132
Foam::word::null
static const word null
An empty word.
Definition: word.H:77
calcFvcDiv.H
Foam::calcFvcDiv::~calcFvcDiv
virtual ~calcFvcDiv()
Destructor.
Definition: calcFvcDiv.C:109
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::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::calcFvcDiv::read
virtual void read(const dictionary &)
Read the calcFvcDiv data.
Definition: calcFvcDiv.C:115