probesTemplates.C
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
00027 #include "probes.H"
00028 #include "volFields.H"
00029 #include "IOmanip.H"
00030
00031
00032
00033 namespace Foam
00034 {
00035
00036
00037 template<class T>
00038 class isNotEqOp
00039 {
00040 public:
00041
00042 void operator()(T& x, const T& y) const
00043 {
00044 const T unsetVal(-VGREAT*pTraits<T>::one);
00045
00046 if (x != unsetVal)
00047 {
00048
00049
00050
00051
00052 }
00053 else
00054 {
00055
00056 x = y;
00057 }
00058 }
00059 };
00060
00061 }
00062
00063
00064
00065
00066 template<class Type>
00067 Foam::label Foam::probes::countFields
00068 (
00069 fieldGroup<Type>& fieldList,
00070 const wordList& fieldTypes
00071 ) const
00072 {
00073 fieldList.setSize(fieldNames_.size());
00074 label nFields = 0;
00075
00076 forAll(fieldNames_, fieldI)
00077 {
00078 if
00079 (
00080 fieldTypes[fieldI]
00081 == GeometricField<Type, fvPatchField, volMesh>::typeName
00082 )
00083 {
00084 fieldList[nFields] = fieldNames_[fieldI];
00085 nFields++;
00086 }
00087 }
00088
00089 fieldList.setSize(nFields);
00090
00091 return nFields;
00092 }
00093
00094
00095 template<class Type>
00096 void Foam::probes::sampleAndWrite
00097 (
00098 const GeometricField<Type, fvPatchField, volMesh>& vField
00099 )
00100 {
00101 Field<Type> values = sample(vField);
00102
00103 if (Pstream::master())
00104 {
00105 unsigned int w = IOstream::defaultPrecision() + 7;
00106 OFstream& probeStream = *probeFilePtrs_[vField.name()];
00107
00108 probeStream << setw(w) << vField.time().value();
00109
00110 forAll(values, probeI)
00111 {
00112 probeStream << ' ' << setw(w) << values[probeI];
00113 }
00114 probeStream << endl;
00115 }
00116 }
00117
00118
00119 template <class Type>
00120 void Foam::probes::sampleAndWrite
00121 (
00122 const fieldGroup<Type>& fields
00123 )
00124 {
00125 forAll(fields, fieldI)
00126 {
00127 if (loadFromFiles_)
00128 {
00129 sampleAndWrite
00130 (
00131 GeometricField<Type, fvPatchField, volMesh>
00132 (
00133 IOobject
00134 (
00135 fields[fieldI],
00136 obr_.time().timeName(),
00137 refCast<const polyMesh>(obr_),
00138 IOobject::MUST_READ,
00139 IOobject::NO_WRITE,
00140 false
00141 ),
00142 refCast<const fvMesh>(obr_)
00143 )
00144 );
00145 }
00146 else
00147 {
00148 objectRegistry::const_iterator iter = obr_.find(fields[fieldI]);
00149
00150 if
00151 (
00152 iter != obr_.end()
00153 && iter()->type()
00154 == GeometricField<Type, fvPatchField, volMesh>::typeName
00155 )
00156 {
00157 sampleAndWrite
00158 (
00159 obr_.lookupObject
00160 <GeometricField<Type, fvPatchField, volMesh> >
00161 (
00162 fields[fieldI]
00163 )
00164 );
00165 }
00166 }
00167 }
00168 }
00169
00170
00171
00172
00173 template<class Type>
00174 Foam::tmp<Foam::Field<Type> >
00175 Foam::probes::sample
00176 (
00177 const GeometricField<Type, fvPatchField, volMesh>& vField
00178 ) const
00179 {
00180 const Type unsetVal(-VGREAT*pTraits<Type>::one);
00181
00182 tmp<Field<Type> > tValues
00183 (
00184 new Field<Type>(probeLocations_.size(), unsetVal)
00185 );
00186
00187 Field<Type>& values = tValues();
00188
00189 forAll(probeLocations_, probeI)
00190 {
00191 if (cellList_[probeI] >= 0)
00192 {
00193 values[probeI] = vField[cellList_[probeI]];
00194 }
00195 }
00196
00197 Pstream::listCombineGather(values, isNotEqOp<Type>());
00198 Pstream::listCombineScatter(values);
00199
00200 return tValues;
00201 }
00202
00203
00204 template<class Type>
00205 Foam::tmp<Foam::Field<Type> >
00206 Foam::probes::sample(const word& fieldName) const
00207 {
00208 return sample
00209 (
00210 obr_.lookupObject<GeometricField<Type, fvPatchField, volMesh> >
00211 (
00212 fieldName
00213 )
00214 );
00215 }
00216
00217
00218
Copyright © 2000-2009 OpenCFD Ltd