Changeset cc9c36
- Timestamp:
- Apr 22, 2008, 12:29:35 PM (17 years ago)
- Children:
- 9bdd86
- Parents:
- 87b8ed
- Location:
- pcp/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
pcp/src/perturbed.c
r87b8ed rcc9c36 3059 3059 fftw_real *sigma_real[NDIM_NDIM]; 3060 3060 double sigma,Sigma; 3061 int it, ion, in, dex, g, Index, i; 3061 double x[NDIM]; 3062 int it, g, ion, in, dex, Index, i, j, d; 3063 int n[NDIM]; 3062 3064 int *N = Lev0->Plan0.plan->N; 3063 3065 //const double FFTfactor = 1.;///Lev0->MaxN; … … 3305 3307 3306 3308 3307 /** Calculates the chemical shielding tensor at the positions of the nuclei. 3308 * The chemical shielding tensor at position R is defined as the proportionality factor between the induced and 3309 * the externally applied field. 3309 /** Calculates the magnetic moment at the positions of the nuclei. 3310 * The magnetic moment at position R is defined as 3310 3311 * \f[ 3311 * \sigma_{ij} (R) = \frac{\delta B_j^{ind} (R)}{\delta B_i^{ext}} 3312 * = \frac{\mu_0}{4 \pi} \int d^3 r' \left ( \frac{r'-r}{| r' - r |^3} \times J_i (r') \right )_j 3312 * m_{ij} (R) = \frac{1}{2} \int d^3 r' \left ( (r'-R) \times J_i (r') \right )_j 3313 3313 * \f] 3314 3314 * One after another for each nuclear position is the tensor evaluated and the result printed … … 3316 3316 * \param *P Problem at hand 3317 3317 * \sa CalculateMagneticSusceptibility() - similar calculation, yet without translation to ion centers. 3318 * \warning This routine is out-dated due to being numerically unstable because of the singularity which is not3319 * considered carefully, recommendend replacement is CalculateChemicalShieldingByReciprocalCurrentDensity().3320 3318 */ 3321 void Calculate ChemicalShielding(struct Problem *P)3319 void CalculateMagneticMoment(struct Problem *P) 3322 3320 { 3323 3321 struct RunStruct *R = &P->R; … … 3326 3324 struct Density *Dens0 = R->Lev0->Dens; 3327 3325 struct Ions *I = &P->Ion; 3328 double sigma[NDIM*NDIM],Sigma[NDIM*NDIM];3326 double moment[NDIM*NDIM],Moment[NDIM*NDIM]; 3329 3327 fftw_real *CurrentDensity[NDIM*NDIM]; 3330 3328 int it, ion, in, dex, i0, n[NDIM], n0, i;//, *NUp; 3331 3329 double r[NDIM], fac[NDIM], X[NDIM]; 3332 3330 const double discrete_factor = Lat->Volume/Lev0->MaxN; 3333 double eta, delta_ sigma, S, A, iso;3331 double eta, delta_moment, S, A, iso; 3334 3332 const int myPE = P->Par.me_comm_ST_Psi; 3335 3333 int N[NDIM]; … … 3338 3336 N[2] = Lev0->Plan0.plan->N[2]; 3339 3337 const int N0 = Lev0->Plan0.plan->local_nx; 3340 FILE * SigmaFile;3341 char suffix sigma[255];3338 FILE *MomentFile; 3339 char suffixmoment[255]; 3342 3340 time_t seconds; 3343 3341 time(&seconds); // get current time 3344 3342 3343 if(P->Call.out[NormalOut]) fprintf(stderr,"(%i) Integrating current density to evaluate magnetic moment\n", P->Par.me); 3344 3345 3345 // set pointers onto current density 3346 3346 CurrentDensity[0] = (fftw_real *) Dens0->DensityArray[CurrentDensity0]; … … 3357 3357 for (it=0; it < I->Max_Types; it++) { // integration over all types 3358 3358 for (ion=0; ion < I->I[it].Max_IonsOfType; ion++) { // and each ion of type 3359 if (P->Call.out[ValueOut]) fprintf(stderr,"(%i) Shielding Tensor for Ion %i of element %s \\sigma_ij = \n",P->Par.me, ion, I->I[it].Name);3359 if (P->Call.out[ValueOut]) fprintf(stderr,"(%i) Magnetic dipole moment Tensor for Ion %i of element %s \\moment_ij = \n",P->Par.me, ion, I->I[it].Name); 3360 3360 for (in=0; in<NDIM; in++) {// index i of vector component in integrand 3361 3361 for (dex=0; dex<NDIM; dex++) { // index j of B component derivation in current density tensor 3362 sigma[in+dex*NDIM] = 0.;3362 moment[in+dex*NDIM] = 0.; 3363 3363 3364 3364 for(n0=0;n0<N0;n0++) // do the integration over real space … … 3373 3373 i0 = n[2]+N[2]*(n[1]+N[1]*(n0)); // the index of current density must match LocalSizeR! 3374 3374 //z = MinImageConv(Lat,r, I->I[it].R[NDIM*ion],in); // "in" always is missing third component in cross product 3375 sigma[in+dex*NDIM] += (X[cross(in,0)] * CurrentDensity[dex*NDIM+cross(in,1)][i0] - X[cross(in,2)] * CurrentDensity[dex*NDIM+cross(in,3)][i0]);3375 moment[in+dex*NDIM] += (X[cross(in,0)] * CurrentDensity[dex*NDIM+cross(in,1)][i0] - X[cross(in,2)] * CurrentDensity[dex*NDIM+cross(in,3)][i0]); 3376 3376 //if (it == 0 && ion == 0) fprintf(stderr,"(%i) moment[%i][%i] += (%e * %e - %e * %e) = %e\n", P->Par.me, in, dex, x,CurrentDensity[dex*NDIM+cross(in,1)][i0],y,CurrentDensity[dex*NDIM+cross(in,3)][i0],moment[in+dex*NDIM]); 3377 3377 } 3378 sigma[in+dex*NDIM] *= -mu0*discrete_factor/(4.*PI); // due to summation instead of integration 3379 MPI_Allreduce ( &sigma[in+dex*NDIM], &Sigma[in+dex*NDIM], 1, MPI_DOUBLE, MPI_SUM, P->Par.comm_ST_Psi); // sum "LocalSize to TotalSize" 3380 I->I[it].sigma[ion][in+dex*NDIM] = Sigma[in+dex*NDIM]; 3381 if (P->Call.out[ValueOut]) fprintf(stderr," %e", Sigma[in+dex*NDIM]); 3378 //moment[in+dex*NDIM] *= -mu0*discrete_factor/(4.*PI); // due to summation instead of integration 3379 moment[in+dex*NDIM] *= 1./2.*discrete_factor; // due to summation instead of integration 3380 MPI_Allreduce ( &moment[in+dex*NDIM], &Moment[in+dex*NDIM], 1, MPI_DOUBLE, MPI_SUM, P->Par.comm_ST_Psi); // sum "LocalSize to TotalSize" 3381 I->I[it].moment[ion][in+dex*NDIM] = Moment[in+dex*NDIM]; 3382 if (P->Call.out[ValueOut]) fprintf(stderr," %e", Moment[in+dex*NDIM]); 3382 3383 } 3383 3384 if (P->Call.out[ValueOut]) fprintf(stderr,"\n"); … … 3386 3387 for (in=0;in<NDIM;in++) 3387 3388 for (dex=0;dex<NDIM;dex++) 3388 gsl_matrix_complex_set(H,in,dex,gsl_complex_rect(( Sigma[in+dex*NDIM]+Sigma[dex+in*NDIM])/2.,0));3389 gsl_matrix_complex_set(H,in,dex,gsl_complex_rect((Moment[in+dex*NDIM]+Moment[dex+in*NDIM])/2.,0)); 3389 3390 // output tensor to file 3390 3391 if (P->Par.me == 0) { 3391 sprintf(&suffix sigma[0], ".sigma_i%i_%s.L%i.csv", ion, I->I[it].Symbol, Lev0->LevelNo);3392 OpenFile(P, & SigmaFile, suffixsigma, "a", P->Call.out[ReadOut]);3393 fprintf( SigmaFile,"# chemical shielding tensor sigma[01,02,03,10,11,12,20,21,22], seed %i, config %s, run on %s", R->Seed, P->Files.default_path, ctime(&seconds));3394 fprintf( SigmaFile,"%lg\t", P->Lat.ECut/(Lat->LevelSizes[0]*Lat->LevelSizes[0]));3392 sprintf(&suffixmoment[0], ".moment_i%i_%s.L%i.csv", ion, I->I[it].Symbol, Lev0->LevelNo); 3393 OpenFile(P, &MomentFile, suffixmoment, "a", P->Call.out[ReadOut]); 3394 fprintf(MomentFile,"# magnetic tensor moment[01,02,03,10,11,12,20,21,22], seed %i, config %s, run on %s", R->Seed, P->Files.default_path, ctime(&seconds)); 3395 fprintf(MomentFile,"%lg\t", Lev0->ECut/4.); // ECut is in Rydberg 3395 3396 for (in=0;in<NDIM*NDIM;in++) 3396 fprintf( SigmaFile,"%e\t", Sigma[in]);3397 fprintf( SigmaFile,"\n");3398 fclose( SigmaFile);3397 fprintf(MomentFile,"%e\t", Moment[in]); 3398 fprintf(MomentFile,"\n"); 3399 fclose(MomentFile); 3399 3400 } 3400 // diagonalize sigma3401 // diagonalize moment 3401 3402 gsl_vector *eval = gsl_vector_alloc(NDIM); 3402 3403 gsl_eigen_herm_workspace *w = gsl_eigen_herm_alloc(NDIM); … … 3414 3415 iso = 0; 3415 3416 for (i=0;i<NDIM;i++) { 3416 I->I[it]. sigma[ion][i] = gsl_vector_get(eval,i);3417 iso += Sigma[i+i*NDIM]/3.;3417 I->I[it].moment[ion][i] = gsl_vector_get(eval,i); 3418 iso += Moment[i+i*NDIM]/3.; 3418 3419 } 3419 3420 eta = (gsl_vector_get(eval,1)-gsl_vector_get(eval,0))/(gsl_vector_get(eval,2)-iso); 3420 delta_ sigma= gsl_vector_get(eval,2) - 0.5*(gsl_vector_get(eval,0)+gsl_vector_get(eval,1));3421 S = (delta_ sigma*delta_sigma)*(1+1./3.*eta*eta);3421 delta_moment = gsl_vector_get(eval,2) - 0.5*(gsl_vector_get(eval,0)+gsl_vector_get(eval,1)); 3422 S = (delta_moment*delta_moment)*(1+1./3.*eta*eta); 3422 3423 A = 0.; 3423 3424 for (i=0;i<NDIM;i++) { 3424 3425 in = cross(i,0); 3425 3426 dex = cross(i,1); 3426 A += pow(-1,i)*pow(0.5*( Sigma[in+dex*NDIM]-Sigma[dex+in*NDIM]),2);3427 A += pow(-1,i)*pow(0.5*(Moment[in+dex*NDIM]-Moment[dex+in*NDIM]),2); 3427 3428 } 3428 3429 if (P->Call.out[ValueOut]) { … … 3431 3432 fprintf(stderr,"\t%lg",gsl_vector_get(eval,i)); 3432 3433 fprintf(stderr,"\nshielding : %e\n", iso); 3433 fprintf(stderr,"anisotropy : %e\n", delta_ sigma);3434 fprintf(stderr,"anisotropy : %e\n", delta_moment); 3434 3435 fprintf(stderr,"asymmetry : %e\n", eta); 3435 3436 fprintf(stderr,"S : %e\n", S); -
pcp/src/perturbed.h
r87b8ed rcc9c36 31 31 void ApplyTotalHamiltonian(struct Problem *P, const fftw_complex *source, fftw_complex *dest, fftw_complex ***fnl, const double PsiFactor, const int first); 32 32 void CalculateMagneticSusceptibility (struct Problem *P); 33 void Calculate ChemicalShielding(struct Problem *P);33 void CalculateMagneticMoment(struct Problem *P); 34 34 void CalculateChemicalShieldingByReciprocalCurrentDensity(struct Problem *P); 35 35 void CalculateChemicalShieldingbyDESolver(struct Problem *P); -
pcp/src/run.c
r87b8ed rcc9c36 1138 1138 CalculateMagneticSusceptibility(P); 1139 1139 debug(P,"Normal calculation of shielding over R-space"); 1140 Calculate ChemicalShielding(P);1140 CalculateMagneticMoment(P); 1141 1141 CalculateChemicalShieldingByReciprocalCurrentDensity(P); 1142 1142 SpeedMeasure(P, CurrDensTime, StopTimeDo);
Note:
See TracChangeset
for help on using the changeset viewer.