Skip to content

Commit 0d9c8d0

Browse files
author
Marion.Baumgartner
committed
changing to use using complex class for alm
1 parent 466fea5 commit 0d9c8d0

13 files changed

+4616
-4591
lines changed

Holo_Multipol/CPPOut.dat

+4,506-4,506
Large diffs are not rendered by default.

Holo_Multipol/Data.cpp

+8-7
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ void Data::readData()
1919
dataF.open(infile);
2020
if(dataF.is_open())
2121
{
22-
std::cout<<"reading file";
22+
std::cout<<"--------------------------------------------------------------- \n reading file\n";
2323
for(int i=0;i<MAXANGLES;i++)
2424
{
25-
double inNum0;
26-
double inNum1;
27-
double inNum2;
28-
double inNum3;
25+
double inNum0; // g(theta,phi)
26+
double inNum1; // theta
27+
double inNum2; //phi
28+
double inNum3; //DOmega
2929
//std::cout<<"\n read data line "<<i;
3030
this->dataF>>inNum0;
3131
//std::cout<<" entry 0 "<<inNum0;
@@ -43,6 +43,7 @@ void Data::readData()
4343
{
4444
thmax=inNum1;
4545
}
46+
//convert angles from degres to radian
4647
messg[i][1]=deg_to_rad(inNum1);
4748
messg[i][2]=deg_to_rad(inNum2);
4849
messg[i][3]=deg_to_rad(inNum3);
@@ -56,12 +57,12 @@ void Data::readData()
5657
}
5758
}else
5859
{
59-
std::cout<<"Can not open file! Will exit!";
60+
std::cout<<"Can not open file! Will exit! \n ---------------------------------------------------------------";
6061
//Throw error here!!!
6162
return;
6263

6364
}
64-
std::cout<<"read file succesfully!";
65+
std::cout<<"read file succesfully! \n ---------------------------------------------------------------";
6566
this->dataF.close();
6667
}
6768

Holo_Multipol/Data.o

200 Bytes
Binary file not shown.

Holo_Multipol/Multipole.cpp

+42-53
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
Multipole::Multipole(std::string fileName, int lmax, int isym, double ekin): Data(fileName),LMAX(lmax), ISYM(isym), k(2*M_PI*sqrt(ekin/150))
66
{
77
assert(LMAX<Multipole::MAX_COEFF);
8-
alm1.resize( LMAX/2+1, std::vector<double>());
9-
alm2.resize( LMAX/2+1, std::vector<double>());
8+
alm.resize( LMAX/2+1, std::vector<std::complex<double> >());
109
}
1110
Multipole::~Multipole()
1211
{
13-
delete alm1;
14-
delete alm2;
12+
//TODO enentiuelle leichen löschen
13+
//delete alm1;
14+
//delete alm2;
1515
}
1616

1717
const int Multipole::getLMAX()
@@ -21,9 +21,8 @@ const int Multipole::getLMAX()
2121

2222
void Multipole::multpl()
2323
{
24-
std::cout<<"\n in multipl function"<<std::endl;
25-
double dtheta=2*M_PI/180.0;
26-
double bnorm=1;
24+
std::cout<<"\n --------------------------------------------------------------- \n expanding multipole coefficients"<<std::endl;
25+
double bnorm = 1;
2726
for(int l=0;l<=LMAX;l+=2)
2827
{
2928
int il=l/2;
@@ -34,32 +33,31 @@ void Multipole::multpl()
3433
//alm2[il].push_back(std::vector<double>(il));
3534
for(int m=0;m<=l;m+=ISYM)
3635
{
37-
double rint1=0;
38-
double rint2=0;
36+
std::complex<double> int_res=0;
3937

38+
//go through all angles alm=int(g(theta,phi)*conj(Y_lm(thea,phi)) dOmega
4039
for(int i=0;i<MAXANGLES;i++)
4140
{
4241
double phi=messg[i][2];
4342
double theta=messg[i][1];
4443
double gmessg=messg[i][0];
44+
double dOmega=messg[i][3];
45+
46+
//std::cout<<"i, phi, theta, g "<<i<<" "<<phi<<","<<theta<<", "<<gmessg<<std::endl;
47+
int_res+=gmessg*std::conj(boost::math::spherical_harmonic<double>(l, m, theta, phi))*dOmega;
4548

46-
std::cout<<"i, phi, theta, g "<<i<<" "<<phi<<","<<theta<<", "<<gmessg<<std::endl;
47-
//norm=sqrt(4.0*M_PI/(2.0*l+1.0))
48-
rint1+=vorz(m)*gmessg*boost::math::spherical_harmonic_r<double>(l, (-1)*m, theta, phi)*sin(theta)*messg[i][3];
4949

50-
rint2+=vorz(m)*gmessg*boost::math::spherical_harmonic_i<double>(l, (-1)*m, theta, phi)*sin(theta)*messg[i][3];
5150
//std::cout<<"real, imag "<<rint1<<", "<<rint2<<"\n";
5251

5352

5453
}
55-
if(l==0 && m==0 && rint1>0.001)
54+
if(l==0 && m==0 && std::real(int_res)>0.001)
5655
{
57-
bnorm=rint1*dtheta;
56+
bnorm=std::real(int_res);
5857
std::cout<<"bnorm="<<bnorm<<std::endl;
5958
}
60-
alm1[il].push_back(rint1*dtheta/bnorm);
61-
alm2[il].push_back(rint2*dtheta/bnorm);
62-
std::cout<<l<<" "<<m<<" "<<alm1[il][m]<<std::endl;//<<" "<<alm2[il][m]<<std::endl;
59+
alm[il].push_back(int_res/ bnorm);
60+
std::cout<<l<<" "<<m<<" "<<alm[il][m]<<std::endl;//<<" "<<alm2[il][m]<<std::endl;
6361
}
6462
//std::cout<<std::endl;
6563
}
@@ -69,42 +67,27 @@ std::cout<<"alm: (l,m,real,imag)\n";
6967

7068
void Multipole::expans()
7169
{
72-
std::cout<<"in expans function\n";
70+
std::cout<<"\n --------------------------------------------------------------- \n expanding function according to calculated coefficients \n";
71+
calc.clear();
7372
for(int i=0;i<MAXANGLES;i++)
7473
{
75-
//std::cout<<"i "<<i<<std::endl;
74+
std::cout<<"i "<<i<<std::endl;
7675
double theta=messg[i][1];
7776
double phi=messg[i][2];
78-
double suml=0;
79-
//std::cout<<"(theta, phi)=("<<theta<<", "<<phi<<")\n";
80-
for (int l=0;l<LMAX;l+=2)
81-
{
82-
//std::cout<<"l is "<<l<<std::endl;
83-
int il=l/2;
84-
suml+=alm1[il][0]*boost::math::spherical_harmonic_r <double> (l,0,theta,phi); //m=0
85-
//std::cout<<"sum"<<sum<<std::endl;
86-
for(int m=1;m<=l;m++)
87-
{
88-
//std::cout<<"in seccond for loop!";
89-
//calculate RE(sum_m A_lm*Y_lm)=sum_m RE(A_lm)*RE(Y_lm)-IM(A_lm)*IM(Y_lm)
90-
double real=alm1[il][m]*boost::math::spherical_harmonic_r <double> (l,m,theta, phi); //imaginary part
91-
double imag=alm2[il][m]*boost::math::spherical_harmonic_i <double> (l,m,theta, phi); //real part
92-
suml+=2*(real-imag); //
93-
//std::cout<<"sum, i"<<sum<<", "<<l<<std::endl;
94-
}
95-
}
77+
double g_theta_phi=intencity(theta,phi);
9678
std::vector<double> temp;
97-
std::cout<<suml<<" "<<180/M_PI*theta<<" "<<180/M_PI*phi<<std::endl;
98-
temp.push_back(suml);
79+
std::cout<<g_theta_phi<<" "<<180/M_PI*theta<<" "<<180/M_PI*phi<<std::endl;
80+
temp.push_back(g_theta_phi);
9981
temp.push_back(theta);
10082
temp.push_back(phi);//TODO if time: make this call better -> works for a start
83+
10184
calc.push_back(temp);
10285
}
103-
std::cout<<"calc:(suml,theta,phi)\n";
86+
std::cout<<"calc:(g(theat,phi),theta,phi)\n";
10487
}
10588

10689

107-
void Multipole::holorad(double alpha, double beta)
90+
/*void Multipole::holorad(double alpha, double beta)
10891
{
10992
double r=0;
11093
double kr=0;
@@ -243,25 +226,31 @@ void Multipole::smooth(double grid)
243226
}
244227
}
245228
}
246-
}*/
229+
}*--->/
247230
}
248231
249232
250233
/*-------------------Private--------------------------------------*/
251-
double Multipole::innerSumm(int l, double alpha, double beta)
234+
double Multipole::intencity(double theta, double phi)
252235
{
253-
double summ=0;
254-
int il=l/2;
255-
for(int m=ISYM;m<=l;m+=ISYM)
236+
double summ0=0;
237+
std::complex<double> summ (0,0);
238+
for(int l=0; l<=LMAX; l+=2)
239+
{
240+
int m=0;
241+
summ0+=std::real(alm[l/2][m]*boost::math::spherical_harmonic<double> (l,m,theta,phi));
242+
m+=ISYM;
243+
for(;m<=l;m+=ISYM)
256244
{
257-
double real=alm1[il][m]*boost::math::spherical_harmonic_r <double> (l,m,alpha, beta); //imaginary part
258-
double imag=alm2[il][m]*boost::math::spherical_harmonic_i <double> (l,m,alpha, beta);
259-
summ+=2*(real-imag);
245+
summ+=alm[l/2][m]*boost::math::spherical_harmonic<double> (l,m,theta,phi);
260246
}
261-
return summ;
247+
}
248+
249+
250+
return summ0+2*std::real(summ);
262251
}
263252

264-
void Multipole::printAlm()
253+
/*void Multipole::printAlm()
265254
{
266255
for(unsigned int i=0;i<alm1.max_size();i++)
267256
{
@@ -343,4 +332,4 @@ double Multipole::calcphi(double x, double y)
343332
}
344333
}
345334
return -1;
346-
}
335+
}*/

Holo_Multipol/Multipole.h

+21-12
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#include <cmath>
66
#include <vector>
77
#include <assert.h>
8+
#include <complex>
9+
810
#include "Data.h"
911
#include <boost/math/special_functions/legendre.hpp>
1012
#include <boost/math/special_functions/spherical_harmonic.hpp>
@@ -61,41 +63,41 @@ class Multipole:public Data //:public Data //this class now has acces to all the
6163
*The radial grid is in angstrom with 0.1\AA spacing
6264
*Function is adopted from the fortran Program by Juerg Osterwalde writen in 1993
6365
*/
64-
void holorad(double, double);
66+
//void holorad(double, double);
6567

6668
/**
6769
*Calculates a two dimensional image of the electron wave field near the photoemitter.
6870
*Equation (3) from A.Stucke et al. (1992) is used.
6971
*Ther radial grid is in angstroem with grid spacing in Angstroe
7072
*Function is adopted from the fortran Program by Juerg Osterwalde writen in 1993
7173
*/
72-
void doyzimage(double grid, int xyz);
74+
//void doyzimage(double grid, int xyz);
7375

7476
/**
7577
*Calculates a two-dimensional image of the electron wave field near the photoemitter.
7678
*Equation (3) from A.Stucke et al. (1992) is used.
7779
*the radial grid is in angstroem with grid angstroem spacing.
7880
*Function is adapted from the fortran program by Juerg Osterwalder written in 6.7.93
7981
*/
80-
void doxyzimage(double grid);
82+
//void doxyzimage(double grid);
8183

8284
/**
8385
*Takes a 2D image array and maps it into a 2d image array of integer numbers ranging from 0 to 255.
8486
*Function makes input in to 'image program more convenient for mac.
8587
*Calculates r * |img(xy)|**2 to produce images.
8688
*adapted from fortran program by Juerg Osterwalder, universite de fribourg, 12.7.93
8789
*/
88-
void scaleimage(double grid);
90+
//void scaleimage(double grid);
8991

9092
/**
9193
*Function performes a gausian smoothing of the image function
9294
*/
93-
void smooth(double grid);
95+
//void smooth(double grid);
9496

9597
/**
9698
*print the real coefficients that were calculated within this program
9799
*/
98-
void printAlm();
100+
//void printAlm();
99101

100102
//=======================================================================================//
101103
private:
@@ -104,8 +106,8 @@ class Multipole:public Data //:public Data //this class now has acces to all the
104106

105107
const double k; //2*pi*sqrt(ekin/150)
106108

107-
std::vector<std::vector<double> > alm1; //real expansion coefficients
108-
std::vector<std::vector<double> > alm2; //imaginary expansion coefficients
109+
std::vector<std::vector<std::complex<double> > > alm; //expansion coefficients
110+
109111
//To add elements to the two dimensional vector use alm.push_back(row)
110112
//where row is a vector of double type containing the data that belonges in to this row
111113
//std::vector<double> gCalc; take this vector from the base clas
@@ -114,23 +116,30 @@ class Multipole:public Data //:public Data //this class now has acces to all the
114116
*calculate (-1)^exp with exp in [1,2,3,4,...]
115117
*@param exp is a positiv or negative integer
116118
*/
117-
int vorz(int);
119+
//int vorz(int);
118120

119121

120-
inline double innerSumm(int l, double alpha, double beta);
122+
/**
123+
*calculate the intencity g(theta,phi) at a given point theta, phi using
124+
* g(theta,phi)=sum_{0<=l<=l_max}[A_l0*Y_l0(theta,phi))+2*Re(sum_{0<m<=l}A_lm*Y_lm(theta,phi))]
125+
126+
*@param theta polar angle
127+
*@param phi azimutal angle
128+
*/
129+
inline double intencity(double theta, double phi);
121130

122131
/**
123132
*calculation of the proper polar angle within the yz-plane.
124133
*All polar angles are positive; negative y values should be accounted for by adding PI to the value of phi.
125134
*@return polar angle in radian (double precission) -> if the function returnes -1 there calculation was corrupded or the function is wrong
126135
*/
127-
double calcth(double y, double z);
136+
//double calcth(double y, double z);
128137

129138
/**
130139
*calculation of the proper azimutal angle within the yz-plane.
131140
*@return azimutal angle in radian (double precission) -> if the function returnes -1 there calculation was corrupded or the function is wrong
132141
*/
133-
double calcphi(double x, double y);
142+
//double calcphi(double x, double y);
134143

135144
static const int MAX_COEFF=100;//100 is the maximum amunt of coefficients that can be calculated
136145
};

Holo_Multipol/Multipole.o

-227 KB
Binary file not shown.

Holo_Multipol/griding.py

+12-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import griding2 as gr2
1919

2020

21+
2122
class Grid:
2223
#Global variables
2324
def __init__(self, gfile="oldinp.itp", nfile="newinp.itp"):
@@ -256,7 +257,7 @@ def cPPOut(self):
256257
with open(self.outputfile, 'w\n') as outFile:
257258
#outFile.write("#g(theta, phi), theta, phi, dphi (values are in degrees)\n")
258259
for i in range(len(self.grid)):
259-
value=str("%f %f %f %f" %(self.grid[i][3],self.grid[i][0],self.grid[i][1],self.grid[i][2]))
260+
value=str("%f %f %f %f" %(self.grid[i][3],self.grid[i][0],self.grid[i][1],self.grid[i][5],))
260261
#print value
261262
outFile.write(value+"\n")
262263
# outFile.write("dtheta=%f"%self.dtheta)
@@ -322,12 +323,21 @@ def main():
322323
newGrid.fitNewToOldGrid()
323324
newGrid.writeGrid("temp.dat")
324325
#newGrid.plotGrid()
326+
newGrid.cPPOut()
327+
print"----------------------------------------------------"
328+
print "writing output for C++ code to ",newGrid.outputfile
329+
print"----------------------------------------------------"
325330

326-
calc = gr2.Calc(newGrid.grid,50)
331+
calc = gr2.Calc(newGrid.grid,10)
327332

328333
calc.multi()
329334
calc.expand()
330335
calc.writeData("calc.dat")
336+
337+
338+
#print('\a')
339+
#sys.stdout.write('\a')
340+
#sys.stdout.flush()
331341
"""s=-1
332342
while True:
333343
s = int(raw_input('Type 0 for Fortan output; 1 for c++ output '))

0 commit comments

Comments
 (0)