void appendToDataFiles() { if (!m_OKToGo) return; openfluid::core::SpatialUnit* UU; // write data files for (std::list<KmlSerieInfo>::iterator it=m_KmlSeriesInfos.begin();it!=m_KmlSeriesInfos.end();++it) { for (std::map<openfluid::core::UnitID_t,KmlUnitInfoExtra>::iterator it2=(*it).UnitsInfos.begin(); it2!=(*it).UnitsInfos.end(); ++it2) { if ((*it2).second.IsPlotted) { UU = OPENFLUID_GetUnit((*it).UnitsClass,(*it2).second.UnitID); if (UU != nullptr) { (*((*it2).second.DataFile)) << OPENFLUID_GetCurrentDate().getAsString("%Y%m%d-%H%M%S"); for (std::vector<openfluid::core::VariableName_t>::iterator it3 = (*it).VarsList.begin(); it3 != (*it).VarsList.end(); ++it3) { if (OPENFLUID_IsVariableExist(UU,*it3,OPENFLUID_GetCurrentTimeIndex(),openfluid::core::Value::DOUBLE)) { double Val; OPENFLUID_GetVariable(UU,*it3,OPENFLUID_GetCurrentTimeIndex(),Val); (*((*it2).second.DataFile)) << ";" << Val; } } (*((*it2).second.DataFile)) << "\n"; } else { (*((*it2).second.DataFile)) << OPENFLUID_GetCurrentDate().getAsString("%Y%m%d-%H%M%S") << ";n/a\n"; } } } } }
bool PrimitivesTypedValuesUseFunction::runStep(const openfluid::base::SimulationStatus* SimStatus) { openfluid::core::Unit* TU; unsigned int TUID; unsigned int CurStep; double RefDouble; long RefLong; bool RefBool; std::string RefString; unsigned long RefVectorSize = 40; unsigned long RefMatrixColsNb = 4; unsigned long RefMatrixRowsNb = 3; double VarDouble; long VarLong; bool VarBool; std::string VarString; openfluid::core::VectorValue VarVectorVal; openfluid::core::MatrixValue VarMatrixVal; openfluid::core::MapValue VarMapVal; double NewDouble; long NewLong; bool NewBool; std::string NewString; unsigned long NewVectorSize = 5; unsigned long NewMatrixColsNb = RefMatrixColsNb + 1; unsigned long NewMatrixRowsNb = RefMatrixRowsNb + 1; DECLARE_UNITS_ORDERED_LOOP(1); BEGIN_UNITS_ORDERED_LOOP(1,"TestUnits",TU) TUID = TU->getID(); CurStep = SimStatus->getCurrentStep(); RefDouble = (double)TUID/10; RefLong = TUID; RefBool = (TUID%2 == 0); RefString = Glib::ustring::compose("ID %1",TUID); NewDouble = TUID*CurStep*0.1; NewLong = TUID*CurStep*10; NewBool = ((TUID*CurStep)%2 == 0); NewString = Glib::ustring::compose("%1 %2x%3","strvalue",TUID,CurStep); // double OPENFLUID_GetVariable(TU,"tests.double",CurStep,VarDouble); if (!openfluid::tools::IsCloseEnough(VarDouble,RefDouble,0.00001)) OPENFLUID_RaiseError("tests.primitivestypedvalues.use","incorrect double value (tests.double) get by reference"); OPENFLUID_SetVariable(TU,"tests.double",CurStep,NewDouble); OPENFLUID_GetVariable(TU,"tests.double",CurStep,VarDouble); if (!openfluid::tools::IsCloseEnough(VarDouble,NewDouble,0.00001)) OPENFLUID_RaiseError("tests.primitivestypedvalues.use","incorrect double value after update (tests.double)"); if (!OPENFLUID_IsTypedVariableExist(TU,"tests.double",openfluid::core::Value::DOUBLE)) OPENFLUID_RaiseError("tests.primitivestypedvalues.use","incorrect OPENFLUID_IsTypedVariableExist (tests.double, DOUBLE)"); // long OPENFLUID_GetVariable(TU,"tests.integer",CurStep,VarLong); if (VarLong != RefLong) OPENFLUID_RaiseError("tests.primitivestypedvalues.use","incorrect long value (tests.integer) get by reference"); OPENFLUID_SetVariable(TU,"tests.integer",CurStep,NewLong); OPENFLUID_GetVariable(TU,"tests.integer",CurStep,VarLong); if (VarLong != NewLong) OPENFLUID_RaiseError("tests.primitivestypedvalues.use","incorrect long value after update (tests.integer)"); if (!OPENFLUID_IsTypedVariableExist(TU,"tests.integer",openfluid::core::Value::INTEGER)) OPENFLUID_RaiseError("tests.primitivestypedvalues.use","incorrect OPENFLUID_IsTypedVariableExist (tests.integer, INTEGER)"); // bool OPENFLUID_GetVariable(TU,"tests.bool",CurStep,VarBool); if (VarBool != RefBool) OPENFLUID_RaiseError("tests.primitivestypedvalues.use","incorrect bool value (tests.bool) get by reference"); OPENFLUID_SetVariable(TU,"tests.bool",CurStep,NewBool); OPENFLUID_GetVariable(TU,"tests.bool",CurStep,VarBool); if (VarBool != NewBool) OPENFLUID_RaiseError("tests.primitivestypedvalues.use","incorrect bool value after update (tests.bool)"); if (!OPENFLUID_IsTypedVariableExist(TU,"tests.bool",openfluid::core::Value::BOOLEAN)) OPENFLUID_RaiseError("tests.primitivestypedvalues.use","incorrect OPENFLUID_IsTypedVariableExist (tests.bool, BOOLEAN)"); // string OPENFLUID_GetVariable(TU,"tests.string",CurStep,VarString); if (VarString != RefString) OPENFLUID_RaiseError("tests.primitivestypedvalues.use","incorrect string value (tests.string) get by reference"); OPENFLUID_SetVariable(TU,"tests.string",CurStep,NewString); OPENFLUID_GetVariable(TU,"tests.string",CurStep,VarString); if (VarString != NewString) OPENFLUID_RaiseError("tests.primitivestypedvalues.use","incorrect string value after update (tests.string)"); if (!OPENFLUID_IsTypedVariableExist(TU,"tests.string",openfluid::core::Value::STRING)) OPENFLUID_RaiseError("tests.primitivestypedvalues.use","incorrect OPENFLUID_IsTypedVariableExist (tests.string, STRING)"); // vector OPENFLUID_GetVariable(TU,"tests.vector",CurStep,VarVectorVal); if (VarVectorVal.getSize() != RefVectorSize) OPENFLUID_RaiseError("tests.primitivestypedvalues.use","incorrect vector size get by reference"); openfluid::core::VectorValue NewVect(NewVectorSize,NewDouble); OPENFLUID_SetVariable(TU,"tests.vector",CurStep,NewVect); OPENFLUID_GetVariable(TU,"tests.vector",CurStep,VarVectorVal); if (VarVectorVal.getSize() != NewVectorSize) OPENFLUID_RaiseError("tests.primitivestypedvalues.use","incorrect vector size after update"); if (!openfluid::tools::IsCloseEnough(VarVectorVal[0],NewDouble,0.00001)) OPENFLUID_RaiseError("tests.primitivestypedvalues.use","incorrect vector value at index 0 after update"); if (!openfluid::tools::IsCloseEnough(VarVectorVal[4],NewDouble,0.00001)) OPENFLUID_RaiseError("tests.primitivestypedvalues.use","incorrect vector value at index 4 after update"); if (!OPENFLUID_IsTypedVariableExist(TU,"tests.vector",openfluid::core::Value::VECTOR)) OPENFLUID_RaiseError("tests.primitivestypedvalues.use","incorrect OPENFLUID_IsTypedVariableExist (tests.vector, VECTOR)"); // old style vector VarVectorVal.clear(); OPENFLUID_GetVariable(TU,"tests.oldvector",CurStep,VarVectorVal); if (VarVectorVal.getSize() != RefVectorSize) OPENFLUID_RaiseError("tests.primitivestypedvalues.use","incorrect oldvector size get by reference"); OPENFLUID_SetVariable(TU,"tests.oldvector",CurStep,NewVect); OPENFLUID_GetVariable(TU,"tests.oldvector",CurStep,VarVectorVal); if (VarVectorVal.getSize() != NewVectorSize) OPENFLUID_RaiseError("tests.primitivestypedvalues.use","incorrect oldvector size after update"); if (!openfluid::tools::IsCloseEnough(VarVectorVal[0],NewDouble,0.00001)) OPENFLUID_RaiseError("tests.primitivestypedvalues.use","incorrect oldvector value at index 0 after update"); if (!openfluid::tools::IsCloseEnough(VarVectorVal[4],NewDouble,0.00001)) OPENFLUID_RaiseError("tests.primitivestypedvalues.use","incorrect oldvector value at index 4 after update"); if (!OPENFLUID_IsTypedVariableExist(TU,"tests.oldvector",openfluid::core::Value::VECTOR)) OPENFLUID_RaiseError("tests.primitivestypedvalues.use","incorrect OPENFLUID_IsTypedVariableExist (tests.oldvector, VECTOR)"); // matrix OPENFLUID_GetVariable(TU,"tests.matrix",CurStep,VarMatrixVal); if (VarMatrixVal.getColsNbr() != RefMatrixColsNb) OPENFLUID_RaiseError("tests.primitivestypedvalues.use","incorrect matrix cols nb get by reference"); if (VarMatrixVal.getRowsNbr() != RefMatrixRowsNb) OPENFLUID_RaiseError("tests.primitivestypedvalues.use","incorrect matrix rows nb get by reference"); openfluid::core::MatrixValue NewMatrix(NewMatrixColsNb,NewMatrixRowsNb,NewDouble); OPENFLUID_SetVariable(TU,"tests.matrix",CurStep,NewMatrix); OPENFLUID_GetVariable(TU,"tests.matrix",CurStep,VarMatrixVal); if (VarMatrixVal.getColsNbr() != NewMatrixColsNb) OPENFLUID_RaiseError("tests.primitivestypedvalues.use","incorrect matrix cols nb after update"); if (VarMatrixVal.getRowsNbr() != NewMatrixRowsNb) OPENFLUID_RaiseError("tests.primitivestypedvalues.use","incorrect matrix rows nb after update"); if (!openfluid::tools::IsCloseEnough(VarMatrixVal.get(0,0),NewDouble,0.00001)) OPENFLUID_RaiseError("tests.primitivestypedvalues.use","incorrect matrix value at index 0,0 after update"); if (!openfluid::tools::IsCloseEnough(VarMatrixVal.get(4,3),NewDouble,0.00001)) OPENFLUID_RaiseError("tests.primitivestypedvalues.use","incorrect matrix value at index 4,3 after update"); if (!OPENFLUID_IsTypedVariableExist(TU,"tests.matrix",openfluid::core::Value::MATRIX)) OPENFLUID_RaiseError("tests.primitivestypedvalues.use","incorrect OPENFLUID_IsTypedVariableExist (tests.matrix, MATRIX)"); // map OPENFLUID_GetVariable(TU,"tests.map",CurStep,VarMapVal); if (VarMapVal.getSize() != 2) OPENFLUID_RaiseError("tests.primitivestypedvalues.use","incorrect map size get by reference"); openfluid::core::MapValue NewMap; NewMap.setString("key1",NewString); NewMap.setDouble("key2",NewDouble); NewMap.setBoolean("key3",NewBool); OPENFLUID_SetVariable(TU,"tests.map",CurStep,NewMap); OPENFLUID_GetVariable(TU,"tests.map",CurStep,VarMapVal); if (VarMapVal.getSize() != 3) OPENFLUID_RaiseError("tests.primitivestypedvalues.use","incorrect map size after update"); if (VarMapVal.getString("key1") != NewString) OPENFLUID_RaiseError("tests.primitivestypedvalues.use","incorrect map value at key key1 after update"); if (!openfluid::tools::IsCloseEnough(VarMapVal.getDouble("key2"),NewDouble,0.00001)) OPENFLUID_RaiseError("tests.primitivestypedvalues.use","incorrect map value at key key2 after update"); if (VarMapVal.getBoolean("key3") != NewBool) OPENFLUID_RaiseError("tests.primitivestypedvalues.use","incorrect map value at key key3 after update"); if (!OPENFLUID_IsTypedVariableExist(TU,"tests.map",openfluid::core::Value::MAP)) OPENFLUID_RaiseError("tests.primitivestypedvalues.use","incorrect OPENFLUID_IsTypedVariableExist (tests.map, MAP)"); // none if (!OPENFLUID_IsTypedVariableExist(TU,"tests.none",openfluid::core::Value::NONE)) OPENFLUID_RaiseError("tests.primitivestypedvalues.use","incorrect OPENFLUID_IsTypedVariableExist (tests.none, NONE)"); if (!OPENFLUID_IsVariableExist(TU,"tests.none",CurStep,openfluid::core::Value::DOUBLE)) OPENFLUID_RaiseError("tests.primitivestypedvalues.use","incorrect OPENFLUID_IsVariableExist (tests.none, DOUBLE)"); VarDouble = 0.0; OPENFLUID_GetVariable(TU,"tests.none",CurStep,VarDouble); if (!openfluid::tools::IsCloseEnough(VarDouble,RefDouble,0.00001)) OPENFLUID_RaiseError("tests.primitivestypedvalues.use","incorrect double value (tests.none)"); OPENFLUID_SetVariable(TU,"tests.none",CurStep,NewLong); if (!OPENFLUID_IsVariableExist(TU,"tests.none",CurStep,openfluid::core::Value::INTEGER)) OPENFLUID_RaiseError("tests.primitivestypedvalues.use","incorrect OPENFLUID_IsVariableExist (tests.none, INTEGER)"); VarLong = 0; OPENFLUID_GetVariable(TU,"tests.none",CurStep,VarLong); if (VarLong != NewLong) OPENFLUID_RaiseError("tests.primitivestypedvalues.use","incorrect long value (tests.none)"); OPENFLUID_SetVariable(TU,"tests.none",CurStep,openfluid::core::NullValue()); if (!OPENFLUID_IsVariableExist(TU,"tests.none",CurStep,openfluid::core::Value::NULLL)) OPENFLUID_RaiseError("tests.primitivestypedvalues.use","incorrect OPENFLUID_IsVariableExist (tests.none, NULL)"); OPENFLUID_SetVariable(TU,"tests.none",CurStep,NewBool); if (!OPENFLUID_IsVariableExist(TU,"tests.none",CurStep,openfluid::core::Value::BOOLEAN)) OPENFLUID_RaiseError("tests.primitivestypedvalues.use","incorrect OPENFLUID_IsVariableExist (tests.none, BOOLEAN)"); VarBool = false; OPENFLUID_GetVariable(TU,"tests.none",CurStep,VarBool); if (VarBool != NewBool) OPENFLUID_RaiseError("tests.primitivestypedvalues.use","incorrect boolean value (tests.none)"); OPENFLUID_SetVariable(TU,"tests.none",CurStep,NewString); if (!OPENFLUID_IsVariableExist(TU,"tests.none",CurStep,openfluid::core::Value::STRING)) OPENFLUID_RaiseError("tests.primitivestypedvalues.use","incorrect OPENFLUID_IsVariableExist (tests.none, STRING)"); VarString= ""; OPENFLUID_GetVariable(TU,"tests.none",CurStep,VarString); if (VarString != NewString) OPENFLUID_RaiseError("tests.primitivestypedvalues.use","incorrect string value (tests.none)"); OPENFLUID_SetVariable(TU,"tests.none",CurStep,NewVect); if (!OPENFLUID_IsVariableExist(TU,"tests.none",CurStep,openfluid::core::Value::VECTOR)) OPENFLUID_RaiseError("tests.primitivestypedvalues.use","incorrect OPENFLUID_IsVariableExist (tests.none, VECTOR)"); VarVectorVal.clear(); OPENFLUID_GetVariable(TU,"tests.none",CurStep,VarVectorVal); if (VarVectorVal.size() != NewVect.size()) OPENFLUID_RaiseError("tests.primitivestypedvalues.use","incorrect vector size value (tests.none)"); if (!openfluid::tools::IsCloseEnough(VarVectorVal[4],NewDouble,0.00001)) OPENFLUID_RaiseError("tests.primitivestypedvalues.use","incorrect vector value at index 4 (tests.none)"); OPENFLUID_SetVariable(TU,"tests.none",CurStep,NewMatrix); if (!OPENFLUID_IsVariableExist(TU,"tests.none",CurStep,openfluid::core::Value::MATRIX)) OPENFLUID_RaiseError("tests.primitivestypedvalues.use","incorrect OPENFLUID_IsVariableExist (tests.none, MATRIX)"); VarMatrixVal.clear(); OPENFLUID_GetVariable(TU,"tests.none",CurStep,VarMatrixVal); if (VarMatrixVal.size() != NewMatrix.size()) OPENFLUID_RaiseError("tests.primitivestypedvalues.use","incorrect matrix size value (tests.none)"); if (!openfluid::tools::IsCloseEnough(VarMatrixVal.get(4,3),NewDouble,0.00001)) OPENFLUID_RaiseError("tests.primitivestypedvalues.use","incorrect matrix value at index 4,3 (tests.none)"); OPENFLUID_SetVariable(TU,"tests.none",CurStep,NewMap); if (!OPENFLUID_IsVariableExist(TU,"tests.none",CurStep,openfluid::core::Value::MAP)) OPENFLUID_RaiseError("tests.primitivestypedvalues.use","incorrect OPENFLUID_IsVariableExist (tests.none, MAP)"); VarMapVal.clear(); OPENFLUID_GetVariable(TU,"tests.none",CurStep,VarMapVal); if (VarMapVal.size() != NewMap.size()) OPENFLUID_RaiseError("tests.primitivestypedvalues.use","incorrect map size value (tests.none)"); if (VarMapVal.getBoolean("key3") != NewBool) OPENFLUID_RaiseError("tests.primitivestypedvalues.use","incorrect map value at key key3 (tests.none)"); END_LOOP return true; }
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; }