void avtTimeIteratorExpression::Execute(void) { FinalizeTimeLoop(); avtContract_p contract = ConstructContractWithVarnames(); contract->DisableExtentsCalculations(); // Store off the original expression list. ParsingExprList *pel = ParsingExprList::Instance(); ExpressionList orig_list = *(pel->GetList()); InitializeOutput(); std::string db = GetInput()->GetInfo().GetAttributes().GetFullDBName(); ref_ptr<avtDatabase> dbp = avtCallback::GetDatabase(db, 0, NULL); if (*dbp == NULL) EXCEPTION1(InvalidFilesException, db.c_str()); // The first EEF already set up its expressions ... we need a new one // to set up filters for the CMFE expressions. avtExpressionEvaluatorFilter myeef; myeef.SetInput(GetInput()); for (int i = 0 ; i < numTimeSlicesToProcess ; i++) { int timeSlice = firstTimeSlice + i*timeStride; if (timeSlice > actualLastTimeSlice) timeSlice = actualLastTimeSlice; debug1 << "Time iterating expression working on time slice " << timeSlice << endl; UpdateExpressions(timeSlice); // won't re-execute without setting modified to true, because // it doesn't check to see if expression definitions change. myeef.ReleaseData(); myeef.GetOutput()->Update(contract); avtCallback::ResetTimeout(5*60); Barrier(); avtCallback::ResetTimeout(5*60); avtDatabaseMetaData *md = dbp->GetMetaData(timeSlice, false, false, false); currentCycle = md->GetCycles()[timeSlice]; currentTime = md->GetTimes()[timeSlice]; ProcessDataTree(myeef.GetTypedOutput()->GetDataTree(), i); debug1 << "Time iterating expression done working on time slice " << timeSlice << endl; } // Get the upstream filters back the way they are supposed to be. GetInput()->Update(executionContract); FinalizeOutput(); // Restore the original expression list ... i.e. undo the temporary // expressions we put in. *(pel->GetList()) = orig_list; }
void avtTimeIteratorExpression::UpdateExpressions(int ts) { ParsingExprList *pel = ParsingExprList::Instance(); ExpressionList new_list = *(pel->GetList()); int nvars = varnames.size(); if (cmfeType == POS_CMFE) nvars--; for (int i = 0 ; i < nvars ; i++) { // No new expression has to be made in this case. if (VariableComesFromCurrentTime(i)) continue; std::string meshname = GetInput()->GetInfo().GetAttributes().GetMeshname(); char expr_defn[1024]; if (cmfeType == CONN_CMFE) { SNPRINTF(expr_defn, 1024, "conn_cmfe(<[%d]i:%s>, <%s>)", ts, varnames[i].c_str(), meshname.c_str()); } else { int defVarIndex = varnames.size()-1; SNPRINTF(expr_defn, 1024, "pos_cmfe(<[%d]i:%s>, <%s>, %s)", ts, varnames[i].c_str(), meshname.c_str(), varnames[defVarIndex].c_str()); } std::string exp_name = GetInternalVarname(i); bool alreadyInList = false; for (int j = 0 ; j < new_list.GetNumExpressions() ; j++) { if (new_list[j].GetName() == exp_name) { alreadyInList = true; new_list[j].SetDefinition(expr_defn); } } if (!alreadyInList) { Expression exp; exp.SetName(exp_name); exp.SetDefinition(expr_defn); exp.SetType(Expression::Unknown); new_list.AddExpressions(exp); } } *(pel->GetList()) = new_list; }
int main(int argc, char *argv[]) { int i; bool parallel = false; #ifdef PARALLEL parallel = true; PAR_Init(argc, argv); #endif VisItInit::Initialize(argc, argv); // // Initialize the plugin readers. // DatabasePluginManager *dbmgr = new DatabasePluginManager; dbmgr->Initialize(DatabasePluginManager::Engine, parallel); dbmgr->LoadPluginsNow(); if (PAR_Rank() == 0) cerr << endl; // whitespace after some expected plugin loading errors if (argc < 4) { UsageAndExit(dbmgr, argv[0]); } string assumedFormat = ""; bool noOptions = false; bool doClean = false; bool disableMIR = false; bool disableExpressions = false; vector<string> vars; int target_chunks = -1; bool outputZonal = false; long long target_zones = -1; //EngineDatabasePluginInfo *edpir = NULL; if (argc > 4) { for (int i = 4 ; i < argc ; i++) { if (strcmp(argv[i], "-clean") == 0) doClean = true; else if (strcmp(argv[i], "-nomir") == 0) disableMIR = true; else if (strcmp(argv[i], "-noexpr") == 0) disableExpressions = true; else if (strcmp(argv[i], "-variable") == 0) { if ((i+1) >= argc) UsageAndExit(dbmgr, argv[0]); i++; vars.push_back(argv[i]); } else if (strcmp(argv[i], "-output_zonal") == 0) { outputZonal = true; } else if (strcmp(argv[i], "-target_chunks") == 0) { if ((i+1) >= argc) UsageAndExit(dbmgr, argv[0]); i++; target_chunks = atoi(argv[i]); } else if (strcmp(argv[i], "-target_zones") == 0) { if ((i+1) >= argc) UsageAndExit(dbmgr, argv[0]); i++; target_zones = 0; int nchars = strlen(argv[i]); for (int j = 0 ; j < nchars ; j++) { if (isdigit(argv[i][j])) { target_zones *= 10; target_zones += argv[i][j] - '0'; } } } else if (strcmp(argv[i], "-assume_format") == 0) { if ((i+1) >= argc) UsageAndExit(dbmgr, argv[0]); i++; assumedFormat = argv[i]; } else if (strcmp(argv[i], "-no_options") == 0) noOptions = true; else { //Ignore.... } } } // // Handle read options if we need to. // HandleReadOptions(noOptions, dbmgr, argv[0], assumedFormat); // // Instantiate the database. // avtDatabase *db = NULL; vector<string> pluginList; TRY { if (strstr(argv[1], ".visit") != NULL) db = avtDatabaseFactory::VisitFile(dbmgr, argv[1], 0, pluginList); else db = avtDatabaseFactory::FileList(dbmgr, argv+1, 1, 0, pluginList); } CATCHALL { if (PAR_Rank() == 0) cerr << "The file " << argv[1] << " does not exist or could " << "not be opened." << endl; PAR_Exit(); exit(EXIT_FAILURE); } ENDTRY if (db == NULL) { if (PAR_Rank() == 0) cerr << "Could not open file " << argv[1] << ". Tried using plugins "; for (size_t i = 0 ; i < pluginList.size() ; i++) { if (PAR_Rank() == 0) { cerr << pluginList[i]; if (i != pluginList.size()-1) cerr << ", "; else cerr << endl; } } } // // Set the write options as the default. // Walk through the write options and have the user iterate over them // from the command line. [MCM] I believe predicating ONLY the FillOptions... // call on value of noOptions permits write options to flow from config // file settings correctly. // EngineDatabasePluginInfo *edpi = GetPluginInfo(dbmgr, argv[0], argv[3]); DBOptionsAttributes *opts = edpi->GetWriteOptions(); if (!noOptions) FillOptionsFromCommandline(opts); edpi->SetWriteOptions(opts); // // Make sure this format has a writer. // avtDatabaseWriter *wrtr = edpi->GetWriter(); if (wrtr == NULL) { if (PAR_Rank() == 0) cerr << "No writer defined for file type " << argv[3] << ".\n" << "Please see a VisIt developer." << endl; UsageAndExit(dbmgr, argv[0]); } if (doClean) wrtr->SetShouldAlwaysDoMIR(doClean); if (disableMIR) wrtr->SetShouldNeverDoMIR(disableMIR); if (disableExpressions) wrtr->SetShouldNeverDoExpressions(disableExpressions); if (target_zones > 0) { bool canDoIt = wrtr->SetTargetZones(target_zones); if (!canDoIt) { if (PAR_Rank() == 0) cerr << "This writer does not support the \"-target_zones\" option" << endl; UsageAndExit(dbmgr, argv[0]); } } if (target_chunks > 0) { bool canDoIt = wrtr->SetTargetChunks(target_chunks); if (!canDoIt) { if (PAR_Rank() == 0) cerr << "This writer does not support the \"-target_chunks\" " << "option" << endl; UsageAndExit(dbmgr, argv[0]); } } if (outputZonal) { bool canDoIt = wrtr->SetOutputZonal(outputZonal); if (!canDoIt) { if (PAR_Rank() == 0) cerr << "This writer does not support the \"-output_zonal\" " << "option" << endl; UsageAndExit(dbmgr, argv[0]); } } // // Figure out which mesh to operate on. // Assume MetaData for timestep 0 is sufficient for what we need here // const avtDatabaseMetaData *md = db->GetMetaData(0); //const avtMeshMetaData *mmd = NULL; string meshname = ""; if (md->GetNumMeshes() >= 1) { if (md->GetNumMeshes() > 1) { if (PAR_Rank() == 0) { cerr << "There are multiple meshes in the file. This program can " << "only\nhandle one mesh at a time. I am using mesh: "; cerr << md->GetMesh(0)->name << endl; } } meshname = md->GetMesh(0)->name; } else if (md->GetNumMeshes() < 1) { if (md->GetNumCurves() > 0) { if (PAR_Rank() == 0) cerr << "Cannot find any meshes, converting curves." << endl; meshname = md->GetCurve(0)->name; } else { if (PAR_Rank() == 0) cerr << "Cannot find any valid meshes or curves to convert.\n" << "Giving up." << endl; PAR_Exit(); exit(EXIT_FAILURE); } } #ifndef DISABLE_EXPRESSIONS // // Hook up the expressions we have associated with the database, so // we can get those as well. // Parser *p = new ExprParser(new avtExprNodeFactory()); ParsingExprList *l = new ParsingExprList(p); ExpressionList *list = l->GetList(); for (i = 0 ; i < md->GetNumberOfExpressions() ; i++) { const Expression *e = md->GetExpression(i); list->AddExpressions(*e); } #endif if (PAR_Rank() == 0) cerr << "Operating on " << md->GetNumStates() << " timestep(s)." << endl; for (i = 0 ; i < md->GetNumStates() ; i++) { avtDataObject_p dob = db->GetOutput(meshname.c_str(), i); #ifndef DISABLE_EXPRESSIONS avtExpressionEvaluatorFilter eef; eef.SetInput(dob); dob = eef.GetOutput(); #endif wrtr->SetInput(dob); char filename[1024]; if (strstr(argv[2], "%") != NULL) sprintf(filename, argv[2], i); else if (md->GetNumStates() == 1) strcpy(filename, argv[2]); else sprintf(filename, "%04d.%s", i, argv[2]); TRY { if (vars.size()) { wrtr->Write("", filename, md, vars, false); } else { wrtr->Write(filename, md); } } CATCH2(VisItException, e) { if (PAR_Rank() == 0) { cerr << "Error encountered. Unable to write files." << endl; cerr << "Error was: " << endl; cerr << e.Message() << endl; } break; } ENDTRY } delete dbmgr; #ifdef PARALLEL PAR_Exit(); #endif return 0; }
void avtTraceHistoryFilter::PerformIteration(int time, avtDataset_p &ds, bool doDisp) { int i; // Store off the original expression list. ParsingExprList *pel = ParsingExprList::Instance(); ExpressionList orig_list = *(pel->GetList()); avtContract_p spec = GetGeneralContract(); avtDataRequest_p dataRequest = spec->GetDataRequest(); int timestep = dataRequest->GetTimestep(); int newTimeIndex = timestep-time; if (newTimeIndex < 0) { EXCEPTION1(VisItException, "You asked to trace back before the first" " dump."); } ExpressionList new_list = *(pel->GetList()); std::vector<std::string> vars = atts.GetVars(); for (i = 0 ; i < vars.size () ; i++) { AddExpression(new_list, vars[i], newTimeIndex); } if (doDisp) AddExpression(new_list, atts.GetDisplacement(), newTimeIndex); *(pel->GetList()) = new_list; avtSourceFromAVTDataset termsrc(ds); avtDataObject_p data = termsrc.GetOutput(); avtExpressionEvaluatorFilter eef; eef.SetInput(data); avtDataRequest_p dataRequest2 = new avtDataRequest(dataRequest); for (i = 0 ; i < vars.size() ; i++) { char exp_name[1024]; SNPRINTF(exp_name, 1024, "AVT_TRACE_HIST_%s", vars[i].c_str()); dataRequest2->AddSecondaryVariable(exp_name); } if (doDisp) { char disp_name[1024]; SNPRINTF(disp_name, 1024, "AVT_TRACE_HIST_%s", atts.GetDisplacement().c_str()); avtDisplaceFilter disp; disp.SetInput(eef.GetOutput()); disp.SetVariable(disp_name); disp.SetFactor(1.); dataRequest2->AddSecondaryVariable(disp_name); avtContract_p spec2 = new avtContract(spec, dataRequest2); disp.Update(spec2); ds = disp.GetTypedOutput(); } else { avtContract_p spec2 = new avtContract(spec, dataRequest2); eef.Update(spec2); ds = eef.GetTypedOutput(); } // Restore the original expression list ... i.e. undo the temporary // expressions we put in. *(pel->GetList()) = orig_list; }