// ----------------------------------------------------------------------------- // CCapInfo::GeneralInfoL() // Write general device capability information. // ----------------------------------------------------------------------------- // void CCapInfo::GeneralInfoL() { TRACE_FUNC_ENTRY; TInt err( KErrNone ); TBuf<KBufSize> buf; TBuf<KBufSize> longName; TBuf<KBufSize> coutryCode; TBuf<KBufSize> networkID; WriteTagL(EGeneral, TXmlParser::EElementBegin); if ( !iSconInfo->IsReady() ) { LOGGER_WRITE("iSconInfo wasn't ready, call iSconInfo->FetchInfoL"); iSconInfo->FetchInfoL( iFsSession ); } if ( iSconInfo->iManufacturer ) { WriteValueL( EManufacturer, *iSconInfo->iManufacturer ); } if ( iSconInfo->iProduct ) { WriteValueL( EModel, *iSconInfo->iProduct ); } // serial number if ( iSconInfo->iSerialNumber ) { WriteValueL( ESN, *iSconInfo->iSerialNumber ); } // software version if ( iSconInfo->iSWVersion ) { WriteAttributeL( ESW, *iSconInfo->iSWVersion, iSconInfo->iDate ); } // language WriteValueL( ELanguage, iSconInfo->iLanguage ); // this must succeed - do not trap MemoryInfoL(); // Operator TRAP( err, CapUtil::GetOperatorNameL( longName, coutryCode, networkID ) ); LOGGER_WRITE_1( "CapUtil::GGetOperatorNameL returned : %d", err ); if( err == KErrNone ) { LOGGER_WRITE_3( "CSConFsHandler::GetOperatorNameL longName = %S coutryCode = %S networkID = %S", &longName, &coutryCode, &networkID ); _LIT( KNetworkInfo, "NetworkInfo" ); _LIT( KCurrentNetwork, "CurrentNetwork=" ); _LIT( KCountryCode, "CountryCode=" ); _LIT( KNetworkID, "NetworkID=" ); WriteTagL( EExt, TXmlParser::EElementBegin ); WriteValueL( EXNam, KNetworkInfo ); // write CurrentNetwork buf.Copy( KCurrentNetwork ); buf.Append( longName ); WriteValueL( EXVal, buf ); // write CountryCode buf.Copy( KCountryCode ); buf.Append( coutryCode ); WriteValueL( EXVal, buf ); // write NetworkID buf.Copy( KNetworkID ); buf.Append( networkID ); WriteValueL( EXVal, buf ); WriteTagL( EExt, TXmlParser::EElementEnd ); } if ( iSconInfo->iModel ) { // print modelname (phone model sales name. For example "N01".) WriteTagL( EExt, TXmlParser::EElementBegin ); _LIT(KModelName, "ModelName"); WriteValueL( EXNam, KModelName ); WriteValueL( EXVal, *iSconInfo->iModel ); WriteTagL( EExt, TXmlParser::EElementEnd ); } if ( iSconInfo->iProductCode ) { // print productcode WriteTagL( EExt, TXmlParser::EElementBegin ); _LIT( KProductCode, "ProductCode" ); WriteValueL( EXNam, KProductCode ); WriteValueL( EXVal, *iSconInfo->iProductCode ); WriteTagL( EExt, TXmlParser::EElementEnd ); } // print advanced info WriteTagL( EExt, TXmlParser::EElementBegin ); _LIT(KAdvancedDeviceInfo, "AdvancedDeviceInfo"); WriteValueL( EXNam, KAdvancedDeviceInfo ); TBuf<KSysVersionInfoTextLength> temp; if ( iSconInfo->iRevision ) { // product revision. For example "01" _LIT( KRevision, "Revision=" ); temp.Copy( KRevision ); temp.Append( *iSconInfo->iRevision ); LOGGER_WRITE_1( "CCapInfo::GeneralInfoL() : %S ", &temp ); WriteValueL( EXVal, temp ); } if ( iSconInfo->iSysVersionInfo ) { _LIT( KFWVersion, "FWVersion=" ); temp.Copy( KFWVersion ); temp.Append( *iSconInfo->iSysVersionInfo ); LOGGER_WRITE_1( "CCapInfo::GeneralInfoL() : %S ", &temp ); WriteValueL( EXVal, temp ); } SysVersionInfo::TSymbianOSVersion osVersion; err = iSconInfo->GetSymbianVersion( osVersion ); LOGGER_WRITE_1("TSymbianOSVersion info error: %d", err) if ( !err ) { // Now osVersion contains the Symbian OS version information _LIT( KSymbianOSVersion, "SymbianOSVersion=%d.%d" ); temp.Format( KSymbianOSVersion, osVersion.iMajorVersion, osVersion.iMinorVersion ); LOGGER_WRITE_1( "CCapInfo::GeneralInfoL() : %S ", &temp ); WriteValueL( EXVal, temp ); } VersionInfo::TPlatformVersion platformVersion; err = iSconInfo->GetS60Version( platformVersion ); if ( !err ) { _LIT( KS60Version, "S60PlatformVersion=%d.%d" ); temp.Format( KS60Version, platformVersion.iMajorVersion, platformVersion.iMinorVersion ); LOGGER_WRITE_1( "CCapInfo::GeneralInfoL() : %S ", &temp ); WriteValueL( EXVal, temp ); } if ( iSconInfo->iLangVersion ) { _LIT( KLangVersion, "LangVersion=" ); temp.Copy( KLangVersion ); temp.Append( *iSconInfo->iLangVersion ); LOGGER_WRITE_1( "CCapInfo::GeneralInfoL() : %S ", &temp ); WriteValueL( EXVal, temp ); } if ( iSconInfo->iLangSWVersion ) { _LIT( KLangSWVersion, "LangSWVersion=" ); temp.Copy( KLangSWVersion ); temp.Append( *iSconInfo->iLangSWVersion ); LOGGER_WRITE_1( "CCapInfo::GeneralInfoL() : %S ", &temp ); WriteValueL( EXVal, temp ); } if ( iSconInfo->iOPVersion ) { // CustomerVersion _LIT( KOPVersion, "OPVersion=" ); temp.Copy( KOPVersion ); temp.Append( *iSconInfo->iOPVersion ); LOGGER_WRITE_1( "CCapInfo::GeneralInfoL() : %S ", &temp ); WriteValueL( EXVal, temp ); } // screen size LOGGER_WRITE_2("Size, width: %d, height: %d", iSconInfo->iScreenSize.iWidth, iSconInfo->iScreenSize.iHeight ); _LIT( KWidth, "ScreenWidth=%d" ); _LIT( KHeight, "ScreenHeight=%d" ); temp.Format( KWidth, iSconInfo->iScreenSize.iWidth ); WriteValueL( EXVal, temp ); temp.Format( KHeight, iSconInfo->iScreenSize.iHeight ); WriteValueL( EXVal, temp ); WriteTagL( EExt, TXmlParser::EElementEnd ); // end of advanced info WriteTagL(EGeneral, TXmlParser::EElementEnd); TRACE_FUNC_EXIT; }
// ----------------------------------------------------------------------------- // CSConTaskQueue::CompleteTask( TInt aTask, TInt aError ) // Set the task to completed -mode // ----------------------------------------------------------------------------- // TInt CSConTaskQueue::CompleteTask( TInt aTask, TInt aError ) { LOGGER_WRITE_1( "CSConTaskQueue::CompleteTask aError: %d", aError ); TInt ret(KErrNone); TInt index( KErrNotFound ); CSConTask* temp = new CSConTask(); if (!temp) return KErrNoMemory; temp->iTaskId = aTask; index = iQueue.Find( temp, CSConTaskQueue::Match ); delete temp; if ( index != KErrNotFound ) { TBool complete( ETrue ); TBool notComplete( EFalse ); TInt progress( KSConCodeTaskCompleted ); switch( aError ) { case KErrNone : iQueue[index]->SetCompleteValue( complete ); progress = KSConCodeTaskCompleted; break; case KErrNotFound : iQueue[index]->SetCompleteValue( complete ); progress = KSConCodeNotFound; break; case KErrCompletion : iQueue[index]->SetCompleteValue( notComplete ); progress = KSConCodeTaskPartiallyCompleted; break; // installer specific errors case SwiUI::KSWInstErrUserCancel: LOGGER_WRITE("User cancelled the operation"); iQueue[index]->SetCompleteValue( complete ); progress = KSConCodeInstErrUserCancel; break; case SwiUI::KSWInstErrFileCorrupted: case KErrSifCorruptedPackage: LOGGER_WRITE("File is corrupted"); iQueue[index]->SetCompleteValue( complete ); progress = KSConCodeInstErrFileCorrupted; break; case SwiUI::KSWInstErrInsufficientMemory: case KErrSifNotEnoughSpace: LOGGER_WRITE("Insufficient free memory in the drive to perform the operation"); iQueue[index]->SetCompleteValue( complete ); progress = KSConCodeInstErrInsufficientMemory; break; case SwiUI::KSWInstErrPackageNotSupported: case KErrSifUnsupportedSoftwareType: LOGGER_WRITE("Installation of the package is not supported"); iQueue[index]->SetCompleteValue( complete ); progress = KSConCodeInstErrPackageNotSupported; break; case SwiUI::KSWInstErrSecurityFailure: LOGGER_WRITE("Package cannot be installed due to security error"); iQueue[index]->SetCompleteValue( complete ); progress = KSConCodeInstErrSecurityFailure; break; case SwiUI::KSWInstErrMissingDependency: case KErrSifMissingDependencies: LOGGER_WRITE("Package cannot be installed due to missing dependency"); iQueue[index]->SetCompleteValue( complete ); progress = KSConCodeInstErrMissingDependency; break; case SwiUI::KSWInstErrFileInUse: LOGGER_WRITE("Mandatory file is in use and prevents the operation"); iQueue[index]->SetCompleteValue( complete ); progress = KSConCodeInstErrFileInUse; break; case SwiUI::KSWInstErrGeneralError: case KErrSifUnknown: LOGGER_WRITE("Unknown error"); iQueue[index]->SetCompleteValue( complete ); progress = KSConCodeInstErrGeneralError; break; case SwiUI::KSWInstErrNoRights: LOGGER_WRITE("The package has no rights to perform the operation"); iQueue[index]->SetCompleteValue( complete ); progress = KSConCodeInstErrNoRights; break; case SwiUI::KSWInstErrNetworkFailure: LOGGER_WRITE("Indicates that network failure aborted the operation"); iQueue[index]->SetCompleteValue( complete ); progress = KSConCodeInstErrNetworkFailure; break; case SwiUI::KSWInstErrBusy: LOGGER_WRITE("Installer is busy doing some other operation"); iQueue[index]->SetCompleteValue( complete ); progress = KSConCodeInstErrBusy; break; case SwiUI::KSWInstErrAccessDenied: LOGGER_WRITE("Target location of package is not accessible"); iQueue[index]->SetCompleteValue( complete ); progress = KSConCodeInstErrAccessDenied; break; case SwiUI::KSWInstUpgradeError: LOGGER_WRITE("The package is an invalid upgrade"); iQueue[index]->SetCompleteValue( complete ); progress = KSConCodeInstUpgradeError; break; case KErrSifMissingBasePackage: LOGGER_WRITE("KErrSifMissingBasePackage"); iQueue[index]->SetCompleteValue( complete ); progress = KSConCodeInstErrSifMissingBasePackage; break; case KErrSifOverflow: LOGGER_WRITE("KErrSifOverflow"); iQueue[index]->SetCompleteValue( complete ); progress = KSConCodeInstErrSifOverflow; break; case KErrSifSameVersionAlreadyInstalled: LOGGER_WRITE("KErrSifSameVersionAlreadyInstalled"); iQueue[index]->SetCompleteValue( complete ); progress = KSConCodeInstErrSifSameVersionAlreadyInstalled; break; case KErrSifNewerVersionAlreadyInstalled: LOGGER_WRITE("KErrSifNewerVersionAlreadyInstalled"); iQueue[index]->SetCompleteValue( complete ); progress = KSConCodeInstErrSifNewerVersionAlreadyInstalled; break; case KErrSifAlreadyActivated: LOGGER_WRITE("KErrSifAlreadyActivated"); iQueue[index]->SetCompleteValue( complete ); progress = KSConCodeInstErrSifAlreadyActivated; break; case KErrSifAlreadyDeactivated: LOGGER_WRITE("KErrSifAlreadyDeactivated"); iQueue[index]->SetCompleteValue( complete ); progress = KSConCodeInstErrSifAlreadyDeactivated; break; case KErrSifBadComponentId: LOGGER_WRITE("KErrSifBadComponentId"); iQueue[index]->SetCompleteValue( complete ); progress = KSConCodeInstErrSifBadComponentId; break; case KErrSifBadInstallerConfiguration: LOGGER_WRITE("KErrSifBadInstallerConfiguration"); iQueue[index]->SetCompleteValue( complete ); progress = KSConCodeInstErrSifBadInstallerConfiguration; break; case KErrSifPackageCannotBeInstalledOnThisDevice: LOGGER_WRITE("KErrSifPackageCannotBeInstalledOnThisDevice"); iQueue[index]->SetCompleteValue( complete ); progress = KSConCodeInstErrSifPackageCannotBeInstalledOnThisDevice; break; case KErrSifUnsupportedLanguage: LOGGER_WRITE("KErrSifUnsupportedLanguage"); iQueue[index]->SetCompleteValue( complete ); progress = KSConCodeInstErrSifUnsupportedLanguage; break; case KErrScrWriteOperationInProgress: LOGGER_WRITE("KErrScrWriteOperationInProgress"); iQueue[index]->SetCompleteValue( complete ); progress = KSConCodeInstErrScrWriteOperationInProgress; break; case KErrScrReadOperationInProgress: LOGGER_WRITE("KErrScrReadOperationInProgress"); iQueue[index]->SetCompleteValue( complete ); progress = KSConCodeInstErrScrReadOperationInProgress; break; case KErrScrNoActiveTransaction: LOGGER_WRITE("KErrScrNoActiveTransaction"); iQueue[index]->SetCompleteValue( complete ); progress = KSConCodeInstErrScrNoActiveTransaction; break; case KErrScrUnsupportedLocale: LOGGER_WRITE("KErrScrUnsupportedLocale"); iQueue[index]->SetCompleteValue( complete ); progress = KSConCodeInstErrScrUnsupportedLocale; break; default : iQueue[index]->SetCompleteValue( complete ); if ( aError < KErrNone && aError >= KErrCorruptSurrogateFound ) { // aError is always negative // -> returned errorcode is from KSConCodeFirstSymbianErr...n progress = KSConCodeFirstSymbianErr - aError; } else { progress = KSConCodeConflict; } break; } iQueue[index]->SetProgressValue( progress ); } else { ret = KErrNotFound; } StartQueue(); return ret; }
// ----------------------------------------------------------------------------- // CSconVersionInfo::FetchInfoL() // fetch device info // ----------------------------------------------------------------------------- // void CSconVersionInfo::FetchInfoL( RFs& aFs ) { TRACE_FUNC_ENTRY; iSymbianVersionError = SysVersionInfo::GetVersionInfo( iSymbianVersion, aFs ); iS60VersionError = VersionInfo::GetVersion( iS60Version, aFs ); TBuf<KSysVersionInfoTextLength> info; TBuf<KSysVersionInfoTextLength> productBuf; TInt err(KErrNone); delete iSWVersion; iSWVersion = NULL; delete iProduct; iProduct = NULL; // get SW version, SW version date and model TRAP( err, CapUtil::GetSWVersionL( info, iDate, productBuf ) ); iSWVersion = info.AllocL(); iProduct = productBuf.AllocL(); LOGGER_WRITE_1("CapUtil::GetSWVersionL err: %d", err); SysVersionInfo::TProductVersion productVersion; TInt sysVersionError = SysVersionInfo::GetVersionInfo( productVersion, aFs ); LOGGER_WRITE_1( "SysVersionInfo::GetVersionInfo returned : %d", sysVersionError ); // Use TelServer to get IMEI and also other info if SysVersionInfo is not supported RTelServer telServer; User::LeaveIfError( telServer.Connect() ); CleanupClosePushL( telServer ); RTelServer::TPhoneInfo teleinfo; User::LeaveIfError( telServer.GetPhoneInfo( 0, teleinfo ) ); RMobilePhone phone; User::LeaveIfError( phone.Open( telServer, teleinfo.iName ) ); CleanupClosePushL( phone ); User::LeaveIfError(phone.Initialise()); TUint32 teleidentityCaps; phone.GetIdentityCaps( teleidentityCaps ); RMobilePhone::TMobilePhoneIdentityV1 telid; TRequestStatus status; phone.GetPhoneId( status, telid ); User::WaitForRequest( status ); if ( status == KErrNone ) { if ( sysVersionError ) { LOGGER_WRITE("Use info from TMobilePhoneIdentityV1"); delete iModel; iModel = NULL; delete iRevision; iRevision = NULL; // phone model sales name. For example "N01". iModel = telid.iModel.AllocL(); // product revision. For example "01" iRevision = telid.iRevision.AllocL(); } delete iSerialNumber; iSerialNumber = NULL; // Phone serial number (IMEI or ESN), in character string format. iSerialNumber = telid.iSerialNumber.AllocL(); } CleanupStack::PopAndDestroy( &phone ); CleanupStack::PopAndDestroy( &telServer ); if ( sysVersionError == KErrNone ) { // use information from SysVersionInfo instead of previous APIs. LOGGER_WRITE("Using SysVersionInfo"); // phone model sales name. For example "N01". delete iModel; iModel = NULL; iModel = productVersion.iModel.AllocL(); // product revision. For example "01" delete iRevision; iRevision = NULL; iRevision = productVersion.iRevision.AllocL(); // manufacturer name. For example "Nokia" delete iManufacturer; iManufacturer = NULL; iManufacturer = productVersion.iManufacturer.AllocL(); // product code name. For example "RM-1" delete iProduct; iProduct = NULL; iProduct = productVersion.iProduct.AllocL(); } else { CapUtil::GetManufacturer( info ); delete iManufacturer; iManufacturer = NULL; iManufacturer = info.AllocL(); } CapUtil::GetLanguage( iLanguage ); err = SysVersionInfo::GetVersionInfo( SysVersionInfo::EFWVersion, info, aFs ); delete iSysVersionInfo; iSysVersionInfo = NULL; if ( !err ) { iSysVersionInfo = info.AllocL(); } err = SysUtil::GetLangVersion( info ); delete iLangVersion; iLangVersion = NULL; if ( !err ) { iLangVersion = info.AllocL(); } sysVersionError = SysUtil::GetLangSWVersion( info ); delete iLangSWVersion; iLangSWVersion = NULL; if ( !sysVersionError ) { iLangSWVersion = info.AllocL(); } sysVersionError = SysVersionInfo::GetVersionInfo( SysVersionInfo::EOPVersion, info, aFs ); delete iOPVersion; iOPVersion = NULL; if ( !sysVersionError ) { iOPVersion = info.AllocL(); } sysVersionError = SysVersionInfo::GetVersionInfo( SysVersionInfo::EProductCode, info, aFs ); delete iProductCode; iProductCode = NULL; if ( !sysVersionError ) { iProductCode = info.AllocL(); } // read DesktopSync key value CRepository* repository(NULL); TRAP( iDesktopSyncError, repository = CRepository::NewL( KCRUidDSDCMOConfig )); if ( !iDesktopSyncError ) { iDesktopSyncError = repository->Get( KNsmlDesktopSync, iDesktopSync ); LOGGER_WRITE_1("iDesktopSyncError: %d", iDesktopSyncError ); LOGGER_WRITE_1("iDesktopSync: %d", iDesktopSync ); delete repository; } else { LOGGER_WRITE_1("Could not create CRepository, err: %d", iDesktopSyncError ); } // screen size HAL::Get(HAL::EDisplayXPixels, iScreenSize.iWidth); HAL::Get(HAL::EDisplayYPixels, iScreenSize.iHeight); iInfoFetched = ETrue; TRACE_FUNC_EXIT; }
void KevScriptTest::theUltimeTest(){ DefaultkevoreeFactory factory; JSONModelLoader loader; JSONModelSerializer jml ; KevScriptEngine kse; ContainerRoot *model=NULL; ifstream f; f.open ("./dataTest/KevScriptTest/kevscriptKevCPP.kevs"); loader.setFactory(&factory); ifstream json_file; json_file.open ("./dataTest/KevScriptTest/model_to_check.json"); if(!json_file){ cout << "no json_file trace" << endl; } ContainerRoot *model_to_compare = (ContainerRoot*)loader.loadModelFromStream(json_file)->front(); CPPUNIT_ASSERT(model_to_compare !=NULL); try { model = factory.createContainerRoot(); CPPUNIT_ASSERT(model !=NULL); if(f){ kse.executeFromStream(f,model); ofstream myfile; myfile.open ("/Users/Aymeric/Documents/dev_Kevoree/kevoree-cpp/debug/bin/kev.json"); myfile << jml.serialize(model); myfile.close(); ModelCompare *compare= new ModelCompare(); list<ModelTrace*>* lst2 =model->toTraces(true, true) ; for(list<ModelTrace*>::iterator it = lst2->begin() ; it != lst2->end(); ++it){ ModelTrace* mt = *it ; //cout << mt->toString()<< endl ; } // cout <<"-----------"<< endl ; lst2 =model_to_compare->toTraces(true, true) ; for(list<ModelTrace*>::iterator it = lst2->begin() ; it != lst2->end(); ++it){ ModelTrace* mt = *it ; //cout << mt->toString()<< endl ; } // cout <<"-----------"<< endl ; // FIX ME TraceSequence *sequencediff = compare->diff(model,model_to_compare); list<ModelTrace*> lst = sequencediff->traces; //cout <<sequencediff->traces.size() << endl ; for(list<ModelTrace*>::iterator it = lst.begin() ; it != lst.end(); ++it){ ModelTrace* mt = *it ; //cout << mt->toString()<< endl ; } CPPUNIT_ASSERT(sequencediff->traces.size() != 0); delete compare; delete sequencediff; } } catch(std::exception const& e) { LOGGER_WRITE(Logger::ERROR," "+string(e.what())); } // TODO AYMERIC CPPUNIT_ASSERT(1); delete model; }
void SimManager::initialize() { #ifdef RUNTIME_PROFILING MEASURETIME_REGION_DEFINE(initSimHandler, "initializeSimulation"); if (MeasureTime::getInstance() != NULL) { MEASURETIME_START(initSimStartValues, initSimHandler, "initializeSimulation"); } #endif _cont_system = dynamic_pointer_cast<IContinuous>(_mixed_system); _timeevent_system = dynamic_pointer_cast<ITime>(_mixed_system); _event_system = dynamic_pointer_cast<IEvent>(_mixed_system); _step_event_system = dynamic_pointer_cast<IStepEvent>(_mixed_system); // Check dynamic casts if (!_event_system) { throw ModelicaSimulationError(SIMMANAGER,"Could not get event system."); } if (!_cont_system) { throw ModelicaSimulationError(SIMMANAGER,"Could not get continuous-event system."); } if (!_timeevent_system) { throw ModelicaSimulationError(SIMMANAGER,"Could not get time-event system."); } if (!_step_event_system) { throw ModelicaSimulationError(SIMMANAGER,"Could not get step-event system."); } LOGGER_WRITE("SimManager: Start initialization",LC_INIT,LL_DEBUG); // Set flag for endless simulation (if solver returns) _continueSimulation = true; // Reset debug ID _dbgId = 0; try { // Build up system and update once _initialization->initializeSystem(); } catch (std::exception& ex) { //ex << error_id(SIMMANAGER); throw ModelicaSimulationError(SIMMANAGER,"Could not initialize system.",string(ex.what()),false); } if (_timeevent_system) { _dimtimeevent = _timeevent_system->getDimTimeEvent(); if (_timeEventCounter) delete[] _timeEventCounter; _timeEventCounter = new int[_dimtimeevent]; memset(_timeEventCounter, 0, _dimtimeevent * sizeof(int)); // compute sampleCycles for RT simulation if (_config->getGlobalSettings()->useEndlessSim()) { if (_sampleCycles) delete[] _sampleCycles; _sampleCycles = new int[_dimtimeevent]; computeSampleCycles(); } } else _dimtimeevent = 0; _tStart = _config->getGlobalSettings()->getStartTime(); _tEnd = _config->getGlobalSettings()->getEndTime(); // _solver->setTimeOut(_config->getGlobalSettings()->getAlarmTime()); _dimZeroFunc = _event_system->getDimZeroFunc(); _solverTask = ISolver::SOLVERCALL(ISolver::FIRST_CALL); if (_dimZeroFunc == _event_system->getDimZeroFunc()) { if (_events) delete[] _events; _events = new bool[_dimZeroFunc]; memset(_events, false, _dimZeroFunc * sizeof(bool)); } LOGGER_WRITE("SimManager: Assemble completed",LC_INIT,LL_DEBUG); //#if defined(__TRICORE__) || defined(__vxworks) // Initialization for RT simulation if (_config->getGlobalSettings()->useEndlessSim()) { _cycleCounter = 0; _resetCycle = _sampleCycles[0]; for (int i = 1; i < _dimtimeevent; i++) _resetCycle *= _sampleCycles[i]; // All Events are updated every cycle. In order to have a change in timeEventCounter, the reset is set to two if(_resetCycle == 1) _resetCycle++; _solver->initialize(); } //#endif #ifdef RUNTIME_PROFILING if (MeasureTime::getInstance() != NULL) { MEASURETIME_END(initSimStartValues, initSimEndValues, (*measureTimeFunctionsArray)[0], initSimHandler); } #endif }
void SimManager::runSingleProcess() { double startTime, endTime, *zeroVal_0, *zeroVal_new; int dimZeroF; std::vector<std::pair<double, int> > tStopsSub; _H = _tEnd; _solverTask = ISolver::SOLVERCALL(_solverTask | ISolver::RECORDCALL); _solver->setStartTime(_tStart); _solver->setEndTime(_tEnd); _solver->solve(_solverTask); _solverTask = ISolver::SOLVERCALL(_solverTask ^ ISolver::RECORDCALL); /* Logs temporarily disabled BOOST_LOG_SEV(simmgr_lg::get(), simmgr_normal) <<"Run single process." ; */ LOGGER_WRITE("SimManager: Run single process",LC_SOLV,LL_DEBUG); memset(_timeEventCounter, 0, _dimtimeevent * sizeof(int)); computeEndTimes(tStopsSub); _tStops.push_back(tStopsSub); dimZeroF = _event_system->getDimZeroFunc(); zeroVal_new = new double[dimZeroF]; _timeevent_system->setTime(_tStart); if (_dimtimeevent) { _timeevent_system->handleTimeEvent(_timeEventCounter); } _cont_system->evaluateAll(IContinuous::CONTINUOUS); // vxworksupdate _event_system->getZeroFunc(zeroVal_new); for (int i = 0; i < _dimZeroFunc; i++) _events[i] = bool(zeroVal_new[i]); _mixed_system->handleSystemEvents(_events); //_cont_system->evaluateODE(IContinuous::CONTINUOUS); // Reset the time-events if (_dimtimeevent) { _timeevent_system->handleTimeEvent(_timeEventCounter); } std::vector<std::pair<double, int> >::iterator iter; iter = _tStops[0].begin(); /* time measurement temporary disabled // Startzeit messen _tClockStart = Time::Time().getSeconds(); */ startTime = _tStart; bool user_stop = false; while (_continueSimulation) { for (; iter != _tStops[0].end(); ++iter) { endTime = iter->first; // Set start time, end time, initial step size _solver->setStartTime(startTime); _solver->setEndTime(endTime); _solver->setInitStepSize(_config->getGlobalSettings()->gethOutput()); _solver->solve(_solverTask); if (_solverTask & ISolver::FIRST_CALL) { _solverTask = ISolver::SOLVERCALL(_solverTask ^ ISolver::FIRST_CALL); _solverTask = ISolver::SOLVERCALL(_solverTask | ISolver::RECALL); } startTime = endTime; if (_dimtimeevent) { // Find all time events at the current time while((iter !=_tStops[0].end()) && (abs(iter->first - endTime) <1e4*UROUND)) { _timeEventCounter[iter->second]++; iter++; } // Set the iterator back to the current end time iter--; // Then handle time events _timeevent_system->handleTimeEvent(_timeEventCounter); _event_system->getZeroFunc(zeroVal_new); for (int i = 0; i < _dimZeroFunc; i++) _events[i] = bool(zeroVal_new[i]); _mixed_system->handleSystemEvents(_events); // Reset time-events _timeevent_system->handleTimeEvent(_timeEventCounter); _cont_system->evaluateAll(IContinuous::CONTINUOUS); _event_system->saveAll(); } user_stop = (_solver->getSolverStatus() & ISolver::USER_STOP); if (user_stop) break; } // end for time events if (abs(_tEnd - endTime) > _config->getSimControllerSettings()->dTendTol && !user_stop) { startTime = endTime; _solver->setStartTime(startTime); _solver->setEndTime(_tEnd); _solver->setInitStepSize(_config->getGlobalSettings()->gethOutput()); _solver->solve(_solverTask); // In _solverTask FIRST_CALL Bit löschen und RECALL Bit setzen if (_solverTask & ISolver::FIRST_CALL) { _solverTask = ISolver::SOLVERCALL(_solverTask ^ ISolver::FIRST_CALL); _solverTask = ISolver::SOLVERCALL(_solverTask | ISolver::RECALL); } if (user_stop) break; } // end if weiter nach Time Events else // Event am Schluss recorden. { if (_writeFinalState) { _solverTask = ISolver::SOLVERCALL(ISolver::RECORDCALL); _solver->solve(_solverTask); } } // Beendigung der Simulation if ((!(_config->getGlobalSettings()->useEndlessSim())) || (_solver->getSolverStatus() & ISolver::SOLVERERROR) || (_solver->getSolverStatus() & ISolver::USER_STOP)) { _continueSimulation = false; } // Endless simulation else { // Zeitinvervall hochzählen _tStart = _tEnd; _tEnd += _H; computeEndTimes(tStopsSub); _tStops.push_back(tStopsSub); if (_dimtimeevent) { if (zeroVal_new) { _timeevent_system->handleTimeEvent(_timeEventCounter); _cont_system->evaluateAll(IContinuous::CONTINUOUS); // vxworksupdate _event_system->getZeroFunc(zeroVal_new); for (int i = 0; i < _dimZeroFunc; i++) _events[i] = bool(zeroVal_new[i]); _mixed_system->handleSystemEvents(_events); //_cont_system->evaluateODE(IContinuous::CONTINUOUS); //reset time-events _timeevent_system->handleTimeEvent(_timeEventCounter); _cont_system->evaluateAll(IContinuous::CONTINUOUS); _event_system->saveAll(); } } iter = _tStops[0].begin(); } } // end while continue _step_event_system->setTerminal(true); _cont_system->evaluateAll(IContinuous::CONTINUOUS); //Is this really necessary? The solver should have already calculated the "final time point" if (zeroVal_new) delete[] zeroVal_new; } // end singleprocess
void Cvode::writeSimulationInfo() { long int nst, nfe, nsetups, nni, ncfn, netf; long int nfQe, netfQ; long int nfSe, nfeS, nsetupsS, nniS, ncfnS; long int nfQSe, netfQS; int qlast, qcur; realtype h0u, hlast, hcur, tcur; int flag; flag = CVodeGetIntegratorStats(_cvodeMem, &nst, &nfe, &nsetups, &netf, &qlast, &qcur, &h0u, &hlast, &hcur, &tcur); flag = CVodeGetNonlinSolvStats(_cvodeMem, &nni, &ncfn); LOGGER_WRITE("Cvode: number steps = " + to_string(nst), LC_SOLV, LL_INFO); LOGGER_WRITE("Cvode: function evaluations 'f' = " + to_string(nfe), LC_SOLV, LL_INFO); LOGGER_WRITE("Cvode: linear solver setups 'nsetups' = " + to_string(nsetups), LC_SOLV, LL_INFO); LOGGER_WRITE("Cvode: nonlinear iterations 'nni' = " + to_string(nni), LC_SOLV, LL_INFO); LOGGER_WRITE("Cvode: convergence failures 'ncfn' = " + to_string(ncfn), LC_SOLV, LL_INFO); LOGGER_WRITE("Cvode: number of evaluateODE calls 'eODE' = " + to_string(_numberOfOdeEvaluations), LC_SOLV, LL_INFO); //// Solver //outputStream << "\nSolver: " << getName() // << "\nVerfahren: "; //if(_cvodesettings->iMethod == EulerSettings::EULERFORWARD) // outputStream << " Expliziter Cvode\n\n"; //else if(_cvodesettings->iMethod == EulerSettings::EULERBACKWARD) // outputStream << " Impliziter Cvode\n\n"; //// System //outputStream // << "Dimension des Systems (ODE): " << (int)_dimSys << "\n"; //// Status, Anzahl Schritte, Nullstellenzeugs //SolverDefaultImplementation::writeSimulationInfo(outputStream); //// Nullstellensuche //if (_cvodesettings->iZeroSearchMethod == SolverSettings::NO_ZERO_SEARCH) //{ // outputStream << "Nullstellensuche: Keine\n\n" << endl; //} //else //{ // /*if (_cvodesettings->iZeroSearchMethod == SolverSettings::BISECTION) // { // outputStream << "Nullstellensuche: Bisektion\n" << endl; // } // else // {*/ // outputStream << "Nullstellensuche: Lineare Interpolation\n" << endl; // /*}*/ //} //// Schritteweite //outputStream // << "ausgegebene Schritte: " << _outStps << "\n" // << "Anfangsschrittweite: " << _cvodesettings->dH_init << "\n" // << "Ausgabeschrittweite: " << dynamic_cast<ISolverSettings*>(_cvodesettings)->getGlobalSettings()->gethOutput() << "\n" // << "Obere Grenze für Schrittweite: " << _hUpLim << "\n\n"; //// Status //outputStream // << "Solver-Status: " << _idid << "\n\n"; }
void Cvode::initialize() { _properties = dynamic_cast<ISystemProperties*>(_system); _continuous_system = dynamic_cast<IContinuous*>(_system); _event_system = dynamic_cast<IEvent*>(_system); _mixed_system = dynamic_cast<IMixedSystem*>(_system); _time_system = dynamic_cast<ITime*>(_system); IGlobalSettings* global_settings = dynamic_cast<ISolverSettings*>(_cvodesettings)->getGlobalSettings(); // Kennzeichnung, dass initialize()() (vor der Integration) aufgerufen wurde _idid = 5000; _tLastEvent = 0.0; _event_n = 0; SolverDefaultImplementation::initialize(); _dimSys = _continuous_system->getDimContinuousStates(); _dimZeroFunc = _event_system->getDimZeroFunc(); if (_dimSys == 0) _dimSys = 1; // introduce dummy state if (_dimSys <= 0) { _idid = -1; throw ModelicaSimulationError(SOLVER,"Cvode::initialize()"); } else { // Allocate state vectors, stages and temporary arrays if (_z) delete[] _z; if (_zInit) delete[] _zInit; if (_zWrite) delete[] _zWrite; if (_zeroSign) delete[] _zeroSign; if (_absTol) delete[] _absTol; if(_delta) delete [] _delta; if(_deltaInv) delete [] _deltaInv; if(_ysave) delete [] _ysave; _z = new double[_dimSys]; _zInit = new double[_dimSys]; _zWrite = new double[_dimSys]; _zeroSign = new int[_dimZeroFunc]; _absTol = new double[_dimSys]; _delta =new double[_dimSys]; _deltaInv =new double[_dimSys]; _ysave =new double[_dimSys]; memset(_z, 0, _dimSys * sizeof(double)); memset(_zInit, 0, _dimSys * sizeof(double)); memset(_ysave, 0, _dimSys * sizeof(double)); // Counter initialisieren _outStps = 0; if (_cvodesettings->getDenseOutput()) { // Ausgabeschrittweite _hOut = global_settings->gethOutput(); } // Allocate memory for the solver _cvodeMem = CVodeCreate(CV_BDF, CV_NEWTON); if (check_flag((void*) _cvodeMem, "CVodeCreate", 0)) { _idid = -5; throw ModelicaSimulationError(SOLVER,/*_idid,_tCurrent,*/"Cvode::initialize()"); } // // Make Cvode ready for integration // // Set initial values for CVODE _continuous_system->evaluateAll(IContinuous::CONTINUOUS); _continuous_system->getContinuousStates(_zInit); memcpy(_z, _zInit, _dimSys * sizeof(double)); // Get nominal values _absTol[0] = 1.0; // in case of dummy state _continuous_system->getNominalStates(_absTol); for (int i = 0; i < _dimSys; i++) _absTol[i] *= dynamic_cast<ISolverSettings*>(_cvodesettings)->getATol(); _CV_y0 = N_VMake_Serial(_dimSys, _zInit); _CV_y = N_VMake_Serial(_dimSys, _z); _CV_yWrite = N_VMake_Serial(_dimSys, _zWrite); _CV_absTol = N_VMake_Serial(_dimSys, _absTol); if (check_flag((void*) _CV_y0, "N_VMake_Serial", 0)) { _idid = -5; throw ModelicaSimulationError(SOLVER,"Cvode::initialize()"); } // Initialize Cvode (Initial values are required) _idid = CVodeInit(_cvodeMem, CV_fCallback, _tCurrent, _CV_y0); if (_idid < 0) { _idid = -5; throw ModelicaSimulationError(SOLVER,"Cvode::initialize()"); } // Set Tolerances _idid = CVodeSVtolerances(_cvodeMem, dynamic_cast<ISolverSettings*>(_cvodesettings)->getRTol(), _CV_absTol); // RTOL and ATOL if (_idid < 0) throw ModelicaSimulationError(SOLVER,"CVode::initialize()"); // Set the pointer to user-defined data _idid = CVodeSetUserData(_cvodeMem, _data); if (_idid < 0) throw ModelicaSimulationError(SOLVER,"Cvode::initialize()"); _idid = CVodeSetInitStep(_cvodeMem, 1e-6); // INITIAL STEPSIZE if (_idid < 0) throw ModelicaSimulationError(SOLVER,"Cvode::initialize()"); _idid = CVodeSetMaxOrd(_cvodeMem, 5); // Max Order if (_idid < 0) throw ModelicaSimulationError(SOLVER,"CVoder::initialize()"); _idid = CVodeSetMaxConvFails(_cvodeMem, 100); // Maximale Fehler im Konvergenztest if (_idid < 0) throw ModelicaSimulationError(SOLVER,"CVoder::initialize()"); _idid = CVodeSetStabLimDet(_cvodeMem, TRUE); // Stability Detection if (_idid < 0) throw ModelicaSimulationError(SOLVER,"CVoder::initialize()"); _idid = CVodeSetMinStep(_cvodeMem, dynamic_cast<ISolverSettings*>(_cvodesettings)->getLowerLimit()); // MINIMUM STEPSIZE if (_idid < 0) throw ModelicaSimulationError(SOLVER,"CVode::initialize()"); _idid = CVodeSetMaxStep(_cvodeMem, global_settings->getEndTime() / 10.0); // MAXIMUM STEPSIZE if (_idid < 0) throw ModelicaSimulationError(SOLVER,"CVode::initialize()"); _idid = CVodeSetMaxNonlinIters(_cvodeMem, 5); // Max number of iterations if (_idid < 0) throw ModelicaSimulationError(SOLVER,"CVode::initialize()"); _idid = CVodeSetMaxErrTestFails(_cvodeMem, 100); if (_idid < 0) throw ModelicaSimulationError(SOLVER,"CVode::initialize()"); _idid = CVodeSetMaxNumSteps(_cvodeMem, 1e3); // Max Number of steps if (_idid < 0) throw ModelicaSimulationError(SOLVER,/*_idid,_tCurrent,*/"Cvode::initialize()"); // Initialize linear solver #ifdef USE_SUNDIALS_LAPACK _idid = CVLapackDense(_cvodeMem, _dimSys); #else _idid = CVDense(_cvodeMem, _dimSys); #endif if (_idid < 0) throw ModelicaSimulationError(SOLVER,"Cvode::initialize()"); // Use own jacobian matrix // Check if Colored Jacobians are worth to use #if SUNDIALS_MAJOR_VERSION >= 2 || (SUNDIALS_MAJOR_VERSION == 2 && SUNDIALS_MINOR_VERSION >= 4) _maxColors = _system->getAMaxColors(); if(_maxColors < _dimSys && _continuous_system->getDimContinuousStates() > 0) { // _idid = CVDlsSetDenseJacFn(_cvodeMem, &CV_JCallback); // initializeColoredJac(); } #endif if (_idid < 0) throw ModelicaSimulationError(SOLVER,"CVode::initialize()"); if (_dimZeroFunc) { _idid = CVodeRootInit(_cvodeMem, _dimZeroFunc, &CV_ZerofCallback); memset(_zeroSign, 0, _dimZeroFunc * sizeof(int)); _idid = CVodeSetRootDirection(_cvodeMem, _zeroSign); if (_idid < 0) throw ModelicaSimulationError(SOLVER,/*_idid,_tCurrent,*/"CVode::initialize()"); memset(_zeroSign, -1, _dimZeroFunc * sizeof(int)); memset(_zeroVal, -1, _dimZeroFunc * sizeof(int)); } _cvode_initialized = true; LOGGER_WRITE("Cvode: initialized",LC_SOLV,LL_DEBUG); } }