Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "cellSource.H"
00027 #include <finiteVolume/volFields.H>
00028 #include <OpenFOAM/IOList.H>
00029
00030
00031
00032 template<class Type>
00033 bool Foam::fieldValues::cellSource::validField(const word& fieldName) const
00034 {
00035 typedef GeometricField<Type, fvPatchField, volMesh> vf;
00036
00037 if (obr_.foundObject<vf>(fieldName))
00038 {
00039 return true;
00040 }
00041
00042 return false;
00043 }
00044
00045
00046 template<class Type>
00047 Foam::tmp<Foam::Field<Type> > Foam::fieldValues::cellSource::setFieldValues
00048 (
00049 const word& fieldName
00050 ) const
00051 {
00052 typedef GeometricField<Type, fvPatchField, volMesh> vf;
00053
00054 if (obr_.foundObject<vf>(fieldName))
00055 {
00056 return filterField(obr_.lookupObject<vf>(fieldName));
00057 }
00058
00059 return tmp<Field<Type> >(new Field<Type>(0.0));
00060 }
00061
00062
00063 template<class Type>
00064 Type Foam::fieldValues::cellSource::processValues
00065 (
00066 const Field<Type>& values,
00067 const scalarField& V,
00068 const scalarField& weightField
00069 ) const
00070 {
00071 Type result = pTraits<Type>::zero;
00072 switch (operation_)
00073 {
00074 case opSum:
00075 {
00076 result = sum(values);
00077 break;
00078 }
00079 case opVolAverage:
00080 {
00081 result = sum(values*V)/sum(V);
00082 break;
00083 }
00084 case opVolIntegrate:
00085 {
00086 result = sum(values*V);
00087 break;
00088 }
00089 case opWeightedAverage:
00090 {
00091 result = sum(values*weightField)/sum(weightField);
00092 break;
00093 }
00094 case opMin:
00095 {
00096 result = min(values);
00097 break;
00098 }
00099 case opMax:
00100 {
00101 result = max(values);
00102 break;
00103 }
00104 default:
00105 {
00106
00107 }
00108 }
00109
00110 return result;
00111 }
00112
00113
00114
00115
00116 template<class Type>
00117 bool Foam::fieldValues::cellSource::writeValues(const word& fieldName)
00118 {
00119 const bool ok = validField<Type>(fieldName);
00120
00121 if (ok)
00122 {
00123 Field<Type> values = combineFields(setFieldValues<Type>(fieldName)());
00124
00125 scalarField V = combineFields(filterField(mesh().V())());
00126
00127 scalarField weightField =
00128 combineFields(setFieldValues<scalar>(weightFieldName_)());
00129
00130 if (Pstream::master())
00131 {
00132 Type result = processValues(values, V, weightField);
00133
00134 if (valueOutput_)
00135 {
00136 IOList<Type>
00137 (
00138 IOobject
00139 (
00140 fieldName + "_" + sourceTypeNames_[source_] + "-"
00141 + sourceName_,
00142 obr_.time().timeName(),
00143 obr_,
00144 IOobject::NO_READ,
00145 IOobject::NO_WRITE
00146 ),
00147 values
00148 ).write();
00149 }
00150
00151
00152 outputFilePtr_()<< tab << result;
00153
00154 if (log_)
00155 {
00156 Info<< " " << operationTypeNames_[operation_]
00157 << "(" << sourceName_ << ") for " << fieldName
00158 << " = " << result << endl;
00159 }
00160 }
00161 }
00162
00163 return ok;
00164 }
00165
00166
00167 template<class Type>
00168 Foam::tmp<Foam::Field<Type> > Foam::fieldValues::cellSource::filterField
00169 (
00170 const Field<Type>& field
00171 ) const
00172 {
00173 return tmp<Field<Type> >(new Field<Type>(field, cellId_));
00174 }
00175
00176
00177
00178