/* Called to handle case 3 from VisItDetectInput where we have console * input that needs to be processed in order to accomplish an action. */ void ProcessConsoleCommand(simulation_data *sim) { /* Read A Command */ char cmd[1000]; if (sim->par_rank == 0) { if(VisItReadConsole(1000, cmd) == VISIT_ERROR) { sprintf(cmd, "quit"); printf("quit\n"); } } #ifdef PARALLEL /* Broadcast the command to all processors. */ MPI_Bcast(cmd, 1000, MPI_CHAR, 0, sim->par_comm); #endif if(strcmp(cmd, "quit") == 0) sim->done = 1; else if(strcmp(cmd, "halt") == 0) sim->runMode = SIM_STOPPED; else if(strcmp(cmd, "step") == 0) simulate_one_timestep(sim); else if(strcmp(cmd, "run") == 0) sim->runMode = SIM_RUNNING; else if(strcmp(cmd, "update") == 0) { VisItTimeStepChanged(); VisItUpdatePlots(); } }
/* Callback function for control commands, which are the buttons in the * GUI's Simulation window. This type of command is handled automatically * provided that you have registered a command callback such as this. */ void SimControlCommandCallback(const char *cmd, const char *args, void *cbdata) { simulation_data *sim = (simulation_data *)cbdata; if(strcmp(cmd, "quit") == 0) sim->done = 1; else if(strcmp(cmd, "halt") == 0) sim->runMode = SIM_STOPPED; else if(strcmp(cmd, "step") == 0) { simulation_data_update(sim); simulation_advance(sim); VisItTimeStepChanged(); VisItUpdatePlots(); } else if(strcmp(cmd, "run") == 0) sim->runMode = SIM_RUNNING; if(sim->echo && sim->par_rank == 0) { fprintf(stderr, "Command '%s' completed.\n", cmd); fflush(stderr); } }
/* Called to handle case 3 from VisItDetectInput where we have console * input that needs to be processed in order to accomplish an action. */ void ProcessConsoleCommand(simulation_data *sim) { /* Read A Command */ char cmd[1000]; int iseof = (fgets(cmd, 1000, stdin) == NULL); if (iseof) { sprintf(cmd, "quit"); printf("quit\n"); } if (strlen(cmd)>0 && cmd[strlen(cmd)-1] == '\n') cmd[strlen(cmd)-1] = '\0'; if(strcmp(cmd, "quit") == 0) sim->done = 1; else if(strcmp(cmd, "halt") == 0) sim->runMode = SIM_STOPPED; else if(strcmp(cmd, "step") == 0) simulate_one_timestep(sim); else if(strcmp(cmd, "run") == 0) sim->runMode = SIM_RUNNING; else if(strcmp(cmd, "update") == 0) { VisItTimeStepChanged(); VisItUpdatePlots(); } }
void simulate_one_timestep(simulation_data *sim) { ++sim->cycle; if(sim->cycle == NUMBER_OF_ITERATIONS) { sim->done = 1; } sim->time += .01; /* Simulate the current round of grid. */ if(calculate) data_simulate(&sim->grid, sim->par_rank, sim->par_size, sim->time); #ifdef VISIT_INSITU if(sim->updateplots) { VisItTimeStepChanged(); VisItUpdatePlots(); } if(sim->savingFiles) { char filename[100]; sprintf(filename, "/scratch/eiger/jfavre/updateplots1k%04d.jpg", sim->saveCounter); if(VisItSaveWindow(filename, 128, 128, VISIT_IMAGEFORMAT_JPEG) == VISIT_OKAY) { sim->saveCounter++; if(sim->par_rank == 0) printf("Saved %s\n", filename); } else if(sim->par_rank == 0) printf("The image could not be saved to %s\n", filename); } #endif }
/* SIMULATE ONE TIME STEP */ void simulate_one_timestep(simulation_data *sim) { ++sim->cycle; sim->time += 0.0134; printf("Simulating time step: cycle=%d, time=%lg\n", sim->cycle, sim->time); sim_sleep(1); VisItTimeStepChanged(); }
void ui_run_clicked(void *cbdata) { simulation_data *sim = (simulation_data *)cbdata; sim->runMode = SIM_RUNNING; if(rank==0) printf("run from gui\n"); VisItTimeStepChanged(); }
void ui_halt_clicked(void *cbdata) { simulation_data *sim = (simulation_data *)cbdata; sim->runMode = SIM_STOPPED; if(rank==0) printf("halt from gui\n"); VisItTimeStepChanged(); }
/****************************************************************************** * * Purpose: This function simulates one time step * * Programmer: Brad Whitlock * Date: Mon Aug 13 11:42:47 PDT 2012 * * Modifications: * *****************************************************************************/ void simulate_one_timestep(simulation_data *sim) { ++sim->cycle; sim->time += (M_PI / 10.); if(sim->par_rank == 0) printf("Simulating time step: cycle=%d, time=%lg\n", sim->cycle, sim->time); VisItTimeStepChanged(); VisItUpdatePlots(); }
void ui_A_changed(int value, void *cbdata) { // simulation_data *sim = (simulation_data *)cbdata; real_t maxp=0.1; real_t minp=-0.1; char buffer [50]; paramA=value/100.0*(maxp-minp)+minp; sprintf(buffer,"%g",paramA); VisItUI_setValueS("ATEXT",buffer,0); //printf("core:%d\t ui_A_changed: %g\n",rank,paramA); VisItTimeStepChanged(); }
/* Called to handle case 3 from VisItDetectInput where we have console * input that needs to be processed in order to accomplish an action. */ void ProcessConsoleCommand(simulation_data *sim) { /* Read A Command */ char cmd[1000]; VisItUI_valueChanged("Mu", ui_Mu_changed, &sim); VisItUI_valueChanged("A", ui_A_changed, &sim); if (sim->par_rank == 0) { int iseof = (fgets(cmd, 1000, stdin) == NULL); if (iseof) { sprintf(cmd, "quit"); printf("quit\n"); } if (strlen(cmd)>0 && cmd[strlen(cmd)-1] == '\n') cmd[strlen(cmd)-1] = '\0'; } /* Broadcast the command to all processors. */ MPI_Bcast(cmd, 1000, MPI_CHAR, 0, MPI_COMM_WORLD); if(strcmp(cmd, "quit") == 0) sim->done = 1; else if(strcmp(cmd, "halt") == 0) sim->runMode = SIM_STOPPED; else if(strcmp(cmd, "step") == 0) simulate_one_timestep(sim); else if(strcmp(cmd, "run") == 0) sim->runMode = SIM_RUNNING; else if(strcmp(cmd, "raz") == 0) init_fields(); else if(strcmp(cmd, "update") == 0) { VisItTimeStepChanged(); VisItUpdatePlots(); } else if(strcmp(cmd, "saveon") == 0) sim->savingFiles = 1; else if(strcmp(cmd, "saveoff") == 0) sim->savingFiles = 0; else if(strcmp(cmd, "addplot") == 0) { VisItExecuteCommand("AddPlot(\"Pseudocolor\", \"zonal\")\n"); VisItExecuteCommand("DrawPlots()\n"); } }
void ui_Mu_changed(int value, void *cbdata) { // simulation_data *sim = (simulation_data *)cbdata; char buffer [50]; paramMu=value/100.0*2 -1.0; if( !rank ) { fprintf( stderr, "\tparamMu= %g\n", paramMu); fflush(stderr); sprintf(buffer,"%g",paramMu); VisItUI_setValueS("MUTEXT",buffer,0); } // printf("core:%d\t ui_Mu_changed: %g\n",rank,paramMu); VisItTimeStepChanged(); }
/* Callback function for control commands, which are the buttons in the * GUI's Simulation window. This type of command is handled automatically * provided that you have registered a command callback such as this. */ void ControlCommandCallback(const char *cmd, const char *args, void *cbdata) { simulation_data *sim = (simulation_data *)cbdata; if(strcmp(cmd, "halt") == 0) sim->runMode = SIM_STOPPED; else if(strcmp(cmd, "step") == 0) simulate_one_timestep(sim); else if(strcmp(cmd, "run") == 0) sim->runMode = SIM_RUNNING; else if(strcmp(cmd, "update") == 0) { VisItTimeStepChanged(); VisItUpdatePlots(); } }
/****************************************************************************** * * Purpose: This function simulates one time step * * Programmer: Brad Whitlock * Date: Wed Feb 1 10:10:18 PST 2012 * * Modifications: * *****************************************************************************/ void simulate_one_timestep(simulation_data *sim) { int i; ++sim->cycle; sim->time += (M_PI / 10.); if(sim->par_rank == 0) printf("Simulating time step: cycle=%d, time=%lg\n", sim->cycle, sim->time); /* Update the variables */ for(i = 0; i < sim->nDomains; ++i) Domain_update_variable(&sim->domains[i], sim->time); VisItTimeStepChanged(); VisItUpdatePlots(); }
void simulate_one_timestep(simulation_data *sim) { int i, ncells; ++sim->cycle; sim->time += (M_PI / 10.); if(sim->par_rank == 0) printf("Simulating time step: cycle=%d, time=%lg\n", sim->cycle, sim->time); quadmesh_2d_create_radial_wave(&sim->blankRectMesh, sim->time); quadmesh_2d_create_radial_wave(&sim->blankCurvMesh, -sim->time); memcpy(sim->blankUcdMesh.data, sim->blankRectMesh.data, sim->blankUcdMesh.ncells * sizeof(float)); for(i = 0; i < 9; ++i) quadmesh_2d_create_radial_wave(&sim->multidomain[i].m, sim->time); VisItTimeStepChanged(); VisItUpdatePlots(); }
void mainloop_batch(simulation_data *sim) { char filebase[100]; const char *extractvars[] = {"q", "xc", "radius", NULL}; double origin[] = {5., 5., 5.}, normal[] = {0., 0.707, 0.707}; double isos[] = {0.2, 0.5, 0.8}; double v0[] = {1.,1.,1.}, v1[] = {5., 1.5, 7.}, v2[] = {8., 2., 5.}; /* Explicitly load VisIt runtime functions and install callbacks. */ VisItInitializeRuntime(); SetupCallbacks(sim); while(!sim->done) { /* Update the simulation data for this iteration.*/ simulation_data_update(sim); /* Tell VisIt that some metadata changed.*/ VisItTimeStepChanged(); /* Make some extracts. */ sprintf(filebase, "slice3v_%04d", sim->cycle); extract_slice_3v(filebase, v0, v1, v2, extractvars); sprintf(filebase, "sliceON_%04d", sim->cycle); extract_slice_origin_normal(filebase, origin, normal, extractvars); sprintf(filebase, "sliceX_%04d", sim->cycle); extract_slice(filebase, 0, 0.5, extractvars); sprintf(filebase, "sliceY_%04d", sim->cycle); extract_slice(filebase, 1, 2.5, extractvars); sprintf(filebase, "sliceZ_%04d", sim->cycle); extract_slice(filebase, 2, 5., extractvars); sprintf(filebase, "iso_%04d", sim->cycle); extract_iso(filebase, "q", isos, 3, extractvars); simulation_advance(sim); } }
/* Called to handle case 3 from VisItDetectInput where we have console * input that needs to be processed in order to accomplish an action. */ void ProcessConsoleCommand(simulation_data *sim) { int i; /* Read A Command */ char cmd[1000]; int iseof = (fgets(cmd, 1000, stdin) == NULL); if (iseof) { sprintf(cmd, "quit"); printf("quit\n"); } if (strlen(cmd)>0 && cmd[strlen(cmd)-1] == '\n') cmd[strlen(cmd)-1] = '\0'; if(strcmp(cmd, "quit") == 0) sim->done = 1; else if(strcmp(cmd, "halt") == 0) sim->runMode = SIM_STOPPED; else if(strcmp(cmd, "step") == 0) simulate_one_timestep(sim); else if(strcmp(cmd, "step25") == 0) { for (i = 0; i < 25; ++i) simulate_one_timestep(sim); } else if(strcmp(cmd, "run") == 0) sim->runMode = SIM_RUNNING; else if(strcmp(cmd, "update") == 0) { VisItTimeStepChanged(); VisItUpdatePlots(); } if (sim->echo) { fprintf(stderr, "Command %s completed.\n", cmd); fflush(stderr); } }
/****************************************************************************** * * Purpose: This function simulates one time step * * Programmer: Brad Whitlock * Date: Fri Jan 12 13:37:17 PST 2007 * * Modifications: * *****************************************************************************/ void simulate_one_timestep(simulation_data *sim) { int i; float x0, x1; ++sim->cycle; sim->time += (M_PI / 10.); if(sim->par_rank == 0) printf("Simulating time step: cycle=%d, time=%lg\n", sim->cycle, sim->time); /* Update the curve */ x0 = sim->par_rank * M_PI * 2; x1 = (sim->par_rank+1) * M_PI * 2; for(i = 0; i < sim->npts; ++i) { float x, y, t, angle; t = ((float)(i)) / ((float)(sim->npts - 1)); x = x0 + (x1 - x0) * t; angle = x + sim->time; y = sin(angle); sim->x[i] = x; sim->y[i] = y; sim->nodal[i] = i; if(i < sim->npts-1) sim->zonal[i] = i; } for(i = 0; i < sim->npts-1; ++i) { sim->conn[3*i] = VISIT_CELL_BEAM; sim->conn[3*i+1] = i; sim->conn[3*i+2] = i+1; } VisItTimeStepChanged(); VisItUpdatePlots(); }
void mainloop_interactive(simulation_data *sim) { int blocking, visitstate = 0, err = 0; /* If we're not running by default then simulate once there's something * once VisIt connects. */ if(sim->runMode == SIM_STOPPED) simulation_data_update(sim); if (sim->par_rank == 0) { fprintf(stderr, "command> "); fflush(stderr); } do { blocking = (sim->runMode == SIM_RUNNING) ? 0 : 1; /* Get input from VisIt or timeout so the simulation can run. */ if(sim->par_rank == 0) { visitstate = VisItDetectInput(blocking, fileno(stdin)); } #ifdef PARALLEL /* Broadcast the return value of VisItDetectInput to all procs. */ MPI_Bcast(&visitstate, 1, MPI_INT, 0, sim->par_comm); #endif /* Do different things depending on the output from VisItDetectInput. */ switch(visitstate) { case 0: /* There was no input from VisIt, return control to sim. */ simulation_data_update(sim); simulation_advance(sim); VisItTimeStepChanged(); VisItUpdatePlots(); break; case 1: /* VisIt is trying to connect to sim. */ if(VisItAttemptToCompleteConnection() == VISIT_OKAY) { fprintf(stderr, "VisIt connected\n"); /* Install callbacks */ SetupCallbacks(sim); } else { /* Print the error message */ char *err = VisItGetLastError(); fprintf(stderr, "VisIt did not connect: %s\n", err); free(err); } break; case 2: /* VisIt wants to tell the engine something. */ if(!SimProcessVisItCommand(sim)) { /* Disconnect on an error or closed connection. */ VisItDisconnect(); /* Start running again if VisIt closes. */ /*sim->runMode = SIM_RUNNING;*/ } break; case 3: /* VisItDetectInput detected console input - do something with it. * NOTE: you can't get here unless you pass a file descriptor to * VisItDetectInput instead of -1. */ mainloop_interactive_console_command(sim); if (sim->par_rank == 0) { fprintf(stderr, "command> "); fflush(stderr); } break; default: fprintf(stderr, "Can't recover from error %d!\n", visitstate); err = 1; break; } } while(!sim->done && err == 0); }