void FluidSimulator::advectVelocity(){


	Cell ** updatedCells = new Cell*[simulationGrid->width];
	for (int i = 0; i < simulationGrid->width; i++){
		updatedCells[i] = new Cell[simulationGrid->height];
	}


	computeTimeStep();

	for (int i = 0; i < simulationGrid->width; i++){
		for (int j = 0; j < simulationGrid->height; j++){
			updatedCells[i][j] = advectCell(i, j);
		}
	}
	simulationGrid->cells = updatedCells;
	for (int i = 0; i < simulationGrid->width; i++){
		for (int j = 0; j < simulationGrid->height; j++){
			addForces(i, j);
		}
	}


	//std::cout << simulationGrid->getVelocityVector(4, 2);
}
Exemple #2
0
void Mesh::setup()
{
    int v = (int)vertices.size();
    
    // build Laplacian
    Eigen::SparseMatrix<double> L(v, v);
    buildLaplacian(L);
    poissonSolver.compute(L);
    
    // build diagonal area matrix
    Eigen::SparseMatrix<double> A(v, v);
    buildAreaMatrix(A);
    
    // compute time step
    double t = computeTimeStep();
    
    // 1. compute heat flow for time t
    heatSolver.compute(A - t*L);
}
Exemple #3
0
//--------------------------------------------------------------------------------------------------
// run
void BasicSPH::run(double time)
{
    double oldTimeStep = _dt;

    // Run simulation!
    double timeLeft = time;
    while (timeLeft > 0.0)
    {
        // Run simulation steps
        buildNeighbors();
        computeDensityAndPressure();
        addExternalForces();
        computeArtificialViscosityForces();
        computePressureForces();

        // Compute time step
        if (_useAdaptiveTimeStep)
            computeTimeStep();

        // Limit timestep to the time left in the simulation
        if (timeLeft < _dt)
        {
            _dt = timeLeft;
        }

        // Update particles
        integrate();

        // Update time
        timeLeft -= _dt;

        std::cout << "Substep done! With timestep = " << _dt << std::endl;
    }

    // Restore old time step
    _dt = oldTimeStep;
}
Exemple #4
0
void DriverBase<Scalar>::advanceFrame(unsigned int frame)
{
    std::cout<<"Begin Frame "<<frame<<"\n";
    //plugin onBeginFrame()
    unsigned int plugin_num = static_cast<unsigned int>(plugins_.size());
    DriverPluginBase<Scalar>* plugin;
    for(unsigned int i = 0; i < plugin_num; ++i)
    {
        plugin = plugins_[i];
        if(plugin != NULL)
            plugin->onBeginFrame(frame);
    }
    //timer start frame
    if(enable_timer_) timer_.startTimer();
    //frame content
    Scalar frame_dt=1.0/frame_rate_;
    Scalar finish_time=time_+frame_dt;
    bool frame_done=false;
    while(!frame_done)
    {
        //compute time step
        dt_=computeTimeStep();
        dt_=(dt_>max_dt_)?max_dt_:dt_;
        //adjust time step if it's the last step of frame
        if(finish_time-time_<=dt_)
        {
            dt_=finish_time-time_;
            frame_done=true;
        }
        //advance step
        advanceStep(dt_);
    }
    std::cout<<"End Frame "<<frame<<" ";
    //timer end frame
    if(enable_timer_)
    {
        timer_.stopTimer();
        Scalar time_cur_frame = timer_.getElapsedTime();
        total_simulation_time_ += time_cur_frame;
        std::cout<<time_cur_frame<<" s";
    }
    std::cout<<"\n";
    //end simulation
    if(frame == end_frame_)
    {
        std::cout<<"Simulation Ended.\n";
        if(enable_timer_)
            std::cout<<"Total simulation time: "<<total_simulation_time_<<" s; Average: "<<total_simulation_time_/(end_frame_-start_frame_)<<" s/frame.\n";
    }
    //write to file
    if(write_to_file_)
    {
        std::stringstream adaptor;
        adaptor<<frame;
        std::string frame_str;
        adaptor>>frame_str;
        std::string file_name=std::string("Frame ")+frame_str;
        write(file_name.c_str());
    }
    //plugin
    for(unsigned int i = 0; i < plugin_num; ++i)
    {
        plugin = plugins_[i];
        if(plugin != NULL)
            plugin->onEndFrame(frame);
    }
}