Changeset cc9c36


Ignore:
Timestamp:
Apr 22, 2008, 12:29:35 PM (17 years ago)
Author:
Frederik Heber <heber@…>
Children:
9bdd86
Parents:
87b8ed
Message:

CalculateChemicalShielding() renamed to CalculateMagneticMoment() and (small) changes to code.

The routine does already almost all that's wanted for moments, only prefactors needed change. The rest was just renaming [sS]igma to [mM]oment.

Location:
pcp/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • pcp/src/perturbed.c

    r87b8ed rcc9c36  
    30593059  fftw_real *sigma_real[NDIM_NDIM];
    30603060  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];
    30623064  int *N = Lev0->Plan0.plan->N;
    30633065  //const double FFTfactor = 1.;///Lev0->MaxN;
     
    33053307
    33063308
    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
    33103311 * \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
    33133313 * \f]
    33143314 * One after another for each nuclear position is the tensor evaluated and the result printed
     
    33163316 * \param *P Problem at hand
    33173317 * \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 not
    3319  * considered carefully, recommendend replacement is CalculateChemicalShieldingByReciprocalCurrentDensity().
    33203318 */
    3321 void CalculateChemicalShielding(struct Problem *P)
     3319void CalculateMagneticMoment(struct Problem *P)
    33223320{
    33233321  struct RunStruct *R = &P->R;
     
    33263324  struct Density *Dens0 = R->Lev0->Dens;
    33273325  struct Ions *I = &P->Ion;
    3328   double sigma[NDIM*NDIM],Sigma[NDIM*NDIM];
     3326  double moment[NDIM*NDIM],Moment[NDIM*NDIM];
    33293327  fftw_real *CurrentDensity[NDIM*NDIM];
    33303328  int it, ion, in, dex, i0, n[NDIM], n0, i;//, *NUp;
    33313329  double r[NDIM], fac[NDIM], X[NDIM];
    33323330  const double discrete_factor = Lat->Volume/Lev0->MaxN;
    3333   double eta, delta_sigma, S, A, iso;
     3331  double eta, delta_moment, S, A, iso;
    33343332  const int myPE =  P->Par.me_comm_ST_Psi;
    33353333  int N[NDIM];
     
    33383336  N[2] = Lev0->Plan0.plan->N[2];
    33393337  const int N0 = Lev0->Plan0.plan->local_nx;
    3340   FILE *SigmaFile;
    3341   char suffixsigma[255];
     3338  FILE *MomentFile;
     3339  char suffixmoment[255];
    33423340  time_t seconds; 
    33433341  time(&seconds); // get current time
    33443342 
     3343   if(P->Call.out[NormalOut]) fprintf(stderr,"(%i) Integrating current density to evaluate magnetic moment\n", P->Par.me);
     3344 
    33453345  // set pointers onto current density
    33463346  CurrentDensity[0] = (fftw_real *) Dens0->DensityArray[CurrentDensity0];
     
    33573357  for (it=0; it < I->Max_Types; it++) {  // integration over all types
    33583358    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);
    33603360      for (in=0; in<NDIM; in++) {// index i of vector component in integrand
    33613361        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.;
    33633363   
    33643364          for(n0=0;n0<N0;n0++) // do the integration over real space
     
    33733373                i0 = n[2]+N[2]*(n[1]+N[1]*(n0));  // the index of current density must match LocalSizeR!
    33743374                //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]);
    33763376                //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]);
    33773377              }
    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]);
    33823383        }
    33833384        if (P->Call.out[ValueOut]) fprintf(stderr,"\n");
     
    33863387      for (in=0;in<NDIM;in++)
    33873388        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));
    33893390      // output tensor to file
    33903391      if (P->Par.me == 0) {
    3391         sprintf(&suffixsigma[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
    33953396        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);
    33993400      }
    3400       // diagonalize sigma
     3401      // diagonalize moment
    34013402      gsl_vector *eval = gsl_vector_alloc(NDIM);
    34023403      gsl_eigen_herm_workspace *w = gsl_eigen_herm_alloc(NDIM);
     
    34143415      iso = 0;
    34153416      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.;
    34183419      }
    34193420      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);
    34223423      A = 0.;
    34233424      for (i=0;i<NDIM;i++) {
    34243425        in = cross(i,0);
    34253426        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);
    34273428      }
    34283429      if (P->Call.out[ValueOut]) {
     
    34313432          fprintf(stderr,"\t%lg",gsl_vector_get(eval,i));
    34323433        fprintf(stderr,"\nshielding  : %e\n", iso);
    3433         fprintf(stderr,"anisotropy : %e\n", delta_sigma);
     3434        fprintf(stderr,"anisotropy : %e\n", delta_moment);
    34343435        fprintf(stderr,"asymmetry  : %e\n", eta);
    34353436        fprintf(stderr,"S          : %e\n", S);
  • pcp/src/perturbed.h

    r87b8ed rcc9c36  
    3131void ApplyTotalHamiltonian(struct Problem *P, const fftw_complex *source, fftw_complex *dest, fftw_complex ***fnl, const double PsiFactor, const int first);
    3232void CalculateMagneticSusceptibility (struct Problem *P);
    33 void CalculateChemicalShielding(struct Problem *P);
     33void CalculateMagneticMoment(struct Problem *P);
    3434void CalculateChemicalShieldingByReciprocalCurrentDensity(struct Problem *P);
    3535void CalculateChemicalShieldingbyDESolver(struct Problem *P);
  • pcp/src/run.c

    r87b8ed rcc9c36  
    11381138          CalculateMagneticSusceptibility(P);
    11391139          debug(P,"Normal calculation of shielding over R-space");
    1140           CalculateChemicalShielding(P);
     1140          CalculateMagneticMoment(P);
    11411141          CalculateChemicalShieldingByReciprocalCurrentDensity(P);
    11421142          SpeedMeasure(P, CurrDensTime, StopTimeDo);
Note: See TracChangeset for help on using the changeset viewer.