Ejemplo n.º 1
0
Archivo: md2.c Proyecto: kneth/MDreac
int main(int argc, char *argv[]) {

    size_t i;
    FILE *statfile;

    ReadParameters(argc, argv);
    Initialize();
    statfile = fopen(outname, "w");
    ReadConfiguration();
    for(i=0; i<nsteps; i++) { /* a number of single time steps */
        ApplyPerBoundaries();
        if ((i % liststeps) == 0) {
            PutInBox();
            MakeList();
        }
        ComputeForces();
        if (microcanon) {
            Leapfrog();
        }
        else {
            NoseHoover();
        }
        if ((i % iosteps) == 0) {
            fprintf(statfile, "%ld %e %e %e %e %e\n", i, Ekin, Epot, P, eta, Ekin+Epot);
        }
    }
    fclose(statfile);
    WriteConfiguration(final_conf);
    return 1;
}
Ejemplo n.º 2
0
void QViPhyManager::setupSimulation()
{
    switch (_odeSolverEnum) {
        case ODESolverEnum::LEAPFROG:
            _simulation->changeODESolver(std::make_unique<Leapfrog>(Leapfrog()));
            break;
        case ODESolverEnum::EULER:
            _simulation->changeODESolver(std::make_unique<Euler>(Euler()));
    }

    loadSimulation();
}
Ejemplo n.º 3
0
// call this to solve the equations and save results to files
// the system will determine the number of steps; all we need is to provide a step length
// returns the system in the state the Leapfrog algoritm leaves it in (or nullptr if that algorithm is not used)
vector<SolarSystem*>* Solvers::Solve(double step)
{
	clock_t start, finish; // timers
	int n = this->_system->nSteps();

	if (this->_useRK4)
	{
		start = clock(); // start timer

		for (int i = 0; i < n; i++) // for each time step
		{
			this->_rk4->plotCurrentStep(i, step); // if we want to plot this step, do it
			RK4(step); // perform step
		}

		// Timing part: End ...
		finish = clock();
		this->rk4Time = (double)(finish - start) / CLOCKS_PER_SEC; // To convert this into seconds !
	}

	if (this->_useLeapfrog)
	{
		start = clock(); // start timer

		for (int i = 0; i < n; i++) // for each time step
		{
			this->_leapfrog->plotCurrentStep(i, step); // if we want to plot this step, do its
			Leapfrog(step); // perform step
		}

		// Timing part: End ...
		finish = clock();
		this->leapfrogTime = (double)(finish - start) / CLOCKS_PER_SEC; // To convert this into seconds !
	}

	if (this->_useEuler)
	{
		start = clock(); // start timer

		for (int i = 0; i < n; i++) // for each time step
		{
			this->_euler->plotCurrentStep(i, step); // if we want to plot this step, do it
			Euler(step); // perform step
		}

		// Timing part: End ...
		finish = clock();
		this->eulerTime = (double)(finish - start) / CLOCKS_PER_SEC; // To convert this into seconds !
	}

	// put systems we want to return in here
	vector<SolarSystem*>* returnSystems = new vector<SolarSystem*>();

	if (this->_useLeapfrog)
	{
		// plot to file (independent of dimension)
		for (int i = 0; i < this->_leapfrog->dim(); i++)
		{
			ostringstream fname = ostringstream();
			fname << "sim_" << this->_leapfrog->name << "_pos" << i << ".dat";
			this->_leapfrog->plotDim(i, fname.str());
		}

		// make sure the system is up to date
		this->_leapfrog->calculate();

		// add to list of systems to return
		returnSystems->push_back(this->_leapfrog);
	}

	if (this->_useRK4)
	{
		// plot to file (independent of dimension)
		for (int i = 0; i < this->_rk4->dim(); i++)
		{
			ostringstream fname = ostringstream();
			fname << "sim_" << this->_rk4->name << "_pos" << i << ".dat";
			this->_rk4->plotDim(i, fname.str());
		}

		// make sure the system is up to date
		this->_rk4->calculate();

		// add to list of systems to return
		returnSystems->push_back(this->_rk4);
	}

	if (this->_useEuler)
	{
		// plot to file (independent of dimension)
		for (int i = 0; i < this->_euler->dim(); i++)
		{
			ostringstream fname = ostringstream();
			fname << "sim_" << this->_euler->name << "_pos" << i << ".dat";
			this->_euler->plotDim(i, fname.str());
		}

		// make sure the system is up to date
		this->_euler->calculate();

		// add to list of systems to return
		returnSystems->push_back(this->_euler);
	}

	cout << "DONE!" << endl << endl;

	this->totalTime = this->leapfrogTime + this->rk4Time + this->eulerTime;

	return returnSystems;
}