// constructor public SoftSpheres(ParticleEnsemble pParticleSet) { epsilon=10.0; // allocate vectors holding positions & forces LJforces = new DPVector[pParticleSet.GetMaxNumberOfParticles()]; // allocate vector holding cutoff distance for calculating Wall-Particle interactions WallDistance = new double[pParticleSet.GetMaxNumberOfParticles()]; // allocate vector holding cutoff distance for calculating particle-particle interaction //Mat_DP tmp(0.0,pParticleSet->GetMaxNumberOfParticles(),pParticleSet->GetMaxNumberOfParticles()); MinimumDistance = new DPMatrix(0, pParticleSet.GetMaxNumberOfParticles(),pParticleSet.GetMaxNumberOfParticles()); // allocate vectors holding particle-particle LJ energy terms LJenergyTermA = new DPMatrix(0, pParticleSet.GetMaxNumberOfParticles(),pParticleSet.GetMaxNumberOfParticles()); // =tmp; LJenergyTermB = new DPMatrix(0, pParticleSet.GetMaxNumberOfParticles(), pParticleSet.GetMaxNumberOfParticles()); // =tmp; LJgradientTermA = new DPMatrix(0, pParticleSet.GetMaxNumberOfParticles(), pParticleSet.GetMaxNumberOfParticles()); // =tmp; LJgradientTermB = new DPMatrix(0, pParticleSet.GetMaxNumberOfParticles(), pParticleSet.GetMaxNumberOfParticles()); // =tmp; CalculateEnergyTerms(pParticleSet); // calculate initial forcefield CalculateForceField(pParticleSet); }
public ParticleEnsemble(int nparticles, double MinRad, double MaxRad, List<string> FFtype, int Height, int Width, double scaleFactor) { int i; maxNumberOfParticles = 1000; // set the maximum number of particles to 1000 kb = 8.314; // value of the boltzmann constant - we dont really care about units now... BerendsenCoupling = 1.0; // value of the berendsen coupling constant - set this to be controlled by the artist... Tequilibrium = 20000; BerendsenThermostat = true; // BerendsenThermostat=false; EnsembleReinitializationFlag = false; NumberOfParticlesChangedFlag = false; NumberOfParticlesIsGreaterFlag = false; radiiScaleFactor = 1.0; InitialKE = 0.0; gradientScaleFactor = scaleFactor; step = 0; NumberOfParticles = nparticles; BoxHeight = Height; BoxWidth = Width; MaxForceThreshold = 1.0e6; initialMaxForceThreshold = MaxForceThreshold; AverageVelocityAutoCorrelationFunction = new List<double>(new double[1024]); InitialMinVel = 100.0; InitialMaxVel = 200.0; for (int ii = 0; ii < maxNumberOfParticles; ++ii) { initializeOneNewParticle(); } if (!EliminateParticleOverlap(Height, Width)) { // adjust particle positions to eliminate overlap do { //cout << "Can't fit " << NumberOfParticles << " particles into the simulation box " << endl; NumberOfParticles -= 1; // if there's too many particles to fit in the simulation box //cout << "Decrementing the number of particles to " << NumberOfParticles << endl; EliminateParticleOverlap(Height, Width); // decrement the particles till it's ok } while (!EliminateParticleOverlap(Height, Width)); } //DPMatrix tmp1 = new DPMatrix(0.0, maxNumberOfParticles, maxNumberOfParticles); // assign tmp1 matrix to distanceMatrix & distanceMatrixLastTime distanceMatrix = new DPMatrix(0.0, maxNumberOfParticles, maxNumberOfParticles); distanceMatrixLastTime = new DPMatrix(0.0, maxNumberOfParticles, maxNumberOfParticles); distanceMatrixLastLastTime = new DPMatrix(0.0, maxNumberOfParticles, maxNumberOfParticles); particlesWithinRange = new BoolMatrix(false, maxNumberOfParticles, maxNumberOfParticles); // update the particlesWithinRange matrix UpdateInterParticleSeparations(); // update the interparticle separation matrix PotentialEnergy = 0.0; //initialize forcefield Object // cout << FFtype[0] << endl; //if(FFtype[0]=="HardSpheres"){ // pForceFieldVector.push_back(new HardSpheres(this)); //} //else{ // push back forceField objects onto pForceFieldVector - at present, we only have LJ forces, but this can be // easily expanded for (i = 0; i < FFtype.Count; ++i) { if (FFtype[i] == "SoftSpheres") { pForceFieldVector.Add(new SoftSpheres(this)); } // if(FFtype[i]=="ExternalField"){ pForceFieldVector.push_back(new ExternalField(this));} } //} // test of the matrix class implementation /* Mat_DP AA(1.0,3,3), BB(2.0,3,3), CC(0.0,3,3); NR::matadd(AA, BB, CC); // matrix addition for(int i=0; i<3; ++i){ // print out for(int j=0; j<3; ++j){ cout << CC[i][j] << endl; } } */ }
// this stuff is for the FFT - move this stuff to a ParticleMath class //void four1(std::vector<double> &data, const int isign); //void realft(std::vector<double> &data, const int isign); // update the interparticle distanceMatrix public void UpdateInterParticleSeparations() { double ijSeparation = 0; DPMatrix temp = distanceMatrixLastLastTime; distanceMatrixLastLastTime = distanceMatrixLastTime; distanceMatrixLastTime = distanceMatrix; distanceMatrix = temp; for (int i = 0; i < NumberOfParticles; ++i) { for (int j = (i + 1); j < NumberOfParticles; ++j) { //distanceMatrixLastLastTime[i, j] = distanceMatrixLastTime[i, j]; //distanceMatrixLastLastTime[j, i] = distanceMatrixLastTime[j, i]; //distanceMatrixLastTime[i, j] = distanceMatrix[i, j]; // move the present distances to the last //distanceMatrixLastTime[j, i] = distanceMatrix[j, i]; //ijSeparation = Math.Sqrt(Math.Pow(pParticleVector[i].getpx() - pParticleVector[j].getpx(), 2.0) + Math.Pow(pParticleVector[i].getpy() - pParticleVector[j].getpy(), 2.0)); ijSeparation = Math.Pow(pParticleVector[i].getpx() - pParticleVector[j].getpx(), 2.0) + Math.Pow(pParticleVector[i].getpy() - pParticleVector[j].getpy(), 2.0); distanceMatrix[i, j] = ijSeparation; distanceMatrix[j, i] = ijSeparation; // assign the present distances } } }
/// <summary> /// update the interparticle distanceMatrix /// </summary> public void UpdateInterParticleSeparations() { double ijSeparation = 0; DPMatrix temp = m_DistanceMatrixLastLastTime; m_DistanceMatrixLastLastTime = m_DistanceMatrixLastTime; m_DistanceMatrixLastTime = m_DistanceMatrix; m_DistanceMatrix = temp; for (int i = 0; i < m_NumberOfParticles; ++i) { for (int j = (i + 1); j < m_NumberOfParticles; ++j) { //distanceMatrixLastLastTime[i, j] = distanceMatrixLastTime[i, j]; //distanceMatrixLastLastTime[j, i] = distanceMatrixLastTime[j, i]; //distanceMatrixLastTime[i, j] = distanceMatrix[i, j]; // move the present distances to the last //distanceMatrixLastTime[j, i] = distanceMatrix[j, i]; //ijSeparation = Math.Sqrt(Math.Pow(pParticleVector[i].getpx() - pParticleVector[j].getpx(), 2.0) + Math.Pow(pParticleVector[i].getpy() - pParticleVector[j].getpy(), 2.0)); DPVector posi = Particles[i].Position; DPVector posj = Particles[j].Position; ijSeparation = Math.Sqrt(Math.Pow(posi.X - posj.X, 2.0) + Math.Pow(posi.Y - posj.Y, 2.0)); m_DistanceMatrix[i, j] = ijSeparation; m_DistanceMatrix[j, i] = ijSeparation; // assign the present distances } } }
public ParticleEnsemble(int nparticles, double MinRad, double MaxRad, List<string> FFtype, int Height, int Width, double scaleFactor) { int i; // set the maximum number of particles to 1000 m_MaxNumberOfParticles = 1000; // value of the boltzmann constant - we dont really care about units now... m_KB = 8.314; // value of the berendsen coupling constant - set this to be controlled by the artist... m_BerendsenCoupling = 1.0; m_Tequilibrium = 20000; m_BerendsenThermostat = true; // BerendsenThermostat=false; m_EnsembleReinitializationFlag = false; m_NumberOfParticlesChangedFlag = false; m_NumberOfParticlesIsGreaterFlag = false; m_RadiiScaleFactor = 1.0; m_InitialKE = 0.0; m_GradientScaleFactor = scaleFactor; m_Step = 0; m_NumberOfParticles = nparticles; m_BoxHeight = Height; m_BoxWidth = Width; m_MaxForceThreshold = 1.0e6; m_InitialMaxForceThreshold = m_MaxForceThreshold; m_AverageVelocityAutoCorrelationFunction = new List<double>(new double[1024]); m_InitialMinVel = 100.0; m_InitialMaxVel = 200.0; for (int ii = 0; ii < m_MaxNumberOfParticles; ++ii) { InitializeOneNewParticle(); } if (!EliminateParticleOverlap(Height, Width)) { // adjust particle positions to eliminate overlap do { //cout << "Can't fit " << NumberOfParticles << " particles into the simulation box " << endl; // if there's too many particles to fit in the simulation box m_NumberOfParticles -= 1; //cout << "Decrementing the number of particles to " << NumberOfParticles << endl; // decrement the particles till it's ok EliminateParticleOverlap(Height, Width); } while (!EliminateParticleOverlap(Height, Width)); } // assign tmp1 matrix to distanceMatrix & distanceMatrixLastTime m_DistanceMatrix = new DPMatrix(0.0, m_MaxNumberOfParticles, m_MaxNumberOfParticles); m_DistanceMatrixLastTime = new DPMatrix(0.0, m_MaxNumberOfParticles, m_MaxNumberOfParticles); m_DistanceMatrixLastLastTime = new DPMatrix(0.0, m_MaxNumberOfParticles, m_MaxNumberOfParticles); // update the particlesWithinRange matrix m_ParticlesWithinRange = new BoolMatrix(false, m_MaxNumberOfParticles, m_MaxNumberOfParticles); // update the interparticle separation matrix UpdateInterParticleSeparations(); m_PotentialEnergy = 0.0; // push back forceField objects onto pForceFieldVector - at present, we only have LJ forces, but this can be easily expanded for (i = 0; i < FFtype.Count; ++i) { if (FFtype[i] == "SoftSpheres") { m_ForceFields.Add(new SoftSpheres(this)); } } }
public ParticleEnsemble(int nparticles, double MinRad, double MaxRad, List<string> FFtype, int Height, int Width, double scaleFactor) { int i; // set the maximum number of particles to 1000 m_MaxNumberOfParticles = 1000; Particles = new ParticleCollection(this, m_MaxNumberOfParticles); // value of the boltzmann constant - we dont really care about units now... kb = 8.314; // value of the berendsen coupling constant - set this to be controlled by the artist... m_BerendsenThermostatCoupling = 1.0; m_EquilibriumTemperature = 20000; BerendsenThermostat = true; // BerendsenThermostat=false; EnsembleReinitializationFlag = false; NumberOfParticlesChangedFlag = false; NumberOfParticlesIsGreaterFlag = false; m_RadiiScaleFactor = 1.0; InitialKE = 0.0; m_GradientScaleFactor = scaleFactor; step = 0; //NumberOfParticles = nparticles; m_BoxHeight = Height; m_BoxWidth = Width; m_MaxForceThreshold = 1.0e6; m_InitialMaxForceThreshold = m_MaxForceThreshold; // allocate maximum space for and initialize the velocity autocorrelation & FFT vectors m_FFTenabled = true; m_FFTofCorrelationFunction = new List<double>(new double[MAX_CORR_FTN_SIZE]); m_VelocityAutoCorrelationFunction = new double[MAX_CORR_FTN_SIZE]; for (int ii = 0; ii < MAX_CORR_FTN_SIZE; ++ii) { m_VelocityAutoCorrelationFunction[ii] = 0.0; m_FFTofCorrelationFunction[ii] = 0.0; } for (int ii = 0; ii < FFTmatrixForMovingAverage.Count(); ++ii) { FFTmatrixForMovingAverage[ii]= new List<double>(new double[m_NumberOfFFTAverages]); for(int kk=0; kk < m_NumberOfFFTAverages; ++kk){ FFTmatrixForMovingAverage[ii][kk] = 0.0; } } InitialMinVel = 100.0; InitialMaxVel = 200.0; for (int ii = 0; ii < m_MaxNumberOfParticles; ++ii) { InitializeOneNewParticle(); } for (int ii = nparticles; ii < m_MaxNumberOfParticles; ++ii) { Particles.Pop(); } if (!EliminateParticleOverlap(Height, Width)) { // adjust particle positions to eliminate overlap do { // if there's too many particles to fit in the simulation box //NumberOfParticles -= 1; Particles.Pop(); // decrement the particles till it's ok EliminateParticleOverlap(Height, Width); } while (!EliminateParticleOverlap(Height, Width)); } // create matrix to distanceMatrix & distanceMatrixLastTime distanceMatrix = new DPMatrix(0.0, MaxNumberOfParticles, MaxNumberOfParticles); distanceMatrixLastTime = new DPMatrix(0.0, MaxNumberOfParticles, MaxNumberOfParticles); distanceMatrixLastLastTime = new DPMatrix(0.0, MaxNumberOfParticles, MaxNumberOfParticles); // update the particlesWithinRange matrix particlesWithinRange = new BoolMatrix(false, MaxNumberOfParticles, MaxNumberOfParticles); // update the interparticle separation matrix UpdateInterParticleSeparations(); m_PotentialEnergy = 0.0; // push back forceField objects onto pForceFieldVector - at present, we only have LJ forces, but this can be // easily expanded for (i = 0; i < FFtype.Count; ++i) { if (FFtype[i] == "SoftSpheres") { ForceFields.Add(new SoftSpheres(this)); } } }
/// <summary> /// update the interparticle distanceMatrix /// </summary> public void UpdateInterParticleSeparations() { double ijSeparation = 0; DPMatrix temp = distanceMatrixLastLastTime; distanceMatrixLastLastTime = distanceMatrixLastTime; distanceMatrixLastTime = distanceMatrix; distanceMatrix = temp; int numberOfParticles = NumberOfParticles; for (int i = 0; i < numberOfParticles; ++i) { Particle particlei = Particles[i]; for (int j = (i + 1); j < numberOfParticles; ++j) { Particle particlej = Particles[j]; if (particlei.GridSector.IsInJoiningSectors(particlej.GridSector) == false) { continue; } // THIS ONE !UsePOW` #if !UsePOW // SQRT MOD //ijSeparation = Math.Sqrt(Math.Pow(Particles[i].Position.X - Particles[j].Position.X, 2.0) + Math.Pow(Particles[i].Position.Y - Particles[j].Position.Y, 2.0)); ijSeparation = Math.Pow(Particles[i].Position.X - Particles[j].Position.X, 2.0) + Math.Pow(Particles[i].Position.Y - Particles[j].Position.Y, 2.0); #else // SQRT MOD //ijSeparation = Math.Sqrt(MathHelper.Pow2(Particles[i].Position.X - Particles[j].Position.X) + MathHelper.Pow2(Particles[i].Position.Y - Particles[j].Position.Y)); ijSeparation = MathHelper.Pow2(Particles[i].Position.X - Particles[j].Position.X) + MathHelper.Pow2(Particles[i].Position.Y - Particles[j].Position.Y); #endif // assign the present distances distanceMatrix[i, j] = ijSeparation; distanceMatrix[j, i] = ijSeparation; } } }