FreeFOAM The Cross-Platform CFD Toolkit
fieldValue.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) 2009-2010 OpenCFD Ltd.
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 "fieldValue.H"
27 #include <finiteVolume/fvMesh.H>
28 #include <OpenFOAM/Time.H>
29 
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 
32 namespace Foam
33 {
34  defineTypeNameAndDebug(fieldValue, 0);
35 
36  defineTemplateTypeNameAndDebug(IOList<vector>, 0);
37  defineTemplateTypeNameAndDebug(IOList<sphericalTensor>, 0);
38  defineTemplateTypeNameAndDebug(IOList<symmTensor>, 0);
39  defineTemplateTypeNameAndDebug(IOList<tensor>, 0);
40 }
41 
42 
43 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
44 
46 {
47  // Do nothing
48 }
49 
50 
52 {
53  // Do nothing
54 }
55 
56 
58 {
59  // Create the forces file if not already created
60  if (outputFilePtr_.empty())
61  {
62  if (debug)
63  {
64  Info<< "Creating output file." << endl;
65  }
66 
67  // File update
68  if (Pstream::master())
69  {
70  fileName outputDir;
71  word startTimeName =
72  obr_.time().timeName(obr_.time().startTime().value());
73 
74  if (Pstream::parRun())
75  {
76  // Put in undecomposed case (Note: gives problems for
77  // distributed data running)
78  outputDir =
79  obr_.time().path()/".."/name_/startTimeName;
80  }
81  else
82  {
83  outputDir = obr_.time().path()/name_/startTimeName;
84  }
85 
86  // Create directory if does not exist
87  mkDir(outputDir);
88 
89  // Open new file at start up
90  outputFilePtr_.reset(new OFstream(outputDir/(type() + ".dat")));
91 
92  // Add headers to output data
93  writeFileHeader();
94  }
95  }
96 }
97 
98 
100 {
101  if (active_)
102  {
103  log_ = dict.lookupOrDefault<Switch>("log", false);
104  dict.lookup("fields") >> fields_;
105  dict.lookup("valueOutput") >> valueOutput_;
106  }
107 }
108 
109 
111 {
112  if (active_)
113  {
114  if (log_)
115  {
116  Info<< type() << " " << name_ << " output:" << nl;
117  }
118 
119  makeFile();
120  }
121 }
122 
123 
124 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
125 
127 (
128  const word& name,
129  const objectRegistry& obr,
130  const dictionary& dict,
131  const bool loadFromFiles
132 )
133 :
134  name_(name),
135  obr_(obr),
136  active_(true),
137  log_(false),
138  sourceName_(dict.lookup("sourceName")),
139  fields_(dict.lookup("fields")),
140  valueOutput_(dict.lookup("valueOutput")),
141  outputFilePtr_(NULL)
142 {
143  // Only active if obr is an fvMesh
144  if (isA<fvMesh>(obr_))
145  {
146  read(dict);
147  }
148  else
149  {
150  WarningIn
151  (
152  "fieldValue::fieldValue"
153  "("
154  "const word&, "
155  "const objectRegistry&, "
156  "const dictionary&, "
157  "const bool"
158  ")"
159  ) << "No fvMesh available, deactivating."
160  << nl << endl;
161  active_ = false;
162  }
163 }
164 
165 
166 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
167 
169 {}
170 
171 
172 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
173 
175 {
176  // Do nothing
177 }
178 
179 
181 {
182  // Do nothing
183 }
184 
185 
186 // ************************ vim: set sw=4 sts=4 et: ************************ //