00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef AMROC_NORMEVALUATOR_H
00013 #define AMROC_NORMEVALUATOR_H
00014
00022 #include <iostream>
00023 #include <cstdio>
00024 #include <cfloat>
00025
00026 #include "Evaluator.h"
00027
00034 template <class VectorType>
00035 class NormEvaluator : public Evaluator<VectorType> {
00036 typedef Evaluator<VectorType> base;
00037 typedef typename VectorType::InternalDataType DataType;
00038
00039 public:
00040 typedef typename base::vector_block_type vector_block_type;
00041 typedef typename base::data_block_type data_block_type;
00042
00043 NormEvaluator() : base() {
00044 std::sprintf(base::title,"Norm evaluation of scalar functions");
00045 }
00046
00047 virtual void SetUp(VisualGridBase *gr) {
00048 EvaluatorBase::SetUp(gr);
00049
00050 std::sprintf(&(base::tkeys[0*LEN_TKEYS]), "Distribution ");
00051 std::sprintf(&(base::tkeys[1*LEN_TKEYS]), "Levels ");
00052 std::sprintf(&(base::tkeys[2*LEN_TKEYS]), "|F1-F2| ");
00053 std::sprintf(&(base::tkeys[3*LEN_TKEYS]), "|F1-F2| dx dy dz ");
00054 std::sprintf(&(base::tkeys[4*LEN_TKEYS]), "|F1-F2|^2 dx dy dz ");
00055 base::fkeys[0] = base::Grid->FKeys();
00056 base::fkeys[1] = base::Grid->FKeys();
00057 base::fkeys[2] = base::Grid->FKeys();
00058 base::fkeys[3] = base::Grid->FKeys();
00059 base::fkeys[4] = base::Grid->FKeys();
00060 base::ikeys[0] = 105; base::ikeys[1] = 115;
00061 base::ikeys[2] = 109; base::ikeys[3] = 49;
00062 base::ikeys[4] = 50;
00063 }
00064
00065 virtual int NKeys() const { return 5; }
00066
00067 virtual void SetScalCells(int key,float v[],int& offset,
00068 vector_block_type& DB, float* dx, bool* CompRead) {
00069 int idx=0;
00070 int keym1 = key-1;
00071 if (key>=3 && key<=5) {
00072 BeginFastIndex3(dat, DB.bbox(), DB.data(), VectorType);
00073 float f1, f2;
00074 float fac = dx[0]*DB.stepsize(0)*dx[1]*DB.stepsize(1)*dx[2]*DB.stepsize(2);
00075 for_3 (i,j,k,DB.bbox(),DB.bbox().stepsize())
00076 v[idx+offset]= FastIndex3(dat,i,j,k)(0);
00077 f1 = FastIndex3(dat,i,j,k)(0);
00078 f2 = FastIndex3(dat,i,j,k)(1);
00079 if (f1<FLT_MAX && f2<FLT_MAX) {
00080 if (key==3)
00081 v[idx+offset] = std::fabs(f1-f2);
00082 else if (key==4)
00083 v[idx+offset] = std::fabs(f1-f2)*fac;
00084 else if (key==5)
00085 v[idx+offset] = (f1-f2)*(f1-f2)*fac;
00086 }
00087 base::mvals[2*keym1] = Min(base::mvals[2*keym1], v[idx+offset]);
00088 base::mvals[2*keym1+1] = Max(base::mvals[2*keym1+1], v[idx+offset]);
00089 idx++;
00090 end_for
00091 EndFastIndex3(dat);
00092 }
00093 offset+=idx;
00094 }
00095
00096 virtual void SetScalNodes(int key,float v[],int& offset,
00097 vector_block_type& DB, const BBox& bbox,
00098 float* dx, bool* CompRead) {
00099 int idx=0;
00100 int keym1 = key-1;
00101 float fac = dx[0]*DB.stepsize(0)*dx[1]*DB.stepsize(1)*dx[2]*DB.stepsize(2);
00102 BeginFastIndex3(dat, DB.bbox(), DB.data(), VectorType);
00103 const Coords& step = bbox.stepsize();
00104 switch(key) {
00105 case 3:
00106 {
00107 for_3 (i,j,k,bbox,step)
00108 BBox AddOver(3,i-step(0),j-step(1),k-step(2),
00109 i,j,k,step(0),step(1),step(2));
00110 AddOver *= DB.bbox();
00111
00112 v[idx+offset] = 0.0;
00113 for_3 (l, m, n, AddOver, step)
00114 if (FastIndex3(dat,l,m,n)(0)<FLT_MAX && FastIndex3(dat,l,m,n)(1)<FLT_MAX) {
00115 v[idx+offset] = Max(std::fabs(FastIndex3(dat,l,m,n)(0)-FastIndex3(dat,l,m,n)(1)),v[idx+offset]);
00116 }
00117 end_for
00118
00119 base::mvals[2*keym1] = Min(base::mvals[2*keym1], v[idx+offset]);
00120 base::mvals[2*keym1+1] = Max(base::mvals[2*keym1+1], v[idx+offset]);
00121 idx++;
00122 end_for
00123 break;
00124 }
00125
00126 case 4:
00127 {
00128 for_3 (i,j,k,bbox,step)
00129 BBox AddOver(3,i-step(0),j-step(1),k-step(2),
00130 i,j,k,step(0),step(1),step(2));
00131 AddOver *= DB.bbox();
00132
00133 float c=0;
00134 v[idx+offset] = 0.0;
00135 for_3 (l, m, n, AddOver, step)
00136 if (FastIndex3(dat,l,m,n)(0)<FLT_MAX && FastIndex3(dat,l,m,n)(1)<FLT_MAX) {
00137 v[idx+offset] += std::fabs(FastIndex3(dat,l,m,n)(0)-FastIndex3(dat,l,m,n)(1));
00138 c += 1.0;
00139 }
00140 end_for
00141 if (c>0) {
00142 v[idx+offset] /= c; v[idx+offset] *= fac;
00143 }
00144 else v[idx+offset] = FLT_MAX;
00145
00146 base::mvals[2*keym1] = Min(base::mvals[2*keym1], v[idx+offset]);
00147 base::mvals[2*keym1+1] = Max(base::mvals[2*keym1+1], v[idx+offset]);
00148 idx++;
00149 end_for
00150 break;
00151 }
00152
00153 case 5:
00154 {
00155 for_3 (i,j,k,bbox,step)
00156 BBox AddOver(3,i-step(0),j-step(1),k-step(2),
00157 i,j,k,step(0),step(1),step(2));
00158 AddOver *= DB.bbox();
00159
00160 float c=0;
00161 v[idx+offset] = 0.0;
00162 for_3 (l, m, n, AddOver, step)
00163 if (FastIndex3(dat,l,m,n)(0)<FLT_MAX && FastIndex3(dat,l,m,n)(1)<FLT_MAX) {
00164 v[idx+offset] += std::fabs(FastIndex3(dat,l,m,n)(0)-FastIndex3(dat,l,m,n)(1));
00165 v[idx+offset] *= v[idx+offset];
00166 c += 1.0;
00167 }
00168 end_for
00169 if (c>0) {
00170 v[idx+offset] /= c; v[idx+offset] *= fac;
00171 }
00172 else v[idx+offset] = FLT_MAX;
00173
00174 base::mvals[2*keym1] = Min(base::mvals[2*keym1], v[idx+offset]);
00175 base::mvals[2*keym1+1] = Max(base::mvals[2*keym1+1], v[idx+offset]);
00176 idx++;
00177 end_for
00178 break;
00179 }
00180 default:
00181 break;
00182 }
00183 EndFastIndex3(dat);
00184 offset+=idx;
00185 }
00186 };
00187
00188
00189 #endif