FreeFOAM The Cross-Platform CFD Toolkit
cellSourceTemplates.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-2011 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 "cellSource.H"
27 #include <finiteVolume/volFields.H>
28 #include <OpenFOAM/IOList.H>
29 
30 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
31 
32 template<class Type>
33 bool Foam::fieldValues::cellSource::validField(const word& fieldName) const
34 {
36 
37  if (obr_.foundObject<vf>(fieldName))
38  {
39  return true;
40  }
41 
42  return false;
43 }
44 
45 
46 template<class Type>
48 (
49  const word& fieldName
50 ) const
51 {
53 
54  if (obr_.foundObject<vf>(fieldName))
55  {
56  return filterField(obr_.lookupObject<vf>(fieldName));
57  }
58 
59  return tmp<Field<Type> >(new Field<Type>(0.0));
60 }
61 
62 
63 template<class Type>
65 (
66  const Field<Type>& values,
67  const scalarField& V,
68  const scalarField& weightField
69 ) const
70 {
71  Type result = pTraits<Type>::zero;
72  switch (operation_)
73  {
74  case opSum:
75  {
76  result = sum(values);
77  break;
78  }
79  case opVolAverage:
80  {
81  result = sum(values*V)/sum(V);
82  break;
83  }
84  case opVolIntegrate:
85  {
86  result = sum(values*V);
87  break;
88  }
89  case opWeightedAverage:
90  {
91  result = sum(values*weightField)/sum(weightField);
92  break;
93  }
94  case opMin:
95  {
96  result = min(values);
97  break;
98  }
99  case opMax:
100  {
101  result = max(values);
102  break;
103  }
104  default:
105  {
106  // Do nothing
107  }
108  }
109 
110  return result;
111 }
112 
113 
114 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
115 
116 template<class Type>
118 {
119  const bool ok = validField<Type>(fieldName);
120 
121  if (ok)
122  {
123  Field<Type> values = combineFields(setFieldValues<Type>(fieldName)());
124 
125  scalarField V = combineFields(filterField(mesh().V())());
126 
127  scalarField weightField =
128  combineFields(setFieldValues<scalar>(weightFieldName_)());
129 
130  if (Pstream::master())
131  {
132  Type result = processValues(values, V, weightField);
133 
134  if (valueOutput_)
135  {
137  (
138  IOobject
139  (
140  fieldName + "_" + sourceTypeNames_[source_] + "-"
141  + sourceName_,
142  obr_.time().timeName(),
143  obr_,
146  ),
147  values
148  ).write();
149  }
150 
151 
152  outputFilePtr_()<< tab << result;
153 
154  if (log_)
155  {
156  Info<< " " << operationTypeNames_[operation_]
157  << "(" << sourceName_ << ") for " << fieldName
158  << " = " << result << endl;
159  }
160  }
161  }
162 
163  return ok;
164 }
165 
166 
167 template<class Type>
169 (
170  const Field<Type>& field
171 ) const
172 {
173  return tmp<Field<Type> >(new Field<Type>(field, cellId_));
174 }
175 
176 
177 // ************************ vim: set sw=4 sts=4 et: ************************ //
178