示例#1
0
        /// <summary>
        /// Creates a Gaussian wavepacket with given properties.
        /// </summary>
        public static WaveFunction CreateGaussianWavePacket(
            GridSpec gridSpec, float latticeSpacing, float mass, Vec3 packetCenter, Vec3 packetWidth, Vec3 avgMomentum, bool multiThread = true)
        {
            WaveFunction wf = new WaveFunction(gridSpec, latticeSpacing);

            int sx = gridSpec.SizeX;
            int sy = gridSpec.SizeY;
            int sz = gridSpec.SizeZ;

            float[][][] wfData = wf.Data;

            Complex I        = Complex.I;
            float   rootPi   = (float)Math.Sqrt(Math.PI);
            float   sigmaXSq = packetWidth.X * packetWidth.X;
            float   sigmaYSq = packetWidth.Y * packetWidth.Y;
            float   sigmaZSq = packetWidth.Z * packetWidth.Z;
            float   norm     = (float)Math.Sqrt((packetWidth.X / (rootPi * sigmaXSq)) * (packetWidth.Y / (rootPi * sigmaYSq)) * (packetWidth.Z / (rootPi * sigmaZSq)));

            TdseUtils.Misc.ForLoop(0, sz, (z) =>
            {
                float zf        = z * latticeSpacing;
                Complex expArgZ = I * zf * avgMomentum.Z - (zf - packetCenter.Z) * (zf - packetCenter.Z) / (2 * sigmaZSq);

                for (int y = 0; y < sy; y++)
                {
                    float yf         = y * latticeSpacing;
                    Complex expArgZY = expArgZ + I * yf * avgMomentum.Y - (yf - packetCenter.Y) * (yf - packetCenter.Y) / (2 * sigmaYSq);

                    float[] wfDataZY = wfData[z][y];
                    for (int x = 0; x < sx; x++)
                    {
                        float xf = x * latticeSpacing;

                        Complex expArgZYX = expArgZY + I * xf * avgMomentum.X - (xf - packetCenter.X) * (xf - packetCenter.X) / (2 * sigmaXSq);
                        Complex wfVal     = norm * Complex.Exp(expArgZYX);

                        wfDataZY[2 * x]     = wfVal.Re;
                        wfDataZY[2 * x + 1] = wfVal.Im;
                    }
                }
            }, multiThread);

            wf.Normalize();
            return(wf);
        }
示例#2
0
 /// <summary>
 /// Compares two GridSpecs by value.
 /// </summary>
 public bool ValueEquals(GridSpec that)
 {
     return((this.SizeX == that.SizeX) && (this.SizeY == that.SizeY) && (this.SizeZ == that.SizeZ));
 }
示例#3
0
 /// <summary>
 /// Copy constructor.
 /// </summary>
 public GridSpec(GridSpec src)
 {
     SizeX = src.SizeX;
     SizeY = src.SizeY;
     SizeZ = src.SizeZ;
 }
示例#4
0
 /// <summary>
 /// Constructor.
 /// </summary>
 public WaveFunction(GridSpec gridSpec, float latticeSpacing)
 {
     m_data           = TdseUtils.Misc.Allocate3DArray(gridSpec.SizeZ, gridSpec.SizeY, 2 * gridSpec.SizeX);
     m_latticeSpacing = latticeSpacing;
 }