void InputHandler::StateSwitched(SimulationState old, SimulationState cur) { int height = mMouse->getMouseState().height; int width = mMouse->getMouseState().width; if (old == SIMULATION && cur == SIMULATION_MOUSELOOK || cur == SIMULATION_TOPDOWNVIEW) { destroySystem(); createSystem(true); //capture(); } else if ((cur == SIMULATION) && old == SIMULATION_MOUSELOOK || old == SIMULATION_TOPDOWNVIEW) { destroySystem(); createSystem(false); //capture(); } setWindowExtents(width, height); }
//----------------------------------------------------------------------------- // Function: apply() //----------------------------------------------------------------------------- void NewSystemPage::apply() { // Create the system in a different way based on the mapping option selection. if (mapRadioButton_->isChecked()) { Q_ASSERT(compTreeWidget_->currentItem() != 0); QVariant data = compTreeWidget_->currentItem()->data(0, Qt::UserRole); emit createSystem(data.value<VLNV>(), viewComboBox_->currentText(), vlnvEditor_->getVLNV(), selectedPath()); } else { emit createSystem(VLNV(), "", vlnvEditor_->getVLNV(),selectedPath()); } }
// here we start the calc... void ProjectSquareWell::slotStartCalc() { if (!checkValues(true)) return; // ok.. now start the game... we create a new temporary system, setting on it // all the input parameters. System is a package-class which holds input data // and output data. it's passed to the calc factory, the model, when the calc // start. However, it's not granted the model is effectively resting. System *s = createSystem(); System *r = NULL; if (m_dialog->richardsonExtrapolation()) { r = createRichardsonSystem(); } // startCalc return false if the model is working on another system. // in this case, we ask to wait, and discard the system we built. // a smarter code should span another project, but i don't care to be // too much smarter, since i want to preserve that little mental sanity i // currently have. now let's go to see Model::startCalc() // new: r is the richardson system. Nothing more than a carbon copy system // with half of the points. We pass it to the model if (!m_model->startCalc(s,r)) { g_error->error("Another calculation in progress","The current project is currently busy. Unable to start new thread.\n Wait for the end or start a new project."); delete s; if (r) delete r; return; } }
int main(int argc, char *argv[]){ int nbParts=20000; float minMax[3][2]={{-1,1},{-1,1},{-1,1}}; float cellSize=2*0.02*1.001;// 2*particle radius + 0.1% float dt=0.002,simTime=5; float dtFrame=0.02; //0.04 <=> 25 frames per seconds int nbDtPerFrame,i; char filename[]="toto.par"; float mass; System *sys; clock_t time; /* FILE *file; float r[3]; file=fopen("filter.plt","w"); fprintf(file,"VARIABLES = x w\n"); r[1]=r[2]=0; for(i=0;i<=100;i++){ r[0]=i/100.; fprintf(file,"%e\t%e\n",i/100.,kernelPoly6(r,1)); } fclose(file); return 0;*/ nbDtPerFrame=dtFrame/dt; sys=createSystem(nbParts,minMax); tmpAddWalls_1(sys); setGrid(sys, cellSize); //printGrid(sys); //test nico //return 0; mass=1000*(minMax[0][1]-minMax[0][0])*(minMax[1][1]-minMax[1][0])*(minMax[2][1]-minMax[2][0])/nbParts; setParticles(sys,0,nbParts-1,mass/4); //for water, ro0=1000kg/m3, so 1000 parts/Liter => mi=1e-3kg setForces(sys); generateParFile(sys,filename,CREATE); i=0; time=clock(); while(sys->time<=simTime){ printf("time = %e (i=%d)\n",sys->time,i);fflush(stdout); updateSys(sys,dt); if((++i)%nbDtPerFrame==0) generateParFile(sys,filename,UPDATE); } time=clock()-time; generateParFile(sys,filename,CLOSE); deleteSystem(sys); updateSys(NULL,0); #ifdef USE_MULTI_THREADING cleanThreads(); #endif printf("done in %f sec!\n", (double)(time)/CLOCKS_PER_SEC); return 0; }
Entity* Model::createEntity( String const& aClassname, FullID const& aFullID ) { if( aFullID.getSystemPath().isModel() ) { THROW_EXCEPTION( BadSystemPath, "empty SystemPath" ); } System* aContainerSystemPtr( getSystem( aFullID.getSystemPath() ) ); Entity* retval( 0 ); if ( !aContainerSystemPtr ) { THROW_EXCEPTION( BadSystemPath, "[" + aFullID.getSystemPath().asString() + "] cannot be reached" ); } switch( aFullID.getEntityType() ) { case EntityType::VARIABLE: { retval = createVariable( aClassname ); retval->setID( aFullID.getID() ); aContainerSystemPtr->registerEntity( static_cast< Variable* >( retval ) ); } break; case EntityType::PROCESS: { retval = createProcess( aClassname ); retval->setID( aFullID.getID() ); aContainerSystemPtr->registerEntity( static_cast< Process* >( retval ) ); } break; case EntityType::SYSTEM: { retval = createSystem( aClassname ); retval->setID( aFullID.getID() ); aContainerSystemPtr->registerEntity( static_cast< System* >( retval ) ); } break; default: THROW_EXCEPTION( InvalidEntityType, "invalid EntityType specified" ); } return retval; }
InputHandler::InputHandler(Simulation *sim, unsigned long hWnd, Ogre::Camera *camera, EntityController * eCont, DataManager * dMan, Ogre::SceneManager * mSceneM) { m_hWnd = hWnd; createSystem(false); m_simulation = sim; m_cam = camera; entController = eCont; dataMan = dMan; mSceneManager = mSceneM; // Get the camera node mPitchNode = camera->getParentSceneNode(); mCamNode = mPitchNode->getParentSceneNode(); }
int main (int argc, char *argv[]) { char *configFile = NULL; char *outputFile = NULL; // Declare objects struct system System; struct tip Tip; struct space Space; struct graphene Graphene; struct substrate Substrate; initSystem(&System, &Tip, &Space, &Graphene, &Substrate); parseOptions(argc, argv, &configFile, &outputFile, &System, &Tip); parseFile(configFile, &System, &Tip, &Space, &Graphene, &Substrate); createSystem(&System, &Tip); createGraphene(&System, &Graphene); // transformCylindric(&System); // createSpace(&System, &Space); createTip(&System, &Tip); createSubstrate(&System, &Substrate); // Spheroidal Tip assignPointers(&System, &Tip, &Space, &Graphene, &Substrate); assignPotential(&System, &Tip, &Space, &Graphene, &Substrate); laplaceSpheroidal(&System, &Tip); retransformSpheroidal(&Tip); retransformCylindric(&System); saveData(outputFile, &System); // Visualize System if necessary if (System.visual) { initVisual(); drawObjects(&System, &Tip, &Space, &Graphene, &Substrate); } free(System.points); // Free all points return EXIT_SUCCESS; }
void ProjectBarrier::slotStartCalc() { if (!checkValues(true)) return; System *s = createSystem(); System *r = NULL; if (m_dialog->richardsonExtrapolation()) { r = createRichardsonSystem(); } if (!m_model->startCalc(s,r)) { g_error->error("Another calculation in progress","The current project is currently busy. Unable to start new thread.\n Wait for the end or start a new project."); delete s; if (r) delete r; return; } }
void Model::setup() { registerBuiltinModules(); // initialize theRootSystem theRootSystem = createSystem( "System" ); theRootSystem->setID( "/" ); theRootSystem->setName( "The Root System" ); // super system of the root system is itself. theRootSystem->setSuperSystem( theRootSystem ); // initialize theSystemStepper theSystemStepper.setModel( this ); theSystemStepper.setID( "___SYSTEM" ); theScheduler.addEvent( StepperEvent( getCurrentTime() + theSystemStepper.getStepInterval(), &theSystemStepper ) ); theLastStepper = &theSystemStepper; }
// Import data. void Database_Versifications::input (const string& contents, const string& name) { // Delete old system if it is there, and create new one. erase (name); int id = createSystem (name); sqlite3 * db = connect (); database_sqlite_exec (db, "PRAGMA temp_store = MEMORY;"); database_sqlite_exec (db, "PRAGMA synchronous = OFF;"); database_sqlite_exec (db, "PRAGMA journal_mode = OFF;"); database_sqlite_exec (db, "BEGIN;"); vector <string> lines = filter_string_explode (contents, '\n'); for (auto line : lines) { line = filter_string_trim (line); if (line.empty ()) continue; Passage passage = filter_passage_explode_passage (line); if ((passage.book == 0) || (passage.chapter == 0) || (passage.verse.empty ())) { Database_Logs::log ("Malformed versification entry: " + line); continue; } SqliteSQL sql = SqliteSQL (); sql.add ("INSERT INTO data (system, book, chapter, verse) VALUES ("); sql.add (id); sql.add (","); sql.add (passage.book); sql.add (","); sql.add (passage.chapter); sql.add (","); sql.add (convert_to_int (passage.verse)); sql.add (");"); database_sqlite_exec (db, sql.sql); } database_sqlite_exec (db, "COMMIT;"); database_sqlite_disconnect (db); }
boost::weak_ptr<IMixedSystem> SimController::LoadSystem(string modelLib,string modelKey) { //if the model is already loaded std::map<string,boost::shared_ptr<IMixedSystem> >::iterator iter = _systems.find(modelKey); if(iter != _systems.end()) { //destroy simdata std::map<string,boost::shared_ptr<ISimData> >::iterator iter2 = _sim_data.find(modelKey); if(iter2 != _sim_data.end()) { _sim_data.erase(iter2); } //destroy system _systems.erase(iter); } boost::shared_ptr<ISimData> simData = getSimData(modelKey).lock(); boost::shared_ptr<ISimVars> simVars = getSimVars(modelKey).lock(); //create system boost::shared_ptr<IMixedSystem> system = createSystem(modelLib, modelKey, _config->getGlobalSettings(), _algloopsolverfactory, simData, simVars); _systems[modelKey] = system; return system; }
/* Calls parseAirports, parseSchedules, and calcRouteTimes if the required files exists. */ void timeRoutes(char* airports, char* schedules, char* routes) { FILE *airportFile, *scheduleFile, *routeFile; char* read = "r"; airportFile = fopen(airports,read); if(!airportFile) { fprintf(stderr,"Cannot open file with list of airport names."); exit(EXIT_FAILURE); } flightSys_t* s = createSystem(); if(s==NULL) { printf("createSystem unimplemented\n"); return; } printf("***Parse and echo airports***\n"); parseAirports(s,airportFile); fclose(airportFile); printAirports(s); scheduleFile = fopen(schedules,read); if(!scheduleFile) { fprintf(stderr,"Cannot open file with schedule."); exit(EXIT_FAILURE); } printf("\n***Parse and echo schedules***\n"); parseSchedule(s,scheduleFile); fclose(scheduleFile); routeFile = fopen(routes,read); if(!routeFile) { fprintf(stderr,"Cannot open file with routes."); exit(EXIT_FAILURE); } printf("\n***Parse and calculate route times***\n"); calcRouteTimes(s,routeFile); fclose(routeFile); deleteSystem(s); }
bool ProjectBarrier::XMLLoadSystem(const QDomElement &project) { System *s; unsigned int eigenfunctions = 0; QString str; QDomElement name = XMLUtils::childWithTag(project, "name"); setName(name.text()); QDomElement system = XMLUtils::childWithTag(project, "system"); QDomElement barrierpotential = XMLUtils::childWithTag(system, "barrierpotential"); // fill the dialog { QDomNode node; QDomElement elem; QLineEdit *edit = NULL; QString tag; bool status = true; for (node = system.firstChild(); !node.isNull(); node = node.nextSibling()) { elem = node.toElement(); if (elem.isNull()) continue; tag = elem.tagName(); if (tag == "points") m_dialog->m_numPoints_edit->setText(elem.attribute("value")); else if (tag == "lowervalue") m_dialog->m_lowIntegration_edit->setText(elem.attribute("value")); else if (tag == "highervalue") m_dialog->m_highIntegration_edit->setText(elem.attribute("value")); else if (tag == "particlemass") m_dialog->m_particleMass_edit->setText(elem.attribute("value")); else if (tag == "eigenfunction") eigenfunctions++; else {} } str.setNum(eigenfunctions); m_dialog->m_eigenNumber_edit->setText(str); for (node = barrierpotential.firstChild(); !node.isNull(); node = node.nextSibling()) { elem = node.toElement(); if (elem.isNull()) continue; tag = elem.tagName(); if (tag == "lowedge") m_dialog->m_potentialLowEdge_edit->setText(elem.attribute("value")); else if (tag == "highedge") m_dialog->m_potentialHighEdge_edit->setText(elem.attribute("value")); else if (tag == "highpotential") m_dialog->m_extPotential_edit->setText(elem.attribute("value")); else if (tag == "barrierlowedge") m_dialog->m_barrierLowEdge_edit->setText(elem.attribute("value")); else if (tag == "barrierhighedge") m_dialog->m_barrierHighEdge_edit->setText(elem.attribute("value")); else if (tag == "barrierheight") m_dialog->m_barrierHeight_edit->setText(elem.attribute("value")); else {} } } // check it if (checkValues(false)) { // fill system and potential s = createSystem(); } else return false; // pass to model return m_model->XMLLoad(s, system); }
void vTaskSI (void* pvParameters) { (void) pvParameters; portTickType xLastWakeTime; Module *entryDist, *asservPosDist, *asservVitDist, *measureDerivatorDist, *imeInIntegratorDist; Module *entryRot, *asservPosRot, *asservVitRot, *measureDerivatorRot, *imeInIntegratorRot; Module *ifaceMERight, *ifaceMELeft, *starter, *operatorIn, *operatorOut, *toggleSwitchLeft, *toggleSwitchRight; EntryConfig entryConfigDist, entryConfigRot; // Enregistrement de l'asservissement en distance ModuleValue posKpDist = 50; ModuleValue posKiDist = 0; ModuleValue posKdDist = 5; // ModuleValue derivDist = 16000; ModuleValue vitKpDist = 1000; ModuleValue vitKiDist = 0; ModuleValue vitKdDist = 15; // ModuleValue accelDist = 500; // ModuleValue commandDist = 2000; entryConfigDist.nbEntry = 9; entryConfigDist.value[0] = &posKpDist; // kp entryConfigDist.value[1] = &posKiDist; // ki entryConfigDist.value[2] = &posKdDist; // kd entryConfigDist.value[3] = &(trajDist.vit); // deriv entryConfigDist.value[4] = &vitKpDist; // kp entryConfigDist.value[5] = &vitKiDist; // ki entryConfigDist.value[6] = &vitKdDist; // kd entryConfigDist.value[7] = &(trajDist.acc); // accel entryConfigDist.value[8] = &(trajDist.pos); // command // Enregistrement de l'asservissement en rotation ModuleValue posKpRot = 50; ModuleValue posKiRot = 3; ModuleValue posKdRot = 15; // ModuleValue derivRot = 8000; ModuleValue vitKpRot = 1000; ModuleValue vitKiRot = 0; ModuleValue vitKdRot = 20; // ModuleValue accelRot = 1000; // ModuleValue commandRot = 200; // (200, -300) = max(command) entryConfigRot.nbEntry = 9; entryConfigRot.value[0] = &posKpRot; // kp entryConfigRot.value[1] = &posKiRot; // ki entryConfigRot.value[2] = &posKdRot; // kd entryConfigRot.value[3] = &(trajRot.vit); // deriv entryConfigRot.value[4] = &vitKpRot; // kp entryConfigRot.value[5] = &vitKiRot; // ki entryConfigRot.value[6] = &vitKdRot; // kd entryConfigRot.value[7] = &(trajRot.acc); // accel entryConfigRot.value[8] = &(trajRot.pos); // command // On ajoute un interupteur à notre shéma bloc // qui empéche l'asserv de s'effectuer quand le pontH n'est pas alimenté EFBclearBit (DDR_HBRIDGE_ON, BIT_HBRIDGE_ON); ToggleSwitchConfig toggleSwitchConfig; toggleSwitchConfig.value = (uint8_t*) &(PORT_HBRIDGE_ON); toggleSwitchConfig.mask = _BV (BIT_HBRIDGE_ON); toggleSwitchConfig.off = TOGGLE_ON; xLastWakeTime = taskGetTickCount (); // Création du Starter starter = initModule(&ctlBlock, 1, 0, starterType, 0); if (starter == 0) { return; } // Création de l'interface systeme (IfaceMERight) ifaceMERight = initModule(&ctlBlock, 1, 2, ifaceMEType, 1); if (ifaceMERight == 0) { return; } // Création de l'interface systeme (IfaceMELeft) ifaceMELeft = initModule(&ctlBlock, 1, 2, ifaceMEType, 0); if (ifaceMELeft == 0) { return; } // Création de l'operateur asservs -> IMEs operatorIn = initModule(&ctlBlock, 2, 2, operatorType, 1); if (operatorIn == 0) { return; } // Création de l'operateur IMEs -> asservs operatorOut = initModule(&ctlBlock, 2, 2, operatorType, 0); if (operatorOut == 0) { return; } toggleSwitchRight = initModule(&ctlBlock, 1, 1, toggleSwitchType, 0); if (toggleSwitchRight == 0) { return; } toggleSwitchLeft = initModule(&ctlBlock, 1, 1, toggleSwitchType, 0); if (toggleSwitchLeft == 0) { return; } // Création de l'Entry entryDist = initModule(&ctlBlock, 0, entryConfigDist.nbEntry, entryType, 0); if (entryDist == 0) { return; } asservPosDist = initModule(&ctlBlock, 6, 1, asservType, 0); if (asservPosDist == 0) { return; } asservVitDist = initModule(&ctlBlock, 6, 1, asservType, 0); if (asservVitDist == 0) { return; } measureDerivatorDist = initModule(&ctlBlock, 1, 1, derivatorType, 0); if (measureDerivatorDist == 0) { return; } imeInIntegratorDist = initModule(&ctlBlock, 1, 1, integratorType, 0); if (imeInIntegratorDist == 0) { return; } // Création de l'Entry entryRot = initModule(&ctlBlock, 0, entryConfigRot.nbEntry, entryType, 0); if (entryRot == 0) { return; } asservPosRot = initModule(&ctlBlock, 6, 1, asservType, 0); if (asservPosRot == 0) { return; } asservVitRot = initModule(&ctlBlock, 6, 1, asservType, 0); if (asservVitRot == 0) { return; } measureDerivatorRot = initModule(&ctlBlock, 1, 1, derivatorType, 0); if (measureDerivatorRot == 0) { return; } imeInIntegratorRot = initModule(&ctlBlock, 1, 1, integratorType, 0); if (imeInIntegratorRot == 0) { return; } debug("H"); if (createSystem(&ctlBlock, starter , 50) == ERR_TIMER_NOT_DEF) { return; } // debug("oii: %l %l\r\n", (uint32_t)getInput(parent, 0), (uint32_t)getInput(parent, 1)); // debug("cp\r\n"); if (configureModule(starter, NULL) != NO_ERR) { return; } if (configureModule(ifaceMELeft, (void*)&imes[0]) != NO_ERR) { return; } if (configureModule(ifaceMERight, (void*)&imes[1]) != NO_ERR) { return; } if (configureModule(operatorIn, (void*)funCalcValueForMotor) != NO_ERR) { return; } if (configureModule(operatorOut, (void*)funCalcValueForAsserv) != NO_ERR) { return; } if (configureModule(toggleSwitchRight, (void*)&toggleSwitchConfig) != NO_ERR) { return; } debug("E"); if (configureModule(toggleSwitchLeft, (void*)&toggleSwitchConfig) != NO_ERR) { return; } debug("E"); if (configureModule(entryDist, (void*)&entryConfigDist) != NO_ERR) { return; } if (configureModule(asservPosDist, NULL) != NO_ERR) { return; } if (configureModule(asservVitDist, NULL) != NO_ERR) { return; } if (configureModule(measureDerivatorDist, NULL) != NO_ERR) { return; } if (configureModule(imeInIntegratorDist, NULL) != NO_ERR) { return; } if (configureModule(entryRot, (void*)&entryConfigRot) != NO_ERR) { return; } if (configureModule(asservPosRot, NULL) != NO_ERR) { return; } if (configureModule(asservVitRot, NULL) != NO_ERR) { return; } if (configureModule(measureDerivatorRot, NULL) != NO_ERR) { return; } if (configureModule(imeInIntegratorRot, NULL) != NO_ERR) { return; } debug("E"); // DISTANCE linkModuleWithInput(entryDist, 8, asservPosDist, AsservCommand); linkModuleWithInput(entryDist, 0, asservPosDist, AsservKp); linkModuleWithInput(entryDist, 1, asservPosDist, AsservKi); linkModuleWithInput(entryDist, 2, asservPosDist, AsservKd); linkModuleWithInput(entryDist, 3, asservPosDist, AsservDeriv); linkModuleWithInput(operatorOut, 0, asservPosDist, AsservMeasure); linkModuleWithInput(asservPosDist, 0, asservVitDist, AsservCommand); linkModuleWithInput(entryDist, 4, asservVitDist, AsservKp); linkModuleWithInput(entryDist, 5, asservVitDist, AsservKi); linkModuleWithInput(entryDist, 6, asservVitDist, AsservKd); linkModuleWithInput(entryDist, 7, asservVitDist, AsservDeriv); linkModuleWithInput(operatorOut, 0, measureDerivatorDist, 0); linkModuleWithInput(measureDerivatorDist, 0, asservVitDist, AsservMeasure); linkModuleWithInput(asservVitDist, 0, imeInIntegratorDist, 0); linkModuleWithInput(imeInIntegratorDist, 0, operatorIn, 0); // ROTATION linkModuleWithInput(entryRot, 8, asservPosRot, AsservCommand); linkModuleWithInput(entryRot, 0, asservPosRot, AsservKp); linkModuleWithInput(entryRot, 1, asservPosRot, AsservKi); linkModuleWithInput(entryRot, 2, asservPosRot, AsservKd); linkModuleWithInput(entryRot, 3, asservPosRot, AsservDeriv); linkModuleWithInput(operatorOut, 1, asservPosRot, AsservMeasure); linkModuleWithInput(asservPosRot, 0, asservVitRot, AsservCommand); linkModuleWithInput(entryRot, 4, asservVitRot, AsservKp); linkModuleWithInput(entryRot, 5, asservVitRot, AsservKi); linkModuleWithInput(entryRot, 6, asservVitRot, AsservKd); linkModuleWithInput(entryRot, 7, asservVitRot, AsservDeriv); linkModuleWithInput(operatorOut, 1, measureDerivatorRot, 0); linkModuleWithInput(measureDerivatorRot, 0, asservVitRot, AsservMeasure); linkModuleWithInput(asservVitRot, 0, imeInIntegratorRot, 0); linkModuleWithInput(imeInIntegratorRot, 0, operatorIn, 1); linkModuleWithInput(operatorIn, 1, ifaceMERight, 0); linkModuleWithInput(operatorIn, 0, ifaceMELeft, 0); // linkModuleWithInput(toggleSwitchRight, 0, ifaceMERight, 0); // linkModuleWithInput(toggleSwitchLeft, 0, ifaceMELeft, 0); linkModuleWithInput(ifaceMERight, 0, operatorOut, 1); linkModuleWithInput(ifaceMELeft, 0, operatorOut, 0); // linkModuleWithInput(ifaceMERight, 0, starter, 1); linkModuleWithInput(ifaceMELeft, 0, starter, 0); debug("E"); //resetSystem(&ctlBlock, portMAX_DELAY); for (;;) { if (startSystem(&ctlBlock) == NO_ERR) { if(waitEndOfSystem(&ctlBlock, 10000) == NO_ERR) { //resetSystem(&ctlBlock, portMAX_DELAY); //command += 500; } } // Cette fonction permet à la tache d'être périodique. // La tache est bloquée pendant (500ms - son temps d'execution). vTaskDelayUntil(&xLastWakeTime, 500/portTICK_RATE_MS); }