derivedFieldWriter.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  Copyright : (C) 2011 Symscape
3  Website : www.symscape.com
4 -------------------------------------------------------------------------------
5 License
6  This file is part of OpenFOAM.
7 
8  OpenFOAM is free software: you can redistribute it and/or modify it
9  under the terms of the GNU General Public License as published by
10  the Free Software Foundation, either version 3 of the License, or
11  (at your option) any later version.
12 
13  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
14  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16  for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
20 
21 Class
22  Foam::derivedFieldWriter
23 
24 Description
25  Basis for writers used in derivedFields e.g., wallShearStressWriter
26 
27  \*---------------------------------------------------------------------------*/
28 
29 #ifndef derivedFieldWriter_H
30 #define derivedFieldWriter_H
31 
32 #include "dictionary.H"
33 #include "entry.H"
34 #include "Switch.H"
35 #include "Pstream.H"
36 
37 
38 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
39 
40 namespace Foam
41 {
42 
43  // Forward declaration of classes
44  class objectRegistry;
45 
46  /*---------------------------------------------------------------------------*\
47  Class derivedFieldWriter Declaration
48  \*---------------------------------------------------------------------------*/
49 
50  class derivedFieldWriter
51  {
52  // Private data
53 
54  //- Produce statistics
56 
57  public:
58  // Destructor
59 
60  virtual ~derivedFieldWriter();
61 
62  // Member Functions
63 
64  //- Write derived field.
65  virtual void write(const objectRegistry& obr) = 0;
66 
67  //- Create obj if requested.
68  template<class T>
69  static T* read(const dictionary& dict)
70  {
71  const bool nonRecursive = false;
72  const bool noPatternMatch = false;
73  T* obj = 0;
74  const entry* entry =
75  dict.lookupEntryPtr(T::FIELD_NAME, nonRecursive, noPatternMatch);
76 
77  if (0 != entry)
78  {
79  obj = new T(entry->dict());
80  }
81 
82  return obj;
83  }
84 
85  protected:
86  // Constructors
87 
89 
90  //- Write min/max/average
91  template<class T_Field>
92  void writeStatistics(const T_Field& fieldp,
93  const word& patchName,
94  const word& fieldName)
95  {
96  if (statistics_ && Pstream::master())
97  {
98  Info<< "Patch: " << patchName
99  << ", Field: " << fieldName
100  << ", min: " << min(fieldp)
101  << ", max: " << max(fieldp)
102  << ", average: " << average(fieldp) << nl << endl;
103  }
104  }
105  };
106 
107  // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
108 
109 } // End namespace Foam
110 
111 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
112 
113 #endif
114 
115 // ************************************************************************* //
Foam::entry
A keyword and a list of tokens is an 'entry'.
Definition: entry.H:65
Foam::Switch
A simple wrapper around bool so that it can be read as a word: true/false, on/off,...
Definition: Switch.H:60
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::derivedFieldWriter::write
virtual void write(const objectRegistry &obr)=0
Write derived field.
Foam::derivedFieldWriter::derivedFieldWriter
derivedFieldWriter(const dictionary &dict)
Definition: derivedFieldWriter.C:28
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
entry.H
Foam::derivedFieldWriter::statistics_
Switch statistics_
Produce statistics.
Definition: derivedFieldWriter.H:54
Foam::objectRegistry
Registry of regIOobjects.
Definition: objectRegistry.H:50
Foam::derivedFieldWriter
Basis for writers used in derivedFields e.g., wallShearStressWriter.
Definition: derivedFieldWriter.H:49
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::Info
messageStream Info
Foam::T
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
Definition: FieldFieldFunctions.C:55
Switch.H
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
Pstream.H
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::entry::dict
virtual const dictionary & dict() const =0
Return dictionary if this entry is a dictionary.
Foam::derivedFieldWriter::~derivedFieldWriter
virtual ~derivedFieldWriter()
Definition: derivedFieldWriter.C:35
Foam::UPstream::master
static bool master(const label communicator=0)
Am I the master process.
Definition: UPstream.H:399
Foam::max
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
Foam::derivedFieldWriter::writeStatistics
void writeStatistics(const T_Field &fieldp, const word &patchName, const word &fieldName)
Write min/max/average.
Definition: derivedFieldWriter.H:91
dictionary.H
Foam::derivedFieldWriter::read
static T * read(const dictionary &dict)
Create obj if requested.
Definition: derivedFieldWriter.H:68
Foam::min
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
Foam::average
dimensioned< Type > average(const DimensionedField< Type, GeoMesh > &df)
Definition: DimensionedFieldFunctions.C:335