00001 00007 #include "InfoStream.h" 00008 #include "ComputeEField.h" 00009 #include "Node.h" 00010 #include "SimParameters.h" 00011 #include "HomePatch.h" 00012 00013 00014 ComputeEField::ComputeEField(ComputeID c, PatchID pid) 00015 : ComputeHomePatch(c,pid) 00016 { 00017 00018 reduction = ReductionMgr::Object()->willSubmit(REDUCTIONS_BASIC); 00019 00020 } 00021 /* END OF FUNCTION ComputeEField */ 00022 00023 00024 ComputeEField::~ComputeEField() 00025 00026 { 00027 delete reduction; 00028 } 00029 /* END OF FUNCTION ~ComputeEField */ 00030 00031 00032 void ComputeEField::doForce(FullAtom* p, Results* r) { 00033 00034 SimParameters *simParams = Node::Object()->simParameters; 00035 Vector eField = simParams->eField; 00036 // Calculate the angular frequency in 1/fs. 00037 BigReal omega = TWOPI * simParams->eFieldFreq / 1000.; 00038 BigReal phi = PI/180.* simParams->eFieldPhase; 00039 BigReal t = patch->flags.step * simParams->dt; 00040 Vector eField1 = cos(omega * t - phi) * eField; 00041 00042 Force *forces = r->f[Results::normal]; 00043 BigReal energy = 0; 00044 Force extForce = 0.; 00045 Tensor extVirial; 00046 00047 // Loop through and check each atom 00048 for (int i=0; i<numAtoms; i++) { 00049 Force force = p[i].charge * eField1; 00050 forces[i] += force; 00051 extForce += force; 00052 Position vpos = homePatch->lattice.reverse_transform( 00053 p[i].position, p[i].transform ); 00054 energy -= force * (vpos - homePatch->lattice.origin()); 00055 extVirial += outer(force,vpos); 00056 } 00057 00058 reduction->item(REDUCTION_MISC_ENERGY) += energy; 00059 ADD_VECTOR_OBJECT(reduction,REDUCTION_EXT_FORCE_NORMAL,extForce); 00060 ADD_TENSOR_OBJECT(reduction,REDUCTION_VIRIAL_NORMAL,extVirial); 00061 reduction->submit(); 00062 00063 } 00064 /* END OF FUNCTION force */
1.3.9.1