long cOo::BreakPointFunction::getNextDataSetFrom(
long fromIndex, Time &time, DataSet &fromQuery ) {
    
    double factor; // interpolation factor
    long foundIndex = IndexNotFound; // init
    RecordIter re, ne; // iterators
    
    // initialize iterators
    re = record.begin(); re++;
    ne = re; re = record.begin();
    
    // then move then until they reach fromIndex
    for( long k=0; k<fromIndex; k++ ) { re++; ne++; }
    
    if( fromIndex > record.size()-1 ) return foundIndex; // check input
    if( time < (*re).time || time > getStopTime() ) return foundIndex;
    
    // search from the given index to 1 before last
    for( long k=fromIndex; k<record.size()-1; k++, re++, ne++ ) {
    
        // if next time one is >=
        if( (*ne).time >= time ) {
        
            factor = ( time - (*re).time ) / ( (*ne).time - (*re).time );
            fromQuery = (*re).data.interpolate( (*ne).data, factor );
            foundIndex = k; break; // we interpolate the data sets
        }
    }
    
    return( foundIndex );
}
Exemplo n.º 2
0
	/*******************************************************//**
	 * Executes the helper do step operation.
	 *
	 * @return	.
	 *******************************************************/
	int MainController::runHelperDoStep_() {
		// Advance to next time step
		fmiStatus_ = fmu_->doStep(fmiComponent_, time_, getStepDelta(), fmiTrue);

		if(fmiStatus_ != fmiOK) {
			Logger::getInstance()->printError("MainController::doOneStep_ resulted in error");
			return 1;
		}
		scalarValueResults_ = mainDataModel_->getScalarValueResults(time_);


		if (scalarValueResults_ == NULL) {
			return 1;
		}

		if (resultCallbackPtr_ != NULL) {
			resultCallbackPtr_(scalarValueResults_->toStruct());
		}

		nSteps_++;
		time_ = min(time_+getStepDelta(), getStopTime());

		return 0;
	}
Exemplo n.º 3
0
	/*******************************************************//**
	 * Initializes the slave.
	 *
	 * @return	.
	 *******************************************************/
	int MainController::initializeSlave_() {
		
		Logger::getInstance()->printDebug(_T("-=MainController::initializeSlave_=-\n"));

		time_ = getStartTime();
		double stopTime = getStopTime();

		Logger::getInstance()->printDebug(_T("-=MainController::initializeSlave_=-B\n"));

		fmiStatus status =  fmu_->initializeSlave(fmiComponent_, time_, fmiTrue, stopTime);

		Logger::getInstance()->printDebug(_T("-=MainController::initializeSlave_=-C\n"));

		if (status > fmiWarning) {
			setStateError_(_T("Could not initialize slaves\n"));
			return 1;
		} else {
			Logger::getInstance()->printDebug(_T("initializeSlave() successful\n"));
			setState_( simStateNative_3_init_initializedSlaves );


			return 0;
		}
	}
Exemplo n.º 4
0
	/*******************************************************//**
	 * Print summary.
	 *******************************************************/
	void MainController::printSummary() {
		// Print simulation summary
		if (isLoggingEnabled_) printf("Step %d to t=%.4f\n", nSteps_, time_);

		char msg1[MSG_BUFFER_SIZE_SMALL];
		char msg2[MSG_BUFFER_SIZE_SMALL];
		char msg3[MSG_BUFFER_SIZE_SMALL];

		sprintf_s(msg1, MSG_BUFFER_SIZE_SMALL,"Simulation from %g to %g terminated successful\n", getStartTime(), getStopTime());
		Logger::getInstance()->printDebug (msg1);

		sprintf_s(msg2, MSG_BUFFER_SIZE_SMALL, "  steps ............ %d\n", nSteps_);
		Logger::getInstance()->printDebug (msg2);

		sprintf_s(msg3, MSG_BUFFER_SIZE_SMALL, "  fixed step size .. %g\n", getStepDelta());
		Logger::getInstance()->printDebug (msg3);
	}
Exemplo n.º 5
0
	/*******************************************************//**
	 * Gets the is simulation complete.
	 *
	 * @return	.
	 *******************************************************/
	int MainController::isSimulationComplete() {
		return !(time_ < getStopTime()) ;
	}
Exemplo n.º 6
0
	/*******************************************************//**
	 * Gets the instantiate slave.
	 *
	 * @return	.
	 *******************************************************/
	int MainController::instantiateSlave_() {

		Logger::getInstance()->printDebug(_T("-=MainController::instantiateSlave_=-\n"));
		Logger::getInstance()->printDebug(_T("MainController::simulateHelperInit\n"));

		_TCHAR currentDirectory[MAX_PATH] =  _T("");
		_TCHAR currentDirectory2[MAX_PATH] =  _T("");
		_TCHAR exeDirectory[MAX_PATH] =  _T("");

		isLoggingEnabled_ = 1;
		const char* guid;                // global unique id of the fmu
		const char* modelIdentifier;                //
		fmiCallbackFunctions callbackFunctions;  // called by the model during simulation
		fmiBoolean toleranceControlled = fmiFalse;
		nSteps_ = 0;
		fmiReal timeout = 100.0;
		fmiBoolean visible = false;
		fmiBoolean interactive = true;

		// Set the start time and initialize
		time_ = getStartTime();

		GetCurrentDirectory(MAX_PATH, currentDirectory);
		Logger::getInstance()->printDebug2(_T("currentDirectory: %s\n"), currentDirectory);

		this->getModuleFolderPath(exeDirectory);

		callbackFunctions.logger = FMUlogger::log;
		callbackFunctions.allocateMemory = calloc;
		callbackFunctions.freeMemory = free;

		guid = getString(fmu_->modelDescription, att_guid);
		modelIdentifier =  getModelIdentifier(fmu_->modelDescription);

		Logger::getInstance()->printDebug2(_T("exeDirectory: %s\n"), exeDirectory);
		Logger::getInstance()->printDebug2(_T("unzipFolderPath_%s\n"), unzipFolderPath_);

		Logger::getInstance()->printDebugDouble(_T("stepDelta: %s\n"), getStepDelta());
		Logger::getInstance()->printDebugDouble(_T("time_: %s\n"), time_);
		Logger::getInstance()->printDebugDouble(_T("stopTime: %s\n"), getStopTime());

		Logger::getInstance()->printDebug2(_T("instanceName is %s\n"), modelIdentifier);
		Logger::getInstance()->printDebug2(_T("GUID = %s!\n"), guid);

		BOOL isSet = SetCurrentDirectory(unzipFolderPath_);
		int bufferLength = GetCurrentDirectory(MAX_PATH, currentDirectory2);
		Logger::getInstance()->printDebug2(_T("currentDirectory2: %s\n"), currentDirectory2);

		fmiComponent_ = fmu_->instantiateSlave (
			modelIdentifier,		//fmiString  instanceName
			guid,					//fmiString  fmuGUID
			"Model1",				//fmuLocation
			"",						//fmiString  mimeType
			timeout,				//fmiReal timeout
			visible,				//fmiBoolean visible
			interactive,			//fmiBoolean interactive
			callbackFunctions,
			isLoggingEnabled_		//
			);

		if (!fmiComponent_) {
			setStateError_(_T("Could not instantiate slaves\n"));
			return 1;
		} else {
			Logger::getInstance()->printDebug(_T("Successfully instantiated one slave\n"));
			mainDataModel_->setFmiComponent(fmiComponent_);
			setState_( simStateNative_3_init_instantiatedSlaves );

			return 0;
		}
	}
void cOo::BreakPointFunction::print( void ) {
    
    cout << isActive() << " | type: " << getType() << " | start: " << getStartTime() << " | stop: "
    << getStopTime() << " | size: " << getSize() << " | head: " << head << " | id: " << id << endl;
}