void surfaceValueAveragePluginFunction<Type>::doEvaluation() { typedef typename GeneralSurfaceEvaluationPluginFunction<Type>::resultType rType; autoPtr<rType> pValueAverage( new rType( IOobject( "surfaceValueAverageInCell", this->mesh().time().timeName(), this->mesh(), IOobject::NO_READ, IOobject::NO_WRITE ), this->mesh(), dimensioned<Type>("no",dimless,pTraits<Type>::zero) ) ); const labelList &cells=this->meshCells(); const scalarField &area=this->theSurface().magSf(); scalarField areaSum(pValueAverage->size(),0); const Field<Type> vals=this->values(); forAll(cells,i) { const label cellI=cells[i]; if(cellI>=0) { pValueAverage()[cellI]+=area[i]*vals[i]; areaSum[cellI]+=area[i]; } } forAll(areaSum,cellI) { if(areaSum[cellI]>SMALL) { const_cast<Type&>(pValueAverage->internalField()[cellI]) /=areaSum[cellI]; } } pValueAverage->correctBoundaryConditions(); this->result().setObjectResult(pValueAverage); }
float DifferenceJob::areaAvg(float x1, float x2, float y1, float y2) const { return areaSum(x1,x2,y1,y2) / (fabs(x1-x2) * fabs(y1-y2)); }