Exemple #1
0
void
Console::timestepSetup()
{
  // Do nothing if output is turned off
  // Do nothing if the problem is steady or if it is not an output interval
  // Do nothing if output_initial = false and the timestep is zero
  if (!_allow_output || !checkInterval() || (!_output_initial && timeStep() == 0))
    return;

  // Stream to build the time step information
  std::stringstream oss;

  // Write timestep data for transient executioners
  if (_transient)
  {
    // Get the length of the time step string
    std::ostringstream time_step_string;
    time_step_string << timeStep();
    unsigned int n = time_step_string.str().size();
    if (n < 2)
      n = 2;

    // Write time step and time information
    oss << std::endl << "Time Step " << std::setw(n) << timeStep();

    // Set precision
    if (_precision > 0)
      oss << std::setw(_precision) << std::setprecision(_precision) << std::setfill('0') << std::showpoint;

    // Show scientific notation
    if (_scientific_time)
      oss << std::scientific;

    // Print the time
    oss << ", time = " << time() << std::endl;

    // Show old time information, if desired
    if (_verbose)
      oss << std::right << std::setw(21) << std::setfill(' ') << "old time = " << std::left << timeOld() << '\n';

    // Show the time delta information
    oss << std::right << std::setw(21) << std::setfill(' ') << "dt = "<< std::left << dt() << '\n';

    // Show the old time delta information, if desired
    if (_verbose)
      oss << std::right << std::setw(21) << std::setfill(' ') << "old dt = " << _dt_old << '\n';
  }

  // Output to the screen
  write(oss.str());
}
// --------------------------------------------------------
HandleWidgetController::HandleWidgetController( RigidWidgetController * attached_widget,
											   const SettingContainer & tool_setting_container,
											   const MagnifyingGlass & mg
) :
	TouchWidgetController(HandleWidgetType),
	_tool_setting_container(tool_setting_container),
	timer(this)
{
	_attached_widget = attached_widget;
	_attached_widget->setAttachedToHandleWidget(true);
	//_attached_widget_original_pos = new QPointF(_attached_widget->pos());
	_absolute_handle = new AbsoluteHandle(mg.srcCenterT(), mg.srcRadiusT());
	_absolute_handle->setPos(attached_widget->pos());
	_absolute_handle->createOriginalPos();
	_clutch_handle = NULL;
	_absolute_touch = NULL;
	_absolute_secondary_touch = NULL;
	_clutch_touch = NULL;
	_clutch_resizing_touch_point = NULL;
	timer.start();
	connect(&timer, SIGNAL(timeout()), this, SLOT(timeStep()));
	_virtual_second_touch = NULL;
	_lock_touch = NULL;

	logger() << "hwc_open" << this << mg.dstCenterT() << mg.dstRadiusT() << mg.srcCenterT() << mg.srcRadiusT();
}
Exemple #3
0
  void threadFunc()
  {
    
    pauseLock.lock();
    while(isContinuing)
      {
	while (isPaused)
	  {
	    pauseCondition.wait(pauseLock);
	  }
	auto t0=g_clock::now();
	//
	consumeInput();
	//
	timeStep();
	// Render
	cbMutex.lock();
	if(nullptr!=cb)
	  {
	    (*cb)(mField,current,nullptr);
	  }
	cbMutex.unlock();
	// Cap game speed
	while(std::chrono::duration_cast<sleep_time>(g_clock::now()-t0).count() < frame_err)
	  {
	    std::this_thread::sleep_for(sleep_time(1));
	  }
      }

  }
Exemple #4
0
void
CSV::output()
{
  // Call the base class output (populates tables)
  TableOutput::output();

  // Print the table containing all the data to a file
  if (!_all_data_table.empty() && processor_id() == 0)
    _all_data_table.printCSV(filename(), 1, _align);

  // Output each VectorPostprocessor's data to a file
  for (std::map<std::string, FormattedTable>::iterator it = _vector_postprocessor_tables.begin(); it != _vector_postprocessor_tables.end(); ++it)
  {
    std::ostringstream output;
    output << _file_base << "_" << it->first;

    output << "_"
           << std::setw(_padding)
           << std::setprecision(0)
           << std::setfill('0')
           << std::right
           << timeStep();

    output << ".csv";

    if (_set_delimiter)
      it->second.setDelimiter(_delimiter);
    it->second.setPrecision(_precision);
    it->second.printCSV(output.str(), 1, _align);
  }
}
Exemple #5
0
void
Console::writeTimestepInformation()
{
  // Stream to build the time step information
  std::stringstream oss;

  // Write timestep data for transient executioners
  if (_transient)
  {
    // Get the length of the time step string
    std::ostringstream time_step_string;
    time_step_string << timeStep();
    unsigned int n = time_step_string.str().size();
    if (n < 2)
      n = 2;

    // Write time step and time information
    oss << std::endl << "Time Step " << std::setw(n) << timeStep();

    // Set precision
    if (_precision > 0)
      oss << std::setw(_precision) << std::setprecision(_precision) << std::setfill('0')
          << std::showpoint;

    // Show scientific notation
    if (_scientific_time)
      oss << std::scientific;

    // Print the time
    oss << ", time = " << time() << std::endl;

    // Show old time information, if desired
    if (_verbose)
      oss << std::right << std::setw(21) << std::setfill(' ') << "old time = " << std::left
          << timeOld() << '\n';

    // Show the time delta information
    oss << std::right << std::setw(21) << std::setfill(' ') << "dt = " << std::left << dt() << '\n';

    // Show the old time delta information, if desired
    if (_verbose)
      oss << std::right << std::setw(21) << std::setfill(' ') << "old dt = " << _dt_old << '\n';
  }

  // Output to the screen
  _console << oss.str();
}
Exemple #6
0
K3bTimeoutWidget::K3bTimeoutWidget( QWidget* parent )
  : QWidget( parent )
{
  d = new Private;
  d->timeout = 10000;
  d->margin = 4;
  connect( &d->timer, SIGNAL(timeout()), this, SLOT(timeStep()) );
}
Exemple #7
0
K3b::TimeoutWidget::TimeoutWidget( QWidget* parent )
  : QWidget( parent )
{
  d = new Private;
  d->timeout = 10000;
  d->padding = 4;
  d->margin = 1;
  d->paused = false;
  connect( &d->timer, SIGNAL(timeout()), this, SLOT(timeStep()) );
}
Exemple #8
0
int render()
{
	//updates piavca's state
	timeStep();
	//updates mesh

	Piavca::Core::getCore()->prerender();
	
	// render the model
	Piavca::Core::getCore()->render();
	return 0;
}
QVector<double> TimeSeriesMotion::time() const
{    
    // Time step based on the max frequency
    const double dt = timeStep();

    QVector<double> v(m_pointCount);

    for (int i = 0; i < m_pointCount; ++i)
        v[i] = i * dt;

    return v;
}
Exemple #10
0
QVector<double> TimeSeriesMotion::timeSeries(
        MotionType type, const QVector<std::complex<double> > & tf, const bool baselineCorrect) const
{
    // Compute the time series
    QVector<double> ts = calcTimeSeries(m_fourierAcc, tf);

    // Remove the zero padded values from the time series
    ts.resize(m_pointCount);

    if (baselineCorrect) {
        const double dt = timeStep();

        // Compute the displacement time series
        QVector<double> disp = ts;
        for (int i = 0; i < 2; ++i)
            disp = integrate(disp);

        // Use a fourth order polynomial
        int term = 4;
        // Fix a polynominal to the data
        QVector<double> dispCoeffs = baselineFit(term, disp);

        // Compute the coeffs to be applied to the acceleration time series
        QVector<double> accelCoeffs;

        for ( int i = 2; i < dispCoeffs.size(); ++i ) {
            accelCoeffs << i * (i-1) * dispCoeffs.at(i);
        }

        for ( int i = 0; i < ts.size(); ++i ) {
            double value = 0;

            for ( int j = 0; j < accelCoeffs.size(); ++j) {
                value += accelCoeffs.at(j) * pow(i * dt,j);
            }

            // correct the accel
            ts[i] -= value;
        }
    }

    // Integrate to the appropriate time series
    for (int i = 0; i < (int)type; ++i)
        ts = integrate(ts);

    // Scale to the appropriate units
    if (type == Velocity || type == Displacement) {
        for ( int i = 0; i < ts.size(); ++i )
            ts[i] *= Units::instance()->tsConv();
    }

    return ts;
}
Exemple #11
0
QVector<double> TimeSeriesMotion::integrate(const QVector<double> & in) const
{
    QVector<double> out(in.size());
    const double dt = timeStep();

    out[0] = 0.0;
    
    for (int i = 1; i < in.size(); ++i)
        out[i] = out.at(i-1) + dt * (in.at(i) + in.at(i-1)) / 2;

    return out;
}
Exemple #12
0
	void Integrator::integrate()
	{
		double timeElapsed = timer.getTime();

    const double step = this->timestep / game_speed;
		while (timeElapsed >= currentTime + step)
		{
			if (timeStep(step, this->currentTime))
				break;

			this->currentTime += step;
		}
	}
Exemple #13
0
std::string
Checkpoint::filename()
{
  // Get the time step with correct zero padding
  std::ostringstream output;
  output << directory()
         << "/"
         << std::setw(_padding)
         << std::setprecision(0)
         << std::setfill('0')
         << std::right
         << timeStep();
  return output.str();
}
Exemple #14
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    timer = new QTimer(this);
    connect(timer, SIGNAL(timeout()), this, SLOT(timeStep()));

    painter = new QPainter(this);

    for (int i = 0; i < MAX_OBJECTS; i++)
        objects[i] = 0;

    timer->start(1000);
}
Exemple #15
0
void
UiSettings::loadSettings()
{
    QSettings s( "CS224", "snow" );

    windowPosition() = s.value( "windowPosition", QPoint(0,0) ).toPoint();
    windowSize() = s.value( "windowSize", QSize(1000,800) ).toSize();

    fillNumParticles() = s.value( "fillNumParticles", 512*128 ).toInt();
    fillResolution() = s.value( "fillResolution", 0.05f ).toFloat();
    fillDensity() = s.value( "fillDensity", 150.f ).toFloat();

    exportDensity() = s.value("exportDensity", false).toBool();
    exportVelocity() = s.value("exportVelocity", false).toBool();

    exportFPS() = s.value("exportFPS", 24).toInt();
    maxTime() = s.value("maxTime", 3).toFloat();

    gridPosition() = vec3( s.value("gridPositionX", 0.f).toFloat(),
                           s.value("gridPositionY", 0.f).toFloat(),
                           s.value("gridPositionZ", 0.f).toFloat() );


    gridDimensions() = glm::ivec3( s.value("gridDimensionX", 128).toInt(),
                                   s.value("gridDimensionY", 128).toInt(),
                                   s.value("gridDimensionZ", 128).toInt() );

    gridResolution() = s.value( "gridResolution", 0.05f ).toFloat();

    timeStep() = s.value( "timeStep", 1e-5 ).toFloat();
    implicit() = s.value( "implicit", true ).toBool();
    materialPreset() = s.value( "materialPreset", MAT_DEFAULT).toInt();

    showContainers() = s.value( "showContainers", true ).toBool();
    showContainersMode() = s.value( "showContainersMode", WIREFRAME ).toInt();
    showColliders() = s.value( "showColliders", true ).toBool();
    showCollidersMode() = s.value( "showCollidersMode", SOLID ).toInt();
    showGrid() = s.value( "showGrid", false ).toBool();
    showGridMode() = s.value( "showGridMode", MIN_FACE_CELLS ).toInt();
    showGridData() = s.value( "showGridData", false ).toBool();
    showGridDataMode() = s.value( "showGridDataMode", NODE_DENSITY ).toInt();
    showParticles() = s.value( "showParticles", true ).toBool();
    showParticlesMode() = s.value( "showParticlesMode", PARTICLE_MASS ).toInt();

    selectionColor() = glm::vec4( 0.302f, 0.773f, 0.839f, 1.f );
}
Exemple #16
0
QVector<double> TimeSeriesMotion::absFourier(const QVector< std::complex<double> >& fa, const QVector<std::complex<double> >& tf) const
{
    QVector<double> absFa(fa.size());
    const double dt = timeStep();

    if (!tf.isEmpty()) {
        Q_ASSERT(fa.size() == tf.size());
        // Apply the transfer function to the fas
        for (int i = 0; i < fa.size(); ++i)
            absFa[i] = abs(tf.at(i) * fa.at(i)) * dt;
    } else {
        // The FAS is scaled by the time-step when it is compared with another motion
        for (int i = 0; i < fa.size(); ++i)
            absFa[i] = abs(fa.at(i)) * dt;
    }

    return absFa;
}
Exemple #17
0
void Application::run() {
    // Launches the game
    sf::Clock clock;
    sf::Time timeSinceLastUpdate = sf::Time::Zero;

    while (mWindow.isOpen()) {
        sf::Time dt = clock.restart();
        timeSinceLastUpdate += dt;

        // While there are still time-steps that ought to have passed
        while (timeSinceLastUpdate > TimePerFrame) {
            timeSinceLastUpdate -= TimePerFrame;
            timeStep();
        }
        updateStatistics(dt);
        render();
    }
}
Exemple #18
0
void
UiSettings::saveSettings()
{
    QSettings s( "CS224", "snow" );

    s.setValue( "windowPosition", windowPosition() );
    s.setValue( "windowSize", windowSize() );

    s.setValue( "fillNumParticles", fillNumParticles() );
    s.setValue( "fillResolution", fillResolution() );
    s.setValue( "fillDensity", fillDensity() );

    s.setValue("exportDensity", exportDensity());
    s.setValue("exportVelocity",exportVelocity());
    s.setValue( "exportFPS", exportFPS());
    s.setValue( "maxTime", maxTime());

    s.setValue( "gridPositionX", gridPosition().x );
    s.setValue( "gridPositionY", gridPosition().y );
    s.setValue( "gridPositionZ", gridPosition().z );

    s.setValue( "gridDimensionX", gridDimensions().x );
    s.setValue( "gridDimensionY", gridDimensions().y );
    s.setValue( "gridDimensionZ", gridDimensions().z );

    s.setValue( "gridResolution", gridResolution() );

    s.setValue( "timeStep", timeStep() );
    s.setValue( "implicit", implicit() );
    s.setValue("materialPreset", materialPreset());

    s.setValue( "showContainers", showContainers() );
    s.setValue( "showContainersMode", showContainersMode() );
    s.setValue( "showColliders", showColliders() );
    s.setValue( "showCollidersMode", showCollidersMode() );
    s.setValue( "showGrid", showGrid() );
    s.setValue( "showGridMode", showGridMode() );
    s.setValue( "showGridData", showGridData() );
    s.setValue( "showGridDataMode", showGridDataMode() );
    s.setValue( "showParticles", showParticles() );
    s.setValue( "showParticlesMode", showParticlesMode() );
}
Exemple #19
0
bool Simulator::oneStep(){
    ThreadedObject::oneStep();

    if (!currentTime()) gettimeofday(&beginTime, NULL);
    if (adjustTime){
        struct timeval tv;
        gettimeofday(&tv, NULL);
        startTimes.push_back(tv);
        if (startTimes.size() > 1.0/timeStep()){
            startTimes.pop_front();
        }
        if (startTimes.size() >= 2){
            const struct timeval& first = startTimes.front();
            const struct timeval& last  = startTimes.back();
            int realT = (last.tv_sec - first.tv_sec)*1e6
                + (last.tv_usec - first.tv_usec);
            int simT = timeStep()*(startTimes.size()-1)*1e6;
            int usec = simT - realT;
            if (usec > 1000){
                usleep(usec);
            }
        }
    }

    tm_control.begin();
    for (unsigned int i=0; i<numBodies(); i++){
        BodyRTC *bodyrtc = dynamic_cast<BodyRTC *>(body(i).get());
        bodyrtc->writeDataPorts(currentTime());
    }
    
    for (unsigned int i=0; i<numBodies(); i++){
        BodyRTC *bodyrtc = dynamic_cast<BodyRTC *>(body(i).get());
        bodyrtc->readDataPorts();
    }
    for (unsigned int i=0; i<numBodies(); i++){
        BodyRTC *bodyrtc = dynamic_cast<BodyRTC *>(body(i).get());
        bodyrtc->preOneStep();
    }
    for (unsigned int i=0; i<receivers.size(); i++){
        receivers[i].tick(timeStep());
    }
    tm_control.end();

#if 1
    tm_collision.begin();
    checkCollision(collisions);
    tm_collision.end();
#endif

    tm_dynamics.begin();
    constraintForceSolver.clearExternalForces();
    if (m_kinematicsOnly){
        for (int i=0; i<numBodies(); i++){
            body(i)->calcForwardKinematics();
        }
        currentTime_ += timeStep();
    }else{
        calcNextState(collisions);
    }
    
    for (unsigned int i=0; i<numBodies(); i++){
        BodyRTC *bodyrtc = dynamic_cast<BodyRTC *>(body(i).get());
        bodyrtc->postOneStep();
    }
    appendLog();
    tm_dynamics.end();
    
    if (m_totalTime && currentTime() > m_totalTime){
        struct timeval endTime;
        gettimeofday(&endTime, NULL);
        double realT = (endTime.tv_sec - beginTime.tv_sec)
            + (endTime.tv_usec - beginTime.tv_usec)/1e6;
        printf("total     :%8.3f[s], %8.3f[sim/real]\n",
               realT, m_totalTime/realT);
        printf("controller:%8.3f[s], %8.3f[ms/frame]\n",
               tm_control.totalTime(), tm_control.averageTime()*1000);
        printf("collision :%8.3f[s], %8.3f[ms/frame]\n",
               tm_collision.totalTime(), tm_collision.averageTime()*1000);
        printf("dynamics  :%8.3f[s], %8.3f[ms/frame]\n",
               tm_dynamics.totalTime(), tm_dynamics.averageTime()*1000);
        for (int i=0; i<numBodies(); i++){
            hrp::BodyPtr body = this->body(i);
            int ntri=0;
            for (int j=0; j<body->numLinks(); j++){
                hrp::Link *l = body->link(j);
                if (l && l->coldetModel){
                    ntri += l->coldetModel->getNumTriangles();
                }
            }
            printf("num of triangles : %s : %d\n", body->name().c_str(), ntri);
        }
        fflush(stdout);
        return false;
    }else{
        return true;
    }
}
Exemple #20
0
void displayFunc()
{
  //std::cout << "start of displayfunc\n";
  //return ;
  //std::cout << "core pointer " << ((int)g_Params.core) << std::endl;
  //std::cout << "core pointer " << Piavca::Core::getCore() << std::endl;
  static float prevTime = Piavca::Core::getCore()->getTime();
  static int framecount = 0;
  static float updateTime = 0;
  static float prerenderTime = 0;
  static float renderTime = 0;

  //std::cout << "display function \n";
  //std::cout << "core pointer " << (int) Piavca::Core::getCore();

  float time1 = Piavca::Core::getCore()->getTime();
  timeStep();	
  glutPostRedisplay();	
  float time2 = Piavca::Core::getCore()->getTime();
  updateTime += time2 - time1;


  //std::cout << "Piavca.render\n";
  Piavca::Core::getCore()->prerender();
  float time3 = Piavca::Core::getCore()->getTime();
  prerenderTime += time3 - time2;

  // clear the vertex and face counters
  //m_vertexCount = 0;
  //m_faceCount = 0;

  // clear all the buffers
  //glClearColor(0.0f, 0.0f, 0.3f, 0.0f);
  glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  // set the projection transformation
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  //gluPerspective(45.0f, (GLdouble)g_Params.width / (GLdouble)g_Params.height, 0.01, 10000);
  float height = 0.4142135*0.01;
  float width = (height*g_Params.width)/ g_Params.height;
  glFrustum(-(GLdouble)(width),(GLdouble)(width), -(GLdouble)(height),(GLdouble)(height), 0.01, 10000);

  // set the model transformation
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();

  // light attributes
  const GLfloat light_ambient[]  = { 0.3f, 0.3f, 0.3f, 1.0f };
  const GLfloat light_diffuse[]  = { 0.52f, 0.5f, 0.5f, 1.0f };
  const GLfloat light_specular[] = { 0.1f, 0.1f, 0.1f, 1.0f };

  // setup the light attributes
  glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
  glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
  glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);

  // set the light position
  GLfloat lightPosition[] = { 0.0f, -1.0f, 1.0f, 1.0f };
  glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);

  // set camera position
  glTranslatef(g_Params.leftright, g_Params.updown, 0.0f);
  glTranslatef(0.0f, 0.0f, -g_Params.distance);
  glRotatef(g_Params.twistAngle, 0.0f, 1.0f, 0.0f);
  glRotatef(g_Params.tiltAngle, 1.0f, 0.0f, 0.0f);
  glTranslatef(0.0f, 0.0f, -90.0f);


  // render the model
  Piavca::Core::getCore()->render();

  // swap the front- and back-buffer
  glutSwapBuffers();
  
	float time4 = Piavca::Core::getCore()->getTime();
	renderTime += time4 - time3;
	
	framecount ++;
	float time = Piavca::Core::getCore()->getTime();
	if((time - prevTime) > 10.0)
	{
		std::cout << "framerate " << framecount/(time - prevTime) 
			<< " update time " << updateTime/framecount  
			<< " prerender time " << prerenderTime/framecount  
			<< " render time " << renderTime/framecount << std::endl;
		framecount = 0;
		updateTime = 0.0;
		prerenderTime = 0.0;
		renderTime = 0.0;
		prevTime = time;
	}

	//std::cout << "finished Piavca.render\n";

}
Exemple #21
0
MainWindow::MainWindow()
{
	//this->setStyleSheet("background-color: black;");

    centralWidget = new QWidget(this);
	//centralWidget->setBackgroundRole(QPalette::Text);
    setCentralWidget(centralWidget);

	centralLayout = new SquareItemWithSidePaneLayout;



	QTimer *timer = new QTimer(this);
	//connect(timer, SIGNAL(timeout()), this, SLOT(timeStep()));
	//connect(timer, SIGNAL(timeout()), TimeSingleton::instance(), SLOT(timeStep()));
	connect(timer, SIGNAL(timeout()), this, SLOT(timeStep()));

#ifdef USE_NETWORK_CLIENT
  connect(timer, SIGNAL(timeout()), &raw_touch_adapter, SLOT(generateTouchEvent()));
	connect(&raw_touch_adapter, SIGNAL(touchEvent(QTouchEvent *)), this, SLOT(touchEvent(QTouchEvent *)));
#endif
	timer->start(10);

    createActions();
    createMenus();

	
	//setBackgroundRole(QPalette::Text);
	//QSpacerItem * spacerItem = new QSpacerItem(100, 20, QSizePolicy::Expanding, QSizePolicy::Expanding);
	//centralLayout->addItem(spacerItem, 0, 0);


	_side_pane = new SidePane(centralWidget);
	centralLayout->addWidget(_side_pane);

	//QGridLayout * sidepane_layout = new QGridLayout;
	//QPushButton * btn = new QPushButton("blah", sidepane);
	//QLabel * lbl = new QLabel("asdf", sidepane);
	//QListWidget * lwg = new QListWidget(sidepane);
	//lwg->insertItem(0, "blah");
	//lwg->insertItem(0, "ablah");
	//lwg->setEnabled(false);
	//btn->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
	//lbl->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
	//lwg->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);

	//QFont fnt("Myriad Pro", 24, QFont::Bold);
	//lbl->setFont(fnt );
	//sidepane_layout->addWidget(btn);
	//sidepane_layout->addWidget(lbl);
	//sidepane_layout->addWidget(lwg);
	//sidepane->setLayout(sidepane_layout);

	//QSpacerItem * spacerItem2 = new QSpacerItem(100, 20, QSizePolicy::Expanding, QSizePolicy::Expanding);
	//centralLayout->addItem(spacerItem2, 0, 2);

	//QPushButton *pushButton = new QPushButton("blah");
	//pushButton->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
	//centralLayout->addWidget(pushButton, 0, 1);


    setWindowTitle(tr("Fat Finger Playground"));
    //resize(1280, 720);
	resize(1200,900);


	connect(_side_pane, SIGNAL(highlightCurrentBall()), this, SLOT(highlightCurrentBall()));
	connect(_side_pane, SIGNAL(changeStudy(QString)), this, SLOT(changeStudy(QString)));

	move(-1500,100);
	//glWidget->start();

	_study = NULL;
	_gl_widget = NULL;

  changeStudy("config");

}
void
BCInterfaceFunctionSolverDefined< FSIOperator >::updatePhysicalSolverVariables()
{

#ifdef HAVE_LIFEV_DEBUG
    debugStream( 5025 ) << "BCInterfaceFunctionSolverDefined::updatePhysicalSolverVariables" << "\n";
#endif

    switch ( M_FSIFunction )
    {
    case RobinWall:
    {
        if ( !M_physicalSolver->isSolid() )
            return;

        // Update the physical solver variables
        for ( UInt i( 0 ); i < M_vectorFunctionRobin.size(); ++i )
        {
            boost::shared_ptr< BCInterfaceFunctionParserSolver< physicalSolver_Type > > castedFunctionSolver =
                boost::dynamic_pointer_cast< BCInterfaceFunctionParserSolver< physicalSolver_Type > > ( M_vectorFunctionRobin[i] );

            if ( castedFunctionSolver != 0 )
                castedFunctionSolver->updatePhysicalSolverVariables();
        }

        // Set coefficients
        Int gid;
        Real x, y, z;
        Real alpha, beta;
        Real t( M_physicalSolver->dataSolid()->dataTime()->time() );
        Real timeStep( M_physicalSolver->dataSolid()->dataTime()->timeStep() );

        // Update Time advance
        M_physicalSolver->solidTimeAdvance()->updateRHSFirstDerivative( timeStep );

        Int verticesGlobalNumber( M_physicalSolver->solidLocalMesh().numGlobalVertices() );
        for ( UInt i(0) ; i < M_physicalSolver->solidLocalMesh().numVertices() ; ++i )
        {
            gid = M_physicalSolver->solidLocalMesh().meshTransformer().pointInitial( i ).id();

            x   = M_physicalSolver->solidLocalMesh().meshTransformer().pointInitial( i ).x();
            y   = M_physicalSolver->solidLocalMesh().meshTransformer().pointInitial( i ).y();
            z   = M_physicalSolver->solidLocalMesh().meshTransformer().pointInitial( i ).z();

            alpha = M_vectorFunctionRobin[0]->functionTimeSpace( t, x, y, z, 0 );
            beta  = M_vectorFunctionRobin[1]->functionTimeSpace( t, x, y, z, 0 );

            alpha += M_physicalSolver->solidTimeAdvance()->coefficientFirstDerivative( 0 ) / timeStep * beta;

            (*M_robinAlphaCoefficient)[gid] = alpha;
            (*M_robinBetaCoefficient)[gid]  = beta;

            (*M_robinAlphaCoefficient)[gid + verticesGlobalNumber] = alpha;
            (*M_robinBetaCoefficient)[gid + verticesGlobalNumber]  = beta;

            (*M_robinAlphaCoefficient)[gid + verticesGlobalNumber * 2] = alpha;
            (*M_robinBetaCoefficient)[gid + verticesGlobalNumber * 2]  = beta;
        }

        *M_robinRHS = M_physicalSolver->solidTimeAdvance()->rhsContributionFirstDerivative();

        break;
    }
    default:
        break;
    }
}
Exemple #23
0
 void Particles::timeStep() {
   timeStep(DEFAULT_DELTA_T);
 }
Exemple #24
0
void
CSV::output(const ExecFlagType & type)
{
  // Start the performance log
  Moose::perf_log.push("CSV::output()", "Output");

  // Call the base class output (populates tables)
  TableOutput::output(type);

  // Print the table containing all the data to a file
  if (_write_all_table && !_all_data_table.empty() && processor_id() == 0)
    _all_data_table.printCSV(filename(), 1, _align);

  // Output each VectorPostprocessor's data to a file
  if (_write_vector_table && processor_id() == 0)
  {
    for (auto & it : _vector_postprocessor_tables)
    {
      std::ostringstream output;
      output << _file_base << "_" << MooseUtils::shortName(it.first);
      output << "_" << std::setw(_padding) << std::setprecision(0) << std::setfill('0') << std::right << timeStep() << ".csv";

      if (_set_delimiter)
        it.second.setDelimiter(_delimiter);
      it.second.setPrecision(_precision);
      it.second.printCSV(output.str(), 1, _align);

      if (_time_data)
      {
        std::ostringstream filename;
        filename << _file_base << "_" << MooseUtils::shortName(it.first) << "_time.csv";
        _vector_postprocessor_time_tables[it.first].printCSV(filename.str());
      }
    }
  }

  // Re-set write flags
  _write_all_table = false;
  _write_vector_table = false;

  Moose::perf_log.pop("CSV::output()", "Output");
}
// call takestep to advance simulation
void LenJonSim::takeStep() {
    timeStep();
}
Exemple #26
0
void Sim1D::solve(int loglevel, bool refine_grid)
{
    int new_points = 1;
    int nsteps;
    doublereal dt = m_tstep;
    int soln_number = -1;
    finalize();

    while (new_points > 0) {
        size_t istep = 0;
        nsteps = m_steps[istep];

        bool ok = false;
        if (loglevel > 0) {
            writeline('.', 78, true, true);
        }
        while (!ok) {
            writelog("Attempt Newton solution of steady-state problem...", loglevel);
            int status = newtonSolve(loglevel-1);

            if (status == 0) {
                if (loglevel > 0) {
                    writelog("    success.\n\n");
                    writelog("Problem solved on [");
                    for (size_t mm = 1; mm < nDomains(); mm+=2) {
                        writelog(int2str(domain(mm).nPoints()));
                        if (mm + 2 < nDomains()) {
                            writelog(", ");
                        }
                    }
                    writelog("] point grid(s).\n");
                }
                if (loglevel > 6) {
                    save("debug_sim1d.xml", "debug",
                         "After successful Newton solve");
                }
                if (loglevel > 7) {
                    saveResidual("debug_sim1d.xml", "residual",
                                 "After successful Newton solve");
                }
                ok = true;
                soln_number++;
            } else {
                char buf[100];
                writelog("    failure. \n", loglevel);
                if (loglevel > 6) {
                    save("debug_sim1d.xml", "debug",
                         "After unsuccessful Newton solve");
                }
                if (loglevel > 7) {
                    saveResidual("debug_sim1d.xml", "residual",
                                 "After unsuccessful Newton solve");
                }
                writelog("Take "+int2str(nsteps)+" timesteps   ", loglevel);
                dt = timeStep(nsteps, dt, DATA_PTR(m_x), DATA_PTR(m_xnew),
                              loglevel-1);
                if (loglevel > 6) {
                    save("debug_sim1d.xml", "debug", "After timestepping");
                }
                if (loglevel > 7) {
                    saveResidual("debug_sim1d.xml", "residual",
                                 "After timestepping");
                }

                if (loglevel == 1) {
                    sprintf(buf, " %10.4g %10.4g \n", dt,
                            log10(ssnorm(DATA_PTR(m_x), DATA_PTR(m_xnew))));
                    writelog(buf);
                }
                istep++;
                if (istep >= m_steps.size()) {
                    nsteps = m_steps.back();
                } else {
                    nsteps = m_steps[istep];
                }
                dt = std::min(dt, m_tmax);
            }
        }
        if (loglevel > 0) {
            writeline('.', 78, true, true);
        }
        if (loglevel > 2) {
            showSolution();
        }

        if (refine_grid) {
            new_points = refine(loglevel);
            if (new_points) {
                // If the grid has changed, preemptively reduce the timestep
                // to avoid multiple successive failed time steps.
                dt = m_tstep;
            }
            if (new_points && loglevel > 6) {
                save("debug_sim1d.xml", "debug", "After regridding");
            }
            if (new_points && loglevel > 7) {
                saveResidual("debug_sim1d.xml", "residual",
                             "After regridding");
            }
            if (new_points < 0) {
                writelog("Maximum number of grid points reached.");
                new_points = 0;
            }
        } else {
            writelog("grid refinement disabled.\n", loglevel);
            new_points = 0;
        }
    }
}
void CPUUncontrolledApproximation::perform() {
    const auto &ctx = kernel->context();
    auto &stateModel = kernel->getCPUKernelStateModel();
    auto nl = stateModel.getNeighborList();
    auto &data = nl->data();
    const auto &box = ctx.boxSize().data();
    const auto &pbc = ctx.periodicBoundaryConditions().data();

    if (ctx.recordReactionsWithPositions()) {
        kernel->getCPUKernelStateModel().reactionRecords().clear();
    }
    if (ctx.recordReactionCounts()) {
        stateModel.resetReactionCounts();
    }

    // gather events
    std::vector<std::promise<std::size_t>> n_events_promises(kernel->getNThreads());
    std::vector<event_promise_t> promises(kernel->getNThreads());
    {

        auto &pool = kernel->pool();

        std::vector<std::function<void(std::size_t)>> executables;
        executables.reserve(kernel->getNThreads());

        std::size_t grainSize = data.size() / kernel->getNThreads();
        std::size_t nlGrainSize = nl->nCells() / kernel->getNThreads();

        auto it = data.cbegin();
        std::size_t it_nl = 0;
        for (auto i = 0U; i < kernel->getNThreads()-1 ; ++i) {
            auto itNext = std::min(it+grainSize, data.cend());

            auto nlNext = std::min(it_nl + nlGrainSize, nl->nCells());
            auto bounds_nl = std::make_tuple(it_nl, nlNext);

            pool.push(findEvents, it, itNext, bounds_nl, kernel, timeStep(), false, std::cref(*nl),
                      std::ref(promises.at(i)), std::ref(n_events_promises.at(i)));

            it = itNext;
            it_nl = nlNext;
        }
        pool.push(findEvents, it, data.cend(), std::make_tuple(it_nl, nl->nCells()), kernel, timeStep(), false,
                  std::cref(*nl), std::ref(promises.back()), std::ref(n_events_promises.back()));
    }

    // collect events
    std::vector<event_t> events;
    {
        std::size_t n_events = 0;
        for (auto &&f : n_events_promises) {
            n_events += f.get_future().get();
        }
        events.reserve(n_events);
        for (auto &&f : promises) {
            auto eventUpdate = std::move(f.get_future().get());
            auto mBegin = std::make_move_iterator(eventUpdate.begin());
            auto mEnd = std::make_move_iterator(eventUpdate.end());
            events.insert(events.end(), mBegin, mEnd);
        }
    }

    // shuffle reactions
    std::shuffle(events.begin(), events.end(), std::mt19937(std::random_device()()));

    // execute reactions
    {
        data_t::EntriesUpdate newParticles{};
        std::vector<data_t::size_type> decayedEntries{};

        // todo better conflict detection?
        for (auto it = events.begin(); it != events.end(); ++it) {
            auto &event = *it;
            if (event.cumulativeRate == 0) {
                auto entry1 = event.idx1;
                if (event.nEducts == 1) {
                    auto reaction = ctx.reactions().order1ByType(event.t1)[event.reactionIndex];
                    if (ctx.recordReactionsWithPositions()) {
                        record_t record;
                        record.id = reaction->id();
                        performReaction(&data, ctx, entry1, entry1, newParticles, decayedEntries, reaction, &record);
                        bcs::fixPosition(record.where, box, pbc);
                        kernel->getCPUKernelStateModel().reactionRecords().push_back(record);
                    } else {
                        performReaction(&data, ctx, entry1, entry1, newParticles, decayedEntries, reaction, nullptr);
                    }
                    if (ctx.recordReactionCounts()) {
                        auto &counts = stateModel.reactionCounts();
                        counts.at(reaction->id())++;
                    }
                    for (auto _it2 = it + 1; _it2 != events.end(); ++_it2) {
                        if (_it2->idx1 == entry1 || _it2->idx2 == entry1) {
                            _it2->cumulativeRate = 1;
                        }
                    }
                } else {
                    auto reaction = ctx.reactions().order2ByType(event.t1, event.t2)[event.reactionIndex];
                    if (ctx.recordReactionsWithPositions()) {
                        record_t record;
                        record.id = reaction->id();
                        performReaction(&data, ctx, entry1, event.idx2, newParticles, decayedEntries, reaction, &record);
                        bcs::fixPosition(record.where, box, pbc);
                        kernel->getCPUKernelStateModel().reactionRecords().push_back(record);
                    } else {
                        performReaction(&data, ctx, entry1, event.idx2, newParticles, decayedEntries, reaction, nullptr);
                    }
                    if (ctx.recordReactionCounts()) {
                        auto &counts = stateModel.reactionCounts();
                        counts.at(reaction->id())++;
                    }
                    for (auto _it2 = it + 1; _it2 != events.end(); ++_it2) {
                        if (_it2->idx1 == entry1 || _it2->idx2 == entry1 ||
                            _it2->idx1 == event.idx2 || _it2->idx2 == event.idx2) {
                            _it2->cumulativeRate = 1;
                        }
                    }
                }
            }
        }
        data.update(std::make_pair(std::move(newParticles), std::move(decayedEntries)));
    }
}