Вот код, который я пишу, по теме см. конец, GenerateAll() и GenerateQuarks(). Сам цикл ещё даже цикл не вставил.
/*
* File: main.cpp
* Author: ubuntu
*
* Created on 29 Август 2010 г., 22:05
*/
#include <cstdlib>
using namespace std;
/*
*
*/
#include <iostream>
#include <float.h>
#include <math.h>
#include <memory.h>
#include <assert.h>
#include <stdlib.h>
#define STDRAND (double)rand()/(double)RAND_MAX
#include "math.cpp"
using namespace std;
// quark type defenition
#define QUARK_VALENCE 0
#define QUARK_DIQUARK 1
#define QUARK_SEA 2
#define QUARK_ANTISEA 3
inline double SqOf(double x) {return x*x;};
typedef struct Quark {
int used; // flag is true if quark is already included in the string formation
double x, y; // quark position
int type; // quark type
double z; // momentum fraction
} Quark;
typedef struct Nucleon {
double x, y; // Parton coordinates
Quark *base; // array of quarks
int count; // number of quarks
} Nucleon;
typedef struct Dipole {
Quark *q1,*q2; // QUARK_SEA-QUARK_ANTISEA or QUARK_VALENCE-QUARK_DIQUARK
bool used; // use the flag if this is a tip of string
} Dipole;
typedef struct String {
Quark *q1, *q2; // two tips of string
double x, y; // string coordinates
double ymin, ymax; // rapidity borders
String *next; // next string in the cluster
int noform; // it is equal 1 if the string can not be formed
} String;
class NucleonCollider
{
public:
double En; // the enegy of colliding nucleons
double b_min, b_max; // impact parameter
double ymin, ymax, ystep; // rapidity interested
double rmax; // confinement radius
double a_s; // constant
double lambda;
double xA,yA,xB,yB; // coordinates of the nucleon
double a; // size of the proton-proton square
void CalcProbMatrix(double *mat,Dipole dipA[],Dipole dipB[],int dipsA,int dipsB);
};
void NucleonCollider::CalcProbMatrix(double *mat,Dipole dipA[],Dipole dipB[],int dipsA,int dipsB) { //(ready)
for (int i=0;i<dipsA;i++) {
for (int j=0;j<dipsB;j++) {
double w1,w2,w3,w4;
w1=SqOf(dipA[i].q1->x-dipB[j].q2->x)+SqOf(dipA[i].q1->y-dipB[j].q2->y);
w2=SqOf(dipA[i].q2->x-dipB[j].q1->x)+SqOf(dipA[i].q2->y-dipB[j].q1->y);
w3=SqOf(dipA[i].q1->x-dipB[j].q1->x)+SqOf(dipA[i].q1->y-dipB[j].q1->y);
w4=SqOf(dipA[i].q2->x-dipB[j].q2->x)+SqOf(dipA[i].q2->y-dipB[j].q2->y);
//mat[i][j]=a_s*a_s/8*SqOf(log(w1*w2/w3/w4));
//cout<<rmax;
double t;
t=rmax;
mat[i,j]=a_s*a_s/2*SqOf((BESSK0(sqrt(w1)/t)+BESSK0(sqrt(w2)/t)-BESSK0(sqrt(w3)/t)-BESSK0(sqrt(w4)/t)));
}
}
}
class QuarkPr
{
public:
QuarkPr();
virtual ~QuarkPr();
Quark *base;
unsigned int count;
unsigned int maxN;
void QgenXYZ(Quark *base, unsigned int count);
protected:
private:
unsigned int *v;
};
QuarkPr::QuarkPr()
{
cout<<"Конструкция QuarkPr"<<endl;
maxN=100;
v=new unsigned int[maxN];
};
QuarkPr::~QuarkPr()
{
cout<<"деструкция QuarkPr"<<endl;
delete v;
};
void QuarkPr::QgenXYZ(Quark *base,unsigned int count){ //cтандартный метод!!!!
if (count>maxN) {
maxN=count;
delete[] v;
v=new unsigned int[maxN];
};
double sumx=0,sumy=0;
double rho,sum2=0,t,A_N;
t=floor(STDRAND*3);
if (t==0.0) A_N=2.5; else A_N=1.5;
A_N=1.5;
do {
sum2=0;
for (unsigned int j=0;j<count-1;j++)
{
v[j]=STDRAND;
base[j].z=SqOf(v[j]);
sum2+=base[j].z;
}
t=STDRAND;
if (sum2<=1.0) {
base[count-1].z=1.0-sum2;
rho=pow(1.0-sum2,A_N);
}
else rho=0;
} while (t>rho);
for (unsigned int j=0;j<count;j++) {
Stdgauss(base[j].x,base[j].y);
sumx+=base[j].z*base[j].x;
sumy+=base[j].z*base[j].y;
}
for (unsigned int j=0;j<count;j++) {
base[j].x-=sumx;
base[j].y-=sumy;
}
double a,n=count/2;
if (A_N==1.5) for (unsigned int j=0;j<count;j++) {
a=sqrt( (2*n-1)*(n*n+6*n+12)/(2*n*(n+2)*(n+3)) );
base[j].x/=a;
base[j].y/=a;
}
else for (unsigned int j=0;j<count;j++) {
a=sqrt( (2*n-1)*(n*n+8*n+24)/(2*n*(n+3)*(n+4)) );
base[j].x/=a;
base[j].y/=a;
}
}
class Generator:public NucleonCollider
{
public:
Generator();
virtual ~Generator();
void GenerateAll();
Dipole *dipA,*dipB;
double *dipProbMatrix;
protected:
unsigned int mA,mB;
unsigned int mAmax,mBmax;
void Generate_mA_mB();
void GenerateQuarks();
Quark *qA, *qB;
private:
void ApplyType(Quark *base,unsigned int m);
double *fi;
QuarkPr qpA,qpB; //generators of the impactB and momentum fraction
};
Generator::Generator()
{
//конструктор
cout<<"конструкция Generator"<<endl;
mAmax=100;
mBmax=100;
qA=new Quark[2*mAmax];
qB=new Quark[2*mBmax];
dipA=new Dipole[mAmax];
dipB=new Dipole[mBmax];
dipProbMatrix=new double[mAmax*mBmax];
};
Generator::~Generator()
{
cout<<"деструкция"<<endl;
//деструктор
delete[] qA;
delete[] qB;
delete[] dipA;
delete[] dipB;
delete[] dipProbMatrix;
cout<<"деструкция1"<<endl;
}
void Generator::Generate_mA_mB()
{
cout<<"генерируем mA:";
mA=genPoissonm(lambda);
cout<<"mA="<<mA<<endl;
cout<<"генерируем mB:";
mB=genPoissonm(lambda);
cout<<"mB="<<mB<<endl;
}
void Generator::ApplyType(Quark *base,unsigned int m)
{
for (unsigned int i=0;i<m;i++) {
base[2*i].type=QUARK_SEA;
base[2*i+1].type=QUARK_ANTISEA;
};
base[2*m-1-1].type=QUARK_VALENCE;
base[2*m-1].type=QUARK_DIQUARK;
}
void Generator::GenerateQuarks()
{
if (mA>mAmax) {
mAmax=mA+1;
delete[] qA;
qA=new Quark[mAmax];
};
if (mB>mBmax) {
mBmax=mB+1;
delete[] qB;
qB=new Quark[mBmax];
};
ApplyType(qA,mA);
ApplyType(qB,mB);
}
void Generator::GenerateAll()
{
cout<<"генерируем все"<<endl;
// geometric part
xA=STDRAND*a;
xB=STDRAND*a;
yA=STDRAND*a;
yB=STDRAND*a;
Generate_mA_mB(); //генерируем количество кварк-антикварковых пар
unsigned int NA=2*mA;
unsigned int NB=2*mB,i,k;
for (i=0;i<NA;i++) {
qA[i].x+=xA;
qA[i].y+=yA;
};
for (i=0;i<NB;i++) {
qB[i].x+=xB;
qB[i].y+=yB;
}
//processing the nucleon
GenerateQuarks(); //генерируем кварки и присваиваем им типы
/*
qpA.QgenXYZ(qA,NA); //we generate x,y and momentum fraction
qpB.QgenXYZ(qB,NB);
//processing dipoles
if (mA>mAmax) {
delete[] dipA;
mAmax=mA;
dipA=new Dipole[mAmax];
delete[] dipProbMatrix;
dipProbMatrix=new double[mAmax*mBmax];
}
if (mB>mBmax) {
delete[] dipB;
mBmax=mB;
dipB=new Dipole[mBmax];
delete[] dipProbMatrix;
dipProbMatrix=new double[mAmax*mBmax];
}
k=0;
for (i=0;i<mA;i++) {
dipA[k].q1=&qA[i*2];
dipA[k].q2=&qA[i*2+1];
k++;
}
double ndipsA=k;
k=0;
for (i=0;i<mB;i++) {
dipB[k].q1=&qB[i*2];
dipB[k].q2=&qB[i*2+1];
k++;
}
double ndipsB=k;
CalcProbMatrix(dipProbMatrix,dipA,dipB,ndipsA,ndipsB);
*/
}
int main(int argc, char** argv) {
Generator gen;
gen.lambda=1000;
gen.GenerateAll();
return 0;
}
разобрался, проблему вызывал другой участок кода.
1. так делать можно.
2. проверять нужно весь код.