sampledSurfaceTemplates.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 "sampledSurface.H"
00028
00029 template<class Type>
00030 bool Foam::sampledSurface::checkFieldSize(const Field<Type>& field) const
00031 {
00032 if (faces().empty() || field.empty())
00033 {
00034 return false;
00035 }
00036
00037 if (field.size() != faces().size())
00038 {
00039 FatalErrorIn
00040 (
00041 "sampledSurface::checkFieldSize(const Field<Type>&) const"
00042 )
00043 << "size mismatch: "
00044 << "field (" << field.size()
00045 << ") != surface (" << faces().size() << ")"
00046 << exit(FatalError);
00047 }
00048
00049 return true;
00050 }
00051
00052
00053 template<class Type>
00054 Type Foam::sampledSurface::integrate(const Field<Type>& field) const
00055 {
00056 Type value = pTraits<Type>::zero;
00057
00058 if (checkFieldSize(field))
00059 {
00060 value = sum(field * magSf());
00061 }
00062
00063 reduce(value, sumOp<Type>());
00064 return value;
00065 }
00066
00067
00068 template<class Type>
00069 Type Foam::sampledSurface::integrate(const tmp<Field<Type> >& field) const
00070 {
00071 Type value = integrate(field());
00072 field.clear();
00073 return value;
00074 }
00075
00076
00077 template<class Type>
00078 Type Foam::sampledSurface::average(const Field<Type>& field) const
00079 {
00080 Type value = pTraits<Type>::zero;
00081
00082 if (checkFieldSize(field))
00083 {
00084 value = sum(field * magSf());
00085 }
00086
00087 reduce(value, sumOp<Type>());
00088
00089
00090 if (area())
00091 {
00092 return value / area();
00093 }
00094 else
00095 {
00096 return pTraits<Type>::zero;
00097 }
00098 }
00099
00100
00101 template<class Type>
00102 Type Foam::sampledSurface::average(const tmp<Field<Type> >& field) const
00103 {
00104 Type value = average(field());
00105 field.clear();
00106 return value;
00107 }
00108
00109
00110 template<class ReturnType, class Type>
00111 void Foam::sampledSurface::project
00112 (
00113 Field<ReturnType>& res,
00114 const Field<Type>& field
00115 ) const
00116 {
00117 if (checkFieldSize(field))
00118 {
00119 const vectorField& norm = Sf();
00120
00121 forAll(norm, faceI)
00122 {
00123 res[faceI] = field[faceI] & (norm[faceI] / mag(norm[faceI]));
00124 }
00125 }
00126 else
00127 {
00128 res.clear();
00129 }
00130 }
00131
00132
00133 template<class ReturnType, class Type>
00134 void Foam::sampledSurface::project
00135 (
00136 Field<ReturnType>& res,
00137 const tmp<Field<Type> >& field
00138 ) const
00139 {
00140 project(res, field());
00141 field.clear();
00142 }
00143
00144
00145 template<class ReturnType, class Type>
00146 Foam::tmp<Foam::Field<ReturnType> >
00147 Foam::sampledSurface::project
00148 (
00149 const tmp<Field<Type> >& field
00150 ) const
00151 {
00152 tmp<Field<ReturnType> > tRes(new Field<ReturnType>(faces().size()));
00153 project(tRes(), field);
00154 return tRes;
00155 }
00156
00157
00158
Copyright © 2000-2009 OpenCFD Ltd