For paramagnetic simulation (no pair interaction declared), the "atom_modify" command has to be used (in order to initialize the bin).

example: atom_modify sort 1000 4.0 (Freq. of sorting, Cutoff distance)

In order to print the actual time with the total mag., the vector associated to the mag. compute was modified. It is now: [time, Mx, My, Mz, |M|, En_mag]

Optimization of the spin_compute routine: energy and mag. have been gathered in a same loop.
This commit is contained in:
julient31 2017-05-16 08:13:20 -06:00
parent bf18d84273
commit 3168704858
4 changed files with 27 additions and 35 deletions

View File

@ -10,13 +10,14 @@ units metal
dimension 3
#setting boundary conditions. (p for periodic, f for fixed, ...)
boundary p p p
#boundary p p p
#boundary f f f
#setting atom_style, defines what can of atoms to use in simulation (atomic, molecule, angle, dipole, ...)
atom_style spin
#atom_style hybrid sphere spin
atom_modify sort 1000 4.0
###########################
#######Create atoms########
@ -27,7 +28,7 @@ lattice fcc 3.54
#Defining a geometric region of space. Sets ID(user's choice), style(block, sphere, ...), then, args depends on the style chosen
#(for block, one has x0, xf, y0, yf, z0, zf, in distance units)
region box block 0.0 2.0 0.0 2.0 0.0 2.0
region box block 0.0 1.0 0.0 1.0 0.0 1.0
#Creating a simulation box based on the specified region. Entries: number of atom types and box ref.
create_box 1 box
@ -50,18 +51,18 @@ mass 1 1.0
#set group all mass 1.0
#Setting spins orientation and moment
#set group all spin/random 11 1.7
set group all spin 1.7 0.0 1.0 0.0
set group all spin 1.7 1.0 0.0 0.0
#Magnetic exchange interaction coefficient for bulk fcc Cobalt
pair_style pair/spin 4.0
pair_coeff * * 0.0446928 0.003496 1.4885
#pair_style pair/spin 4.0
#pair_coeff * * 0.0446928 0.003496 1.4885
#pair_coeff * * 0.0 0.003496 1.4885
#Fix Langevin spins (merging damping and temperature)
#Defines a cutof distance for the neighbors.
#neighbor 0.5 bin
#Magnetic field fix
fix 1 all force/spin zeeman 50 0.0 0.0 1.0
fix 1 all force/spin zeeman 10 0.0 0.0 1.0
#fix 1 all force/spin zeeman 0.0 0.0 0.0 1.0
#fix 1 all force/spin anisotropy 0.1 0.0 0.0 1.0
@ -74,13 +75,13 @@ fix 3 all nve/spin
#compute total magnetization and magnetic energy
compute mag all compute/spin
fix outmag all ave/time 1 1 100 c_mag[1] c_mag[2] c_mag[3] c_mag[4] c_mag[5] file mag.dat
fix outmag all ave/time 1 1 50 c_mag[1] c_mag[2] c_mag[3] c_mag[4] c_mag[5] c_mag[6] file mag.dat
#Defining a computation that will be performed on a group of atoms.
#Entries: ID(user assigned), group-ID(group of atoms to peform the sim on), style(temp, pe, ...), args
#Setting the timestep for the simulation
timestep 0.000005
timestep 0.00005
##################
#######run########
@ -90,6 +91,6 @@ timestep 0.000005
dump 1 all custom 100 dump_spin.lammpstrj type x y z spx spy spz
#Running the simulations for N timesteps
run 10
run 1000000
#run 100

View File

@ -32,7 +32,7 @@ ComputeSpin::ComputeSpin(LAMMPS *lmp, int narg, char **arg) :
if ((narg != 3) && (narg != 4)) error->all(FLERR,"Illegal compute compute/spin command");
vector_flag = 1;
size_vector = 5;
size_vector = 6;
extvector = 0;
init();
@ -61,7 +61,7 @@ void ComputeSpin::compute_vector()
int i, index;
invoked_vector = update->ntimestep;
countsp = countsptot = 0.0;
mag[0] = mag[1] = mag[2] = mag[3] = 0.0;
magtot[0] = magtot[1] = magtot[2] = magtot[3] = 0.0;
@ -77,13 +77,16 @@ void ComputeSpin::compute_vector()
int nlocal = atom->nlocal;
// compute total magnetization
// compute total magnetization and magnetic energy
for (i = 0; i < nlocal; i++) {
if (mask[i] & groupbit) {
if (atom->mumag_flag && atom->sp_flag) {
mag[0] += sp[i][0];
mag[1] += sp[i][1];
mag[2] += sp[i][2];
magenergy += mumag[i]*sp[i][0]*fm[i][0];
magenergy += mumag[i]*sp[i][1]*fm[i][1];
magenergy += mumag[i]*sp[i][2]*fm[i][2];
countsp++;
}
}
@ -91,6 +94,7 @@ void ComputeSpin::compute_vector()
}
MPI_Allreduce(mag,magtot,4,MPI_DOUBLE,MPI_SUM,world);
MPI_Allreduce(&magenergy,&magenergytot,1,MPI_DOUBLE,MPI_SUM,world);
MPI_Allreduce(&countsp,&countsptot,1,MPI_DOUBLE,MPI_SUM,world);
double scale = 1.0/countsptot;
@ -99,25 +103,12 @@ void ComputeSpin::compute_vector()
magtot[2] *= scale;
magtot[3] = sqrt(square(magtot[0])+square(magtot[1])+square(magtot[2]));
// compute total magnetic energy
for (i = 0; i < nlocal; i++) {
if (mask[i] & groupbit) {
if (atom->mumag_flag && atom->sp_flag) {
magenergy += mumag[i]*sp[i][0]*fm[i][0];
magenergy += mumag[i]*sp[i][1]*fm[i][1];
magenergy += mumag[i]*sp[i][2]*fm[i][2];
}
else error->all(FLERR,"Compute spin/compute declared magnetic quantities (sp and mumag flags)");
}
}
MPI_Allreduce(&magenergy,&magenergytot,1,MPI_DOUBLE,MPI_SUM,world);
vector[0] = magtot[0];
vector[1] = magtot[1];
vector[2] = magtot[2];
vector[3] = magtot[3];
vector[4] = magenergytot;
vector[0] = invoked_vector*update->dt;
vector[1] = magtot[0];
vector[2] = magtot[1];
vector[3] = magtot[2];
vector[4] = magtot[3];
vector[5] = magenergytot;
}
/* ----------------------------------------------------------------------
@ -129,6 +120,6 @@ void ComputeSpin::allocate()
memory->destroy(mag);
memory->create(mag,4,"compute/spin:mag");
memory->create(magtot,5,"compute/spin:mag");
vector = magtot;
memory->create(vector,6,"compute/spin:vector");
}

View File

@ -189,7 +189,7 @@ void FixForceSpin::post_force(int vflag)
//emag -= (sp[i][0]*fm[i][0] + sp[i][1]*fm[i][1] + sp[i][2]*fm[i][2]);
}
}
//printf("test force. 1;i=0, fx=%g, fy=%g, fz=%g \n",fm[0][0],fm[0][1],fm[0][2]);
printf("test force. 1;i=0, fx=%g, fy=%g, fz=%g \n",fm[0][0],fm[0][1],fm[0][2]);
//printf("Field force compute, fm[0][2]=%g \n",fm[0][2]);
}

View File

@ -70,7 +70,7 @@ proc enable_trace {} {
trace variable vmd_frame([molinfo top]) w vmd_draw_spin
}
set molid [mol addfile {/ascldap/users/jtranch/Documents/Test_lammps_Spin3/src/dump_spin.lammpstrj} type {lammpstrj} autobonds off first 0 last -1 step 1 waitfor all]
set molid [mol addfile {/home/jtranch/Documents/lammps/src/dump_spin.lammpstrj} type {lammpstrj} autobonds off first 0 last -1 step 1 waitfor all]
scale by 0.5
animate style Loop
enable_trace