/// <summary> /// See the base. /// </summary> public override bool Equals(object obj) { if (obj == null) { return(false); } ExternalField cmpSettings = obj as ExternalField; if (!base.Equals(obj) || !Equals(FeatureFilterCfg, cmpSettings.FeatureFilterCfg) ) { return(false); } return(true); }
public IEntity Map(MemberInfo mi) { IEntity tag = (IEntity)_entityCache[GetCacheKey(mi)]; if (null == tag) { switch (mi.MemberType) { case MemberTypes.Method: { return Map((MethodInfo)mi); } case MemberTypes.Constructor: { return Map((ConstructorInfo)mi); } case MemberTypes.Field: { tag = new ExternalField(this, (FieldInfo)mi); break; } case MemberTypes.Property: { tag = new ExternalProperty(this, (PropertyInfo)mi); break; } case MemberTypes.Event: { tag = new ExternalEvent(this, (EventInfo)mi); break; } case MemberTypes.NestedType: { return Map((Type)mi); } default: { throw new NotImplementedException(mi.ToString()); } } _entityCache.Add(GetCacheKey(mi), tag); } return tag; }
/// <summary> /// The deep copy constructor. /// </summary> /// <param name="source">Source instance</param> public ExternalField(ExternalField source) : base(source) { FeatureFilterCfg = FeatureFilterFactory.DeepClone(source.FeatureFilterCfg); return; }
/* // function to propagate the particle ensemble public void VelocityVerletPropagation(int, int, ExternalField) { } */ // velocity verlet routine to propagate the particle ensemble public void VelocityVerletPropagation(int Height, int Width, ExternalField pExternalField) { int i, kk; double V = 0.0, T = 0.0, dt, pxnew, pynew, factor; AllPositionsUnchangedFromLastStep = true; BoxWidth = Width; BoxHeight = Height; if (NumberOfParticlesChangedFlag) { NumberOfParticlesChangedFlag = false; if (NumberOfParticlesIsGreaterFlag) { for (kk = 0; kk < GetNumberOfForceFieldObjects(); ++kk) { // calculate the ij energy terms for particle set including the new ones GetForceFieldObject(kk).UpdateEnergyTerms(this); } } } else { // Timestep = 1.0/(double)ofGetFrameRate(); Timestep = 0.005; dt = Timestep; ++step; // increment ParticleEnsemble Private data member step if (BerendsenThermostat) { // Berendsen Thermostat BerendsenVelocityRescaling(); } // T=GetKineticEnergy(); // V=GetPotentialEnergy(); // get the potential energy - pretty useless when the external field is time dependent - but useful for // TotalEnergy=T+V; // testing that new interparticle forceFields conserve energy //this loop uses verlet scheme (VV) to propagate the positions forward one step for (i = 0; i < GetNumberOfParticles(); ++i) { SetLastXParticlePosition(i, GetXParticlePosition(i)); SetLastYParticlePosition(i, GetYParticlePosition(i)); factor = 0.5 * dt * dt / GetParticleMass(i); pxnew = GetXParticlePosition(i) + GetXParticleVelocity(i) * dt + GetXParticleForce(i) * factor; pynew = GetYParticlePosition(i) + GetYParticleVelocity(i) * dt + GetYParticleForce(i) * factor; // cout << "x " << pxnew << " y " << pynew << endl; if (pxnew > GetParticleRadius(i) && pxnew < (BoxWidth - GetParticleRadius(i))) { SetXParticlePosition(i, pxnew); // this the standard VV code here // AllPositionsUnchangedFromLastStep = false; // this is a stability measure, to detect if the simulation has frozen from frame to frame } else { // this is to reflect off the walls; added by DRG in lieu of soft walls to improve real time stability... not part of a standard VV scheme SetXParticlePosition(i, GetLastXParticlePosition(i)); SetXParticleVelocity(i, -1.0 * GetXParticleVelocity(i)); SetWasReflectedByWall(i, true); calculateParticleVelocitiesInXWallFrame(i); // cout << "X Wall Reflection, Particle " << i << endl; } if (pynew > GetParticleRadius(i) && pynew < (BoxHeight - GetParticleRadius(i))) { // this the standard VV code here SetYParticlePosition(i, pynew); } else { // this is to reflect off the walls; added by DRG in lieu of soft walls to improve real time stability... not part of a standard VV scheme SetYParticlePosition(i, GetLastYParticlePosition(i)); SetYParticleVelocity(i, -1.0 * GetYParticleVelocity(i)); SetWasReflectedByWall(i, true); calculateParticleVelocitiesInYWallFrame(i); // cout << "Y Wall Reflection, Particle " << i << endl; } } //check whether all the positions are changed from the last step for (i = 0; i < GetNumberOfParticles(); ++i) { if (GetYParticlePosition(i) != GetLastYParticlePosition(i) || GetXParticlePosition(i) != GetLastXParticlePosition(i)) { AllPositionsUnchangedFromLastStep = false; } } if (AllPositionsUnchangedFromLastStep) { // this is a stability measure; if the frame is frozen wrt to the previous frame, //cout << "Positions unchanged" << endl; EliminateParticleOverlap(BoxHeight, BoxWidth); // adjust particle positions to eliminate overlap - this can cause the sim to freeze for (i = 0; i < GetNumberOfParticles(); ++i) { // then we zero out the forces and velocities & repropagate the positions // cout << px[i] << " " << py[i] << " " << vx[i] << " " << vy[i] << " " << fx[i] << " " << fy[i] << " " << fxLast[i] << " " << fyLast[i] << endl; SetXParticleForce(i, 0.0); SetYParticleForce(i, 0.0); SetLastXParticlePosition(i, GetXParticlePosition(i)); SetLastYParticlePosition(i, GetYParticlePosition(i)); SetXParticlePosition(i, GetXParticlePosition(i) + GetXParticleVelocity(i) * dt + (GetXParticleForce(i) / GetParticleMass(i)) * dt * dt * 0.5); SetYParticlePosition(i, GetYParticlePosition(i) + GetYParticleVelocity(i) * dt + (GetYParticleForce(i) / GetParticleMass(i)) * dt * dt * 0.5); } AllPositionsUnchangedFromLastStep = false; } UpdateInterParticleSeparations(); if (pExternalField != null) { pExternalField.CalculateForceField(this); } if (GetForceFieldObject(0).ForceFieldType == "HardSphereForceField") { GetForceFieldObject(0).CalculateForceField(this); } else { for (i = 0; i < GetNumberOfParticles(); ++i) { // save the present forces to t-1 vectors SetLastXParticleForce(i, GetXParticleForce(i)); SetLastYParticleForce(i, GetYParticleForce(i)); } ZeroXForces(); // zero out the force vectors & potential energy ZeroYForces(); SetPotentialEnergy(0.0); for (kk = 0; kk < GetNumberOfForceFieldObjects(); ++kk) { // calculate & set the forces at the new positions GetForceFieldObject(kk).CalculateForceField(this); } for (i = 0; i < GetNumberOfParticles(); ++i) { // use VV scheme to propagate the velocities forward factor = dt * 0.5 / GetParticleMass(i); SetXParticleVelocity(i, GetXParticleVelocity(i) + (GetXParticleForce(i) + GetLastXParticleForce(i)) * factor); SetYParticleVelocity(i, GetYParticleVelocity(i) + (GetYParticleForce(i) + GetLastYParticleForce(i)) * factor); } // see whether any collisions occurred DetermineIfCollisionsOccurred(); } } }