Added new fieldValues function object
[OpenFOAM-1.6.x.git] / src / postProcessing / functionObjects / field / fieldValues / cellSource / cellSource.H
blob89cc9ad0103807883d0d8ab396f19c2c81b4fc79
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2009-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     option) any later version.
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.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 Class
26     Foam::fieldValues::cellSource
28 Description
29     Cell source variant of field value function object. Values of user-
30     specified fields reported for collections of cells.
32     cellObj1                        // Name also used to identify output folder
33     {
34         type            cellSource;
35         functionObjectLibs ("libfieldValueFunctionObjects.so");
36         enabled         true;
37         outputControl   outputTime;
38         log             true;       // log to screen?
39         valueOutput     true;       // Write values at run-time output times?
40         source          cellZone;   // Type of cell source
41         sourceName      c0;
42         operation       volAverage; // none, sum, volAverage, volIntegrate
43         fields
44         (
45             p
46             U
47         );
48     }
50 SourceFiles
51     cellSource.C
53 \*---------------------------------------------------------------------------*/
55 #ifndef cellSource_H
56 #define cellSource_H
58 #include "NamedEnum.H"
59 #include "fieldValue.H"
60 #include "labelList.H"
61 #include "volFieldsFwd.H"
63 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
65 namespace Foam
67 namespace fieldValues
70 /*---------------------------------------------------------------------------*\
71                          Class cellSource Declaration
72 \*---------------------------------------------------------------------------*/
74 class cellSource
76     public fieldValue
79 public:
81     // Public data types
83         //- Source type enumeration
84         enum sourceType
85         {
86             stCellZone
87         };
89         //- Source type names
90         static const NamedEnum<sourceType, 1> sourceTypeNames_;
93         //- Operation type enumeration
94         enum operationType
95         {
96             opNone,
97             opSum,
98             opVolAverage,
99             opVolIntegrate
100         };
102         //- Operation type names
103         static const NamedEnum<operationType, 4> operationTypeNames_;
106 private:
108     // Private member functions
110         //- Set cells to evaluate based on a cell zone
111         void setCellZoneCells();
113         //- Set cells to evaluate based on a patch
114         void setPatchCells();
117 protected:
119     // Protected data
121         //- Source type
122         sourceType source_;
124         //- Operation to apply to values
125         operationType operation_;
127         //- Local list of cell IDs
128         labelList cellId_;
131     // Protected member functions
133         //- Initialise, e.g. cell addressing
134         void initialise();
136         //- Insert field values into values list
137         template<class Type>
138         bool setFieldValues
139         (
140             const word& fieldName,
141             List<Type>& values
142         ) const;
144         //- Apply the 'operation' to the values
145         template<class Type>
146         Type processValues(const List<Type>& values) const;
148         //- Output file header information
149         virtual void writeFileHeader();
152 public:
154     //- Run-time type information
155     TypeName("cellSource");
158     //- Construct from components
159     cellSource
160     (
161         const word& name,
162         const objectRegistry& obr,
163         const dictionary& dict,
164         const bool loadFromFiles = false
165     );
168     //- Destructor
169     virtual ~cellSource();
172     // Public member functions
174         // Access
176             //- Return the source type
177             inline const sourceType& source() const;
179             //- Return the local list of cell IDs
180             inline const labelList& cellId() const;
183         // Function object functions
185             //- Read from dictionary
186             virtual void read(const dictionary&);
188             //- Calculate and write
189             virtual void write();
191             //- Templated helper function to output field values
192             template<class Type>
193             bool writeValues(const word& fieldName);
195             //- Filter a field according to cellIds
196             template<class Type>
197             tmp<Field<Type> > filterField(const Field<Type>& field) const;
201 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
203 } // End namespace fieldValues
204 } // End namespace Foam
206 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
208 #include "cellSourceI.H"
210 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
212 #ifdef NoRepository
213     #include "cellSourceTemplates.C"
214 #endif
216 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
218 #endif
220 // ************************************************************************* //