⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 state.h

📁 使用量子轨道方法计算量子主方程的C++库
💻 H
📖 第 1 页 / 共 2 页
字号:
//   State.h -*- C++ -*- State algebra in Hilbert space.//     //   Copyright (C) 1995  Todd Brun and Ruediger Schack//   //   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., 675 Mass Ave, Cambridge, MA 02139, USA.////   ----------------------------------------------------------------------//   If you improve the code or make additions to it, or if you have//   comments or suggestions, please contact us:////   Dr. Todd Brun			        Tel    +44 (0)171 775 3292//   Department of Physics                      FAX    +44 (0)181 981 9465//   Queen Mary and Westfield College           email  t.brun@qmw.ac.uk//   Mile End Road, London E1 4NS, UK////   Dr. Ruediger Schack                        Tel    +44 (0)1784 443097//   Department of Mathematics                  FAX    +44 (0)1784 430766//   Royal Holloway, University of London       email  r.schack@rhbnc.ac.uk//   Egham, Surrey TW20 0EX, UK/////////////////////////////////////////////////////////////////////////////#ifndef _State_hhh#define _State_hhh 1#include "Complex.h"enum FreedomType{ ALL, FIELD, SPIN, ATOM };// FreedomType lists the different types of physical systems specifically// recognized by this program; more may be added if necessary.// FIELD is an oscillator degree of freedom, which is described in the//   Fock state or Excited Coherent State basis;// SPIN is a spin 1/2 or two-level atom;// ATOM is an atom or N-level system;// ALL leaves the physical type of system unspecified.// Note that certain member functions will only work for degrees of freedom// of a particular type.enum ImaginaryUnit{ IMAGINARY_UNIT, MINUS_IMAGINARY_UNIT };const ImaginaryUnit IM = IMAGINARY_UNIT;const ImaginaryUnit M_IM = MINUS_IMAGINARY_UNIT;// For efficiency, special routines have been included allowing States// and Operators to be multiplied by i and -i without invoking the full// Complex arithmetic.  Note that multiplication by ImaginaryUnit is// define ONLY for States and Operators; 3*IM is not a legal// expression.#ifndef NON_GNU_PROTOTYPE  class PrimaryOperator;#else  extern class PrimaryOperator;#endif// I/O functions for FreedomTypeostream& operator<<( ostream&, FreedomType );istream& operator>>( istream&, FreedomType& );class State{// The State class represents quantum states in a particular choice of// Hilbert space; this can include varying numbers of physical degrees// of freedom, described by varying numbers of basis states.public:						// public functions// constructors and destructors  State();    // Default constructor; produces a State of size 0.  State(const State& state);    // Copy constructor.  State(int n, FreedomType form=FIELD);    // Produces a single degree-of-freedom State with n basis states;    // all basis states have amplitude 0 except the ground state,    // which has amplitude 1; form gives the FreedomType of the State    // (default is FIELD).  State(int n, int* dimensions, FreedomType* forms);    // Multiple degree of freedom ground State.  n gives the number of    // degrees of freedom; dimensions is an array of n integers, which    // specify the number of basis states to allocate for each degree    // of freedom; forms is an array of n FreedomTypes, giving the    // physical type of each degree of freedom.  The basis of the full    // n-freedom state is given by the products of the basis states of    // the n freedoms; all have amplitude 0 except for the ground state.  State(int n, Complex* elements, FreedomType form=FIELD);    // Produces a one degree-of-freedom State with n basis    // states.  elements is an array of n Complex numbers, representing    // the amplitudes of the n basis states; form gives the FreedomType    // of the State (default is FIELD).  State(int n, int nstate, FreedomType form=FIELD);	// Fock state    // Produces a single degree-of-freedom State with n basis states;    // all basis states have amplitude 0 except state number nstate,    // which has amplitude 1; form gives the FreedomType of the State    // (default is FIELD).  State(int n, Complex alpha, FreedomType form=FIELD);	// Coherent state    // Produces a one degree-of-freedom State with n basis    // states in a coherent state given by the Complex number alpha.    // The State is represented in a Fock (number) state basis.    // form gives the FreedomType of the State (default is FIELD).  State(int n, int nstate, Complex alpha, FreedomType form=FIELD);    // Excited coherent state.  Produces a single degree-of-freedom State    // with n basis states.  Basis state number nstate has amplitude 1,    // all others have amplitude 0, and the state is in the excited coherent    // state or displaced Fock state basis, centered at alpha in phase space.    // form gives the FreedomType of the State (default is FIELD).  State(int n, State* stateList);		// Product state    // Produces an n degree-of-freedom state.  stateList is an array of    // n one-freedom states.  The n-freedom state will be produced in a    // product state of the n states in stateList.  The FreedomTypes and    // dimensions of the different freedoms of the n-freedom state will    // match those of the one-freedom states in stateList.  ~State();					// destructor// public functions used by constructors and destructors  void fock(int n, int nstate);			// create a Fock state  void coherent(int n, Complex alpha);		// create a Coherent state  void productState(int n, State* stateList);	// create a product state// Member arithmetic operations  inline Complex& operator[](int n) {	        // subscript operator; gives     if( nSkip != 1 )				// access to the amplitude       return myPointer[nSkip*n];		// of the nth basis state     else					// Note that this amplitude       return myPointer[n];			// can be changed as well as  };						// read.  Usage: psi[n]						// Note the presence of nSkip;						// this is part of the						// SkipVector structure, used						// for multiple freedom states  Complex elem(const int*) const;    // MultiDim subscripting; takes as an argument an array of integers    // of length equal to the number of degrees of freedom.  Returns    // the amplitude of the corresponding basis state.  Note that this    // subscripting is read-only.  Usage: psi.elem(n_array)  Complex& operator[](int*);    // same as elem (above), but also permits the amplitudes to be    // changed.  Usage:  psi[n_array]  State& operator=(const State&);		// assignment  State& operator=(int);    // zero assignment; enables one to type psi=0 to set all amplitudes    // to 0.  Gives an error for any int other than 0.  Complex operator*(const State&) const;	// inner product  State& operator*=(const Complex&);		// multiply by Complex scalar  State& operator*=(double);			// multiply by real scalar  State& operator*=(ImaginaryUnit);		// multiply by ImaginaryUnit  State& operator+=(const State&);		// add a State  State& operator-=(const State&);		// subtract State// Friend arithmetic operations  friend State operator*(const Complex&, const State&);    // multiply a State by a Complex scalar:  z*psi  friend State operator*(const State&, const Complex&);    // multiply a State by a Complex scalar (other order): psi*z  friend State operator*(double, const State&);    // multiply a State by a real scalar:  x*psi  friend State operator*(const State&, double);    // multiply a State by a real scalar (other order):  psi*x  friend State operator*(ImaginaryUnit, const State&);    // multiply a State by an ImaginaryUnit (i or -i)  friend State operator*(const State&, ImaginaryUnit);    // multiply a State by an ImaginaryUnit (i or -i) (other order)  friend State operator+(const State&, const State&);    // add two States  friend State operator-(const State&, const State&);    // subtract one State from another  friend State operator+(const State&);		// unary +  friend State operator-(const State&);		// unary -// Friend I/O operations  friend ostream& operator<<( ostream&, const State&);    // outputs a state in a standard ASCII form.  This can be used to

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -