/* Quantum Minigolf, a computer game illustrating quantum mechanics Copyright (C) 2007 Friedemann Reinhard This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "QuantumSimulator.h" #include "quantumminigolf.h" #define INTENS 120 // color intensity at maximal probability density // constructor: setup the FFT engine and compute the Momentum Propagator QuantumSimulator::QuantumSimulator(int width, int height, float dt) { this->dt = dt; this->width = width; this->height = height; psi = (fftwf_complex *)fftwf_malloc(sizeof(fftwf_complex)*width*height); prop = (fftwf_complex *)fftwf_malloc(sizeof(fftwf_complex)*width*height); xprop = (fftwf_complex *)fftwf_malloc(sizeof(fftwf_complex)*width*height); printf("Initializing FFT engine ... "); fft = fftwf_plan_dft_2d(width, height, psi, psi, FFTW_FORWARD, FFTW_MEASURE); printf("done \n"); printf("Initializing inverse FFT engine ... "); ifft = fftwf_plan_dft_2d(width, height, psi, psi, FFTW_BACKWARD, FFTW_MEASURE); BuildMomentumPropagator(); // construct a dummy position propagator. The right propagator // is constructed from the track, once the user has made its choice // where to play. for(int x=0; xpixels; // extract the potential for(x=0; xformat, &red, &dummy, &dummy); xprop[x*height+y][0] = cos(-.5*(float)(red)*dt*30000/255); xprop[x*height+y][1] = sin(-.5*(float)(red)*dt*30000/255); if(red>250){ xprop[x*height+y][0] = 0; xprop[x*height+y][1] = 0; } } } } //PropagateMomentum -- FFT into k-space and apply the momentum propagator // to the wave function // effectively, this propagates the wavefunction by dt in a zero potential void QuantumSimulator::PropagateMomentum(void){ volatile float tre, tim, pre, pim; // swap register and propagator real and imaginary parts volatile int x, y; // propagate in momentum space fftwf_execute(fft); for(x=0; x width)xupper =width; int yupper = (int)(cy+2.5*w); if(yupper > height)yupper =height; for(x=xlower; x