/** propagate angular velocities and quaternions \todo implement for fixed_coord_flag */ void propagate_omega_quat_particle(Particle* p) { double lambda; double Qd[4], Qdd[4], S[3], Wd[3]; #ifdef ROTATION_PER_PARTICLE if (!p->p.rotation) return; #endif define_Qdd(p, Qd, Qdd, S, Wd); lambda = 1 - S[0]*time_step_squared_half - sqrt(1 - time_step_squared*(S[0] + time_step*(S[1] + time_step_half/2.*(S[2]-S[0]*S[0])))); for(int j=0; j < 3; j++){ p->m.omega[j]+= time_step_half*Wd[j]; } ONEPART_TRACE(if(p->p.identity==check_id) fprintf(stderr,"%d: OPT: PV_1 v_new = (%.3e,%.3e,%.3e)\n",this_node,p->m.v[0],p->m.v[1],p->m.v[2])); p->r.quat[0]+= time_step*(Qd[0] + time_step_half*Qdd[0]) - lambda*p->r.quat[0]; p->r.quat[1]+= time_step*(Qd[1] + time_step_half*Qdd[1]) - lambda*p->r.quat[1]; p->r.quat[2]+= time_step*(Qd[2] + time_step_half*Qdd[2]) - lambda*p->r.quat[2]; p->r.quat[3]+= time_step*(Qd[3] + time_step_half*Qdd[3]) - lambda*p->r.quat[3]; // Update the director convert_quat_to_quatu(p->r.quat, p->r.quatu); #ifdef DIPOLES // When dipoles are enabled, update dipole moment convert_quatu_to_dip(p->r.quatu, p->p.dipm, p->r.dip); #endif ONEPART_TRACE(if(p->p.identity==check_id) fprintf(stderr,"%d: OPT: PPOS p = (%.3f,%.3f,%.3f)\n",this_node,p->r.p[0],p->r.p[1],p->r.p[2])); }
/** propagate angular velocities and quaternions \todo implement for fixed_coord_flag */ void propagate_omega_quat() { Particle *p; Cell *cell; int c,i,j, np; double lambda, dt2, dt4, dtdt, dtdt2; dt2 = time_step*0.5; dt4 = time_step*0.25; dtdt = time_step*time_step; dtdt2 = dtdt*0.5; INTEG_TRACE(fprintf(stderr,"%d: propagate_omega_quat:\n",this_node)); for (c = 0; c < local_cells.n; c++) { cell = local_cells.cell[c]; p = cell->part; np = cell->n; for(i = 0; i < np; i++) { double Qd[4], Qdd[4], S[3], Wd[3]; #ifdef VIRTUAL_SITES // Virtual sites are not propagated in the integration step if (ifParticleIsVirtual(&p[i])) continue; #endif define_Qdd(&p[i], Qd, Qdd, S, Wd); lambda = 1 - S[0]*dtdt2 - sqrt(1 - dtdt*(S[0] + time_step*(S[1] + dt4*(S[2]-S[0]*S[0])))); for(j=0; j < 3; j++){ p[i].m.omega[j]+= dt2*Wd[j]; } ONEPART_TRACE(if(p[i].p.identity==check_id) fprintf(stderr,"%d: OPT: PV_1 v_new = (%.3e,%.3e,%.3e)\n",this_node,p[i].m.v[0],p[i].m.v[1],p[i].m.v[2])); p[i].r.quat[0]+= time_step*(Qd[0] + dt2*Qdd[0]) - lambda*p[i].r.quat[0]; p[i].r.quat[1]+= time_step*(Qd[1] + dt2*Qdd[1]) - lambda*p[i].r.quat[1]; p[i].r.quat[2]+= time_step*(Qd[2] + dt2*Qdd[2]) - lambda*p[i].r.quat[2]; p[i].r.quat[3]+= time_step*(Qd[3] + dt2*Qdd[3]) - lambda*p[i].r.quat[3]; // Update the director convert_quat_to_quatu(p[i].r.quat, p[i].r.quatu); #ifdef DIPOLES // When dipoles are enabled, update dipole moment convert_quatu_to_dip(p[i].r.quatu, p[i].p.dipm, p[i].r.dip); #endif ONEPART_TRACE(if(p[i].p.identity==check_id) fprintf(stderr,"%d: OPT: PPOS p = (%.3f,%.3f,%.3f)\n",this_node,p[i].r.p[0],p[i].r.p[1],p[i].r.p[2])); } } }
/** Rotate the particle p around the NORMALIZED axis aSpaceFrame by amount phi */ void rotate_particle(Particle* p, double* aSpaceFrame, double phi) { // Convert rotation axis to body-fixed frame double a[3]; convert_vec_space_to_body(p,aSpaceFrame,a); // Apply restrictions from the rotation_per_particle feature #ifdef ROTATION_PER_PARTICLE // printf("%g %g %g - ",a[0],a[1],a[2]); // Rotation turned off entirely? if (p->p.rotation <2) return; // Per coordinate fixing if (!(p->p.rotation & 2)) a[0]=0; if (!(p->p.rotation & 4)) a[1]=0; if (!(p->p.rotation & 8)) a[2]=0; // Re-normalize rotation axis double l=sqrt(sqrlen(a)); // Check, if the rotation axis is nonzero if (l<1E-10) return; for (int i=0;i<3;i++) a[i]/=l; // printf("%g %g %g\n",a[0],a[1],a[2]); #endif double q[4]; q[0]=cos(phi/2); double tmp=sin(phi/2); q[1]=tmp*a[0]; q[2]=tmp*a[1]; q[3]=tmp*a[2]; // Normalize normalize_quaternion(q); // Rotate the particle double qn[4]; // Resulting quaternion multiply_quaternions(p->r.quat,q,qn); for (int k=0; k<4; k++) p->r.quat[k]=qn[k]; convert_quat_to_quatu(p->r.quat, p->r.quatu); #ifdef DIPOLES // When dipoles are enabled, update dipole moment convert_quatu_to_dip(p->r.quatu, p->p.dipm, p->r.dip); #endif }