From a551cedeaa34885a44d0cf500c02ef66287b2d77 Mon Sep 17 00:00:00 2001 From: Yeongdo Park Date: Thu, 1 Nov 2018 13:09:18 -0400 Subject: [PATCH] count results that differ more than relative tolerence --- testApp/chemFoam.C | 44 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/testApp/chemFoam.C b/testApp/chemFoam.C index df4e56f..783422c 100644 --- a/testApp/chemFoam.C +++ b/testApp/chemFoam.C @@ -47,6 +47,18 @@ Description // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +const scalar relTol = 1. / 100.; + +inline scalar relError (scalar x, scalar x0) +{ + return (x - x0) / x0; +} + +inline bool exceedTolerence (scalar rError) +{ + return rError > relTol || rError < -relTol; +} + int main(int argc, char *argv[]) { argList::noParallel(); @@ -93,6 +105,10 @@ int main(int argc, char *argv[]) Info<< "\nTemperature Loop\n" << endl; + label errorCount = 0; + + label testCount = 0; + forAll(T, i) { // OpenFOAM diffusivity model @@ -114,15 +130,35 @@ int main(int argc, char *argv[]) forAll(thermo.composition().species(), k) { - Info << thermo.composition().species()[k] << tab << 100. * (diff.D(k)[0] - Dc[k]) / Dc[k] << endl; + // Info << thermo.composition().species()[k] << tab << 100. * (diff.D(k)[0] - Dc[k]) / Dc[k] << endl; + if (exceedTolerence(relError(diff.D(k)[0], Dc[k]))) + { + Info << thermo.composition().species()[k] << ", T = " << T[i] + << " relative error = " << (100. * relError(diff.D(k)[0], Dc[k])) << " %" << endl; + errorCount++; + } + testCount++; } - Info << "mu" << tab << 100.*(diff.mu()[0] - tr_->viscosity())/tr_->viscosity() << endl; + // Info << "mu" << tab << 100.*(diff.mu()[0] - tr_->viscosity())/tr_->viscosity() << endl; + if (exceedTolerence(relError(diff.mu()[0], tr_->viscosity()))) + { + Info << "T = " << T[i] << " relative error = " << (100. * relError(diff.mu()[0], tr_->viscosity())) << " %"<< endl; + errorCount++; + } + testCount++; } - Info << "End" << nl << endl; + Info << errorCount << " / " << testCount << " End" << nl << endl; - return 0; + if (errorCount == 0) + { + return 0; + } + else + { + return -1; + } }