void DummyModalSpatialSimple::update(openfluid::builderext::FluidXUpdateFlags::Flags /*UpdateFlags*/) { std::string DirStr; OPENFLUID_GetRunEnvironment("dir.input",DirStr); std::cout << OPENFLUID_GetWareID() << ", IN: " << DirStr << std::endl; OPENFLUID_GetRunEnvironment("dir.output",DirStr); std::cout << OPENFLUID_GetWareID() << ", OUT: " << DirStr << std::endl; }
void onPrepared() { OPENFLUID_GetRunEnvironment("dir.output",m_OutputDir); OPENFLUID_GetRunEnvironment("dir.input",m_InputDir); std::map<std::string, SerieInfo>::iterator Sit; std::map<std::string, SerieInfo>::iterator Sitb = m_Series.begin(); std::map<std::string, SerieInfo>::iterator Site = m_Series.end(); for (Sit = Sitb; Sit != Site; ++Sit) { if ((*Sit).second.Type == SerieInfo::SERIE_VAR) { (*Sit).second.FileHandle = new std::ofstream(std::string(m_OutputDir+"/"+(*Sit).second.SourceFile).c_str()); } } }
bool OGRGDALImportExtension::initialize() { std::string DirStr; OPENFLUID_GetRunEnvironment("dir.input",DirStr); m_InputDir = QString::fromStdString(DirStr); OPENFLUID_GetRunEnvironment("dir.temp",DirStr); m_TempDir = QString::fromStdString(DirStr); CPLSetErrorHandler(CPLOGRGDALErrorHandler); OGRRegisterAll(); if (OGRGetDriverByName("WFS") == NULL) ui->AddWFSButton->setEnabled(false); return true; }
bool GraphvizViewExtension::initialize() { #if defined(OPENFLUID_OS_WINDOWS) openfluid::utils::ExternalProgram DotProgram("dot.exe"); #else openfluid::utils::ExternalProgram DotProgram("dot"); #endif if (!DotProgram.isFound()) { QMessageBox::critical(this,QString("Error"),tr("GraphViz software (dot) cannot be found!\n" "Please make sure the dot program is accessible in the PATH\n" "and try launching this extension again."), QMessageBox::Close); return false; } std::string TmpDir; OPENFLUID_GetRunEnvironment("dir.temp",TmpDir); QDir().mkpath(QString::fromStdString(TmpDir)); m_GVFileName = QString("%1/graphviz-extension.gv").arg(QString::fromStdString(TmpDir)); m_SVGFileName = QString("%1/graphviz-extension.svg").arg(QString::fromStdString(TmpDir)); mp_GraphvizScene = new GraphvizScene(m_SVGFileName,this); ui->GraphView->setScene(mp_GraphvizScene); connect(mp_GraphvizScene,SIGNAL(changed(const QList<QRectF>)),this,SLOT(handleSceneChanged())); connect(ui->RankDirComboBox,SIGNAL(currentIndexChanged(int)),this,SLOT(launchSVGFileGeneration())); connect(ui->FitViewButton,SIGNAL(clicked()),ui->GraphView,SLOT(fitViewToItems())); connect(ui->PNGExportButton,SIGNAL(clicked()),ui->GraphView,SLOT(exportSceneAsPNG())); connect(ui->SVGExportButton,SIGNAL(clicked()),ui->GraphView,SLOT(exportSceneAsSVG())); return true; }
openfluid::base::SchedulingRequest ToolsSimulator::initializeRun() { openfluid::tools::ColumnTextParser CTParser("#"); std::string InputDir; double DoubleValue; std::string StrValue; OPENFLUID_GetRunEnvironment("dir.input",InputDir); std::string FileName = InputDir + "/" + "columnfile.txt"; if (openfluid::tools::Filesystem::isFile(FileName)) { CTParser.loadFromFile(FileName); if (CTParser.getColsCount() != 5) OPENFLUID_RaiseError("wrong columns number in " + FileName); if (!CTParser.getDoubleValue(2,1,&DoubleValue)) OPENFLUID_RaiseError("error reading double value (3,2) in " + FileName); if (!openfluid::scientific::isVeryClose(DoubleValue,1.2)) OPENFLUID_RaiseError("wrong double value for (3,2) in " + FileName); if (!CTParser.getStringValue(0,0,&StrValue)) OPENFLUID_RaiseError("error reading string value (0,0) in " + FileName); if (StrValue != "5") OPENFLUID_RaiseError("wrong string value for (0,0) in " + FileName); if (CTParser.getStringValue(5,5,&StrValue)) OPENFLUID_RaiseError("error : found value out of range (5,5) in " + FileName); } else OPENFLUID_RaiseError("file " + FileName + " not found!"); return DefaultDeltaT(); }
void prepareTempDirectory() { std::string TmpDir; OPENFLUID_GetRunEnvironment("dir.temp",TmpDir); m_TmpDir = openfluid::tools::Filesystem::makeUniqueSubdirectory(TmpDir,m_TmpSubDirRoot); openfluid::tools::Filesystem::makeDirectory(m_TmpDir); if (!openfluid::tools::Filesystem::isDirectory(m_TmpDir)) { OPENFLUID_LogWarning("Cannot initialize temporary directory"); m_OKToGo = false; return; } openfluid::tools::Filesystem::removeDirectory(m_TmpDir+"/"+m_KmzSubDir); openfluid::tools::Filesystem::makeDirectory(m_TmpDir+"/"+m_KmzSubDir); if (!openfluid::tools::Filesystem::isDirectory(m_TmpDir+"/"+m_KmzSubDir)) { OPENFLUID_LogWarning("Cannot initialize kmz temporary directory"); m_OKToGo = false; return; } openfluid::tools::Filesystem::makeDirectory(m_TmpDir+"/"+m_KmzSubDir+"/"+m_KmzDataSubDir); if (!openfluid::tools::Filesystem::isDirectory(m_TmpDir+"/"+m_KmzSubDir+"/"+m_KmzDataSubDir)) { OPENFLUID_LogWarning("Cannot initialize kmz data temporary directory"); m_OKToGo = false; return; } }
void initParams(const openfluid::ware::WareParams_t& Params) { openfluid::ware::WareParamsTree ParamsTree; try { ParamsTree.setParams(Params); } catch (openfluid::base::FrameworkException& E) { OPENFLUID_LogWarning(E.getMessage()); m_OKToGo = false; return; } OGRRegisterAll(); OPENFLUID_GetRunEnvironment("dir.input",m_InputDir); OPENFLUID_GetRunEnvironment("dir.output",m_OutputDir); // general try { m_Title = ParamsTree.root().getChildValue("title",m_Title); m_OutputFileName = ParamsTree.root().getChildValue("kmzfilename",m_OutputFileName); ParamsTree.root().getChildValue("tryopengearth",m_TryOpenGEarth).toBoolean(m_TryOpenGEarth); if (!ParamsTree.root().hasChild("layers")) { OPENFLUID_LogWarning("No layer defined"); m_OKToGo = false; return; } for (auto& Layer : ParamsTree.root().child("layers")) { KmlSerieInfo KSI; KSI.UnitsClass = Layer.second.getChildValue("unitsclass",""); if (KSI.UnitsClass == "") { // search for deprecated "unitclass" parameter KSI.UnitsClass = Layer.second.getChildValue("unitclass",""); } KSI.VarsListStr = Layer.second.getChildValue("varslist","*"); // TODO Manage selection of plotted spatial units Layer.second.getChildValue("linewidth",1).toInteger(KSI.LineWidth); KSI.DefaultColor = Layer.second.getChildValue("defaultcolor","ffffffff"); KSI.PlottedColor = Layer.second.getChildValue("plottedcolor","ff0000ff"); KSI.SourceIsDatastore = (Layer.second.getChildValue("source","file").get() == "datastore"); if (KSI.SourceIsDatastore) return; else { KSI.SourceFilename = Layer.second.getChildValue("sourcefile",""); if (KSI.SourceFilename.empty()) { OPENFLUID_LogWarning("wrong sourcefile format"); m_OKToGo = false; return; } KSI.SourceFilename = m_InputDir + "/" + KSI.SourceFilename; } if (transformVectorLayerToKmlGeometry(KSI)) { m_KmlSeriesInfos.push_back(KSI); } } } catch (openfluid::base::FrameworkException& E) { OPENFLUID_LogWarning(E.getMessage()); m_OKToGo = false; return; } m_OKToGo = true; m_KmzSubDir = m_OutputFileName + "_kmz-dir"; m_GNUPlotSubDir = m_OutputFileName + "_gnuplot-dir"; }
void initParams(const openfluid::ware::WareParams_t& Params) { openfluid::core::StringValue ParamStrVal; openfluid::core::DoubleValue ParamDoubleVal; openfluid::core::VectorValue ParamVectorVal; openfluid::core::MatrixValue ParamMatrixVal; openfluid::core::MapValue ParamMapVal; std::vector<std::string> ParamStrArray; std::vector<long> ParamLongArray; std::vector<double> ParamDoubleArray; if (!OPENFLUID_IsSimulatorParameterExist(Params,"strparam")) OPENFLUID_RaiseError("missing parameter (strparam)"); if (OPENFLUID_IsSimulatorParameterExist(Params,"fakestrparam")) OPENFLUID_RaiseError("unexpected parameter (fakestrparam)"); // ====== String param ====== m_ParamString = ""; if (!OPENFLUID_GetSimulatorParameter(Params,"strparam",m_ParamString)) OPENFLUID_RaiseError("incorrect OPENFLUID_GetSimulatorParameter (strparam) get by reference"); if (m_ParamString != "strvalue") OPENFLUID_RaiseError("incorrect OPENFLUID_GetSimulatorParameter (strparam, value) get by reference"); m_ParamString = OPENFLUID_GetSimulatorParameter(Params,"strparam"); if (m_ParamString != "strvalue") OPENFLUID_RaiseError("incorrect OPENFLUID_GetSimulatorParameter (strparam, value) get by return"); if (OPENFLUID_GetSimulatorParameter(Params,"wrongstrparam",m_ParamString)) OPENFLUID_RaiseError("incorrect OPENFLUID_GetSimulatorParameter (wrongstrparam)"); if (OPENFLUID_GetSimulatorParameter(Params,"strparam",ParamDoubleVal)) OPENFLUID_RaiseError("incorrect OPENFLUID_GetSimulatorParameter (strparam) into DoubleValue"); if (!OPENFLUID_GetSimulatorParameter(Params,"strparam",ParamStrVal)) OPENFLUID_RaiseError("incorrect OPENFLUID_GetSimulatorParameter (strparam) into StringValue"); if(ParamStrVal.get() != "strvalue") OPENFLUID_RaiseError("incorrect OPENFLUID_GetSimulatorParameter (strparam, value) into StringValue"); if (OPENFLUID_GetSimulatorParameter(Params,"wrongstrparam",ParamStrVal)) OPENFLUID_RaiseError("incorrect OPENFLUID_GetSimulatorParameter (wrongstrparam) into StringValue"); if (OPENFLUID_GetSimulatorParameter(Params,"strparam",ParamVectorVal)) OPENFLUID_RaiseError("incorrect OPENFLUID_GetSimulatorParameter (strparam) into VectorValue"); // ====== Double param ====== m_ParamDouble = 0.0; if (!OPENFLUID_GetSimulatorParameter(Params,"doubleparam",m_ParamDouble)) OPENFLUID_RaiseError("incorrect OPENFLUID_GetSimulatorParameter (doubleparam) get by reference"); if(!openfluid::scientific::isCloseEnough(m_ParamDouble,0.1,0.00001)) OPENFLUID_RaiseError("incorrect OPENFLUID_GetSimulatorParameter (doubleparam, value) get by reference"); if (OPENFLUID_GetSimulatorParameter(Params,"wrongdoubleparam",m_ParamDouble)) OPENFLUID_RaiseError("incorrect OPENFLUID_GetSimulatorParameter (wrongdoubleparam)"); if (!OPENFLUID_GetSimulatorParameter(Params,"doubleparam",ParamDoubleVal)) OPENFLUID_RaiseError("incorrect OPENFLUID_GetSimulatorParameter (doubleparam) into DoubleValue"); if(!openfluid::scientific::isCloseEnough(ParamDoubleVal.get(),0.1,0.00001)) OPENFLUID_RaiseError("incorrect OPENFLUID_GetSimulatorParameter (doubleparam, value) into DoubleValue"); if (OPENFLUID_GetSimulatorParameter(Params,"wrongdoubleparam",ParamDoubleVal)) OPENFLUID_RaiseError("incorrect OPENFLUID_GetSimulatorParameter (wrongdoubleparam) into DoubleValue"); if (!OPENFLUID_GetSimulatorParameter(Params,"doubleparam",ParamStrVal)) OPENFLUID_RaiseError("incorrect OPENFLUID_GetSimulatorParameter (doubleparam) into StringValue"); if(ParamStrVal.get() != "0.1") OPENFLUID_RaiseError("incorrect OPENFLUID_GetSimulatorParameter (doubleparam, value) into StringValue"); if (!OPENFLUID_GetSimulatorParameter(Params,"doubleparam",ParamVectorVal)) OPENFLUID_RaiseError("incorrect OPENFLUID_GetSimulatorParameter (doubleparam) into VectorValue"); if(ParamVectorVal.size() != 1) OPENFLUID_RaiseError("incorrect OPENFLUID_GetSimulatorParameter (doubleparam, size) into VectorValue"); if(!openfluid::scientific::isCloseEnough(ParamVectorVal[0],0.1,0.00001)) OPENFLUID_RaiseError("incorrect OPENFLUID_GetSimulatorParameter (doubleparam, value) into VectorValue"); // ====== Long param ====== m_ParamLong = 0; if (!OPENFLUID_GetSimulatorParameter(Params,"longparam",m_ParamLong)) OPENFLUID_RaiseError("incorrect OPENFLUID_GetSimulatorParameter (longparam) get by reference"); if(m_ParamLong != 10) OPENFLUID_RaiseError("incorrect OPENFLUID_GetSimulatorParameter (longparam, value) get by reference"); if (OPENFLUID_GetSimulatorParameter(Params,"wronglongparam",m_ParamLong)) OPENFLUID_RaiseError("incorrect OPENFLUID_GetSimulatorParameter (wronglongparam)"); if (!OPENFLUID_GetSimulatorParameter(Params,"longparam",ParamDoubleVal)) OPENFLUID_RaiseError("incorrect OPENFLUID_GetSimulatorParameter (longparam) into DoubleValue"); if(!openfluid::scientific::isCloseEnough<double>(ParamDoubleVal.get(),10,0.00001)) OPENFLUID_RaiseError("incorrect OPENFLUID_GetSimulatorParameter (longparam, value) into DoubleValue"); if (!OPENFLUID_GetSimulatorParameter(Params,"longparam",ParamStrVal)) OPENFLUID_RaiseError("incorrect OPENFLUID_GetSimulatorParameter (longparam) into StringValue"); if(ParamStrVal.get() != "10") OPENFLUID_RaiseError("incorrect OPENFLUID_GetSimulatorParameter (longparam, value) into StringValue"); if (!OPENFLUID_GetSimulatorParameter(Params,"longparam",ParamVectorVal)) OPENFLUID_RaiseError("incorrect OPENFLUID_GetSimulatorParameter (longparam) into VectorValue"); if(ParamVectorVal.size() != 1) OPENFLUID_RaiseError("incorrect OPENFLUID_GetSimulatorParameter (longparam, size) into VectorValue"); if(!openfluid::scientific::isCloseEnough<double>(ParamVectorVal[0],10,0.00001)) OPENFLUID_RaiseError("incorrect OPENFLUID_GetSimulatorParameter (longparam, value) into VectorValue"); // ====== Bool param ====== if (!OPENFLUID_GetSimulatorParameter(Params,"boolparam",ParamStrVal)) OPENFLUID_RaiseError("incorrect OPENFLUID_GetSimulatorParameter (boolparam) into StringValue"); bool aBool = false; if(!ParamStrVal.toBoolean(aBool)) OPENFLUID_RaiseError("incorrect OPENFLUID_GetSimulatorParameter (boolparam, type)"); if(aBool != true) OPENFLUID_RaiseError("incorrect OPENFLUID_GetSimulatorParameter (boolparam, value)"); // ====== String array param ====== ParamStrArray.clear(); if (!OPENFLUID_GetSimulatorParameter(Params,"strarrayparam",ParamStrArray)) OPENFLUID_RaiseError("incorrect OPENFLUID_GetSimulatorParameter (strarrayparam) get by reference"); if (ParamStrArray.size() != 3) OPENFLUID_RaiseError("incorrect OPENFLUID_GetSimulatorParameter (strarrayparam, size) get by reference"); if (ParamStrArray[1] != "strvalue2") OPENFLUID_RaiseError("incorrect OPENFLUID_GetSimulatorParameter (strarrayparam, value) get by reference"); if (OPENFLUID_GetSimulatorParameter(Params,"wrongstrarrayparam",ParamStrArray)) OPENFLUID_RaiseError("incorrect OPENFLUID_GetSimulatorParameter (wrongstrarrayparam)"); if (OPENFLUID_GetSimulatorParameter(Params,"strarrayparam",ParamDoubleVal)) OPENFLUID_RaiseError("incorrect OPENFLUID_GetSimulatorParameter (strarrayparam) into DoubleValue"); if (!OPENFLUID_GetSimulatorParameter(Params,"strarrayparam",ParamStrVal)) OPENFLUID_RaiseError("incorrect OPENFLUID_GetSimulatorParameter (strarrayparam) into StringValue"); if(ParamStrVal.get() != "strvalue1;strvalue2;strvalue3") OPENFLUID_RaiseError("incorrect OPENFLUID_GetSimulatorParameter (strarrayparam, value) into StringValue"); if (OPENFLUID_GetSimulatorParameter(Params,"strarrayparam",ParamVectorVal)) OPENFLUID_RaiseError("incorrect OPENFLUID_GetSimulatorParameter (strarrayparam) into VectorValue"); // ====== Double array param ====== ParamDoubleArray.clear(); if (!OPENFLUID_GetSimulatorParameter(Params,"doublearrayparam",ParamDoubleArray)) OPENFLUID_RaiseError("incorrect OPENFLUID_GetSimulatorParameter (doublearrayparam) get by reference"); if (ParamDoubleArray.size() != 4) OPENFLUID_RaiseError("incorrect OPENFLUID_GetSimulatorParameter (doublearrayparam, size) get by reference"); if (!openfluid::scientific::isCloseEnough(ParamDoubleArray[2],1.3,0.00001)) OPENFLUID_RaiseError("incorrect OPENFLUID_GetSimulatorParameter (doublearrayparam, value) get by reference"); if (openfluid::scientific::isCloseEnough(ParamDoubleArray[3],1.3,0.00001)) OPENFLUID_RaiseError("incorrect OPENFLUID_GetSimulatorParameter (doublearrayparam, wrongvalue) " "get by reference"); if (OPENFLUID_GetSimulatorParameter(Params,"wrongdoublearrayparam",ParamDoubleArray)) OPENFLUID_RaiseError("incorrect OPENFLUID_GetSimulatorParameter (wrongdoublearrayparam)"); if (OPENFLUID_GetSimulatorParameter(Params,"doublearrayparam",ParamDoubleVal)) OPENFLUID_RaiseError("incorrect OPENFLUID_GetSimulatorParameter (doublearrayparam) into DoubleValue"); if (!OPENFLUID_GetSimulatorParameter(Params,"doublearrayparam",ParamStrVal)) OPENFLUID_RaiseError("incorrect OPENFLUID_GetSimulatorParameter (doublearrayparam) into StringValue"); if(ParamStrVal.get() != "1.1;1.3;1.3;1.4") OPENFLUID_RaiseError("incorrect OPENFLUID_GetSimulatorParameter (doublearrayparam, value) into StringValue"); if (!OPENFLUID_GetSimulatorParameter(Params,"doublearrayparam",ParamVectorVal)) OPENFLUID_RaiseError("incorrect OPENFLUID_GetSimulatorParameter (doublearrayparam) into VectorValue"); if(ParamVectorVal.size() != 4) OPENFLUID_RaiseError("incorrect OPENFLUID_GetSimulatorParameter (doublearrayparam, size) into VectorValue"); if(!openfluid::scientific::isCloseEnough(ParamVectorVal[2],1.3,0.00001)) OPENFLUID_RaiseError("incorrect OPENFLUID_GetSimulatorParameter (doublearrayparam, value) into VectorValue"); // ====== Long array param ====== ParamLongArray.clear(); if (!OPENFLUID_GetSimulatorParameter(Params,"longarrayparam",ParamLongArray)) OPENFLUID_RaiseError("incorrect OPENFLUID_GetSimulatorParameter (longarrayparam) get by reference"); if (ParamLongArray.size() != 5) OPENFLUID_RaiseError("incorrect OPENFLUID_GetSimulatorParameter (longarrayparam, size) get by reference"); if (ParamLongArray[3] != 14) OPENFLUID_RaiseError("incorrect OPENFLUID_GetSimulatorParameter (longarrayparam, value) get by reference"); if (ParamLongArray[4] == 14) OPENFLUID_RaiseError("incorrect OPENFLUID_GetSimulatorParameter (longarrayparam, wrongvalue) get by reference"); if (OPENFLUID_GetSimulatorParameter(Params,"wronglongarrayparam",ParamLongArray)) OPENFLUID_RaiseError("incorrect OPENFLUID_GetSimulatorParameter (wronglongarrayparam)"); if (OPENFLUID_GetSimulatorParameter(Params,"longarrayparam",ParamDoubleVal)) OPENFLUID_RaiseError("incorrect OPENFLUID_GetSimulatorParameter (longarrayparam) into DoubleValue"); if (!OPENFLUID_GetSimulatorParameter(Params,"longarrayparam",ParamStrVal)) OPENFLUID_RaiseError("incorrect OPENFLUID_GetSimulatorParameter (longarrayparam) into StringValue"); if(ParamStrVal.get() != "11;12;13;14;15") OPENFLUID_RaiseError("incorrect OPENFLUID_GetSimulatorParameter (longarrayparam, value) into StringValue"); if (!OPENFLUID_GetSimulatorParameter(Params,"longarrayparam",ParamVectorVal)) OPENFLUID_RaiseError("incorrect OPENFLUID_GetSimulatorParameter (longarrayparam) into VectorValue"); if(ParamVectorVal.size() != 5) OPENFLUID_RaiseError("incorrect OPENFLUID_GetSimulatorParameter (longarrayparam, size) into VectorValue"); if(!openfluid::scientific::isCloseEnough<double>(ParamVectorVal[3],14,0.00001)) OPENFLUID_RaiseError("incorrect OPENFLUID_GetSimulatorParameter (longarrayparam, value) into VectorValue"); // ====== Matrix param ====== if (!OPENFLUID_GetSimulatorParameter(Params,"matrixparam",ParamMatrixVal)) OPENFLUID_RaiseError("incorrect OPENFLUID_GetSimulatorParameter (matrixparam) get by reference"); if (ParamMatrixVal.getColsNbr() != 2) OPENFLUID_RaiseError("incorrect OPENFLUID_GetSimulatorParameter (matrixparam, cols nb) get by reference"); if (ParamMatrixVal.getRowsNbr() != 3) OPENFLUID_RaiseError("incorrect OPENFLUID_GetSimulatorParameter (matrixparam, rows nb) get by reference"); if (!openfluid::scientific::isCloseEnough(ParamMatrixVal.get(0,0),1.1)) OPENFLUID_RaiseError("incorrect OPENFLUID_GetSimulatorParameter (matrixparam, value) get by reference"); if (!openfluid::scientific::isCloseEnough(ParamMatrixVal.get(0,1),2.1)) OPENFLUID_RaiseError("incorrect OPENFLUID_GetSimulatorParameter (matrixparam, wrongvalue) get by reference"); if (!openfluid::scientific::isCloseEnough(ParamMatrixVal.get(1,2),3.2)) OPENFLUID_RaiseError("incorrect OPENFLUID_GetSimulatorParameter (matrixparam, wrongvalue) get by reference"); if (OPENFLUID_GetSimulatorParameter(Params,"wrongmatrixparam",ParamMatrixVal)) OPENFLUID_RaiseError("incorrect OPENFLUID_GetSimulatorParameter (wrongmatrixparam)"); if (OPENFLUID_GetSimulatorParameter(Params,"matrixparam",ParamDoubleVal)) OPENFLUID_RaiseError("incorrect OPENFLUID_GetSimulatorParameter (matrixparam) into DoubleValue"); if (OPENFLUID_GetSimulatorParameter(Params,"matrixparam",ParamVectorVal)) OPENFLUID_RaiseError("incorrect OPENFLUID_GetSimulatorParameter (matrixparam) into VectorValue"); if (!OPENFLUID_GetSimulatorParameter(Params,"matrixparam",ParamStrVal)) OPENFLUID_RaiseError("incorrect OPENFLUID_GetSimulatorParameter (matrixparam) into StringValue"); if(ParamStrVal.get() != "1.1;1.2|2.1;2.2|3.1;3.2") OPENFLUID_RaiseError("incorrect OPENFLUID_GetSimulatorParameter (matrixparam, value) into StringValue"); // ====== Map param ====== if (!OPENFLUID_GetSimulatorParameter(Params,"mapparam",ParamStrVal)) OPENFLUID_RaiseError("incorrect OPENFLUID_GetSimulatorParameter (mapparam) into StringValue"); if(!ParamStrVal.toMapValue(";",ParamMapVal)) OPENFLUID_RaiseError("incorrect OPENFLUID_GetSimulatorParameter (mapparam, type)"); if(ParamMapVal.size() != 3) OPENFLUID_RaiseError("incorrect OPENFLUID_GetSimulatorParameter (mapparam, size)"); double aDouble = 0.0; if(!ParamMapVal["key1"].asStringValue().toDouble(aDouble)) OPENFLUID_RaiseError("incorrect OPENFLUID_GetSimulatorParameter (mapparam, type for key key1)"); if(!openfluid::scientific::isCloseEnough(aDouble,1.1)) OPENFLUID_RaiseError("incorrect OPENFLUID_GetSimulatorParameter (mapparam, value for key key1)"); if(ParamMapVal.getString("key2") != "a string") OPENFLUID_RaiseError("incorrect OPENFLUID_GetSimulatorParameter (mapparam, value for key key2)"); aBool = false; if(!ParamMapVal["key3"].asStringValue().toBoolean(aBool)) OPENFLUID_RaiseError("incorrect OPENFLUID_GetSimulatorParameter (mapparam, type for key key3)"); if(aBool != true) OPENFLUID_RaiseError("incorrect OPENFLUID_GetSimulatorParameter (mapparam, value for key key3)"); // ====== Vars replacements in params ====== std::string InPath; std::string OutPath; std::string TempPath; OPENFLUID_GetRunEnvironment("dir.input",InPath); OPENFLUID_GetRunEnvironment("dir.output",OutPath); OPENFLUID_GetRunEnvironment("dir.temp",TempPath); OPENFLUID_GetSimulatorParameter(Params,"inpath",ParamStrVal); if (ParamStrVal.toString() != (InPath+"/path/in")) OPENFLUID_RaiseError("incorrect inpath parameter value"); OPENFLUID_GetSimulatorParameter(Params,"outpath",ParamStrVal); if (ParamStrVal.toString() != (OutPath+"/path/out")) OPENFLUID_RaiseError("incorrect outpath parameter value"); OPENFLUID_GetSimulatorParameter(Params,"temppath",ParamStrVal); if (ParamStrVal.toString() != (TempPath+"/path/temp")) OPENFLUID_RaiseError("incorrect temppath parameter value"); }
void initParams(const openfluid::ware::WareParams_t& Params) { openfluid::ware::WareParamsTree ParamsTree; try { ParamsTree.setParams(Params); } catch (openfluid::base::FrameworkException& E) { OPENFLUID_RaiseError(E.getMessage()); } // checking of mandatory parameters if (!ParamsTree.root().hasChild("format")) { OPENFLUID_LogWarning("Missing GDAL format for output files"); return; } if (!ParamsTree.root().hasChild("format")) { OPENFLUID_LogWarning("No serie defined"); return; } // process of format parameter m_GDALFormat = ParamsTree.root().getChildValue("format",""); openfluid::utils::GDALDriversFilesExts_t ValidVectorDrivers = openfluid::utils::getOGRFilesDriversForOpenFLUID(); if (ValidVectorDrivers.find(m_GDALFormat) == ValidVectorDrivers.end()) { OPENFLUID_LogWarning("Unsupported GDAL format for output files"); return; } std::string OutfileExt = ValidVectorDrivers[m_GDALFormat].FilesExts.front(); // process of parameter for optional output subdirectory std::string OutSeriesSubdir = ParamsTree.root().getChildValue("outsubdir",""); // get paths for input dataset and output directory OPENFLUID_GetRunEnvironment("dir.input",m_InputPath); OPENFLUID_GetRunEnvironment("dir.output",m_OutputPath); if (!OutSeriesSubdir.empty()) m_OutputPath += "/"+OutSeriesSubdir; for (auto& Serie : ParamsTree.root().child("geoserie")) { GeoVectorSerie::WhenModeCases Mode = GeoVectorSerie::WHENCONTINUOUS; openfluid::core::Duration_t ContinuousDelay = 1; std::string SerieName = Serie.first; std::string GeoSourceFilename = Serie.second.getChildValue("sourcefile",""); std::string VarsString = Serie.second.getChildValue("vars",""); openfluid::core::UnitsClass_t UnitsClass = Serie.second.getChildValue("unitsclass",""); std::string WhenModeString = Serie.second.getChildValue("when",""); if (GeoSourceFilename.empty()) OPENFLUID_LogWarning("Missing geographic source filename for serie "+SerieName); else if (UnitsClass.empty()) OPENFLUID_LogWarning("Missing units class for serie "+SerieName); else if (VarsString.empty()) OPENFLUID_LogWarning("Missing variables list for serie "+SerieName); else { GeoVectorSerie::VariablesSet_t VarsSet = convertParamToVariableSet(VarsString); if (VarsSet.empty()) OPENFLUID_LogWarning("Format error in variables list for serie "+SerieName); else { if (setWhenModeFromParam(WhenModeString,Mode,ContinuousDelay)) { // everything's OK, add the serie to the active series set m_Series.push_back(GeoVectorSerie(SerieName, m_InputPath + "/" + GeoSourceFilename, UnitsClass,VarsSet, OutfileExt, Mode,ContinuousDelay)); } else OPENFLUID_LogWarning("Format error in whenmode for serie "+SerieName); } } } }
bool PrimitivesUseFunction::runStep(const openfluid::base::SimulationStatus* SimStatus) { // std::cout << "PrimitiveUseFunc runStep begin" << std::endl; openfluid::core::Unit* TU; unsigned long VectorSize = 40; unsigned long NewVectorSize = 5; openfluid::core::VectorValue TheVector; openfluid::core::DoubleValue TheScalar; double TheInputDouble; std::string TheInputStr; openfluid::core::EventsCollection TheEvents; openfluid::core::Event Ev; DECLARE_UNITS_ORDERED_LOOP(1); std::string RunEnvStr; bool RunEnvBool; unsigned int UnitsCount; std::cout << std::endl; // std::cout << "PrimitiveUseFunc runStep Units..." << std::endl; // ===== Units ===== if (!OPENFLUID_IsUnitClassExist("TestUnits")) OPENFLUID_RaiseError("tests.primitives.use","incorrect OPENFLUID_IsUnitClassExist (TestUnits)"); if (!OPENFLUID_IsUnitClassExist("ParentTestUnits")) OPENFLUID_RaiseError("tests.primitives.use","incorrect OPENFLUID_IsUnitClassExist (ParentTestUnits)"); if (OPENFLUID_IsUnitClassExist("unknown")) OPENFLUID_RaiseError("tests.primitives.use","incorrect OPENFLUID_IsUnitClassExist (unknown)"); if (!OPENFLUID_GetUnitsCount("TestUnits",UnitsCount) || UnitsCount != 12) OPENFLUID_RaiseError("tests.primitives.use","incorrect OPENFLUID_getUnitsCount or count value (TestUnits)"); if (!OPENFLUID_GetUnitsCount("ParentTestUnits",UnitsCount)|| UnitsCount != 2) OPENFLUID_RaiseError("tests.primitives.use","incorrect OPENFLUID_getUnitsCount (ParentTestUnits)"); if (OPENFLUID_GetUnitsCount("unknown",UnitsCount)) OPENFLUID_RaiseError("tests.primitives.use","incorrect OPENFLUID_getUnitsCount (unknown)"); // std::cout << "PrimitiveUseFunc runStep Environt..." << std::endl; // ===== Run environment ===== RunEnvStr.clear(); if (!OPENFLUID_GetRunEnvironment("dir.input",&RunEnvStr)) OPENFLUID_RaiseError("tests.primitives.use","incorrect OPENFLUID_GetRunEnvironment (dir.input)"); std::cout << "dir.input = " << RunEnvStr << std::endl; if (!OPENFLUID_GetRunEnvironment("dir.output",&RunEnvStr)) OPENFLUID_RaiseError("tests.primitives.use","incorrect OPENFLUID_GetRunEnvironment (dir.output)"); std::cout << "dir.output = " << RunEnvStr << std::endl; if (OPENFLUID_GetRunEnvironment("wrong.str",&RunEnvStr)) OPENFLUID_RaiseError("tests.primitives.use","incorrect OPENFLUID_GetRunEnvironment (wrong.str)"); RunEnvBool = false; if (OPENFLUID_GetRunEnvironment("mode.verbose",&RunEnvBool)) OPENFLUID_RaiseError("tests.primitives.use","incorrect OPENFLUID_GetRunEnvironment (mode.verbose)"); if (RunEnvBool) OPENFLUID_RaiseError("tests.primitives.use","incorrect OPENFLUID_GetRunEnvironment (mode.verbose is true)"); if (OPENFLUID_GetRunEnvironment("wrong.bool",&RunEnvBool)) OPENFLUID_RaiseError("tests.primitives.use","incorrect OPENFLUID_GetRunEnvironment (wrong.bool)"); // std::cout << "*** PrimitiveUseFunc runStep Start Loop" << std::endl; BEGIN_UNITS_ORDERED_LOOP(1,"TestUnits",TU) // std::cout << "PrimitiveUseFunc runStep child/parents..." << std::endl; // std::cout << "TU->getID() : " << TU->getID() << std::endl; // std::cout << "TU->getParentUnits(\"ParentTestUnits\")->size() : " << TU->getParentUnits("ParentTestUnits")->size() << std::endl; // ====== Units child/Parents ====== if (TU->getID() < 10) { if (!(TU->getParentUnits("ParentTestUnits")->size() == 1)) OPENFLUID_RaiseError("tests.primitives.use","incorrect parent count for TestUnits ID < 10"); if (TU->getID() % 2 == 0) { if (!(TU->getParentUnits("ParentTestUnits")->front()->getID() == 2)) OPENFLUID_RaiseError("tests.primitives.use","incorrect parent for even TestUnits ID"); } else { if (!(TU->getParentUnits("ParentTestUnits")->front()->getID() == 1)) OPENFLUID_RaiseError("tests.primitives.use","incorrect parent for odd TestUnits ID"); } } // std::cout << "PrimitiveUseFunc runStep scalar..." << std::endl; // ====== Scalar ====== OPENFLUID_GetVariable(TU,"tests.scalar",SimStatus->getCurrentStep(),&TheScalar); if ((openfluid::core::UnitID_t)TheScalar != TU->getID()) OPENFLUID_RaiseError("tests.primitives.use","incorrect scalar value (tests.scalar)"); OPENFLUID_SetVariable(TU,"tests.scalar",SimStatus->getCurrentStep(),(double)(TU->getID()*SimStatus->getCurrentStep())); if (SimStatus->getCurrentStep() > 0 ) { OPENFLUID_GetVariable(TU,"tests.scalar",SimStatus->getCurrentStep()-1,&TheScalar); if (!openfluid::tools::IsCloseEnough(TheScalar,(double)(TU->getID()*(SimStatus->getCurrentStep()-1)),0.00001)) OPENFLUID_RaiseError("tests.primitives.use","incorrect scalar value at t-1 (tests.scalar)"); } OPENFLUID_GetVariable(TU,"tests.scalar",SimStatus->getCurrentStep(),&TheScalar); if (!openfluid::tools::IsCloseEnough(TheScalar,(double)(TU->getID()*SimStatus->getCurrentStep()),0.00001)) OPENFLUID_RaiseError("tests.primitives.use","incorrect scalar value after update (tests.scalar)"); if (!OPENFLUID_IsVariableExist(TU,"tests.scalar")) OPENFLUID_RaiseError("tests.primitives.use","incorrect OPENFLUID_IsVariableExist (tests.scalar)"); if (!OPENFLUID_IsTypedVariableExist(TU,"tests.scalar",openfluid::core::Value::NONE)) OPENFLUID_RaiseError("tests.primitives.use","incorrect OPENFLUID_IsTypedVariableExist (tests.scalar, NONE)"); if (OPENFLUID_IsVariableExist(TU,"tests.wrongscalar")) OPENFLUID_RaiseError("tests.primitives.use","incorrect OPENFLUID_IsVariableExist (tests.wrongscalar)"); if (OPENFLUID_IsTypedVariableExist(TU,"tests.wrongscalar",openfluid::core::Value::NONE)) OPENFLUID_RaiseError("tests.primitives.use","incorrect OPENFLUID_IsTypedVariableExist (tests.wrongscalar, NONE)"); if (!OPENFLUID_IsVariableExist(TU,"tests.scalar",SimStatus->getCurrentStep())) OPENFLUID_RaiseError("tests.primitives.use","incorrect OPENFLUID_IsVariableExist (tests.scalar, timestep)"); if (!OPENFLUID_IsTypedVariableExist(TU,"tests.scalar",SimStatus->getCurrentStep(),openfluid::core::Value::NONE)) OPENFLUID_RaiseError("tests.primitives.use","incorrect OPENFLUID_IsTypedVariableExist (tests.scalar, timestep, NONE)"); if (OPENFLUID_IsVariableExist(TU,"tests.scalar",SimStatus->getCurrentStep()+1)) OPENFLUID_RaiseError("tests.primitives.use","incorrect OPENFLUID_IsVariableExist (tests.scalar, timestep+1)"); if (OPENFLUID_IsTypedVariableExist(TU,"tests.scalar",SimStatus->getCurrentStep()+1,openfluid::core::Value::NONE)) OPENFLUID_RaiseError("tests.primitives.use","incorrect OPENFLUID_IsTypedVariableExist (tests.scalar, timestep+1, NONE)"); if (OPENFLUID_IsVariableExist(TU,"tests.wrongscalar",SimStatus->getCurrentStep())) OPENFLUID_RaiseError("tests.primitives.use","incorrect OPENFLUID_IsVariableExist (tests.wrongscalar, timestep)"); if (OPENFLUID_IsTypedVariableExist(TU,"tests.wrongscalar",SimStatus->getCurrentStep(),openfluid::core::Value::NONE)) OPENFLUID_RaiseError("tests.primitives.use","incorrect OPENFLUID_IsVariableExist (tests.wrongscalar, timestep, NONE)"); if (OPENFLUID_IsVariableExist(TU,"tests.wrongscalar",SimStatus->getCurrentStep()+1)) OPENFLUID_RaiseError("tests.primitives.use","incorrect OPENFLUID_IsVariableExist (tests.wrongscalar, timestep+1)"); if (OPENFLUID_IsTypedVariableExist(TU,"tests.wrongscalar",SimStatus->getCurrentStep()+1,openfluid::core::Value::NONE)) OPENFLUID_RaiseError("tests.primitives.use","incorrect OPENFLUID_IsTypedVariableExist (tests.wrongscalar, timestep+1, NONE)"); if (!OPENFLUID_IsVariableExist(TU,"tests.scalar",SimStatus->getCurrentStep(), openfluid::core::Value::DOUBLE)) OPENFLUID_RaiseError("tests.primitives.use","incorrect OPENFLUID_IsVariableExist (tests.scalar, timestep, DOUBLE)"); if (!OPENFLUID_IsTypedVariableExist(TU,"tests.scalar",SimStatus->getCurrentStep(), openfluid::core::Value::NONE)) OPENFLUID_RaiseError("tests.primitives.use","incorrect OPENFLUID_IsVariableExist (tests.scalar, timestep, NONE)"); if (OPENFLUID_IsVariableExist(TU,"tests.scalar",SimStatus->getCurrentStep()+2000, openfluid::core::Value::DOUBLE)) OPENFLUID_RaiseError("tests.primitives.use","incorrect OPENFLUID_IsVariableExist (tests.scalar, timestep+2000, DOUBLE)"); if (OPENFLUID_IsTypedVariableExist(TU,"tests.scalar",SimStatus->getCurrentStep()+2000, openfluid::core::Value::NONE)) OPENFLUID_RaiseError("tests.primitives.use","incorrect OPENFLUID_IsTypedVariableExist (tests.scalar, timestep+2000, NONE)"); if (OPENFLUID_IsVariableExist(TU,"tests.wrongscalar",SimStatus->getCurrentStep(), openfluid::core::Value::DOUBLE)) OPENFLUID_RaiseError("tests.primitives.use","incorrect OPENFLUID_IsVariableExist (tests.wrongscalar, timestep, DOUBLE)"); if (OPENFLUID_IsVariableExist(TU,"tests.wrongscalar",SimStatus->getCurrentStep()+1920, openfluid::core::Value::DOUBLE)) OPENFLUID_RaiseError("tests.primitives.use","incorrect OPENFLUID_IsVariableExist (tests.wrongscalar, timestep+1920, DOUBLE)"); if (OPENFLUID_IsVariableExist(TU,"tests.scalar",SimStatus->getCurrentStep(), openfluid::core::Value::VECTOR)) OPENFLUID_RaiseError("tests.primitives.use","incorrect OPENFLUID_IsVariableExist (tests.scalar, timestep, VECTOR)"); // std::cout << "PrimitiveUseFunc runStep Vector..." << std::endl; // ====== Vector ====== OPENFLUID_GetVariable(TU,"tests.vector",SimStatus->getCurrentStep(),&TheVector); if (TheVector.getSize() != VectorSize) OPENFLUID_RaiseError("tests.primitives.use","incorrect vector size"); openfluid::core::VectorValue NewVect(NewVectorSize,SimStatus->getCurrentStep()); OPENFLUID_SetVariable(TU,"tests.vector",SimStatus->getCurrentStep(),NewVect); OPENFLUID_GetVariable(TU,"tests.vector",SimStatus->getCurrentStep(),&TheVector); if (TheVector.getSize() != NewVectorSize) OPENFLUID_RaiseError("tests.primitives.use","incorrect vector size after update"); if (!openfluid::tools::IsCloseEnough(TheVector[0],(double)SimStatus->getCurrentStep(),0.00001)) OPENFLUID_RaiseError("tests.primitives.use","incorrect vector value at index 0 after update"); if (!openfluid::tools::IsCloseEnough(TheVector[4],(double)SimStatus->getCurrentStep(),0.00001)) OPENFLUID_RaiseError("tests.primitives.use","incorrect vector value at index 4 after update"); if (SimStatus->getCurrentStep() > 0) { OPENFLUID_GetVariable(TU,"tests.vector",SimStatus->getCurrentStep()-1,&TheVector); if (TheVector.getSize() != NewVectorSize) OPENFLUID_RaiseError("tests.primitives.use","incorrect vector size at t-1"); if (!openfluid::tools::IsCloseEnough(TheVector[0],(double)(SimStatus->getCurrentStep()-1),0.00001)) OPENFLUID_RaiseError("tests.primitives.use","incorrect vector value at index 0 at t-1"); if (!openfluid::tools::IsCloseEnough(TheVector[4],(double)(SimStatus->getCurrentStep()-1),0.00001)) OPENFLUID_RaiseError("tests.primitives.use","incorrect vector value at index 4 at t-1"); } if (!OPENFLUID_IsVariableExist(TU,"tests.vector")) OPENFLUID_RaiseError("tests.primitives.use","incorrect OPENFLUID_IsVariableExist (tests.vector)"); if (!OPENFLUID_IsTypedVariableExist(TU,"tests.vector",openfluid::core::Value::VECTOR)) OPENFLUID_RaiseError("tests.primitives.use","incorrect OPENFLUID_IsTypedVariableExist (tests.vector, VECTOR)"); if (OPENFLUID_IsVariableExist(TU,"tests.wrongvector")) OPENFLUID_RaiseError("tests.primitives.use","incorrect OPENFLUID_IsVariableExist (tests.wrongvector)"); if (OPENFLUID_IsTypedVariableExist(TU,"tests.wrongvector",openfluid::core::Value::VECTOR)) OPENFLUID_RaiseError("tests.primitives.use","incorrect OPENFLUID_IsTypedVariableExist (tests.wrongvector, VECTOR)"); if (!OPENFLUID_IsVariableExist(TU,"tests.vector",SimStatus->getCurrentStep())) OPENFLUID_RaiseError("tests.primitives.use","incorrect OPENFLUID_IsVariableExist (tests.vector, timestep)"); if (!OPENFLUID_IsTypedVariableExist(TU,"tests.vector",SimStatus->getCurrentStep(),openfluid::core::Value::VECTOR)) OPENFLUID_RaiseError("tests.primitives.use","incorrect OPENFLUID_IsTypedVariableExist (tests.vector, timestep, VECTOR)"); if (OPENFLUID_IsVariableExist(TU,"tests.wrongvector",SimStatus->getCurrentStep())) OPENFLUID_RaiseError("tests.primitives.use","incorrect OPENFLUID_IsVariableExist (tests.wrongvector, timestep)"); if (OPENFLUID_IsTypedVariableExist(TU,"tests.wrongvector",SimStatus->getCurrentStep(),openfluid::core::Value::VECTOR)) OPENFLUID_RaiseError("tests.primitives.use","incorrect OPENFLUID_IsTypedVariableExist (tests.wrongvector, timestep, VECTOR)"); if (!OPENFLUID_IsVariableExist(TU,"tests.vector",SimStatus->getCurrentStep(), openfluid::core::Value::VECTOR)) OPENFLUID_RaiseError("tests.primitives.use","incorrect OPENFLUID_IsVariableExist (tests.vector, timestep, VECTOR)"); if (!OPENFLUID_IsTypedVariableExist(TU,"tests.vector",SimStatus->getCurrentStep(), openfluid::core::Value::VECTOR)) OPENFLUID_RaiseError("tests.primitives.use","incorrect OPENFLUID_IsTypedVariableExist (tests.vector, timestep, VECTOR)"); if (OPENFLUID_IsVariableExist(TU,"tests.vector",SimStatus->getCurrentStep()+1, openfluid::core::Value::VECTOR)) OPENFLUID_RaiseError("tests.primitives.use","incorrect OPENFLUID_IsVariableExist (tests.vector, timestep+1, VECTOR)"); if (OPENFLUID_IsTypedVariableExist(TU,"tests.vector",SimStatus->getCurrentStep()+1, openfluid::core::Value::VECTOR)) OPENFLUID_RaiseError("tests.primitives.use","incorrect OPENFLUID_IsTypedVariableExist (tests.vector, timestep+1, VECTOR)"); if (OPENFLUID_IsVariableExist(TU,"tests.wrongvector",SimStatus->getCurrentStep(), openfluid::core::Value::VECTOR)) OPENFLUID_RaiseError("tests.primitives.use","incorrect OPENFLUID_IsVariableExist (tests.wrongvector, timestep, VECTOR)"); if (OPENFLUID_IsTypedVariableExist(TU,"tests.wrongvector",SimStatus->getCurrentStep(), openfluid::core::Value::VECTOR)) OPENFLUID_RaiseError("tests.primitives.use","incorrect OPENFLUID_IsTypedVariableExist (tests.wrongvector, timestep, VECTOR)"); if (OPENFLUID_IsVariableExist(TU,"tests.wrongvector",SimStatus->getCurrentStep()+21, openfluid::core::Value::VECTOR)) OPENFLUID_RaiseError("tests.primitives.use","incorrect OPENFLUID_IsVariableExist (tests.wrongvector, timestep+21, VECTOR)"); if (OPENFLUID_IsVariableExist(TU,"tests.vector",SimStatus->getCurrentStep(), openfluid::core::Value::DOUBLE)) OPENFLUID_RaiseError("tests.primitives.use","incorrect OPENFLUID_IsVariableExist (tests.vector, timestep, DOUBLE)"); // std::cout << "PrimitiveUseFunc runStep InputData..." << std::endl; // ====== Input data ====== if (!OPENFLUID_IsInputDataExist(TU,"indataA")) OPENFLUID_RaiseError("tests.primitives.use","incorrect OPENFLUID_IsInputDataExist (indataA)"); if (!OPENFLUID_IsInputDataExist(TU,"indataB")) OPENFLUID_RaiseError("tests.primitives.use","incorrect OPENFLUID_IsInputDataExist (indataB)"); if (!OPENFLUID_IsInputDataExist(TU,"indataC")) OPENFLUID_RaiseError("tests.primitives.use","incorrect OPENFLUID_IsInputDataExist (indataC)"); if (OPENFLUID_IsInputDataExist(TU,"wrongdata")) OPENFLUID_RaiseError("tests.primitives.use","incorrect OPENFLUID_IsInputDataExist (wrongdata)"); TheInputDouble = 0.0; OPENFLUID_GetInputData(TU,"indataA",&TheInputDouble); if (!openfluid::tools::IsVeryClose(TheInputDouble,1.1)) OPENFLUID_RaiseError("tests.primitives.use","incorrect OPENFLUID_GetInputData (indataA wrongvalue)"); TheInputStr = ""; OPENFLUID_GetInputData(TU,"indataB",&TheInputStr); std::string RefStr; openfluid::tools::ConvertValue(TU->getID(),&RefStr); RefStr = "CODE"+RefStr; if (TheInputStr != RefStr) OPENFLUID_RaiseError("tests.primitives.use","incorrect OPENFLUID_GetInputData (indataB wrongvalue)"); // std::cout << "PrimitiveUseFunc runStep Events..." << std::endl; // ====== Events ====== TheEvents.clear(); OPENFLUID_GetEvents(TU,SimStatus->getCurrentTime(),SimStatus->getCurrentTime() + SimStatus->getTimeStep(),&TheEvents); if (TheEvents.getCount() > 2) OPENFLUID_RaiseError("tests.primitives.use","incorrect OPENFLUID_GetEvents"); Ev = openfluid::core::Event(openfluid::core::DateTime(SimStatus->getCurrentTime()+(SimStatus->getTimeStep()*2))); OPENFLUID_AppendEvent(TU,Ev); END_LOOP // std::cout << "*** PrimitiveUseFunc runStep End Loop" << std::endl; return true; }
void ExportUnitsGraphAsDotFile(const std::string& Filename, const std::string& SubTitle) { std::ofstream DotFile; std::string OutputDir; const openfluid::core::UnitsListByClassMap_t* UnitsByClass = mp_SpatialData->allSpatialUnitsByClass(); const openfluid::core::UnitsList_t* UnitsList = nullptr; std::vector<openfluid::core::UnitsClass_t> ClassVector; openfluid::core::SpatialUnit* TheUnit; openfluid::core::UnitsListByClassMap_t::const_iterator itUnitsClass; openfluid::core::UnitsList_t::const_iterator itUnitsList; OPENFLUID_GetRunEnvironment("dir.output",OutputDir); DotFile.open(std::string(OutputDir+"/"+Filename).c_str()); DotFile << "digraph \"spatial-graph\" {" << "\n"; DotFile << "\n"; DotFile << "label = \"" << m_Title << "\\n" << SubTitle << "\";" << "\n"; DotFile << "fontsize = 24;" << "\n"; DotFile << "\n"; for (itUnitsClass=UnitsByClass->begin(); itUnitsClass!=UnitsByClass->end(); ++itUnitsClass) { ClassVector.push_back((*itUnitsClass).first); std::string Options = ""; std::string ClassStr = (*itUnitsClass).first; UnitsClassStyles_t::iterator ItStyle = m_UnitsClassStyles.find(ClassStr); if (ItStyle != m_UnitsClassStyles.end()) { Options = "["; StyleAttibutes_t::iterator ItAttr = (*ItStyle).second.begin(); for (; ItAttr!=(*ItStyle).second.end(); ++ItAttr) { if (ItAttr != (*ItStyle).second.begin()) Options += ","; Options += (*ItAttr).first+"="+(*ItAttr).second; } Options += "];"; } UnitsList=((*itUnitsClass).second).list(); for (itUnitsList=UnitsList->begin(); itUnitsList!=UnitsList->end(); ++itUnitsList) { TheUnit = const_cast<openfluid::core::SpatialUnit*>(&(*itUnitsList)); std::string IDStr = ""; openfluid::tools::convertValue(TheUnit->getID(),&IDStr); DotFile << generateDotNode(ClassStr,IDStr,Options) << "\n"; } } DotFile << "\n"; for (itUnitsClass=UnitsByClass->begin(); itUnitsClass!=UnitsByClass->end(); ++itUnitsClass) { UnitsList=((*itUnitsClass).second).list(); for (itUnitsList=UnitsList->begin(); itUnitsList!=UnitsList->end(); ++itUnitsList) { TheUnit = const_cast<openfluid::core::SpatialUnit*>(&(*itUnitsList)); std::string SrcClassStr = TheUnit->getClass(); std::string SrcIDStr = ""; openfluid::tools::convertValue(TheUnit->getID(),&SrcIDStr); for (unsigned int i=0; i<ClassVector.size(); i++) { const openfluid::core::UnitsPtrList_t* ToUnits = const_cast<openfluid::core::UnitsPtrList_t*>(TheUnit->toSpatialUnits(ClassVector[i])); if (ToUnits != nullptr) { std::string DestClassStr = ClassVector[i]; openfluid::core::UnitsPtrList_t::const_iterator itToUnits; for (itToUnits=ToUnits->begin(); itToUnits!=ToUnits->end(); ++itToUnits) { std::string DestIDStr = ""; openfluid::tools::convertValue((*itToUnits)->getID(),&DestIDStr); DotFile << generateDotEdge(SrcClassStr,SrcIDStr,DestClassStr,DestIDStr,"") << "\n"; } } const openfluid::core::UnitsPtrList_t* ParentUnits = const_cast<openfluid::core::UnitsPtrList_t*>(TheUnit->parentSpatialUnits(ClassVector[i])); if (ParentUnits != nullptr) { std::string DestClassStr = ClassVector[i]; openfluid::core::UnitsPtrList_t::const_iterator itParentUnits; for (itParentUnits=ParentUnits->begin(); itParentUnits!=ParentUnits->end(); ++itParentUnits) { std::string DestIDStr = ""; openfluid::tools::convertValue((*itParentUnits)->getID(),&DestIDStr); DotFile << generateDotEdge(SrcClassStr,SrcIDStr, DestClassStr,DestIDStr, "[arrowhead=odiamond,color=gray50,style=dashed]") << "\n"; } } } } } DotFile << "\n"; DotFile << "}" << "\n"; DotFile.close(); }