src/qcphase.cpp

00001 /***************************************************************************
00002  *   Quantum Construct (qC++)                                                                  *
00003  *   The Quantum Physics Computational Library                                         *
00004  *   Copyright (C) 2005 by Shekhar S. Chandra                                      *
00005  *   Shekhar.Chandra@sci.monash,edu.au                                     *
00006  *                                                                         *
00007  *   This program is free software; you can redistribute it and/or modify  *
00008  *   it under the terms of the GNU General Public License as published by  *
00009  *   the Free Software Foundation; either version 2 of the License, or     *
00010  *   (at your option) any later version.                                   *
00011  *                                                                         *
00012  *   This program is distributed in the hope that it will be useful,       *
00013  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00014  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00015  *   GNU General Public License for more details.                          *
00016  *                                                                         *
00017  *   You should have received a copy of the GNU General Public License     *
00018  *   along with this program; if not, write to the                         *
00019  *   Free Software Foundation, Inc.,                                       *
00020  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00021  ***************************************************************************/
00022 /*
00023         Ver Info - QCPhase.cpp
00024         1.0.0 - Original Implementation
00025 */
00026 
00027 #include "qcphase.h"
00028 
00029 QCPhase::QCPhase(void)
00030 {
00031         disturbPosition = 0;
00032         disturbWidth = 0;
00033         disturbHeight = 0.0;
00034 }
00035 
00036 QCPhase::~QCPhase(void)
00037 {}
00038 
00039 parameterType QCPhase::constantFunction()
00040 {
00041         parameterType phase = 1.5;
00042 
00043         return phase;
00044 }
00045 
00046 parameterType QCPhase::spiralFunction(parameterType  x, parameterType y)
00047 {
00048         parameterType phase = 0.0;
00049 
00050         phase = atan2(y,x);
00051 
00052         return phase;
00053 }
00054 
00055 void QCPhase::applyUniform(QCComplexField<2> &field, parameterType  deltaX, parameterType deltaY, int x0, int y0)
00056 {
00057         parameterType x, y;
00058 
00059         for(int k = 0; k < field.noOfColumns(); k++)
00060         {
00061                 y = k*deltaY - y0;
00062                 for(int j = 0; j < field.noOfRows(); j++)
00063                 {
00064                         x = j*deltaX - x0;
00065                         field.assignElement(j,k,sqrt(norm(field.retrieveElement(j,k)))*exp(i*constantFunction()));
00066                 }
00067         }
00068 }
00069 
00070 void QCPhase::applyUniform(QCComplexField<3> &field, parameterType  deltaX, parameterType deltaY, parameterType deltaZ, int x0, int y0, int z0)
00071 {
00072         parameterType x, y, z;
00073 
00074         for(int l = 0; l < field.height(); l ++)
00075         {
00076                 z = l*deltaZ - z0;
00077                 for(int k = 0; k < field.noOfColumns(); k++)
00078                 {
00079                         y = k*deltaY - y0;
00080                         for(int j = 0; j < field.noOfRows(); j++)
00081                         {
00082                                 x = j*deltaX - x0;
00083                                 field.assignElement(j,k,l,sqrt(norm(field.retrieveElement(j,k,l)))*exp(i*constantFunction()));
00084                         }
00085                 }
00086         }
00087 }
00088 
00089 void QCPhase::applyRandom(QCComplexField<2> &field, parameterType  deltaX, parameterType deltaY, int x0, int y0)
00090 {
00091         parameterType randNo;
00092         srand(112);
00093 
00094         for(int k = 0; k < field.noOfColumns(); k++)
00095                 for(int j = 0; j < field.noOfRows(); j++)
00096                 {
00097                         randNo = (double)(rand() % 7);
00098                         field.assignElement(j,k,sqrt(norm(field.retrieveElement(j,k)))*exp(i*randNo));
00099                 }
00100 }
00101 
00102 void QCPhase::applyRandomQuadrant(QCComplexField<2> &field, parameterType deltaX, parameterType deltaY, int x0, int y0)
00103 {
00104         parameterType randNo1, randNo2, randNo;
00105         int maxRandNo = 4;
00106         srand(112);
00107 
00108         randNo1 = (double)(rand() % maxRandNo);
00109         randNo2 = (double)(rand() % maxRandNo);
00110         for(int k = 0; k < field.noOfColumns(); k++)
00111                 for(int j = 0; j < field.noOfRows(); j++)
00112                 {
00113                         if(j > field.noOfRows()/2 && k <= field.noOfColumns()/2)
00114                                 randNo = randNo1 + randNo2;
00115                         if(j > field.noOfRows()/2 && k > field.noOfColumns()/2)
00116                                 randNo = randNo1 - randNo2;
00117                         if(j < field.noOfRows()/2 && k <= field.noOfColumns()/2)
00118                                 randNo = randNo1;
00119                         if(j < field.noOfRows()/2 && k > field.noOfColumns()/2)
00120                                 randNo = randNo2;
00121                         field.assignElement(j,k,sqrt(norm(field.retrieveElement(j,k)))*exp(i*randNo));
00122                 }
00123 }
00124 
00125 void QCPhase::applyVortex(QCComplexField<2> &field, parameterType deltaX, parameterType deltaY, int x0, int y0)
00126 {
00127         parameterType x, y;
00128 
00129         for(int k = 0; k < field.noOfColumns(); k++)
00130         {
00131                 y = (k)*deltaY - y0;
00132                 for(int j = 0; j < field.noOfRows(); j++)
00133                 {
00134                         x = (j)*deltaX - x0;
00135                         field.assignElement(j,k,sqrt(norm(field.retrieveElement(j,k)))*exp(i*spiralFunction(x,y)));
00136                 }
00137         }
00138 }
00139 
00140 void QCPhase::applyVortex(QCComplexField<3> &field, parameterType  deltaX, parameterType deltaY, parameterType deltaZ, int x0, int y0, int z0)
00141 {
00142         parameterType x, y, z;
00143 
00144         for(int l = 0; l < field.height(); l ++)
00145         {
00146                 z = l*deltaZ - z0;
00147                 for(int k = 0; k < field.noOfColumns(); k++)
00148                 {
00149                         y = k*deltaY - y0;
00150                         for(int j = 0; j < field.noOfRows(); j++)
00151                         {
00152                                 x = j*deltaX - x0;
00153                                 field.assignElement(j,k,l,sqrt(norm(field.retrieveElement(j,k,l)))*exp(i*spiralFunction(x,y)));
00154                         }
00155                 }
00156         }
00157 }
00158 
00159 void QCPhase::applyVortexReverse(QCComplexField<2> &field, parameterType deltaX, parameterType deltaY, int x0, int y0)
00160 {
00161         parameterType x, y;
00162 
00163         for(int k = 0; k < field.noOfColumns(); k++)
00164         {
00165                 y = (k)*deltaY - y0;
00166                 for(int j = 0; j < field.noOfRows(); j++)
00167                 {
00168                         x = (j)*deltaX - x0;
00169                         field.assignElement(j,k,sqrt(norm(field.retrieveElement(j,k)))*exp(i*spiralFunction(x,-y)));
00170                 }
00171         }
00172 }
00173 
00174 void QCPhase::applyDisturbanceTypeI(QCComplexField<2> &field, parameterType deltaX, parameterType deltaY, int x0, int y0)
00175 {
00176         complexType height(0.1,M_PI_2/4.0);
00177 
00178         for(int k = 20; k < 45; k ++)
00179                 for(int j = 1; j < field.noOfRows()-1; j ++)
00180                         field.assignElement(j,k,sqrt(norm(field.retrieveElement(j,k)))*height);
00181 }
00182 
00183 void QCPhase::applyDisturbanceTypeII(QCComplexField<2> &field, parameterType deltaX, parameterType deltaY, int x0, int y0)
00184 {
00185         complexType height(0.0,disturbHeight);
00186         parameterType endCounter = double(disturbWidth), counter = 1.0, gradientFactor = 0.0;
00187 
00188         for(int k = disturbPosition; k < field.noOfColumns(); k ++)
00189         {
00190                 for(int j = 0; j < field.noOfRows(); j ++)
00191                 {
00192                         gradientFactor = counter/endCounter;
00193                         field.assignElement(j,k,field.retrieveElement(j,k)*exp(gradientFactor*height));
00194                 }
00195                 if(counter < endCounter)
00196                         counter ++;
00197         }
00198 }
00199 
00200 void QCPhase::applyDisturbanceTypeII(QCComplexField<3> &field, parameterType deltaX, parameterType deltaY, int x0, int y0)
00201 {
00202         complexType height(0.0,disturbHeight);
00203         parameterType endCounter = double(disturbWidth), counter = 1.0, gradientFactor = 0.0;
00204 
00205         for(int l = 0; l < field.height(); l ++)
00206                 for(int k = disturbPosition; k < field.noOfColumns(); k ++)
00207                 {
00208                         for(int j = 0; j < field.noOfRows(); j ++)
00209                         {
00210                                 gradientFactor = counter/endCounter;
00211                                 field.assignElement(j,k,l,sqrt(norm(field.retrieveElement(j,k,l)))*exp(gradientFactor*height));
00212                         }
00213                         if(counter < endCounter)
00214                                 counter ++;
00215                 }
00216 }
00217 
00218 bool QCPhase::outputPhaseFunction(QCComplexField<2> &field, const char* filename)
00219 {
00220         ofstream outFile(filename,ios::out);
00221         outFile.precision(filePrecision);
00222 
00223         if(outFile.fail())
00224         {
00225                 cerr << "File Error: " << filename << endl;
00226                 return false;
00227         }
00228         else
00229         {
00230                 for(int k = 0; k < field.noOfColumns(); k++)
00231                 {
00232                         for(int j = 0; j < field.noOfRows(); j++)
00233                                 outFile << spiralFunction(field.realPart()(j,k),field.imaginaryPart()(j,k)) << " , ";
00234                         outFile << endl;
00235                 }
00236                 return true;
00237         }
00238 }
00239 
00240 bool QCPhase::outputPhaseFunction(QCComplexField<3> &field, const char* filename)
00241 {
00242         ofstream outFile(filename,ios::out);
00243         outFile.precision(filePrecision);
00244 
00245         if(outFile.fail())
00246         {
00247                 cerr << "File Error: " << filename << endl;
00248                 return false;
00249         }
00250         else
00251         {
00252                 int l = field.height()/2;
00253                 for(int k = 0; k < field.noOfColumns(); k++)
00254                 {
00255                         for(int j = 0; j < field.noOfRows(); j++)
00256                                 outFile << spiralFunction(field.realPart()(j,k,l),field.imaginaryPart()(j,k,l)) << " , ";
00257                         outFile << endl;
00258                 }
00259                 return true;
00260         }
00261 }
00262 

Generated on Sat May 13 13:22:49 2006 for Quantum Construct (qC++) by  doxygen 1.4.6-NO