1 #pragma once 2 /* Quantum Minigolf, a computer game illustrating quantum mechanics 3 Copyright (C) 2007 Friedemann Reinhard <friedemann.reinhard@gmail.com> 4 5 This program is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published by 7 the Free Software Foundation; either version 2 of the License, or 8 (at your option) any later version. 9 10 This program is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program; if not, write to the Free Software 17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 18 */ 19 20 21 //QuantumSimulator - the class implementing the numerical solution of the 22 // time-dependent Schr�dinger equation. 23 // The solution is based on a time-splitting scheme. 24 // The propagation is performed successively in momentum and position space 25 // To propagate in momentum space, the wave function is fourier-transformed. 26 // 27 28 #ifdef WIN32 29 #include <windows.h> 30 #endif 31 32 #include <stdlib.h> 33 #include <time.h> 34 #include <stdlib.h> 35 #include <math.h> 36 #include <fftw3.h> 37 #include <SDL.h> 38 39 class QuantumSimulator 40 { 41 public: 42 QuantumSimulator(int width, int height, float dt); 43 44 void BuildPositionPropagator(SDL_Surface *V); 45 void BuildMomentumPropagator(); 46 47 float PropagatePosition(float quench); 48 void PropagateMomentum(); 49 50 // return the result of a position measurement on psi 51 void PositionMeasurement(int *x, int *y); 52 53 // GenGauss - initialize psi with a gaussian wavepacket of width w, 54 // centered around cx and cy in position and around kx and ky in momentum space 55 void GenGauss(int cx, int cy, float kx, float ky, float w ); 56 void ClearWave(void); 57 58 fftwf_complex *psi; // the complex wavefunction 59 fftwf_complex *xprop; // the propagator in position space 60 61 public: 62 ~QuantumSimulator(void); 63 64 private: 65 fftwf_complex *prop; // the propagator in momentum space 66 67 fftwf_plan fft, ifft; // plans for the Fourier transformations 68 // into momentum and position space 69 float dt; // the timestep 70 int width, height; 71 float GaussNorm; // Norm of the wave packet after initialization 72 73 }; 74