00001
00002
00003
00004
00005
00006 #ifndef AMROC_AMRStatistics_H
00007 #define AMROC_AMRStatistics_H
00008
00016 #include <iostream>
00017 #include <fstream>
00018 #include <string>
00019 #include <stdlib.h>
00020 #include <algorithm>
00021 #include "DAGH.h"
00022 #include "AMRBase.h"
00023 #include "Interpolation.h"
00024
00025 #include "StatParser/StatParser.h"
00026
00027 #define DEBUG_PRINT_STATISTICS
00028
00029 #define MAXGROUPS 8
00030 #define MAXSTATOPS 4
00031 #define MAXPERVAR 4
00032 #define AVGOP 0
00033 #define MODEOP 1
00034 #define MEDIANOP 2
00035 #define STDDEVIATIONOP 3
00036 #define MINMAX 4
00037 #define GRADOP 5
00038 #define CURLOP 6
00039 #define FFTOP 7
00040
00041 #define NUMBINS 10
00042 #define TOLSTAT 1e-8
00043 #define MINFIN 0.9e+37
00044
00045 #define MAXGRADS 4
00046
00047 template <class VectorType, class InterpolationType, class OutputType, int dim>
00048 class AMRStatistics : public AMRBase<VectorType,dim>,
00049 private StatParser<typename InterpolationType::point_type,
00050 typename VectorType::InternalDataType,dim> {
00051 typedef AMRBase<VectorType,dim> base;
00052 typedef typename VectorType::InternalDataType DataType;
00053 typedef typename InterpolationType::point_type point_type;
00054 typedef StatParser<point_type,DataType,dim> stparser;
00055 typedef typename stparser::symrec symrec;
00056
00057
00058 using StatParser<point_type,DataType,dim>::group_table;
00059 using StatParser<point_type,DataType,dim>::putsym;
00060 using StatParser<point_type,DataType,dim>::unlinksym;
00061 using StatParser<point_type,DataType,dim>::vectorize;
00062 using StatParser<point_type,DataType,dim>::buildcoords;
00063 using StatParser<point_type,DataType,dim>::clearcoords;
00064
00065
00066 public:
00067 typedef typename base::vec_grid_fct_type vec_grid_fct_type;
00068 typedef GridFunction<DataType,dim> grid_fct_type;
00069
00070 public:
00071 AMRStatistics(InterpolationType *int_ref, OutputType* out_ref) : base() {
00072 _Step = 1;
00073 _FileOutput = out_ref;
00074 _Interpolation = int_ref;
00075 _OutputFile = "stats";
00076 _DumpMeshes = 0;
00077 _NumStats = 0;
00078
00079 _NumGrads = 0;
00080
00081 _SepFiles = 0;
00082
00083
00084 for (register int i = 0; i < 3+MAXPERVAR; i++)
00085 for (register int j = 0; j < MAXSTATOPS; j++)
00086 statOp[i][j] = -1;
00087
00088 std::vector<double> d;
00089 std::vector<std::vector<double> > axis;
00090 axis.push_back(d);
00091 ctmp.resize(2*dim+1);
00092 ftmp.resize(2*dim+1);
00093
00094
00095
00096
00097 for (register int i = 0; i < MAXGRADS; i++) {
00098 calcount[i]=1;
00099 gcount[i]=0;
00100 curltog[i]=0;
00101 wvtog[i]=0;
00102 uwtog[i]=0;
00103 vutog[i]=0;
00104 }
00105
00106
00107
00108
00109
00110
00111
00112
00113 OpNames.clear();
00114 OpNames.push_back(" avgerage ");
00115 OpNames.push_back(" mode ");
00116 OpNames.push_back(" median ");
00117 OpNames.push_back(" stddeviation ");
00118 OpNames.push_back(" min-max ");
00119
00120 }
00121
00122 void Setup(GridHierarchy *gh, const int& ghosts, int* shape, double* geom) {
00123 base::SetupData(gh, ghosts);
00124
00125 int me = MY_PROC;
00126 if (me == VizServer) {
00127 for (register int j = 0; j < _NumStats; j++) {
00128 for (register int i = 0; i < 3+MAXPERVAR; i++)
00129 std::cout << "["<<i<<"]["<<j<<"] " << statOp[i][j]<< " : ";
00130 std::cout << " _NumPerVar " << _NumPerVar[j] << std::endl;
00131 }
00132 for (register int i = 0; i < _NumGrads; i++) {
00133 std:: cout << "calcount["<<i<<"] " << calcount[i] << "\n";
00134 std::cout << "Gradgroup["<<i<<"] " << GradGroup[i] << "\n";
00135 for (register int d = 0; d < dim; d++) {
00136 std::cout << "Grads["<<d<<"]["<<i<<"] " << Grads[d][i] << "\n";
00137 }
00138 }
00139 for (register int i = 0; i < MAXGROUPS; i++) {
00140 std:: cout << "GroupVars["<<i<<"] " << GroupVars[i] << "\n";
00141 }
00142
00143
00144 }
00145
00146 int MaxLev;
00147 int nx, ny, nz;
00148 char s[36];
00149
00150 MaxLev = MaxLevel(base::GH());
00151
00152 nx = shape[0];
00153 putsym(TOK_INTEGER, STAT_NX)->vdata.ivalue = nx;
00154
00155 sprintf(s, "%s(%d)", STAT_NX, 1);
00156 putsym(TOK_INTEGER, s)->vdata.ivalue = nx;
00157 for ( int i = 0; i < MaxLev ; i++ ) {
00158 sprintf(s, "%s(%d)", STAT_NX, i+2);
00159 nx *= RefineFactor(base::GH(),i);
00160 putsym(TOK_INTEGER, s)->vdata.ivalue = nx;
00161 }
00162 putsym(TOK_INTEGER, STAT_NXF)->vdata.ivalue = nx;
00163 putsym(TOK_DOUBLE, STAT_XMIN)->vdata.dvalue = geom[0];
00164 putsym(TOK_DOUBLE, STAT_XMAX)->vdata.dvalue = geom[1];
00165
00166 if ( dim > 1 ) {
00167 ny = shape[1];
00168 putsym(TOK_INTEGER, STAT_NY)->vdata.ivalue = ny;
00169
00170 sprintf(s, "%s(%d)", STAT_NY, 1);
00171 putsym(TOK_INTEGER, s)->vdata.ivalue = ny;
00172 for ( int i = 0; i < MaxLev ; i++ ) {
00173 sprintf(s, "%s(%d)", STAT_NY, i+2);
00174 ny *= RefineFactor(base::GH(),i);;
00175 putsym(TOK_INTEGER, s)->vdata.ivalue = ny;
00176 }
00177 putsym(TOK_INTEGER, STAT_NYF)->vdata.ivalue = ny;
00178 putsym(TOK_DOUBLE, STAT_YMIN)->vdata.dvalue = geom[2];
00179 putsym(TOK_DOUBLE, STAT_YMAX)->vdata.dvalue = geom[3];
00180 }
00181
00182 if ( dim > 2 ) {
00183 nz = shape[2];
00184 putsym(TOK_INTEGER, STAT_NZ)->vdata.ivalue = nz;
00185
00186 sprintf(s, "%s(%d)", STAT_NZ, 1);
00187 putsym(TOK_INTEGER, s)->vdata.ivalue = nz;
00188 for ( int i = 0; i < MaxLev ; i++ ) {
00189 sprintf(s, "%s(%d)", STAT_NZ, i+2);
00190 nz *= RefineFactor(base::GH(),i);;
00191 putsym(TOK_INTEGER, s)->vdata.ivalue = nz;
00192 }
00193 putsym(TOK_INTEGER, STAT_NZF)->vdata.ivalue = nz;
00194 putsym(TOK_DOUBLE, STAT_ZMIN)->vdata.dvalue = geom[4];
00195 putsym(TOK_DOUBLE, STAT_ZMAX)->vdata.dvalue = geom[5];
00196 }
00197
00198
00199
00200
00201 symrec *ptr;
00202
00203 putsym(TOK_VARIABLE, "rho")->vdata.iptr = 1;
00204 putsym(TOK_VARIABLE, "r")->vdata.iptr = 1;
00205 (ptr = putsym(TOK_VARIABLE, "u"))->vdata.iptr = 2; ptr->src = STAT_DERIVED;
00206 if ( dim > 1 ) {
00207 (ptr = putsym(TOK_VARIABLE, "v"))->vdata.iptr = 3; ptr->src = STAT_DERIVED;
00208 }
00209 if ( dim > 2 ) {
00210 (ptr = putsym(TOK_VARIABLE, "w"))->vdata.iptr = 4; ptr->src = STAT_DERIVED;
00211 }
00212 putsym(TOK_VARIABLE, "E")->vdata.iptr = 5;
00213 for ( int i = 0; i < NVARS - 5 ; i++ ) {
00214 char name[12];
00215 sprintf(name, "Y%d", i+1);
00216 (ptr = putsym(TOK_VARIABLE, name))->vdata.iptr =
00217 ((dim == 1 ? 7 : (dim == 2 ? 8 : 9))+i); ptr->src = STAT_DERIVED;
00218 }
00219 if ( dim == 3 ) {
00220 (ptr = putsym(TOK_VARIABLE, "sgske"))->vdata.iptr = (NVARS+5); ptr->src = STAT_DERIVED;
00221 }
00222 putsym(TOK_VARIABLE, "T")->vdata.iptr = NVARS+1;
00223 (ptr = putsym(TOK_VARIABLE, "p"))->vdata.iptr =
00224 (dim == 1 ? 5 : (dim == 2 ? 6 : 7)); ptr->src = STAT_DERIVED;
00225 (ptr = putsym(TOK_VARIABLE, "gamma"))->vdata.iptr =
00226 (dim == 1 ? 6 : (dim == 2 ? 7 : 8)); ptr->src = STAT_DERIVED;
00227 putsym(TOK_VARINARRAY, "q")->vdata.iptr = 0;
00228 (ptr = putsym(TOK_VARINARRAY, "qout"))->vdata.iptr = 0; ptr->src = STAT_DERIVED;
00229
00231 if ( _DefFile.length() ) {
00232 stparser::parse(_DefFile.c_str());
00234 for ( typename stparser::grpvec::const_iterator g = group_table.begin() ;
00235 g != group_table.end(); g++)
00236 if ( (*g)->step == 0 ) (*g)->step = _Step;
00237
00239 int me = MY_PROC;
00240 if (me == VizServer) {
00241 if ( _DumpMeshes == 1) {
00242 int ig = 1;
00243 for ( typename stparser::grpvec::const_iterator g = group_table.begin() ;
00244 g != group_table.end(); g++, ig++) {
00246 int ip = 1;
00247 for ( typename stparser::provec::const_iterator p = (*g)->probe_table.begin() ;
00248 p != (*g)->probe_table.end() ; p ++, ip++ )
00249 {
00250 if ( buildcoords(*p) != RETURN_OK ) return;
00251
00252 int i, j;
00253 FILE * fp;
00254 char name[128];
00255 #if defined(WJSON) || defined(SJSON)
00256 sprintf(name, "group%d-probe%d.json", ig, ip);
00257 #else
00258 sprintf(name, "group%d-probe%d.dat", ig, ip);
00259 #endif
00260 fp = fopen(name, "w");
00261 if ( (*p)->type == TOK_THREAD ) {
00262 for ( i = 0 ; i < (*p)->options.thread.na ; i++ ) {
00263 fprintf(fp, "%12.8lf %12.8lf %12.8lf\n", (*p)->coords[i](0),
00264 (*p)->coords[i](1),
00265 (*p)->coords[i](2));
00266 }
00267 } else {
00268 int na, nb;
00269 if ( (*p)->type == TOK_SURFACE ) {
00270 na = (*p)->options.surface.na;
00271 nb = (*p)->options.surface.nb;
00272 } else if ((*p)->type == TOK_PLANES ) {
00273 na = (*p)->options.plane.na;
00274 nb = (*p)->options.plane.nb;
00275 }
00276 #if defined(WJSON) || defined(SJSON)
00277 fprintf(fp, "\{\n\t\"COORDS\": [\"X\", \"Y\", \"Z\"],\n");
00278 fprintf(fp, "\t\"NA\": %d, \"NB\": %d,\n", na, nb);
00279 fprintf(fp, "\t\"VALUES\": [\n");
00280 #else
00281 fprintf(fp, "VARIABLES = \"X\", \"Y\", \"Z\"\n");
00282 fprintf(fp, "ZONE I=%d, J=%d, F=POINT\n", na, nb);
00283 #endif
00284 for ( j = 0 ; j < nb ; j++ )
00285 for ( i = 0 ; i < na ; i++ ) {
00286 int l = i+j*na;
00287 #if defined(WJSON) || defined(SJSON)
00288 if (l < na*nb-1) fprintf(fp, "\t\t [ %12.8lf, %12.8lf, %12.8lf ],\n", (*p)->coords[l](0),
00289 (*p)->coords[l](1), (*p)->coords[l](2));
00290 else fprintf(fp, "\t\t [ %12.8lf, %12.8lf, %12.8lf ]\n", (*p)->coords[l](0),
00291 (*p)->coords[l](1), (*p)->coords[l](2));
00292 #else
00293 fprintf(fp, "%12.8lf %12.8lf %12.8lf\n", (*p)->coords[l](0),
00294 (*p)->coords[l](1), (*p)->coords[l](2));
00295 #endif
00296 }
00297 #if defined(WJSON) || defined(SJSON)
00298 fprintf(fp, "\t]\n}");
00299 #endif
00300 }
00301 fclose(fp);
00302
00303 clearcoords(*p);
00304 }
00305 }
00306 }
00307 }
00308 }
00309 }
00310
00311 virtual void register_at(ControlDevice& Ctrl) { register_at(Ctrl, ""); }
00312 virtual void register_at(ControlDevice& Ctrl, const std::string& prefix) {
00313 LocCtrl = Ctrl.getSubDevice(prefix+"Statistics");
00314
00315 RegisterAt(LocCtrl,"DefinitionFile",_DefFile);
00316 RegisterAt(LocCtrl,"OutputFile",_OutputFile);
00317 RegisterAt(LocCtrl,"Step",_Step);
00318 RegisterAt(LocCtrl,"WriteMeshes", _DumpMeshes);
00319 RegisterAt(LocCtrl,"SeparateFiles", _SepFiles);
00320
00321 RegisterAt(LocCtrl,"NumStats", _NumStats);
00322 char VariableName[32];
00323 for (register int i = 0; i < MAXSTATOPS; i++) {
00324 std::sprintf(VariableName,"G(%02d)",i+1);
00325 RegisterAt(LocCtrl,std::string(VariableName),statOp[0][i]);
00326 std::sprintf(VariableName,"P(%02d)",i+1);
00327 RegisterAt(LocCtrl,std::string(VariableName),statOp[1][i]);
00328 std::sprintf(VariableName,"V(%02d)",i+1);
00329 RegisterAt(LocCtrl,std::string(VariableName),statOp[2][i]);
00330 std::sprintf(VariableName,"N(%02d)",i+1);
00331 RegisterAt(LocCtrl,std::string(VariableName),_NumPerVar[i]);
00332 for (register int j = 0; j < MAXPERVAR; j++) {
00333 std::sprintf(VariableName,"Op%02d(%02d)",j+1,i+1);
00334 RegisterAt(LocCtrl,std::string(VariableName),statOp[3+j][i]);
00335 }
00336 }
00337
00338 RegisterAt(LocCtrl,"NumGrads", _NumGrads);
00339 for (register int j = 0; j < MAXGRADS; j++) {
00340 std::sprintf(VariableName,"GradGroup(%02d)",j+1);
00341 RegisterAt(LocCtrl,std::string(VariableName),GradGroup[j]);
00342 std::sprintf(VariableName,"GradVars(%02d)",j+1);
00343 RegisterAt(LocCtrl,std::string(VariableName),GradVars[j]);
00344 std::sprintf(VariableName,"Curl(%02d)",j+1);
00345 RegisterAt(LocCtrl,std::string(VariableName),curltog[j]);
00346 std::sprintf(VariableName,"wv(%02d)",j+1);
00347 RegisterAt(LocCtrl,std::string(VariableName),wvtog[j]);
00348 std::sprintf(VariableName,"uw(%02d)",j+1);
00349 RegisterAt(LocCtrl,std::string(VariableName),uwtog[j]);
00350 std::sprintf(VariableName,"vu(%02d)",j+1);
00351 RegisterAt(LocCtrl,std::string(VariableName),vutog[j]);
00352 }
00353 for (register int i = 0; i < dim; i++) {
00354 for (register int j = 0; j < MAXGRADS; j++) {
00355 if (i == 0)
00356 std::sprintf(VariableName,"GradX(%02d)",j+1);
00357 else if (i == 1)
00358 std::sprintf(VariableName,"GradY(%02d)",j+1);
00359 else
00360 std::sprintf(VariableName,"GradZ(%02d)",j+1);
00361 RegisterAt(LocCtrl,std::string(VariableName),Grads[i][j]);
00362 }
00363 }
00364
00365 for (register int j = 0; j < MAXGROUPS; j++) {
00366 std::sprintf(VariableName,"GroupVars(%02d)",j+1);
00367 RegisterAt(LocCtrl,std::string(VariableName),GroupVars[j]);
00368 }
00369
00370 }
00371
00372 ~AMRStatistics() {
00373 _FileOutput = NULL;
00374 _Interpolation = NULL;
00375 }
00376
00377 public:
00378
00379 virtual void CalcStat(int OpType, int Lpoints, double * adata, double * result) {
00380
00381 double avg = 0., bin = 0., stddev = 0., st1 = 0., st2 = 0., min = MINFIN, max = -MINFIN;
00382 int intervals[NUMBINS+1], mfid = 0, mfreq = 0, count = 0, mini = 0, maxi = 0;
00383 std::vector<double> tmp( adata, adata + Lpoints );
00384 switch ( OpType ) {
00385 case AVGOP:
00386 for (register int i=0; i<Lpoints; i++) {
00387 avg += tmp[i];
00388 }
00389 avg /= Lpoints;
00390 *result = avg;
00391 break;
00392 case MODEOP:
00393 tmp.resize(Lpoints);
00394 sort(tmp.begin(),tmp.end());
00395 for (register int i = 0; i < NUMBINS+1; i++ ) {
00396 intervals[i] = 0;
00397 }
00398 bin = (tmp[Lpoints-1] - tmp[0])/(double)NUMBINS;
00399 if (bin > TOLSTAT) {
00400 for (register int i = 0; i < Lpoints; i++ ) {
00401 intervals[ (int) std::floor( (tmp[i]-tmp[0])/bin ) ] += 1;
00402 }
00403 for (register int b = 0; b < NUMBINS+1; b++ ) {
00404 count = intervals[b];
00405 if (count > mfreq) {
00406 mfreq = count;
00407 mfid = b;
00408 }
00409 }
00410 *result = tmp[mfid];
00411 }
00412 else {
00413 *result = tmp[Lpoints/2];
00414 }
00415 tmp.clear();
00416 break;
00417 case MEDIANOP:
00418 tmp.resize(Lpoints);
00419 sort(tmp.begin(),tmp.end());
00420 *result = tmp[Lpoints/2];
00421 tmp.clear();
00422 break;
00423 case STDDEVIATIONOP:
00424 avg = 0.;
00425 st1 = 0.;
00426 st2 = 0.;
00427 for (register int i=0; i<Lpoints; i++) {
00428 stddev += (adata[i]-avg)*(adata[i]-avg);
00429 st1 += (adata[i]);
00430 st2 += (adata[i])*(adata[i]);
00431 }
00432 st1 = std::sqrt( ((double)Lpoints*st2 - st1*st1)/(double)(Lpoints*(Lpoints-1)) );
00433 *result = st1;
00434 break;
00435 case MINMAX:
00436 for (register int i=0; i<Lpoints; i++) {
00437 if (min > tmp[i]) { min = tmp[i]; mini = i; }
00438 if (max < tmp[i]) { max = tmp[i]; maxi = i; }
00439 }
00440 result[0] = min; result[1] = (double)mini;
00441 result[2] = max; result[3] = (double)maxi;
00442 break;
00443
00444 }
00445
00446 }
00447
00448 #ifdef SJSON
00449 virtual void CalcGradient(int groupNum, int * dir, int nvars, int Lpoints, int na, int nb, std::vector<std::vector<point_type> > cdata,
00450 std::vector<std::vector<double> > vdata, int nstep, double * t, int curl, int wv, int uw, int vu) {
00451 #else
00452 virtual void CalcGradient(int groupNum, int * dir, int nvars, int Lpoints, int na, int nb, std::vector<std::vector<point_type> > cdata,
00453 std::vector<std::vector<double> > vdata, int nstep, double * t, std::ostream* out, int curl, int wv, int uw, int vu) {
00454 #endif
00455
00456 std::vector<std::vector<double> > gradi;
00457 std::vector<double> res;
00458 res.resize(Lpoints);
00459 int pos,posi;
00460
00461 #ifdef STATS_DEBUG
00462 std::cout << "******* *CalgGrad()* ********\n";
00463 std::cout << "vdata.size() " << vdata.size() << std::endl;
00464 std::cout << "vdata[0].size() " << vdata[0].size() << std::endl;
00465 #endif
00466
00467 #if defined(WJSON)
00468 *out << "\t\t\t\"Gradient\": {\n";
00469 #elif !defined(WJSON) && !defined(SJSON)
00470 *out << "# Gradient\n";
00471 #endif
00472 for (register int nv=0; nv<nvars; nv++) {
00473 #if defined(WJSON)
00474 *out << "\t\t\t\t\"VAR" << nv+1 << "\": {\n";
00475 #elif !defined(WJSON) && !defined(SJSON)
00476 *out << "# NVAR " << nv+1 << "\n";
00477 #endif
00478 pos = nv*Lpoints;
00479 for ( register int d=0; d<dim; d++) {
00480 if (dir[d] == 1) {
00481 #if defined(WJSON)
00482 *out << "\t\t\t\t\t\"dim" << d << "\": [";
00483 #elif !defined(WJSON) && !defined(SJSON)
00484 *out << "# dim " << d << "\n";
00485 #endif
00486 for (register int i=0; i<Lpoints; i++) {
00487 posi = pos+i;
00488 if (vdata[0][posi] < -MINFIN ) {
00489 res[i] = MINFIN;
00490 } else if (vdata[2*d+1][posi] < -MINFIN ) {
00491 res[i] = (vdata[0][posi] -vdata[2*d+2][posi])/(cdata[0][i](d)-cdata[2*d+2][i](d));
00492 } else if (vdata[2*d+2][posi] < -MINFIN ) {
00493 res[i] = (vdata[2*d+1][posi] -vdata[0][posi])/(cdata[2*d+1][i](d)-cdata[0][i](d));
00494 } else if (vdata[2*d][posi] > -MINFIN && vdata[2*d+1][posi] > -MINFIN &&
00495 vdata[2*d+2][posi] > -MINFIN) {
00496 res[i] = (vdata[2*d+1][posi] -vdata[2*d+2][posi])/(cdata[2*d+1][i](d)-cdata[2*d+2][i](d));
00497 }
00498 #if defined(WJSON)
00499 if (i<Lpoints-1) *out << res[i] << ", ";
00500 else {
00501 if (d<dim-1) *out << res[i] << " ],";
00502 else *out << res[i] << " ]";
00503 }
00504 #elif !defined(WJSON) && !defined(SJSON)
00505 *out << res[i] << " ";
00506 #endif
00507 }
00508 #ifndef SJSON
00509 *out << std::endl;
00510 #endif
00511
00512 gradi.push_back(res);
00513
00514 }
00515 }
00516 #if defined(WJSON)
00517 if (nv<nvars-1) *out << "\t\t\t\t},\n";
00518 else *out << "\t\t\t\t}\n";
00519 #endif
00520 }
00521 #if defined(WJSON)
00522 if (curl) {
00523 *out << "\t\t\t},\n";
00524 } else *out << "\t\t\t}\n";
00525 #endif
00526
00528 if (curl > 0) {
00529 #if defined(WJSON)
00530 *out << "\t\t\t\"CURL\": { \n";
00531 #elif defined SJSON
00532 if (_SepFiles == 1) {
00533 char sfname[256];
00534 std::ofstream sepOut;
00535 if (wv) {
00536 std::sprintf(sfname,"%s%d_wv_%d.json",_OutputFile.c_str(),groupNum,CurrentTime(base::GH(), 0) );
00537 std::cout << " *** Writing " << sfname << std::endl;
00538 sepOut.open(sfname, std::ios::out );
00539 sepOut << "{\n\t\"iter\": " << CurrentTime(base::GH(), 0) << ", \"time\": " << t[0] << "," << std::endl;
00540 sepOut << "\t\"wv\": [ ";
00541 for (register int i=0; i<Lpoints-1; i++) {
00542 if (i<Lpoints-1) sepOut << gradi[3][i] - gradi[2][i] << ", ";
00543 }
00544 sepOut << gradi[3][Lpoints-1] - gradi[2][Lpoints-1] << " ]\n}";
00545 sepOut.close();
00546 }
00547 if (uw) {
00548 std::sprintf(sfname,"%s%d_uw_%d.json",_OutputFile.c_str(),groupNum,CurrentTime(base::GH(), 0) );
00549 std::cout << " *** Writing " << sfname << std::endl;
00550 sepOut.open(sfname, std::ios::out );
00551 sepOut << "{\n\t\"iter\": " << CurrentTime(base::GH(), 0) << ", \"time\": " << t[0] << "," << std::endl;
00552 sepOut << "\t\"uw\": [ ";
00553 for (register int i=0; i<Lpoints-1; i++) {
00554 if (i<Lpoints-1) sepOut << gradi[1][i] - gradi[3][i] << ", ";
00555 }
00556 sepOut << gradi[1][Lpoints-1] - gradi[3][Lpoints-1] << " ]\n}";
00557 sepOut.close();
00558 }
00559 if (vu) {
00560 std::sprintf(sfname,"%s%d_vu_%d.json",_OutputFile.c_str(),groupNum,CurrentTime(base::GH(), 0) );
00561 std::cout << " *** Writing " << sfname << std::endl;
00562 sepOut.open(sfname, std::ios::out );
00563 sepOut << "{\n\t\"iter\": " << CurrentTime(base::GH(), 0) << ", \"time\": " << t[0] << "," << std::endl;
00564 sepOut << "\t\"vu\": [ ";
00565 for (register int i=0; i<Lpoints-1; i++) {
00566 if (i<Lpoints-1) sepOut << gradi[2][i] - gradi[1][i] << ", ";
00567 }
00568 sepOut << gradi[2][Lpoints-1] - gradi[1][Lpoints-1] << " ]\n}";
00569 sepOut.close();
00570 }
00571 }
00572 #else
00573 *out << "# CURL\n";
00574 #endif
00575
00576 #if defined(WJSON)
00577 *out << "\t\t\t\t\"wv\": [ ";
00578 #endif
00579 for (register int i=0; i<Lpoints; i++) {
00580 #if defined(WJSON)
00581 if (i<Lpoints-1) *out << gradi[3][i] - gradi[2][i] << ", ";
00582 else *out << gradi[3][i] - gradi[2][i] << " ],";
00583 #elif !defined(SJSON)
00584 *out << gradi[3][i] - gradi[2][i] << " ";
00585 #endif
00586 }
00587 #if defined(WJSON)
00588 *out << std::endl;
00589 *out << "\t\t\t\t\"uw\": [ ";
00590 #endif
00591 for (register int i=0; i<Lpoints; i++) {
00592 #if defined(WJSON)
00593 if (i<Lpoints-1) *out << gradi[1][i] - gradi[3][i] << ", ";
00594 else *out << gradi[1][i] - gradi[3][i] << "], ";
00595 #elif !defined(SJSON)
00596 *out << gradi[1][i] - gradi[3][i] << " ";
00597 #endif
00598 }
00599 #if defined(WJSON)
00600 *out << std::endl;
00601 *out << "\t\t\t\t\"vu\": [ ";
00602 #endif
00603 for (register int i=0; i<Lpoints; i++) {
00604 #if defined(WJSON)
00605 if (i<Lpoints-1) *out << gradi[2][i] - gradi[1][i] << ", ";
00606 else *out << gradi[2][i] - gradi[1][i] << "]";
00607 #elif !defined(SJSON)
00608 *out << gradi[2][i] - gradi[1][i] << " ";
00609 #endif
00610 }
00611 #if defined(WJSON)
00612 *out << std::endl;
00613 #endif
00614 }
00615 #if defined(WJSON)
00616 *out << "\t\t\t},\n";
00617 #endif
00618 }
00619
00620 void Evaluate(double * t, vec_grid_fct_type& U, grid_fct_type& Work)
00621 {
00622 int me;
00623 int Npoints;
00624
00625 char fname[256];
00626 std::ofstream outfile;
00627 std::ostream* out;
00628
00629 if ( group_table.size() == 0 ) return;
00630
00631 int TimeC = StepsTaken(base::GH(),0);
00632
00633
00634 int gcheck = 0;
00635 for ( typename stparser::grpvec::const_iterator g = group_table.begin() ;
00636 g != group_table.end(); g++) {
00637 if ( TimeC%((*g)->step) == 0 ) {
00638 gcheck = 1;
00639 break;
00640 }
00641 }
00642
00643 if ( gcheck == 0 ) return;
00644
00645 me = MY_PROC;
00646
00648 if (me == VizServer) {
00649 #if defined(WJSON)
00650 std::sprintf(fname,"%s%d.json",_OutputFile.c_str(),CurrentTime(base::GH(), 0));
00651 outfile.open(fname, std::ios::out );
00652 out = new std::ostream(outfile.rdbuf());
00653 #elif !defined(WJSON) && !defined(SJSON)
00654 std::sprintf(fname,"%s%d.dat",_OutputFile.c_str(),CurrentTime(base::GH(), 0));
00655 outfile.open(fname, std::ios::out );
00656 out = new std::ostream(outfile.rdbuf());
00657 #endif
00658
00659 #if defined(WJSON)
00660 *out << "{\n\t\"iter\": " << CurrentTime(base::GH(), 0) << ", \"time\": " << t[0] << "," << std::endl;
00661 #elif !defined(WJSON) && !defined(SJSON)
00662 *out << "# time " << t[0] << std::endl;
00663 #endif
00664 }
00665
00667 int ig = 1, iptr;
00668 for ( typename stparser::grpvec::const_iterator g = group_table.begin() ;
00669 g != group_table.end(); g++, ig++ ) {
00670
00671 int ipv = 0;
00672 if ( TimeC%((*g)->step) == 0 ) {
00673 if (me == VizServer) {
00674 #if defined(WJSON)
00675 *out << "\t\t\"group" << ig << "\": {"<< std::endl;
00676 #elif !defined(WJSON) && !defined(SJSON)
00677 *out << "# group " << ig << std::endl;
00678 #endif
00679
00680 }
00681
00683 Npoints = 0;
00684 for ( typename stparser::provec::const_iterator p = (*g)->probe_table.begin() ;
00685 p != (*g)->probe_table.end() ; p ++) {
00686 ipv = 0;
00687 switch ( (*p)->type ) {
00688 case TOK_THREAD:
00689 Npoints += (*p)->options.thread.na;
00690 break;
00691 case TOK_SURFACE:
00692 Npoints += (*p)->options.surface.na*(*p)->options.surface.nb;
00693 break;
00694 case TOK_PLANES:
00695 Npoints += (*p)->options.plane.na*(*p)->options.plane.nb;
00696 break;
00697 case TOK_VOLUME:
00698
00699 break;
00700 }
00701 }
00702
00703 point_type* CList = new point_type[Npoints];
00704 int cli=0;
00705
00706 for ( typename stparser::provec::const_iterator p = (*g)->probe_table.begin() ;
00707 p != (*g)->probe_table.end() ; p ++) {
00708 if ( buildcoords(*p) != RETURN_OK ) return;
00709 int Lpoints;
00710 switch ( (*p)->type ) {
00711 case TOK_THREAD:
00712 Lpoints = (*p)->options.thread.na;
00713 break;
00714 case TOK_SURFACE:
00715 Lpoints = (*p)->options.surface.na*(*p)->options.surface.nb;
00716 break;
00717 case TOK_PLANES:
00718 Lpoints = (*p)->options.plane.na*(*p)->options.plane.nb;
00719 break;
00720 case TOK_VOLUME:
00721
00722 break;
00723 }
00724 for (register int li=0; li<Lpoints; li++, cli++)
00725 CList[cli] = (*p)->coords[li];
00726 if (me == VizServer)
00727 (*p)->out = new std::stringstream(std::stringstream::in | std::stringstream::out);
00728 }
00729
00730 bool *lused = new bool[Npoints];
00731 int Level = 0;
00732 int Time = CurrentTime(base::GH(),Level);
00733 int NpUsed =_Interpolation->LocalPoints(Work,Time,Level,Npoints,CList,lused);
00734 point_type* CUList = new point_type[NpUsed];
00735 cli = 0;
00736 for (register int i=0; i<Npoints; i++)
00737 if (lused[i]) CUList[cli++] = CList[i];
00738 delete [] CList;
00739
00740 symrec *ptr, *ptr_ref;
00741
00742
00743 ptr = stparser::clonestack((*g)->sym_table);
00744
00745
00746 while ( ptr ) {
00747 #ifdef DEBUG_PRINT_STATISTICS
00748 (comm_service::log() << stparser::token(ptr->type) << "\n").flush();
00749 #endif
00750
00751 vectorize(ptr, NpUsed);
00752
00753
00754
00755
00756 switch( ptr->type ) {
00757 case TOK_OP_PLUS:
00758 vectorize(ptr->prev, NpUsed);
00759 vectorize(ptr->prev->prev, NpUsed);
00760 for ( register int l = 0 ; l < NpUsed ; l++ )
00761 ptr->pdata[l] = ptr->prev->prev->pdata[l] + ptr->prev->pdata[l];
00762 unlinksym(ptr->prev->prev);
00763 unlinksym(ptr->prev);
00764 break;
00765 case TOK_OP_MINUS:
00766 vectorize(ptr->prev, NpUsed);
00767 vectorize(ptr->prev->prev, NpUsed);
00768 for ( register int l = 0 ; l < NpUsed ; l++ )
00769 ptr->pdata[l] = ptr->prev->prev->pdata[l] - ptr->prev->pdata[l];
00770 unlinksym(ptr->prev->prev);
00771 unlinksym(ptr->prev);
00772 break;
00773 case TOK_OP_PROD:
00774 vectorize(ptr->prev, NpUsed);
00775 vectorize(ptr->prev->prev, NpUsed);
00776 for ( register int l = 0 ; l < NpUsed ; l++ )
00777 ptr->pdata[l] = ptr->prev->prev->pdata[l] * ptr->prev->pdata[l];
00778 unlinksym(ptr->prev->prev);
00779 unlinksym(ptr->prev);
00780 break;
00781 case TOK_OP_DIV:
00782 vectorize(ptr->prev, NpUsed);
00783 vectorize(ptr->prev->prev, NpUsed);
00784 for ( register int l = 0 ; l < NpUsed ; l++ )
00785 ptr->pdata[l] = ptr->prev->prev->pdata[l] / ptr->prev->pdata[l];
00786 unlinksym(ptr->prev->prev);
00787 unlinksym(ptr->prev);
00788 break;
00789 case TOK_OP_NEG:
00790 vectorize(ptr->prev, NpUsed);
00791 for ( register int l = 0 ; l < NpUsed ; l++ )
00792 ptr->pdata[l] = - ptr->prev->pdata[l];
00793 unlinksym(ptr->prev);
00794 break;
00795 case TOK_OP_POWER:
00796 vectorize(ptr->prev, NpUsed);
00797 vectorize(ptr->prev->prev, NpUsed);
00798 for ( register int l = 0 ; l < NpUsed ; l++ )
00799 ptr->pdata[l] = pow(ptr->prev->prev->pdata[l], ptr->prev->pdata[l]);
00800 unlinksym(ptr->prev->prev);
00801 unlinksym(ptr->prev);
00802 break;
00803 case TOK_POINTER:
00804 ptr_ref = ptr->ref;
00805 switch(ptr_ref->type) {
00806 case TOK_FUNCTION1:
00807 vectorize(ptr->prev, NpUsed);
00808 for ( register int l = 0 ; l < NpUsed ; l++ )
00809 ptr->pdata[l] = ((func_t1)ptr_ref->vdata.ptr)(ptr->prev->pdata[l]);
00810 unlinksym(ptr->prev);
00811 break;
00812 case TOK_FUNCTION2:
00813 vectorize(ptr->prev, NpUsed);
00814 vectorize(ptr->prev->prev, NpUsed);
00815 for ( register int l = 0 ; l < NpUsed ; l++ )
00816 ptr->pdata[l] = ((func_t2)ptr_ref->vdata.ptr)(ptr->prev->prev->pdata[l],
00817 ptr->prev->pdata[l]);
00818 unlinksym(ptr->prev->prev);
00819 unlinksym(ptr->prev);
00820 break;
00821 case TOK_VARINARRAY:
00822 case TOK_VARIABLE:
00823
00824
00825
00826
00827 if ( ptr_ref->type == TOK_VARINARRAY )
00828 iptr = ptr->vdata.iptr;
00829 else
00830 iptr = ptr_ref->vdata.iptr;
00831
00832
00833 if ( ptr_ref->src == STAT_DERIVED ) {
00834
00835 for (register int l=0; l<=FineLevel(base::GH()); l++) {
00836 int Time = CurrentTime(base::GH(),l);
00837
00838 _FileOutput->Transform(U, Work, Time, l, iptr, t[l]);
00839 }
00840 #ifdef DEBUG_PRINT_STATISTICS
00841 (comm_service::log() << " convert output\n" ).flush();
00842 #endif
00843 } else {
00844 int _dim = dim;
00845
00846 if ( _dim == 2 ) {
00847 for ( int Level = FineLevel(base::GH()) ; Level >= 0 ; Level --) {
00848 int Time = CurrentTime(base::GH(),Level);
00849 forall (U,Time,Level,c)
00850 Coords ss(U(Time,Level,c).bbox().stepsize());
00851 BBox bbi(U.boundingbbox(Time,Level,c));
00852 BeginFastIndex2(U, U(Time,Level,c).bbox(),
00853 U(Time,Level,c).data(), VectorType);
00854 BeginFastIndex2(Work, Work(Time,Level,c).bbox(),
00855 Work(Time,Level,c).data(), DataType);
00856 for_2 (i, j, bbi, ss)
00857 FastIndex2(Work,i,j) = FastIndex2(U,i,j)(iptr-1);
00858 end_for
00859 EndFastIndex2(U);
00860 EndFastIndex2(Work);
00861 end_forall
00862 }
00863 } else if ( _dim == 3 ) {
00864 for ( int Level = FineLevel(base::GH()) ; Level >= 0 ; Level --) {
00865 int Time = CurrentTime(base::GH(),Level);
00866 forall (U,Time,Level,c)
00867 Coords ss(U(Time,Level,c).bbox().stepsize());
00868 BBox bbi(U.boundingbbox(Time,Level,c));
00869 BeginFastIndex3(U, U(Time,Level,c).bbox(),
00870 U(Time,Level,c).data(), VectorType);
00871 BeginFastIndex3(Work, Work(Time,Level,c).bbox(),
00872 Work(Time,Level,c).data(), DataType);
00873 for_3 (i, j, k, bbi, ss)
00874 FastIndex3(Work,i,j,k) = FastIndex3(U,i,j,k)(iptr-1);
00875 end_for
00876 EndFastIndex3(U);
00877 EndFastIndex3(Work);
00878 end_forall
00879 }
00880 }
00881 #ifdef DEBUG_PRINT_STATISTICS
00882 (comm_service::log() << " convert array\n" ).flush();
00883 #endif
00884 }
00885
00886 _Interpolation->PointsValues(Work,t[0],NpUsed,CUList,ptr->pdata);
00887 #ifdef DEBUG_PRINT_STATISTICS
00888 (comm_service::log() << "after\n" ).flush();
00889 #endif
00890 break;
00891 case TOK_COORDINATE:
00892 {
00893 int iptr = (ptr_ref->vdata.iptr)-1;
00894 if ( iptr >= dim ) {
00895 staterror("invalid coordinate in this stack");
00896 return;
00897 }
00898 for ( register int l = 0 ; l < NpUsed ; l++ )
00899 ptr->pdata[l] = CUList[l](iptr);
00900 }
00901 break;
00902 default:
00903 staterror("there should not be any other pointer type left in this stack");
00904 return;
00905 }
00906
00907 break;
00908
00909 case TOK_SEPARATOR:
00910
00911 {
00912 int na, nb, avea, aveb;
00913 vectorize(ptr->prev, NpUsed);
00914
00915 cli=0;
00916 int ip = 1;
00917 int ccli=0;
00918 for ( typename stparser::provec::const_iterator p = (*g)->probe_table.begin() ;
00919 p != (*g)->probe_table.end() ; p ++, ip++ ) {
00920
00921 int Lpoints;
00922
00923 switch((*p)->type) {
00924 case TOK_THREAD:
00925 Lpoints = (*p)->options.thread.na;
00926 if ( (*p)->options.thread.ave == STAT_AVERAGED ) {
00927 double sum = 0.0, rsum;
00928 for ( register int ipl = 0 ; ipl < Lpoints ; ipl ++ )
00929 if (lused[ipl+cli])
00930 sum += ptr->prev->pdata[ccli++];
00931 MPI_Reduce(&sum, &rsum, 1, MPI_DOUBLE, MPI_SUM, VizServer, comm_service::comm());
00932 if (me == VizServer)
00933 *(*p)->out << (rsum/Lpoints) << std::endl;
00934 } else {
00935 double *adata = new double[Lpoints];
00936 for ( register int ipl = 0 ; ipl < Lpoints ; ipl ++ )
00937 if (lused[ipl+cli])
00938 adata[ipl] = ptr->prev->pdata[ccli++];
00939 else
00940 adata[ipl] = _Interpolation->ErrorValue();
00941 _Interpolation->ArrayCombine(VizServer, Lpoints, adata);
00942 if (me == VizServer) {
00943 double *result = 0;
00944 int ti = 0;
00945 for (register int i = 0; i < MAXSTATOPS; i++)
00946 if ( statOp[0][i] == ig ) {
00947
00948 if ( statOp[1][i] == ip) {
00949
00950 if ( statOp[2][i] == ipv) {
00951
00952
00953
00954 ti = i;
00955 if (statOp[3][i] < 4) {
00956 result = new double;
00957 CalcStat(statOp[3][i], Lpoints, adata, result);
00958 }
00959 else if (statOp[3][i] == 4) {
00960
00961
00962
00963 }
00964
00965 }
00966 }
00967 }
00968
00969 for ( register int ipl = 0 ; ipl < Lpoints ; ipl ++ ) {
00970
00971 *(*p)->out << adata[ipl] << " ";
00972 }
00973 #if defined SJSON
00974
00975 if (_SepFiles == 1) {
00976 int write = 1;
00977 int gtest = 1;
00978 if (_NumGrads > 1 ) gtest = _NumGrads-1;
00979 for (register int n = 0; n < gtest; n++) {
00980 if (ig == GradGroup[n]) {
00981 write = 0;
00982 }
00983 if (write == 1) {
00984 char sfname[256];
00985 std::ofstream sepOut;
00986 std::sprintf(sfname,"%s%d_%d_%d_%d.json",_OutputFile.c_str(), ig, ip, ipv, CurrentTime(base::GH(), 0) );
00987 std::cout << " *** Writing " << sfname << std::endl;
00988 sepOut.open(sfname, std::ios::out );
00989 sepOut << "{\n\t\"iter\": " << CurrentTime(base::GH(), 0) << ", \"time\": " << t[0] << "," << std::endl;
00990 sepOut << "\t\"VAR"<<ipv<<"\": [ ";
00991 for ( register int ipl = 0 ; ipl < Lpoints-1 ; ipl ++ ) {
00992 sepOut << adata[ipl] << ", ";
00993
00994 }
00995 sepOut << adata[Lpoints-1] << " ]\n}";
00996 sepOut.close();
00997 }
00998 }
00999 }
01000 #endif
01001
01002 if (result) {
01003 if (statOp[3][ti] < 4) {
01004 *(*p)->out << *result << " ";
01005
01006 }
01007 else if (statOp[3][ti] == 4) {
01008 *(*p)->out << *result << " ";
01009
01010
01011
01012 }
01013 }
01014 #ifndef SJSON
01015 *(*p)->out << std::endl;
01016 #endif
01017 ipv++;
01018 delete [] result;
01019 }
01020 delete [] adata;
01021 }
01022 break;
01023 case TOK_SURFACE:
01024 Lpoints = (*p)->options.surface.na*(*p)->options.surface.nb;
01025 avea = (*p)->options.surface.avea;
01026 aveb = (*p)->options.surface.aveb;
01027 na = (*p)->options.surface.na;
01028 nb = (*p)->options.surface.nb;
01029 case TOK_PLANES:
01030 if ( (*p)->type == TOK_PLANES ) {
01031 Lpoints = (*p)->options.plane.na*(*p)->options.plane.nb;
01032 avea = STAT_AVERAGED;
01033 aveb = STAT_AVERAGED;
01034 na = (*p)->options.plane.na;
01035 nb = (*p)->options.plane.nb;
01036 }
01037
01038 if ( avea == STAT_AVERAGED && aveb == STAT_AVERAGED ) {
01039 double sum = 0.0, rsum;
01040 for ( register int ip = 0 ; ip < Lpoints ; ip ++ )
01041 if (lused[ip+cli])
01042 sum += ptr->prev->pdata[ccli++];
01043 MPI_Reduce(&sum, &rsum, 1, MPI_DOUBLE, MPI_SUM, VizServer, comm_service::comm());
01044 if (me == VizServer)
01045 *(*p)->out << (rsum/Lpoints) << std::endl;
01046 } else {
01047 double *adata = new double[Lpoints];
01048 for ( register int j = 0 ; j < nb ; j++ )
01049 for ( register int i = 0 ; i < na ; i++ )
01050 if (lused[i+j*na+cli])
01051 adata[i+j*na] = ptr->prev->pdata[ccli++];
01052 else
01053 adata[i+j*na] = _Interpolation->ErrorValue();
01054
01055 if ( avea == STAT_RAW && aveb == STAT_AVERAGED ) {
01056 for ( register int i = 0 ; i < na ; i++ ) {
01057 double sum=0.0, rsum;
01058 for ( register int j = 0 ; j < nb ; j++ )
01059 if (adata[i+j*na]!=_Interpolation->ErrorValue())
01060 sum += adata[i+j*na];
01061 MPI_Reduce(&sum, &rsum, 1, MPI_DOUBLE, MPI_SUM, VizServer, comm_service::comm());
01062 if (me == VizServer)
01063 *(*p)->out << (rsum/nb) << " ";
01064 }
01065 #if !defined(WJSON) && !defined(SJSON)
01066 if (me == VizServer)
01067 *(*p)->out << std::endl;
01068 #endif
01069 } else if ( avea == STAT_AVERAGED && aveb == STAT_RAW ) {
01070 for ( register int j = 0 ; j < nb ; j++ ) {
01071 double sum=0.0, rsum;
01072 for ( register int i = 0 ; i < na ; i++ )
01073 if (adata[i+j*na]!=_Interpolation->ErrorValue())
01074 sum += adata[i+j*na];
01075 MPI_Reduce(&sum, &rsum, 1, MPI_DOUBLE, MPI_SUM, VizServer, comm_service::comm());
01076 if (me == VizServer)
01077 *(*p)->out << (rsum/na) << " ";
01078 }
01079 #if !defined(WJSON) && !defined(SJSON)
01080 if (me == VizServer)
01081 *(*p)->out << std::endl;
01082 #endif
01083 } else {
01084 _Interpolation->ArrayCombine(VizServer, Lpoints, adata);
01085 if (me == VizServer) {
01086
01087 #ifdef WJSON
01088
01089
01090 *(*p)->out << "\t\t\t\t\"VAR"<<ipv<<"\": [ ";
01091 for ( register int ipl = 0 ; ipl < Lpoints ; ipl ++ ) {
01092 *(*p)->out << adata[ipl];
01093 if (ipl<Lpoints-1) *(*p)->out << ", ";
01094
01095 }
01096 if (ipv<GroupVars[ig-1]-1 ) *(*p)->out << " ],";
01097 else *(*p)->out << " ]";
01098 #elif defined(SJSON)
01099
01100 if (_SepFiles == 1) {
01101 int write = 1;
01102 int gtest = 1;
01103 if (_NumGrads > 1 ) gtest = _NumGrads-1;
01104 for (register int n = 0; n < gtest; n++) {
01105
01106 if (ig == GradGroup[n]) {
01107 write = 0;
01108 }
01109 if (write == 1) {
01110 char sfname[256];
01111 std::ofstream sepOut;
01112 std::sprintf(sfname,"%s%d_%d_%d_%d.json",_OutputFile.c_str(), ig, ip, ipv, CurrentTime(base::GH(), 0) );
01113 std::cout << " *** Writing " << sfname << std::endl;
01114 sepOut.open(sfname, std::ios::out );
01115 sepOut << "{\n\t\"iter\": " << CurrentTime(base::GH(), 0) << ", \"time\": " << t[0] << "," << std::endl;
01116 sepOut << "\t\"VAR"<<ipv<<"\": [ ";
01117 for ( register int ipl = 0 ; ipl < Lpoints-1 ; ipl ++ ) {
01118 sepOut << adata[ipl] << ", ";
01119
01120 }
01121 sepOut << adata[Lpoints-1] << " ]\n}";
01122 sepOut.close();
01123 }
01124 }
01125 }
01126
01127 #else
01128 for ( register int ipl = 0 ; ipl < Lpoints ; ipl ++ ) {
01129 *(*p)->out << adata[ipl] << " ";
01130
01131 }
01132 #endif
01133 double * result = 0;
01134 std::vector<double>stats;
01135
01136 for (register int i = 0; i < _NumStats; i++) {
01137 if ( statOp[0][i] == ig ) {
01138
01139 if ( statOp[1][i] == ip) {
01140
01141 if ( statOp[2][i] == ipv) {
01142 #ifdef STATS_DEBUG
01143 std::cout << " DO a Stat on group " << ig;
01144 std::cout << " on probe " << ip << std::endl;
01145 #endif
01146
01147 for (register int j = 0; j < _NumPerVar[i]; j++) {
01148 if (statOp[3+j][i] >= 0) {
01149 if (statOp[3+j][i] < 4) {
01150
01151 result = new double;
01152 CalcStat(statOp[3+j][i], Lpoints, adata, result);
01153 #if defined(WJSON) || defined(SJSON)
01154 if (j==0 && ipv==GroupVars[ig-1]-1 ) *(*p)->out << ",\n\t\t\t\t\"VAR"<< ipv <<"STAT" << j << "\": { \"type\": \"" << OpNames[statOp[3+j][i]] << "\", ";
01155 else *(*p)->out << "\n\t\t\t\t\"VAR"<< ipv <<"STAT" << j << "\": { \"type\": \"" << OpNames[statOp[3+j][i]] << "\", ";
01156
01157 if (j==_NumPerVar[i]-1 && ipv==GroupVars[ig-1]-1 ) *(*p)->out << "\"value\": " << result[0] << " }";
01158 else *(*p)->out << "\"value\": " << result[0] << " },";
01159 #else
01160 *(*p)->out << "\n# STAT " << statOp[3+j][i] << " :" << OpNames[statOp[3+j][i]] << "\n";
01161 *(*p)->out << result[0] << " ";
01162 #endif
01163
01164 }
01165 else if (statOp[3+j][i] == 4) {
01166
01167 result = new double[4];
01168 CalcStat(statOp[3+j][i], Lpoints, adata, result);
01169 #if defined(WJSON) || defined(SJSON)
01170 if (j==0 && ipv==GroupVars[ig-1]-1 ) *(*p)->out << ",\n\t\t\t\t\"VAR"<< ipv <<"STAT" << j << "\": { \"type\": \""<< OpNames[statOp[3+j][i]] << "\",";
01171 else *(*p)->out << "\n\t\t\t\t\"VAR"<< ipv <<"STAT" << j << "\": { \"type\": \""<< OpNames[statOp[3+j][i]] << "\",";
01172
01173 if (j==_NumPerVar[i]-1 && ipv==GroupVars[ig-1]-1 ) *(*p)->out << "\"value\": [ " << result[0] << ", " << result[1] << ", " << result[2] << ", " << result[3] << " ] }";
01174 else *(*p)->out << "\"value\": [ " << result[0] << ", " << result[1] << ", " << result[2] << ", " << result[3] << " ] },";
01175 #else
01176 *(*p)->out << "\n# STAT " << statOp[3+j][i] << " :" << OpNames[statOp[3+j][i]] << "\n";
01177 *(*p)->out << result[0] << " " << result[1] << " " << result[2] << " " << result[3];
01178 #endif
01179 }
01180 }
01181 }
01182 }
01183 }
01184 }
01185
01186 }
01187
01188
01189 for (register int n = 0; n <_NumGrads; n++) {
01190 int na, nb;
01191
01192
01193
01194
01195
01196
01197 if (GradGroup[n] == ig && ip == 1 && ipv == 0) {
01198 for (register int i = 0; i < dim; i++) {
01199 if (Grads[i][n]) {
01200 calcount[n] += 2;
01201 }
01202 }
01203
01204 }
01205
01206
01207 if (GradGroup[n] == ig && ipv == 0) {
01208 if ( (*p)->type == TOK_SURFACE ) {
01209 na = (*p)->options.surface.na;
01210 nb = (*p)->options.surface.nb;
01211 } else if ((*p)->type == TOK_PLANES ) {
01212 na = (*p)->options.plane.na;
01213 nb = (*p)->options.plane.nb;
01214 }
01215
01216
01217
01218
01219
01220
01221
01222
01223
01224
01225
01226
01227 ctmp[ip-1].clear();
01228 std::copy( &(*p)->coords[0], &(*p)->coords[na*nb-1], back_inserter(ctmp[ip-1]) );
01229 }
01230
01231
01232
01233 if (Grads[(ip)/2][n] && GradGroup[n] == ig ) {
01234 if (ip==1) {
01235
01236
01237 }
01238 else {
01239 dircheck[(ip-2)/2] = 1;
01240
01241
01242 }
01243
01244 std::copy( adata, adata + Lpoints, back_inserter(ftmp[ip-1]) );
01245 gcount[n]++;
01246
01247
01248
01249
01250
01251 if ( gcount[n] == GradVars[n]*calcount[n] && ip == (*g)->probe_table.size() && ipv+1 == GradVars[n] ) {
01252 #ifdef SJSON
01253 CalcGradient(ig,dircheck,GradVars[n],Lpoints,na,nb,ctmp,ftmp,TimeC,t,curltog[n],wvtog[n],uwtog[n],vutog[n]);
01254 #else
01255 CalcGradient(ig,dircheck,GradVars[n],Lpoints,na,nb,ctmp,ftmp,TimeC,t,out,curltog[n],wvtog[n],uwtog[n],vutog[n]);
01256 #endif
01257 calcount[n] = 1;
01258 gcount[n] = 0;
01259 ipv=0;
01260 for (register int cp=0; cp<2*dim+1; cp++)
01261 ftmp[cp].clear();
01262
01263 }
01264
01265 }
01266 }
01267
01268 #ifndef SJSON
01269 *(*p)->out << std::endl;
01270 #endif
01271
01272 delete [] result;
01273 }
01274 }
01275 delete [] adata;
01276 }
01277 break;
01278 case TOK_VOLUME:
01279 break;
01280 }
01281 cli += Lpoints;
01282 clearcoords(*p);
01283
01284 }
01285 ipv++;
01286 unlinksym(ptr->prev);
01287 }
01288 #ifndef DAGH_NO_MPI
01289 MPI_Barrier(comm_service::comm());
01290 #endif
01291 break;
01292 case TOK_FUNCTION1:
01293 case TOK_FUNCTION2:
01294 case TOK_VARINARRAY:
01295 case TOK_VARIABLE:
01296 case TOK_COORDINATE:
01297 staterror("there should not be any pointer type tokens"
01298 " left in the stack");
01299 return;
01300 default:
01301 if ( ptr->type != TOK_DOUBLE ) {
01302 staterror("unhandled stack token");
01303 return;
01304 }
01305 break;
01306 }
01307
01308 if ( ptr->type == TOK_SEPARATOR ) {
01309 ptr_ref = ptr->next;
01310 unlinksym(ptr);
01311 ptr = ptr_ref;
01312 } else {
01313 ptr->type = TOK_DOUBLE;
01314 ptr = ptr->next;
01315 }
01316
01317 #ifdef DEBUG_PRINT_STATISTICS
01318 (comm_service::log() << " end of token switch\n" ).flush();
01319 #endif
01320 }
01321 delete [] lused;
01322 delete [] CUList;
01323
01324 if (me == VizServer) {
01325 int ip = 1;
01326 for ( typename stparser::provec::const_iterator p = (*g)->probe_table.begin() ;
01327 p != (*g)->probe_table.end() ; p ++, ip++) {
01328 #ifdef WJSON
01329 *out << "\t\t\t\"probe" << stparser::token((*p)->type) << ip << "\": {" << std::endl;
01330 #elif !defined(WJSON) && !defined(SJSON)
01331 *out << "# probe " << stparser::token((*p)->type) << " " << ip << std::endl;
01332 ( *out << (*p)->out->str() ).flush();;
01333 #endif
01334 #ifdef WJSON
01335 if (ip<(*g)->probe_table.size()) *out << "\t\t\t},\n";
01336 else {
01337 *out << "\t\t\t}\n";
01338 if (ig<group_table.size()) *out << "\t\t},\n";
01339
01340 else *out << "\t\t}\n}";
01341 }
01342 #endif
01343 delete (*p)->out;
01344 }
01345 }
01346 }
01347 }
01348
01349
01350 #ifndef SJSON
01351 if (me == VizServer) {
01352 outfile.close();
01353 delete out;
01354 }
01355 #endif
01356 }
01357
01358 private:
01359 int _DumpMeshes;
01360 int _Step;
01361 ControlDevice LocCtrl;
01362 std::string _OutputFile;
01363 std::string _DefFile;
01364
01365 OutputType* _FileOutput;
01366 InterpolationType* _Interpolation;
01367
01368 int _NumStats, _NumPerVar[MAXSTATOPS];
01369 int statOp[3+MAXPERVAR][MAXSTATOPS];
01370
01371 int _NumGrads, GradGroup[MAXGRADS], GradVars[MAXGRADS], Grads[dim][MAXGRADS];
01372 std::vector<std::vector <double> > ftmp;
01373 std::vector<std::vector <point_type> > ctmp;
01374 int gcount[MAXGRADS], calcount[MAXGRADS], curltog[MAXGRADS], wvtog[MAXGRADS], uwtog[MAXGRADS], vutog[MAXGRADS];
01375 int dircheck[dim];
01376
01377 std::vector<std::string> OpNames;
01378 int GroupVars[MAXGROUPS];
01379
01380 int _SepFiles;
01381 };
01382
01383 #endif