1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
|
/**
*** Copyright (c) 1995, 1996, 1997, 1998, 1999, 2000 by
*** The Board of Trustees of the University of Illinois.
*** All rights reserved.
**/
#include "InfoStream.h"
#include "ComputeMField.h"
#include "Node.h"
#include "SimParameters.h"
#include "HomePatch.h"
#include "Sequencer.h"
#include "HomePatch.h"
#include "ReductionMgr.h"
#include "CollectionMgr.h"
#include "BroadcastObject.h"
#include "Output.h"
#include "Controller.h"
#include "Broadcasts.h"
#include "Molecule.h"
#include "NamdOneTools.h"
#include "LdbCoordinator.h"
#include "Thread.h"
#include "Random.h"
#include "PatchMap.inl"
#include "ComputeMgr.h"
#include "ComputeGlobal.h"
ComputeMField::ComputeMField(ComputeID c, PatchID pid)
: ComputeHomePatch(c,pid)
{
reduction = ReductionMgr::Object()->willSubmit(REDUCTIONS_BASIC);
}
/* END OF FUNCTION ComputeMField */
ComputeMField::~ComputeMField()
{
delete reduction;
}
/* END OF FUNCTION ~ComputeMField */
void ComputeMField::doForce(FullAtom* p, Results* r) {
SimParameters *simParams = Node::Object()->simParameters;
Vector mField = simParams->mField;
// Calculate the angular frequency in 1/fs.
//TODO: Kosar, does frequency and phase make sense in magnetic field? If not, change where approperate
BigReal omega = TWOPI * simParams->mFieldFreq / 1000.;
BigReal phi = PI/180.* simParams->mFieldPhase;
BigReal t = patch->flags.step * simParams->dt;
Vector mField1 = cos(omega * t - phi) * mField;
const int normalized = simParams->mFieldNormalized;
if ( normalized ) {
Lattice &l = homePatch->lattice;
mField1 = Vector(l.a_r()*mField1, l.b_r()*mField1, l.c_r()*mField1);
}
Force *forces = r->f[Results::normal];
BigReal energy = 0;
Force extForce = 0.;
Tensor extVirial;
// Loop through and check each atom
for (int i=0; i<numAtoms; i++) {
Force force = (-p[i].charge) * cross(mField1, p[i].velocity);
forces[i] += force;
Position vpos = homePatch->lattice.reverse_transform(
p[i].position, p[i].transform );
energy -= force * (vpos - homePatch->lattice.origin()); //TODO: Kosar, energy preservation should hold
printf("charge: %f", p[i].charge);
printf(", force: [%f, %f, %f]", force.x, force.y, force.z);
printf(", velocity: [%f, %f, %f]\n\n", p[i].velocityHalfStep.x, p[i].velocityHalfStep.y, p[i].velocityHalfStep.z);
if ( ! normalized ) {
extForce += force;
extVirial += outer(force,vpos);
}
}
reduction->item(REDUCTION_MISC_ENERGY) += energy;
if ( ! normalized ) {
ADD_VECTOR_OBJECT(reduction,REDUCTION_EXT_FORCE_NORMAL,extForce);
ADD_TENSOR_OBJECT(reduction,REDUCTION_VIRIAL_NORMAL,extVirial);
}
reduction->submit();
}
/* END OF FUNCTION force */
|