extern void marksources(void) /* find and mark source objects */ { int foundsource = 0; int i; register OBJREC *o, *m; register int ns; /* initialize dispatch table */ initstypes(); /* find direct sources */ for (i = 0; i < nsceneobjs; i++) { o = objptr(i); if (!issurface(o->otype) || o->omod == OVOID) continue; /* find material */ m = findmaterial(objptr(o->omod)); if (m == NULL) continue; if (m->otype == MAT_CLIP) { markclip(m); /* special case for antimatter */ continue; } if (!islight(m->otype)) continue; /* not source modifier */ if (m->oargs.nfargs != (m->otype == MAT_GLOW ? 4 : m->otype == MAT_SPOT ? 7 : 3)) objerror(m, USER, "bad # arguments"); if (m->oargs.farg[0] <= FTINY && m->oargs.farg[1] <= FTINY && m->oargs.farg[2] <= FTINY) continue; /* don't bother */ if (m->otype == MAT_GLOW && o->otype != OBJ_SOURCE && m->oargs.farg[3] <= FTINY) { foundsource += (ambounce > 0); continue; /* don't track these */ } if (sfun[o->otype].of == NULL || sfun[o->otype].of->setsrc == NULL) objerror(o, USER, "illegal material"); if ((ns = newsource()) < 0) goto memerr; setsource(&source[ns], o); if (m->otype == MAT_GLOW) { source[ns].sflags |= SPROX; source[ns].sl.prox = m->oargs.farg[3]; if (source[ns].sflags & SDISTANT) { source[ns].sflags |= SSKIP; foundsource += (ambounce > 0); } } else if (m->otype == MAT_SPOT) { source[ns].sflags |= SSPOT; if ((source[ns].sl.s = makespot(m)) == NULL) goto memerr; if (source[ns].sflags & SFLAT && !checkspot(source[ns].sl.s,source[ns].snorm)) { objerror(o, WARNING, "invalid spotlight direction"); source[ns].sflags |= SSKIP; } } #if SHADCACHE initobscache(ns); #endif foundsource += !(source[ns].sflags & SSKIP); } if (!foundsource) { error(WARNING, "no light sources found"); return; } markvirtuals(); /* find and add virtual sources */ /* allocate our contribution arrays */ maxcntr = nsources + MAXSPART; /* start with this many */ srccnt = (CONTRIB *)malloc(maxcntr*sizeof(CONTRIB)); cntord = (CNTPTR *)malloc(maxcntr*sizeof(CNTPTR)); if ((srccnt == NULL) | (cntord == NULL)) goto memerr; return; memerr: error(SYSTEM, "out of memory in marksources"); }
void write_vtkFile(const char *szProblem, int timeStepNumber, double xlength, double ylength, double zlength, int imax, int jmax, int kmax, double dx, double dy, double dz, double ***U, double ***V, double ***W, double ***P, int ***Flag) { int i,j,k; double uVel,vVel,wVel; char szFileName[80]; FILE *fp=NULL; sprintf( szFileName, "/media/norbert/940CB6150CB5F27A/Documents/simulation/%s.%i.vtk", szProblem, timeStepNumber ); //sprintf( szFileName, "/media/norbert/940CB6150CB5F27A/Documents/simulation/%s.%i.vtk", szProblem, timeStepNumber ); fp = fopen( szFileName, "w"); if( fp == NULL ) { char szBuff[80]; sprintf( szBuff, "Failed to open %s", szFileName ); ERROR( szBuff ); return; } write_vtkHeader(fp, imax, jmax, kmax, dx, dy, dz); write_vtkPointCoordinates(fp, imax, jmax, kmax, dx, dy, dz); fprintf(fp,"POINT_DATA %i \n", (imax+1)*(jmax+1)*(kmax+1) ); fprintf(fp,"\n"); fprintf(fp, "VECTORS velocity float\n"); for(k = 0; k < kmax+1; k++) { for(j = 0; j < jmax+1; j++) { for(i = 0; i < imax+1; i++) { //fprintf(fp, "%f %f %f\n", getValidValue((U[i][j][k] + U[i+1][j][k]) * 0.5), getValidValue((V[i][j][k] + V[i][j+1][k]) * 0.5), getValidValue((W[i][j][k] + W[i][j][k+1]) * 0.5) ); //fprintf(fp, "%f %f %f\n", getValidValue((U[i][j][k] + U[i][j+1][k]) * 0.5), getValidValue((V[i][j][k] + V[i+1][j][k]) * 0.5), getValidValue((W[i][j][k] + W[i][j][k+1]) * 0.5) ); uVel = getValidValue((U[i][j][k] + U[i][j+1][k] + U[i][j][k+1] + U[i][j+1][k+1]) * 0.25); vVel = getValidValue((V[i][j][k] + V[i+1][j][k] + V[i][j][k+1] + V[i+1][j][k+1]) * 0.25); wVel = getValidValue((W[i][j][k] + W[i+1][j][k] + W[i][j+1][k] + W[i+1][j+1][k]) * 0.25); fprintf(fp, "%f %f %f\n",uVel,vVel,wVel); } } } printf( "%f %f %f\n",uVel,vVel,wVel); fprintf(fp,"\n"); fprintf(fp,"CELL_DATA %i \n", ((imax)*(jmax)*(kmax)) ); fprintf(fp, "SCALARS pressure float 1 \n"); fprintf(fp, "LOOKUP_TABLE default \n"); for(k = 1; k < kmax+1; k++) { for(j = 1; j < jmax+1; j++) { for(i = 1; i < imax+1; i++) { fprintf(fp, "%f\n",getValidValue(P[i][j][k])); } } } fprintf(fp,"\n"); fprintf(fp, "SCALARS flag short 1 \n"); fprintf(fp, "LOOKUP_TABLE default \n"); for(k = 1; k < kmax+1; k++) { for(j = 1; j < jmax+1; j++) { for(i = 1; i < imax+1; i++) { if(issurface(Flag[i][j][k]) && isfluid(Flag[i][j][k])){ fprintf(fp, "20\n"); } else{ fprintf(fp, "%d\n",getcelltype(Flag[i][j][k])); } } } } if( fclose(fp) ) { char szBuff[80]; sprintf( szBuff, "Failed to close %s", szFileName ); ERROR( szBuff ); } }