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-2014 OpenFOAM Foundation
6  \\/ M anipulation |
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 
41 Foam::volScalarField& Foam::calcFvcDiv::divField
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,
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 
79 Foam::calcFvcDiv::calcFvcDiv
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_("undefined-resultName")
92 {
93  // Check if the available mesh is an fvMesh, otherwise deactivate
94  if (!isA<fvMesh>(obr_))
95  {
96  active_ = false;
97  WarningIn
98  (
99  "calcFvcDiv::calcFvcDiv"
100  "("
101  "const word&, "
102  "const objectRegistry&, "
103  "const dictionary&, "
104  "const bool"
105  ")"
106  ) << "No fvMesh available, deactivating." << nl
107  << endl;
108  }
109 
110  read(dict);
111 }
112 
113 
114 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
115 
117 {}
118 
119 
120 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
121 
123 {
124  if (active_)
125  {
126  dict.lookup("fieldName") >> fieldName_;
127  dict.lookup("resultName") >> resultName_;
128 
129  if (resultName_ == "none")
130  {
131  resultName_ = "fvc::div(" + fieldName_ + ")";
132  }
133  }
134 }
135 
136 
138 {
139  if (active_)
140  {
141  bool processed = false;
142 
143  calcDiv<surfaceScalarField>(fieldName_, resultName_, processed);
144  calcDiv<volVectorField>(fieldName_, resultName_, processed);
145 
146  if (!processed)
147  {
148  WarningIn("void Foam::calcFvcDiv::write()")
149  << "Unprocessed field " << fieldName_ << endl;
150  }
151  }
152 }
153 
154 
156 {
157  if (active_)
158  {
159  execute();
160  }
161 }
162 
163 
165 {
166  // Do nothing
167 }
168 
169 
171 {
172  if (active_)
173  {
174  if (obr_.foundObject<regIOobject>(resultName_))
175  {
176  const regIOobject& field =
177  obr_.lookupObject<regIOobject>(resultName_);
178 
179  Info<< type() << " " << name_ << " output:" << nl
180  << " writing field " << field.name() << nl << endl;
181 
182  field.write();
183  }
184  }
185 }
186 
187 
188 // ************************************************************************* //
virtual ~calcFvcDiv()
Destructor.
Definition: calcFvcDiv.C:116
A class for handling words, derived from string.
Definition: word.H:59
messageStream Info
dynamicFvMesh & mesh
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
const dimensionSet dimLength(0, 1, 0, 0, 0, 0, 0)
Definition: dimensionSets.H:50
Namespace for OpenFOAM.
virtual bool write() const
Write using setting from DB.
static const char nl
Definition: Ostream.H:260
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
virtual void timeSet()
Called when time was set at the end of the Time::operator++.
Definition: calcFvcDiv.C:164
#define WarningIn(functionName)
Report a warning using Foam::Warning.
virtual void end()
Execute at the final time-loop, currently does nothing.
Definition: calcFvcDiv.C:155
GeometricField< scalar, fvPatchField, volMesh > volScalarField
Definition: volFieldsFwd.H:52
virtual void execute()
Execute, currently does nothing.
Definition: calcFvcDiv.C:137
const word & name() const
Return name.
Definition: IOobject.H:260
fileName::Type type(const fileName &)
Return the file type: DIRECTORY or FILE.
Definition: POSIX.C:589
regIOobject is an abstract class derived from IOobject to handle automatic object registration with t...
Definition: regIOobject.H:60
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:452
virtual void read(const dictionary &)
Read the calcFvcDiv data.
Definition: calcFvcDiv.C:122
Registry of regIOobjects.
bool read(const char *, int32_t &)
Definition: int32IO.C:87
virtual void write()
Calculate the calcFvcDiv and write.
Definition: calcFvcDiv.C:170
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
defineTypeNameAndDebug(combustionModel, 0)